Project

General

Profile

1
import {Component, Inject, Input, Optional} from '@angular/core';
2
import {Location}                 from '@angular/common';
3
import {ActivatedRoute}           from '@angular/router';
4
import {Title, Meta}              from '@angular/platform-browser';
5
import {RESPONSE} from "@nguniversal/express-engine/tokens";
6
import {EnvProperties} from "../utils/properties/env-properties";
7
import {SEOService} from "../sharedComponents/SEO/SEO.service";
8

    
9
@Component({
10
    selector: 'error',
11
    template: `
12
    <div id="tm-main" class=" uk-section  uk-margin-small-top tm-middle">
13
      <div uk-grid uk-grid>
14
       <div class="tm-main uk-width-1-1@s uk-width-1-1@m  uk-width-1-1@l uk-row-first ">
15
        <div class="uk-container">
16
            <h2>
17
                Bad karma: we can't find that page!
18
            </h2>
19
            <h5 *ngIf="page_type" class="uk-margin-remove">
20
              Not valid or missing {{page_type_name}} id. 
21
              <a *ngIf="page_type" routerLinkActive="router-link-active" [routerLink]="searchPage">Search </a>another {{page_type_name}}?
22
            </h5>
23
            <br>
24
            <p>
25
                You asked for {{page}}, but despite our computers looking very hard, we could not find it. What happened ?
26
            </p>
27
            <ul>
28
                <li>the link you clicked to arrive here has a typo in it</li>
29
                <li>or somehow we removed that page, or gave it another name</li>
30
                <li>or, quite unlikely for sure, maybe you typed it yourself and there was a little mistake ?</li>
31
            </ul>
32
        </div>
33
      </div>
34
     </div>
35
  </div>
36
    `
37
})
38

    
39
export class ErrorPageComponent {
40
    public page: string;
41
    public page_type: string;
42
    public searchPage: string;
43
    public page_type_name: string;
44

    
45
    constructor (private _location: Location, private _meta: Meta,
46
                 private _title: Title, private route: ActivatedRoute,
47
                 @Optional() @Inject(RESPONSE) private response: any,
48
                 private seoService: SEOService) {
49

    
50
        var title = "OpenAIRE | Error page";
51

    
52
        this._meta.updateTag({content:title},"property='og:title'");
53
        this._title.setTitle(title);
54
        this.page = _location.path(true);
55
        //this.page = _router.url;
56
        //this.page = location.href;
57
    }
58
    ngOnInit() {
59
      if(this.response) {
60
        this.response.statusCode = 404;
61
        this.response.statusMessage = '404 - Page not found';
62
      }
63
      this.route.data
64
        .subscribe((data: { envSpecific: EnvProperties }) => {
65
          let properties = data.envSpecific;
66
          this.seoService.createLinkForCanonicalURL(properties.baseLink + "/error");
67

    
68
          this.route.queryParams.subscribe(data => {
69
            this.page = data['page'];
70
            if (!this.page) {
71
              this.page = this._location.path(true);
72
            }
73

    
74
            this.page_type = data['page_type'];
75
            if(this.page_type) {
76
              if (this.page_type == "publication") {
77
                this.searchPage = properties.searchLinkToPublications;
78
                this.page_type_name = "publication";
79
              } else if (this.page_type == "software") {
80
                this.searchPage = properties.searchLinkToSoftware;
81
                this.page_type_name = "software";
82
              } else if (this.page_type == "dataset") {
83
                this.searchPage = properties.searchLinkToDatasets;
84
                this.page_type_name = "dataset";
85
              } else if (this.page_type == "orp") {
86
                this.searchPage = properties.searchLinkToOrps;
87
                this.page_type_name = "research product";
88
              } else if (this.page_type == "organization") {
89
                this.searchPage = properties.searchLinkToOrganizations;
90
                this.page_type_name = "organization";
91
              } else if (this.page_type == "project") {
92
                this.searchPage = properties.searchLinkToProjects;
93
                this.page_type_name = "project";
94
              } else if (this.page_type == "dataprovider") {
95
                this.searchPage = properties.searchLinkToDataProviders;
96
                this.page_type_name = "content provider";
97
              }
98
            }
99
          });
100
      });
101
    }
102
}
(2-2/3)