landing pages: keep the loaded url as canonical if there is a timeout error - show the correct message

This commit is contained in:
argirok 2021-12-17 15:39:32 +02:00
parent ca430fd89f
commit f911dec31e
4 changed files with 94 additions and 76 deletions

View File

@ -145,6 +145,7 @@ export class DataProviderComponent {
//this.getDivContents();
this.getPageContents();
this.updateUrl(this.properties.domain + this.properties.baseLink + this._router.url);
this.seoService.createLinkForCanonicalURL(this.properties.domain +this.properties.baseLink + this._router.url);
this.subscriptions.push(this.route.queryParams.subscribe(data => {
this.updateTitle("Content provider");
this.updateDescription("");
@ -259,10 +260,13 @@ export class DataProviderComponent {
"page_type": "dataprovider"
}
});
}else if(err.name == "TimeoutError"){
this.errorMessage = 'An error occurred please try again later';
}else {
this.errorMessage = 'No dataProvider found';
this.seoService.createLinkForCanonicalURL(this.properties.domain + this.properties.baseLink + this.properties.searchLinkToDataProviders);
}
this.errorMessage = 'No dataProvider found';
this.showLoading = false;
this.seoService.createLinkForCanonicalURL(this.properties.domain + this.properties.baseLink + this.properties.searchLinkToDataProviders);
}
));
}

View File

