Project

General

Profile

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="!vertical && (resultTypes || quickFilter)" [formGroup]="control" 
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" formControlName="QFselected" (change)="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
          <span *ngIf="showPublications" class="uk-margin-small-left"> <input type="checkbox" id="publ" name="Publications" formControlName="publication" (change)="changed()"> Publications </span>
24
          <span *ngIf="showDatasets" class="uk-margin-small-left"> <input type="checkbox" formControlName="dataset" (change)="changed()"> Research data </span>
25
          <span *ngIf="showSoftware" class="uk-margin-small-left"> <input type="checkbox" formControlName="software" (change)="changed()"> Software </span>
26
          <span *ngIf="showOrp" class="uk-margin-small-left"> <input type="checkbox" formControlName="other" (change)="changed()"> Other research products </span>
27
        </span>
28
      </div>
29
    </form>
30
    <form *ngIf="vertical && (resultTypes || quickFilter)" [formGroup]="control" 
31
          [class]="(isDisabled ? 'uk-disabled' : '') + ' uk-margin-small-bottom uk-list uk-list-divider'">
32
    <!--  <li   *ngIf="quickFilter" class="uk-margin-small-bottom ">
33
        <div class="uk-margin-small-top uk-padding-remove-left uk-margin-right ">
34
          <h5 class="">{{quickFilter.value}}</h5>
35
          <mat-slide-toggle
36
            class="uk-margin-small-left" formControlName="QFselected" (change)="quickFilterChanged()">
37
          </mat-slide-toggle>
38
        </div>
39
      </li>-->
40
<!--      {{showEntities}} - {{showPublications}} - {{showDatasets}} - {{showSoftware}} &#45;&#45; {{showOrp}}-->
41
      <li *ngIf="resultTypes && showEntities" class="uk-margin-small-bottom ng-star-inserted">
42
        <div class="uk-margin-small-top uk-margin-bottom uk-grid uk-flex uk-flex-bottom">
43
          <h5 class="uk-margin-bottom-remove" title="Community">Research Type ({{(this.showPublications + this.showDatasets + this.showSoftware + this.showOrp)}})</h5>
44
          <a *ngIf="selectedTypesNum>0" (click)="clearTypes()" class="portal-link">
45
            Clear
46
          </a>
47
        </div>
48
        <div>
49
          <div>
50
            <div *ngIf="showPublications" class="uk-animation-fade filterItem searchFilterItem uk-text-small ng-star-inserted">
51
              <div title="Publications">
52
                <label class="ng-star-inserted"><input class="uk-checkbox" type="checkbox" id="publ" name="Publications" formControlName="publication" (change)="changed()"> Publications</label>
53
              </div>
54
            </div>
55
            <div *ngIf="showDatasets"  class="uk-animation-fade filterItem searchFilterItem uk-text-small ng-star-inserted">
56
              <div title="Research data">
57
                <label class="ng-star-inserted"><input class="uk-checkbox" type="checkbox" formControlName="dataset" (change)="changed()"> Research data </label>
58
              </div>
59
            </div>
60
            <div *ngIf="showSoftware" class="uk-animation-fade filterItem searchFilterItem uk-text-small ng-star-inserted">
61
              <div title="Software">
62
                <label class="ng-star-inserted"> <input class="uk-checkbox" type="checkbox" formControlName="software" (change)="changed()"> Software</label>
63
              </div>
64
            </div>
65
            <div *ngIf="showOrp" class="uk-animation-fade filterItem searchFilterItem uk-text-small ng-star-inserted">
66
              <div title=" Other research products">
67
                <label class="ng-star-inserted"><input class="uk-checkbox" type="checkbox" formControlName="other" (change)="changed()"> Other research products</label>
68
              </div>
69
            </div>
70
          </div>
71
        </div>
72
      </li>
73
    </form>
