From 9851bdeb190df32419f4c2968c3badccd3c03621 Mon Sep 17 00:00:00 2001 From: "k.triantafyllou" Date: Mon, 1 Feb 2021 10:14:08 +0000 Subject: [PATCH] [Library | Trunk]: 1. Fix chips css. 2. Stakeholder Service: Init is Upload after request git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@60326 d315682c-612b-4755-9ff5-7f18f6832af3 --- monitor/services/stakeholder.service.ts | 29 +++++++++++++++++----- sharedComponents/input/input.component.css | 4 +++ sharedComponents/input/input.component.ts | 6 ++--- sharedComponents/input/input.module.ts | 4 +-- utils/icons/icons.ts | 5 ++++ utils/string-utils.class.ts | 13 +++++++--- 6 files changed, 46 insertions(+), 15 deletions(-) diff --git a/monitor/services/stakeholder.service.ts b/monitor/services/stakeholder.service.ts index dbe5867e..7f80fa6a 100644 --- a/monitor/services/stakeholder.service.ts +++ b/monitor/services/stakeholder.service.ts @@ -7,6 +7,8 @@ import {map} from "rxjs/operators"; import {ActivatedRoute} from "@angular/router"; import {properties} from "../../../../environments/environment"; import {CustomOptions} from "../../services/servicesUtils/customOptions.class"; +import {StringUtils} from "../../utils/string-utils.class"; +import {el} from "@angular/platform-browser/testing/src/browser_util"; let maps: string[] = ['parameters', 'filters']; @@ -43,7 +45,7 @@ export class StakeholderService { if (!this.stakeholderSubject.value || this.stakeholderSubject.value.alias !== alias) { this.promise = new Promise((resolve, reject) => { this.sub = this.http.get(properties.monitorServiceAPIURL + '/stakeholder/' + encodeURIComponent(alias), CustomOptions.registryOptions()).pipe(map(stakeholder => { - return this.formalize(stakeholder); + return this.formalize(this.checkIsUpload(stakeholder)); })).subscribe(stakeholder => { this.stakeholderSubject.next(stakeholder); resolve(); @@ -70,25 +72,25 @@ export class StakeholderService { getStakeholders(url: string, type: string = null): Observable<(Stakeholder & StakeholderInfo)[]> { return this.http.get(url + '/stakeholder' + ((type) ? ('?type=' + type) : ''), CustomOptions.registryOptions()).pipe(map(stakeholders => { - return this.formalize(stakeholders); + return this.formalize(this.checkIsUpload(stakeholders)); })); } getMyStakeholders(url: string, type: string = null): Observable { return this.http.get(url + '/my-stakeholder' + ((type) ? ('?type=' + type) : ''), CustomOptions.registryOptions()).pipe(map(stakeholders => { - return this.formalize(stakeholders); + return this.formalize(this.checkIsUpload(stakeholders)); })); } getDefaultStakeholders(url: string, type: string = null): Observable { return this.http.get(url + '/stakeholder/default' + ((type) ? ('?type=' + type) : ''), CustomOptions.registryOptions()).pipe(map(stakeholders => { - return this.formalize(stakeholders); + return this.formalize(this.checkIsUpload(stakeholders)); })); } buildStakeholder(url: string, stakeholder: Stakeholder): Observable { return this.http.post(url + '/build-stakeholder', stakeholder, CustomOptions.registryOptions()).pipe(map(stakeholder => { - return this.formalize(stakeholder); + return this.formalize(this.checkIsUpload(stakeholder)); })); } @@ -100,7 +102,11 @@ export class StakeholderService { path = HelperFunctions.encodeArray(path); return this.http.post(url + ((path.length > 0) ? '/' : '') + path.join('/') + '/save', element, CustomOptions.registryOptions()).pipe(map(element => { - return this.formalize(element); + if(path.length === 0) { + return this.formalize(this.checkIsUpload(element)); + } else { + this.formalize(element); + } })); } @@ -136,6 +142,17 @@ export class StakeholderService { this.stakeholderSubject.next(stakeholder); } + private checkIsUpload(response: Stakeholder | Stakeholder[]): any | any[] { + if(Array.isArray(response)) { + response.forEach(value => { + value.isUpload = !StringUtils.isValidUrl(value.logoUrl); + }); + } else { + response.isUpload = !StringUtils.isValidUrl(response.logoUrl); + } + return response; + } + private formalize(element: any) { return HelperFunctions.copy(element); } diff --git a/sharedComponents/input/input.component.css b/sharedComponents/input/input.component.css index b6f78eaf..4d0e27d4 100644 --- a/sharedComponents/input/input.component.css +++ b/sharedComponents/input/input.component.css @@ -32,3 +32,7 @@ font-family: "Roboto", sans-serif; font-size: 14px; } + +.chip-input { + min-width: 100px; +} diff --git a/sharedComponents/input/input.component.ts b/sharedComponents/input/input.component.ts index ac8285bd..103010f9 100644 --- a/sharedComponents/input/input.component.ts +++ b/sharedComponents/input/input.component.ts @@ -72,13 +72,11 @@ export interface Option { {{chip.value[chipLabel]}} - + -
+
{{placeholder}}
diff --git a/sharedComponents/input/input.module.ts b/sharedComponents/input/input.module.ts index 761dc9d0..fdd702d4 100644 --- a/sharedComponents/input/input.module.ts +++ b/sharedComponents/input/input.module.ts @@ -7,7 +7,7 @@ import {MatSelectModule} from "@angular/material/select"; import {MatCheckboxModule} from '@angular/material/checkbox'; import {IconsModule} from "../../utils/icons/icons.module"; import {IconsService} from "../../utils/icons/icons.service"; -import {lock} from "../../utils/icons/icons"; +import {lock, remove_circle} from "../../utils/icons/icons"; import {MatChipsModule} from "@angular/material/chips"; import {MatAutocompleteModule} from "@angular/material/autocomplete"; import {MatIconModule} from "@angular/material/icon"; @@ -33,6 +33,6 @@ import {MatIconModule} from "@angular/material/icon"; }) export class InputModule { constructor(private iconsService: IconsService) { - this.iconsService.registerIcons([lock]); + this.iconsService.registerIcons([lock, remove_circle]); } } diff --git a/utils/icons/icons.ts b/utils/icons/icons.ts index 052f0272..95e02a97 100644 --- a/utils/icons/icons.ts +++ b/utils/icons/icons.ts @@ -62,6 +62,11 @@ export const bullet: Icon = { data: '' } +export const remove_circle = { + name: 'remove_circle', + data: '' +} + export const remove_circle_outline = { name: 'remove_circle_outline', data: '' diff --git a/utils/string-utils.class.ts b/utils/string-utils.class.ts index 77490d30..30c6912c 100644 --- a/utils/string-utils.class.ts +++ b/utils/string-utils.class.ts @@ -187,6 +187,11 @@ export class Identifier { } export class StringUtils { + + public static urlRegex = 'https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.' + + '[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.' + + '[a-zA-Z0-9]+\.[^\s]{2,}'; + public static urlPrefix(url: string): string { if (url.startsWith("http://") || url.startsWith("https://") || url.startsWith("//")) { return ""; @@ -230,10 +235,12 @@ export class StringUtils { return !!email.match("^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$"); } + public static isValidUrl(url: string): boolean { + return new RegExp(this.urlRegex).test(url); + } + public static urlValidator(): ValidatorFn { - return Validators.pattern('https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.' + - '[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.' + - '[a-zA-Z0-9]+\.[^\s]{2,}'); + return Validators.pattern(this.urlRegex); } public static sliceString(mystr, size: number): string {