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 {SEOService} from "../sharedComponents/SEO/SEO.service";
7
import {properties} from "../../../environments/environment";
8

    
9
@Component({
10
    selector: 'error',
11
    template: `
12
    <div id="tm-main" class=" uk-section tm-middle">
13
      <div uk-grid class="uk-margin-small-top">
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
            <h3>
17
              <span  *ngIf="page !='-1'">Bad karma: we can't find that page!</span>
18
              <div  *ngIf="page =='-1'" class="uk-text-center uk-margin-large-top">
19
                <svg _ngcontent-my-app-c8="" fill="black" height="24px" viewBox="0 0 24 24" width="24px" xmlns="http://www.w3.org/2000/svg"><path _ngcontent-my-app-c8="" d="M0 0h24v24H0z" fill="none"></path><path _ngcontent-my-app-c8="" d="M18 8h-1V6c0-2.76-2.24-5-5-5S7 3.24 7 6v2H6c-1.1 0-2 .9-2 2v10c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V10c0-1.1-.9-2-2-2zm-6 9c-1.1 0-2-.9-2-2s.9-2 2-2 2 .9 2 2-.9 2-2 2zm3.1-9H8.9V6c0-1.71 1.39-3.1 3.1-3.1 1.71 0 3.1 1.39 3.1 3.1v2z"></path></svg>
20
              Private Data</div>
21
            </h3>
22
            <h6 *ngIf="page_type" class="uk-margin-remove">
23
              Not valid or missing {{page_type_name}} id. 
24
              <a *ngIf="page_type" routerLinkActive="router-link-active" [routerLink]="searchPage">Search </a>another {{page_type_name}}?
25
            </h6>
26
            <br>
27
          <div *ngIf="page !='-1'">
28
            <p>
29
                You asked for {{page}}, but despite our computers looking very hard, we could not find it. What happened ?
30
            </p>
31
            <ul>
32
                <li>the link you clicked to arrive here has a typo in it</li>
33
                <li>or somehow we removed that page, or gave it another name</li>
34
                <li>or, quite unlikely for sure, maybe you typed it yourself and there was a little mistake ?</li>
35
            </ul>
36
          </div>
37
        </div>
38
      </div>
39
     </div>
40
  </div>
41
    `
42
})
43

    
44
export class ErrorPageComponent {
45
    @Input() public page: string;
46
    public page_type: string;
47
    public searchPage: string;
48
    public page_type_name: string;
49

    
50
    constructor (private _location: Location, private _meta: Meta,
51
                 private _title: Title, private route: ActivatedRoute,
52
                 @Optional() @Inject(RESPONSE) private response: any,
53
                 private seoService: SEOService) {}
54
                 
55
    ngOnInit() {
56
      this.seoService.createLinkForCanonicalURL(properties.domain + properties.baseLink + "/error");
57
      this.route.queryParams.subscribe(data => {
58
        this.page = this.page?this.page:data['page'];
59
        if (!this.page) {
60
          this.page = this._location.path(true);
61
        }
62
        if(this.response) {
63
          this.response.statusCode = 404;
64
          this.response.statusMessage = '404 - Page not found';
65
        }
66
        if(this.page != "-1") {
67
          let title = "OpenAIRE | Error page";
68
          this._meta.updateTag({content:title},"property='og:title'");
69
          this._title.setTitle(title);
70
        } else{
71
          let title = "OpenAIRE | Private data";
72
          this._meta.updateTag({content:title},"property='og:title'");
73
          this._title.setTitle(title);
74
        }
75
        this.page_type = data['page_type'];
76
        if(this.page_type) {
77
          if (this.page_type == "publication") {
78
            this.searchPage = properties.searchLinkToPublications;
79
            this.page_type_name = "publication";
80
          } else if (this.page_type == "software") {
81
            this.searchPage = properties.searchLinkToSoftware;
82
            this.page_type_name = "software";
83
          } else if (this.page_type == "dataset") {
84
            this.searchPage = properties.searchLinkToDatasets;
85
            this.page_type_name = "dataset";
86
          } else if (this.page_type == "orp") {
87
            this.searchPage = properties.searchLinkToOrps;
88
            this.page_type_name = "research product";
89
          } else if (this.page_type == "organization") {
90
            this.searchPage = properties.searchLinkToOrganizations;
91
            this.page_type_name = "organization";
92
          } else if (this.page_type == "project") {
93
            this.searchPage = properties.searchLinkToProjects;
94
            this.page_type_name = "project";
95
          } else if (this.page_type == "dataprovider") {
96
            this.searchPage = properties.searchLinkToDataProviders;
97
            this.page_type_name = "content provider";
98
          }
99
        }
100
      });
101
    }
102
}
(2-2/3)