Revision 59816
Added by Argiro Kokogiannaki over 3 years ago
fetchProjects.class.ts | ||
---|---|---|
5 | 5 |
import {EnvProperties} from '../../utils/properties/env-properties'; |
6 | 6 |
import {StringUtils} from '../../utils/string-utils.class'; |
7 | 7 |
import {SearchResult} from "../entities/searchResult"; |
8 |
import {Subscriber} from "rxjs"; |
|
8 | 9 |
|
9 | 10 |
export class FetchProjects { |
10 | 11 |
private errorCodes: ErrorCodes; |
... | ... | |
14 | 15 |
|
15 | 16 |
public filters; // for getResultsForOrganizations |
16 | 17 |
public funders: any = []; // for getResultsForOrganizations // this is filled with the initial query - before filtering |
17 |
|
|
18 |
public sub: any; |
|
19 |
public subResults: any; |
|
18 |
|
|
19 |
subscriptions = []; |
|
20 | 20 |
public searchUtils: SearchUtilsClass = new SearchUtilsClass(); |
21 | 21 |
|
22 | 22 |
|
... | ... | |
26 | 26 |
this.searchUtils.status = this.errorCodes.LOADING; |
27 | 27 |
|
28 | 28 |
} |
29 |
|
|
30 |
public ngOnDestroy() {
|
|
31 |
if (this.sub) { |
|
32 |
this.sub.unsubscribe();
|
|
33 |
}
|
|
34 |
if (this.subResults) {
|
|
35 |
this.subResults.unsubscribe();
|
|
36 |
} |
|
29 |
|
|
30 |
public clearSubscriptions() {
|
|
31 |
|
|
32 |
this.subscriptions.forEach(subscription => {
|
|
33 |
if (subscription instanceof Subscriber) {
|
|
34 |
subscription.unsubscribe();
|
|
35 |
}
|
|
36 |
});
|
|
37 | 37 |
} |
38 |
|
|
39 | 38 |
public getResultsByKeyword(keyword: string, page: number, size: number, properties: EnvProperties, customFilter: SearchCustomFilter = null) { |
40 | 39 |
var parameters = ""; |
41 | 40 |
if (keyword.length > 0) { |
... | ... | |
48 | 47 |
if (customFilter) { |
49 | 48 |
refineParams = (refineParams ? (refineParams + '&') : '') + "&fq=" + StringUtils.URIEncode(customFilter.queryFieldName + " exact " + StringUtils.quote((customFilter.valueId))); |
50 | 49 |
} |
51 |
this.subResults = this._searchProjectsService.searchProjects(parameters, refineParams, page, size, [], properties).subscribe(
|
|
50 |
this.subscriptions.push(this._searchProjectsService.searchProjects(parameters, refineParams, page, size, [], properties).subscribe(
|
|
52 | 51 |
data => { |
53 | 52 |
this.searchUtils.totalResults = data[0]; |
54 | 53 |
//console.info("search Projects: [Parameters:"+parameters+" ] [total results:"+this.searchUtils.totalResults+"]"); |
... | ... | |
78 | 77 |
this.handleError("Error getting projects for keyword: " + keyword, err); |
79 | 78 |
this.searchUtils.status = this.errorMessages.getErrorCode(err.status); |
80 | 79 |
} |
81 |
); |
|
80 |
));
|
|
82 | 81 |
} |
83 | 82 |
|
84 | 83 |
public getResultsForDataproviders(id: string, page: number, size: number, properties: EnvProperties) { |
85 | 84 |
//var errorCodes:ErrorCodes = new ErrorCodes(); |
86 | 85 |
this.searchUtils.status = this.errorCodes.LOADING; |
87 |
|
|
88 |
this._searchProjectsService.getProjectsforDataProvider(id, page, size, properties).subscribe( |
|
86 |
|
|
87 |
this.subscriptions.push(this._searchProjectsService.getProjectsforDataProvider(id, page, size, properties).subscribe(
|
|
89 | 88 |
data => { |
90 | 89 |
this.searchUtils.totalResults = data[0]; |
91 | 90 |
//console.info("search Projects for Dataproviders: [Id:"+id+" ] [total results:"+this.searchUtils.totalResults+"]"); |
... | ... | |
115 | 114 |
this.handleError("Error getting projects for content provider with id: " + id, err); |
116 | 115 |
this.searchUtils.status = this.errorMessages.getErrorCode(err.status); |
117 | 116 |
} |
118 |
); |
|
117 |
));
|
|
119 | 118 |
} |
120 | 119 |
|
121 | 120 |
public getNumForEntity(entity: string, id: string, properties: EnvProperties) { |
... | ... | |
123 | 122 |
this.searchUtils.status = this.errorCodes.LOADING; |
124 | 123 |
|
125 | 124 |
if (id != "" && entity != "") { |
126 |
|
|
127 |
this._searchProjectsService.numOfEntityProjects(id, entity, properties).subscribe( |
|
125 |
|
|
126 |
this.subscriptions.push(this._searchProjectsService.numOfEntityProjects(id, entity, properties).subscribe(
|
|
128 | 127 |
data => { |
129 | 128 |
this.searchUtils.totalResults = data; |
130 | 129 |
|
... | ... | |
153 | 152 |
this.handleError("Error getting number of projects for " + entity + " with id: " + id, err); |
154 | 153 |
this.searchUtils.status = this.errorMessages.getErrorCode(err.status); |
155 | 154 |
} |
156 |
); |
|
155 |
));
|
|
157 | 156 |
} |
158 | 157 |
} |
159 | 158 |
|
160 | 159 |
public getResultsForOrganizations(organizationId: string, filterquery: string, page: number, size: number, refineFields: string[], properties: EnvProperties) { |
161 | 160 |
//var errorCodes:ErrorCodes = new ErrorCodes(); |
162 | 161 |
this.searchUtils.status = this.errorCodes.LOADING; |
163 |
this._searchProjectsService.getProjectsForOrganizations(organizationId, filterquery, page, size, refineFields, properties).subscribe( |
|
162 |
this.subscriptions.push(this._searchProjectsService.getProjectsForOrganizations(organizationId, filterquery, page, size, refineFields, properties).subscribe(
|
|
164 | 163 |
data => { |
165 | 164 |
this.searchUtils.totalResults = data[0]; // the results can be filtered so this number can be no total results |
166 | 165 |
//console.info("search Projects for Organization: [Id:"+organizationId+" ] [total results:"+this.searchUtils.totalResults+"]"); |
... | ... | |
203 | 202 |
this.handleError("Error getting projects for organization with id: " + organizationId, err); |
204 | 203 |
this.searchUtils.status = this.errorMessages.getErrorCode(err.status); |
205 | 204 |
} |
206 |
); |
|
205 |
));
|
|
207 | 206 |
} |
208 | 207 |
|
209 | 208 |
private handleError(message: string, error) { |
Also available in: Unified diff
[Library|Trunk]
code clean up:
-remove app.* files from library
-remove unused imports, code, files (Old search pages for results, dataproviders, map search page, etc)
-remove Freeguard from modules
-unsubscribe all subscriptions
-Services: configuration, isvocabularies, user management: unsubscribe from app component or the component that uses them (clearSubscriptions())
-Fetchers: unsubscribe from the component that uses them (clearSubscriptions())