From 90f748f8e6669f31dbde8f3c5eea3730274dcaa7 Mon Sep 17 00:00:00 2001 From: "konstantina.galouni" Date: Thu, 7 Nov 2019 09:51:09 +0000 Subject: [PATCH] [Trunk | Library]: 1. error.module & errorPage.component: Set canonical url to '/error'. 2. dataProvider.component & organization.component & project.component & resultLanding.component: Use 'location.path(true)' for page parameter in error navigation. 3. organization.service: [Bug fix]: Initialize 'objIdentifier' field only when an organization was found. git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@57536 d315682c-612b-4755-9ff5-7f18f6832af3 --- error/error.module.ts | 3 +- error/errorPage.component.ts | 31 +++++++++++-------- .../dataProvider/dataProvider.component.ts | 8 +++-- .../organization/organization.component.ts | 9 ++++-- landingPages/project/project.component.ts | 8 +++-- .../result/resultLanding.component.ts | 9 +++--- services/organization.service.ts | 2 +- 7 files changed, 41 insertions(+), 29 deletions(-) diff --git a/error/error.module.ts b/error/error.module.ts index 02de4ec5..2ea188a9 100644 --- a/error/error.module.ts +++ b/error/error.module.ts @@ -4,10 +4,11 @@ import {FormsModule} from '@angular/forms'; import {ErrorPageComponent} from './errorPage.component'; import {RouterModule} from "@angular/router"; +import { SEOServiceModule } from '../sharedComponents/SEO/SEOService.module'; @NgModule({ imports: [ - CommonModule, FormsModule, RouterModule + CommonModule, FormsModule, RouterModule, SEOServiceModule ], providers: [], declarations: [ diff --git a/error/errorPage.component.ts b/error/errorPage.component.ts index 92a47198..66959271 100644 --- a/error/errorPage.component.ts +++ b/error/errorPage.component.ts @@ -4,6 +4,7 @@ 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', @@ -43,7 +44,8 @@ export class ErrorPageComponent { constructor (private _location: Location, private _meta: Meta, private _title: Title, private route: ActivatedRoute, - @Optional() @Inject(RESPONSE) private response: any) { + @Optional() @Inject(RESPONSE) private response: any, + private seoService: SEOService) { var title = "OpenAIRE | Error page"; @@ -58,16 +60,19 @@ export class ErrorPageComponent { this.response.statusCode = 404; this.response.statusMessage = '404 - Page not found'; } - 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) { - this.route.data - .subscribe((data: { envSpecific: EnvProperties }) => { - let properties = data.envSpecific; + 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"; @@ -90,8 +95,8 @@ export class ErrorPageComponent { this.searchPage = properties.searchLinkToDataProviders; this.page_type_name = "content provider"; } - }); - } + } + }); }); } } diff --git a/landingPages/dataProvider/dataProvider.component.ts b/landingPages/dataProvider/dataProvider.component.ts index 53fe5d1c..1361ab96 100644 --- a/landingPages/dataProvider/dataProvider.component.ts +++ b/landingPages/dataProvider/dataProvider.component.ts @@ -20,6 +20,7 @@ import {PiwikService} from '../../utils/piwik/piwik.service'; import {SEOService} from '../../sharedComponents/SEO/SEO.service'; import {HelperFunctions} from "../../utils/HelperFunctions.class"; import {HelperService} from "../../utils/helper/helper.service"; +import {Location} from "@angular/common"; @Component({ @@ -105,7 +106,8 @@ export class DataProviderComponent { private _searchProjectsService: SearchProjectsService, private _searchDataprovidersService: SearchDataprovidersService, private seoService: SEOService, - private helper: HelperService) { + private helper: HelperService, + private _location: Location) { this.fetchPublications = new FetchResearchResults(this._searchResearchResultsService); this.fetchDatasets = new FetchResearchResults(this._searchResearchResultsService); this.fetchSoftware = new FetchResearchResults(this._searchResearchResultsService); @@ -132,7 +134,7 @@ export class DataProviderComponent { this.getDataProviderInfo(this.datasourceId); } else { this.showLoading = false; - this._router.navigate(['/error'], {queryParams: {"page": this.properties.searchLinkToDataProvider + this.datasourceId, "page_type": "dataprovider"}}); + this._router.navigate(['/error'], {queryParams: {"page": this._location.path(true), "page_type": "dataprovider"}}); } HelperFunctions.scroll(); @@ -204,7 +206,7 @@ export class DataProviderComponent { //console.log(err); this.handleError("Error getting content provider for id: " + this.datasourceId, err); if(err.status == 404) { - this._router.navigate(['/error'], {queryParams: {"page": this.properties.searchLinkToDataProvider + this.datasourceId, "page_type": "dataprovider"}}); + this._router.navigate(['/error'], {queryParams: {"page": this._location.path(true), "page_type": "dataprovider"}}); } //this.errorMessage = 'No dataProvider found'; this.showLoading = false; diff --git a/landingPages/organization/organization.component.ts b/landingPages/organization/organization.component.ts index b785410a..0b188645 100644 --- a/landingPages/organization/organization.component.ts +++ b/landingPages/organization/organization.component.ts @@ -24,6 +24,7 @@ import {EnvProperties} from '../../utils/properties/env-properties'; import {SEOService} from '../../sharedComponents/SEO/SEO.service'; import {HelperFunctions} from "../../utils/HelperFunctions.class"; import {HelperService} from "../../utils/helper/helper.service"; +import {Location} from "@angular/common"; @Component({ selector: 'organization', @@ -118,7 +119,8 @@ export class OrganizationComponent { private _title: Title, private _router: Router, private helper: HelperService, - private seoService: SEOService) { + private seoService: SEOService, + private _location: Location) { this.fetchPublications = new FetchResearchResults(this._searchResearchResultsService); // this.fetchDatasets = new FetchDatasets(this._searchDatasetsService); @@ -146,7 +148,7 @@ export class OrganizationComponent { this.getOrganizationInfo(); } else { this.showLoading = false; - this._router.navigate(['/error'], {queryParams: {"page": this.properties.searchLinkToOrganization + this.organizationId, "page_type": "organization"}}); + this._router.navigate(['/error'], {queryParams: {"page": this._location.path(true), "page_type": "organization"}}); //this.warningMessage = "No valid organization id"; } @@ -219,6 +221,7 @@ export class OrganizationComponent { data => { if (data == null) { this.showLoading = false; + this._router.navigate(['/error'], {queryParams: {"page": this._location.path(true), "page_type": "organization"}}); this.errorMessage = 'No organization found'; } else { this.organizationInfo = data; @@ -256,7 +259,7 @@ export class OrganizationComponent { //console.log(err) this.handleError("Error getting organization for id: " + this.organizationId, err); if(err.status == 404) { - this._router.navigate(['/error'], {queryParams: {"page": this.properties.searchLinkToOrganization + this.organizationId, "page_type": "organization"}}); + this._router.navigate(['/error'], {queryParams: {"page": this._location.path(true), "page_type": "organization"}}); } this.seoService.createLinkForCanonicalURL(this.properties.baseLink + this.properties.searchLinkToOrganizations); //this.errorMessage = 'No organization found'; diff --git a/landingPages/project/project.component.ts b/landingPages/project/project.component.ts index 416451ba..dc31b61e 100644 --- a/landingPages/project/project.component.ts +++ b/landingPages/project/project.component.ts @@ -19,6 +19,7 @@ import {EnvProperties} from '../../utils/properties/env-properties'; import {SEOService} from '../../sharedComponents/SEO/SEO.service'; import {HelperFunctions} from "../../utils/HelperFunctions.class"; import {HelperService} from "../../utils/helper/helper.service"; +import {Location} from "@angular/common"; @Component({ selector: 'project', @@ -110,7 +111,8 @@ export class ProjectComponent { private _title: Title, private _router: Router, private helper: HelperService, - private seoService: SEOService) { + private seoService: SEOService, + private _location: Location) { } ngOnInit() { @@ -148,7 +150,7 @@ export class ProjectComponent { } else { this.showLoading = false; - this._router.navigate(['/error'], {queryParams: {"page": this.properties.searchLinkToProject + this.projectId, "page_type": "project"}}); + this._router.navigate(['/error'], {queryParams: {"page": this._location.path(true), "page_type": "project"}}); //this.warningMessage = "No valid project id"; } @@ -331,7 +333,7 @@ export class ProjectComponent { //console.log(err); this.handleError("Error getting project for id: " + this.projectId, err); if(err.status == 404) { - this._router.navigate(['/error'], {queryParams: {"page": this.properties.searchLinkToProject + this.projectId, "page_type": "project"}}); + this._router.navigate(['/error'], {queryParams: {"page": this._location.path(true), "page_type": "project"}}); } this.seoService.createLinkForCanonicalURL(this.properties.baseLink + this.properties.searchLinkToProjects); //this.errorMessage = 'No project found'; diff --git a/landingPages/result/resultLanding.component.ts b/landingPages/result/resultLanding.component.ts index e7f51ce5..ad902051 100644 --- a/landingPages/result/resultLanding.component.ts +++ b/landingPages/result/resultLanding.component.ts @@ -11,7 +11,7 @@ import {ResultLandingService} from './resultLanding.service'; import {SEOService} from '../../sharedComponents/SEO/SEO.service'; import {HelperFunctions} from '../../utils/HelperFunctions.class'; import {HelperService} from '../../utils/helper/helper.service'; -import {isPlatformBrowser} from "@angular/common"; +import {Location} from "@angular/common"; import {LoginErrorCodes} from "../../login/utils/guardHelper.class"; @@ -97,8 +97,7 @@ export class ResultLandingComponent { private _router: Router, private helper: HelperService, private seoService: SEOService, - @Inject(PLATFORM_ID) private platformId: string) { - this.testBrowser = isPlatformBrowser(platformId); + private _location: Location) { } ngOnInit() { @@ -146,7 +145,7 @@ export class ResultLandingComponent { } else { this.showLoading = false; - this._router.navigate(['/error'], {queryParams: {"page": this.linkToSearchPage + this.id, "page_type": this.type}}); + this._router.navigate(['/error'], {queryParams: {"page": this._location.path(true), "page_type": this.type}}); /* this.warningMessage = "No valid "; if(this.type == "publication" || this.type == "software") { @@ -292,7 +291,7 @@ export class ResultLandingComponent { this.handleError("Error getting "+this.type+" for id: " + this.id, err); if(err.status == 404) { - this._router.navigate(['/error'], {queryParams: {"page": this.linkToSearchPage + this.id, "page_type": this.type}}); + this._router.navigate(['/error'], {queryParams: {"page": this._location.path(true), "page_type": this.type}}); } if(this.type == "publication" || this.type == "software") { diff --git a/services/organization.service.ts b/services/organization.service.ts index 4cd65c8a..dead6d04 100644 --- a/services/organization.service.ts +++ b/services/organization.service.ts @@ -50,9 +50,9 @@ export class OrganizationService { let organization; let relations; - this.organizationInfo.objIdentifier = data["result"]["header"]["dri:objIdentifier"]; if(data != null) { organization = data['result']['metadata']['oaf:entity']['oaf:organization']; + this.organizationInfo.objIdentifier = data["result"]["header"]["dri:objIdentifier"]; relations = data['result']['metadata']['oaf:entity']['oaf:organization']['rels']['rel']; } else { return null;