Project

General

Profile

1 59632 argiro.kok
import {ChangeDetectorRef, Component, EventEmitter, Input, Output} from '@angular/core';
2
import {FormBuilder} from "@angular/forms";
3 58072 argiro.kok
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 59632 argiro.kok
import {Subscription} from "rxjs";
7
import {ActivatedRoute, Router} from "@angular/router";
8 50169 argiro.kok
9
@Component({
10 58072 argiro.kok
  selector: 'quick-selections',
11
  template: `
12 59632 argiro.kok
    <div *ngIf="!vertical && (resultTypes || quickFilter)"
13 59074 konstantin
          [class]="(isDisabled ? 'uk-disabled' : '') + ' uk-text-small uk-margin-small-bottom uk-grid uk-inline uk-flex uk-margin-small-left'">
14 58525 argiro.kok
      <div  *ngIf="quickFilter" class="uk-margin-small-top uk-padding-remove-left uk-margin-right ">
15 58093 argiro.kok
        <span class="uk-text-bold">{{quickFilter.value}}</span>
16
        <mat-slide-toggle
17 59632 argiro.kok
                          class="uk-margin-small-left" name="qf" [(ngModel)]="quickFilter.selected" (ngModelChange)="quickFilterChanged()">
18 58072 argiro.kok
        </mat-slide-toggle>
19
      </div>
20 58525 argiro.kok
      <div *ngIf="resultTypes && showEntities" class="uk-margin-small-top uk-padding-remove-left">
21 58093 argiro.kok
        <span class="uk-text-muted">Include: </span>
22 58525 argiro.kok
        <span>
23 59632 argiro.kok
          <ng-container *ngFor="let value of resultTypes.values">
24 59945 k.triantaf
            <span class="uk-margin-small-left">
25
              <input #input type="checkbox" class="uk-checkbox" [(ngModel)]="value.selected" (ngModelChange)="changed()"/>
26
              <span class="space clickable" (click)="input.click()">{{value.name}}</span>
27
            </span>
28 59632 argiro.kok
          </ng-container>
29 58525 argiro.kok
        </span>
30 58093 argiro.kok
      </div>
31 59632 argiro.kok
    </div>
32
    <div *ngIf="vertical && (resultTypes || quickFilter)"
33 59074 konstantin
          [class]="(isDisabled ? 'uk-disabled' : '') + ' uk-margin-small-bottom uk-list uk-list-divider'">
34 59632 argiro.kok
      <search-filter
35
                     [isDisabled]="isDisabled"
36
                     [filter]="resultTypes" [showResultCount]='false'
37
                     (onFilterChange)="changed()" [actionRoute]="actionRoute"></search-filter>
38
    </div>
39
40 58072 argiro.kok
  `
41
})
42 50169 argiro.kok
43 59632 argiro.kok
export class QuickSelectionsComponent {
44
  @Input() resultTypes:Filter;
45 58072 argiro.kok
  @Output() typeChange = new EventEmitter();
46
  @Input() isDisabled;
47
  @Input() quickFilter: { filter: Filter, selected: boolean, filterId: string, value: string };
48
  initialized = false;
49 58093 argiro.kok
  @Input() properties: EnvProperties;
50 58815 argiro.kok
  @Input() vertical: boolean=false;
51 58093 argiro.kok
  showPublications:boolean= false;
52
  showDatasets:boolean= false;
53
  showSoftware: boolean = false;
54
  showOrp: boolean = false;
55
  showEntities = false;
56 59632 argiro.kok
  @Input() actionRoute:boolean = false;
57
  queryParams = {};
58 59074 konstantin
59
  subs: Subscription[] = [];
60
61 59632 argiro.kok
  constructor(private _fb: FormBuilder, private config: ConfigurationService, private _router: Router, private route: ActivatedRoute, private cdr:ChangeDetectorRef) {
62 58072 argiro.kok
  }
63
64 58348 argiro.kok
  changed() {
65
66 58072 argiro.kok
    this.typeChange.emit({});
67
  }
68 50169 argiro.kok
69 58072 argiro.kok
  quickFilterChanged() {
70 58093 argiro.kok
    if(this.quickFilter.filter) {
71 58348 argiro.kok
      this.quickFilter.filter.countSelectedValues = 0;
72 59632 argiro.kok
      if (this.quickFilter.selected) {
73 58093 argiro.kok
        for (let filterValue of this.quickFilter.filter.values) {
74 58156 argiro.kok
          if((filterValue.name == this.quickFilter.value)) {
75
            filterValue.selected = true
76
            this.quickFilter.filter.countSelectedValues = 1;
77
          }else{
78
            filterValue.selected = false;
79
          }
80 58093 argiro.kok
        }
81
      } else {
82
        for (let filterValue of this.quickFilter.filter.values) {
83
          filterValue.selected = false;
84
        }
85 58072 argiro.kok
      }
86
    }
87
    this.typeChange.emit({});
88
  }
89 50169 argiro.kok
90 58072 argiro.kok
  ngOnInit() {
91 59816 argiro.kok
    this.subs.push(this.route.queryParams.subscribe(params => {
92 59632 argiro.kok
      this.queryParams = Object.assign({}, params);
93
      this.initializeFilters();
94 59816 argiro.kok
    }));
95 59966 argiro.kok
   //Allow all types
96
   /* if(this.properties && !this.initialized) {
97
      if(this.properties.adminToolsCommunity !== "monitor") {
98 59632 argiro.kok
         this.subs.push(this.config.communityInformationState.subscribe(data => {
99 59074 konstantin
          if(data) {
100
            var showEntity = {};
101
            for (var i = 0; i < data['entities'].length; i++) {
102
              showEntity["" + data['entities'][i]["pid"] + ""] = data['entities'][i]["isEnabled"];
103
            }
104
            this.showPublications = showEntity["publication"];
105
            this.showDatasets = showEntity["dataset"];
106
            this.showSoftware = showEntity["software"];
107
            this.showOrp = showEntity["orp"];
108
            this.showEntities = this.showPublications || this.showDatasets || this.showSoftware || this.showOrp;
109 59632 argiro.kok
            this.initialized = true;
110
            this.initializeFilters();
111 59007 k.triantaf
          }
112
        }, error => {
113
          this.showPublications = true;
114
          this.showDatasets = true;
115
          this.showSoftware = true;
116
          this.showOrp = true;
117
          this.showEntities = true;
118 59632 argiro.kok
          this.initializeFilters();
119 59074 konstantin
        }));
120 59966 argiro.kok
      } else {*/
121 59007 k.triantaf
        this.showPublications = true;
122
        this.showDatasets = true;
123
        this.showSoftware = true;
124
        this.showOrp = true;
125
        this.showEntities = true;
126 59632 argiro.kok
        this.initialized = true;
127
        this.initializeFilters();
128 59966 argiro.kok
      /*}
129 59632 argiro.kok
130
    }else{
131
      this.initializeFilters();
132 59966 argiro.kok
     }*/
133 58348 argiro.kok
134 58072 argiro.kok
  }
135 59632 argiro.kok
  initializeFilters(){
136
    if(this.showEntities ){
137
      let selected = [];
138
      for(let value of this.resultTypes.values){
139
        if(value.selected){
140
          selected.push(value.id);
141
        }
142
      }
143
      this.resultTypes.countSelectedValues = selected.length;
144
      this.resultTypes.values = [];
145
      if(this.showPublications){
146
        this.resultTypes.values.push({name: "Publications" , id:"publications",selected:selected.indexOf("publications")!=-1, number:0});
147
      }
148
      if(this.showDatasets){
149
        this.resultTypes.values.push({name: "Research data" , id:"datasets",selected:selected.indexOf("datasets")!=-1, number:0});
150
      }
151
      if(this.showSoftware){
152
        this.resultTypes.values.push({name: "Software" , id:"software",selected:selected.indexOf("software")!=-1, number:0});
153
      }
154
      if(this.showOrp){
155
        this.resultTypes.values.push({name: "Other research products" , id:"other",selected:selected.indexOf("other")!=-1, number:0});
156
      }
157
    }
158
    this.typeChange.emit("filters_update");
159
  }
160 59074 konstantin
  public ngOnDestroy() {
161
    for (let sub of this.subs) {
162
      sub.unsubscribe();
163
    }
164
  }
165 50169 argiro.kok
}