[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
This commit is contained in:
argiro.kokogiannaki 2021-03-12 14:49:12 +00:00
parent 372f33cb21
commit 50dda276c6
9 changed files with 64 additions and 28 deletions

View File

@ -5,7 +5,7 @@
<div class="uk-grid helper-grid"> <div class="uk-grid helper-grid">
<div class="uk-width-expand "> <div class="uk-width-expand ">
<div <div
class="uk-card-body uk-padding-remove-bottom uk-padding-remove-top " [class.portal-hr]=" class="uk-card-body uk-padding-remove-bottom uk-padding-remove-top " [class.paging-hr]="
!pageLoading && claims && claims.length > 0"> !pageLoading && claims && claims.length > 0">
<helper *ngIf="pageContents && pageContents['top'] && pageContents['top'].length > 0" <helper *ngIf="pageContents && pageContents['top'] && pageContents['top'].length > 0"
[texts]="pageContents['top']"></helper> [texts]="pageContents['top']"></helper>
@ -62,10 +62,10 @@
</div> </div>
<div *ngIf="resultsNum" class="uk-width-1-2 uk-grid uk-flex-right uk-flex-middle "> <div *ngIf="resultsNum" class="uk-width-1-2 uk-grid uk-flex-right uk-flex-middle ">
<div> <div class="uk-text-muted uk-text-uppercase">
<span class="portal-color">{{resultsNum|number}}</span> links, page <span <span class="uk-text-bold">{{resultsNum|number}}</span> links, page <span
class="portal-color">{{page | number}}</span> of <span class="uk-text-bold">{{page | number}}</span> of <span
class="portal-color">{{totalPages(resultsNum)|number}}</span> class="uk-text-bold">{{totalPages(resultsNum)|number}}</span>
</div> </div>
<paging-no-load [currentPage]="page" [totalResults]="resultsNum" [size]="size" <paging-no-load [currentPage]="page" [totalResults]="resultsNum" [size]="size"
[loading]="pageLoading" [loading]="pageLoading"
@ -91,7 +91,7 @@
<div class="uk-alert uk-alert-primary ">No entries found.</div> <div class="uk-alert uk-alert-primary ">No entries found.</div>
</div> </div>
<div class=""> <div class="uk-margin-small-top">
<div *ngFor="let claim of claims " <div *ngFor="let claim of claims "
class="uk-card uk-card-default uk-card-body uk-margin-bottom ng-star-inserted"> class="uk-card uk-card-default uk-card-body uk-margin-bottom ng-star-inserted">
@ -128,12 +128,12 @@
</div> </div>
<div *ngIf="!( showErrorMessage || showForbiddenMessage || userValidMessage.length > 0 || (claims <div *ngIf="!( showErrorMessage || showForbiddenMessage || userValidMessage.length > 0 || (claims
&& claims.length && claims.length
==0))" class="portal-hr uk-margin-top"> ==0))" class="paging-hr uk-margin-top">
<div class="uk-grid "> <div class="uk-grid ">
<div *ngIf="resultsNum>0" class="uk-width-1-2"> <div *ngIf="resultsNum>0" class="uk-width-1-2 uk-text-muted uk-text-uppercase">
<span class="portal-color">{{resultsNum|number}}</span> links, page <span <span class="uk-text-bold">{{resultsNum|number}}</span> links, page <span
class="portal-color">{{page | number}}</span> of <span class="uk-text-bold">{{page | number}}</span> of <span
class="portal-color">{{totalPages(resultsNum)|number}}</span> class="uk-text-bold">{{totalPages(resultsNum)|number}}</span>
</div> </div>
<div *ngIf="resultsNum" class="uk-width-1-2 "> <div *ngIf="resultsNum" class="uk-width-1-2 ">

View File

@ -17,6 +17,7 @@ import {LoginErrorCodes} from '../../login/utils/guardHelper.class';
import {HelperFunctions} from "../../utils/HelperFunctions.class"; import {HelperFunctions} from "../../utils/HelperFunctions.class";
import {Subscriber} from "rxjs"; import {Subscriber} from "rxjs";
import {properties} from "../../../../environments/environment"; import {properties} from "../../../../environments/environment";
import {StringUtils} from '../../utils/string-utils.class';
@Component({ @Component({
selector: 'div-help-contents', selector: 'div-help-contents',
@ -363,8 +364,7 @@ export class DivHelpContentsComponent implements OnInit {
} }
public cutContent(divHelpContent: DivHelpContent) { public cutContent(divHelpContent: DivHelpContent) {
divHelpContent.content = divHelpContent.content.replace(/<[^>]*>/g, ''); divHelpContent.content = StringUtils.HTMLToString(divHelpContent.content);
divHelpContent.content = divHelpContent.content.replace(/(\r\n|\n|\r| +(?= ))|\s\s+/gm, " ");
if (divHelpContent.content.length > 200) { if (divHelpContent.content.length > 200) {
divHelpContent.content = divHelpContent.content.substr(0, 200) + "..."; divHelpContent.content = divHelpContent.content.substr(0, 200) + "...";
} }

View File

@ -86,7 +86,8 @@
<div *ngIf="!selectedPageId" > <div *ngIf="!selectedPageId" >
<div class="page" href="#">{{check.pageHelpContent.page.name}}</div> <div class="page" href="#">{{check.pageHelpContent.page.name}}</div>
</div> </div>
<div class="content">{{check.pageHelpContent.content}}</div> <div class="content multi-line-ellipsis lines-2">
<p>{{check.pageHelpContent.content|htmlToString}}</p></div>
</div> </div>
<div class="uk-grid uk-width-1-1 uk-margin-left"> <div class="uk-grid uk-width-1-1 uk-margin-left">
<div class=" "> <div class=" ">

View File

@ -187,7 +187,6 @@ export class PageHelpContentsComponent implements OnInit {
this.checkboxes = []; this.checkboxes = [];
for (let i = this.pageHelpContents.length - 1; i >= 0; i -= 1) { for (let i = this.pageHelpContents.length - 1; i >= 0; i -= 1) {
this.cutContent(this.pageHelpContents[i]);
this.checkboxes.unshift(<CheckPageHelpContent>{ this.checkboxes.unshift(<CheckPageHelpContent>{
pageHelpContent: this.pageHelpContents[i], pageHelpContent: this.pageHelpContents[i],
checked: false checked: false
@ -331,7 +330,6 @@ export class PageHelpContentsComponent implements OnInit {
} }
public pageHelpContentSavedSuccessfully(pageHelpContent: PageHelpContent) { public pageHelpContentSavedSuccessfully(pageHelpContent: PageHelpContent) {
this.cutContent(pageHelpContent);
this.checkboxes.push(<CheckPageHelpContent>{pageHelpContent: pageHelpContent, checked: false}); this.checkboxes.push(<CheckPageHelpContent>{pageHelpContent: pageHelpContent, checked: false});
this.pageHelpContents.push(pageHelpContent); this.pageHelpContents.push(pageHelpContent);
this.applyCheck(false); this.applyCheck(false);
@ -355,20 +353,11 @@ export class PageHelpContentsComponent implements OnInit {
return idFlag && activeFlag && textFlag; 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() { public applyFilter() {
this.checkboxes = []; this.checkboxes = [];
this.pageHelpContents.filter(item => this.filterPageHelpContent(item, this.filters)).forEach( this.pageHelpContents.filter(item => this.filterPageHelpContent(item, this.filters)).forEach(
_ => { _ => {
this.cutContent(_);
this.checkboxes.push(<CheckPageHelpContent>{pageHelpContent: _, checked: false}) this.checkboxes.push(<CheckPageHelpContent>{pageHelpContent: _, checked: false})
} }
); );

View File

@ -17,12 +17,13 @@ import {IconsModule} from '../../utils/icons/icons.module';
import {IconsService} from '../../utils/icons/icons.service'; import {IconsService} from '../../utils/icons/icons.service';
import {add, arrow_left} from '../../utils/icons/icons'; import {add, arrow_left} from '../../utils/icons/icons';
import {LoadingModule} from '../../utils/loading/loading.module'; import {LoadingModule} from '../../utils/loading/loading.module';
import {HTMLToStringPipeModule} from '../../utils/pipes/HTMLToStringPipe.module';
@NgModule({ @NgModule({
imports: [ imports: [
CommonModule, RouterModule, FormsModule, SafeHtmlPipeModule, CommonModule, RouterModule, FormsModule, SafeHtmlPipeModule,
AlertModalModule, ReactiveFormsModule, MatSlideToggleModule, AdminToolServiceModule, InputModule, PageHelpContentsRoutingModule, PageContentModule, AlertModalModule, ReactiveFormsModule, MatSlideToggleModule, AdminToolServiceModule, InputModule, PageHelpContentsRoutingModule, PageContentModule,
SearchInputModule, IconsModule, LoadingModule SearchInputModule, IconsModule, LoadingModule, HTMLToStringPipeModule
], ],
declarations: [ declarations: [
PageHelpContentsComponent PageHelpContentsComponent

View File

@ -6,6 +6,7 @@ import {Notification, NotificationUser} from "./notifications";
import {CustomOptions} from "../services/servicesUtils/customOptions.class"; import {CustomOptions} from "../services/servicesUtils/customOptions.class";
import {not} from "rxjs/internal-compatibility"; import {not} from "rxjs/internal-compatibility";
import {map} from "rxjs/operators"; import {map} from "rxjs/operators";
import {StringUtils} from '../utils/string-utils.class';
@Injectable({ @Injectable({
providedIn: "root" providedIn: "root"
@ -46,8 +47,7 @@ export class NotificationService {
if (notification.title) { if (notification.title) {
notification.preview = notification.title; notification.preview = notification.title;
} else { } else {
notification.preview = notification.message.replace(/<[^>]*>/g, ''); notification.preview = StringUtils.HTMLToString(notification.message);
notification.preview = notification.preview.replace(/(\r\n|\n|\r| +(?= ))|\s\s+/gm, " ");
} }
return notification; return notification;
} }

View File

@ -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);
}
}

View File

@ -0,0 +1,22 @@
import { NgModule } from '@angular/core';
import {HTMLToStringPipe} from './HTMLToString.pipe';
@NgModule({
imports: [
],
declarations: [
HTMLToStringPipe
],
providers:[],
exports: [
HTMLToStringPipe
]
})
export class HTMLToStringPipeModule{
}

View File

@ -363,4 +363,14 @@ export class StringUtils {
} }
return false; return false;
} }
public static HTMLToString( html:string){
try {
html = html.replace(/&nbsp;/g, ' ');
html = html.replace(/(\r\n|\n|\r| +(?= ))|\s\s+/gm, " ");
html = html.replace(/<[^>]*>/g, '');
}catch( e){
}
console.log(html);
return html;
}
} }