Project

General

Profile

1
import {Component, EventEmitter, Input, OnChanges, Output, SimpleChanges} 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 {RouterHelper} from "../../utils/routerHelper.class";
7
import {Router} from "@angular/router";
8

    
9
@Component({
10
  selector: 'entities-selection',
11
  template: `
12
     <span  class="entitiesSelection portal-box uk-text-small " style="" >
13
      <mat-select *ngIf="show && selectedEntity" [(value)]="selectedEntity"
14
                 (valueChange)="entityChanged()" [disableOptionCentering]="true" panelClass="matSelectionPanel">
15
        <mat-option
16
          *ngIf="simpleView && (showResearchOutcomes + showDataProviders + showOrganizations + showProjects )>1 "
17
          value="all">All content
18
        </mat-option>
19
        <mat-option *ngIf="showResearchOutcomes" value="result">Research outcomes</mat-option>
20
        <mat-option *ngIf="showProjects" value="project">Projects</mat-option>
21
        <mat-option *ngIf="showDataProviders" value="dataprovider">Content providers</mat-option>
22
        <mat-option *ngIf="showOrganizations" value="organization">Organizations</mat-option>
23
      </mat-select>
24
      <mat-select *ngIf="!show && currentEntity" [(value)]="selectedEntity">
25
        <mat-option [value]="selectedEntity">
26
          <span *ngIf="currentEntity=='all'">All content</span>
27
          <span *ngIf="currentEntity=='result'">Research outcomes</span>
28
          <span *ngIf="currentEntity=='project'">Projects</span>
29
          <span *ngIf="currentEntity=='dataprovider'">Content providers</span>
30
          <span *ngIf="currentEntity=='organization'">Organizations</span>
31
        </mat-option>
32

    
33
      </mat-select>
34
    </span>
35

    
36

    
37

    
38

    
39
  `
40
})
41

    
42
export class EntitiesSelectionComponent {
43

    
44
  showResearchOutcomes: boolean = false;
45
  showProjects: boolean = false;
46
  showDataProviders: boolean = false;
47
  showOrganizations: boolean = false;
48
  @Input() properties: EnvProperties;
49
  @Input() customFilter: SearchCustomFilter = null;
50
  @Input() @Output() selectedEntity = "Research Outcomes";
51
  @Input() currentEntity = "Research Outcomes";
52
  @Input() simpleView: boolean = true;
53
  @Input() onChangeNavigate: boolean = true;
54
  @Output() selectionChange = new EventEmitter();
55
  show = false;
56

    
57
  constructor(private _fb: FormBuilder, private config: ConfigurationService, private router: Router) {
58

    
59

    
60
  }
61

    
62

    
63
  ngOnInit() {
64
    if (this.properties) {
65
      this.config.getCommunityInformation(this.properties, (this.customFilter && this.customFilter.queryFieldName == "communitId") ? this.customFilter.valueId : this.properties.adminToolsCommunity).subscribe(data => {
66
        var showEntity = {};
67
        for (var i = 0; i < data['entities'].length; i++) {
68

    
69
          showEntity["" + data['entities'][i]["pid"] + ""] = data['entities'][i]["isEnabled"];
70
        }
71
        this.showResearchOutcomes = showEntity["publication"] || showEntity["dataset"] || showEntity["software"] || showEntity["orp"];
72
        this.showProjects = showEntity["project"];
73
        this.showOrganizations = showEntity["organization"];
74
        this.showDataProviders = showEntity["datasource"];
75

    
76
        if (this.customFilter && this.customFilter.queryFieldName == "communityId") {
77
          this.showProjects = false;
78
          this.showOrganizations = false;
79
          this.showDataProviders = false;
80
        }
81
        this.show = true;
82
      });
83
    }
84
    this.selectedEntity = this.currentEntity;
85
    this.selectionChange.emit({
86
      entity: this.selectedEntity,
87
      simpleUrl: this.getUrl(true),
88
      advancedUrl: this.getUrl(false)
89
    });
90
  }
91

    
92

    
93
  entityChanged() {
94

    
95
    if (!this.simpleView || this.onChangeNavigate) {
96
      this.router.navigate([this.getUrl(this.simpleView)]);
97
    } else {
98
      this.selectionChange.emit({
99
        entity: this.selectedEntity,
100
        simpleUrl: this.getUrl(true),
101
        advancedUrl: this.getUrl(false)
102
      });
103
    }
104

    
105
  }
106

    
107
  getUrl(simpleView: boolean) {
108
    let url = "";
109
    if (this.selectedEntity == "all") {
110
      url = (simpleView ? "/search/find/" : null);
111
    } else if (this.selectedEntity == "result") {
112
      url = (simpleView ? this.properties.searchLinkToResults : this.properties.searchLinkToAdvancedResults);
113
    } else if (this.selectedEntity == "project") {
114
      url = (simpleView ? this.properties.searchLinkToProjects : this.properties.searchLinkToAdvancedProjects);
115
    } else if (this.selectedEntity == "dataprovider") {
116
      url = (simpleView ? this.properties.searchLinkToDataProviders : this.properties.searchLinkToAdvancedDataProviders);
117
    } else if (this.selectedEntity == "organization") {
118
      url = (simpleView ? this.properties.searchLinkToOrganizations : this.properties.searchLinkToAdvancedOrganizations);
119
    }
120
    return url;
121
  }
122

    
123

    
124
}
(17-17/54)