Project

General

Profile

1
import {Component, ViewChild} from '@angular/core';
2
import {Subscription} from 'rxjs';
3
import {ActivatedRoute, Router} from '@angular/router';
4
import {Location} from '@angular/common';
5
import "rxjs/add/observable/zip";
6
import {Meta, Title} from '@angular/platform-browser';
7
import {ConfigurationService} from '../openaireLibrary/utils/configuration/configuration.service';
8
import {SearchDataprovidersService} from '../openaireLibrary/services/searchDataproviders.service';
9
import {SearchProjectsService} from '../openaireLibrary/services/searchProjects.service';
10
import {SearchOrganizationsService} from '../openaireLibrary/services/searchOrganizations.service';
11
import {RefineFieldResultsService} from '../openaireLibrary/services/refineFieldResults.service';
12
import {SearchFields} from '../openaireLibrary/utils/properties/searchFields';
13

    
14
import {RouterHelper} from '../openaireLibrary/utils/routerHelper.class';
15
import {EnvProperties} from '../openaireLibrary/utils/properties/env-properties';
16
import {ErrorCodes} from '../openaireLibrary/utils/properties/errorCodes';
17
import {PiwikService} from '../openaireLibrary/utils/piwik/piwik.service';
18
import {SEOService} from '../openaireLibrary/sharedComponents/SEO/SEO.service';
19
import {SearchResearchResultsService} from "../openaireLibrary/services/searchResearchResults.service";
20
import {HelperService} from "../openaireLibrary/utils/helper/helper.service";
21
import {Filter} from "../openaireLibrary/searchPages/searchUtils/searchHelperClasses.class";
22
import {properties} from "../../environments/environment";
23
import {Numbers, NumbersComponent} from "../openaireLibrary/sharedComponents/numbers/numbers.component";
24

    
25
@Component({
26
  selector: 'home',
27
  templateUrl: 'home.component.html',
28
})
29
export class HomeComponent {
30
  // MAX 12 logos in every slide
31
  public logos = {
32
    "publication": [
33
      [
34
        "logo-pubmed.png",
35
        "logo-arxiv.png",
36
        "logo-base.png",
37
        "logo-scielo.png",
38
        "logo-la-referencia.png",
39
        "logo-soar.png",
40
        "logo-repec.png",
41
        "logo-core.png",
42
        "logo-zenodo.png",
43
        "logo-narcis.png"
44
      ],
45
      [
46
        "logo-crossref.png",
47
        "logo-unpaywall.png",
48
        "logo-elsevier.png",
49
        "logo-spring-nature.png",
50
        "logo-frontiers.png",
51
        "logo-opencitations.png",
52
        "logo-doaj.png",
53
        "logo-microsoft.png",
54
        "logo-plos.png",
55
        "logo-f1000.png",
56
        "logo-copernicus.png"
57
      ]
58
    ],
59
    "software": [
60
      [
61
        "logo-software-heritage.png",
62
        "logo-github.png",
63
        "logo-doecode.png",
64
        "logo-bitbucket.png",
65
        "logo-elixir-bio-tools.png",
66
        "logo-google-code.png",
67
        "logo-sourceforge.png",
68
        "logo-zenodo.png"
69
      ]
70
    ],
71
    "dataset": [
72
      [
73
        "logo-scholexplorer.png",
74
        "logo-zenodo.png",
75
        "logo-datacite.png",
76
        "logo-pangea.png",
77
        "logo-figshare.png",
78
        "logo-protocols.png",
79
        "logo-opentrials.png",
80
        "logo-kaggle.png",
81
        "logo-reactome.png",
82
        "logo-easy.png",
83
        "logo-dryad.png"
84
      ]
85
    ],
86
    //"other": [],
87
    "persistent": [
88
      [
89
        "logo-re3data.png",
90
        "logo-orcid.png",
91
        "logo-opendoar.png",
92
        "logo-grid.png"
93
      ]
94
    ],
95
    "funder": [
96
      [
97
        "logo-european-commision.png",
98
        "logo-nsf.png",
99
        "logo-miur.png",
100
        "logo-nhmrc.png",
101
        "logo-sfi.png",
102
        "logo-nwo.png",
103
        "logo-welcome-trust.png",
104
        "logo-fct.png",
105
        "logo-gsrt.png",
106
        "logo-fnsnf.png"
107
      ]
108
    ]
109
  };
110
  
111
  public pageTitle = "OpenAIRE";
112
  public keyword: string = "";
113
  
114
  public searchFields: SearchFields = new SearchFields();
115
  public errorCodes: ErrorCodes = new ErrorCodes();
116
  public routerHelper: RouterHelper = new RouterHelper();
117
  public numbers: Numbers;
118
  showPublications: boolean = false;
119
  showDatasets: boolean = false;
120
  showSoftware: boolean = false;
121
  showOrp: boolean = false;
122
  showProjects: boolean = false;
123
  showDataProviders: boolean = false;
124
  showOrganizations: boolean = false;
125
  properties: EnvProperties = properties;
126
  public readMore: boolean = false;
127
  
128
  subs: Subscription[] = [];
129
  
130
  resultsQuickFilter: { filter: Filter, selected: boolean, filterId: string, value: string } = {
131
    filter: null,
132
    selected: true,
133
    filterId: "resultbestaccessright",
134
    value: "Open Access"
135
  };
136
  selectedEntity = "all";
137
  selectedEntitySimpleUrl;
138
  selectedEntityAdvancedUrl;
139
  resultTypes: Filter = {
140
    values: [],
141
    filterId: "type",
142
    countSelectedValues: 0,
143
    filterType: 'checkbox',
144
    originalFilterId: "",
145
    valueIsExact: true,
146
    title: "Result Types",
147
    filterOperator: "or"
148
  };
149
  public pageContents = null;
150
  @ViewChild("numbersComponent") numbersComponent: NumbersComponent;
151
  
152
  constructor(
153
    private route: ActivatedRoute,
154
    private _router: Router,
155
    private _searchResearchResultsService: SearchResearchResultsService,
156
    private _searchDataprovidersService: SearchDataprovidersService,
157
    private _searchProjectsService: SearchProjectsService,
158
    private _searchOrganizationsService: SearchOrganizationsService,
159
    private _refineFieldResultsService: RefineFieldResultsService,
160
    private location: Location, private _piwikService: PiwikService,
161
    private config: ConfigurationService, private _meta: Meta, private _title: Title, private seoService: SEOService,
162
    private helper: HelperService
163
  ) {
164
    let description = "OpenAIRE Explore: Over 100M of research deduplicated, 170K research software, 11M research data. One of the largest open scholarly records collection worldwide.";
165
    let title = "OpenAIRE | Find and Share research";
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
  private getPageContents() {
173
    this.subs.push(this.helper.getPageHelpContents(this.properties, 'openaire', this._router.url).subscribe(contents => {
174
      this.pageContents = contents;
175
    }));
176
  }
177
  
178
  public getKeys(obj: {}) {
179
    return Object.keys(obj);
180
  }
181
  
182
  createRange(number) {
183
    var items: number[] = [];
184
    for (var i = 1; i <= number; i++) {
185
      items.push(i);
186
    }
187
    return items;
188
  }
189
  
190
  public ceil(num: number) {
191
    return Math.ceil(num);
192
  }
193
  
194
  public ngOnInit() {
195
    this.seoService.createLinkForCanonicalURL(this.properties.domain + this.properties.baseLink + this._router.url, false);
196
    this.getPageContents();
197
    if (this.properties != null) {
198
      var url = this.properties.domain + this.properties.baseLink + this._router.url;
199
      this._meta.updateTag({content: url}, "property='og:url'");
200
      if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
201
        this.subs.push(this._piwikService.trackView(this.properties, "OpenAIRE").subscribe());
202
      }
203
      //this.config.getCommunityInformation(this.properties, this.properties.adminToolsCommunity ).subscribe(data => {
204
      this.subs.push(this.config.communityInformationState.subscribe(data => {
205
          if (data) {
206
            var showEntity = {};
207
            for (var i = 0; i < data['entities'].length; i++) {
208
              showEntity["" + data['entities'][i]["pid"] + ""] = data['entities'][i]["isEnabled"];
209
            }
210
            this.showPublications = !!showEntity["publication"];
211
            this.showDatasets = !!showEntity["dataset"];
212
            this.showSoftware = !!showEntity["software"];
213
            this.showOrp = !!showEntity["orp"];
214
            this.showProjects = !!showEntity["project"];
215
            this.showDataProviders = !!showEntity["datasource"];
216
            this.showOrganizations = !!showEntity["organization"];
217
            if (this.showPublications) {
218
              this.resultTypes.values.push({name: "Publications", id: "publications", selected: true, number: 0});
219
            }
220
            if (this.showDatasets) {
221
              this.resultTypes.values.push({name: "Research data", id: "datasets", selected: true, number: 0});
222
            }
223
            if (this.showSoftware) {
224
              this.resultTypes.values.push({name: "Software", id: "software", selected: true, number: 0});
225
            }
226
            if (this.showOrp) {
227
              this.resultTypes.values.push({name: "Other research products", id: "other", selected: true, number: 0});
228
            }
229
            this.numbersComponent.init(this.showDatasets, this.showSoftware, this.showPublications, this.showDatasets, this.showSoftware, this.showOrp, this.showProjects, this.showDataProviders);
230
          }
231
        },
232
        error => {
233
          this.handleError("Error getting community information", error);
234
        }
235
      ));
236
    }
237
  }
238
  
239
  public ngOnDestroy() {
240
    for (let sub of this.subs) {
241
      sub.unsubscribe();
242
    }
243
  }
244
  
245
  private handleError(message: string, error) {
246
    console.error("Home Page: " + message, error);
247
  }
248
  
249
  entityChanged($event) {
250
    this.selectedEntity = $event.entity;
251
    this.selectedEntitySimpleUrl = $event.simpleUrl;
252
    this.selectedEntityAdvancedUrl = $event.advancedUrl;
253
  }
254
  
255
  goTo(simple: boolean) {
256
    let url = (simple) ? this.selectedEntitySimpleUrl : this.selectedEntityAdvancedUrl;
257
    let parameterNames = [];
258
    let parameterValues = [];
259
    if (this.selectedEntity == "result") {
260
      if (this.resultTypes) {
261
        let values = [];
262
        for (let value of this.resultTypes.values) {
263
          if (value.selected) {
264
            values.push(value.id);
265
          }
266
        }
267
        if (values.length > 0 && values.length != 4) {
268
          parameterNames.push("type");
269
          parameterValues.push(values.join(","));
270
        }
271
        if (this.resultsQuickFilter) {
272
          parameterNames.push("qf");
273
          parameterValues.push("" + this.resultsQuickFilter.selected);
274
        }
275
      }
276
    } else if (this.selectedEntity == "all") {
277
      if (this.resultsQuickFilter) {
278
        parameterNames.push("qf");
279
        parameterValues.push("true");
280
      }
281
    }
282
    if (this.keyword.length > 0) {
283
      parameterNames.push("fv0");
284
      parameterValues.push(this.keyword);
285
      parameterNames.push("f0");
286
      parameterValues.push("q");
287
    }
288
    this._router.navigate([url], {queryParams: this.routerHelper.createQueryParams(parameterNames, parameterValues)});
289
  }
290
}
(3-3/4)