Revision 58579
Added by Argiro Kokogiannaki almost 4 years ago
modules/uoa-services-library/trunk/ng-openaire-library/src/app/sharedComponents/searchBar/searchBar.component.ts | ||
---|---|---|
1 | 1 |
import {Component, Input} from '@angular/core'; |
2 |
import {ActivatedRoute, Router} from '@angular/router'; |
|
2 |
import {ActivatedRoute, NavigationEnd, NavigationStart, Router} from '@angular/router';
|
|
3 | 3 |
import {EnvProperties} from "../../utils/properties/env-properties"; |
4 | 4 |
import {SearchCustomFilter} from "../../searchPages/searchUtils/searchUtils.class"; |
5 | 5 |
|
... | ... | |
24 | 24 |
advancedSearchLink = null; |
25 | 25 |
constructor(private router: Router, |
26 | 26 |
private route: ActivatedRoute ) { |
27 |
this.router.events.subscribe((e) => { |
|
28 |
if(e instanceof NavigationEnd){ |
|
29 |
// console.log(e) |
|
30 |
this.initialize(); |
|
31 |
} |
|
32 |
}); |
|
27 | 33 |
} |
28 | 34 |
|
29 | 35 |
ngOnInit() { |
... | ... | |
32 | 38 |
if(this.communityId){ |
33 | 39 |
this.customFilter = new SearchCustomFilter("Community", "communityId", this.communityId, ""); |
34 | 40 |
} |
41 |
this.entityType = "all"; |
|
35 | 42 |
this.route.queryParams.subscribe(params => { |
36 | 43 |
this.parameters = Object.assign({}, params); |
37 |
this.entityType = "all"; |
|
38 | 44 |
if(this.onlyresults) { |
39 | 45 |
if (params["type"] && params["type"].length > 0) { |
40 | 46 |
let types = params["type"].split(","); |
... | ... | |
50 | 56 |
} |
51 | 57 |
} |
52 | 58 |
} |
53 |
}else{ |
|
54 |
let currentRoute= this.getCurrentRoute(); |
|
55 |
if(currentRoute== this.properties.searchLinkToProjects){ |
|
56 |
this.entityType = "project"; |
|
57 |
}else if(currentRoute== this.properties.searchLinkToDataProviders){ |
|
58 |
this.entityType = "dataprovider"; |
|
59 |
}else if(currentRoute== this.properties.searchLinkToOrganizations){ |
|
60 |
this.entityType = "organization"; |
|
61 |
}else{ |
|
62 |
this.entityType = "result"; |
|
63 |
} |
|
64 | 59 |
} |
65 |
if(this.getCurrentRoute() == this.properties.searchLinkToAdvancedResults){ |
|
66 |
this.enableSearchbar = false; |
|
60 |
}); |
|
61 |
this.initialize() |
|
62 |
} |
|
63 |
initialize(){ |
|
64 |
if(!this.onlyresults){ |
|
65 |
let currentRoute= this.getCurrentRoute(); |
|
66 |
if(currentRoute== this.properties.searchLinkToProjects){ |
|
67 |
this.entityType = "project"; |
|
68 |
}else if(currentRoute== this.properties.searchLinkToDataProviders){ |
|
69 |
this.entityType = "dataprovider"; |
|
70 |
}else if(currentRoute== this.properties.searchLinkToOrganizations){ |
|
71 |
this.entityType = "organization"; |
|
67 | 72 |
}else{ |
68 |
this.enableSearchbar = true;
|
|
73 |
this.entityType = "result";
|
|
69 | 74 |
} |
70 |
if(this.getCurrentRoute() == this.properties.searchLinkToResults){
|
|
71 |
this.advancedSearchLink = this.properties.searchLinkToAdvancedResults;
|
|
72 |
}else{
|
|
73 |
this.advancedSearchLink = null;
|
|
74 |
}
|
|
75 |
});
|
|
76 |
|
|
75 |
}
|
|
76 |
if(this.getCurrentRoute() == this.properties.searchLinkToAdvancedResults){
|
|
77 |
this.enableSearchbar = false;
|
|
78 |
}else{
|
|
79 |
this.enableSearchbar = true;
|
|
80 |
} |
|
81 |
this.showAdvancedLink(); |
|
77 | 82 |
} |
78 |
|
|
83 |
showAdvancedLink(){ |
|
84 |
if(this.getCurrentRoute() == this.properties.searchLinkToResults && this.entityType == "result"){ |
|
85 |
this.advancedSearchLink = this.properties.searchLinkToAdvancedResults; |
|
86 |
}else{ |
|
87 |
this.advancedSearchLink = null; |
|
88 |
} |
|
89 |
} |
|
79 | 90 |
isEnabled(required, enabled) { |
80 | 91 |
if (!required) { |
81 | 92 |
return true; |
... | ... | |
96 | 107 |
if(!this.onlyresults && this.entityType == "result") { |
97 | 108 |
this.parameters["qf"] = true; |
98 | 109 |
} |
99 |
/* if(this.entityType == "result"){ |
|
100 |
this.advancedSearchLink = this.properties.searchLinkToAdvancedResults; |
|
101 |
}else{ |
|
102 |
this.advancedSearchLink = null; |
|
103 |
}*/ |
|
110 |
this.showAdvancedLink(); |
|
104 | 111 |
} |
105 | 112 |
keywordChanged(){ |
106 | 113 |
if(!this.onlyresults) { |
Also available in: Unified diff
[Library|Trunk]
Search Bar:
catch more events and initialize on params change, route chnages, and on entity changed