143 lines
4.1 KiB
TypeScript
143 lines
4.1 KiB
TypeScript
import {Component, Input} from '@angular/core';
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
|
import {EnvProperties} from "../../utils/properties/env-properties";
|
|
import {SearchCustomFilter} from "../../searchPages/searchUtils/searchUtils.class";
|
|
|
|
@Component({
|
|
selector: 'search-bar',
|
|
templateUrl: 'searchBar.component.html',
|
|
styles:[`
|
|
.mat-select-panel-wrap {
|
|
z-index: 2001
|
|
}
|
|
`]
|
|
|
|
})
|
|
export class SearchBarComponent {
|
|
|
|
@Input() searchRoute: string = "/search/find";
|
|
@Input() searchPlaceHolder: string = "Search for research results";
|
|
@Input() entitiesSelection:boolean = true;
|
|
@Input() properties:EnvProperties;
|
|
keyword: string = "";
|
|
entityType = "all";
|
|
enableSearchbar:boolean = true;
|
|
@Input() customFilter: SearchCustomFilter = null;
|
|
parameters = {};
|
|
constructor(private router: Router,
|
|
private route: ActivatedRoute ) {
|
|
}
|
|
|
|
ngOnInit() {
|
|
|
|
// this.activeRouteEnabled = false;
|
|
this.route.queryParams.subscribe(params => {
|
|
console.log("Init");
|
|
console.log(params);
|
|
this.parameters = Object.assign({}, params);
|
|
this.entityType = "all";
|
|
if (params["type"] && params["type"].length > 0) {
|
|
let types= params["type"].split(",");
|
|
if(types.length == 1){
|
|
if(types.indexOf("publications")!=-1 ){
|
|
this.entityType = "publications";
|
|
}else if(types.indexOf("datasets")!=-1 ){
|
|
this.entityType = "datasets";
|
|
}else if(types.indexOf("software")!=-1 ){
|
|
this.entityType = "software";
|
|
}else if(types.indexOf("other")!=-1 ){
|
|
this.entityType = "other";
|
|
}
|
|
}
|
|
}
|
|
console.log(this.entityType);
|
|
if(this.getCurrentRoute() == "/search/advanced/research-outcomes" ){
|
|
this.enableSearchbar = false;
|
|
}else{
|
|
this.enableSearchbar = true;
|
|
}
|
|
// this.initialize();
|
|
});
|
|
|
|
}
|
|
|
|
/*
|
|
ngOnDestroy() {
|
|
this.sub.unsubscribe();
|
|
}
|
|
|
|
initialize() {
|
|
this.activeRouteEnabled = false;
|
|
this.isAuthorized = Session.isClaimsCurator(this.user) || Session.isPortalAdministrator(this.user);
|
|
/!*if (this.properties.adminToolsAPIURL && this.communityId) {
|
|
this.config.getCommunityInformation(this.properties, this.communityId).subscribe(data => {
|
|
for (var i = 0; i < data['entities'].length; i++) {
|
|
|
|
this.showEntity["" + data['entities'][i]["pid"] + ""] = data['entities'][i]["isEnabled"];
|
|
}
|
|
for (var i = 0; i < data['pages'].length; i++) {
|
|
this.showPage[data['pages'][i]["route"]] = data['pages'][i]["isEnabled"];
|
|
|
|
}
|
|
|
|
},
|
|
error => {
|
|
this.handleError("Error getting community information (e.g. pages,entities) for community with id: " + this.communityId, error);
|
|
});
|
|
}*!/
|
|
|
|
}*/
|
|
|
|
isEnabled(required, enabled) {
|
|
if (!required) {
|
|
return true;
|
|
}
|
|
for (let requiredEntity of required) {
|
|
if (typeof enabled[requiredEntity] === "undefined" || enabled[requiredEntity] == false) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
private handleError(message: string, error) {
|
|
console.error("NavigationBar (component): " + message, error);
|
|
}
|
|
|
|
getCurrentRoute() {
|
|
return this.router.url.split('?')[0];
|
|
}
|
|
entityChanged($event){
|
|
this.entityType = $event.entity;
|
|
this.searchRoute = $event.simpleUrl;
|
|
|
|
// this.selectedEntityAdvancedUrl = $event.advancedUrl;
|
|
// check if it is search or not
|
|
//no search page
|
|
|
|
}
|
|
keywordChanged(){
|
|
// this.parameters = {};
|
|
if ( this.keyword.length > 0) {
|
|
this.parameters["fv0"] = this.keyword;
|
|
this.parameters["f0"] = "q";
|
|
}else{
|
|
delete this.parameters['fv0'];
|
|
delete this.parameters['f0'];
|
|
}
|
|
if(this.entityType != "all"){
|
|
this.parameters["type"] = this.entityType;
|
|
}else{
|
|
delete this.parameters['type'];
|
|
}
|
|
//set true only if it is not set allready
|
|
if(!this.parameters["qf"]) {
|
|
this.parameters["qf"] = true;
|
|
}
|
|
console.log(this.parameters);
|
|
this.router.navigate([this.searchRoute], {queryParams: this.parameters} );
|
|
}
|
|
}
|