74
  `
75
})
76

    
77
export class QuickSelectionsComponent implements OnChanges {
78
  @Input() resultTypes;
79
  @Output() typeChange = new EventEmitter();
80
  @Input() isDisabled;
81
  @Input() quickFilter: { filter: Filter, selected: boolean, filterId: string, value: string };
82
  @Input() QFselected: boolean;
83
  control: FormGroup;
84
  initialized = false;
85
  @Input() properties: EnvProperties;
86
  @Input() vertical: boolean=false;
87
  showPublications:boolean= false;
88
  showDatasets:boolean= false;
89
  showSoftware: boolean = false;
90
  showOrp: boolean = false;
91
  showEntities = false;
92
  selectedTypesNum = 0;
93
  @Input() delayTime = 0;
94
  private clicks = new Subject();
95

    
96
  subs: Subscription[] = [];
97

    
98
  constructor(private _fb: FormBuilder, private config: ConfigurationService) {
99

    
100
    this.control = this._fb.group({
101
      publication: true,
102
      dataset: true,
103
      software: true,
104
      other: true,
105
      QFselected: true
106
    });
107

    
108

    
109
  }
110

    
111
  changed() {
112
    if (!this.initialized && this.isDisabled) {
113
      this.initialized = true;
114
      return;
115
    }
116
    this.clicks.next();
117
  }
118
  actuallyChanged(){
119

    
120
    let value = this.control.getRawValue();
121
    this.resultTypes.publication = value.publication;
122
    this.resultTypes.dataset = value.dataset;
123
    this.resultTypes.software = value.software;
124
    this.resultTypes.other = value.other;
125
    if (this.resultTypes && !this.resultTypes.publication && !this.resultTypes.dataset && !this.resultTypes.software && !this.resultTypes.other && !this.vertical) {
126
      this.resultTypes.publication = true;
127
      this.resultTypes.dataset = true;
128
      this.resultTypes.software = true;
129
      this.resultTypes.other = true;
130
      this.setFormValues();
131
    }
132
    this.typeChange.emit({});
133
  }
134

    
135
  quickFilterChanged() {
136
    let value = this.control.getRawValue();
137
    this.quickFilter.selected = value.QFselected;
138
    if(this.quickFilter.filter) {
139
      this.quickFilter.filter.countSelectedValues = 0;
140
      if (value.QFselected) {
141
        for (let filterValue of this.quickFilter.filter.values) {
142
          if((filterValue.name == this.quickFilter.value)) {
143
            filterValue.selected = true
144
            this.quickFilter.filter.countSelectedValues = 1;
145
          }else{
146
            filterValue.selected = false;
147
          }
148
        }
149
      } else {
150
        for (let filterValue of this.quickFilter.filter.values) {
151
          filterValue.selected = false;
152
        }
153
      }
154
    }
155
    this.typeChange.emit({});
156
  }
157

    
158
  ngOnInit() {
159
    if (this.resultTypes) {
160
      this.setFormValues();
161
    }
162
    if(this.properties) {
163
      if(this.properties.adminToolsCommunity !== "monitor") {
164
        //this.subs.push(this.config.getCommunityInformation(this.properties, this.properties.adminToolsCommunity).subscribe(data => {
165
        this.subs.push(this.config.communityInformationState.subscribe(data => {
166
          if(data) {
167
            var showEntity = {};
168
            for (var i = 0; i < data['entities'].length; i++) {
169
              showEntity["" + data['entities'][i]["pid"] + ""] = data['entities'][i]["isEnabled"];
170
            }
171
            this.showPublications = showEntity["publication"];
172
            this.showDatasets = showEntity["dataset"];
173
            this.showSoftware = showEntity["software"];
174
            this.showOrp = showEntity["orp"];
175
            this.showEntities = this.showPublications || this.showDatasets || this.showSoftware || this.showOrp;
176
          }
177
        }, error => {
178
          this.showPublications = true;
179
          this.showDatasets = true;
180
          this.showSoftware = true;
181
          this.showOrp = true;
182
          this.showEntities = true;
183
        }));
184
      } else {
185
        this.showPublications = true;
186
        this.showDatasets = true;
187
        this.showSoftware = true;
188
        this.showOrp = true;
189
        this.showEntities = true;
190
      }
191
    }
192
    this.subs.push(this.clicks.pipe(
193
      debounceTime(this.delayTime)
194
    ).subscribe(e =>{this.actuallyChanged()} ));
195

    
196
  }
197

    
198
  public ngOnDestroy() {
199
    for (let sub of this.subs) {
200
      sub.unsubscribe();
201
    }
202
  }
203

    
204
  ngOnChanges(changes: SimpleChanges): void {
205
    if (changes.isDisabled) {
206
      if (changes.isDisabled.currentValue == true) {
207
        this.control.disable();
208
      } else if (changes.isDisabled.currentValue == false) {
209
        this.control.enable();
210
      }
211
    }
212

    
213
    if (changes.QFselected) {
214
      let value = this.control.getRawValue();
215
      if (changes.QFselected.currentValue != value.QFselected) {
216
        this.setFormValues();
217
      }
218

    
219
    }
220
    if (changes.resultTypes) {
221
      this.setFormValues();
222
    }
223
  }
224

    
225
  setFormValues() {
226
    this.control.setValue({
227
      publication: (this.resultTypes && this.resultTypes.publication)?this.resultTypes.publication:null,
228
      dataset: (this.resultTypes && this.resultTypes.dataset)?this.resultTypes.dataset:null,
229
      software: (this.resultTypes && this.resultTypes.software)?this.resultTypes.software:null,
230
      other: (this.resultTypes && this.resultTypes.other)?this.resultTypes.other:null,
231
      QFselected: this.QFselected
232
    });
233
    this.selectedTypesNum = (this.resultTypes && this.resultTypes.publication)?this.resultTypes.publication:0 + (this.resultTypes && this.resultTypes.dataset)?this.resultTypes.dataset:0+ (this.resultTypes && this.resultTypes.software)?this.resultTypes.software:0 + (this.resultTypes && this.resultTypes.other)?this.resultTypes.other:null;
234
  }
235

    
236
  clearTypes(){
237
    this.resultTypes.publication = false;
238
    this.resultTypes.dataset = false;
239
    this.resultTypes.software = false;
240
    this.resultTypes.other = false;
241
    this.setFormValues();
242
    this.changed()
243
  }
244

    
245
}
(24-24/55)