2020-10-20 11:11:15 +02:00
|
|
|
import {ChangeDetectorRef, Component, EventEmitter, Input, Output} from '@angular/core';
|
|
|
|
import {FormBuilder} from "@angular/forms";
|
2020-02-11 12:58:51 +01:00
|
|
|
import {Filter} from "./searchHelperClasses.class";
|
2020-02-13 15:44:51 +01:00
|
|
|
import {EnvProperties} from "../../utils/properties/env-properties";
|
|
|
|
import {ConfigurationService} from "../../utils/configuration/configuration.service";
|
2020-10-20 11:11:15 +02:00
|
|
|
import {Subscription} from "rxjs";
|
|
|
|
import {ActivatedRoute, Router} from "@angular/router";
|
2020-02-11 12:58:51 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'quick-selections',
|
|
|
|
template: `
|
2020-10-20 11:11:15 +02:00
|
|
|
<div *ngIf="!vertical && (resultTypes || quickFilter)"
|
2020-07-13 00:19:30 +02:00
|
|
|
[class]="(isDisabled ? 'uk-disabled' : '') + ' uk-text-small uk-margin-small-bottom uk-grid uk-inline uk-flex uk-margin-small-left'">
|
2020-04-23 09:33:23 +02:00
|
|
|
<div *ngIf="quickFilter" class="uk-margin-small-top uk-padding-remove-left uk-margin-right ">
|
2020-02-13 15:44:51 +01:00
|
|
|
<span class="uk-text-bold">{{quickFilter.value}}</span>
|
|
|
|
<mat-slide-toggle
|
2020-10-20 11:11:15 +02:00
|
|
|
class="uk-margin-small-left" name="qf" [(ngModel)]="quickFilter.selected" (ngModelChange)="quickFilterChanged()">
|
2020-02-11 12:58:51 +01:00
|
|
|
</mat-slide-toggle>
|
|
|
|
</div>
|
2020-04-23 09:33:23 +02:00
|
|
|
<div *ngIf="resultTypes && showEntities" class="uk-margin-small-top uk-padding-remove-left">
|
2020-02-13 15:44:51 +01:00
|
|
|
<span class="uk-text-muted">Include: </span>
|
2020-04-23 09:33:23 +02:00
|
|
|
<span>
|
2020-10-20 11:11:15 +02:00
|
|
|
<ng-container *ngFor="let value of resultTypes.values">
|
2020-11-24 09:53:22 +01:00
|
|
|
<span class="uk-margin-small-left">
|
|
|
|
<input #input type="checkbox" class="uk-checkbox" [(ngModel)]="value.selected" (ngModelChange)="changed()"/>
|
|
|
|
<span class="space clickable" (click)="input.click()">{{value.name}}</span>
|
|
|
|
</span>
|
2020-10-20 11:11:15 +02:00
|
|
|
</ng-container>
|
2020-04-23 09:33:23 +02:00
|
|
|
</span>
|
2020-02-13 15:44:51 +01:00
|
|
|
</div>
|
2020-10-20 11:11:15 +02:00
|
|
|
</div>
|
|
|
|
<div *ngIf="vertical && (resultTypes || quickFilter)"
|
2020-07-13 00:19:30 +02:00
|
|
|
[class]="(isDisabled ? 'uk-disabled' : '') + ' uk-margin-small-bottom uk-list uk-list-divider'">
|
2020-10-20 11:11:15 +02:00
|
|
|
<search-filter
|
|
|
|
[isDisabled]="isDisabled"
|
|
|
|
[filter]="resultTypes" [showResultCount]='false'
|
|
|
|
(onFilterChange)="changed()" [actionRoute]="actionRoute"></search-filter>
|
|
|
|
</div>
|
|
|
|
|
2020-02-11 12:58:51 +01:00
|
|
|
`
|
|
|
|
})
|
|
|
|
|
2020-10-20 11:11:15 +02:00
|
|
|
export class QuickSelectionsComponent {
|
|
|
|
@Input() resultTypes:Filter;
|
2020-02-11 12:58:51 +01:00
|
|
|
@Output() typeChange = new EventEmitter();
|
|
|
|
@Input() isDisabled;
|
|
|
|
@Input() quickFilter: { filter: Filter, selected: boolean, filterId: string, value: string };
|
|
|
|
initialized = false;
|
2020-02-13 15:44:51 +01:00
|
|
|
@Input() properties: EnvProperties;
|
2020-06-01 11:02:16 +02:00
|
|
|
@Input() vertical: boolean=false;
|
2020-02-13 15:44:51 +01:00
|
|
|
showPublications:boolean= false;
|
|
|
|
showDatasets:boolean= false;
|
|
|
|
showSoftware: boolean = false;
|
|
|
|
showOrp: boolean = false;
|
|
|
|
showEntities = false;
|
2020-10-20 11:11:15 +02:00
|
|
|
@Input() actionRoute:boolean = false;
|
|
|
|
queryParams = {};
|
2020-07-13 00:19:30 +02:00
|
|
|
|
|
|
|
subs: Subscription[] = [];
|
|
|
|
|
2020-10-20 11:11:15 +02:00
|
|
|
constructor(private _fb: FormBuilder, private config: ConfigurationService, private _router: Router, private route: ActivatedRoute, private cdr:ChangeDetectorRef) {
|
2020-02-11 12:58:51 +01:00
|
|
|
}
|
|
|
|
|
2020-03-27 13:39:18 +01:00
|
|
|
changed() {
|
|
|
|
|
2020-02-11 12:58:51 +01:00
|
|
|
this.typeChange.emit({});
|
|
|
|
}
|
|
|
|
|
|
|
|
quickFilterChanged() {
|
2020-02-13 15:44:51 +01:00
|
|
|
if(this.quickFilter.filter) {
|
2020-03-27 13:39:18 +01:00
|
|
|
this.quickFilter.filter.countSelectedValues = 0;
|
2020-10-20 11:11:15 +02:00
|
|
|
if (this.quickFilter.selected) {
|
2020-02-13 15:44:51 +01:00
|
|
|
for (let filterValue of this.quickFilter.filter.values) {
|
2020-02-28 11:05:59 +01:00
|
|
|
if((filterValue.name == this.quickFilter.value)) {
|
|
|
|
filterValue.selected = true
|
|
|
|
this.quickFilter.filter.countSelectedValues = 1;
|
|
|
|
}else{
|
|
|
|
filterValue.selected = false;
|
|
|
|
}
|
2020-02-13 15:44:51 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (let filterValue of this.quickFilter.filter.values) {
|
|
|
|
filterValue.selected = false;
|
|
|
|
}
|
2020-02-11 12:58:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
this.typeChange.emit({});
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
2020-11-11 15:43:13 +01:00
|
|
|
this.subs.push(this.route.queryParams.subscribe(params => {
|
2020-10-20 11:11:15 +02:00
|
|
|
this.queryParams = Object.assign({}, params);
|
|
|
|
this.initializeFilters();
|
2020-11-11 15:43:13 +01:00
|
|
|
}));
|
2020-11-25 18:12:31 +01:00
|
|
|
//Allow all types
|
|
|
|
/* if(this.properties && !this.initialized) {
|
|
|
|
if(this.properties.adminToolsCommunity !== "monitor") {
|
2020-10-20 11:11:15 +02:00
|
|
|
this.subs.push(this.config.communityInformationState.subscribe(data => {
|
2020-07-13 00:19:30 +02:00
|
|
|
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;
|
2020-10-20 11:11:15 +02:00
|
|
|
this.initialized = true;
|
|
|
|
this.initializeFilters();
|
2020-06-29 15:15:52 +02:00
|
|
|
}
|
|
|
|
}, error => {
|
|
|
|
this.showPublications = true;
|
|
|
|
this.showDatasets = true;
|
|
|
|
this.showSoftware = true;
|
|
|
|
this.showOrp = true;
|
|
|
|
this.showEntities = true;
|
2020-10-20 11:11:15 +02:00
|
|
|
this.initializeFilters();
|
2020-07-13 00:19:30 +02:00
|
|
|
}));
|
2020-11-25 18:12:31 +01:00
|
|
|
} else {*/
|
2020-06-29 15:15:52 +02:00
|
|
|
this.showPublications = true;
|
|
|
|
this.showDatasets = true;
|
|
|
|
this.showSoftware = true;
|
|
|
|
this.showOrp = true;
|
|
|
|
this.showEntities = true;
|
2020-10-20 11:11:15 +02:00
|
|
|
this.initialized = true;
|
|
|
|
this.initializeFilters();
|
2020-11-25 18:12:31 +01:00
|
|
|
/*}
|
2020-03-27 13:39:18 +01:00
|
|
|
|
2020-10-20 11:11:15 +02:00
|
|
|
}else{
|
|
|
|
this.initializeFilters();
|
2020-11-25 18:12:31 +01:00
|
|
|
}*/
|
2020-07-13 00:19:30 +02:00
|
|
|
|
2020-10-20 11:11:15 +02:00
|
|
|
}
|
|
|
|
initializeFilters(){
|
|
|
|
if(this.showEntities ){
|
|
|
|
let selected = [];
|
|
|
|
for(let value of this.resultTypes.values){
|
|
|
|
if(value.selected){
|
|
|
|
selected.push(value.id);
|
|
|
|
}
|
2020-02-11 12:58:51 +01:00
|
|
|
}
|
2020-10-20 11:11:15 +02:00
|
|
|
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});
|
2020-02-11 12:58:51 +01:00
|
|
|
}
|
2020-04-22 15:00:13 +02:00
|
|
|
}
|
2020-10-20 11:11:15 +02:00
|
|
|
this.typeChange.emit("filters_update");
|
2020-02-11 12:58:51 +01:00
|
|
|
}
|
2020-10-20 11:11:15 +02:00
|
|
|
public ngOnDestroy() {
|
|
|
|
for (let sub of this.subs) {
|
|
|
|
sub.unsubscribe();
|
|
|
|
}
|
2020-06-01 11:02:16 +02:00
|
|
|
}
|
2020-02-11 12:58:51 +01:00
|
|
|
}
|