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

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

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

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

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

    
119
  public publicationsSize:any = null;
120
  public datasetsSize:any = null;
121
  public softwareSize: any = null;
122
  public otherSize: any = null;
123
  public fundersSize:any = null;
124
  public projectsSize:any = null;
125
  public datasourcesSize:any = null;
126

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

    
130
  showPublications:boolean= false;
131
  showDatasets:boolean= false;
132
  showSoftware: boolean = false;
133
  showOrp: boolean = false;
134
  showProjects:boolean= false;
135
  showDataProviders:boolean= false;
136
  properties: EnvProperties;
137
  public readMore: boolean = false;
138
public subPub;public subData;public subProjects;public subOrg; public subDataPr;
139
  public subSoft;
140
  public subOrp;
141
  trelloImg: string = 'trello.svg';
142
  trelloImg2: string = 'trello.svg';
143
  constructor (
144
    private route: ActivatedRoute,
145
      private _router: Router,
146
      private _searchResearchResultsService: SearchResearchResultsService,
147
      private _searchDataprovidersService: SearchDataprovidersService,
148
      private _searchProjectsService: SearchProjectsService,
149
      private _searchOrganizationsService: SearchOrganizationsService,
150
      private _refineFieldResultsService:RefineFieldResultsService,
151
      private location: Location, private _piwikService:PiwikService,
152
      private config: ConfigurationService, private _meta: Meta, private _title: Title, private seoService: SEOService
153
    ) {
154

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

    
157
          var title = "OpenAIRE | Explore";
158

    
159
          this._title.setTitle(title);
160
          this._meta.updateTag({content:description},"name='description'");
161
          this._meta.updateTag({content:description},"property='og:description'");
162
          this._meta.updateTag({content:title},"property='og:title'");
163

    
164

    
165
          //this.fetchDataproviders = new FetchDataproviders(this._searchDataprovidersService);
166
  }
167

    
168
  public getKeys(obj: {}) {
169
    return Object.keys(obj);
170
  }
171

    
172
  createRange(number){
173
    var items: number[] = [];
174
    for(var i = 1; i <= number; i++){
175
      items.push(i);
176
    }
177
    return items;
178
  }
179

    
180
  public ceil(num: number) {
181
    return Math.ceil(num);
182
  }
183

    
184
  public ngOnInit() {
185
    this.route.data
186
     .subscribe((data: { envSpecific: EnvProperties }) => {
187
        this.properties = data.envSpecific;
188
        this.seoService.createLinkForCanonicalURL(this.properties.baseLink+this._router.url, false);
189
        if(this.properties!=null){
190
          var url = this.properties.baseLink+this._router.url;
191
          this._meta.updateTag({content:url},"property='og:url'");
192
          if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){
193
            this.piwiksub = this._piwikService.trackView(this.properties, "OpenAIRE").subscribe();
194
          }
195

    
196
          this.config.getCommunityInformation(this.properties, this.properties.adminToolsCommunity ).subscribe(data => {
197
                 var showEntity = {};
198
                 for(var i=0; i< data['entities'].length; i++){
199

    
200
                   showEntity[""+data['entities'][i]["pid"]+""] = data['entities'][i]["isEnabled"];
201
                 }
202
                 this.showPublications =  showEntity["publication"];
203
                 this.showDatasets =   showEntity["dataset"];
204
                 this.showSoftware = showEntity["software"];
205
                 this.showOrp = showEntity["orp"];
206
                 this.showProjects =   showEntity["project"];
207
                  this.showDataProviders =   showEntity["datasource"];
208
                  this.getNumbers();
209
                  // if(this.showDataProviders) {
210
                  //   this.fetchDataproviders.getResultsForHome(this.numResults, this.properties);
211
                  // }
212
               },
213
                error => {
214
                  this.handleError("Error getting community information", error);
215
                }
216
            );
217
        }
218
       });
219

    
220
  }
