Revision 59816
Added by Argiro Kokogiannaki over 3 years ago
ISVocabularies.service.ts | ||
---|---|---|
1 | 1 |
import {Injectable} from '@angular/core'; |
2 | 2 |
import {HttpClient, HttpErrorResponse} from "@angular/common/http"; |
3 |
import {Observable, throwError, of, BehaviorSubject, from} from 'rxjs'; |
|
3 |
import {Observable, throwError, of, BehaviorSubject, from, Subscriber} from 'rxjs';
|
|
4 | 4 |
import {AutoCompleteValue} from '../../searchPages/searchUtils/searchHelperClasses.class'; |
5 | 5 |
import 'rxjs/add/observable/zip'; |
6 | 6 |
|
... | ... | |
11 | 11 |
export class ISVocabulariesService { |
12 | 12 |
private vocabularies: Map<string, BehaviorSubject<AutoCompleteValue[]>> = new Map<string, BehaviorSubject<AutoCompleteValue[]>>(); |
13 | 13 |
private provenanceActionVocabulary: BehaviorSubject<{}> = new BehaviorSubject(null); |
14 |
private subscriptions = []; |
|
14 | 15 |
|
15 | 16 |
constructor(private http: HttpClient) {} |
16 |
|
|
17 |
|
|
18 |
ngOnDestroy() { |
|
19 |
this.clearSubscriptions(); |
|
20 |
} |
|
21 |
|
|
22 |
clearSubscriptions() { |
|
23 |
this.subscriptions.forEach(subscription => { |
|
24 |
if (subscription instanceof Subscriber) { |
|
25 |
subscription.unsubscribe(); |
|
26 |
} |
|
27 |
}); |
|
28 |
} |
|
17 | 29 |
getVocabularyByType(field: string, entity: string, properties: EnvProperties): Observable<any> { |
18 | 30 |
//console.log("getVocabulary field: "+ field + " for entity: "+ entity); |
19 | 31 |
var file = ""; |
... | ... | |
78 | 90 |
await new Promise<any>(resolve => { |
79 | 91 |
this.vocabularies.set(vocabularyName, new BehaviorSubject<any>(null)); |
80 | 92 |
|
81 |
this.getVocabularyFromService(vocabularyName, properties).subscribe( |
|
93 |
this.subscriptions.push(this.getVocabularyFromService(vocabularyName, properties).subscribe(
|
|
82 | 94 |
vocabularyRes => { |
83 | 95 |
this.vocabularies.get(vocabularyName).next(vocabularyRes); |
84 | 96 |
resolve(); |
... | ... | |
86 | 98 |
this.vocabularies.get(vocabularyName).next(null); |
87 | 99 |
resolve(); |
88 | 100 |
} |
89 |
); |
|
101 |
));
|
|
90 | 102 |
}); |
103 |
this.clearSubscriptions(); |
|
91 | 104 |
} |
92 | 105 |
|
93 | 106 |
return this.vocabularies.get(vocabularyName).getValue(); |
... | ... | |
127 | 140 |
async getProvenanceActionVocabularyFromServiceAsync (vocabularyName: string, properties: EnvProperties): Promise<{}> { |
128 | 141 |
if(!this.provenanceActionVocabulary || !this.provenanceActionVocabulary.getValue()) { |
129 | 142 |
await new Promise<any>(resolve => { |
130 |
this.getProvenanceActionVocabularyFromService(vocabularyName, properties).subscribe( |
|
143 |
this.subscriptions.push(this.getProvenanceActionVocabularyFromService(vocabularyName, properties).subscribe(
|
|
131 | 144 |
vocabularyRes => { |
132 | 145 |
this.provenanceActionVocabulary.next(vocabularyRes); |
133 | 146 |
resolve(); |
... | ... | |
136 | 149 |
this.provenanceActionVocabulary.next(null); |
137 | 150 |
resolve(); |
138 | 151 |
} |
139 |
); |
|
152 |
));
|
|
140 | 153 |
}); |
154 |
this.clearSubscriptions(); |
|
141 | 155 |
} |
142 | 156 |
return this.provenanceActionVocabulary.getValue(); |
143 | 157 |
} |
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())