Project

General

Profile

1
import {Component} 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 {Title, Meta}                  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
import {  NumberUtils} from '../openaireLibrary/utils/number-utils.class';
14

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

    
30
@Component({
31
  selector: 'home',
32
  templateUrl: 'home.component.html',
33
})
34
export class HomeComponent {
35

    
36

    
37
  // public pageTitle = "OpenAIRE - Explore |" ;
38
  public keyword:string = "";
39

    
40
  public searchFields:SearchFields = new SearchFields();
41
  public errorCodes:ErrorCodes = new ErrorCodes();
42
  public routerHelper:RouterHelper = new RouterHelper();
43

    
44
  public publicationsSize:any = null;
45
  public datasetsSize:any = null;
46
  public datasetsLinkedSize:any = null;
47
  public softwareLinkedSize:any = null;
48
  public softwareSize: any = null;
49
  public otherSize: any = null;
50
  public fundersSize:any = null;
51
  public projectsSize:any = null;
52
  public datasourcesSize:any = null;
53

    
54
  showPublications: boolean = portalProperties.entities.publication.isEnabled;
55
  showDatasets: boolean = portalProperties.entities.dataset.isEnabled;
56
  showSoftware: boolean = portalProperties.entities.software.isEnabled;
57
  showOrp: boolean = portalProperties.entities.other.isEnabled;
58
  showOrganizations: boolean = portalProperties.entities.organization.isEnabled;
59
  showProjects: boolean = portalProperties.entities.project.isEnabled;
60
  showDataProviders: boolean = portalProperties.entities.datasource.isEnabled;
61
  properties: EnvProperties;
62
  public readMore: boolean = false;
63

    
64
  subs: Subscription[] = [];
65

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

    
98
    this._title.setTitle(title);
99
    this._meta.updateTag({content:description},"name='description'");
100
    this._meta.updateTag({content:description},"property='og:description'");
101
    this._meta.updateTag({content:title},"property='og:title'");
102

    
103

    
104
  }
105

    
106
  private getPageContents() {
107
    this.subs.push(this.helper.getPageHelpContents(this.properties, 'openaire', this._router.url).subscribe(contents => {
108
      this.pageContents = contents;
109
    }));
110
  }
111

    
112
  public getKeys(obj: {}) {
113
    return Object.keys(obj);
114
  }
115

    
116
  createRange(number){
117
    var items: number[] = [];
118
    for(var i = 1; i <= number; i++){
119
      items.push(i);
120
    }
121
    return items;
122
  }
123

    
124
  public ceil(num: number) {
125
    return Math.ceil(num);
126
  }
127

    
128
  public ngOnInit() {
129
    this.properties = properties;
130
    this.seoService.createLinkForCanonicalURL(this.properties.domain + this.properties.baseLink+this._router.url, false);
131
    this.getPageContents();
132

    
133
    if(this.properties!=null){
134
      var url = this.properties.domain + this.properties.baseLink+this._router.url;
135
      this._meta.updateTag({content:url},"property='og:url'");
136
      if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){
137
        this.subs.push(this._piwikService.trackView(this.properties, "OpenAIRE").subscribe());
138
      }
139

    
140
      //this.config.getCommunityInformation(this.properties, this.properties.adminToolsCommunity ).subscribe(data => {
141
      this.subs.push(this.config.communityInformationState.subscribe(data => {
142
          if(data) {
143
            var showEntity = {};
144
            for (var i = 0; i < data['entities'].length; i++) {
145

    
146
              showEntity["" + data['entities'][i]["pid"] + ""] = data['entities'][i]["isEnabled"];
147
            }
148
            this.showPublications = showEntity["publication"];
149
            this.showDatasets = showEntity["dataset"];
150
            this.showSoftware = showEntity["software"];
151
            this.showOrp = showEntity["orp"];
152
            this.showProjects = showEntity["project"];
153
            this.showDataProviders = showEntity["datasource"];
154
            this.showOrganizations = showEntity["organization"];
155
            if(this.showPublications){
156
              this.resultTypes.values.push({name: "Publications" , id:"publications",selected:true, number:0});
157
            }
158
            if(this.showDatasets){
159
              this.resultTypes.values.push({name: "Research data" , id:"datasets",selected:true, number:0});
160
            }
161
            if(this.showSoftware){
162
              this.resultTypes.values.push({name: "Software" , id:"software",selected:true, number:0});
163
            }
164
            if(this.showOrp){
165
              this.resultTypes.values.push({name: "Other research products" , id:"other",selected:true, number:0});
166
            }
167
            this.getNumbers();
168
          }
169
        },
170
        error => {
171
          this.handleError("Error getting community information", error);
172
        }
173
      ));
174
    }
