From e9e2ee9f3a626cb528b044b07729fe078bee5492 Mon Sep 17 00:00:00 2001 From: "konstantina.galouni" Date: Mon, 28 Nov 2022 19:22:01 +0200 Subject: [PATCH] [Library]: [Bug fix] Strip html tags for titles and descriptions and show them as innerHTML. 1. dataProvider.component.ts & organization.component.ts & project.component.ts & resultLanding.component.ts & orcid-work.component.ts: Commented unused @ViewChild fields. 2. dataProvider.service.ts & project.service.ts & resultLanding.service.ts: Strip html tags from title. 3. resultLanding.component.ts: [Bug fix] resultLanding.description is string, not array. 4. orcidWork.ts: [Bug fix] resultLanding.description is string, not array & strip html tags from description. 5. refineFieldResults.service.ts: In method "getSearchAPIURLForEntity()", for entityType "result" set suffix to "results/". 6. searchDataproviders.service.ts & searchOrganizations.service.ts & searchProjects.service.ts & searchResearchResults.service.ts: Strip html tags from title | Do not cut description (multi line ellipsis is used in html). 7. jsonld-document-serializer.service.ts: [Bug fix] resultLanding.description is string, not array. 8. result-preview.component.html: Show description as innerHTML to properly display special characters. --- .../dataProvider/dataProvider.component.ts | 34 +++++++++---------- .../dataProvider/dataProvider.service.ts | 12 +++++-- .../landing-utils/parsingFunctions.class.ts | 2 +- .../organization/organization.component.ts | 6 ++-- landingPages/project/project.component.ts | 4 +-- landingPages/project/project.service.ts | 7 +++- .../result/resultLanding.component.ts | 22 ++++++------ landingPages/result/resultLanding.service.ts | 6 ++-- orcid/orcid-work.component.ts | 24 ++++++------- orcid/orcidWork.ts | 4 ++- services/refineFieldResults.service.ts | 2 +- services/searchDataproviders.service.ts | 16 ++++++--- services/searchOrganizations.service.ts | 6 ++-- services/searchProjects.service.ts | 16 +++++---- services/searchResearchResults.service.ts | 10 +++--- .../jsonld-document-serializer.service.ts | 4 +-- .../result-preview.component.html | 4 +-- 17 files changed, 101 insertions(+), 78 deletions(-) diff --git a/landingPages/dataProvider/dataProvider.component.ts b/landingPages/dataProvider/dataProvider.component.ts index cf833781..c5df0b83 100644 --- a/landingPages/dataProvider/dataProvider.component.ts +++ b/landingPages/dataProvider/dataProvider.component.ts @@ -68,8 +68,8 @@ export class DataProviderComponent { // Statistics tab variables public statsClicked: boolean = false; - @ViewChild('statisticsModal') statisticsModal; - @ViewChild('relatedDatasourcesModal') relatedDatasourcesModal; + // @ViewChild('statisticsModal') statisticsModal; + // @ViewChild('relatedDatasourcesModal') relatedDatasourcesModal; @ViewChild('addThisModal') addThisModal // Variables for publications, research data, projects, datasources, related datasources tabs @@ -672,21 +672,21 @@ export class DataProviderComponent { return !(this.totalViews != null && this.totalDownloads != null && this.pageViews != null) || this.totalViews > 0 || this.totalDownloads > 0 || this.pageViews > 0; } - public openStatistics() { - this.statsClicked = true; - this.statisticsModal.cancelButton = false; - this.statisticsModal.okButton = false; - this.statisticsModal.alertTitle = "Statistics of"; - this.statisticsModal.open(); - } - - public openRelatedDatasources() { - this.searchRelatedDatasources(1, 0); - this.relatedDatasourcesModal.cancelButton = false; - this.relatedDatasourcesModal.okButton = false; - this.relatedDatasourcesModal.alertTitle = "Related "+this.openaireEntities.DATASOURCES+" of"; - this.relatedDatasourcesModal.open(); - } + // public openStatistics() { + // this.statsClicked = true; + // this.statisticsModal.cancelButton = false; + // this.statisticsModal.okButton = false; + // this.statisticsModal.alertTitle = "Statistics of"; + // this.statisticsModal.open(); + // } + // + // public openRelatedDatasources() { + // this.searchRelatedDatasources(1, 0); + // this.relatedDatasourcesModal.cancelButton = false; + // this.relatedDatasourcesModal.okButton = false; + // this.relatedDatasourcesModal.alertTitle = "Related "+this.openaireEntities.DATASOURCES+" of"; + // this.relatedDatasourcesModal.open(); + // } public openAddThisModal() { this.addThisModal.cancelButton = false; diff --git a/landingPages/dataProvider/dataProvider.service.ts b/landingPages/dataProvider/dataProvider.service.ts index f1c8598a..8973f7da 100644 --- a/landingPages/dataProvider/dataProvider.service.ts +++ b/landingPages/dataProvider/dataProvider.service.ts @@ -6,7 +6,7 @@ import{EnvProperties} from '../../utils/properties/env-properties'; import {map} from "rxjs/operators"; import {ParsingFunctions} from "../landing-utils/parsingFunctions.class"; import {OpenaireEntities} from "../../utils/properties/searchFields"; -import {Identifier} from "../../utils/string-utils.class"; +import {Identifier, StringUtils} from "../../utils/string-utils.class"; import {properties} from "../../../../environments/environment"; @@ -138,8 +138,14 @@ export class DataProviderService { this.dataProviderInfo.relcanId = ParsingFunctions.parseRelCanonicalId(this.dataProviderInfo.record, "datasource"); if(data[0] != null) { - this.dataProviderInfo.title = {"name": (data[0].englishname)?data[0].englishname: data[0].officialname, "url": data[0].websiteurl}; - this.dataProviderInfo.officialName = data[0].officialname; + this.dataProviderInfo.title = {"name": "", "url": data[0].websiteurl}; + if(data[0].officialname) { + this.dataProviderInfo.title.name = StringUtils.HTMLToString(String(data[0].officialname)); + this.dataProviderInfo.officialName = StringUtils.HTMLToString(String(data[0].officialname)); + } + if(data[0].englishname) { + this.dataProviderInfo.title.name = StringUtils.HTMLToString(String(data[0].englishname)); + } var pattern = /.{12}::.+/; var originalIds =(data[0].originalId)?data[0].originalId:""; diff --git a/landingPages/landing-utils/parsingFunctions.class.ts b/landingPages/landing-utils/parsingFunctions.class.ts index 5b423b10..23592e3f 100644 --- a/landingPages/landing-utils/parsingFunctions.class.ts +++ b/landingPages/landing-utils/parsingFunctions.class.ts @@ -802,7 +802,7 @@ export class ParsingFunctions { if(stripHTML) { return abstracts.join(' '); } else { - return abstracts.length > 0 ? ('

' + abstracts.join('

') + '

') : abstracts.join(' '); + return abstracts.length > 0 ? ('

' + abstracts.join('

') + '

') : abstracts.join(' '); } } } diff --git a/landingPages/organization/organization.component.ts b/landingPages/organization/organization.component.ts index 62edddb3..60a148d0 100644 --- a/landingPages/organization/organization.component.ts +++ b/landingPages/organization/organization.component.ts @@ -70,8 +70,8 @@ export class OrganizationComponent { public activeTab: string = ""; @ViewChild('downloadReportsModal') downloadReportsModal; - @ViewChild('downloadReportModal') downloadReportModal; - @ViewChild('downloadFunderReportModal') downloadFunderReportModal; + // @ViewChild('downloadReportModal') downloadReportModal; + // @ViewChild('downloadFunderReportModal') downloadFunderReportModal; @ViewChild('addThisModal') addThisModal; @ViewChild(ModalLoading) loading: ModalLoading; @@ -118,7 +118,7 @@ export class OrganizationComponent { public feedbackFields: string [] = ['Name', 'Country', 'Other']; @ViewChild('AlertModalDeletedByInference') alertModalDeletedByInference; - @ViewChild('projectsModal') projectsModal; + // @ViewChild('projectsModal') projectsModal; public deleteByInferenceOpened: boolean = false; diff --git a/landingPages/project/project.component.ts b/landingPages/project/project.component.ts index a7da88da..56622846 100644 --- a/landingPages/project/project.component.ts +++ b/landingPages/project/project.component.ts @@ -80,8 +80,8 @@ export class ProjectComponent { // Active tab variable for responsiveness public activeTab: string = ""; - @ViewChild('statisticsModal') statisticsModal; - @ViewChild('linkProjectModal') linkProjectModal; + // @ViewChild('statisticsModal') statisticsModal; + // @ViewChild('linkProjectModal') linkProjectModal; @ViewChild('embedResultsModal') embedResultsModal; @ViewChild('downloadReportModal') downloadReportModal; @ViewChild('addThisModal') addThisModal diff --git a/landingPages/project/project.service.ts b/landingPages/project/project.service.ts index dbafa780..17084a51 100644 --- a/landingPages/project/project.service.ts +++ b/landingPages/project/project.service.ts @@ -9,6 +9,7 @@ import{EnvProperties} from '../../utils/properties/env-properties'; import { ParsingFunctions } from '../landing-utils/parsingFunctions.class'; import {map} from "rxjs/operators"; +import {StringUtils} from "../../utils/string-utils.class"; @Injectable() export class ProjectService { @@ -123,7 +124,11 @@ export class ProjectService { // ['result']['metadata']['oaf:entity']['oaf:project'] if(data[0] != null) { this.projectInfo.acronym = data[0].acronym; - this.projectInfo.title = Array.isArray(data[0]['title']) ? data[0].title[0] : data[0].title; + if(data[0]['title']) { + this.projectInfo.title = Array.isArray(data[0]['title']) ? StringUtils.HTMLToString(String(data[0].title[0])) : StringUtils.HTMLToString(String(data[0].title)); + } else { + this.projectInfo.title = ""; + } this.projectInfo.funding.code = data[0].code; if(data[0].startdate) { let date: number = Date.parse(data[0].startdate); diff --git a/landingPages/result/resultLanding.component.ts b/landingPages/result/resultLanding.component.ts index 401261b1..61ce733b 100644 --- a/landingPages/result/resultLanding.component.ts +++ b/landingPages/result/resultLanding.component.ts @@ -37,11 +37,11 @@ export class ResultLandingComponent { @Input() piwikSiteId = properties.piwikSiteId; @Input() communityId = null; enermapsId; - @ViewChild('linkModal') linkModal; + // @ViewChild('linkModal') linkModal; @ViewChild('citeModal') citeModal; @ViewChild('addThisModal') addThisModal; @ViewChild('AlertModalDeletedByInference') alertModalDeletedByInference; - @ViewChild('relationModal') relationModal; + // @ViewChild('relationModal') relationModal; public deleteByInferenceOpened: boolean = false; @Input() public resultFromInput: boolean = false; @Input() public resultLandingInfo: ResultLandingInfo; @@ -118,7 +118,7 @@ export class ResultLandingComponent { public isLoggedIn: boolean = false; public pid: string; - @ViewChild("annotation") annotation: AnnotationComponent; + // @ViewChild("annotation") annotation: AnnotationComponent; public contextsWithLink: any; public relatedClassFilters: Option[]=[{"label": "All relations", "value": ""}]; @@ -743,12 +743,12 @@ export class ResultLandingComponent { } } - public openLinkModal() { - this.linkModal.cancelButton = false; - this.linkModal.okButton = false; - this.linkModal.alertTitle = "Link this " + this.getTypeName() + " to"; - this.linkModal.open(); - } + // public openLinkModal() { + // this.linkModal.cancelButton = false; + // this.linkModal.okButton = false; + // this.linkModal.alertTitle = "Link this " + this.getTypeName() + " to"; + // this.linkModal.open(); + // } public openCiteModal() { this.citeThisClicked = true; @@ -804,7 +804,7 @@ export class ResultLandingComponent { let abstract_words = ["operacao-feliz-natal.blogspot.com", "moviedouban.site", "hack-expert-solution.link"]; allow = allow && !( (this.hasKeyword(resultLandingInfo.title,title_authors_words) || (resultLandingInfo.authors && this.hasKeyword(resultLandingInfo.authors.map(o => o.fullName).join(" "),title_authors_words)) - || (resultLandingInfo.description && resultLandingInfo.description[0] && this.hasKeyword(resultLandingInfo.description[0],abstract_words)) + || (resultLandingInfo.description && this.hasKeyword(resultLandingInfo.description,abstract_words)) ) && ((resultLandingInfo.publisher && resultLandingInfo.publisher.toLowerCase() == "zenodo") || (resultLandingInfo.hostedBy_collectedFrom && resultLandingInfo.hostedBy_collectedFrom.filter(value => { @@ -816,7 +816,7 @@ export class ResultLandingComponent { let common_abstract = ["international audience","n/a","peer reviewed","national audience","info:eu-repo/semantics/published","-",".","graphical abstract","met lit. opg","international audience; no abstract",'.',"politics","info:eu-repo/semantics/publishedversion","copia digital. madrid : ministerio de educación, cultura y deporte, 2016",'',"peer-reviewed","copia digital. madrid : ministerio de educación, cultura y deporte. subdirección general de coordinación bibliotecaria, 2015","-","imperial users only","yüksek lisans"]; let common_authors = ["[s.n.]","null &na;","nn","(:unap)","(:null)","null anonymous","anonymous"]; allow = allow && !( - this.isKeyword(resultLandingInfo.title,common_titles) || (resultLandingInfo.description && resultLandingInfo.description[0] && this.isKeyword(resultLandingInfo.description[0],common_abstract)) || + this.isKeyword(resultLandingInfo.title,common_titles) || (resultLandingInfo.description && this.isKeyword(resultLandingInfo.description,common_abstract)) || (resultLandingInfo.authors && this.hasKeyword("_"+resultLandingInfo.authors.map(o => o.fullName).join("_")+"_",common_authors, "_")) ); // console.log("common content " + allow) diff --git a/landingPages/result/resultLanding.service.ts b/landingPages/result/resultLanding.service.ts index c40c9993..f240ebeb 100644 --- a/landingPages/result/resultLanding.service.ts +++ b/landingPages/result/resultLanding.service.ts @@ -153,10 +153,10 @@ export class ResultLandingService { for(let i=0; i 0 ? resultLandingInfo.description[0] : ""; + resultLandingInfo.description = StringUtils.HTMLToString(resultLandingInfo.description); + work['short-description'] = resultLandingInfo.description.substring(0, description_limit-1); } // citation (Citation, optional), diff --git a/services/refineFieldResults.service.ts b/services/refineFieldResults.service.ts index eca09c9d..d40819ab 100644 --- a/services/refineFieldResults.service.ts +++ b/services/refineFieldResults.service.ts @@ -77,7 +77,7 @@ export class RefineFieldResultsService { }else if(entityType == "person"){ suffix="people/"; }else if(entityType == "result"){ - suffix="publications/"; + suffix="results/"; } return suffix; } diff --git a/services/searchDataproviders.service.ts b/services/searchDataproviders.service.ts index d452003a..3160d7ee 100644 --- a/services/searchDataproviders.service.ts +++ b/services/searchDataproviders.service.ts @@ -106,8 +106,14 @@ export class SearchDataprovidersService { result['title'] = {"name": '', "accessMode": ''}; - result['title'].name = resData.officialname; - result['englishname'] = resData.englishname; + if(resData.officialname) { + result['title'].name = StringUtils.HTMLToString(String(resData.officialname)); + } + if(resData.englishname) { + result['englishname'] = StringUtils.HTMLToString(String(resData.englishname)); + } else { + result['englishname'] = ""; + } //result['title'].url = OpenaireProperties.getsearchLinkToDataProvider(); //result['title'].url += Array.isArray(data) ? data[i]['result']['header']['dri:objIdentifier'] : data['result']['header']['dri:objIdentifier']; @@ -125,9 +131,9 @@ export class SearchDataprovidersService { let abstracts = this.parsingFunctions.parseDescription(resData.description, true); result.description = abstracts; - if (result.description && result.description.length > this.sizeOfDescription) { - result.description = result.description.substring(0, this.sizeOfDescription) + "..."; - } + // if (result.description && result.description.length > this.sizeOfDescription) { + // result.description = result.description.substring(0, this.sizeOfDescription) + "..."; + // } let typeid: string = resData['datasourcetype'].classid; if(typeid != "entityregistry" && typeid != "entityregistry::projects" && typeid != "entityregistry::repositories") { diff --git a/services/searchOrganizations.service.ts b/services/searchOrganizations.service.ts index a41a4084..d35f9f97 100644 --- a/services/searchOrganizations.service.ts +++ b/services/searchOrganizations.service.ts @@ -94,9 +94,11 @@ export class SearchOrganizationsService { result['title'] = {"name": '', "accessMode": ''}; - result['title'].name = resData.legalshortname; + if(resData.legalshortname) { + result['title'].name = StringUtils.HTMLToString(String(resData.legalshortname)); + } if(!result['title'].name || result['title'].name == '') { - result['title'].name = resData.legalname; + result['title'].name = StringUtils.HTMLToString(String(resData.legalname)); } //result['title'].url = OpenaireProperties.getsearchLinkToOrganization(); diff --git a/services/searchProjects.service.ts b/services/searchProjects.service.ts index b9e60214..e898dcda 100644 --- a/services/searchProjects.service.ts +++ b/services/searchProjects.service.ts @@ -135,11 +135,15 @@ export class SearchProjectsService { // if(resData['acronym'] != undefined && resData['acronym'] != "") { // result['title'].name = resData['acronym'] + " - "; // } - if(Array.isArray(resData['title'])) { - result['title'].name += resData['title'][0]; + if(resData['title']) { + if (Array.isArray(resData['title'])) { + result['title'].name += StringUtils.HTMLToString(String(resData['title'][0])); } else { - result['title'].name += resData['title']; + result['title'].name += StringUtils.HTMLToString(String(resData['title'])); } + } else { + result['title'].name = ""; + } // if(result['title'].name != '') { // result['title'].name += " ("+resData['code']+")" @@ -160,9 +164,9 @@ export class SearchProjectsService { let abstracts = this.parsingFunctions.parseDescription(resData.summary, true); result.description = abstracts; - if (result.description && result.description.length > this.sizeOfDescription) { - result.description = result.description.substring(0, this.sizeOfDescription) + "..."; - } + // if (result.description && result.description.length > this.sizeOfDescription) { + // result.description = result.description.substring(0, this.sizeOfDescription) + "..."; + // } if(resData['rels'].hasOwnProperty("rel")) { let relLength = Array.isArray(resData['rels']['rel']) ? resData['rels']['rel'].length : 1; diff --git a/services/searchResearchResults.service.ts b/services/searchResearchResults.service.ts index 4609e22c..69490ab9 100644 --- a/services/searchResearchResults.service.ts +++ b/services/searchResearchResults.service.ts @@ -299,7 +299,7 @@ export class SearchResearchResultsService { for (let i = 0; i < resData['title'].length; i++) { if (resData['title'][i] && resData['title'][i].content) { if (!result.title.name || resData['title'][i].classid == "main title") { - result['title'].name = String(resData['title'][i].content); + result['title'].name = StringUtils.HTMLToString(String(resData['title'][i].content)); } if (resData['title'][i].classid == "main title") { break; @@ -311,7 +311,7 @@ export class SearchResearchResultsService { } // result['title'].name = (resData['title'][0] && resData['title'][0].content) ? String(resData['title'][0].content) : ""; } else { - result['title'].name = (resData['title'] && resData['title'].content) ? String(resData['title'].content) : ""; + result['title'].name = (resData['title'] && resData['title'].content) ? StringUtils.HTMLToString(String(resData['title'].content)) : ""; } result['id'] = Array.isArray(data) ? data[i]['result']['header']['dri:objIdentifier'] : data['result']['header']['dri:objIdentifier']; @@ -373,9 +373,9 @@ export class SearchResearchResultsService { let abstracts = this.parsingFunctions.parseDescription(resData.description, true); result.description = abstracts; - if (result.description && result.description.length > this.sizeOfDescription) { - result.description = result.description.substring(0, this.sizeOfDescription) + "..."; - } + // if (result.description && result.description.length > this.sizeOfDescription) { + // result.description = result.description.substring(0, this.sizeOfDescription) + "..."; + // } if (resData.embargoenddate && resData.embargoenddate != '') { result.embargoEndDate = Dates.getDate(resData.embargoenddate); diff --git a/sharedComponents/schema2jsonld/service/jsonld-document-serializer.service.ts b/sharedComponents/schema2jsonld/service/jsonld-document-serializer.service.ts index 9e8ba621..fdd02654 100644 --- a/sharedComponents/schema2jsonld/service/jsonld-document-serializer.service.ts +++ b/sharedComponents/schema2jsonld/service/jsonld-document-serializer.service.ts @@ -117,8 +117,8 @@ export class JsonldDocumentSerializerService { } serializeDescription(doc, buffer){ - if(doc.description && doc.description[0]) { - buffer["description"] = doc.description[0]; + if(doc.description) { + buffer["description"] = doc.description; } } serializeIdentifier(doc, buffer){ diff --git a/utils/result-preview/result-preview.component.html b/utils/result-preview/result-preview.component.html index 6d4321a5..b6ff3bd4 100644 --- a/utils/result-preview/result-preview.component.html +++ b/utils/result-preview/result-preview.component.html @@ -285,9 +285,7 @@
-

- {{result.description}} -

+