196 lines
8.0 KiB
TypeScript
196 lines
8.0 KiB
TypeScript
import {Component, EventEmitter, Input, Output, ViewChild} from '@angular/core';
|
|
import {FormBuilder} from "@angular/forms";
|
|
import {EnvProperties} from "../../utils/properties/env-properties";
|
|
import {SearchCustomFilter} from "./searchUtils.class";
|
|
import {ConfigurationService} from "../../utils/configuration/configuration.service";
|
|
import {Router} from "@angular/router";
|
|
import {LoginErrorCodes} from "../../login/utils/guardHelper.class";
|
|
import {MatSelect} from "@angular/material";
|
|
|
|
@Component({
|
|
selector: 'entities-selection',
|
|
template: `
|
|
<span *ngIf="!disableSelect" class=" entitiesSelection portal-box uk-text-small clickable" style="" (click)="open()" >
|
|
<mat-select *ngIf="show>1 && selectedEntity && !disableSelect && !onlyresults" [(value)]="selectedEntity"
|
|
(valueChange)="entityChanged()" [disableOptionCentering]="true" [panelClass]="matPanelClass" >
|
|
<mat-option
|
|
*ngIf="simpleView && (show)>1 && !(this.customFilter && this.customFilter.queryFieldName=='communityId' )"
|
|
value="all">All content
|
|
</mat-option>
|
|
<mat-option *ngIf="showResearchOutcomes" value="result">Research outcomes</mat-option>
|
|
<mat-option *ngIf="showProjects" value="project">Projects</mat-option>
|
|
<mat-option *ngIf="showDataProviders" value="dataprovider">Content providers</mat-option>
|
|
<mat-option *ngIf="showOrganizations" value="organization">Organizations</mat-option>
|
|
</mat-select>
|
|
<mat-select *ngIf="onlyresults && show>1 && selectedEntity " [(value)]="selectedEntity"
|
|
(valueChange)="entityChanged()" [disableOptionCentering]="true" [panelClass]="matPanelClass" >
|
|
<mat-option
|
|
*ngIf="simpleView && (show)>1 && !(this.customFilter && this.customFilter.queryFieldName=='communityId' )"
|
|
value="all">All research outcomes
|
|
</mat-option>
|
|
<mat-option *ngIf="showPublications" value="publications">Publications</mat-option>
|
|
<mat-option *ngIf="showDatasets" value="datasets">Datasets</mat-option>
|
|
<mat-option *ngIf="showSoftware" value="software">Software</mat-option>
|
|
<mat-option *ngIf="showOther" value="other">Other Research products</mat-option>
|
|
</mat-select>
|
|
|
|
</span>
|
|
<span *ngIf=" currentEntity && disableSelect" class="entitiesSelection portal-box uk-text-small " style="">
|
|
<div>
|
|
<span *ngIf="currentEntity=='all'">{{onlyresults ? 'All research outcomes' : 'All content'}}</span>
|
|
<span *ngIf="currentEntity=='result'">Research outcomes</span>
|
|
<span *ngIf="currentEntity=='project'">Projects</span>
|
|
<span *ngIf="currentEntity=='dataprovider'">Content providers</span>
|
|
<span *ngIf="currentEntity=='organization'">Organizations</span>
|
|
<span *ngIf="currentEntity=='publications'">Publications</span>
|
|
<span *ngIf="currentEntity=='datasets'">Datasets</span>
|
|
<span *ngIf="currentEntity=='software'">Software</span>
|
|
<span *ngIf="currentEntity=='other'">Other Research products</span>
|
|
</div>
|
|
</span>
|
|
<!--<span *ngIf="onlyresults && !disableSelect">
|
|
<select *ngIf="show" [(ngModel)]="selectedEntity" class="uk-select uk-width-auto portal-box uk-text-small" (ngModelChange)="entityChanged()" >
|
|
<option
|
|
*ngIf="simpleView && (show)>1 && !(this.customFilter && this.customFilter.queryFieldName=='communityId' )"
|
|
value="all">All research outcomes
|
|
</option>
|
|
<option *ngIf="showPublications" value="publications">Publications</option>
|
|
<option *ngIf="showDatasets" value="datasets">Datasets</option>
|
|
<option *ngIf="showSoftware" value="software">Software</option>
|
|
<option *ngIf="showOther" value="other">Other Research products</option>
|
|
</select>
|
|
</span>-->
|
|
|
|
|
|
|
|
|
|
`
|
|
})
|
|
|
|
export class EntitiesSelectionComponent {
|
|
|
|
showResearchOutcomes: boolean = false;
|
|
showPublications: boolean = false;
|
|
showDatasets: boolean = false;
|
|
showSoftware: boolean = false;
|
|
showOther: boolean = false;
|
|
showProjects: boolean = false;
|
|
showDataProviders: boolean = false;
|
|
showOrganizations: boolean = false;
|
|
@Input() properties: EnvProperties;
|
|
@Input() customFilter: SearchCustomFilter = null;
|
|
@Input() @Output() selectedEntity = "Research Outcomes";
|
|
@Input() currentEntity = "Research Outcomes";
|
|
@Input() simpleView: boolean = true;
|
|
@Input() onChangeNavigate: boolean = true;
|
|
@Output() selectionChange = new EventEmitter();
|
|
@Input() onlyresults: boolean = false;
|
|
@Input() matPanelClass="matSelectionPanel";
|
|
@Input() disableSelect:boolean=false;
|
|
show = 0;
|
|
@ViewChild(MatSelect)matSelect:MatSelect;
|
|
|
|
constructor(private _fb: FormBuilder, private config: ConfigurationService, private router: Router) {
|
|
|
|
|
|
}
|
|
|
|
|
|
ngOnInit() {
|
|
this.show = 0;
|
|
if (this.properties) {
|
|
// console.log(this.customFilter)
|
|
this.config.getCommunityInformation(this.properties, (this.customFilter && this.customFilter.queryFieldName == "communityId") ? this.customFilter.valueId : this.properties.adminToolsCommunity).subscribe(data => {
|
|
var showEntity = {};
|
|
for (var i = 0; i < data['entities'].length; i++) {
|
|
|
|
showEntity["" + data['entities'][i]["pid"] + ""] = data['entities'][i]["isEnabled"];
|
|
}
|
|
this.showResearchOutcomes = showEntity["publication"] || showEntity["dataset"] || showEntity["software"] || showEntity["orp"];
|
|
this.showPublications = showEntity["publication"];
|
|
this.showDatasets = showEntity["dataset"];
|
|
this.showSoftware = showEntity["software"];
|
|
this.showOther = showEntity["orp"];
|
|
this.showProjects = showEntity["project"];
|
|
this.showOrganizations = showEntity["organization"];
|
|
this.showDataProviders = showEntity["datasource"];
|
|
|
|
if (this.customFilter && this.customFilter.queryFieldName == "communityId") {
|
|
this.showOrganizations = false;
|
|
if(!this.simpleView){
|
|
this.showProjects = false;
|
|
this.showDataProviders = false;
|
|
}
|
|
}
|
|
if(this.showResearchOutcomes){
|
|
this.show++;
|
|
}
|
|
if(this.showDataProviders){
|
|
this.show++;
|
|
}
|
|
if(this.showOrganizations){
|
|
this.show++;
|
|
}
|
|
if(this.showProjects){
|
|
this.show++;
|
|
}
|
|
if(this.show ==1){
|
|
this.disableSelect = true;
|
|
}
|
|
});
|
|
}
|
|
this.selectedEntity = this.currentEntity;
|
|
this.selectionChange.emit({
|
|
entity: this.selectedEntity,
|
|
simpleUrl: this.getUrl(true),
|
|
advancedUrl: this.getUrl(false)
|
|
});
|
|
}
|
|
|
|
|
|
entityChanged() {
|
|
|
|
if (!this.simpleView || this.onChangeNavigate) {
|
|
this.router.navigate([this.getUrl(this.simpleView)]);
|
|
} else {
|
|
this.selectionChange.emit({
|
|
entity: this.selectedEntity,
|
|
simpleUrl: this.getUrl(true),
|
|
advancedUrl: this.getUrl(false)
|
|
});
|
|
}
|
|
|
|
}
|
|
|
|
getUrl(simpleView: boolean) {
|
|
let url = "";
|
|
if(!this.onlyresults) {
|
|
if (this.selectedEntity == "all") {
|
|
url = (simpleView ? "/search/find/" : null);
|
|
} else if (this.selectedEntity == "result") {
|
|
url = (simpleView ? this.properties.searchLinkToResults : this.properties.searchLinkToAdvancedResults);
|
|
} else if (this.selectedEntity == "project") {
|
|
url = (simpleView ? this.properties.searchLinkToProjects : this.properties.searchLinkToAdvancedProjects);
|
|
} else if (this.selectedEntity == "dataprovider") {
|
|
url = (simpleView ? this.properties.searchLinkToDataProviders : this.properties.searchLinkToAdvancedDataProviders);
|
|
} else if (this.selectedEntity == "organization") {
|
|
url = (simpleView ? this.properties.searchLinkToOrganizations : this.properties.searchLinkToAdvancedOrganizations);
|
|
}
|
|
}else{
|
|
url = (simpleView ? this.properties.searchLinkToResults : this.properties.searchLinkToAdvancedResults);
|
|
}
|
|
return url;
|
|
}
|
|
toggle(){
|
|
if(this.matSelect) {
|
|
this.matSelect.toggle();
|
|
}
|
|
}
|
|
open(){
|
|
if(this.matSelect && !this.matSelect.focused) {
|
|
this.matSelect.open();
|
|
}
|
|
}
|
|
|
|
}
|