Revision 59816
Added by Argiro Kokogiannaki over 3 years ago
fetchDataproviders.class.ts | ||
---|---|---|
4 | 4 |
import {SearchCustomFilter, SearchUtilsClass} from '../../searchPages/searchUtils/searchUtils.class'; |
5 | 5 |
import {EnvProperties} from '../../utils/properties/env-properties'; |
6 | 6 |
import {StringUtils} from '../../utils/string-utils.class'; |
7 |
import {Subscriber} from "rxjs"; |
|
7 | 8 |
|
8 | 9 |
export class FetchDataproviders { |
9 | 10 |
private errorCodes: ErrorCodes; |
... | ... | |
11 | 12 |
|
12 | 13 |
public results = []; |
13 | 14 |
public searchUtils: SearchUtilsClass = new SearchUtilsClass(); |
14 |
public sub: any; |
|
15 |
public subResults: any; |
|
15 |
subscriptions = []; |
|
16 | 16 |
public CSV: any = { |
17 | 17 |
"columnNames": ["Title", "Type", "Coutries", "Compatibility"], |
18 | 18 |
"export": [] |
... | ... | |
27 | 27 |
this.errorMessages = new ErrorMessagesComponent(); |
28 | 28 |
this.searchUtils.status = this.errorCodes.LOADING; |
29 | 29 |
} |
30 |
|
|
31 |
|
|
32 |
public ngOnDestroy() {
|
|
33 |
if (this.sub) { |
|
34 |
this.sub.unsubscribe();
|
|
35 |
}
|
|
36 |
if (this.subResults) {
|
|
37 |
this.subResults.unsubscribe();
|
|
38 |
} |
|
30 |
|
|
31 |
|
|
32 |
public clearSubscriptions() {
|
|
33 |
|
|
34 |
this.subscriptions.forEach(subscription => {
|
|
35 |
if (subscription instanceof Subscriber) {
|
|
36 |
subscription.unsubscribe();
|
|
37 |
}
|
|
38 |
});
|
|
39 | 39 |
} |
40 | 40 |
|
41 | 41 |
public getResultsByKeyword(keyword: string, page: number, size: number, properties: EnvProperties, customFilter: SearchCustomFilter = null) { |
... | ... | |
51 | 51 |
if (customFilter) { |
52 | 52 |
refineParams = (refineParams ? (refineParams + '&') : '') + "&fq=" + StringUtils.URIEncode(customFilter.queryFieldName + " exact " + StringUtils.quote((customFilter.valueId))); |
53 | 53 |
} |
54 |
this.subResults = this._searchDataprovidersService.searchDataproviders(parameters, refineParams, page, size, [], properties).subscribe(
|
|
54 |
this.subscriptions.push(this._searchDataprovidersService.searchDataproviders(parameters, refineParams, page, size, [], properties).subscribe(
|
|
55 | 55 |
data => { |
56 | 56 |
this.searchUtils.totalResults = data[0]; |
57 | 57 |
//console.info("search Content Providers: [Parameters:"+parameters+" ] [total results:"+this.searchUtils.totalResults+"]"); |
... | ... | |
82 | 82 |
this.handleError("Error getting content providers for keyword: " + keyword, err); |
83 | 83 |
this.searchUtils.status = this.errorMessages.getErrorCode(err.status); |
84 | 84 |
} |
85 |
); |
|
85 |
));
|
|
86 | 86 |
} |
87 | 87 |
|
88 | 88 |
public getResultsForHome(size: number, properties: EnvProperties) { |
... | ... | |
90 | 90 |
var parameters = "&sortBy=resultdateofacceptance,descending";//"orderby=date"; |
91 | 91 |
|
92 | 92 |
this.searchUtils.status = this.errorCodes.LOADING; |
93 |
|
|
94 |
this.subResults = this._searchDataprovidersService.searchDataproviders(parameters, null, page, size, [], properties).subscribe(
|
|
93 |
|
|
94 |
this.subscriptions.push(this._searchDataprovidersService.searchDataproviders(parameters, null, page, size, [], properties).subscribe(
|
|
95 | 95 |
data => { |
96 | 96 |
this.searchUtils.totalResults = data[0]; |
97 | 97 |
//console.info("search Content Providers: [Parameters:"+parameters+" ] [total results:"+this.searchUtils.totalResults+"]"); |
... | ... | |
115 | 115 |
this.handleError("Error getting content providers with parameters: " + parameters + " for Home", err); |
116 | 116 |
this.searchUtils.status = this.errorMessages.getErrorCode(err.status); |
117 | 117 |
} |
118 |
); |
|
118 |
));
|
|
119 | 119 |
} |
120 | 120 |
|
121 | 121 |
public getNumForEntity(entity: string, id: string, properties: EnvProperties) { |
... | ... | |
123 | 123 |
this.searchUtils.status = this.errorCodes.LOADING; |
124 | 124 |
|
125 | 125 |
if (id != "" && entity != "") { |
126 |
|
|
127 |
this._searchDataprovidersService.numOfEntityDataproviders(id, entity, properties).subscribe( |
|
126 |
|
|
127 |
this.subscriptions.push(this._searchDataprovidersService.numOfEntityDataproviders(id, entity, properties).subscribe(
|
|
128 | 128 |
data => { |
129 | 129 |
this.searchUtils.totalResults = data; |
130 | 130 |
|
... | ... | |
152 | 152 |
this.handleError("Error getting content providers for " + entity + " with id: " + id, err); |
153 | 153 |
this.searchUtils.status = this.errorMessages.getErrorCode(err.status); |
154 | 154 |
} |
155 |
); |
|
155 |
));
|
|
156 | 156 |
} |
157 | 157 |
} |
158 | 158 |
|
159 | 159 |
public getNumForSearch(keyword: string, properties: EnvProperties, refineParams: string = null) { |
160 | 160 |
//var errorCodes:ErrorCodes = new ErrorCodes(); |
161 | 161 |
this.searchUtils.status = this.errorCodes.LOADING; |
162 |
|
|
163 |
this._searchDataprovidersService.numOfSearchDataproviders(keyword, properties, refineParams).subscribe( |
|
162 |
|
|
163 |
this.subscriptions.push(this._searchDataprovidersService.numOfSearchDataproviders(keyword, properties, refineParams).subscribe(
|
|
164 | 164 |
data => { |
165 | 165 |
this.searchUtils.totalResults = data; |
166 | 166 |
this.searchUtils.status = this.errorCodes.DONE; |
... | ... | |
187 | 187 |
this.handleError("Error getting number of content providers for keyword: " + keyword, err); |
188 | 188 |
this.searchUtils.status = this.errorMessages.getErrorCode(err.status); |
189 | 189 |
} |
190 |
); |
|
190 |
));
|
|
191 | 191 |
} |
192 | 192 |
|
193 | 193 |
public getResultsForDeposit(id: string, type: string, page: number, size: number, properties: EnvProperties) { |
... | ... | |
198 | 198 |
this.loadPaging = false; |
199 | 199 |
|
200 | 200 |
if (id != "") { |
201 |
|
|
202 |
this._searchDataprovidersService.searchDataprovidersForDeposit(id, type, page, size, properties).subscribe( |
|
201 |
|
|
202 |
this.subscriptions.push(this._searchDataprovidersService.searchDataprovidersForDeposit(id, type, page, size, properties).subscribe(
|
|
203 | 203 |
data => { |
204 | 204 |
this.searchUtils.totalResults = data[0]; |
205 | 205 |
//console.info("search Dataproviders forDeposit: [id:"+id+", type:"+type+" ] [total results:"+this.searchUtils.totalResults+"]"); |
... | ... | |
246 | 246 |
this.loadPaging = true; |
247 | 247 |
this.oldTotalResults = 0; |
248 | 248 |
} |
249 |
); |
|
249 |
));
|
|
250 | 250 |
} |
251 | 251 |
} |
252 | 252 |
|
... | ... | |
257 | 257 |
this.results = []; |
258 | 258 |
this.searchUtils.totalResults = 0; |
259 | 259 |
this.loadPaging = false; |
260 |
|
|
261 |
this._searchDataprovidersService.searchDataProvidersBySubjects(subject, type, page, size, properties).subscribe( |
|
260 |
|
|
261 |
this.subscriptions.push(this._searchDataprovidersService.searchDataProvidersBySubjects(subject, type, page, size, properties).subscribe(
|
|
262 | 262 |
data => { |
263 | 263 |
this.searchUtils.totalResults = data[0]; |
264 | 264 |
//console.info("search Dataproviders forDeposit: [subject:"+subject+", type:"+type+" ] [total results:"+this.searchUtils.totalResults+"]"); |
... | ... | |
304 | 304 |
this.loadPaging = true; |
305 | 305 |
this.oldTotalResults = 0; |
306 | 306 |
} |
307 |
); |
|
307 |
));
|
|
308 | 308 |
|
309 | 309 |
} |
310 | 310 |
|
... | ... | |
319 | 319 |
} |
320 | 320 |
|
321 | 321 |
if (parameters != "") { |
322 |
|
|
323 |
this._searchDataprovidersService.searchDataprovidersForEntity(parameters, page, size, properties).subscribe( |
|
322 |
|
|
323 |
this.subscriptions.push(this._searchDataprovidersService.searchDataprovidersForEntity(parameters, page, size, properties).subscribe(
|
|
324 | 324 |
data => { |
325 | 325 |
this.searchUtils.totalResults = data[0]; |
326 | 326 |
//console.info("search Dataproviders for "+entity+": [Parameters:"+parameters+" ] [total results:"+this.searchUtils.totalResults+"]"); |
... | ... | |
350 | 350 |
this.handleError("Error getting content providers for " + entity + " with id: " + id, err); |
351 | 351 |
this.searchUtils.status = this.errorMessages.getErrorCode(err.status); |
352 | 352 |
} |
353 |
); |
|
353 |
));
|
|
354 | 354 |
} |
355 | 355 |
} |
356 | 356 |
|
357 | 357 |
public getResultsForDataproviders(id: string, page: number, size: number, properties: EnvProperties) { |
358 | 358 |
//var errorCodes:ErrorCodes = new ErrorCodes(); |
359 | 359 |
this.searchUtils.status = this.errorCodes.LOADING; |
360 |
|
|
361 |
this._searchDataprovidersService.getDataProvidersforEntityRegistry(id, page, size, properties).subscribe( |
|
360 |
|
|
361 |
this.subscriptions.push(this._searchDataprovidersService.getDataProvidersforEntityRegistry(id, page, size, properties).subscribe(
|
|
362 | 362 |
data => { |
363 | 363 |
this.searchUtils.totalResults = data[0]; |
364 | 364 |
//console.info("search Dataproviders for Entity Registry: [Id:"+id+" ] [total results:"+this.searchUtils.totalResults+"]"); |
... | ... | |
388 | 388 |
this.handleError("Error getting content providers for entity registry with id: " + id, err); |
389 | 389 |
this.searchUtils.status = this.errorMessages.getErrorCode(err.status); |
390 | 390 |
} |
391 |
); |
|
391 |
));
|
|
392 | 392 |
} |
393 | 393 |
|
394 | 394 |
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())