Project

General

Profile

1
import {Component, EventEmitter, Input, Output, ViewChild} from '@angular/core';
2
import {FormBuilder} from "@angular/forms";
3
import {EnvProperties} from "../../utils/properties/env-properties";
4
import {SearchCustomFilter} from "./searchUtils.class";
5
import {ConfigurationService} from "../../utils/configuration/configuration.service";
6
import {Router} from "@angular/router";
7
import {LoginErrorCodes} from "../../login/utils/guardHelper.class";
8
import {MatSelect} from "@angular/material";
9
import {properties} from "../../../../environments/environment";
10
import {Subscription} from "rxjs";
11

    
12
@Component({
13
  selector: 'entities-selection',
14
  template: `
15
    <span *ngIf="!disableSelect && show>1 && selectedEntity"
16
          class=" entitiesSelection portal-box uk-text-small clickable" style=""
17
          (click)="open()">
18
      <mat-select *ngIf="!onlyresults" [(value)]="selectedEntity"
19
                  (valueChange)="entityChanged()" [disableOptionCentering]="true" [panelClass]="matPanelClass">
20
        <mat-option *ngIf="simpleView && showAll"
21
            value="all">All content
22
        </mat-option>
23
        <mat-option *ngIf="showResearchOutcomes" value="result">Research outcomes</mat-option>
24
        <mat-option *ngIf="showProjects" value="project">Projects</mat-option>
25
        <mat-option *ngIf="showDataProviders" value="dataprovider">Content providers</mat-option>
26
        <mat-option *ngIf="showOrganizations" value="organization">Organizations</mat-option>
27
      </mat-select>
28
      <mat-select *ngIf="onlyresults" [(value)]="selectedEntity"
29
                  (valueChange)="entityChanged()" [disableOptionCentering]="true" [panelClass]="matPanelClass">
30
        <mat-option
31
            *ngIf="simpleView && showAll"
32
            value="all">All research outcomes
33
        </mat-option>
34
        <mat-option *ngIf="showPublications" value="publications">Publications</mat-option>
35
        <mat-option *ngIf="showDatasets" value="datasets">Datasets</mat-option>
36
        <mat-option *ngIf="showSoftware" value="software">Software</mat-option>
37
        <mat-option *ngIf="showOther" value="other">Other Research products</mat-option>
38
      </mat-select>
39
      
40
     </span>
41
    <span *ngIf="currentEntity && disableSelect" class="entitiesSelection portal-box uk-text-small " style="">
42
      <div>
43
        <span *ngIf="currentEntity=='all'">{{onlyresults ? 'All research outcomes' : 'All content'}}</span>
44
        <span *ngIf="currentEntity=='result'">Research outcomes</span>
45
        <span *ngIf="currentEntity=='project'">Projects</span>
46
        <span *ngIf="currentEntity=='dataprovider'">Content providers</span>
47
        <span *ngIf="currentEntity=='organization'">Organizations</span>
48
        <span *ngIf="currentEntity=='publications'">Publications</span>
49
        <span *ngIf="currentEntity=='datasets'">Datasets</span>
50
        <span *ngIf="currentEntity=='software'">Software</span>
51
        <span *ngIf="currentEntity=='other'">Other Research products</span>
52
      </div>
53
     </span>
54
    <!--<span *ngIf="onlyresults && !disableSelect">
55
     <select *ngIf="show" [(ngModel)]="selectedEntity" class="uk-select uk-width-auto  portal-box uk-text-small" (ngModelChange)="entityChanged()" >
56
       <option
57
         *ngIf="simpleView && (show)>1 && !(this.customFilter && this.customFilter.queryFieldName=='communityId' )"
58
         value="all">All research outcomes
59
       </option>
60
       <option *ngIf="showPublications" value="publications">Publications</option>
61
       <option *ngIf="showDatasets" value="datasets">Datasets</option>
62
       <option *ngIf="showSoftware" value="software">Software</option>
63
       <option *ngIf="showOther" value="other">Other Research products</option>
64
       </select>
65
   </span>-->
66
  
67
  
68
  
69
  
70
  `
71
})
72

    
73
export class EntitiesSelectionComponent {
74
  
75
  showResearchOutcomes: boolean = false;
76
  showPublications: boolean = false;
77
  showDatasets: boolean = false;
78
  showSoftware: boolean = false;
79
  showOther: boolean = false;
80
  showProjects: boolean = false;
81
  showDataProviders: boolean = false;
82
  showOrganizations: boolean = false;
83
  showAll: boolean = true;
84
  @Input() properties: EnvProperties;
85
  @Input() customFilter: SearchCustomFilter = null;
86
  @Input() @Output() selectedEntity = "Research Outcomes";
87
  @Input() currentEntity = "Research Outcomes";
88
  @Input() simpleView: boolean = true;
89
  @Input() onChangeNavigate: boolean = true;
90
  @Output() selectionChange = new EventEmitter();
91
  @Input() onlyresults: boolean = false;
92
  @Input() matPanelClass = "matSelectionPanel";
93
  @Input() disableSelect: boolean = false;
94
  show = 0;
95
  @ViewChild(MatSelect) matSelect: MatSelect;
96

    
97
  subs: Subscription[] = [];
98

    
99
  constructor(private _fb: FormBuilder, private config: ConfigurationService, private router: Router) {
100
  
101
  
102
  }
103
  
104
  
105
  ngOnInit() {
106
    this.show = 0;
107
    if (this.properties) {
108
      if((this.customFilter && this.customFilter.queryFieldName == "communityId") || this.properties.adminToolsCommunity !== "monitor") {
109
        //this.config.getCommunityInformation(this.properties, (this.customFilter && this.customFilter.queryFieldName == "communityId") ? this.customFilter.valueId : this.properties.adminToolsCommunity).subscribe(data => {
110
        this.subs.push(this.config.communityInformationState.subscribe(data => {
111
          if(data) {
112
            let showEntity = {};
113
            let showPage = {};
114
            for (let i = 0; i < data['entities'].length; i++) {
115

    
116
              showEntity["" + data['entities'][i]["pid"] + ""] = data['entities'][i]["isEnabled"];
117
            }
118
            for (let i = 0; i < data['pages'].length; i++) {
119
              showPage["" + data['pages'][i]["route"] + ""] = data['pages'][i]["isEnabled"];
120
            }
121
            this.showResearchOutcomes = showPage[this.properties.searchLinkToResults] && (showEntity["publication"] || showEntity["dataset"] || showEntity["software"] || showEntity["orp"]);
122
            this.showPublications = showPage[this.properties.searchLinkToResults] && showEntity["publication"];
123
            this.showDatasets = showPage[this.properties.searchLinkToResults] && showEntity["dataset"];
124
            this.showSoftware = showPage[this.properties.searchLinkToResults] && showEntity["software"];
125
            this.showOther = showPage[this.properties.searchLinkToResults] && showEntity["orp"];
126
            this.showProjects = showPage[this.properties.searchLinkToProjects] && showEntity["project"];
127
            this.showOrganizations = showPage[this.properties.searchLinkToOrganizations] && showEntity["organization"];
128
            this.showDataProviders = showPage[this.properties.searchLinkToDataProviders] && showEntity["datasource"];
129
            if (this.customFilter && this.customFilter.queryFieldName == "communityId") {
130
              this.showOrganizations = false;
131
              if (!this.simpleView) {
132
                this.showProjects = false;
133
                this.showDataProviders = false;
134
              }
135
            }
136
            if (this.showResearchOutcomes) {
137
              this.show++;
138
            }
139
            if (this.showDataProviders) {
140
              this.show++;
141
            }
142
            if (this.showOrganizations) {
143
              this.show++;
144
            }
145
            if (this.showProjects) {
146
              this.show++;
147
            }
148
            if (this.show == 1) {
149
              this.disableSelect = true;
150
            }
151
          }
152
        }));
153
      } else if((this.customFilter && this.customFilter.queryFieldName == "communityId") && this.properties.adminToolsCommunity === "monitor") {
154
        this.show = 1;
155
        this.disableSelect = true;
156
      } else if(this.customFilter && (this.customFilter.queryFieldName == "relfunderid" || this.customFilter.queryFieldName == "funderid")) {
157
        /*this.showResearchOutcomes = true;
158
        this.showPublications = true;
159
        this.showDatasets = true;
160
        this.showSoftware = true;
161
        this.showOther = true;
162
        this.showProjects = true;
163
        this.showAll = false;
164
        this.show = 2;*/
165
        this.show = 1;
166
        this.disableSelect = true;
167
      } else if(this.customFilter && this.customFilter.queryFieldName == "relorganizationid") {
168
        /*this.showResearchOutcomes = true;
169
        this.showPublications = true;
170
        this.showDatasets = true;
171
        this.showSoftware = true;
172
        this.showOther = true;
173
        this.showProjects = true;
174
        this.showDataProviders = true;
175
        this.showAll = false;
176
        this.show = 3;*/
177
        this.show = 1;
178
        this.disableSelect = true;
179
      } else {
180
        this.showResearchOutcomes = true;
181
        this.showPublications = true;
182
        this.showDatasets = true;
183
        this.showSoftware = true;
184
        this.showOther = true;
185
        this.showProjects = true;
186
        this.showOrganizations = true;
187
        this.showDataProviders = true;
188
        this.showAll = false;
189
        this.show = 4;
190
      }
191
    }
192
    this.selectedEntity = this.currentEntity;
193
    this.selectionChange.emit({
194
      entity: this.selectedEntity,
195
      simpleUrl: this.getUrl(true),
196
      advancedUrl: this.getUrl(false)
197
    });
198
  }
199

    
200
  public ngOnDestroy() {
201
    for (let sub of this.subs) {
202
      sub.unsubscribe();
203
    }
204
  }
205
  
206
  entityChanged() {
207
    if (!this.simpleView || this.onChangeNavigate) {
208
      this.router.navigate([this.getUrl(this.simpleView)]);
209
    } else {
210
      this.selectionChange.emit({
211
        entity: this.selectedEntity,
212
        simpleUrl: this.getUrl(true),
213
        advancedUrl: this.getUrl(false)
214
      });
215
    }
216
    
217
  }
218
  
219
  getUrl(simpleView: boolean) {
220
    let url = "";
221
    if (!this.onlyresults) {
222
      if (this.selectedEntity == "all") {
223
        url = (simpleView ? "/search/find/" : null);
224
      } else if (this.selectedEntity == "result") {
225
        url = (simpleView ? this.properties.searchLinkToResults : this.properties.searchLinkToAdvancedResults);
226
      } else if (this.selectedEntity == "project") {
227
        url = (simpleView ? this.properties.searchLinkToProjects : this.properties.searchLinkToAdvancedProjects);
228
      } else if (this.selectedEntity == "dataprovider") {
229
        url = (simpleView ? this.properties.searchLinkToDataProviders : this.properties.searchLinkToAdvancedDataProviders);
230
      } else if (this.selectedEntity == "organization") {
231
        url = (simpleView ? this.properties.searchLinkToOrganizations : this.properties.searchLinkToAdvancedOrganizations);
232
      }
233
    } else {
234
      url = (simpleView ? this.properties.searchLinkToResults : this.properties.searchLinkToAdvancedResults);
235
    }
236
    return url;
237
  }
238
  
239
  toggle() {
240
    if (this.matSelect) {
241
      this.matSelect.toggle();
242
    }
243
  }
244
  
245
  open() {
246
    if (this.matSelect && !this.matSelect.focused) {
247
      this.matSelect.open();
248
    }
249
  }
250
  
251
}
(14-14/55)