Project

General

Profile

1
import {Component, Input, Output, EventEmitter, ViewChild, ChangeDetectionStrategy, ViewEncapsulation} from '@angular/core';
2
import {Observable}       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 {  FetchDataproviders}             from '../openaireLibrary/utils/fetchEntitiesClasses/fetchDataproviders.class';
9
import {  SearchDataprovidersService} from '../openaireLibrary/services/searchDataproviders.service';
10
import {  SearchProjectsService} from '../openaireLibrary/services/searchProjects.service';
11
import {  SearchOrganizationsService} from '../openaireLibrary/services/searchOrganizations.service';
12
import {  RefineFieldResultsService} from '../openaireLibrary/services/refineFieldResults.service';
13
import {  SearchFields} from '../openaireLibrary/utils/properties/searchFields';
14
import {  NumberUtils} from '../openaireLibrary/utils/number-utils.class';
15

    
16
import {  RouterHelper} from '../openaireLibrary/utils/routerHelper.class';
17
import { EnvProperties} from '../openaireLibrary/utils/properties/env-properties';
18
import { ErrorCodes} from '../openaireLibrary/utils/properties/errorCodes';
19
import {PiwikService} from '../openaireLibrary/utils/piwik/piwik.service';
20
import { SEOService } from '../openaireLibrary/sharedComponents/SEO/SEO.service';
21
import {SearchResearchResultsService} from "../openaireLibrary/services/searchResearchResults.service";
22
import {HelperService} from "../openaireLibrary/utils/helper/helper.service";
23

    
24
@Component({
25
    selector: 'home',
26
    templateUrl: 'home.component.html',
27
})
28
export class HomeComponent {
29
  public piwiksub: any;
30
  public subfunders: any;
31

    
32
  // MAX 12 logos in every slide
33
  public logos = {
34
    "publication": [
35
      [
36
        "logo-pubmed.png",
37
        "logo-arxiv.png",
38
        "logo-base.png",
39
        "logo-scielo.png",
40
        "logo-la-referencia.png",
41
        "logo-soar.png",
42
        "logo-repec.png",
43
        "logo-core.png",
44
        "logo-zenodo.png",
45
        "logo-narcis.png"
46
      ],
47
      [
48
        "logo-crossref.png",
49
        "logo-unpaywall.png",
50
        "logo-elsevier.png",
51
        "logo-spring-nature.png",
52
        "logo-frontiers.png",
53
        "logo-opencitations.png",
54
        "logo-doaj.png",
55
        "logo-microsoft.png",
56
        "logo-plos.png",
57
        "logo-f1000.png",
58
        "logo-copernicus.png"
59
      ]
60
    ],
61
    "software": [
62
      [
63
        "logo-software-heritage.png",
64
        "logo-github.png",
65
        "logo-doecode.png",
66
        "logo-bitbucket.png",
67
        "logo-elixir-bio-tools.png",
68
        "logo-google-code.png",
69
        "logo-sourceforge.png",
70
        "logo-zenodo.png"
71
      ]
72
    ],
73
    "dataset": [
74
      [
75
        "logo-scholexplorer.png",
76
        "logo-zenodo.png",
77
        "logo-datacite.png",
78
        "logo-pangea.png",
79
        "logo-figshare.png",
80
        "logo-protocols.png",
81
        "logo-opentrials.png",
82
        "logo-kaggle.png",
83
        "logo-reactome.png",
84
        "logo-easy.png",
85
        "logo-dryad.png"
86
      ]
87
    ],
88
    //"other": [],
89
    "persistent": [
90
      [
91
        "logo-re3data.png",
92
        "logo-orcid.png",
93
        "logo-opendoar.png",
94
        "logo-grid.png"
95
      ]
96
    ],
97
    "funder": [
98
      [
99
        "logo-european-commision.png",
100
        "logo-nsf.png",
101
        "logo-miur.png",
102
        "logo-nhmrc.png",
103
        "logo-sfi.png",
104
        "logo-nwo.png",
105
        "logo-welcome-trust.png",
106
        "logo-fct.png",
107
        "logo-gsrt.png",
108
        "logo-fnsnf.png"
109
      ]
110
    ]
111
  };
112

    
113
  public pageTitle = "OpenAIRE";
114
  public keyword:string = "";
115

    
116
  public searchFields:SearchFields = new SearchFields();
117
  public errorCodes:ErrorCodes = new ErrorCodes();
118
  public routerHelper:RouterHelper = new RouterHelper();
119

    
120
  public publicationsSize:any = null;
121
  public datasetsSize:any = null;
122
  public datasetsLinkedSize:any = null;
123
  public softwareLinkedSize:any = null;
124
  public softwareSize: any = null;
125
  public otherSize: any = null;
126
  public fundersSize:any = null;
127
  public projectsSize:any = null;
128
  public datasourcesSize:any = null;
129

    
130
  private numResults: number = 2;
131
  public fetchDataproviders : FetchDataproviders;
132

    
133
  showPublications:boolean= false;
134
  showDatasets:boolean= false;
135
  showSoftware: boolean = false;
136
  showOrp: boolean = false;
137
  showProjects:boolean= false;
138
  showDataProviders:boolean= false;
139
  properties: EnvProperties;
140
  public readMore: boolean = false;
141
public subPub;public subData;public subProjects;public subOrg; public subDataPr;
142
  public subSoft;public subDataLinked; public subSoftLinked;
143
  public subOrp;
144
  trelloImg: string = 'trello.svg';
145
  trelloImg2: string = 'trello.svg';
146

    
147
  public pageContents = null;
148

    
149
  constructor (
150
    private route: ActivatedRoute,
151
      private _router: Router,
152
      private _searchResearchResultsService: SearchResearchResultsService,
153
      private _searchDataprovidersService: SearchDataprovidersService,
154
      private _searchProjectsService: SearchProjectsService,
155
      private _searchOrganizationsService: SearchOrganizationsService,
156
      private _refineFieldResultsService:RefineFieldResultsService,
157
      private location: Location, private _piwikService:PiwikService,
158
      private config: ConfigurationService, private _meta: Meta, private _title: Title, private seoService: SEOService,
159
    private helper: HelperService
160
    ) {
161

    
162
          var description = "openAIRE explore, open access, publications, research results, European commission, search";
163

    
164
          var title = "OpenAIRE | Explore";
165

    
166
          this._title.setTitle(title);
167
          this._meta.updateTag({content:description},"name='description'");
168
          this._meta.updateTag({content:description},"property='og:description'");
169
          this._meta.updateTag({content:title},"property='og:title'");
170

    
171

    
172
          //this.fetchDataproviders = new FetchDataproviders(this._searchDataprovidersService);
173
  }
174

    
175
  private getPageContents() {
176
    this.helper.getPageHelpContents(this._router.url, this.properties, 'openaire').subscribe(contents => {
177
      this.pageContents = contents;
178
    })
179
  }
180

    
181
  public getKeys(obj: {}) {
182
    return Object.keys(obj);
183
  }
184

    
185
  createRange(number){
186
    var items: number[] = [];
187
    for(var i = 1; i <= number; i++){
188
      items.push(i);
189
    }
190
    return items;
191
  }
192

    
193
  public ceil(num: number) {
194
    return Math.ceil(num);
195
  }
196

    
197
  public ngOnInit() {
198
    this.route.data
199
     .subscribe((data: { envSpecific: EnvProperties }) => {
200
        this.properties = data.envSpecific;
201
        this.seoService.createLinkForCanonicalURL(this.properties.baseLink+this._router.url, false);
202
       this.getPageContents();
203

    
204
       if(this.properties!=null){
205
          var url = this.properties.baseLink+this._router.url;
206
          this._meta.updateTag({content:url},"property='og:url'");
207
          if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){
208
            this.piwiksub = this._piwikService.trackView(this.properties, "OpenAIRE").subscribe();
209
          }
210

    
211
          this.config.getCommunityInformation(this.properties, this.properties.adminToolsCommunity ).subscribe(data => {
212
                 var showEntity = {};
213
                 for(var i=0; i< data['entities'].length; i++){
214

    
215
                   showEntity[""+data['entities'][i]["pid"]+""] = data['entities'][i]["isEnabled"];
216
                 }
217
                 this.showPublications =  showEntity["publication"];
218
                 this.showDatasets =   showEntity["dataset"];
219
                 this.showSoftware = showEntity["software"];
220
                 this.showOrp = showEntity["orp"];
221
                 this.showProjects =   showEntity["project"];
222
                  this.showDataProviders =   showEntity["datasource"];
223
                  this.getNumbers();
224
                  // if(this.showDataProviders) {
225
                  //   this.fetchDataproviders.getResultsForHome(this.numResults, this.properties);
226
                  // }
227
               },
228
                error => {
229
                  this.handleError("Error getting community information", error);
230
                }
231
            );
232
        }
233
       });
234

    
235
  }
