diff --git a/searchPages/find/searchAll.component.ts b/searchPages/find/searchAll.component.ts index 3d208365..b64cb652 100644 --- a/searchPages/find/searchAll.component.ts +++ b/searchPages/find/searchAll.component.ts @@ -203,39 +203,59 @@ export class SearchAllComponent { loadAll() { this.reloadTabs(); - this.subs.push(this.route.queryParams.subscribe(params => { - this.parameters = Object.assign({}, params); - this.keyword = (params['keyword']) ? params['keyword'] : (params["q"] ? params["q"] : (params["f0"] && params["f0"] == "q" && params["fv0"]?params["fv0"]:"")); + this.subs.push(this.route.queryParams.subscribe(queryParams => { + this.parameters = Object.assign({}, queryParams); + this.keyword = (queryParams['keyword']) ? queryParams['keyword'] : (queryParams["q"] ? queryParams["q"] : (queryParams["f0"] && queryParams["f0"] == "q" && queryParams["fv0"]?queryParams["fv0"]:"")); this.selectedFields[0].value = StringUtils.URIDecode(this.keyword); - this.quickFilter.selected = ((params['qf']== undefined || params["qf"] == "true") == true); - if (params["type"] && params["type"].length > 0) { - this.resultTypes['publication'] = (params["type"].split(",").indexOf("publications") != -1); - this.resultTypes['dataset'] = (params["type"].split(",").indexOf("datasets") != -1); - this.resultTypes['software'] = (params["type"].split(",").indexOf("software") != -1); - this.resultTypes['other'] = (params["type"].split(",").indexOf("other") != -1); + this.quickFilter.selected = ((queryParams['qf']== undefined || queryParams["qf"] == "true") == true); + if (queryParams["type"] && queryParams["type"].length > 0) { + this.resultTypes['publication'] = (queryParams["type"].split(",").indexOf("publications") != -1); + this.resultTypes['dataset'] = (queryParams["type"].split(",").indexOf("datasets") != -1); + this.resultTypes['software'] = (queryParams["type"].split(",").indexOf("software") != -1); + this.resultTypes['other'] = (queryParams["type"].split(",").indexOf("other") != -1); } - if(this.activeEntity == null && (!params["active"] || params["active"].length ==0)){ - this.activeEntity = this.getDefaultEntityToShow(); - }else if(params["active"] && params["active"].length >0 ){ - this.activeEntity = ((["result","projects","organizations","datasources","services"]).indexOf(params["active"])!= -1)?params["active"]:this.getDefaultEntityToShow(); - }else if (this.activeEntity !=null && (!params["active"] || params["active"].length ==0)){ - this.parameters["active"]=this.activeEntity; - if((typeof document !== 'undefined') && location.search && location.search.indexOf("active=") == -1){ - this.location.go(location.pathname, ((location.search)?(location.search+"&"):("?")) +"active=" + this.activeEntity); + let active = null; + if (queryParams["active"] && queryParams["active"].length > 0) { + active = ((["result","projects","organizations","datasources","services"]).indexOf(queryParams["active"])!= -1)?queryParams["active"]:null; + } + this.subs.push(this.route.params.subscribe(params => { + if(this.activeEntity == null && (!params["entity"] || params["entity"].length == 0)){ + if (active) { + this.activeEntity = active; + // if((typeof document !== 'undefined')){ + // if (active == "result") { + // active = "research-outcomes"; + // } + // console.log(location.search); + // let query = location.search.replace(/((active=).*&)|((active=).*)/, ''); + // console.log(query); + // this.location.go(location.pathname + '/' + active, query == '?' ? '' : query); + // } + } else { + this.activeEntity = this.getDefaultEntityToShow(); + } + } else if(params["entity"] && params["entity"].length > 0 ){ + let entity = params["entity"]; + if(entity == "research-outcomes") { + entity = "result"; + } else if (entity == "dataproviders") { + entity = "datasources"; + } + this.activeEntity = ((["result","projects","organizations","datasources","services"]).indexOf(entity)!= -1)?entity:this.getDefaultEntityToShow(); } - } - if (this.activeEntity == "result") { - this.searchResults(); - } else if (this.activeEntity == "projects") { - this.searchProjects(); - } else if (this.activeEntity == "datasources") { - this.searchDataProviders(); - } else if (this.activeEntity == "services") { - this.searchServices(); - } else if (this.activeEntity == "organizations") { - this.searchOrganizations(); - } - this.count(); + if (this.activeEntity == "result") { + this.searchResults(); + } else if (this.activeEntity == "projects") { + this.searchProjects(); + } else if (this.activeEntity == "datasources") { + this.searchDataProviders(); + } else if (this.activeEntity == "services") { + this.searchServices(); + } else if (this.activeEntity == "organizations") { + this.searchOrganizations(); + } + this.count(); + })); })); } @@ -549,9 +569,8 @@ export class SearchAllComponent { this.searchOrganizationsComponent.ngOnDestroy(); } this.activeEntity = entity; - this.parameters = {}; - this.reload[entity]= true; - this.parameters["active"] = entity; + this.parameters = {}; + this.reload[entity]= true; if ( this.keyword.length > 0) { this.parameters["fv0"] = this.keyword; this.parameters["f0"] = "q"; @@ -559,7 +578,11 @@ export class SearchAllComponent { if(this.customFilter){ this.parameters = this.customFilter.getParameters(this.parameters); } - this.router.navigate(["/search/find"], {queryParams: this.parameters}); + if (entity == "result") { + entity = "research-outcomes"; + this.parameters["resultbestaccessright"] = '"' + encodeURIComponent("Open Access") + '"'; + } + this.router.navigate(["/search/find", entity], {queryParams: this.parameters}); } }