Project

General

Profile

1
import {Component, Input, Output}     from '@angular/core';
2
import {EventEmitter, ViewChild}      from '@angular/core';
3
import {ChangeDetectionStrategy}      from '@angular/core';
4
import {ViewEncapsulation}            from '@angular/core';
5
import {ActivatedRoute, Router}       from '@angular/router';
6
import {Location}                     from '@angular/common';
7
import {Title, Meta}                  from '@angular/platform-browser';
8

    
9
import {Observable}                   from 'rxjs';
10

    
11
import {FetchPublications}            from '../../utils/fetchEntitiesClasses/fetchPublications.class';
12
import {FetchDataproviders}           from  '../../utils/fetchEntitiesClasses/fetchDataproviders.class';
13
import {FetchProjects}                from  '../../utils/fetchEntitiesClasses/fetchProjects.class';
14
import {FetchDatasets}                from '../../utils/fetchEntitiesClasses/fetchDatasets.class';
15
import {FetchSoftware}                from '../../utils/fetchEntitiesClasses/fetchSoftware.class';
16
import {FetchOrps}                    from '../../utils/fetchEntitiesClasses/fetchOrps.class';
17
import {FetchOrganizations}           from '../../utils/fetchEntitiesClasses/fetchOrganizations.class';
18

    
19
import {SearchPublicationsService}    from '../../services/searchPublications.service';
20
import {SearchDataprovidersService}   from '../../services/searchDataproviders.service';
21
import {SearchProjectsService}        from '../../services/searchProjects.service';
22
import {SearchDatasetsService}        from '../../services/searchDatasets.service';
23
import {SearchSoftwareService}        from '../../services/searchSoftware.service';
24
import {SearchOrpsService}        from '../../services/searchOrps.service';
25
import {SearchOrganizationsService}   from '../../services/searchOrganizations.service';
26

    
27
import {SearchFields, FieldDetails}   from '../../utils/properties/searchFields';
28
import {ErrorCodes}                   from '../../utils/properties/errorCodes';
29
import {RouterHelper}                 from '../../utils/routerHelper.class';
30
import {RefineFieldResultsService}    from '../../services/refineFieldResults.service';
31
import {PiwikService}                 from '../../utils/piwik/piwik.service';
32
import {ConfigurationService}         from '../../utils/configuration/configuration.service';
33
import {EnvProperties}                from '../../utils/properties/env-properties';
34
import { SEOService } from '../../sharedComponents/SEO/SEO.service';
35
import {StringUtils}             from '../../utils/string-utils.class';
36

    
37
@Component({
38
  changeDetection: ChangeDetectionStrategy.Default,
39
  encapsulation: ViewEncapsulation.Emulated,
40
    selector: 'search-find',
41
    templateUrl: 'search.component.html'
42
})
43
export class SearchComponent {
44
  public sub: any; piwiksub: any;
45
  public reloadPublications: boolean;
46
  public reloadDatasets: boolean;
47
  public reloadSoftware: boolean;
48
  public reloadOrps: boolean;
49
  public reloadProjects: boolean;
50
  public reloadDataproviders: boolean;
51
  public reloadOrganizations: boolean;
52

    
53

    
54
  public pageTitle = "Search in OpenAIRE"
55
  public keyword:string = "";
56
  public publications:string[];
57
  public datasets:string[];
58
  public software:string[];
59
  public orps:string[];
60
  public projectsTab:string[];
61
  public dataproviders:string[];
62
  public organizations:string[];
63

    
64
  public activeTab = "publications";
65
  public linkToSearchPublications = "";
66
  public linkToSearchProjects = "";
67
  public linkToSearchDataproviders = "";
68
  public linkToSearchDatasets = "";
69
  public linkToSearchSoftware = "";
70
  public linkToSearchOrps = "";
71
  public linkToSearchOrganizations = "";
72

    
73
  public fetchPublications : FetchPublications;
74
  public fetchDataproviders : FetchDataproviders;
75
  public fetchProjects : FetchProjects;
76
  public fetchDatasets: FetchDatasets;
77
  public fetchSoftware: FetchSoftware;
78
  public fetchOrps: FetchOrps;
79
  public fetchOrganizations: FetchOrganizations;
80

    
81
  public searchFields:SearchFields = new SearchFields();
82
  public errorCodes:ErrorCodes = new ErrorCodes();
83
  public routerHelper:RouterHelper = new RouterHelper();
84

    
85
  public publicationsSize:any = null;
86
  public datasetsSize:any = null;
87
  public softwareSize:any = null;
88
  public oprsSize:any = null;
89
  public fundersSize:any = null;
90
  public projectsSize:any = null;
91
  public datasourcesSize:any = null;
92
  showPublications:boolean= false;
93
  showDatasets:boolean= false;
94
  showSoftware:boolean=false;
95
  showOrps:boolean=false;
96
  showProjects:boolean= false;
97
  showDataProviders:boolean= false;
98
  showOrganizations:boolean= false;
99
  advancedSearchLink:string ="/search/advanced/publications";
100
  properties: EnvProperties;
101
  @Input() logoURL;
102
  @Input() name;
103
  @Input() connectCommunityId =null;
104
  @Input() piwikSiteId = null;
105
  @Input() formPlaceholderText = "Search for research results, projects, content providers & organizations in OpenAIRE";
106

    
107

    
108
public subPub;public subData; public subSoftware; public subOrps; public subProjects;public subOrg; public subDataPr;
109
  constructor ( private route: ActivatedRoute,
110
      private _router: Router,
111
      private _searchPublicationsService: SearchPublicationsService,
112
      private _searchDataprovidersService: SearchDataprovidersService,
113
      private _searchProjectsService: SearchProjectsService,
114
      private _searchDatasetsService: SearchDatasetsService,
115
      private _searchSoftwareService: SearchSoftwareService,
116
      private _searchOrpsService: SearchOrpsService,
117
      private _searchOrganizationsService: SearchOrganizationsService,
118
      private _refineFieldResultsService:RefineFieldResultsService,
119
      private location: Location,
120
      private _meta: Meta,
121
      private _title: Title,
122
      private _piwikService:PiwikService,
123
      private config: ConfigurationService,
124
    private seoService: SEOService ) {
125
          this.fetchPublications = new FetchPublications(this._searchPublicationsService);
126
          this.fetchDataproviders = new FetchDataproviders(this._searchDataprovidersService);
127
          this.fetchProjects = new FetchProjects(this._searchProjectsService);
128
          this.fetchDatasets = new FetchDatasets( this._searchDatasetsService);
129
          this.fetchSoftware = new FetchSoftware(this._searchSoftwareService);
130
          this.fetchOrps = new FetchOrps( this._searchOrpsService);
131
          this.fetchOrganizations = new FetchOrganizations( this._searchOrganizationsService);
132

    
133
  }
134

    
135
  public ngOnInit() {
136
    this.route.data
137
      .subscribe((data: { envSpecific: EnvProperties }) => {
138

    
139
        var description = "open access, research, scientific publication, European Commission, EC, FP7, ERC, Horizon 2020, H2020, search, projects ";
140
        var title = "OpenAIRE | Search publications, research data, projects... | OpenAIRE";
141
        this.properties = data.envSpecific;
142
        var url = data.envSpecific.baseLink+this._router.url;
143
        this._title.setTitle(title);
144
        this._meta.updateTag({content:description},"name='description'");
145
        this._meta.updateTag({content:description},"property='og:description'");
146
        this._meta.updateTag({content:title},"property='og:title'");
147
        this._meta.updateTag({content:url},"property='og:url'");
148
        this.seoService.createLinkForCanonicalURL(this.properties.baseLink+this._router.url,false);
149
        if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){
150
          this.piwiksub = this._piwikService.trackView(this.properties, "OpenAIRE |Search publications, research data, projects...", this.piwikSiteId).subscribe();
151

    
152
        }
153

    
154

    
155

    
156
      this.config.getCommunityInformation(this.properties.adminToolsAPIURL, (this.connectCommunityId)?this.connectCommunityId:this.properties.adminToolsCommunity ).subscribe(data => {
157
          var showEntity = {};
158
          for(var i=0; i< data['entities'].length; i++){
159

    
160
            showEntity[""+data['entities'][i]["pid"]+""] = data['entities'][i]["isEnabled"];
161
          }
162
          this.showPublications =  showEntity["publication"];
163
          this.showDatasets =   showEntity["dataset"];
164
          this.showProjects =   showEntity["project"];
165
          this.showOrganizations =   showEntity["organization"];
166
          this.showDataProviders =   showEntity["datasource"];
167
          this.showSoftware =  showEntity["software"];
168
          this.showOrps =   showEntity["orp"];
169
          if(this.connectCommunityId){
170
            this.showProjects = false;
171
            this.showOrganizations = false;
172
            this.showDataProviders = false;
173
          }
174

    
175
          this.sub =  this.route.queryParams.subscribe(params => {
176

    
177
                this.reloadTabs();
178
                this.keyword = (params['keyword'])?params['keyword']:"";
179
                if(this.keyword !=null && this.keyword.length > 0){
180
                  //if showPublications == false will set another entity as the first
181
                  if(this.showPublications){
182
                    this.activeTab = "publications";
183
                    this.searchPublications();
184
                  }else if(this.showDatasets){
185
                    this.activeTab = "research data";
186
                    this.searchDatasets();
187
                  }else if(this.showSoftware){
188
                    this.activeTab = "software";
189
                    this.searchSoftware();
190
                  }else if(this.showOrps){
191
                    this.activeTab = "other research products";
192
                    this.searchOrps();
193
                  }else if(this.showProjects){
194
                    this.activeTab = "projects";
195
                    this.searchProjects();
196
                  }else if(this.showDataProviders){
197
                    this.activeTab = "content providers";
198
                    this.searchDataProviders();
199
                  }else if(this.showOrganizations){
200
                    this.activeTab = "organizations";
201
                    this.searchOrganizations();
202
                  }
203
                  this.count();
204
                }
205
              });
206
        });
207
          });
208
      }