236
  public ngOnDestroy() {
237
    if(this.piwiksub){
238
      this.piwiksub.unsubscribe();
239
    }
240
    if(this.subfunders){
241
      this.subfunders.unsubscribe();
242
    }
243
        if(this.subPub){
244
          this.subPub.unsubscribe();
245
        }
246
        if(this.subData){
247
          this.subData.unsubscribe();
248
        }
249
      if(this.subDataLinked){
250
        this.subDataLinked.unsubscribe();
251
      }
252
    if(this.subSoftLinked){
253
      this.subSoftLinked.unsubscribe();
254
    }
255
    //     if(this.subProjects){
256
    //       this.subProjects.unsubscribe();
257
    //     }
258
    //     if(this.subOrg){
259
    //       this.subOrg.unsubscribe();
260
    //     }
261
        if(this.subDataPr){
262
          this.subDataPr.unsubscribe();
263
        }
264

    
265
  }
266

    
267
   private getNumbers() {
268
     if(this.showPublications){
269
       this.subPub = this._searchResearchResultsService.numOfSearchResults("publication", "", this.properties).subscribe(
270
               data => {
271
                  if(data && data != null && data > 0 ){
272
                      this.publicationsSize = NumberUtils.roundNumber(data);
273

    
274
                  }
275
               },
276
               err => {
277
         		    //console.log(err);
278
                this.handleError("Error getting number of publications", err);
279
          		 }
280
        );
281
      }
282
      if(this.showDatasets){
283
       this.subData = this._searchResearchResultsService.numOfSearchResults("dataset", "", this.properties).subscribe(
284
             data => {
285
               if(data && data != null && data > 0 ){
286
                   this.datasetsSize = NumberUtils.roundNumber(data);
287
               }
288
             },
289
             err => {
290
                 //console.log(err);
291
                 this.handleError("Error getting number of research data", err);
292
               }
293
         );
294
        this.subDataLinked = this._searchResearchResultsService.numOfSearchResultsLinkedToPub("dataset", this.properties).subscribe(
295
          data => {
296
            if(data && data != null && data > 0 ){
297
              this.datasetsLinkedSize = NumberUtils.roundNumber(data);
298
            }
299
          },
300
          err => {
301
            //console.log(err);
302
            this.handleError("Error getting number of linkedresearch data", err);
303
          }
304
        );
305

    
306
       }
307
     if (this.showSoftware) {
308
       this.subSoft = this._searchResearchResultsService.numOfSearchResults("software", "", this.properties).subscribe(
309
         data => {
310
           if (data && data > 0) {
311
             this.softwareSize = NumberUtils.roundNumber(data);
312
           }else{
313
             this.showSoftware = false;
314
           }
315
         },
316
         err => {
317
           this.handleError("Error getting number of software data", err);
318
         }
319
       );
320
       this.subSoftLinked = this._searchResearchResultsService.numOfSearchResultsLinkedToPub("software", this.properties).subscribe(
321
         data => {
322
           if(data && data != null && data > 0 ){
323
             this.softwareLinkedSize = NumberUtils.roundNumber(data);
324
           }
325
         },
326
         err => {
327
           //console.log(err);
328
           this.handleError("Error getting number of linked software", err);
329
         }
330
       );
331
     }
332
     if (this.showOrp) {
333
       this.subOrp = this._searchResearchResultsService.numOfSearchResults("other", "", this.properties).subscribe(
334
         data => {
335
           if (data && data > 0) {
336
             this.otherSize = NumberUtils.roundNumber(data);
337
           }else{
338
             this.showOrp = false;
339
           }
340
         },
341
         err => {
342
           this.handleError("Error getting number of software data", err);
343
         }
344
       );
345
     }
346
       if(this.showProjects){
347
         this.subfunders = this._refineFieldResultsService.getRefineFieldsResultsByEntityName(["funder"],"project", this.properties).subscribe(
348
           data => {
349

    
350

    
351
                if(data[0] && data[0] > 0 ){
352
                  this.projectsSize = NumberUtils.roundNumber(data[0]);
353
                }
354
                if(data[1].length > 0 && data[1][0].filterId == "funder" && data[1][0].values ){
355
                  this.fundersSize = NumberUtils.roundNumber(data[1][0].values.length);
356
                }
357

    
358
           },
359
           err => {
360
               //console.log(err);
361
               this.handleError("Error getting 'funder' field results of projects", err);
362
        });
363
      }
364
      if(this.showDataProviders){
365
        this.subDataPr = this._searchDataprovidersService.numOfSearchDataproviders("", this.properties).subscribe(
366
           data => {
367
             if(data && data != null && data > 0 ){
368
                 this.datasourcesSize = NumberUtils.roundNumber(data);
369
             }
370

    
371
           },
372
           err => {
373
               //console.log(err);
374
               this.handleError("Error getting number of content providers", err);
375
           }
376
       );
377
     }
378
   }
379

    
380
   private handleError(message: string, error) {
381
       console.error("Home Page: "+message, error);
382
   }
383
}
(3-3/4)