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

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

    
95
    this.control = this._fb.group({
96
      publication: true,
97
      dataset: true,
98
      software: true,
99
      other: true,
100
      QFselected: true
101
    });
102

    
103

    
104
  }
105

    
106
  changed() {
107
    if (!this.initialized && this.isDisabled) {
108
      this.initialized = true;
109
      return;
110
    }
111
    this.clicks.next();
112
  }
113
  actuallyChanged(){
114

    
115
    let value = this.control.getRawValue();
116
    this.resultTypes.publication = value.publication;
117
    this.resultTypes.dataset = value.dataset;
118
    this.resultTypes.software = value.software;
119
    this.resultTypes.other = value.other;
120
    if (this.resultTypes && !this.resultTypes.publication && !this.resultTypes.dataset && !this.resultTypes.software && !this.resultTypes.other && !this.vertical) {
121
      this.resultTypes.publication = true;
122
      this.resultTypes.dataset = true;
123
      this.resultTypes.software = true;
124
      this.resultTypes.other = true;
125
      this.setFormValues();
126
    }
127
    this.typeChange.emit({});
128
  }
129

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

    
153
  ngOnInit() {
154
    if (this.resultTypes) {
155
      this.setFormValues();
156
    }
157
    if(this.properties) {
158
      this.config.getCommunityInformation(this.properties, this.properties.adminToolsCommunity).subscribe(data => {
159
        var showEntity = {};
160
        for (var i = 0; i < data['entities'].length; i++) {
161
          showEntity["" + data['entities'][i]["pid"] + ""] = data['entities'][i]["isEnabled"];
162
        }
163
        this.showPublications = showEntity["publication"];
164
        this.showDatasets = showEntity["dataset"];
165
        this.showSoftware = showEntity["software"];
166
        this.showOrp = showEntity["orp"];
167
        this.showEntities = this.showPublications || this.showDatasets || this.showSoftware || this.showOrp;
168
      });
169
    }
170
    this.resultTypesObs  = this.clicks.pipe(
171
      debounceTime(this.delayTime)
172
    ).subscribe(e =>{this.actuallyChanged()} );
173

    
174
  }
175

    
176
  ngOnChanges(changes: SimpleChanges): void {
177
    if (changes.isDisabled) {
178
      if (changes.isDisabled.currentValue == true) {
179
        this.control.disable();
180
      } else if (changes.isDisabled.currentValue == false) {
181
        this.control.enable();
182
      }
183
    }
184

    
185
    if (changes.QFselected) {
186
      let value = this.control.getRawValue();
187
      if (changes.QFselected.currentValue != value.QFselected) {
188
        this.setFormValues();
189
      }
190

    
191
    }
192
    if (changes.resultTypes) {
193
      this.setFormValues();
194
    }
195
  }
196

    
197
  setFormValues() {
198
    this.control.setValue({
199
      publication: (this.resultTypes && this.resultTypes.publication)?this.resultTypes.publication:null,
200
      dataset: (this.resultTypes && this.resultTypes.dataset)?this.resultTypes.dataset:null,
201
      software: (this.resultTypes && this.resultTypes.software)?this.resultTypes.software:null,
202
      other: (this.resultTypes && this.resultTypes.other)?this.resultTypes.other:null,
203
      QFselected: this.QFselected
204
    });
205
    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;
206
  }
207

    
208
  clearTypes(){
209
    this.resultTypes.publication = false;
210
    this.resultTypes.dataset = false;
211
    this.resultTypes.software = false;
212
    this.resultTypes.other = false;
213
    this.setFormValues();
214
    this.changed()
215
  }
216

    
217
}
(24-24/55)