1
|
import {Component, EventEmitter, Input, OnChanges, Output, SimpleChanges} from '@angular/core';
|
2
|
import {FormBuilder, FormGroup} 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 {Subject, Subscription} from "rxjs";
|
7
|
import {debounceTime} from "rxjs/operators";
|
8
|
|
9
|
@Component({
|
10
|
selector: 'quick-selections',
|
11
|
template: `
|
12
|
<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
|
<span class="uk-text-bold">{{quickFilter.value}}</span>
|
15
|
<mat-slide-toggle
|
16
|
class="uk-margin-small-left" formControlName="QFselected" (change)="quickFilterChanged()">
|
17
|
</mat-slide-toggle>
|
18
|
</div>
|
19
|
<div *ngIf="resultTypes && showEntities" class="uk-margin-small-top uk-padding-remove-left">
|
20
|
<span class="uk-text-muted">Include: </span>
|
21
|
<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
|
</div>
|
28
|
</form>
|
29
|
`
|
30
|
})
|
31
|
|
32
|
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
|
@Input() properties: EnvProperties;
|
41
|
showPublications:boolean= false;
|
42
|
showDatasets:boolean= false;
|
43
|
showSoftware: boolean = false;
|
44
|
showOrp: boolean = false;
|
45
|
showEntities = false;
|
46
|
resultTypesObs: Subscription ;
|
47
|
private clicks = new Subject();
|
48
|
constructor(private _fb: FormBuilder, private config: ConfigurationService) {
|
49
|
|
50
|
this.control = this._fb.group({
|
51
|
publication: true,
|
52
|
dataset: true,
|
53
|
software: true,
|
54
|
other: true,
|
55
|
QFselected: true
|
56
|
});
|
57
|
|
58
|
|
59
|
}
|
60
|
|
61
|
changed() {
|
62
|
if (!this.initialized && this.isDisabled) {
|
63
|
this.initialized = true;
|
64
|
return;
|
65
|
}
|
66
|
this.clicks.next();
|
67
|
}
|
68
|
actuallyChanged(){
|
69
|
|
70
|
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
|
if (this.resultTypes && !this.resultTypes.publication && !this.resultTypes.dataset && !this.resultTypes.software && !this.resultTypes.other) {
|
76
|
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
|
|
85
|
quickFilterChanged() {
|
86
|
let value = this.control.getRawValue();
|
87
|
this.quickFilter.selected = value.QFselected;
|
88
|
if(this.quickFilter.filter) {
|
89
|
this.quickFilter.filter.countSelectedValues = 0;
|
90
|
if (value.QFselected) {
|
91
|
for (let filterValue of this.quickFilter.filter.values) {
|
92
|
if((filterValue.name == this.quickFilter.value)) {
|
93
|
filterValue.selected = true
|
94
|
this.quickFilter.filter.countSelectedValues = 1;
|
95
|
}else{
|
96
|
filterValue.selected = false;
|
97
|
}
|
98
|
}
|
99
|
} else {
|
100
|
for (let filterValue of this.quickFilter.filter.values) {
|
101
|
filterValue.selected = false;
|
102
|
}
|
103
|
}
|
104
|
}
|
105
|
this.typeChange.emit({});
|
106
|
}
|
107
|
|
108
|
ngOnInit() {
|
109
|
if (this.resultTypes) {
|
110
|
this.setFormValues();
|
111
|
}
|
112
|
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
|
this.resultTypesObs = this.clicks.pipe(
|
126
|
debounceTime(1000)
|
127
|
).subscribe(e =>{this.actuallyChanged()} );
|
128
|
|
129
|
}
|
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
|
if (changes.resultTypes) {
|
148
|
this.setFormValues();
|
149
|
}
|
150
|
}
|
151
|
|
152
|
setFormValues() {
|
153
|
this.control.setValue({
|
154
|
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
|
QFselected: this.QFselected
|
159
|
});
|
160
|
}
|
161
|
|
162
|
|
163
|
}
|