2020-10-20 11:11:15 +02:00
|
|
|
import {ChangeDetectorRef, Component, EventEmitter, Input, Output} from '@angular/core';
|
2022-09-23 12:25:08 +02:00
|
|
|
import {UntypedFormBuilder} 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";
|
2022-04-15 23:49:35 +02:00
|
|
|
import {properties} from "../../../../environments/environment";
|
2022-04-19 01:09:42 +02:00
|
|
|
import {OpenaireEntities} from "../../utils/properties/searchFields";
|
2020-02-11 12:58:51 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'quick-selections',
|
|
|
|
template: `
|
2022-05-05 08:32:18 +02:00
|
|
|
<div *ngIf="quickFilter" class="uk-margin-bottom">
|
2022-04-19 01:09:42 +02:00
|
|
|
<mat-slide-toggle name="qf" [(ngModel)]="quickFilter.selected" (ngModelChange)="quickFilterChanged()">
|
|
|
|
<span class="uk-text-bold">{{quickFilter.value}}</span>
|
|
|
|
</mat-slide-toggle>
|
|
|
|
</div>
|
2022-05-25 11:44:13 +02:00
|
|
|
<div class="uk-flex uk-flex-middle uk-text-small uk-text-nowrap">
|
2022-04-19 01:09:42 +02:00
|
|
|
<div class="uk-width-auto@s uk-width-1-3 uk-flex uk-flex-right uk-text-meta uk-margin-small-right">Include:</div>
|
|
|
|
<div class="uk-width-expand">
|
2022-05-19 17:35:59 +02:00
|
|
|
<div class="uk-grid uk-grid-small uk-flex-middle uk-child-width-auto@m uk-child-width-1-2@s uk-child-width-1-1" uk-grid>
|
2022-04-19 01:09:42 +02:00
|
|
|
<ng-container *ngFor="let value of resultTypes.values">
|
|
|
|
<div>
|
|
|
|
<input #input type="checkbox" class="uk-checkbox" [(ngModel)]="value.selected" (ngModelChange)="changed()"/>
|
|
|
|
<label class="uk-margin-small-left" (click)="input.click()">{{value.name}}</label>
|
|
|
|
</div>
|
|
|
|
</ng-container>
|
2022-04-15 23:49:35 +02:00
|
|
|
</div>
|
2022-04-19 01:09:42 +02:00
|
|
|
</div>
|
2020-10-20 11:11:15 +02:00
|
|
|
</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 };
|
2022-04-15 23:49:35 +02:00
|
|
|
@Input() actionRoute:boolean = false;
|
2020-02-11 12:58:51 +01:00
|
|
|
initialized = false;
|
2022-04-15 23:49:35 +02:00
|
|
|
properties: EnvProperties = properties;
|
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
|
|
|
queryParams = {};
|
2020-07-13 00:19:30 +02:00
|
|
|
|
|
|
|
subs: Subscription[] = [];
|
|
|
|
|
2022-09-23 12:25:08 +02:00
|
|
|
constructor(private _fb: UntypedFormBuilder, 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;
|
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
|
|
|
}
|