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 softwareSize: any = null;
123
  public otherSize: any = null;
124
  public fundersSize:any = null;
125
  public projectsSize:any = null;
126
  public datasourcesSize:any = null;
127

    
128
  private numResults: number = 2;
129
  public fetchDataproviders : FetchDataproviders;
130

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

    
145
  public pageContents = null;
146

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

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

    
162
          var title = "OpenAIRE | Explore";
163

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

    
169

    
170
          //this.fetchDataproviders = new FetchDataproviders(this._searchDataprovidersService);
171
  }
172

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

    
179
  public getKeys(obj: {}) {
180
    return Object.keys(obj);
181
  }
182

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

    
191
  public ceil(num: number) {
192
    return Math.ceil(num);
193
  }
194

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

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

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

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

    
233
  }
234
  public ngOnDestroy() {
235
    if(this.piwiksub){
236
      this.piwiksub.unsubscribe();
237
    }
238
    if(this.subfunders){
239
      this.subfunders.unsubscribe();
240
    }
241
        if(this.subPub){
242
          this.subPub.unsubscribe();
243
        }
244
        if(this.subData){
245
          this.subData.unsubscribe();
246
        }
247
    //     if(this.subProjects){
248
    //       this.subProjects.unsubscribe();
249
    //     }
250
    //     if(this.subOrg){
251
    //       this.subOrg.unsubscribe();
252
    //     }
253
        if(this.subDataPr){
254
          this.subDataPr.unsubscribe();
255
        }
256

    
257
  }
258

    
259
   private getNumbers() {
260
     if(this.showPublications){
261
       this.subPub = this._searchResearchResultsService.numOfSearchResults("publication", "", this.properties).subscribe(
262
               data => {
263
                  if(data && data != null && data > 0 ){
264
                      this.publicationsSize = NumberUtils.roundNumber(data);
265

    
266
                  }
267
               },
268
               err => {
269
         		    //console.log(err);
270
                this.handleError("Error getting number of publications", err);
271
          		 }
272
        );
273
      }
274
      if(this.showDatasets){
275
       this.subData = this._searchResearchResultsService.numOfSearchResults("dataset", "", this.properties).subscribe(
276
             data => {
277
               if(data && data != null && data > 0 ){
278
                   this.datasetsSize = NumberUtils.roundNumber(data);
279
               }
280
             },
281
             err => {
282
                 //console.log(err);
283
                 this.handleError("Error getting number of research data", err);
284
               }
285
         );
286
       }
287
     if (this.showSoftware) {
288
       this.subSoft = this._searchResearchResultsService.numOfSearchResults("software", "", this.properties).subscribe(
289
         data => {
290
           if (data && data > 0) {
291
             this.softwareSize = NumberUtils.roundNumber(data);
292
           }else{
293
             this.showSoftware = false;
294
           }
295
         },
296
         err => {
297
           this.handleError("Error getting number of software data", err);
298
         }
299
       );
300
     }
301
     if (this.showOrp) {
302
       this.subOrp = this._searchResearchResultsService.numOfSearchResults("other", "", this.properties).subscribe(
303
         data => {
304
           if (data && data > 0) {
305
             this.otherSize = NumberUtils.roundNumber(data);
306
           }else{
307
             this.showOrp = false;
308
           }
309
         },
310
         err => {
311
           this.handleError("Error getting number of software data", err);
312
         }
313
       );
314
     }
315
       if(this.showProjects){
316
         this.subfunders = this._refineFieldResultsService.getRefineFieldsResultsByEntityName(["funder"],"project", this.properties).subscribe(
317
           data => {
318

    
319

    
320
                if(data[0] && data[0] > 0 ){
321
                  this.projectsSize = NumberUtils.roundNumber(data[0]);
322
                }
323
                if(data[1].length > 0 && data[1][0].filterId == "funder" && data[1][0].values ){
324
                  this.fundersSize = NumberUtils.roundNumber(data[1][0].values.length);
325
                }
326

    
327
           },
328
           err => {
329
               //console.log(err);
330
               this.handleError("Error getting 'funder' field results of projects", err);
331
        });
332
      }
333
      if(this.showDataProviders){
334
        this.subDataPr = this._searchDataprovidersService.numOfSearchDataproviders("", this.properties).subscribe(
335
           data => {
336
             if(data && data != null && data > 0 ){
337
                 this.datasourcesSize = NumberUtils.roundNumber(data);
338
             }
339

    
340
           },
341
           err => {
342
               //console.log(err);
343
               this.handleError("Error getting number of content providers", err);
344
           }
345
       );
346
     }
347
   }
348

    
349
   private handleError(message: string, error) {
350
       console.error("Home Page: "+message, error);
351
   }
352
}
(3-3/4)