1
|
import {Component, EventEmitter, Input, Output, ViewChild} from '@angular/core';
|
2
|
import {FormBuilder} from "@angular/forms";
|
3
|
import {EnvProperties} from "../../utils/properties/env-properties";
|
4
|
import {SearchCustomFilter} from "./searchUtils.class";
|
5
|
import {ConfigurationService} from "../../utils/configuration/configuration.service";
|
6
|
import {Router} from "@angular/router";
|
7
|
import {LoginErrorCodes} from "../../login/utils/guardHelper.class";
|
8
|
import {MatSelect} from "@angular/material";
|
9
|
|
10
|
@Component({
|
11
|
selector: 'entities-selection',
|
12
|
template: `
|
13
|
<span *ngIf="!disableSelect" class=" entitiesSelection portal-box uk-text-small clickable" style="" (click)="open()" >
|
14
|
<mat-select *ngIf="show>1 && selectedEntity && !disableSelect && !onlyresults" [(value)]="selectedEntity"
|
15
|
(valueChange)="entityChanged()" [disableOptionCentering]="true" [panelClass]="matPanelClass" >
|
16
|
<mat-option
|
17
|
*ngIf="simpleView && (show)>1 && !(this.customFilter && this.customFilter.queryFieldName=='communityId' )"
|
18
|
value="all">All content
|
19
|
</mat-option>
|
20
|
<mat-option *ngIf="showResearchOutcomes" value="result">Research outcomes</mat-option>
|
21
|
<mat-option *ngIf="showProjects" value="project">Projects</mat-option>
|
22
|
<mat-option *ngIf="showDataProviders" value="dataprovider">Content providers</mat-option>
|
23
|
<mat-option *ngIf="showOrganizations" value="organization">Organizations</mat-option>
|
24
|
</mat-select>
|
25
|
<mat-select *ngIf="onlyresults && show>1 && selectedEntity " [(value)]="selectedEntity"
|
26
|
(valueChange)="entityChanged()" [disableOptionCentering]="true" [panelClass]="matPanelClass" >
|
27
|
<mat-option
|
28
|
*ngIf="simpleView && (show)>1 && !(this.customFilter && this.customFilter.queryFieldName=='communityId' )"
|
29
|
value="all">All research outcomes
|
30
|
</mat-option>
|
31
|
<mat-option *ngIf="showPublications" value="publications">Publications</mat-option>
|
32
|
<mat-option *ngIf="showDatasets" value="datasets">Datasets</mat-option>
|
33
|
<mat-option *ngIf="showSoftware" value="software">Software</mat-option>
|
34
|
<mat-option *ngIf="showOther" value="other">Other Research products</mat-option>
|
35
|
</mat-select>
|
36
|
|
37
|
</span>
|
38
|
<span *ngIf=" currentEntity && disableSelect" class="entitiesSelection portal-box uk-text-small " style="">
|
39
|
<div>
|
40
|
<span *ngIf="currentEntity=='all'">{{onlyresults ? 'All research outcomes' : 'All content'}}</span>
|
41
|
<span *ngIf="currentEntity=='result'">Research outcomes</span>
|
42
|
<span *ngIf="currentEntity=='project'">Projects</span>
|
43
|
<span *ngIf="currentEntity=='dataprovider'">Content providers</span>
|
44
|
<span *ngIf="currentEntity=='organization'">Organizations</span>
|
45
|
<span *ngIf="currentEntity=='publications'">Publications</span>
|
46
|
<span *ngIf="currentEntity=='datasets'">Datasets</span>
|
47
|
<span *ngIf="currentEntity=='software'">Software</span>
|
48
|
<span *ngIf="currentEntity=='other'">Other Research products</span>
|
49
|
</div>
|
50
|
</span>
|
51
|
<!--<span *ngIf="onlyresults && !disableSelect">
|
52
|
<select *ngIf="show" [(ngModel)]="selectedEntity" class="uk-select uk-width-auto portal-box uk-text-small" (ngModelChange)="entityChanged()" >
|
53
|
<option
|
54
|
*ngIf="simpleView && (show)>1 && !(this.customFilter && this.customFilter.queryFieldName=='communityId' )"
|
55
|
value="all">All research outcomes
|
56
|
</option>
|
57
|
<option *ngIf="showPublications" value="publications">Publications</option>
|
58
|
<option *ngIf="showDatasets" value="datasets">Datasets</option>
|
59
|
<option *ngIf="showSoftware" value="software">Software</option>
|
60
|
<option *ngIf="showOther" value="other">Other Research products</option>
|
61
|
</select>
|
62
|
</span>-->
|
63
|
|
64
|
|
65
|
|
66
|
|
67
|
`
|
68
|
})
|
69
|
|
70
|
export class EntitiesSelectionComponent {
|
71
|
|
72
|
showResearchOutcomes: boolean = false;
|
73
|
showPublications: boolean = false;
|
74
|
showDatasets: boolean = false;
|
75
|
showSoftware: boolean = false;
|
76
|
showOther: boolean = false;
|
77
|
showProjects: boolean = false;
|
78
|
showDataProviders: boolean = false;
|
79
|
showOrganizations: boolean = false;
|
80
|
@Input() properties: EnvProperties;
|
81
|
@Input() customFilter: SearchCustomFilter = null;
|
82
|
@Input() @Output() selectedEntity = "Research Outcomes";
|
83
|
@Input() currentEntity = "Research Outcomes";
|
84
|
@Input() simpleView: boolean = true;
|
85
|
@Input() onChangeNavigate: boolean = true;
|
86
|
@Output() selectionChange = new EventEmitter();
|
87
|
@Input() onlyresults: boolean = false;
|
88
|
@Input() matPanelClass="matSelectionPanel";
|
89
|
@Input() disableSelect:boolean=false;
|
90
|
show = 0;
|
91
|
@ViewChild(MatSelect)matSelect:MatSelect;
|
92
|
|
93
|
constructor(private _fb: FormBuilder, private config: ConfigurationService, private router: Router) {
|
94
|
|
95
|
|
96
|
}
|
97
|
|
98
|
|
99
|
ngOnInit() {
|
100
|
this.show = 0;
|
101
|
if (this.properties) {
|
102
|
// console.log(this.customFilter)
|
103
|
this.config.getCommunityInformation(this.properties, (this.customFilter && this.customFilter.queryFieldName == "communityId") ? this.customFilter.valueId : this.properties.adminToolsCommunity).subscribe(data => {
|
104
|
let showEntity = {};
|
105
|
let showPage = {};
|
106
|
for (let i = 0; i < data['entities'].length; i++) {
|
107
|
|
108
|
showEntity["" + data['entities'][i]["pid"] + ""] = data['entities'][i]["isEnabled"];
|
109
|
}
|
110
|
for (let i = 0; i < data['pages'].length; i++) {
|
111
|
showPage["" + data['pages'][i]["route"] + ""] = data['pages'][i]["isEnabled"];
|
112
|
}
|
113
|
this.showResearchOutcomes = showPage[this.properties.searchLinkToResults] && (showEntity["publication"] || showEntity["dataset"] || showEntity["software"] || showEntity["orp"]);
|
114
|
this.showPublications = showPage[this.properties.searchLinkToResults] && showEntity["publication"];
|
115
|
this.showDatasets = showPage[this.properties.searchLinkToResults] && showEntity["dataset"];
|
116
|
this.showSoftware = showPage[this.properties.searchLinkToResults] && showEntity["software"];
|
117
|
this.showOther = showPage[this.properties.searchLinkToResults] && showEntity["orp"];
|
118
|
this.showProjects = showPage[this.properties.searchLinkToProjects] && showEntity["project"];
|
119
|
this.showOrganizations = showPage[this.properties.searchLinkToOrganizations] && showEntity["organization"];
|
120
|
this.showDataProviders = showPage[this.properties.searchLinkToDataProviders] && showEntity["datasource"];
|
121
|
|
122
|
if (this.customFilter && this.customFilter.queryFieldName == "communityId") {
|
123
|
this.showOrganizations = false;
|
124
|
if(!this.simpleView){
|
125
|
this.showProjects = false;
|
126
|
this.showDataProviders = false;
|
127
|
}
|
128
|
}
|
129
|
if(this.showResearchOutcomes){
|
130
|
this.show++;
|
131
|
}
|
132
|
if(this.showDataProviders){
|
133
|
this.show++;
|
134
|
}
|
135
|
if(this.showOrganizations){
|
136
|
this.show++;
|
137
|
}
|
138
|
if(this.showProjects){
|
139
|
this.show++;
|
140
|
}
|
141
|
if(this.show ==1){
|
142
|
this.disableSelect = true;
|
143
|
}
|
144
|
});
|
145
|
}
|
146
|
this.selectedEntity = this.currentEntity;
|
147
|
this.selectionChange.emit({
|
148
|
entity: this.selectedEntity,
|
149
|
simpleUrl: this.getUrl(true),
|
150
|
advancedUrl: this.getUrl(false)
|
151
|
});
|
152
|
}
|
153
|
|
154
|
|
155
|
entityChanged() {
|
156
|
|
157
|
if (!this.simpleView || this.onChangeNavigate) {
|
158
|
this.router.navigate([this.getUrl(this.simpleView)]);
|
159
|
} else {
|
160
|
this.selectionChange.emit({
|
161
|
entity: this.selectedEntity,
|
162
|
simpleUrl: this.getUrl(true),
|
163
|
advancedUrl: this.getUrl(false)
|
164
|
});
|
165
|
}
|
166
|
|
167
|
}
|
168
|
|
169
|
getUrl(simpleView: boolean) {
|
170
|
let url = "";
|
171
|
if(!this.onlyresults) {
|
172
|
if (this.selectedEntity == "all") {
|
173
|
url = (simpleView ? "/search/find/" : null);
|
174
|
} else if (this.selectedEntity == "result") {
|
175
|
url = (simpleView ? this.properties.searchLinkToResults : this.properties.searchLinkToAdvancedResults);
|
176
|
} else if (this.selectedEntity == "project") {
|
177
|
url = (simpleView ? this.properties.searchLinkToProjects : this.properties.searchLinkToAdvancedProjects);
|
178
|
} else if (this.selectedEntity == "dataprovider") {
|
179
|
url = (simpleView ? this.properties.searchLinkToDataProviders : this.properties.searchLinkToAdvancedDataProviders);
|
180
|
} else if (this.selectedEntity == "organization") {
|
181
|
url = (simpleView ? this.properties.searchLinkToOrganizations : this.properties.searchLinkToAdvancedOrganizations);
|
182
|
}
|
183
|
}else{
|
184
|
url = (simpleView ? this.properties.searchLinkToResults : this.properties.searchLinkToAdvancedResults);
|
185
|
}
|
186
|
return url;
|
187
|
}
|
188
|
toggle(){
|
189
|
if(this.matSelect) {
|
190
|
this.matSelect.toggle();
|
191
|
}
|
192
|
}
|
193
|
open(){
|
194
|
if(this.matSelect && !this.matSelect.focused) {
|
195
|
this.matSelect.open();
|
196
|
}
|
197
|
}
|
198
|
|
199
|
}
|