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

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

    
64

    
65

    
66

    
67
  `
68
})
69

    
70
export class EntitiesSelectionComponent {
71

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

    
93
  constructor(private _fb: FormBuilder, private config: ConfigurationService, private router: Router) {
94

    
95

    
96
  }
97

    
98

    
99
  ngOnInit() {
100
    this.show = 0;
101
    if (this.properties) {
102
      // console.log(this.customFilter)
103
      this.config.getCommunityInformation(this.properties, (this.customFilter && this.customFilter.queryFieldName == "communityId") ? this.customFilter.valueId : this.properties.adminToolsCommunity).subscribe(data => {
104
        var showEntity = {};
105
        for (var i = 0; i < data['entities'].length; i++) {
106

    
107
          showEntity["" + data['entities'][i]["pid"] + ""] = data['entities'][i]["isEnabled"];
108
        }
109
        this.showResearchOutcomes = showEntity["publication"] || showEntity["dataset"] || showEntity["software"] || showEntity["orp"];
110
        this.showPublications = showEntity["publication"];
111
        this.showDatasets = showEntity["dataset"];
112
        this.showSoftware = showEntity["software"];
113
        this.showOther = showEntity["orp"];
114
        this.showProjects = showEntity["project"];
115
        this.showOrganizations = showEntity["organization"];
116
        this.showDataProviders = showEntity["datasource"];
117

    
118
        if (this.customFilter && this.customFilter.queryFieldName == "communityId") {
119
          this.showOrganizations = false;
120
          if(!this.simpleView){
121
            this.showProjects = false;
122
            this.showDataProviders = false;
123
          }
124
        }
125
        if(this.showResearchOutcomes){
126
          this.show++;
127
        }
128
        if(this.showDataProviders){
129
          this.show++;
130
        }
131
        if(this.showOrganizations){
132
          this.show++;
133
        }
134
        if(this.showProjects){
135
          this.show++;
136
        }
137
        if(this.show ==1){
138
          this.disableSelect = true;
139
        }
140
      });
141
    }
142
    this.selectedEntity = this.currentEntity;
143
    this.selectionChange.emit({
144
      entity: this.selectedEntity,
145
      simpleUrl: this.getUrl(true),
146
      advancedUrl: this.getUrl(false)
147
    });
148
  }
149

    
150

    
151
  entityChanged() {
152

    
153
    if (!this.simpleView || this.onChangeNavigate) {
154
      this.router.navigate([this.getUrl(this.simpleView)]);
155
    } else {
156
      this.selectionChange.emit({
157
        entity: this.selectedEntity,
158
        simpleUrl: this.getUrl(true),
159
        advancedUrl: this.getUrl(false)
160
      });
161
    }
162

    
163
  }
164

    
165
  getUrl(simpleView: boolean) {
166
    let url = "";
167
    if(!this.onlyresults) {
168
      if (this.selectedEntity == "all") {
169
        url = (simpleView ? "/search/find/" : null);
170
      } else if (this.selectedEntity == "result") {
171
        url = (simpleView ? this.properties.searchLinkToResults : this.properties.searchLinkToAdvancedResults);
172
      } else if (this.selectedEntity == "project") {
173
        url = (simpleView ? this.properties.searchLinkToProjects : this.properties.searchLinkToAdvancedProjects);
174
      } else if (this.selectedEntity == "dataprovider") {
175
        url = (simpleView ? this.properties.searchLinkToDataProviders : this.properties.searchLinkToAdvancedDataProviders);
176
      } else if (this.selectedEntity == "organization") {
177
        url = (simpleView ? this.properties.searchLinkToOrganizations : this.properties.searchLinkToAdvancedOrganizations);
178
      }
179
    }else{
180
      url = (simpleView ? this.properties.searchLinkToResults : this.properties.searchLinkToAdvancedResults);
181
    }
182
    return url;
183
  }
184
  toggle(){
185
    if(this.matSelect) {
186
      this.matSelect.toggle();
187
    }
188
  }
189
  open(){
190
    if(this.matSelect && !this.matSelect.focused) {
191
      this.matSelect.open();
192
    }
193
  }
194

    
195
}
(17-17/55)