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.simpleView?this.properties.searchLinkToResults:this.properties.searchLinkToAdvancedResults] && (showEntity["publication"] || showEntity["dataset"] || showEntity["software"] || showEntity["orp"]);
122
            this.showPublications = showPage[this.simpleView?this.properties.searchLinkToResults:this.properties.searchLinkToAdvancedResults] && showEntity["publication"];
123
            this.showDatasets = showPage[this.simpleView?this.properties.searchLinkToResults:this.properties.searchLinkToAdvancedResults] && showEntity["dataset"];
124
            this.showSoftware = showPage[this.simpleView?this.properties.searchLinkToResults:this.properties.searchLinkToAdvancedResults] && showEntity["software"];
125
            this.showOther = showPage[this.simpleView?this.properties.searchLinkToResults:this.properties.searchLinkToAdvancedResults] && showEntity["orp"];
126
            this.showProjects = showPage[this.simpleView?this.properties.searchLinkToProjects:this.properties.searchLinkToAdvancedProjects] && showEntity["project"];
127
            this.showOrganizations = showPage[this.simpleView?this.properties.searchLinkToOrganizations:this.properties.searchLinkToAdvancedOrganizations] && showEntity["organization"];
128
            this.showDataProviders = showPage[this.simpleView?this.properties.searchLinkToDataProviders:this.properties.searchLinkToAdvancedDataProviders] && showEntity["datasource"];
129
            if (this.customFilter && this.customFilter.queryFieldName == "communityId" ||  this.properties.adminToolsCommunity === "connect") {
130
              //for community pages: no organization in simple search, only results in advanced
131
              this.showAll = false;
132
              this.showOrganizations = false;
133
              if (!this.simpleView) {
134
                this.showProjects = false;
135
                this.showDataProviders = false;
136
              }
137
            }
138
            if (this.showResearchOutcomes) {
139
              this.show++;
140
            }
141
            if (this.showDataProviders) {
142
              this.show++;
143
            }
144
            if (this.showOrganizations) {
145
              this.show++;
146
            }
147
            if (this.showProjects) {
148
              this.show++;
149
            }
150
            if (this.show == 1) {
151
              this.disableSelect = true;
152
            }
153
          }
154
        }));
155
      } else if((this.customFilter && this.customFilter.queryFieldName == "communityId") && this.properties.adminToolsCommunity === "monitor") {
156
        this.show = 1;
157
        this.disableSelect = true;
158
      } else if(this.customFilter && (this.customFilter.queryFieldName == "relfunderid" || this.customFilter.queryFieldName == "funderid")) {
159
        /*this.showResearchOutcomes = true;
160
        this.showPublications = true;
161
        this.showDatasets = true;
162
        this.showSoftware = true;
163
        this.showOther = true;
164
        this.showProjects = true;
165
        this.showAll = false;
166
        this.show = 2;*/
167
        this.show = 1;
168
        this.disableSelect = true;
169
      } else if(this.customFilter && this.customFilter.queryFieldName == "relorganizationid") {
170
        /*this.showResearchOutcomes = true;
171
        this.showPublications = true;
172
        this.showDatasets = true;
173
        this.showSoftware = true;
174
        this.showOther = true;
175
        this.showProjects = true;
176
        this.showDataProviders = true;
177
        this.showAll = false;
178
        this.show = 3;*/
179
        this.show = 1;
180
        this.disableSelect = true;
181
      } else {
182
        this.showResearchOutcomes = true;
183
        this.showPublications = true;
184
        this.showDatasets = true;
185
        this.showSoftware = true;
186
        this.showOther = true;
187
        this.showProjects = true;
188
        this.showOrganizations = true;
189
        this.showDataProviders = true;
190
        this.showAll = false;
191
        this.show = 4;
192
      }
193
    }
194
    this.selectedEntity = this.currentEntity;
195
    this.selectionChange.emit({
196
      entity: this.selectedEntity,
197
      simpleUrl: this.getUrl(true),
198
      advancedUrl: this.getUrl(false)
199
    });
200
  }
201

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