209

    
210

    
211

    
212

    
213
  public ngOnDestroy() {
214
    if(this.sub){
215
      this.sub.unsubscribe();
216
    }
217
    if(this.piwiksub){
218
        this.piwiksub.unsubscribe();
219
      }
220
    if(this.keyword !=null && this.keyword.length > 0){
221
        if(this.subPub){
222
          this.subPub.unsubscribe();
223
        }
224
        if(this.subData){
225
          this.subData.unsubscribe();
226
        }
227
        if(this.subSoftware){
228
          this.subSoftware.unsubscribe();
229
        }
230
        if(this.subOrps){
231
          this.subOrps.unsubscribe();
232
        }
233
        if(this.subProjects){
234
          this.subProjects.unsubscribe();
235
        }
236
        if(this.subOrg){
237
          this.subOrg.unsubscribe();
238
        }
239
        if(this.subDataPr){
240
          this.subDataPr.unsubscribe();
241
        }
242

    
243
    }
244
  }
245
  public searchPublications() {
246
    this.activeTab = "publications";
247
    this.advancedSearchLink ="/search/advanced/publications";
248
    if( this.reloadPublications &&
249
         this.fetchPublications.searchUtils.status != this.errorCodes.NONE /*&&
250
        this.fetchPublications.searchUtils.status != this.errorCodes.ERROR*/) {
251
      this.reloadPublications = false;
252
      this.fetchPublications.getResultsByKeyword(this.keyword,  1, 10,this.properties, this.connectCommunityId);
253
      this.linkToSearchPublications = this.properties.searchLinkToPublications;// + "?keyword="  + this.keyword;
254
    }
255
   }