221
  public ngOnDestroy() {
222
    if(this.piwiksub){
223
      this.piwiksub.unsubscribe();
224
    }
225
    if(this.subfunders){
226
      this.subfunders.unsubscribe();
227
    }
228
        if(this.subPub){
229
          this.subPub.unsubscribe();
230
        }
231
        if(this.subData){
232
          this.subData.unsubscribe();
233
        }
234
    //     if(this.subProjects){
235
    //       this.subProjects.unsubscribe();
236
    //     }
237
    //     if(this.subOrg){
238
    //       this.subOrg.unsubscribe();
239
    //     }
240
        if(this.subDataPr){
241
          this.subDataPr.unsubscribe();
242
        }
243

    
244
  }
245

    
246
   private getNumbers() {
247
     if(this.showPublications){
248
       this.subPub = this._searchResearchResultsService.numOfSearchResults("publication", "", this.properties).subscribe(
249
               data => {
250
                  if(data && data != null && data > 0 ){
251
                      this.publicationsSize = NumberUtils.roundNumber(data);
252

    
253
                  }
254
               },
255
               err => {
256
         		    //console.log(err);
257
                this.handleError("Error getting number of publications", err);
258
          		 }
259
        );
260
      }
261
      if(this.showDatasets){
262
       this.subData = this._searchResearchResultsService.numOfSearchResults("dataset", "", this.properties).subscribe(
263
             data => {
264
               if(data && data != null && data > 0 ){
265
                   this.datasetsSize = NumberUtils.roundNumber(data);
266
               }
267
             },
268
             err => {
269
                 //console.log(err);
270
                 this.handleError("Error getting number of research data", err);
271
               }
272
         );
273
       }
274
     if (this.showSoftware) {
275
       this.subSoft = this._searchResearchResultsService.numOfSearchResults("software", "", this.properties).subscribe(
276
         data => {
277
           if (data && data > 0) {
278
             this.softwareSize = NumberUtils.roundNumber(data);
279
           }else{
280
             this.showSoftware = false;
281
           }
282
         },
283
         err => {
284
           this.handleError("Error getting number of software data", err);
285
         }
286
       );
287
     }
288
     if (this.showOrp) {
289
       this.subOrp = this._searchResearchResultsService.numOfSearchResults("other", "", this.properties).subscribe(
290
         data => {
291
           if (data && data > 0) {
292
             this.otherSize = NumberUtils.roundNumber(data);
293
           }else{
294
             this.showOrp = false;
295
           }
296
         },
297
         err => {
298
           this.handleError("Error getting number of software data", err);
299
         }
300
       );
301
     }
302
       if(this.showProjects){
303
         this.subfunders = this._refineFieldResultsService.getRefineFieldsResultsByEntityName(["funder"],"project", this.properties).subscribe(
304
           data => {
305

    
306

    
307
                if(data[0] && data[0] > 0 ){
308
                  this.projectsSize = NumberUtils.roundNumber(data[0]);
309
                }
310
                if(data[1].length > 0 && data[1][0].filterId == "funder" && data[1][0].values ){
311
                  this.fundersSize = NumberUtils.roundNumber(data[1][0].values.length);
312
                }
313

    
314
           },
315
           err => {
316
               //console.log(err);
317
               this.handleError("Error getting 'funder' field results of projects", err);
318
        });
319
      }
320
      if(this.showDataProviders){
321
        this.subDataPr = this._searchDataprovidersService.numOfSearchDataproviders("", this.properties).subscribe(
322
           data => {
323
             if(data && data != null && data > 0 ){
324
                 this.datasourcesSize = NumberUtils.roundNumber(data);
325
             }
326

    
327
           },
328
           err => {
329
               //console.log(err);
330
               this.handleError("Error getting number of content providers", err);
331
           }
332
       );
333
     }
334
   }
335

    
336
   private handleError(message: string, error) {
337
       console.error("Home Page: "+message, error);
338
   }
339
}
(3-3/4)