1 |
58072
|
argiro.kok
|
import {Component, EventEmitter, Input, OnChanges, Output, SimpleChanges} from '@angular/core';
|
2 |
|
|
import {FormBuilder, FormGroup} from "@angular/forms";
|
3 |
|
|
import {Filter} from "./searchHelperClasses.class";
|
4 |
58093
|
argiro.kok
|
import {EnvProperties} from "../../utils/properties/env-properties";
|
5 |
|
|
import {ConfigurationService} from "../../utils/configuration/configuration.service";
|
6 |
58348
|
argiro.kok
|
import {Subject, Subscription} from "rxjs";
|
7 |
|
|
import {debounceTime} from "rxjs/operators";
|
8 |
50169
|
argiro.kok
|
|
9 |
|
|
@Component({
|
10 |
58072
|
argiro.kok
|
selector: 'quick-selections',
|
11 |
|
|
template: `
|
12 |
58525
|
argiro.kok
|
<form *ngIf="resultTypes || quickFilter" [formGroup]="control" class="uk-text-small uk-margin-small-bottom uk-grid uk-inline uk-flex uk-margin-small-left">
|
13 |
|
|
<div *ngIf="quickFilter" class="uk-margin-small-top uk-padding-remove-left uk-margin-right ">
|
14 |
58093
|
argiro.kok
|
<span class="uk-text-bold">{{quickFilter.value}}</span>
|
15 |
|
|
<mat-slide-toggle
|
16 |
|
|
class="uk-margin-small-left" formControlName="QFselected" (change)="quickFilterChanged()">
|
17 |
58072
|
argiro.kok
|
</mat-slide-toggle>
|
18 |
|
|
</div>
|
19 |
58525
|
argiro.kok
|
<div *ngIf="resultTypes && showEntities" class="uk-margin-small-top uk-padding-remove-left">
|
20 |
58093
|
argiro.kok
|
<span class="uk-text-muted">Include: </span>
|
21 |
58525
|
argiro.kok
|
<span>
|
22 |
|
|
<span *ngIf="showPublications" class="uk-margin-small-left"> <input type="checkbox" id="publ" name="Publications" formControlName="publication" (change)="changed()"> Publications </span>
|
23 |
|
|
<span *ngIf="showDatasets" class="uk-margin-small-left"> <input type="checkbox" formControlName="dataset" (change)="changed()"> Research data </span>
|
24 |
|
|
<span *ngIf="showSoftware" class="uk-margin-small-left"> <input type="checkbox" formControlName="software" (change)="changed()"> Software </span>
|
25 |
|
|
<span *ngIf="showOrp" class="uk-margin-small-left"> <input type="checkbox" formControlName="other" (change)="changed()"> Other research products </span>
|
26 |
|
|
</span>
|
27 |
58093
|
argiro.kok
|
</div>
|
28 |
58072
|
argiro.kok
|
</form>
|
29 |
|
|
`
|
30 |
|
|
})
|
31 |
50169
|
argiro.kok
|
|
32 |
58072
|
argiro.kok
|
export class QuickSelectionsComponent implements OnChanges {
|
33 |
|
|
@Input() resultTypes;
|
34 |
|
|
@Output() typeChange = new EventEmitter();
|
35 |
|
|
@Input() isDisabled;
|
36 |
|
|
@Input() quickFilter: { filter: Filter, selected: boolean, filterId: string, value: string };
|
37 |
|
|
@Input() QFselected: boolean;
|
38 |
|
|
control: FormGroup;
|
39 |
|
|
initialized = false;
|
40 |
58093
|
argiro.kok
|
@Input() properties: EnvProperties;
|
41 |
|
|
showPublications:boolean= false;
|
42 |
|
|
showDatasets:boolean= false;
|
43 |
|
|
showSoftware: boolean = false;
|
44 |
|
|
showOrp: boolean = false;
|
45 |
|
|
showEntities = false;
|
46 |
58348
|
argiro.kok
|
resultTypesObs: Subscription ;
|
47 |
|
|
private clicks = new Subject();
|
48 |
58093
|
argiro.kok
|
constructor(private _fb: FormBuilder, private config: ConfigurationService) {
|
49 |
50169
|
argiro.kok
|
|
50 |
58072
|
argiro.kok
|
this.control = this._fb.group({
|
51 |
|
|
publication: true,
|
52 |
|
|
dataset: true,
|
53 |
|
|
software: true,
|
54 |
|
|
other: true,
|
55 |
|
|
QFselected: true
|
56 |
|
|
});
|
57 |
|
|
|
58 |
58093
|
argiro.kok
|
|
59 |
58072
|
argiro.kok
|
}
|
60 |
|
|
|
61 |
58348
|
argiro.kok
|
changed() {
|
62 |
58072
|
argiro.kok
|
if (!this.initialized && this.isDisabled) {
|
63 |
|
|
this.initialized = true;
|
64 |
|
|
return;
|
65 |
50169
|
argiro.kok
|
}
|
66 |
58348
|
argiro.kok
|
this.clicks.next();
|
67 |
|
|
}
|
68 |
|
|
actuallyChanged(){
|
69 |
|
|
|
70 |
58072
|
argiro.kok
|
let value = this.control.getRawValue();
|
71 |
|
|
this.resultTypes.publication = value.publication;
|
72 |
|
|
this.resultTypes.dataset = value.dataset;
|
73 |
|
|
this.resultTypes.software = value.software;
|
74 |
|
|
this.resultTypes.other = value.other;
|
75 |
58348
|
argiro.kok
|
if (this.resultTypes && !this.resultTypes.publication && !this.resultTypes.dataset && !this.resultTypes.software && !this.resultTypes.other) {
|
76 |
58072
|
argiro.kok
|
this.resultTypes.publication = true;
|
77 |
|
|
this.resultTypes.dataset = true;
|
78 |
|
|
this.resultTypes.software = true;
|
79 |
|
|
this.resultTypes.other = true;
|
80 |
|
|
this.setFormValues();
|
81 |
|
|
}
|
82 |
|
|
this.typeChange.emit({});
|
83 |
|
|
}
|
84 |
50169
|
argiro.kok
|
|
85 |
58072
|
argiro.kok
|
quickFilterChanged() {
|
86 |
|
|
let value = this.control.getRawValue();
|
87 |
|
|
this.quickFilter.selected = value.QFselected;
|
88 |
58093
|
argiro.kok
|
if(this.quickFilter.filter) {
|
89 |
58348
|
argiro.kok
|
this.quickFilter.filter.countSelectedValues = 0;
|
90 |
58093
|
argiro.kok
|
if (value.QFselected) {
|
91 |
|
|
for (let filterValue of this.quickFilter.filter.values) {
|
92 |
58156
|
argiro.kok
|
if((filterValue.name == this.quickFilter.value)) {
|
93 |
|
|
filterValue.selected = true
|
94 |
|
|
this.quickFilter.filter.countSelectedValues = 1;
|
95 |
|
|
}else{
|
96 |
|
|
filterValue.selected = false;
|
97 |
|
|
}
|
98 |
58093
|
argiro.kok
|
}
|
99 |
|
|
} else {
|
100 |
|
|
for (let filterValue of this.quickFilter.filter.values) {
|
101 |
|
|
filterValue.selected = false;
|
102 |
|
|
}
|
103 |
58072
|
argiro.kok
|
}
|
104 |
|
|
}
|
105 |
|
|
this.typeChange.emit({});
|
106 |
|
|
}
|
107 |
50169
|
argiro.kok
|
|
108 |
58072
|
argiro.kok
|
ngOnInit() {
|
109 |
|
|
if (this.resultTypes) {
|
110 |
|
|
this.setFormValues();
|
111 |
|
|
}
|
112 |
58093
|
argiro.kok
|
if(this.properties) {
|
113 |
|
|
this.config.getCommunityInformation(this.properties, this.properties.adminToolsCommunity).subscribe(data => {
|
114 |
|
|
var showEntity = {};
|
115 |
|
|
for (var i = 0; i < data['entities'].length; i++) {
|
116 |
|
|
showEntity["" + data['entities'][i]["pid"] + ""] = data['entities'][i]["isEnabled"];
|
117 |
|
|
}
|
118 |
|
|
this.showPublications = showEntity["publication"];
|
119 |
|
|
this.showDatasets = showEntity["dataset"];
|
120 |
|
|
this.showSoftware = showEntity["software"];
|
121 |
|
|
this.showOrp = showEntity["orp"];
|
122 |
|
|
this.showEntities = this.showPublications || this.showDatasets || this.showSoftware || this.showOrp;
|
123 |
|
|
});
|
124 |
|
|
}
|
125 |
58348
|
argiro.kok
|
this.resultTypesObs = this.clicks.pipe(
|
126 |
|
|
debounceTime(1000)
|
127 |
|
|
).subscribe(e =>{this.actuallyChanged()} );
|
128 |
|
|
|
129 |
58072
|
argiro.kok
|
}
|
130 |
|
|
|
131 |
|
|
ngOnChanges(changes: SimpleChanges): void {
|
132 |
|
|
if (changes.isDisabled) {
|
133 |
|
|
if (changes.isDisabled.currentValue == true) {
|
134 |
|
|
this.control.disable();
|
135 |
|
|
} else if (changes.isDisabled.currentValue == false) {
|
136 |
|
|
this.control.enable();
|
137 |
|
|
}
|
138 |
|
|
}
|
139 |
|
|
|
140 |
|
|
if (changes.QFselected) {
|
141 |
|
|
let value = this.control.getRawValue();
|
142 |
|
|
if (changes.QFselected.currentValue != value.QFselected) {
|
143 |
|
|
this.setFormValues();
|
144 |
|
|
}
|
145 |
|
|
|
146 |
|
|
}
|
147 |
58517
|
argiro.kok
|
if (changes.resultTypes) {
|
148 |
|
|
this.setFormValues();
|
149 |
|
|
}
|
150 |
58072
|
argiro.kok
|
}
|
151 |
|
|
|
152 |
|
|
setFormValues() {
|
153 |
|
|
this.control.setValue({
|
154 |
58073
|
argiro.kok
|
publication: (this.resultTypes && this.resultTypes.publication)?this.resultTypes.publication:null,
|
155 |
|
|
dataset: (this.resultTypes && this.resultTypes.dataset)?this.resultTypes.dataset:null,
|
156 |
|
|
software: (this.resultTypes && this.resultTypes.software)?this.resultTypes.software:null,
|
157 |
|
|
other: (this.resultTypes && this.resultTypes.other)?this.resultTypes.other:null,
|
158 |
58072
|
argiro.kok
|
QFselected: this.QFselected
|
159 |
|
|
});
|
160 |
|
|
}
|
161 |
|
|
|
162 |
|
|
|
163 |
50169
|
argiro.kok
|
}
|