Project

General

Profile

1 50359 argiro.kok
import {Component, Input, Output, EventEmitter, ViewChild, ChangeDetectionStrategy, ViewEncapsulation} from '@angular/core';
2 55965 argiro.kok
import {Observable}       from 'rxjs';
3 50359 argiro.kok
import {ActivatedRoute, Router} from '@angular/router';
4
import {Location} from '@angular/common';
5
import "rxjs/add/observable/zip";
6 51840 argiro.kok
import {Title, Meta}                  from '@angular/platform-browser';
7 50789 argiro.kok
import {ConfigurationService} from '../openaireLibrary/utils/configuration/configuration.service';
8 51995 konstantin
import {  FetchDataproviders}             from '../openaireLibrary/utils/fetchEntitiesClasses/fetchDataproviders.class';
9 50789 argiro.kok
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 50359 argiro.kok
16 50789 argiro.kok
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 53745 argiro.kok
import { SEOService } from '../openaireLibrary/sharedComponents/SEO/SEO.service';
21 57035 konstantin
import {SearchResearchResultsService} from "../openaireLibrary/services/searchResearchResults.service";
22 57501 konstantin
import {HelperService} from "../openaireLibrary/utils/helper/helper.service";
23 50359 argiro.kok
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 57308 konstantin
  // MAX 12 logos in every slide
33
  public logos = {
34
    "publication": [
35
      [
36 57339 konstantin
        "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 57308 konstantin
      ],
47
      [
48 57339 konstantin
        "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 57308 konstantin
      ]
60
    ],
61
    "software": [
62
      [
63 57339 konstantin
        "logo-software-heritage.png",
64
        "logo-github.png",
65
        "logo-doecode.png",
66
        "logo-bitbucket.png",
67 57362 konstantin
        "logo-elixir-bio-tools.png",
68 57339 konstantin
        "logo-google-code.png",
69
        "logo-sourceforge.png",
70
        "logo-zenodo.png"
71 57308 konstantin
      ]
72
    ],
73
    "dataset": [
74
      [
75 57339 konstantin
        "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 57308 konstantin
      ]
87
    ],
88
    //"other": [],
89
    "persistent": [
90
      [
91 57339 konstantin
        "logo-re3data.png",
92
        "logo-orcid.png",
93
        "logo-opendoar.png",
94
        "logo-grid.png"
95 57308 konstantin
      ]
96
    ],
97
    "funder": [
98
      [
99 57339 konstantin
        "logo-european-commision.png",
100
        "logo-nsf.png",
101 57308 konstantin
        "logo-miur.png",
102 57339 konstantin
        "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 57308 konstantin
      ]
110
    ]
111
  };
112
113
  public pageTitle = "OpenAIRE";
114 50359 argiro.kok
  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 56075 argiro.kok
  public softwareSize: any = null;
123
  public otherSize: any = null;
124 50359 argiro.kok
  public fundersSize:any = null;
125
  public projectsSize:any = null;
126
  public datasourcesSize:any = null;
127
128 51995 konstantin
  private numResults: number = 2;
129
  public fetchDataproviders : FetchDataproviders;
130
131 50359 argiro.kok
  showPublications:boolean= false;
132
  showDatasets:boolean= false;
133 56075 argiro.kok
  showSoftware: boolean = false;
134
  showOrp: boolean = false;
135 50359 argiro.kok
  showProjects:boolean= false;
136
  showDataProviders:boolean= false;
137 50587 argiro.kok
  properties: EnvProperties;
138 57295 k.triantaf
  public readMore: boolean = false;
139 50359 argiro.kok
public subPub;public subData;public subProjects;public subOrg; public subDataPr;
140 56075 argiro.kok
  public subSoft;
141
  public subOrp;
142 57295 k.triantaf
  trelloImg: string = 'trello.svg';
143
  trelloImg2: string = 'trello.svg';
144 57501 konstantin
145
  public pageContents = null;
146
147 50359 argiro.kok
  constructor (
148
    private route: ActivatedRoute,
149
      private _router: Router,
150 57035 konstantin
      private _searchResearchResultsService: SearchResearchResultsService,
151 50359 argiro.kok
      private _searchDataprovidersService: SearchDataprovidersService,
152
      private _searchProjectsService: SearchProjectsService,
153
      private _searchOrganizationsService: SearchOrganizationsService,
154
      private _refineFieldResultsService:RefineFieldResultsService,
155 51840 argiro.kok
      private location: Location, private _piwikService:PiwikService,
156 57501 konstantin
      private config: ConfigurationService, private _meta: Meta, private _title: Title, private seoService: SEOService,
157
    private helper: HelperService
158 50359 argiro.kok
    ) {
159
160 53745 argiro.kok
          var description = "openAIRE explore, open access, publications, research results, European commission, search";
161 50359 argiro.kok
162 53745 argiro.kok
          var title = "OpenAIRE | Explore";
163 50359 argiro.kok
164 51840 argiro.kok
          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 50359 argiro.kok
169 53745 argiro.kok
170 51995 konstantin
          //this.fetchDataproviders = new FetchDataproviders(this._searchDataprovidersService);
171 50587 argiro.kok
  }
