import {ChangeDetectorRef, Component, EventEmitter, Input, Output} from '@angular/core'; import {FormBuilder} from "@angular/forms"; import {Filter} from "./searchHelperClasses.class"; import {EnvProperties} from "../../utils/properties/env-properties"; import {ConfigurationService} from "../../utils/configuration/configuration.service"; import {Subscription} from "rxjs"; import {ActivatedRoute, Router} from "@angular/router"; @Component({ selector: 'quick-selections', template: `
{{quickFilter.value}}
Include: {{value.name}}
` }) export class QuickSelectionsComponent { @Input() resultTypes:Filter; @Output() typeChange = new EventEmitter(); @Input() isDisabled; @Input() quickFilter: { filter: Filter, selected: boolean, filterId: string, value: string }; initialized = false; @Input() properties: EnvProperties; @Input() vertical: boolean=false; showPublications:boolean= false; showDatasets:boolean= false; showSoftware: boolean = false; showOrp: boolean = false; showEntities = false; @Input() actionRoute:boolean = false; queryParams = {}; subs: Subscription[] = []; constructor(private _fb: FormBuilder, private config: ConfigurationService, private _router: Router, private route: ActivatedRoute, private cdr:ChangeDetectorRef) { } changed() { this.typeChange.emit({}); } quickFilterChanged() { if(this.quickFilter.filter) { this.quickFilter.filter.countSelectedValues = 0; if (this.quickFilter.selected) { for (let filterValue of this.quickFilter.filter.values) { if((filterValue.name == this.quickFilter.value)) { filterValue.selected = true this.quickFilter.filter.countSelectedValues = 1; }else{ filterValue.selected = false; } } } else { for (let filterValue of this.quickFilter.filter.values) { filterValue.selected = false; } } } this.typeChange.emit({}); } ngOnInit() { this.route.queryParams.subscribe(params => { this.queryParams = Object.assign({}, params); this.initializeFilters(); }); if(this.properties && !this.initialized) { if(this.properties.adminToolsCommunity !== "monitor") { this.subs.push(this.config.communityInformationState.subscribe(data => { if(data) { var showEntity = {}; for (var i = 0; i < data['entities'].length; i++) { showEntity["" + data['entities'][i]["pid"] + ""] = data['entities'][i]["isEnabled"]; } this.showPublications = showEntity["publication"]; this.showDatasets = showEntity["dataset"]; this.showSoftware = showEntity["software"]; this.showOrp = showEntity["orp"]; this.showEntities = this.showPublications || this.showDatasets || this.showSoftware || this.showOrp; this.initialized = true; this.initializeFilters(); } }, error => { this.showPublications = true; this.showDatasets = true; this.showSoftware = true; this.showOrp = true; this.showEntities = true; this.initializeFilters(); })); } else { this.showPublications = true; this.showDatasets = true; this.showSoftware = true; this.showOrp = true; this.showEntities = true; this.initialized = true; this.initializeFilters(); } }else{ this.initializeFilters(); } } initializeFilters(){ if(this.showEntities ){ let selected = []; for(let value of this.resultTypes.values){ if(value.selected){ selected.push(value.id); } } this.resultTypes.countSelectedValues = selected.length; this.resultTypes.values = []; if(this.showPublications){ this.resultTypes.values.push({name: "Publications" , id:"publications",selected:selected.indexOf("publications")!=-1, number:0}); } if(this.showDatasets){ this.resultTypes.values.push({name: "Research data" , id:"datasets",selected:selected.indexOf("datasets")!=-1, number:0}); } if(this.showSoftware){ this.resultTypes.values.push({name: "Software" , id:"software",selected:selected.indexOf("software")!=-1, number:0}); } if(this.showOrp){ this.resultTypes.values.push({name: "Other research products" , id:"other",selected:selected.indexOf("other")!=-1, number:0}); } } this.typeChange.emit("filters_update"); } public ngOnDestroy() { for (let sub of this.subs) { sub.unsubscribe(); } } }