[Library|Trunk]

Search Bar:
	catch more events and initialize on params change, route chnages, and on entity changed


git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@58579 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
argiro.kokogiannaki 2020-04-30 09:23:30 +00:00
parent 0b5cf0f6f8
commit b35ebb80fc
1 changed files with 37 additions and 30 deletions

View File

@ -1,5 +1,5 @@
import {Component, Input} from '@angular/core'; import {Component, Input} from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router'; import {ActivatedRoute, NavigationEnd, NavigationStart, Router} from '@angular/router';
import {EnvProperties} from "../../utils/properties/env-properties"; import {EnvProperties} from "../../utils/properties/env-properties";
import {SearchCustomFilter} from "../../searchPages/searchUtils/searchUtils.class"; import {SearchCustomFilter} from "../../searchPages/searchUtils/searchUtils.class";
@ -24,6 +24,12 @@ export class SearchBarComponent {
advancedSearchLink = null; advancedSearchLink = null;
constructor(private router: Router, constructor(private router: Router,
private route: ActivatedRoute ) { private route: ActivatedRoute ) {
this.router.events.subscribe((e) => {
if(e instanceof NavigationEnd){
// console.log(e)
this.initialize();
}
});
} }
ngOnInit() { ngOnInit() {
@ -32,9 +38,9 @@ export class SearchBarComponent {
if(this.communityId){ if(this.communityId){
this.customFilter = new SearchCustomFilter("Community", "communityId", this.communityId, ""); this.customFilter = new SearchCustomFilter("Community", "communityId", this.communityId, "");
} }
this.entityType = "all";
this.route.queryParams.subscribe(params => { this.route.queryParams.subscribe(params => {
this.parameters = Object.assign({}, params); this.parameters = Object.assign({}, params);
this.entityType = "all";
if(this.onlyresults) { if(this.onlyresults) {
if (params["type"] && params["type"].length > 0) { if (params["type"] && params["type"].length > 0) {
let types = params["type"].split(","); let types = params["type"].split(",");
@ -50,7 +56,12 @@ export class SearchBarComponent {
} }
} }
} }
}else{ }
});
this.initialize()
}
initialize(){
if(!this.onlyresults){
let currentRoute= this.getCurrentRoute(); let currentRoute= this.getCurrentRoute();
if(currentRoute== this.properties.searchLinkToProjects){ if(currentRoute== this.properties.searchLinkToProjects){
this.entityType = "project"; this.entityType = "project";
@ -67,15 +78,15 @@ export class SearchBarComponent {
}else{ }else{
this.enableSearchbar = true; this.enableSearchbar = true;
} }
if(this.getCurrentRoute() == this.properties.searchLinkToResults){ this.showAdvancedLink();
}
showAdvancedLink(){
if(this.getCurrentRoute() == this.properties.searchLinkToResults && this.entityType == "result"){
this.advancedSearchLink = this.properties.searchLinkToAdvancedResults; this.advancedSearchLink = this.properties.searchLinkToAdvancedResults;
}else{ }else{
this.advancedSearchLink = null; this.advancedSearchLink = null;
} }
});
} }
isEnabled(required, enabled) { isEnabled(required, enabled) {
if (!required) { if (!required) {
return true; return true;
@ -96,11 +107,7 @@ export class SearchBarComponent {
if(!this.onlyresults && this.entityType == "result") { if(!this.onlyresults && this.entityType == "result") {
this.parameters["qf"] = true; this.parameters["qf"] = true;
} }
/* if(this.entityType == "result"){ this.showAdvancedLink();
this.advancedSearchLink = this.properties.searchLinkToAdvancedResults;
}else{
this.advancedSearchLink = null;
}*/
} }
keywordChanged(){ keywordChanged(){
if(!this.onlyresults) { if(!this.onlyresults) {