1 |
61381
|
k.triantaf
|
import {ChangeDetectorRef, Component, EventEmitter, Input, Output} from '@angular/core';
|
2 |
|
|
import {FormBuilder} from "@angular/forms";
|
3 |
|
|
import {Filter} from "./searchHelperClasses.class";
|
4 |
|
|
import {EnvProperties} from "../../utils/properties/env-properties";
|
5 |
|
|
import {ConfigurationService} from "../../utils/configuration/configuration.service";
|
6 |
|
|
import {Subscription} from "rxjs";
|
7 |
|
|
import {ActivatedRoute, Router} from "@angular/router";
|
8 |
|
|
|
9 |
|
|
@Component({
|
10 |
|
|
selector: 'quick-selections',
|
11 |
|
|
template: `
|
12 |
|
|
<div *ngIf="!vertical && (resultTypes || quickFilter)"
|
13 |
|
|
[class]="(isDisabled ? 'uk-disabled' : '') + ' uk-text-small uk-margin-small-bottom uk-grid uk-inline uk-flex uk-margin-small-left'">
|
14 |
|
|
<div *ngIf="quickFilter" class="uk-margin-small-top uk-padding-remove-left uk-margin-right ">
|
15 |
|
|
<span class="uk-text-bold">{{quickFilter.value}}</span>
|
16 |
|
|
<mat-slide-toggle
|
17 |
|
|
class="uk-margin-small-left" name="qf" [(ngModel)]="quickFilter.selected" (ngModelChange)="quickFilterChanged()">
|
18 |
|
|
</mat-slide-toggle>
|
19 |
|
|
</div>
|
20 |
|
|
<div *ngIf="resultTypes && showEntities" class="uk-margin-small-top uk-padding-remove-left">
|
21 |
|
|
<span class="uk-text-muted">Include: </span>
|
22 |
|
|
<span>
|
23 |
|
|
<ng-container *ngFor="let value of resultTypes.values">
|
24 |
|
|
<span class="uk-margin-small-left">
|
25 |
|
|
<input #input type="checkbox" class="uk-checkbox" [(ngModel)]="value.selected" (ngModelChange)="changed()"/>
|
26 |
|
|
<span class="space clickable" (click)="input.click()">{{value.name}}</span>
|
27 |
|
|
</span>
|
28 |
|
|
</ng-container>
|
29 |
|
|
</span>
|
30 |
|
|
</div>
|
31 |
|
|
</div>
|
32 |
|
|
<div *ngIf="vertical && (resultTypes || quickFilter)"
|
33 |
|
|
[class]="(isDisabled ? 'uk-disabled' : '') + ' uk-margin-small-bottom uk-list uk-list-divider'">
|
34 |
|
|
<search-filter
|
35 |
|
|
[isDisabled]="isDisabled"
|
36 |
|
|
[filter]="resultTypes" [showResultCount]='false'
|
37 |
|
|
(onFilterChange)="changed()" [actionRoute]="actionRoute"></search-filter>
|
38 |
|
|
</div>
|
39 |
|
|
|
40 |
|
|
`
|
41 |
|
|
})
|
42 |
|
|
|
43 |
|
|
export class QuickSelectionsComponent {
|
44 |
|
|
@Input() resultTypes:Filter;
|
45 |
|
|
@Output() typeChange = new EventEmitter();
|
46 |
|
|
@Input() isDisabled;
|
47 |
|
|
@Input() quickFilter: { filter: Filter, selected: boolean, filterId: string, value: string };
|
48 |
|
|
initialized = false;
|
49 |
|
|
@Input() properties: EnvProperties;
|
50 |
|
|
@Input() vertical: boolean=false;
|
51 |
|
|
showPublications:boolean= false;
|
52 |
|
|
showDatasets:boolean= false;
|
53 |
|
|
showSoftware: boolean = false;
|
54 |
|
|
showOrp: boolean = false;
|
55 |
|
|
showEntities = false;
|
56 |
|
|
@Input() actionRoute:boolean = false;
|
57 |
|
|
queryParams = {};
|
58 |
|
|
|
59 |
|
|
subs: Subscription[] = [];
|
60 |
|
|
|
61 |
|
|
constructor(private _fb: FormBuilder, private config: ConfigurationService, private _router: Router, private route: ActivatedRoute, private cdr:ChangeDetectorRef) {
|
62 |
|
|
}
|
63 |
|
|
|
64 |
|
|
changed() {
|
65 |
|
|
|
66 |
|
|
this.typeChange.emit({});
|
67 |
|
|
}
|
68 |
|
|
|
69 |
|
|
quickFilterChanged() {
|
70 |
|
|
if(this.quickFilter.filter) {
|
71 |
|
|
this.quickFilter.filter.countSelectedValues = 0;
|
72 |
|
|
if (this.quickFilter.selected) {
|
73 |
|
|
for (let filterValue of this.quickFilter.filter.values) {
|
74 |
|
|
if((filterValue.name == this.quickFilter.value)) {
|
75 |
|
|
filterValue.selected = true
|
76 |
|
|
this.quickFilter.filter.countSelectedValues = 1;
|
77 |
|
|
}else{
|
78 |
|
|
filterValue.selected = false;
|
79 |
|
|
}
|
80 |
|
|
}
|
81 |
|
|
} else {
|
82 |
|
|
for (let filterValue of this.quickFilter.filter.values) {
|
83 |
|
|
filterValue.selected = false;
|
84 |
|
|
}
|
85 |
|
|
}
|
86 |
|
|
}
|
87 |
|
|
this.typeChange.emit({});
|
88 |
|
|
}
|
89 |
|
|
|
90 |
|
|
ngOnInit() {
|
91 |
|
|
this.subs.push(this.route.queryParams.subscribe(params => {
|
92 |
|
|
this.queryParams = Object.assign({}, params);
|
93 |
|
|
this.initializeFilters();
|
94 |
|
|
}));
|
95 |
|
|
//Allow all types
|
96 |
|
|
/* if(this.properties && !this.initialized) {
|
97 |
|
|
if(this.properties.adminToolsCommunity !== "monitor") {
|
98 |
|
|
this.subs.push(this.config.communityInformationState.subscribe(data => {
|
99 |
|
|
if(data) {
|
100 |
|
|
var showEntity = {};
|
101 |
|
|
for (var i = 0; i < data['entities'].length; i++) {
|
102 |
|
|
showEntity["" + data['entities'][i]["pid"] + ""] = data['entities'][i]["isEnabled"];
|
103 |
|
|
}
|
104 |
|
|
this.showPublications = showEntity["publication"];
|
105 |
|
|
this.showDatasets = showEntity["dataset"];
|
106 |
|
|
this.showSoftware = showEntity["software"];
|
107 |
|
|
this.showOrp = showEntity["orp"];
|
108 |
|
|
this.showEntities = this.showPublications || this.showDatasets || this.showSoftware || this.showOrp;
|
109 |
|
|
this.initialized = true;
|
110 |
|
|
this.initializeFilters();
|
111 |
|
|
}
|
112 |
|
|
}, error => {
|
113 |
|
|
this.showPublications = true;
|
114 |
|
|
this.showDatasets = true;
|
115 |
|
|
this.showSoftware = true;
|
116 |
|
|
this.showOrp = true;
|
117 |
|
|
this.showEntities = true;
|
118 |
|
|
this.initializeFilters();
|
119 |
|
|
}));
|
120 |
|
|
} else {*/
|
121 |
|
|
this.showPublications = true;
|
122 |
|
|
this.showDatasets = true;
|
123 |
|
|
this.showSoftware = true;
|
124 |
|
|
this.showOrp = true;
|
125 |
|
|
this.showEntities = true;
|
126 |
|
|
this.initialized = true;
|
127 |
|
|
this.initializeFilters();
|
128 |
|
|
/*}
|
129 |
|
|
|
130 |
|
|
}else{
|
131 |
|
|
this.initializeFilters();
|
132 |
|
|
}*/
|
133 |
|
|
|
134 |
|
|
}
|
135 |
|
|
initializeFilters(){
|
136 |
|
|
if(this.showEntities ){
|
137 |
|
|
let selected = [];
|
138 |
|
|
for(let value of this.resultTypes.values){
|
139 |
|
|
if(value.selected){
|
140 |
|
|
selected.push(value.id);
|
141 |
|
|
}
|
142 |
|
|
}
|
143 |
|
|
this.resultTypes.countSelectedValues = selected.length;
|
144 |
|
|
this.resultTypes.values = [];
|
145 |
|
|
if(this.showPublications){
|
146 |
|
|
this.resultTypes.values.push({name: "Publications" , id:"publications",selected:selected.indexOf("publications")!=-1, number:0});
|
147 |
|
|
}
|
148 |
|
|
if(this.showDatasets){
|
149 |
|
|
this.resultTypes.values.push({name: "Research data" , id:"datasets",selected:selected.indexOf("datasets")!=-1, number:0});
|
150 |
|
|
}
|
151 |
|
|
if(this.showSoftware){
|
152 |
|
|
this.resultTypes.values.push({name: "Software" , id:"software",selected:selected.indexOf("software")!=-1, number:0});
|
153 |
|
|
}
|
154 |
|
|
if(this.showOrp){
|
155 |
|
|
this.resultTypes.values.push({name: "Other research products" , id:"other",selected:selected.indexOf("other")!=-1, number:0});
|
156 |
|
|
}
|
157 |
|
|
}
|
158 |
|
|
this.typeChange.emit("filters_update");
|
159 |
|
|
}
|
160 |
|
|
public ngOnDestroy() {
|
161 |
|
|
for (let sub of this.subs) {
|
162 |
|
|
sub.unsubscribe();
|
163 |
|
|
}
|
164 |
|
|
}
|
165 |
|
|
}
|