256
   public searchDatasets() {
257
     this.activeTab = "research data";
258
     this.advancedSearchLink ="/search/advanced/datasets";
259
     if(this.reloadDatasets &&
260
        this.fetchDatasets.searchUtils.status != this.errorCodes.NONE /*&&
261
        this.fetchDatasets.searchUtils.status != this.errorCodes.ERROR*/) {
262
       this.reloadDatasets = false;
263
       this.fetchDatasets.getResultsByKeyword(this.keyword,  1, 10,this.properties, this.connectCommunityId);
264
       this.linkToSearchDatasets =this.properties.searchLinkToDatasets;// + "?keyword="  + this.keyword;
265
     }
266
   }
267
   public searchSoftware() {
268

    
269
     this.activeTab = "software";
270
     this.advancedSearchLink ="/search/advanced/software";
271
     if(this.reloadSoftware
272
       && this.fetchSoftware.searchUtils.status != this.errorCodes.NONE/* &&
273
        ( this.fetchSoftware.searchUtils.status == this.errorCodes.LOADING ||
274
          this.fetchSoftware.searchUtils.status == this.errorCodes.DONE )*/) {
275
       this.reloadSoftware = false;
276
       this.fetchSoftware.getResultsByKeyword(this.keyword,  1, 10,this.properties, this.connectCommunityId);
277
       this.linkToSearchSoftware = this.properties.searchLinkToSoftware;// + "?keyword="  + this.keyword;
278
     }
279
   }