175

    
176
  }
177
  public ngOnDestroy() {
178
    for (let sub of this.subs) {
179
      sub.unsubscribe();
180
    }
181
  }
182

    
183
  private getNumbers() {
184
    let refineQuery = null
185
    if(this.customFilter){
186
      refineQuery= "&fq="+StringUtils.URIEncode(this.customFilter.queryFieldName + " exact " + StringUtils.quote((this.customFilter.valueId )));
187
    }
188
    if(this.showPublications){
189
      this.subs.push(this._searchResearchResultsService.numOfSearchResults("publication", "", this.properties, refineQuery).subscribe(
190
        data => {
191
          if(data && data != null && data > 0 ){
192
            this.publicationsSize = NumberUtils.roundNumber(data);
193

    
194
          }
195
        },
196
        err => {
197
          //console.log(err);
198
          this.handleError("Error getting number of publications", err);
199
        }
200
      ));
201
    }
202
    if(this.showDatasets){
203
      this.subs.push(this._searchResearchResultsService.numOfSearchResults("dataset", "", this.properties, refineQuery).subscribe(
204
        data => {
205
          if(data && data != null && data > 0 ){
206
            this.datasetsSize = NumberUtils.roundNumber(data);
207
          }
208
        },
209
        err => {
210
          //console.log(err);
211
          this.handleError("Error getting number of research data", err);
212
        }
213
      ));
214
      /*this.subs.push(this._searchResearchResultsService.numOfSearchResultsLinkedToPub("dataset", this.properties, refineQuery).subscribe(
215
        data => {
216
          if(data && data != null && data > 0 ){
217
            this.datasetsLinkedSize = NumberUtils.roundNumber(data);
218
          }
219
        },
220
        err => {
221
          //console.log(err);
222
          this.handleError("Error getting number of linkedresearch data", err);
223
        }
224
      ));*/
225

    
226
    }
227
    if (this.showSoftware) {
228
      this.subs.push(this._searchResearchResultsService.numOfSearchResults("software", "", this.properties, refineQuery).subscribe(
229
        data => {
230
          if (data && data > 0) {
231
            this.softwareSize = NumberUtils.roundNumber(data);
232
          }else{
233
            this.showSoftware = false;
234
          }
235
        },
236
        err => {
237
          this.handleError("Error getting number of software data", err);
238
        }
239
      ));
240
    /*  this.subs.push(this._searchResearchResultsService.numOfSearchResultsLinkedToPub("software", this.properties, refineQuery).subscribe(
241
        data => {
242
          if(data && data != null && data > 0 ){
243
            this.softwareLinkedSize = NumberUtils.roundNumber(data);
244
          }
245
        },
246
        err => {
247
          //console.log(err);
248
          this.handleError("Error getting number of linked software", err);
249
        }
250
      ));*/
251
    }
252
    if (this.showOrp) {
253
      this.subs.push(this._searchResearchResultsService.numOfSearchResults("other", "", this.properties, refineQuery).subscribe(
254
        data => {
255
          if (data && data > 0) {
256
            this.otherSize = NumberUtils.roundNumber(data);
257
          }else{
258
            this.showOrp = false;
259
          }
260
        },
261
        err => {
262
          this.handleError("Error getting number of software data", err);
263
        }
264
      ));
265
    }
266
    if(this.showProjects){
267
      this.subs.push(this._refineFieldResultsService.getRefineFieldsResultsByEntityName(["funder"],"project", this.properties, refineQuery).subscribe(
268
        data => {
269

    
270

    
271
          if(data[0] && data[0] > 0 ){
272
            this.projectsSize = NumberUtils.roundNumber(data[0]);
273
          }
274
          if(data[1].length > 0 && data[1][0].filterId == "funder" && data[1][0].values ){
275
            this.fundersSize = NumberUtils.roundNumber(data[1][0].values.length);
276
          }
277

    
278
        },
279
        err => {
280
          //console.log(err);
281
          this.handleError("Error getting 'funder' field results of projects", err);
282
        }));
283
    }
284
    if(this.showDataProviders){
285
      this.subs.push(this._searchDataprovidersService.numOfSearchDataproviders("", this.properties, refineQuery).subscribe(
286
        data => {
287
          if(data && data != null && data > 0 ){
288
            this.datasourcesSize = NumberUtils.roundNumber(data);
289
          }
290

    
291
        },
292
        err => {
293
          //console.log(err);
294
          this.handleError("Error getting number of content providers", err);
295
        }
296
      ));
297
    }
298
  }
