openaire-library/searchPages/searchUtils/entitiesSelection.component.ts

105 lines
4.4 KiB
TypeScript
Raw Normal View History

import {Component, EventEmitter, Input, OnChanges, Output, SimpleChanges} 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 {RouterHelper} from "../../utils/routerHelper.class";
import {Router} from "@angular/router";
@Component({
selector: 'entities-selection',
template: `
<select *ngIf="show" [(ngModel)]="selectedEntity" class="uk-select uk-width-auto portal-box uk-text-small" (ngModelChange)="entityChanged()" >
<option *ngIf="simpleView && (showResearchOutcomes + showDataProviders + showOrganizations + showProjects )>1 " value="all">All content</option>
<option *ngIf="showResearchOutcomes" value="result">Research outcomes</option>
<option *ngIf="showProjects" value="project">Projects</option>
<option *ngIf="showDataProviders" value="content provider">Content providers</option>
<option *ngIf="showOrganizations" value="organization">Organizations</option>
</select>
<button *ngIf="!show && currentEntity" class="uk-select uk-width-auto portal-box uk-text-small">
<span *ngIf="currentEntity=='all'">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>
</button>
`
})
export class EntitiesSelectionComponent {
showResearchOutcomes: 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();
show = false;
constructor(private _fb: FormBuilder, private config: ConfigurationService, private router: Router) {
}
ngOnInit() {
if(this.properties) {
this.config.getCommunityInformation(this.properties, (this.customFilter && this.customFilter.queryFieldName == "communitId") ? 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.showProjects = showEntity["project"];
this.showOrganizations = showEntity["organization"];
this.showDataProviders = showEntity["datasource"];
if (this.customFilter && this.customFilter.queryFieldName == "communityId") {
this.showProjects = false;
this.showOrganizations = false;
this.showDataProviders = false;
}
this.show = true;
});
}
this.selectedEntity = this.currentEntity;
this.selectionChange.emit({entity:this.selectedEntity, simpleUrl:this.getUrl(true) , advancedUrl:this.getUrl(false)});
}
entityChanged(){
if(!this.simpleView){
this.router.navigate([this.getUrl(false)]);
}else{
this.selectionChange.emit({entity:this.selectedEntity, simpleUrl:this.getUrl(true) , advancedUrl:this.getUrl(false)});
}
}
getUrl(simpleView:boolean){
let url = "";
if(this.selectedEntity == "all"){
url = "/search/find/";
}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 == "content provider"){
url = (simpleView?this.properties.searchLinkToDataProviders:this.properties.searchLinkToAdvancedDataProviders);
}else if(this.selectedEntity == "organization"){
url = (simpleView?this.properties.searchLinkToOrganizations:this.properties.searchLinkToAdvancedOrganizations);
}
return url;
}
}