1
|
import {Component, Input} from '@angular/core';
|
2
|
import {ActivatedRoute, Router} from '@angular/router';
|
3
|
import {EnvProperties} from "../../utils/properties/env-properties";
|
4
|
import {SearchCustomFilter} from "../../searchPages/searchUtils/searchUtils.class";
|
5
|
|
6
|
@Component({
|
7
|
selector: 'search-bar',
|
8
|
templateUrl: 'searchBar.component.html',
|
9
|
styles:[`
|
10
|
.mat-select-panel-wrap {
|
11
|
z-index: 2001
|
12
|
}
|
13
|
`]
|
14
|
|
15
|
})
|
16
|
export class SearchBarComponent {
|
17
|
|
18
|
@Input() searchRoute: string = "/search/find";
|
19
|
@Input() searchPlaceHolder: string = "Search for research results";
|
20
|
@Input() entitiesSelection:boolean = true;
|
21
|
@Input() properties:EnvProperties;
|
22
|
keyword: string = "";
|
23
|
entityType = "all";
|
24
|
enableSearchbar:boolean = true;
|
25
|
@Input() customFilter: SearchCustomFilter = null;
|
26
|
parameters = {};
|
27
|
constructor(private router: Router,
|
28
|
private route: ActivatedRoute ) {
|
29
|
}
|
30
|
|
31
|
ngOnInit() {
|
32
|
|
33
|
// this.activeRouteEnabled = false;
|
34
|
this.route.queryParams.subscribe(params => {
|
35
|
console.log("Init");
|
36
|
console.log(params);
|
37
|
this.parameters = Object.assign({}, params);
|
38
|
this.entityType = "all";
|
39
|
if (params["type"] && params["type"].length > 0) {
|
40
|
let types= params["type"].split(",");
|
41
|
if(types.length == 1){
|
42
|
if(types.indexOf("publications")!=-1 ){
|
43
|
this.entityType = "publications";
|
44
|
}else if(types.indexOf("datasets")!=-1 ){
|
45
|
this.entityType = "datasets";
|
46
|
}else if(types.indexOf("software")!=-1 ){
|
47
|
this.entityType = "software";
|
48
|
}else if(types.indexOf("other")!=-1 ){
|
49
|
this.entityType = "other";
|
50
|
}
|
51
|
}
|
52
|
}
|
53
|
console.log(this.entityType);
|
54
|
if(this.getCurrentRoute() == "/search/advanced/research-outcomes" ){
|
55
|
this.enableSearchbar = false;
|
56
|
}else{
|
57
|
this.enableSearchbar = true;
|
58
|
}
|
59
|
// this.initialize();
|
60
|
});
|
61
|
|
62
|
}
|
63
|
|
64
|
/*
|
65
|
ngOnDestroy() {
|
66
|
this.sub.unsubscribe();
|
67
|
}
|
68
|
|
69
|
initialize() {
|
70
|
this.activeRouteEnabled = false;
|
71
|
this.isAuthorized = Session.isClaimsCurator(this.user) || Session.isPortalAdministrator(this.user);
|
72
|
/!*if (this.properties.adminToolsAPIURL && this.communityId) {
|
73
|
this.config.getCommunityInformation(this.properties, this.communityId).subscribe(data => {
|
74
|
for (var i = 0; i < data['entities'].length; i++) {
|
75
|
|
76
|
this.showEntity["" + data['entities'][i]["pid"] + ""] = data['entities'][i]["isEnabled"];
|
77
|
}
|
78
|
for (var i = 0; i < data['pages'].length; i++) {
|
79
|
this.showPage[data['pages'][i]["route"]] = data['pages'][i]["isEnabled"];
|
80
|
|
81
|
}
|
82
|
|
83
|
},
|
84
|
error => {
|
85
|
this.handleError("Error getting community information (e.g. pages,entities) for community with id: " + this.communityId, error);
|
86
|
});
|
87
|
}*!/
|
88
|
|
89
|
}*/
|
90
|
|
91
|
isEnabled(required, enabled) {
|
92
|
if (!required) {
|
93
|
return true;
|
94
|
}
|
95
|
for (let requiredEntity of required) {
|
96
|
if (typeof enabled[requiredEntity] === "undefined" || enabled[requiredEntity] == false) {
|
97
|
return false;
|
98
|
}
|
99
|
}
|
100
|
return true;
|
101
|
}
|
102
|
|
103
|
|
104
|
|
105
|
private handleError(message: string, error) {
|
106
|
console.error("NavigationBar (component): " + message, error);
|
107
|
}
|
108
|
|
109
|
getCurrentRoute() {
|
110
|
console.log(this.router.url.split('?')[0]);
|
111
|
return this.router.url.split('?')[0];
|
112
|
}
|
113
|
entityChanged($event){
|
114
|
this.entityType = $event.entity;
|
115
|
this.searchRoute = $event.simpleUrl;
|
116
|
|
117
|
// this.selectedEntityAdvancedUrl = $event.advancedUrl;
|
118
|
// check if it is search or not
|
119
|
//no search page
|
120
|
|
121
|
}
|
122
|
keywordChanged(){
|
123
|
// this.parameters = {};
|
124
|
if ( this.keyword.length > 0) {
|
125
|
this.parameters["fv0"] = this.keyword;
|
126
|
this.parameters["f0"] = "q";
|
127
|
}else{
|
128
|
delete this.parameters['fv0'];
|
129
|
delete this.parameters['f0'];
|
130
|
}
|
131
|
if(this.entityType != "all"){
|
132
|
this.parameters["type"] = this.entityType;
|
133
|
}else{
|
134
|
delete this.parameters['type'];
|
135
|
}
|
136
|
//set true only if it is not set allready
|
137
|
if(!this.parameters["qf"]) {
|
138
|
this.parameters["qf"] = true;
|
139
|
}
|
140
|
console.log(this.parameters);
|
141
|
this.router.navigate([this.searchRoute], {queryParams: this.parameters} );
|
142
|
}
|
143
|
}
|