openaire-library/error/errorPage.component.ts

103 lines
4.2 KiB
TypeScript

import {Component, Inject, Input, Optional} from '@angular/core';
import {Location} from '@angular/common';
import {ActivatedRoute} from '@angular/router';
import {Title, Meta} from '@angular/platform-browser';
import {RESPONSE} from "@nguniversal/express-engine/tokens";
import {EnvProperties} from "../utils/properties/env-properties";
import {SEOService} from "../sharedComponents/SEO/SEO.service";
@Component({
selector: 'error',
template: `
<div id="tm-main" class=" uk-section uk-margin-small-top tm-middle">
<div uk-grid uk-grid>
<div class="tm-main uk-width-1-1@s uk-width-1-1@m uk-width-1-1@l uk-row-first ">
<div class="uk-container">
<h2>
Bad karma: we can't find that page!
</h2>
<h5 *ngIf="page_type" class="uk-margin-remove">
Not valid or missing {{page_type_name}} id.
<a *ngIf="page_type" routerLinkActive="router-link-active" [routerLink]="searchPage">Search </a>another {{page_type_name}}?
</h5>
<br>
<p>
You asked for {{page}}, but despite our computers looking very hard, we could not find it. What happened ?
</p>
<ul>
<li>the link you clicked to arrive here has a typo in it</li>
<li>or somehow we removed that page, or gave it another name</li>
<li>or, quite unlikely for sure, maybe you typed it yourself and there was a little mistake ?</li>
</ul>
</div>
</div>
</div>
</div>
`
})
export class ErrorPageComponent {
public page: string;
public page_type: string;
public searchPage: string;
public page_type_name: string;
constructor (private _location: Location, private _meta: Meta,
private _title: Title, private route: ActivatedRoute,
@Optional() @Inject(RESPONSE) private response: any,
private seoService: SEOService) {
var title = "OpenAIRE | Error page";
this._meta.updateTag({content:title},"property='og:title'");
this._title.setTitle(title);
this.page = _location.path(true);
//this.page = _router.url;
//this.page = location.href;
}
ngOnInit() {
if(this.response) {
this.response.statusCode = 404;
this.response.statusMessage = '404 - Page not found';
}
this.route.data
.subscribe((data: { envSpecific: EnvProperties }) => {
let properties = data.envSpecific;
this.seoService.createLinkForCanonicalURL(properties.baseLink + "/error");
this.route.queryParams.subscribe(data => {
this.page = data['page'];
if (!this.page) {
this.page = this._location.path(true);
}
this.page_type = data['page_type'];
if(this.page_type) {
if (this.page_type == "publication") {
this.searchPage = properties.searchLinkToPublications;
this.page_type_name = "publication";
} else if (this.page_type == "software") {
this.searchPage = properties.searchLinkToSoftware;
this.page_type_name = "software";
} else if (this.page_type == "dataset") {
this.searchPage = properties.searchLinkToDatasets;
this.page_type_name = "dataset";
} else if (this.page_type == "orp") {
this.searchPage = properties.searchLinkToOrps;
this.page_type_name = "research product";
} else if (this.page_type == "organization") {
this.searchPage = properties.searchLinkToOrganizations;
this.page_type_name = "organization";
} else if (this.page_type == "project") {
this.searchPage = properties.searchLinkToProjects;
this.page_type_name = "project";
} else if (this.page_type == "dataprovider") {
this.searchPage = properties.searchLinkToDataProviders;
this.page_type_name = "content provider";
}
}
});
});
}
}