Project

General

Profile

1
import {Component, ViewChild} from '@angular/core';
2
import {Subscription} from 'rxjs';
3
import {ActivatedRoute, Router} from '@angular/router';
4
import {Location} from '@angular/common';
5
import "rxjs/add/observable/zip";
6
import {Meta, Title} from '@angular/platform-browser';
7
import {ConfigurationService} from '../openaireLibrary/utils/configuration/configuration.service';
8
import {SearchDataprovidersService} from '../openaireLibrary/services/searchDataproviders.service';
9
import {SearchProjectsService} from '../openaireLibrary/services/searchProjects.service';
10
import {SearchOrganizationsService} from '../openaireLibrary/services/searchOrganizations.service';
11
import {RefineFieldResultsService} from '../openaireLibrary/services/refineFieldResults.service';
12
import {SearchFields} from '../openaireLibrary/utils/properties/searchFields';
13

    
14
import {RouterHelper} from '../openaireLibrary/utils/routerHelper.class';
15
import {EnvProperties} from '../openaireLibrary/utils/properties/env-properties';
16
import {ErrorCodes} from '../openaireLibrary/utils/properties/errorCodes';
17
import {PiwikService} from '../openaireLibrary/utils/piwik/piwik.service';
18
import {SEOService} from '../openaireLibrary/sharedComponents/SEO/SEO.service';
19
import {SearchResearchResultsService} from "../openaireLibrary/services/searchResearchResults.service";
20
import {HelperService} from "../openaireLibrary/utils/helper/helper.service";
21
import {Filter} from "../openaireLibrary/searchPages/searchUtils/searchHelperClasses.class";
22
import {AggregatorInfo, PortalAggregators} from "../utils/aggregators";
23
import {SearchCustomFilter} from "../openaireLibrary/searchPages/searchUtils/searchUtils.class";
24
import {properties} from "../../environments/environment";
25
import {portalProperties} from "../../environments/environment-aggregator";
26
import {StringUtils} from "../openaireLibrary/utils/string-utils.class";
27
import {ConnectHelper} from "../openaireLibrary/connect/connectHelper";
28
import {NumbersComponent} from "../openaireLibrary/sharedComponents/numbers/numbers.component";
29

    
30
@Component({
31
  selector: 'home',
32
  templateUrl: 'home.component.html',
33
})
34
export class HomeComponent {
35
  public keyword:string = "";
36

    
37
  public searchFields:SearchFields = new SearchFields();
38
  public errorCodes:ErrorCodes = new ErrorCodes();
39
  public routerHelper:RouterHelper = new RouterHelper();
40
  showPublications: boolean = portalProperties.entities.publication.isEnabled;
41
  showDatasets: boolean = portalProperties.entities.dataset.isEnabled;
42
  showSoftware: boolean = portalProperties.entities.software.isEnabled;
43
  showOrp: boolean = portalProperties.entities.other.isEnabled;
44
  showOrganizations: boolean = portalProperties.entities.organization.isEnabled;
45
  showProjects: boolean = portalProperties.entities.project.isEnabled;
46
  showDataProviders: boolean = portalProperties.entities.datasource.isEnabled;
47
  properties: EnvProperties = properties;
48
  public readMore: boolean = false;
49

    
50
  subs: Subscription[] = [];
51

    
52
  resultsQuickFilter: { filter: Filter, selected: boolean, filterId: string, value: string } = {
53
    filter: null,
54
    selected: true,
55
    filterId: "resultbestaccessright",
56
    value: "Open Access"
57
  };
58
  selectedEntity = "all";
59
  selectedEntitySimpleUrl;
60
  selectedEntityAdvancedUrl;
61
  resultTypes:Filter = {values:[],filterId:"type", countSelectedValues: 0, filterType: 'checkbox', originalFilterId: "", valueIsExact: true, title: "Result Types",filterOperator:"or"};
62
  public pageContents = null;
63
  customFilter:SearchCustomFilter= null;
64
  aggregatorId;
65
  aggregator:AggregatorInfo;
66
  @ViewChild('numbersComponent') numbersComponent: NumbersComponent;
67
  
68
  constructor (
69
    private route: ActivatedRoute,
70
    private _router: Router,
71
    private _searchResearchResultsService: SearchResearchResultsService,
72
    private _searchDataprovidersService: SearchDataprovidersService,
73
    private _searchProjectsService: SearchProjectsService,
74
    private _searchOrganizationsService: SearchOrganizationsService,
75
    private _refineFieldResultsService:RefineFieldResultsService,
76
    private location: Location, private _piwikService:PiwikService,
77
    private config: ConfigurationService, private _meta: Meta, private _title: Title, private seoService: SEOService,
78
    private helper: HelperService
79
  ) {
80
    this.aggregatorId = ConnectHelper.getCommunityFromDomain(properties.domain);
81
    this.aggregator =  PortalAggregators.getFilterInfoByMenuId(this.aggregatorId);
82
    this.customFilter = PortalAggregators.getSearchCustomFilterByAggregator(this.aggregator);
83
    let description = "OpenAIRE Explore: Over 100M of research deduplicated, 170K research software, 11M research data. One of the largest open scholarly records collection worldwide.";
84
    let title = "OpenAIRE - Explore| " +this.aggregator.title;
85

    
86
    this._title.setTitle(title);
87
    this._meta.updateTag({content:description},"name='description'");
88
    this._meta.updateTag({content:description},"property='og:description'");
89
    this._meta.updateTag({content:title},"property='og:title'");
90

    
91

    
92
  }
93

    
94
  private getPageContents() {
95
    this.subs.push(this.helper.getPageHelpContents(this.properties, 'openaire', this._router.url).subscribe(contents => {
96
      this.pageContents = contents;
97
    }));
98
  }
99

    
100
  public ceil(num: number) {
101
    return Math.ceil(num);
102
  }
103

    
104
  public ngOnInit() {
105
    this.seoService.createLinkForCanonicalURL(this.properties.domain + this.properties.baseLink+this._router.url, false);
106
    this.getPageContents();
107
    if(this.properties!=null){
108
      var url = this.properties.domain + this.properties.baseLink+this._router.url;
109
      this._meta.updateTag({content:url},"property='og:url'");
110
      if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){
111
        this.subs.push(this._piwikService.trackView(this.properties, "OpenAIRE").subscribe());
112
      }
113

    
114
      //this.config.getCommunityInformation(this.properties, this.properties.adminToolsCommunity ).subscribe(data => {
115
      this.subs.push(this.config.communityInformationState.subscribe(data => {
116
          if(data) {
117
            var showEntity = {};
118
            for (var i = 0; i < data['entities'].length; i++) {
119

    
120
              showEntity["" + data['entities'][i]["pid"] + ""] = data['entities'][i]["isEnabled"];
121
            }
122
            this.showPublications = !!showEntity["publication"];
123
            this.showDatasets = !!showEntity["dataset"];
124
            this.showSoftware = !!showEntity["software"];
125
            this.showOrp = !!showEntity["orp"];
126
            this.showProjects = !!showEntity["project"];
127
            this.showDataProviders = !!showEntity["datasource"];
128
            this.showOrganizations = !!showEntity["organization"];
129
            if(this.showPublications){
130
              this.resultTypes.values.push({name: "Publications" , id:"publications",selected:true, number:0});
131
            }
132
            if(this.showDatasets){
133
              this.resultTypes.values.push({name: "Research data" , id:"datasets",selected:true, number:0});
134
            }
135
            if(this.showSoftware){
136
              this.resultTypes.values.push({name: "Software" , id:"software",selected:true, number:0});
137
            }
138
            if(this.showOrp){
139
              this.resultTypes.values.push({name: "Other research products" , id:"other",selected:true, number:0});
140
            }
141
            this.numbersComponent.init(false, false, this.showPublications, this.showDatasets,
142
              this.showSoftware, this.showOrp, this.showProjects, this.showDataProviders,
143
              StringUtils.URIEncode(this.customFilter.queryFieldName + " exact " + StringUtils.quote((this.customFilter.valueId ))));
144
          }
145
        },
146
        error => {
147
          this.handleError("Error getting community information", error);
148
        }
149
      ));
150
    }
151

    
152
  }