299

    
300
  private handleError(message: string, error) {
301
    console.error("Home Page: "+message, error);
302
  }
303
  entityChanged($event){
304
    this.selectedEntity = $event.entity;
305
    this.selectedEntitySimpleUrl = $event.simpleUrl;
306
    this.selectedEntityAdvancedUrl = $event.advancedUrl;
307
  }
308
  goTo(simple:boolean){
309
    let url = (simple)?this.selectedEntitySimpleUrl:this.selectedEntityAdvancedUrl;
310
    let parameterNames = [];
311
    let parameterValues = [];
312
    if (this.selectedEntity == "result") {
313
      if (this.resultTypes) {
314
        let values = [];
315
        for(let value of this.resultTypes.values){
316
          if (value.selected) {
317
            values.push(value.id);
318
          }
319
        }
320
        if (values.length > 0 && values.length !=4) {
321
          parameterNames.push("type");
322
          parameterValues.push(values.join(","));
323
        }
324
        if (this.resultsQuickFilter) {
325
          parameterNames.push("qf");
326
          parameterValues.push("" + this.resultsQuickFilter.selected);
327
        }
328
      }
329
    }else if(this.selectedEntity == "all"){
330
      if (this.resultsQuickFilter) {
331
        parameterNames.push("qf");
332
        parameterValues.push("true");
333
      }
334
    }
335
    if(this.keyword.length > 0) {
336
      parameterNames.push("fv0");
337
      parameterValues.push(this.keyword);
338
      parameterNames.push("f0");
339
      parameterValues.push("q");
340
    }
341
    if(this.customFilter){
342
      parameterNames.push(this.customFilter.queryFieldName);
343
      parameterValues.push(this.customFilter.valueId);
344
      parameterNames.push("cf");
345
      parameterValues.push("true");
346
    }
347
    this._router.navigate([url], {queryParams: this.routerHelper.createQueryParams(parameterNames, parameterValues)});
348
  }
349
  getQueryParamsForAdvancedSearch(entity){
350
    let params = {};
351
    if (entity == "result") {
352
      if (this.resultsQuickFilter) {
353
        params["qf"] = "" + this.resultsQuickFilter.selected;
354
      }
355
    }
356
    if(this.keyword.length > 0) {
357
      params["fv0"] = "" + this.keyword;
358
      params["f0"] = "q";
359
    }
360
    if(this.customFilter){
361
     params = this.customFilter.getParameters(params);
362
    }
363
    return params;
364
  }
365
}
(3-3/4)