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 {Meta, Title} from '@angular/platform-browser';
6
import {ConfigurationService} from '../openaireLibrary/utils/configuration/configuration.service';
7
import {SearchDataprovidersService} from '../openaireLibrary/services/searchDataproviders.service';
8
import {SearchProjectsService} from '../openaireLibrary/services/searchProjects.service';
9
import {SearchOrganizationsService} from '../openaireLibrary/services/searchOrganizations.service';
10
import {RefineFieldResultsService} from '../openaireLibrary/services/refineFieldResults.service';
11
import {SearchFields} from '../openaireLibrary/utils/properties/searchFields';
12

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

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