From b35ebb80fc2a2c995073d11d473862d5392670c6 Mon Sep 17 00:00:00 2001 From: "argiro.kokogiannaki" Date: Thu, 30 Apr 2020 09:23:30 +0000 Subject: [PATCH] [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 --- .../searchBar/searchBar.component.ts | 67 ++++++++++--------- 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/sharedComponents/searchBar/searchBar.component.ts b/sharedComponents/searchBar/searchBar.component.ts index 613badcb..aef7222a 100644 --- a/sharedComponents/searchBar/searchBar.component.ts +++ b/sharedComponents/searchBar/searchBar.component.ts @@ -1,5 +1,5 @@ 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 {SearchCustomFilter} from "../../searchPages/searchUtils/searchUtils.class"; @@ -24,6 +24,12 @@ export class SearchBarComponent { advancedSearchLink = null; constructor(private router: Router, private route: ActivatedRoute ) { + this.router.events.subscribe((e) => { + if(e instanceof NavigationEnd){ + // console.log(e) + this.initialize(); + } + }); } ngOnInit() { @@ -32,9 +38,9 @@ export class SearchBarComponent { if(this.communityId){ this.customFilter = new SearchCustomFilter("Community", "communityId", this.communityId, ""); } + this.entityType = "all"; this.route.queryParams.subscribe(params => { this.parameters = Object.assign({}, params); - this.entityType = "all"; if(this.onlyresults) { if (params["type"] && params["type"].length > 0) { let types = params["type"].split(","); @@ -50,32 +56,37 @@ export class SearchBarComponent { } } } - }else{ - let currentRoute= this.getCurrentRoute(); - if(currentRoute== this.properties.searchLinkToProjects){ - this.entityType = "project"; - }else if(currentRoute== this.properties.searchLinkToDataProviders){ - this.entityType = "dataprovider"; - }else if(currentRoute== this.properties.searchLinkToOrganizations){ - this.entityType = "organization"; - }else{ - this.entityType = "result"; - } - } - if(this.getCurrentRoute() == this.properties.searchLinkToAdvancedResults){ - this.enableSearchbar = false; - }else{ - this.enableSearchbar = true; - } - if(this.getCurrentRoute() == this.properties.searchLinkToResults){ - this.advancedSearchLink = this.properties.searchLinkToAdvancedResults; - }else{ - this.advancedSearchLink = null; } }); - + this.initialize() + } + initialize(){ + if(!this.onlyresults){ + let currentRoute= this.getCurrentRoute(); + if(currentRoute== this.properties.searchLinkToProjects){ + this.entityType = "project"; + }else if(currentRoute== this.properties.searchLinkToDataProviders){ + this.entityType = "dataprovider"; + }else if(currentRoute== this.properties.searchLinkToOrganizations){ + this.entityType = "organization"; + }else{ + this.entityType = "result"; + } + } + if(this.getCurrentRoute() == this.properties.searchLinkToAdvancedResults){ + this.enableSearchbar = false; + }else{ + this.enableSearchbar = true; + } + this.showAdvancedLink(); + } + showAdvancedLink(){ + if(this.getCurrentRoute() == this.properties.searchLinkToResults && this.entityType == "result"){ + this.advancedSearchLink = this.properties.searchLinkToAdvancedResults; + }else{ + this.advancedSearchLink = null; + } } - isEnabled(required, enabled) { if (!required) { return true; @@ -96,11 +107,7 @@ export class SearchBarComponent { if(!this.onlyresults && this.entityType == "result") { this.parameters["qf"] = true; } -/* if(this.entityType == "result"){ - this.advancedSearchLink = this.properties.searchLinkToAdvancedResults; - }else{ - this.advancedSearchLink = null; - }*/ + this.showAdvancedLink(); } keywordChanged(){ if(!this.onlyresults) {