Revision 59816
Added by Argiro Kokogiannaki over 3 years ago
directLinking.component.ts | ||
---|---|---|
1 | 1 |
import {Component, Input, ViewChild} from '@angular/core'; |
2 | 2 |
import {ActivatedRoute, Router} from '@angular/router'; |
3 |
import {Meta, Title} from '@angular/platform-browser'; |
|
4 |
|
|
5 | 3 |
import {EnvProperties} from '../../utils/properties/env-properties'; |
6 | 4 |
import {ClaimEntity, ClaimProject, ShowOptions} from '../claim-utils/claimHelper.class'; |
7 | 5 |
import {EntitiesSearchService} from '../../utils/entitiesAutoComplete/entitySearch.service'; |
8 | 6 |
import {SearchResearchResultsService} from '../../services/searchResearchResults.service'; |
9 | 7 |
import {LinkingGenericComponent} from "../linking/linkingGeneric.component"; |
10 | 8 |
import {ClaimResultSearchFormComponent} from "../claim-utils/claimResultSearchForm.component"; |
9 |
import {Subscriber} from "rxjs"; |
|
11 | 10 |
|
12 | 11 |
|
13 | 12 |
@Component({ |
... | ... | |
31 | 30 |
validEntityTypes = ["dataset", "publication", "software", "orp", "project", "context"]; |
32 | 31 |
sources: ClaimEntity[] = []; |
33 | 32 |
inlineEntity: ClaimEntity = null; |
34 |
sub: any = null; |
|
35 | 33 |
validInput: boolean = null;//'true; |
36 | 34 |
properties: EnvProperties; |
37 | 35 |
@Input() communityId: string = null; |
38 | 36 |
localStoragePrefix: string = ""; |
39 | 37 |
constructor(private _router: Router, private route: ActivatedRoute,private entitySearch:EntitiesSearchService, |
40 | 38 |
private _searchResearchResultsService: SearchResearchResultsService) {} |
41 |
|
|
39 |
subscriptions = []; |
|
40 |
ngOnDestroy() { |
|
41 |
this.subscriptions.forEach(subscription => { |
|
42 |
if (subscription instanceof Subscriber) { |
|
43 |
subscription.unsubscribe(); |
|
44 |
} |
|
45 |
}); |
|
46 |
} |
|
42 | 47 |
ngOnInit() { |
43 |
this.route.data |
|
48 |
this.subscriptions.push(this.route.data
|
|
44 | 49 |
.subscribe((data: { envSpecific: EnvProperties }) => { |
45 | 50 |
this.properties = data.envSpecific; |
46 |
}); |
|
51 |
}));
|
|
47 | 52 |
|
48 |
this.sub = this.route.queryParams.subscribe(params => {
|
|
53 |
this.subscriptions.push(this.route.queryParams.subscribe(params => {
|
|
49 | 54 |
this.id = params['id']; |
50 | 55 |
this.type = params['type']; |
51 | 56 |
this.showOptions.linkTo = params['linkTo']; |
... | ... | |
104 | 109 |
|
105 | 110 |
} |
106 | 111 |
|
107 |
}); |
|
112 |
}));
|
|
108 | 113 |
} |
109 | 114 |
|
110 | 115 |
isValidInput(result: ClaimEntity) { |
... | ... | |
122 | 127 |
} |
123 | 128 |
|
124 | 129 |
getProjectById(id: string) { |
125 |
this.sub = this.entitySearch.fetchByType(id,"project", this.properties).subscribe(
|
|
130 |
this.subscriptions.push(this.entitySearch.fetchByType(id,"project", this.properties).subscribe(
|
|
126 | 131 |
data => { |
127 | 132 |
this.createClaimEntity(data, "project"); |
128 | 133 |
}, |
... | ... | |
130 | 135 |
this.validInput = this.isValidInput(null); |
131 | 136 |
//console.log("An error occured") |
132 | 137 |
this.handleError("Error getting project by id: " + id, err); |
133 |
}); |
|
138 |
}));
|
|
134 | 139 |
} |
135 | 140 |
|
136 | 141 |
getResearchResultById(resultType: string, id: string) { |
137 |
this.sub = this._searchResearchResultsService.searchById(resultType, id, this.properties).subscribe(data => {
|
|
142 |
this.subscriptions.push(this._searchResearchResultsService.searchById(resultType, id, this.properties).subscribe(data => {
|
|
138 | 143 |
this.createClaimEntity(data, resultType); |
139 | 144 |
}, |
140 | 145 |
err => { |
141 | 146 |
this.validInput = this.isValidInput(null); |
142 | 147 |
//console.log("An error occured") |
143 | 148 |
this.handleError("Error getting "+this.getEntityName(resultType, false, true)+" by id: " + id, err); |
144 |
}); |
|
149 |
}));
|
|
145 | 150 |
} |
146 | 151 |
|
147 | 152 |
createClaimEntity(data, type: string) { |
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())