153
  public ngOnDestroy() {
154
    for (let sub of this.subs) {
155
      sub.unsubscribe();
156
    }
157
  }
158

    
159
  private handleError(message: string, error) {
160
    console.error("Home Page: "+message, error);
161
  }
162
  entityChanged($event){
163
    this.selectedEntity = $event.entity;
164
    this.selectedEntitySimpleUrl = $event.simpleUrl;
165
    this.selectedEntityAdvancedUrl = $event.advancedUrl;
166
  }
167
  goTo(simple:boolean){
168
    let url = (simple)?this.selectedEntitySimpleUrl:this.selectedEntityAdvancedUrl;
169
    let parameterNames = [];
170
    let parameterValues = [];
171
    if (this.selectedEntity == "result") {
172
      if (this.resultTypes) {
173
        let values = [];
174
        for(let value of this.resultTypes.values){
175
          if (value.selected) {
176
            values.push(value.id);
177
          }
178
        }
179
        if (values.length > 0 && values.length !=4) {
180
          parameterNames.push("type");
181
          parameterValues.push(values.join(","));
182
        }
183
        if (this.resultsQuickFilter) {
184
          parameterNames.push("qf");
185
          parameterValues.push("" + this.resultsQuickFilter.selected);
186
        }
187
      }
188
    }else if(this.selectedEntity == "all"){
189
      if (this.resultsQuickFilter) {
190
        parameterNames.push("qf");
191
        parameterValues.push("true");
192
      }
193
    }
194
    if(this.keyword.length > 0) {
195
      parameterNames.push("fv0");
196
      parameterValues.push(this.keyword);
197
      parameterNames.push("f0");
198
      parameterValues.push("q");
199
    }
200
    if(this.customFilter){
201
      parameterNames.push(this.customFilter.queryFieldName);
202
      parameterValues.push(this.customFilter.valueId);
203
      parameterNames.push("cf");
204
      parameterValues.push("true");
205
    }
206
    this._router.navigate([url], {queryParams: this.routerHelper.createQueryParams(parameterNames, parameterValues)});
207
  }
208
  getQueryParamsForAdvancedSearch(entity){
209
    let params = {};
210
    if (entity == "result") {
211
      if (this.resultsQuickFilter) {
212
        params["qf"] = "" + this.resultsQuickFilter.selected;
213
      }
214
    }
215
    if(this.keyword.length > 0) {
216
      params["fv0"] = "" + this.keyword;
217
      params["f0"] = "q";
218
    }
219
    if(this.customFilter){
220
     params = this.customFilter.getParameters(params);
221
    }
222
    return params;
223
  }
224
}
(3-3/4)