280
   public searchOrps() {
281
     this.activeTab = "other research products";
282
     this.advancedSearchLink ="/search/advanced/other";
283
     if(this.reloadOrps &&
284
        this.fetchOrps.searchUtils.status != this.errorCodes.NONE /*&&
285
        this.fetchOrps.searchUtils.status != this.errorCodes.ERROR*/) {
286
       this.reloadOrps = false;
287
       this.fetchOrps.getResultsByKeyword(this.keyword,  1, 10,this.properties, this.connectCommunityId);
288
       this.linkToSearchOrps =this.properties.searchLinkToOrps;
289
     }
290
   }
291
   public  searchProjects() {
292
     this.activeTab = "projects";
293
     this.advancedSearchLink ="/search/advanced/projects";
294
     if(this.reloadProjects &&
295
        this.fetchProjects.searchUtils.status != this.errorCodes.NONE /*&&
296
        this.fetchProjects.searchUtils.status != this.errorCodes.ERROR*/) {
297
       this.reloadProjects = false;
298
       this.fetchProjects.getResultsByKeyword(this.keyword,  1, 10,this.properties);
299
       this.linkToSearchProjects = this.properties.searchLinkToProjects;// + "?keyword="  + this.keyword;
300
     }
301
   }
302
   public  searchDataProviders() {
303
     this.activeTab = "content providers";
304
     this.advancedSearchLink ="/search/advanced/dataproviders";
305
     if( this.reloadDataproviders &&
306
         this.fetchDataproviders.searchUtils.status != this.errorCodes.NONE /*&&
307
         this.fetchDataproviders.searchUtils.status != this.errorCodes.ERROR*/) {
308
       this.reloadDataproviders = false;
309
       this.fetchDataproviders.getResultsByKeyword(this.keyword, 1, 10,this.properties);
310
       this.linkToSearchDataproviders = this.properties.searchLinkToDataProviders;// + "?keyword="  + this.keyword;
311
     }
312
   }
313
   public searchOrganizations() {
314
     this.activeTab = "organizations";
315
     this.advancedSearchLink ="/search/advanced/organizations";
316
     if( this.reloadOrganizations &&
317
         this.fetchOrganizations.searchUtils.status != this.errorCodes.NONE /*&&
318
         this.fetchOrganizations.searchUtils.status != this.errorCodes.ERROR*/) {
319
       this.reloadOrganizations = false;
320
       this.fetchOrganizations.getResultsByKeyword(this.keyword,  1, 10,this.properties);
321
       this.linkToSearchOrganizations = this.properties.searchLinkToOrganizations;// + "?keyword="  + this.keyword;
322
     }
323
   }