172
173 57501 konstantin
  private getPageContents() {
174
    this.helper.getPageHelpContents(this._router.url, this.properties, 'openaire').subscribe(contents => {
175
      this.pageContents = contents;
176
    })
177
  }
178
179 57308 konstantin
  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 50587 argiro.kok
  public ngOnInit() {
196
    this.route.data
197
     .subscribe((data: { envSpecific: EnvProperties }) => {
198
        this.properties = data.envSpecific;
199 54749 argiro.kok
        this.seoService.createLinkForCanonicalURL(this.properties.baseLink+this._router.url, false);
200 57501 konstantin
       this.getPageContents();
201
202
       if(this.properties!=null){
203 50587 argiro.kok
          var url = this.properties.baseLink+this._router.url;
204 51840 argiro.kok
          this._meta.updateTag({content:url},"property='og:url'");
205 50587 argiro.kok
          if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){
206 50789 argiro.kok
            this.piwiksub = this._piwikService.trackView(this.properties, "OpenAIRE").subscribe();
207 50359 argiro.kok
          }
208
209 55999 argiro.kok
          this.config.getCommunityInformation(this.properties, this.properties.adminToolsCommunity ).subscribe(data => {
210 50587 argiro.kok
                 var showEntity = {};
211 55965 argiro.kok
                 for(var i=0; i< data['entities'].length; i++){
212 50359 argiro.kok
213 55965 argiro.kok
                   showEntity[""+data['entities'][i]["pid"]+""] = data['entities'][i]["isEnabled"];
214 50587 argiro.kok
                 }
215
                 this.showPublications =  showEntity["publication"];
216
                 this.showDatasets =   showEntity["dataset"];
217 56075 argiro.kok
                 this.showSoftware = showEntity["software"];
218
                 this.showOrp = showEntity["orp"];
219 50587 argiro.kok
                 this.showProjects =   showEntity["project"];
220
                  this.showDataProviders =   showEntity["datasource"];
221
                  this.getNumbers();
222 51995 konstantin
                  // if(this.showDataProviders) {
223
                  //   this.fetchDataproviders.getResultsForHome(this.numResults, this.properties);
224
                  // }
225 54850 konstantin
               },
226
                error => {
227
                  this.handleError("Error getting community information", error);
228
                }
229
            );
230
        }
231 50587 argiro.kok
       });
232
233 50359 argiro.kok
  }
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 57035 konstantin
       this.subPub = this._searchResearchResultsService.numOfSearchResults("publication", "", this.properties).subscribe(
262 50359 argiro.kok
               data => {
263
                  if(data && data != null && data > 0 ){
264
                      this.publicationsSize = NumberUtils.roundNumber(data);
265
266
                  }
267
               },
268
               err => {
269 54850 konstantin
         		    //console.log(err);
270
                this.handleError("Error getting number of publications", err);
271 50359 argiro.kok
          		 }
272
        );
273
      }
274
      if(this.showDatasets){
275 57035 konstantin
       this.subData = this._searchResearchResultsService.numOfSearchResults("dataset", "", this.properties).subscribe(
276 50359 argiro.kok
             data => {
277
               if(data && data != null && data > 0 ){
278
                   this.datasetsSize = NumberUtils.roundNumber(data);
279
               }
280
             },
281
             err => {
282 54850 konstantin
                 //console.log(err);
283
                 this.handleError("Error getting number of research data", err);
284 50359 argiro.kok
               }
285
         );
286
       }
287 56075 argiro.kok
     if (this.showSoftware) {
288 57035 konstantin
       this.subSoft = this._searchResearchResultsService.numOfSearchResults("software", "", this.properties).subscribe(
289 56075 argiro.kok
         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 57035 konstantin
       this.subOrp = this._searchResearchResultsService.numOfSearchResults("other", "", this.properties).subscribe(
303 56075 argiro.kok
         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 50359 argiro.kok
       if(this.showProjects){
316 50587 argiro.kok
         this.subfunders = this._refineFieldResultsService.getRefineFieldsResultsByEntityName(["funder"],"project", this.properties).subscribe(
317 50359 argiro.kok
           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 54850 konstantin
               //console.log(err);
330
               this.handleError("Error getting 'funder' field results of projects", err);
331 50359 argiro.kok
        });
332
      }
333
      if(this.showDataProviders){
334 50587 argiro.kok
        this.subDataPr = this._searchDataprovidersService.numOfSearchDataproviders("", this.properties).subscribe(
335 50359 argiro.kok
           data => {
336
             if(data && data != null && data > 0 ){
337
                 this.datasourcesSize = NumberUtils.roundNumber(data);
338
             }
339
340
           },
341
           err => {
342 54850 konstantin
               //console.log(err);
343
               this.handleError("Error getting number of content providers", err);
344 50359 argiro.kok
           }
345
       );
346
     }
347
   }
348 54850 konstantin
349
   private handleError(message: string, error) {
350
       console.error("Home Page: "+message, error);
351
   }
352 50359 argiro.kok
}