@ -32,20 +32,20 @@ import {properties} from "../../../../environments/environment";
export class OrganizationComponent {
@Input() piwikSiteId = null;
@Input() communityId = null;
public organizationInfo: OrganizationInfo;
public organizationId: string;
// Message variables
public warningMessage = "";
public errorMessage = "";
public showLoading: boolean = true;
// CSV variables
public downloadURLAPI: string;
public csvProjectParamsHead: string;
public csvParamsTail: string;
// Variables for publications, research data, projects, dataproviders tabs
public fetchProjects: FetchProjects;
public fetchPublications: FetchResearchResults;
@ -67,18 +67,18 @@ export class OrganizationComponent {
@ViewChild('downloadReportModal') downloadReportModal;
@ViewChild('downloadFunderReportModal') downloadFunderReportModal;
@ViewChild(ModalLoading) loading: ModalLoading;
// Alert box when CSV: Project Publications for a funder is requested
@ViewChild('AlertModalApplyAll') alertApplyAll;
// Alert box when something is wrong with CSV requests
@ViewChild('AlertModalCsvError') alertCsvError;
public routerHelper: RouterHelper = new RouterHelper();
public errorCodes: ErrorCodes = new ErrorCodes();
public pageContents = null;
public divContents = null;
// Helper variables to specify funder in downloadPublicationsFile function
public contentTypes: [string, string][] = [
['results', 'all research outcomes'],
@ -97,11 +97,11 @@ export class OrganizationComponent {
public indexUpdateDate: Date;
public showFeedback: boolean = false;
public feedbackFields: string [] = ['Name', 'Country', 'Other'];
@ViewChild('AlertModalDeletedByInference') alertModalDeletedByInference;
@ViewChild('projectsModal') projectsModal;
public deleteByInferenceOpened: boolean = false;
constructor(private element: ElementRef,
private _organizationService: OrganizationService,
@ -125,7 +125,7 @@ export class OrganizationComponent {
this.fetchSoftware = new FetchResearchResults(this._searchResearchResultsService);
this.fetchOrps = new FetchResearchResults(this._searchResearchResultsService);
}
ngOnInit() {
this.properties = properties;
@ -139,14 +139,15 @@ export class OrganizationComponent {
//this.getDivContents();
this.getPageContents();
this.updateUrl(this.properties.domain + this.properties.baseLink + this._router.url);
this.seoService.createLinkForCanonicalURL(this.properties.domain +this.properties.baseLink + this._router.url);
this.subscriptions.push(this.route.queryParams.subscribe(params => {
this.organizationInfo = null;
this.updateTitle("Organization");
this.updateDescription("");
this.organizationId = params['organizationId'];
if (this.organizationId && StringUtils.isOpenAIREID(this.organizationId)) {
this.getOrganizationInfo();
} else {
@ -160,13 +161,13 @@ export class OrganizationComponent {
}
this.csvParamsTail = '" and relorganizationid exact "' + this.organizationId + '" ))';
}));
this.downloadURLAPI = this.properties.csvAPIURL;
//this.csvAffiliatedPublications = this.downloadURLAPI + "?format=csv&type=publications&fq=(((oaftype exact result) and (resulttypeid exact publication)) and (relorganizationid exact \"" + this.organizationId + "\"))";
this.csvProjectParamsHead = 'format=csv&type=projects&fq=((funder exact "';
//this.csvPublicationParamsHead = 'format=csv-special&type=publications&page=0&query=((((oaftype exact result) and (resulttypeid exact publication)) and (funderid exact ';
}
private getPageContents() {
if(this.communityId) {
this.subscriptions.push(this.helper.getPageHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => {
@ -174,7 +175,7 @@ export class OrganizationComponent {
}));
}
}
private getDivContents() {
if(this.communityId) {
this.subscriptions.push(this.helper.getDivHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => {
@ -209,11 +210,11 @@ export class OrganizationComponent {
this.fetchSoftware.getNumForEntity('software', 'organization', this.organizationId, this.properties);
this.fetchOrps.getNumForEntity('other', 'organization', this.organizationId, this.properties);
}
private getTotalDataproviders() {
this.fetchDataproviders.getNumForEntity('organization', this.organizationId, this.properties);
}
// private searchContentProviders() {
// this.fetchDataproviders.getResultsForEntity("organization", this.organizationId, 1, this.searchNumber, this.properties);
// }
@ -227,7 +228,7 @@ export class OrganizationComponent {
}
this.reloadDataproviders = false;
}
// private searchPublications() {
// this.fetchPublications.getResultsForEntity("publication", "organization", this.organizationId, 1, size, this.properties);
// }
@ -241,7 +242,7 @@ export class OrganizationComponent {
}
this.reloadPublications = false;
}
// private searchDatasets() {
// this.fetchDatasets.getResultsForEntity("dataset", "organization", this.organizationId, 1, this.searchNumber, this.properties);
// }
@ -283,13 +284,13 @@ export class OrganizationComponent {
}
this.reloadOrps = false;
}
private getOrganizationInfo() {
this.warningMessage = '';
this.errorMessage = ""
this.showLoading = true;
this.organizationInfo = null;
this.subscriptions.push(this._organizationService.getOrganizationInfo(this.organizationId, this.properties).subscribe(
@ -337,14 +338,17 @@ export class OrganizationComponent {
"page_type": "organization"
}
});
}else if(err.name == "TimeoutError"){
this.errorMessage = 'An error occurred please try again later';
}else {
this.seoService.createLinkForCanonicalURL(this.properties.domain + this.properties.baseLink + this.properties.searchLinkToOrganizations);
this.errorMessage = 'No organization found';
}
this.seoService.createLinkForCanonicalURL(this.properties.domain+ this.properties.baseLink + this.properties.searchLinkToOrganizations);
this.errorMessage = 'No organization found';
this.showLoading = false;
}
));
}
public downloadFile(url: string, filename: string) {
this.openLoading();
this.setMessageLoading("Downloading CSV file");
@ -352,7 +356,7 @@ export class OrganizationComponent {
this.subscriptions.push(this._reportsService.downloadCSVFile(url).subscribe(
data => {
this.closeLoading();
var url = window.URL.createObjectURL(data);
var a = window.document.createElement('a');
window.document.body.appendChild(a);
@ -362,7 +366,7 @@ export class OrganizationComponent {
a.click();
window.URL.revokeObjectURL(url);
a.remove(); // remove the element
//window.open(window.URL.createObjectURL(data));
if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
this.subscriptions.push(this._piwikService.trackDownload(this.properties, "DownloadCSV" + filename, this.piwikSiteId).subscribe());
@ -371,26 +375,26 @@ export class OrganizationComponent {
err => {
//console.log("Error downloading the file.");
this.handleError("Error downloading file: " + filename + ".csv", err);
this.closeLoading();
this.confirmOpenCsvError();
}/*,
() => console.log('Completed file download.')*/
));
}
private downloadFileByFunder() {
this.openLoading();
this.setMessageLoading("Downloading CSV file");
let response: string[] = [];
let totalResponse: string = "";
let projects = [];
let counter: number = this.funderCount;
let title: boolean = false;
let title_index: number = 0;
let filename: string = 'funder-project-' + this.funderContentType + '-report';
this.subscriptions.push(this._searchProjectsService.getProjectsForOrganizations(this.organizationId, ' and (funder exact "' + this.encodeURI(this.funderId) + '" ) ', 1, this.funderCount, [], this.properties).subscribe(
@ -404,7 +408,7 @@ export class OrganizationComponent {
counter--;
response[index] = "";
//console.info("index: "+index, "counter: "+counter, "id:"+projects[index].id, response[index]);
if (counter == 0) {
//for(let i=count-1; i>=0; i--) {
for (let i = 0; i < projects.length; i++) {
@ -417,7 +421,7 @@ export class OrganizationComponent {
}
}
this.closeLoading();
var csvurl = window.URL.createObjectURL(new Blob([totalResponse], {type: 'text/csv'}));
var a = window.document.createElement('a');
window.document.body.appendChild(a);
@ -447,7 +451,7 @@ export class OrganizationComponent {
counter--;
response[index] = data;
//console.info("index: "+index, "counter: "+counter, "id:"+projects[index].id, response[index]);
if (counter == 0) {
//for(let i=count-1; i>=0; i--) {
for (let i = 0; i < projects.length; i++) {
@ -460,7 +464,7 @@ export class OrganizationComponent {
}
}
this.closeLoading();
var csvurl = window.URL.createObjectURL(new Blob([totalResponse], {type: 'text/csv'}));
var a = window.document.createElement('a');
window.document.body.appendChild(a);
@ -477,7 +481,7 @@ export class OrganizationComponent {
},
err => {
this.handleError("Error downloading file: " + filename, err);
this.closeLoading();
this.confirmOpenCsvError();
this.innerReportSubscriptions.forEach(subscription => subscription.unsubscribe());
@ -496,18 +500,18 @@ export class OrganizationComponent {
},
err => {
this.handleError("Error getting projects for organization with id: " + this.organizationId, err);
this.closeLoading();
this.confirmOpenCsvError();
}
));
}
private updateDescription(description: string) {
this._meta.updateTag({content: description.substring(0, 160)}, "name='description'");
this._meta.updateTag({content: description.substring(0, 160)}, "property='og:description'");
}
private updateTitle(title: string) {
var _prefix = "";
// if(!this.communityId) {
@ -517,11 +521,11 @@ export class OrganizationComponent {
this._title.setTitle(title);
this._meta.updateTag({content: title}, "property='og:title'");
}
private updateUrl(url: string) {
this._meta.updateTag({content: url}, "property='og:url'");
}
private openLoading() {
this.closeDownloadReportModal();
this.closeDownloadFunderReportModal();
@ -530,19 +534,19 @@ export class OrganizationComponent {
this.loading.open();
}
}
private closeLoading() {
if (this.loading) {
this.loading.close();
}
}
private setMessageLoading(message: string) {
if (this.loading) {
this.loading.message = message;
}
}
public confirmOpenApplyAll(contentType: string) {
this.alertApplyAll.cancelButton = true;
this.alertApplyAll.okButton = true;
@ -555,11 +559,11 @@ export class OrganizationComponent {
this.funderCount = this.funder.number;
this.funderContentType = contentType;
}
public confirmCloseApplyAll() {
this.downloadFileByFunder();
}
public confirmOpenCsvError() {
this.alertCsvError.cancelButton = false;
this.alertCsvError.okButton = true;
@ -568,15 +572,15 @@ export class OrganizationComponent {
this.alertCsvError.okButtonText = "OK";
this.alertCsvError.open();
}
encodeURI(input: string): string {
return StringUtils.URIEncode(input);
}
private handleError(message: string, error) {
console.error("Organizaton Landing Page: " + message, error);
}
openDeletedByInference() {
this.deleteByInferenceOpened = true;
this.alertModalDeletedByInference.cancelButton = false;
@ -584,26 +588,26 @@ export class OrganizationComponent {
this.alertModalDeletedByInference.alertTitle = "Other versions of";
this.alertModalDeletedByInference.open();
}
public getTypeParam(type: string): string {
if (type == 'results') {
type = 'publications&type=datasets&type=software&type=other';
}
return 'type=' + type;
}
getCSVAffiliated(contentType: string): string {
return this.downloadURLAPI + '?format=csv&' + this.getTypeParam(contentType) + '&fq=(relorganizationid exact "' + this.organizationId + '")';
}
getFunderProjects(): string {
return this.downloadURLAPI + '?' + this.csvProjectParamsHead + encodeURI(this.funder.id) + this.csvParamsTail;
}
open(value: any) {
console.log(value);
}
openDownloadReportModal() {
this.downloadReportModal.cancelButton = false;
this.downloadReportModal.okButton = false;
@ -614,7 +618,7 @@ export class OrganizationComponent {
closeDownloadReportModal() {
this.downloadReportModal.cancel();
}
openDownloadFunderReportModal() {
this.funder = this.fetchProjects.funders[0];
this.downloadFunderReportModal.cancelButton = false;
@ -634,7 +638,7 @@ export class OrganizationComponent {
return this.routerHelper.createQueryParams(['f0', 'fv0'], ['relorganizationid', this.organizationId]);
}
}
public onSelectActiveTab(activeTabId) {
if (this.activeTab != activeTabId) { // tab really changed
if (activeTabId == 'projects') {
@ -657,7 +661,7 @@ export class OrganizationComponent {
}
}
}
public get total(): number {
let total = this.fetchPublications.searchUtils.totalResults;
total += this.fetchDatasets.searchUtils.totalResults;
@ -665,7 +669,7 @@ export class OrganizationComponent {
total += this.fetchOrps.searchUtils.totalResults;
return total;
}
// public get numberOfTabs(): number {
// if (this.tabsAreInitialized) {
// return this._numberOfTabs;
@ -724,7 +728,7 @@ export class OrganizationComponent {
// this.tabsAreInitialized = true;
// return this._numberOfTabs;
// }
private getEntityName(entityType: string, plural: boolean, full: boolean): string {
if (entityType == "publication") {
return "publication" + (plural ? "s" : "");
@ -740,7 +744,7 @@ export class OrganizationComponent {
return entityType + (plural ? "s" : "");
}
}
public scroll() {
HelperFunctions.scroll();
}

View File

@ -152,6 +152,7 @@ export class ProjectComponent {
//this.getDivContents();
this.getPageContents();
this.updateUrl(this.properties.domain + this.properties.baseLink + this._router.url);
this.seoService.createLinkForCanonicalURL(this.properties.domain +this.properties.baseLink + this._router.url);
this.subscriptions.push(this.route.queryParams.subscribe(params => {
@ -351,9 +352,12 @@ export class ProjectComponent {
this.handleError("Error getting project for id: " + this.projectId, err);
if(err.status == 404) {
this._router.navigate(['/error'], {queryParams: {"page": this._location.path(true), "page_type": "project"}});
}else if(err.name == "TimeoutError"){
this.errorMessage = 'An error occurred please try again later';
}else {
this.seoService.createLinkForCanonicalURL(this.properties.domain + this.properties.baseLink + this.properties.searchLinkToProjects);
this.errorMessage = 'No project found';
}
this.seoService.createLinkForCanonicalURL(this.properties.domain + this.properties.baseLink + this.properties.searchLinkToProjects);
this.errorMessage = 'No project found';
this.showLoading = false;
}
));
@ -380,9 +384,12 @@ export class ProjectComponent {
this.handleError("Error getting project for grant id: " + grantId + " and funder: " + funder, err);
if(err.status == 404) {
this._router.navigate(['/error'], {queryParams: {"page": this._location.path(true), "page_type": "project"}});
}else if(err.name == "TimeoutError"){
this.errorMessage = 'An error occurred please try again later';
}else {
this.seoService.createLinkForCanonicalURL(this.properties.domain + this.properties.baseLink + this.properties.searchLinkToProjects);
this.errorMessage = 'No project found';
}
this.seoService.createLinkForCanonicalURL(this.properties.domain + this.properties.baseLink + this.properties.searchLinkToProjects);
this.errorMessage = 'No project found';
this.showLoading = false;
}
));

View File

@ -143,6 +143,7 @@ export class ResultLandingComponent {
//this.getDivContents();
this.getPageContents();
this.updateUrl(this.properties.domain +this.properties.baseLink + this._router.url);
this.seoService.createLinkForCanonicalURL(this.properties.domain +this.properties.baseLink + this._router.url);
this.subscriptions.push(this.route.queryParams.subscribe(data => {
if (data['articleId']) {
this.id = data['articleId'];
@ -422,17 +423,19 @@ export class ResultLandingComponent {
this.handleError("Error getting " + this.type + " for " + (this.id ? ("id: " + this.id) : ("pid: " + this.identifier.id + " ("+this.identifier.class+")")), err);
if (err.status == 404) {
this._router.navigate(['/error'], {queryParams: {"page": this._location.path(true), "page_type": this.type}});
}
if (this.type == "publication" || this.type == "software") {
this.errorMessage = 'No ' + this.type + ' found';
} else if (this.type == "dataset") {
this.errorMessage += "No research data found";
} else if (this.type == "orp") {
this.errorMessage += "No research product found";
}else if(err.name == "TimeoutError"){
this.errorMessage = 'An error occurred please try again later';
}else{
if (this.type == "publication" || this.type == "software") {
this.errorMessage = 'No ' + this.type + ' found';
} else if (this.type == "dataset") {
this.errorMessage += "No research data found";
} else if (this.type == "orp") {
this.errorMessage += "No research product found";
}
this.seoService.createLinkForCanonicalURL(this.properties.domain+ properties.baseLink + this.linkToSearchPage);
}
this.showLoading = false;
this.seoService.createLinkForCanonicalURL(this.properties.domain+ properties.baseLink + this.linkToSearchPage);
}
));
}