324

    
325

    
326
   public keywordChanged($event){
327

    
328
    this.keyword = $event.value;
329
    //console.info("Search Find: search with keyword \"" +  this.keyword + "\"" );
330
      this.location.go(location.pathname,"?keyword="  + this.keyword);
331
    this.reloadTabs();
332
    if(this.activeTab == "publications") {
333
      this.searchPublications();
334
    }
335
    if(this.activeTab == "projects") {
336
      this.searchProjects();
337
    }
338
    if(this.activeTab == "content providers") {
339
      this.searchDataProviders();
340
    }
341
    if(this.activeTab == "research data") {
342
      this.searchDatasets();
343
    }
344
    if(this.activeTab == "software") {
345
      this.searchSoftware();
346
    }
347
    if(this.activeTab == "other research products") {
348
      this.searchOrps();
349
    }
350
    if(this.activeTab == "organizations") {
351
      this.searchOrganizations();
352
    }
353

    
354
    this.count();
355
   }
356

    
357
   private count() {
358
     var refineParams = this.connectCommunityId?("&fq="+StringUtils.URIEncode("communityId exact " + StringUtils.quote((this.connectCommunityId )))):null;
359
     if(this.activeTab != "publications" && this.showPublications){
360
      this.fetchPublications.searchUtils.status = this.errorCodes.LOADING;
361
      this.fetchPublications.results = [];
362

    
363
      this.subPub = this._searchPublicationsService.numOfSearchPublications(this.keyword,this.properties, refineParams).subscribe(
364
             data => {
365
                 this.fetchPublications.searchUtils.totalResults = data;
366
                 this.fetchPublications.searchUtils.status = this.errorCodes.DONE;
367
                 if(this.fetchPublications.searchUtils.totalResults == 0) {
368
                   this.fetchPublications.searchUtils.status = this.errorCodes.NONE;
369
                 }
370
             },
371
             err => {
372
       		    //console.log(err);
373
              this.handleError("Error getting number of Publications", err);
374
              this.fetchPublications.searchUtils.status = this.errorCodes.ERROR;
375
       		 }
376
      );
377
    }
378
    if(this.activeTab != "research data" && this.showDatasets){
379
       this.fetchDatasets.searchUtils.status = this.errorCodes.LOADING;
380
       this.fetchDatasets.results = [];
381
       this.subData = this._searchDatasetsService.numOfSearchDatasets(this.keyword,this.properties, refineParams).subscribe(
382
             data => {
383
                 this.fetchDatasets.searchUtils.totalResults = data;
384
                 this.fetchDatasets.searchUtils.status = this.errorCodes.DONE;
385
                 if(this.fetchDatasets.searchUtils.totalResults == 0) {
386
                   this.fetchDatasets.searchUtils.status = this.errorCodes.NONE;
387
                 }
388
             },
389
             err => {
390
                 //console.log(err);
391
                 this.handleError("Error getting number of Research Data", err);
392
                 this.fetchDatasets.searchUtils.status = this.errorCodes.ERROR;
393
              }
394
       );
395
    }
396
    if(this.activeTab != "software" && this.showSoftware){
397
       this.fetchSoftware.searchUtils.status = this.errorCodes.LOADING;
398
       this.fetchSoftware.results = [];
399
       this.subSoftware = this._searchSoftwareService.numOfSearchSoftware(this.keyword,this.properties, refineParams).subscribe(
400
             data => {
401
                 this.fetchSoftware.searchUtils.totalResults = data;
402
                 this.fetchSoftware.searchUtils.status = this.errorCodes.DONE;
403
                 if(this.fetchSoftware.searchUtils.totalResults == 0) {
404
                   this.fetchSoftware.searchUtils.status = this.errorCodes.NONE;
405
                 }
406
             },
407
             err => {
408
                this.handleError("Error getting number of Software", err);
409
                 /*console.log(err);
410
                 if(err.status == '404') {
411
                   this.fetchSoftware.searchUtils.status = this.errorCodes.NOT_FOUND;
412
                 } else if(err.status == '500') {
413
                   this.fetchSoftware.searchUtils.status = this.errorCodes.ERROR;
414
                 } else {
415
                   this.fetchSoftware.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
416
                 }*/
417
                 this.fetchSoftware.searchUtils.status = this.errorCodes.ERROR;
418
              }
419
       );
420
    }
421
    if(this.activeTab != "other research products" && this.showOrps){
422
       this.fetchOrps.searchUtils.status = this.errorCodes.LOADING;
423
       this.fetchOrps.results = [];
424
       this.subOrps = this._searchOrpsService.numOfSearchOrps(this.keyword,this.properties, refineParams).subscribe(
425
             data => {
426
                 this.fetchOrps.searchUtils.totalResults = data;
427
                 this.fetchOrps.searchUtils.status = this.errorCodes.DONE;
428
                 if(this.fetchOrps.searchUtils.totalResults == 0) {
429
                   this.fetchOrps.searchUtils.status = this.errorCodes.NONE;
430
                 }
431
             },
432
             err => {
433
                 //console.log(err);
434
                 this.handleError("Error getting number of Other Research Products", err);
435
                 this.fetchOrps.searchUtils.status = this.errorCodes.ERROR;
436
              }
437
       );
438
    }
439
    if(this.activeTab != "projects" && this.showProjects){
440
      this.fetchProjects.searchUtils.status = this.errorCodes.LOADING;
441
      this.fetchProjects.results = [];
442
      this.subProjects = this._searchProjectsService.numOfSearchProjects(this.keyword,this.properties).subscribe(
443
             data => {
444
                 this.fetchProjects.searchUtils.totalResults = data;
445
                 this.fetchProjects.searchUtils.status = this.errorCodes.DONE;
446
                 if(this.fetchProjects.searchUtils.totalResults == 0) {
447
                   this.fetchProjects.searchUtils.status = this.errorCodes.NONE;
448
                 }
449
             },
450
             err => {
451
                 //console.log(err);
452
                 this.handleError("Error getting number of Projects", err);
453
                 this.fetchProjects.searchUtils.status = this.errorCodes.ERROR;
454
              }
455
       );
456
     }
457
     if(this.activeTab != "content providers" && this.showDataProviders){
458
       this.fetchDataproviders.results = [];
459
       this.fetchDataproviders.getNumForSearch(this.keyword,this.properties);
460
     }
461
      if(this.activeTab != "organizations" && this.showOrganizations){
462
       this.fetchOrganizations.searchUtils.status = this.errorCodes.LOADING;
463
       this.fetchOrganizations.results = [];
464
       this.subOrg = this._searchOrganizationsService.numOfSearchOrganizations(this.keyword,this.properties).subscribe(
465
             data => {
466
                 this.fetchOrganizations.searchUtils.totalResults = data;
467
                 this.fetchOrganizations.searchUtils.status = this.errorCodes.DONE;
468
                 if(this.fetchOrganizations.searchUtils.totalResults == 0) {
469
                   this.fetchOrganizations.searchUtils.status = this.errorCodes.NONE;
470
                 }
471
             },
472
             err => {
473
                 //console.log(err);
474
                 this.handleError("Error getting number of Organizations", err);
475
                 this.fetchOrganizations.searchUtils.status = this.errorCodes.ERROR;
476

    
477
              }
478
         );
479
       }
480

    
481

    
482
   }
483

    
484
   private reloadTabs() {
485
       this.reloadPublications = true;
486
       this.reloadDatasets = true;
487
       this.reloadSoftware = true;
488
       this.reloadOrps = true;
489
       this.reloadProjects = true;
490
       this.reloadDataproviders = true;
491
       this.reloadOrganizations = true;
492
       this.fetchOrganizations.searchUtils.status = null;
493
       this.fetchDataproviders.searchUtils.status = null;
494
       this.fetchProjects.searchUtils.status = null;
495
       this.fetchPublications.searchUtils.status = null;
496
       this.fetchDatasets.searchUtils.status = null;
497
       this.fetchSoftware.searchUtils.status = null;
498
       this.fetchOrps.searchUtils.status = null;
499
   }
500

    
501
   private handleError(message: string, error) {
502
     console.error("General Search Page: "+message, error);
503
   }
504
}
(3-3/3)