Project

General

Profile

1
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">  <input  type="checkbox" class="uk-checkbox"
25
                                                        [(ngModel)]="value.selected" (ngModelChange)="changed()" />{{value.name}}</span>
26
          </ng-container>
27
        </span>
28
      </div>
29
    </div>
30
    <div *ngIf="vertical && (resultTypes || quickFilter)"  
31
          [class]="(isDisabled ? 'uk-disabled' : '') + ' uk-margin-small-bottom uk-list uk-list-divider'">
32
      <search-filter 
33
                     [isDisabled]="isDisabled"
34
                     [filter]="resultTypes" [showResultCount]='false'
35
                     (onFilterChange)="changed()" [actionRoute]="actionRoute"></search-filter>
36
    </div>
37
 
38
  `
39
})
40

    
41
export class QuickSelectionsComponent {
42
  @Input() resultTypes:Filter;
43
  @Output() typeChange = new EventEmitter();
44
  @Input() isDisabled;
45
  @Input() quickFilter: { filter: Filter, selected: boolean, filterId: string, value: string };
46
  initialized = false;
47
  @Input() properties: EnvProperties;
48
  @Input() vertical: boolean=false;
49
  showPublications:boolean= false;
50
  showDatasets:boolean= false;
51
  showSoftware: boolean = false;
52
  showOrp: boolean = false;
53
  showEntities = false;
54
  @Input() actionRoute:boolean = false;
55
  queryParams = {};
56

    
57
  subs: Subscription[] = [];
58

    
59
  constructor(private _fb: FormBuilder, private config: ConfigurationService, private _router: Router, private route: ActivatedRoute, private cdr:ChangeDetectorRef) {
60
  }
61

    
62
  changed() {
63

    
64
    this.typeChange.emit({});
65
  }
66

    
67
  quickFilterChanged() {
68
    if(this.quickFilter.filter) {
69
      this.quickFilter.filter.countSelectedValues = 0;
70
      if (this.quickFilter.selected) {
71
        for (let filterValue of this.quickFilter.filter.values) {
72
          if((filterValue.name == this.quickFilter.value)) {
73
            filterValue.selected = true
74
            this.quickFilter.filter.countSelectedValues = 1;
75
          }else{
76
            filterValue.selected = false;
77
          }
78
        }
79
      } else {
80
        for (let filterValue of this.quickFilter.filter.values) {
81
          filterValue.selected = false;
82
        }
83
      }
84
    }
85
    this.typeChange.emit({});
86
  }
87

    
88
  ngOnInit() {
89
    this.subs.push(this.route.queryParams.subscribe(params => {
90
      this.queryParams = Object.assign({}, params);
91
      this.initializeFilters();
92
    }));
93

    
94
    if(this.properties && !this.initialized) {
95
      if(this.properties.adminToolsCommunity !== "monitor") {
96
         this.subs.push(this.config.communityInformationState.subscribe(data => {
97
          if(data) {
98
            var showEntity = {};
99
            for (var i = 0; i < data['entities'].length; i++) {
100
              showEntity["" + data['entities'][i]["pid"] + ""] = data['entities'][i]["isEnabled"];
101
            }
102
            this.showPublications = showEntity["publication"];
103
            this.showDatasets = showEntity["dataset"];
104
            this.showSoftware = showEntity["software"];
105
            this.showOrp = showEntity["orp"];
106
            this.showEntities = this.showPublications || this.showDatasets || this.showSoftware || this.showOrp;
107
            this.initialized = true;
108
            this.initializeFilters();
109
          }
110
        }, error => {
111
          this.showPublications = true;
112
          this.showDatasets = true;
113
          this.showSoftware = true;
114
          this.showOrp = true;
115
          this.showEntities = true;
116
          this.initializeFilters();
117
        }));
118
      } else {
119
        this.showPublications = true;
120
        this.showDatasets = true;
121
        this.showSoftware = true;
122
        this.showOrp = true;
123
        this.showEntities = true;
124
        this.initialized = true;
125
        this.initializeFilters();
126
      }
127

    
128
    }else{
129
      this.initializeFilters();
130
    }
131

    
132
  }
133
  initializeFilters(){
134
    if(this.showEntities ){
135
      let selected = [];
136
      for(let value of this.resultTypes.values){
137
        if(value.selected){
138
          selected.push(value.id);
139
        }
140
      }
141
      this.resultTypes.countSelectedValues = selected.length;
142
      this.resultTypes.values = [];
143
      if(this.showPublications){
144
        this.resultTypes.values.push({name: "Publications" , id:"publications",selected:selected.indexOf("publications")!=-1, number:0});
145
      }
146
      if(this.showDatasets){
147
        this.resultTypes.values.push({name: "Research data" , id:"datasets",selected:selected.indexOf("datasets")!=-1, number:0});
148
      }
149
      if(this.showSoftware){
150
        this.resultTypes.values.push({name: "Software" , id:"software",selected:selected.indexOf("software")!=-1, number:0});
151
      }
152
      if(this.showOrp){
153
        this.resultTypes.values.push({name: "Other research products" , id:"other",selected:selected.indexOf("other")!=-1, number:0});
154
      }
155
    }
156
    this.typeChange.emit("filters_update");
157
  }
158
  public ngOnDestroy() {
159
    for (let sub of this.subs) {
160
      sub.unsubscribe();
161
    }
162
  }
163
}
(21-21/47)