[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:
parent
0b5cf0f6f8
commit
b35ebb80fc
|
@ -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,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) {
|
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) {
|
||||||
|
|
Loading…
Reference in New Issue