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 {Title, Meta} 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
import {NumberUtils} from '../openaireLibrary/utils/number-utils.class';
14

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

    
26
@Component({
27
  selector: 'home',
28
  templateUrl: 'home.component.html',
29
})
30
export class HomeComponent {
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
  public numbers: Numbers;
119
  showPublications: boolean = false;
120
  showDatasets: boolean = false;
121
  showSoftware: boolean = false;
122
  showOrp: boolean = false;
123
  showProjects: boolean = false;
124
  showDataProviders: boolean = false;
125
  showOrganizations: boolean = false;
126
  properties: EnvProperties = properties;
127
  public readMore: boolean = false;
128
  
129
  subs: Subscription[] = [];
130
  
131
  resultsQuickFilter: { filter: Filter, selected: boolean, filterId: string, value: string } = {
132
    filter: null,
133
    selected: true,
134
    filterId: "resultbestaccessright",
135
    value: "Open Access"
136
  };
137
  selectedEntity = "all";
138
  selectedEntitySimpleUrl;
139
  selectedEntityAdvancedUrl;
140
  resultTypes: Filter = {
141
    values: [],
142
    filterId: "type",
143
    countSelectedValues: 0,
144
    filterType: 'checkbox',
145
    originalFilterId: "",
146
    valueIsExact: true,
147
    title: "Result Types",
148
    filterOperator: "or"
149
  };
150
  public pageContents = null;
151
  @ViewChild("numbersComponent") numbersComponent: NumbersComponent;
152
  
153
  constructor(
154
    private route: ActivatedRoute,
155
    private _router: Router,
156
    private _searchResearchResultsService: SearchResearchResultsService,
157
    private _searchDataprovidersService: SearchDataprovidersService,
158
    private _searchProjectsService: SearchProjectsService,
159
    private _searchOrganizationsService: SearchOrganizationsService,
160
    private _refineFieldResultsService: RefineFieldResultsService,
161
    private location: Location, private _piwikService: PiwikService,
162
    private config: ConfigurationService, private _meta: Meta, private _title: Title, private seoService: SEOService,
163
    private helper: HelperService
164
  ) {
165
    let description = "OpenAIRE Explore: Over 100M of research deduplicated, 170K research software, 11M research data. One of the largest open scholarly records collection worldwide.";
166
    let title = "OpenAIRE | Find and Share research";
167
    this._title.setTitle(title);
168
    this._meta.updateTag({content: description}, "name='description'");
169
    this._meta.updateTag({content: description}, "property='og:description'");
170
    this._meta.updateTag({content: title}, "property='og:title'");
171
  }
172
  
173
  private getPageContents() {
174
    this.subs.push(this.helper.getPageHelpContents(this.properties, 'openaire', this._router.url).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.seoService.createLinkForCanonicalURL(this.properties.domain + this.properties.baseLink + this._router.url, false);
197
    this.getPageContents();
198
    if (this.properties != null) {
199
      var url = this.properties.domain + this.properties.baseLink + this._router.url;
200
      this._meta.updateTag({content: url}, "property='og:url'");
201
      if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
202
        this.subs.push(this._piwikService.trackView(this.properties, "OpenAIRE").subscribe());
203
      }
204
      //this.config.getCommunityInformation(this.properties, this.properties.adminToolsCommunity ).subscribe(data => {
205
      this.subs.push(this.config.communityInformationState.subscribe(data => {
206
          if (data) {
207
            var showEntity = {};
208
            for (var i = 0; i < data['entities'].length; i++) {
209
              showEntity["" + data['entities'][i]["pid"] + ""] = data['entities'][i]["isEnabled"];
210
            }
211
            this.showPublications = showEntity["publication"];
212
            this.showDatasets = showEntity["dataset"];
213
            this.showSoftware = showEntity["software"];
214
            this.showOrp = showEntity["orp"];
215
            this.showProjects = showEntity["project"];
216
            this.showDataProviders = showEntity["datasource"];
217
            this.showOrganizations = showEntity["organization"];
218
            if (this.showPublications) {
219
              this.resultTypes.values.push({name: "Publications", id: "publications", selected: true, number: 0});
220
            }
221
            if (this.showDatasets) {
222
              this.resultTypes.values.push({name: "Research data", id: "datasets", selected: true, number: 0});
223
            }
224
            if (this.showSoftware) {
225
              this.resultTypes.values.push({name: "Software", id: "software", selected: true, number: 0});
226
            }
227
            if (this.showOrp) {
228
              this.resultTypes.values.push({name: "Other research products", id: "other", selected: true, number: 0});
229
            }
230
            this.numbersComponent.init(this.showDatasets, this.showSoftware, this.showPublications, this.showDatasets, this.showSoftware, this.showOrp, this.showProjects, this.showDataProviders);
231
          }
232
        },
233
        error => {
234
          this.handleError("Error getting community information", error);
235
        }
236
      ));
237
    }
238
  }
239
  
240
  public ngOnDestroy() {
241
    for (let sub of this.subs) {
242
      sub.unsubscribe();
243
    }
244
  }
245
  
246
  private handleError(message: string, error) {
247
    console.error("Home Page: " + message, error);
248
  }
249
  
250
  entityChanged($event) {
251
    this.selectedEntity = $event.entity;
252
    this.selectedEntitySimpleUrl = $event.simpleUrl;
253
    this.selectedEntityAdvancedUrl = $event.advancedUrl;
254
  }
255
  
256
  goTo(simple: boolean) {
257
    let url = (simple) ? this.selectedEntitySimpleUrl : this.selectedEntityAdvancedUrl;
258
    let parameterNames = [];
259
    let parameterValues = [];
260
    if (this.selectedEntity == "result") {
261
      if (this.resultTypes) {
262
        let values = [];
263
        for (let value of this.resultTypes.values) {
264
          if (value.selected) {
265
            values.push(value.id);
266
          }
267
        }
268
        if (values.length > 0 && values.length != 4) {
269
          parameterNames.push("type");
270
          parameterValues.push(values.join(","));
271
        }
272
        if (this.resultsQuickFilter) {
273
          parameterNames.push("qf");
274
          parameterValues.push("" + this.resultsQuickFilter.selected);
275
        }
276
      }
277
    } else if (this.selectedEntity == "all") {
278
      if (this.resultsQuickFilter) {
279
        parameterNames.push("qf");
280
        parameterValues.push("true");
281
      }
282
    }
283
    if (this.keyword.length > 0) {
284
      parameterNames.push("fv0");
285
      parameterValues.push(this.keyword);
286
      parameterNames.push("f0");
287
      parameterValues.push("q");
288
    }
289
    console.log(this.routerHelper.createQueryParams(parameterNames, parameterValues))
290
    this._router.navigate([url], {queryParams: this.routerHelper.createQueryParams(parameterNames, parameterValues)});
291
  }
292
}
(3-3/4)