From 50dda276c60869db9c9bf5c0f5d04c7d74de10ce Mon Sep 17 00:00:00 2001 From: "argiro.kokogiannaki" Date: Fri, 12 Mar 2021 14:49:12 +0000 Subject: [PATCH] [Library|Trunk] String utils: add function HTMLToString create HTMLToStringPipe git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@60647 d315682c-612b-4755-9ff5-7f18f6832af3 --- .../displayClaims.component.html | 22 +++++++++---------- .../div-help-contents.component.ts | 4 ++-- .../page-help-contents.component.html | 3 ++- .../helpTexts/page-help-contents.component.ts | 11 ---------- .../helpTexts/page-help-contents.module.ts | 3 ++- notifications/notification.service.ts | 4 ++-- utils/pipes/HTMLToString.pipe.ts | 13 +++++++++++ utils/pipes/HTMLToStringPipe.module.ts | 22 +++++++++++++++++++ utils/string-utils.class.ts | 10 +++++++++ 9 files changed, 64 insertions(+), 28 deletions(-) create mode 100644 utils/pipes/HTMLToString.pipe.ts create mode 100644 utils/pipes/HTMLToStringPipe.module.ts diff --git a/claims/claim-utils/displayClaims/displayClaims.component.html b/claims/claim-utils/displayClaims/displayClaims.component.html index 38eb9504..409bf365 100644 --- a/claims/claim-utils/displayClaims/displayClaims.component.html +++ b/claims/claim-utils/displayClaims/displayClaims.component.html @@ -5,7 +5,7 @@
@@ -62,10 +62,10 @@
-
- {{resultsNum|number}} links, page {{page | number}} of {{totalPages(resultsNum)|number}} +
+ {{resultsNum|number}} links, page {{page | number}} of {{totalPages(resultsNum)|number}}
No entries found.
-
+
@@ -128,12 +128,12 @@
+ ==0))" class="paging-hr uk-margin-top">
-
- {{resultsNum|number}} links, page {{page | number}} of {{totalPages(resultsNum)|number}} +
+ {{resultsNum|number}} links, page {{page | number}} of {{totalPages(resultsNum)|number}}
diff --git a/dashboard/divhelpcontent/div-help-contents.component.ts b/dashboard/divhelpcontent/div-help-contents.component.ts index 55de77f2..964e9424 100644 --- a/dashboard/divhelpcontent/div-help-contents.component.ts +++ b/dashboard/divhelpcontent/div-help-contents.component.ts @@ -17,6 +17,7 @@ import {LoginErrorCodes} from '../../login/utils/guardHelper.class'; import {HelperFunctions} from "../../utils/HelperFunctions.class"; import {Subscriber} from "rxjs"; import {properties} from "../../../../environments/environment"; +import {StringUtils} from '../../utils/string-utils.class'; @Component({ selector: 'div-help-contents', @@ -363,8 +364,7 @@ export class DivHelpContentsComponent implements OnInit { } public cutContent(divHelpContent: DivHelpContent) { - divHelpContent.content = divHelpContent.content.replace(/<[^>]*>/g, ''); - divHelpContent.content = divHelpContent.content.replace(/(\r\n|\n|\r| +(?= ))|\s\s+/gm, " "); + divHelpContent.content = StringUtils.HTMLToString(divHelpContent.content); if (divHelpContent.content.length > 200) { divHelpContent.content = divHelpContent.content.substr(0, 200) + "..."; } diff --git a/dashboard/helpTexts/page-help-contents.component.html b/dashboard/helpTexts/page-help-contents.component.html index 360144cd..559aa342 100644 --- a/dashboard/helpTexts/page-help-contents.component.html +++ b/dashboard/helpTexts/page-help-contents.component.html @@ -86,7 +86,8 @@
{{check.pageHelpContent.page.name}}
-
{{check.pageHelpContent.content}}
+
+

{{check.pageHelpContent.content|htmlToString}}

diff --git a/dashboard/helpTexts/page-help-contents.component.ts b/dashboard/helpTexts/page-help-contents.component.ts index 37f8dffb..855288f7 100644 --- a/dashboard/helpTexts/page-help-contents.component.ts +++ b/dashboard/helpTexts/page-help-contents.component.ts @@ -187,7 +187,6 @@ export class PageHelpContentsComponent implements OnInit { this.checkboxes = []; for (let i = this.pageHelpContents.length - 1; i >= 0; i -= 1) { - this.cutContent(this.pageHelpContents[i]); this.checkboxes.unshift({ pageHelpContent: this.pageHelpContents[i], checked: false @@ -331,7 +330,6 @@ export class PageHelpContentsComponent implements OnInit { } public pageHelpContentSavedSuccessfully(pageHelpContent: PageHelpContent) { - this.cutContent(pageHelpContent); this.checkboxes.push({pageHelpContent: pageHelpContent, checked: false}); this.pageHelpContents.push(pageHelpContent); this.applyCheck(false); @@ -355,20 +353,11 @@ export class PageHelpContentsComponent implements OnInit { return idFlag && activeFlag && textFlag; } - public cutContent(pageHelpContent: PageHelpContent) { - pageHelpContent.content = pageHelpContent.content.replace(/<[^>]*>/g, ''); - pageHelpContent.content = pageHelpContent.content.replace(/(\r\n|\n|\r| +(?= ))|\s\s+/gm, " "); - - if (pageHelpContent.content.length > 200) { - pageHelpContent.content = pageHelpContent.content.substr(0, 200) + "..."; - } - } public applyFilter() { this.checkboxes = []; this.pageHelpContents.filter(item => this.filterPageHelpContent(item, this.filters)).forEach( _ => { - this.cutContent(_); this.checkboxes.push({pageHelpContent: _, checked: false}) } ); diff --git a/dashboard/helpTexts/page-help-contents.module.ts b/dashboard/helpTexts/page-help-contents.module.ts index 3a5fbb1d..30f04793 100644 --- a/dashboard/helpTexts/page-help-contents.module.ts +++ b/dashboard/helpTexts/page-help-contents.module.ts @@ -17,12 +17,13 @@ import {IconsModule} from '../../utils/icons/icons.module'; import {IconsService} from '../../utils/icons/icons.service'; import {add, arrow_left} from '../../utils/icons/icons'; import {LoadingModule} from '../../utils/loading/loading.module'; +import {HTMLToStringPipeModule} from '../../utils/pipes/HTMLToStringPipe.module'; @NgModule({ imports: [ CommonModule, RouterModule, FormsModule, SafeHtmlPipeModule, AlertModalModule, ReactiveFormsModule, MatSlideToggleModule, AdminToolServiceModule, InputModule, PageHelpContentsRoutingModule, PageContentModule, - SearchInputModule, IconsModule, LoadingModule + SearchInputModule, IconsModule, LoadingModule, HTMLToStringPipeModule ], declarations: [ PageHelpContentsComponent diff --git a/notifications/notification.service.ts b/notifications/notification.service.ts index 28dc496e..e45e7e80 100644 --- a/notifications/notification.service.ts +++ b/notifications/notification.service.ts @@ -6,6 +6,7 @@ import {Notification, NotificationUser} from "./notifications"; import {CustomOptions} from "../services/servicesUtils/customOptions.class"; import {not} from "rxjs/internal-compatibility"; import {map} from "rxjs/operators"; +import {StringUtils} from '../utils/string-utils.class'; @Injectable({ providedIn: "root" @@ -46,8 +47,7 @@ export class NotificationService { if (notification.title) { notification.preview = notification.title; } else { - notification.preview = notification.message.replace(/<[^>]*>/g, ''); - notification.preview = notification.preview.replace(/(\r\n|\n|\r| +(?= ))|\s\s+/gm, " "); + notification.preview = StringUtils.HTMLToString(notification.message); } return notification; } diff --git a/utils/pipes/HTMLToString.pipe.ts b/utils/pipes/HTMLToString.pipe.ts new file mode 100644 index 00000000..615bcde8 --- /dev/null +++ b/utils/pipes/HTMLToString.pipe.ts @@ -0,0 +1,13 @@ +import {Pipe, PipeTransform} from '@angular/core'; + +import {SafeUrl} from '@angular/platform-browser'; +import {StringUtils} from '../string-utils.class'; + +@Pipe({ name: 'htmlToString'}) +export class HTMLToStringPipe implements PipeTransform { + constructor() {} + + transform(value):SafeUrl { + return StringUtils.HTMLToString(value); + } +} diff --git a/utils/pipes/HTMLToStringPipe.module.ts b/utils/pipes/HTMLToStringPipe.module.ts new file mode 100644 index 00000000..98dbe64b --- /dev/null +++ b/utils/pipes/HTMLToStringPipe.module.ts @@ -0,0 +1,22 @@ +import { NgModule } from '@angular/core'; +import {HTMLToStringPipe} from './HTMLToString.pipe'; + + + +@NgModule({ + imports: [ + + ], + declarations: [ + HTMLToStringPipe + ], + providers:[], + exports: [ + HTMLToStringPipe + ] +}) + + +export class HTMLToStringPipeModule{ + +} diff --git a/utils/string-utils.class.ts b/utils/string-utils.class.ts index 0a14f05e..4b60b1c7 100644 --- a/utils/string-utils.class.ts +++ b/utils/string-utils.class.ts @@ -363,4 +363,14 @@ export class StringUtils { } return false; } + public static HTMLToString( html:string){ + try { + html = html.replace(/ /g, ' '); + html = html.replace(/(\r\n|\n|\r| +(?= ))|\s\s+/gm, " "); + html = html.replace(/<[^>]*>/g, ''); + }catch( e){ + } + console.log(html); + return html; + } }