From 7282f1bac552e73c83e08fe6b0065133df412767 Mon Sep 17 00:00:00 2001 From: "k.triantafyllou" Date: Thu, 13 Jan 2022 15:46:22 +0200 Subject: [PATCH] Add validator for page route. Change icons for buttons. Disable edit page with a Portal PID. --- dashboard/divId/divIds.component.html | 6 +- dashboard/divId/divIds.module.ts | 4 +- .../class-help-contents.component.html | 25 +- .../class-help-contents.module.ts | 4 +- dashboard/entity/entities.component.html | 5 +- dashboard/entity/entities.module.ts | 4 +- .../page-help-contents.component.html | 94 ++++---- .../helpTexts/page-help-contents.module.ts | 4 +- dashboard/menu/menu.component.html | 219 ++++++++++-------- dashboard/menu/menu.component.ts | 4 +- dashboard/menu/menu.module.ts | 4 +- dashboard/page/pages.component.html | 104 +++++---- dashboard/page/pages.component.ts | 6 +- dashboard/page/pages.module.ts | 4 +- dashboard/portal/portals.component.html | 5 +- dashboard/portal/portals.module.ts | 4 +- .../admin-tabs/admin-tabs.component.ts | 2 +- utils/string-utils.class.ts | 20 +- 18 files changed, 277 insertions(+), 241 deletions(-) diff --git a/dashboard/divId/divIds.component.html b/dashboard/divId/divIds.component.html index dd03452e..3dc4a283 100644 --- a/dashboard/divId/divIds.component.html +++ b/dashboard/divId/divIds.component.html @@ -77,11 +77,9 @@ -
- - + +
diff --git a/dashboard/divId/divIds.module.ts b/dashboard/divId/divIds.module.ts index e4221fc3..24815b02 100644 --- a/dashboard/divId/divIds.module.ts +++ b/dashboard/divId/divIds.module.ts @@ -20,7 +20,7 @@ import {ClassesRoutingModule} from "./classes-routing.module"; import {SearchInputModule} from "../../sharedComponents/search-input/search-input.module"; import {IconsModule} from "../../utils/icons/icons.module"; import {IconsService} from "../../utils/icons/icons.service"; -import {add} from "../../utils/icons/icons"; +import {add, edit, remove} from "../../utils/icons/icons"; import {LoadingModule} from "../../utils/loading/loading.module"; @NgModule({ @@ -34,6 +34,6 @@ import {LoadingModule} from "../../utils/loading/loading.module"; }) export class DivIdsModule { constructor(private iconsService: IconsService) { - this.iconsService.registerIcons([add]); + this.iconsService.registerIcons([add, edit, remove]); } } diff --git a/dashboard/divhelpcontent/class-help-contents.component.html b/dashboard/divhelpcontent/class-help-contents.component.html index a4dddb10..5472a224 100644 --- a/dashboard/divhelpcontent/class-help-contents.component.html +++ b/dashboard/divhelpcontent/class-help-contents.component.html @@ -94,22 +94,15 @@
-
- - - Edit - -
-
- - - Delete - -
+ +
diff --git a/dashboard/divhelpcontent/class-help-contents.module.ts b/dashboard/divhelpcontent/class-help-contents.module.ts index 59843842..5ab74f17 100644 --- a/dashboard/divhelpcontent/class-help-contents.module.ts +++ b/dashboard/divhelpcontent/class-help-contents.module.ts @@ -12,7 +12,7 @@ import {InputModule} from '../../sharedComponents/input/input.module'; import {SearchInputModule} from '../../sharedComponents/search-input/search-input.module'; import {IconsModule} from '../../utils/icons/icons.module'; import {IconsService} from '../../utils/icons/icons.service'; -import {add, arrow_left} from '../../utils/icons/icons'; +import {add, arrow_left, edit, remove} from '../../utils/icons/icons'; import {LoadingModule} from '../../utils/loading/loading.module'; import {HTMLToStringPipeModule} from '../../utils/pipes/HTMLToStringPipe.module'; import {ClassHelpContentsRoutingModule} from './class-help-contents-routing.module'; @@ -33,6 +33,6 @@ import {PageContentModule} from '../sharedComponents/page-content/page-content.m }) export class ClassHelpContentsModule { constructor(private iconsService: IconsService) { - this.iconsService.registerIcons([add, arrow_left]) + this.iconsService.registerIcons([add, arrow_left, edit, remove]) } } diff --git a/dashboard/entity/entities.component.html b/dashboard/entity/entities.component.html index 94d870b0..06d26acc 100644 --- a/dashboard/entity/entities.component.html +++ b/dashboard/entity/entities.component.html @@ -91,9 +91,8 @@
- - + +
diff --git a/dashboard/entity/entities.module.ts b/dashboard/entity/entities.module.ts index 349c2adf..69d8d4a4 100644 --- a/dashboard/entity/entities.module.ts +++ b/dashboard/entity/entities.module.ts @@ -13,7 +13,7 @@ import {EntitiesRoutingModule} from "./entities-routing.module"; import {SearchInputModule} from "../../sharedComponents/search-input/search-input.module"; import {IconsModule} from "../../utils/icons/icons.module"; import {IconsService} from "../../utils/icons/icons.service"; -import {add} from "../../utils/icons/icons"; +import {add, edit, remove} from "../../utils/icons/icons"; import {LoadingModule} from "../../utils/loading/loading.module"; @NgModule({ @@ -26,6 +26,6 @@ import {LoadingModule} from "../../utils/loading/loading.module"; }) export class EntitiesModule { constructor(private iconsService: IconsService) { - this.iconsService.registerIcons([add]); + this.iconsService.registerIcons([add, edit, remove]); } } diff --git a/dashboard/helpTexts/page-help-contents.component.html b/dashboard/helpTexts/page-help-contents.component.html index 783ce5ee..6758cf75 100644 --- a/dashboard/helpTexts/page-help-contents.component.html +++ b/dashboard/helpTexts/page-help-contents.component.html @@ -61,60 +61,56 @@
    -
  • -
    -
    -
    -
    +
  • +
    +
    +
    +
    +
    +
    +
    +
    {{check.pageHelpContent.page.name}}
    +
    +
    +

    {{check.pageHelpContent.content|htmlToString}}

    +
    +
    +
    + Placement: {{check.pageHelpContent.placement}} +
    +
    + Order: {{check.pageHelpContent.order}} +
    +
    + Enable/disable: + +
    +
    -
    -
    -
    {{check.pageHelpContent.page.name}}
    -
    -
    -

    {{check.pageHelpContent.content|htmlToString}}

    -
    -
    -
    - Placement: {{check.pageHelpContent.placement}} -
    -
    - Order: {{check.pageHelpContent.order}} -
    -
    - Enable/disable: - +
    +
    +
    +
    +
    + + +
    -
    -
    -
    -
    - - Edit -
    -
    - - - Delete - -
    -
    -
    -
    -
    -
  • -
+ +
diff --git a/dashboard/helpTexts/page-help-contents.module.ts b/dashboard/helpTexts/page-help-contents.module.ts index c4350d7d..ad23dd57 100644 --- a/dashboard/helpTexts/page-help-contents.module.ts +++ b/dashboard/helpTexts/page-help-contents.module.ts @@ -13,7 +13,7 @@ import {PageContentModule} from '../sharedComponents/page-content/page-content.m import {SearchInputModule} from '../../sharedComponents/search-input/search-input.module'; import {IconsModule} from '../../utils/icons/icons.module'; import {IconsService} from '../../utils/icons/icons.service'; -import {add, arrow_left} from '../../utils/icons/icons'; +import {add, arrow_left, edit, remove} from '../../utils/icons/icons'; import {LoadingModule} from '../../utils/loading/loading.module'; import {HTMLToStringPipeModule} from '../../utils/pipes/HTMLToStringPipe.module'; @@ -30,6 +30,6 @@ import {HTMLToStringPipeModule} from '../../utils/pipes/HTMLToStringPipe.module' }) export class PageHelpContentsModule { constructor(private iconsService: IconsService) { - this.iconsService.registerIcons([add, arrow_left]) + this.iconsService.registerIcons([add, arrow_left, edit, remove]) } } diff --git a/dashboard/menu/menu.component.html b/dashboard/menu/menu.component.html index 0c7786e2..f7d949f5 100644 --- a/dashboard/menu/menu.component.html +++ b/dashboard/menu/menu.component.html @@ -1,17 +1,18 @@
-
- -
-
- +
+
+ +
+
+
+ +
+
+ +
No menu items found
-
-
+
+
- -
-
-
- -
- -
-
Select one of the pages
-
+ + +
+
+ +
+ +
+
Select one of the pages
+
- -
-
- -
Create New Page
-
- -
-
-
- -
- -
-
- + +
+
+ +
Create New Page
+
+
+
+
+
+ +
+
+
+
+ - \ No newline at end of file + diff --git a/dashboard/menu/menu.component.ts b/dashboard/menu/menu.component.ts index c0590a8c..412189c7 100644 --- a/dashboard/menu/menu.component.ts +++ b/dashboard/menu/menu.component.ts @@ -42,7 +42,6 @@ export class MenuComponent implements OnInit { public menuItemForm: FormGroup; public pageForm: FormGroup; public rootMenuItems = []; - public menuItems = []; public allPages = []; public selectedMenuItem: string; @@ -173,7 +172,7 @@ export class MenuComponent implements OnInit { this.newPageWindowOpen = !this.newPageWindowOpen; this.pageForm = this._fb.group({ _id: this._fb.control(null), - route: this._fb.control('', Validators.required), + route: this._fb.control('', [Validators.required, StringUtils.validRoute(this.allPages, 'value')]), name: this._fb.control('', Validators.required), isEnabled: this._fb.control(true), portalType: this._fb.control(this.properties.adminToolsPortalType, Validators.required), @@ -203,6 +202,7 @@ export class MenuComponent implements OnInit { }); this.newPageWindowOpen = !this.newPageWindowOpen; this.menuItemForm.get('route').setValue(page.route); + this.menuItemForm.get('route').markAsDirty(); this.showLoading = false; }, error => this.handleError('System error creating page', error) diff --git a/dashboard/menu/menu.module.ts b/dashboard/menu/menu.module.ts index 450812d8..a57d6f90 100644 --- a/dashboard/menu/menu.module.ts +++ b/dashboard/menu/menu.module.ts @@ -13,7 +13,7 @@ import {MenuRoutingModule} from "./menu-routing.module"; import {SearchInputModule} from "../../sharedComponents/search-input/search-input.module"; import {IconsModule} from "../../utils/icons/icons.module"; import {IconsService} from "../../utils/icons/icons.service"; -import {add} from "../../utils/icons/icons"; +import {add, edit, remove} from "../../utils/icons/icons"; import {LoadingModule} from "../../utils/loading/loading.module"; @NgModule({ @@ -26,6 +26,6 @@ import {LoadingModule} from "../../utils/loading/loading.module"; }) export class MenuModule { constructor(private iconsService: IconsService) { - this.iconsService.registerIcons([add]); + this.iconsService.registerIcons([add, edit, remove]); } } diff --git a/dashboard/page/pages.component.html b/dashboard/page/pages.component.html index 6ca9c468..5437ff27 100644 --- a/dashboard/page/pages.component.html +++ b/dashboard/page/pages.component.html @@ -63,57 +63,71 @@
  • -
    -
    -
    -
    -
    Name
    -
    {{check.page.name}}
    -
    Entities: - {{getEntitiesAsString(check.page)}}
    -
    Route: {{check.page.route}}
    -
    Type: {{check.page.type}}
    -
    - Portal type: {{check.page.portalType}} +
    +
    +
    -
    -
    -
    Actions
    -
    - - +
    +
    Name
    +
    {{check.page.name}}
    +
    Entities: + {{getEntitiesAsString(check.page)}}
    +
    Route: {{check.page.route}}
    +
    Type: {{check.page.type}}
    +
    + Portal type: {{check.page.portalType}} +
    +
    + Portal PID: {{check.page.portalPid}} +
    -
    -
  • diff --git a/dashboard/page/pages.component.ts b/dashboard/page/pages.component.ts index af631036..59785e37 100644 --- a/dashboard/page/pages.component.ts +++ b/dashboard/page/pages.component.ts @@ -242,7 +242,7 @@ export class PagesComponent implements OnInit { this.index = this.pages.findIndex(value => value._id === page._id); this.pageForm = this._fb.group({ _id: this._fb.control(page._id), - route: this._fb.control(page.route, Validators.required), + route: this._fb.control(page.route, [Validators.required, StringUtils.validRoute(this.pages, 'route', page.route)]), name: this._fb.control(page.name, Validators.required), isEnabled: this._fb.control(page.isEnabled), portalType: this._fb.control(page.portalType, Validators.required), @@ -268,7 +268,7 @@ export class PagesComponent implements OnInit { this.entitiesCtrl = this._fb.array([]); this.pageForm = this._fb.group({ _id: this._fb.control(null), - route: this._fb.control('', Validators.required), + route: this._fb.control('', [Validators.required, StringUtils.validRoute(this.pages, 'route')]), name: this._fb.control('', Validators.required), isEnabled: this._fb.control(true), portalType: this._fb.control('', Validators.required), @@ -364,7 +364,7 @@ export class PagesComponent implements OnInit { if (error == null) { // this.formComponent.reset(); this.pageForm = this._fb.group({ - route: this._fb.control('', Validators.required), + route: this._fb.control('', [Validators.required, StringUtils.validRoute(this.pages, 'route')]), name: this._fb.control('', Validators.required), isEnabled: this._fb.control(true), portalType: this._fb.control('', Validators.required), diff --git a/dashboard/page/pages.module.ts b/dashboard/page/pages.module.ts index bdac5062..ba6a54a5 100644 --- a/dashboard/page/pages.module.ts +++ b/dashboard/page/pages.module.ts @@ -16,7 +16,7 @@ import {PagesRoutingModule} from "./pages-routing.module"; import {SearchInputModule} from "../../sharedComponents/search-input/search-input.module"; import {IconsModule} from "../../utils/icons/icons.module"; import {IconsService} from "../../utils/icons/icons.service"; -import {add} from "../../utils/icons/icons"; +import {add, edit, remove} from "../../utils/icons/icons"; import {LoadingModule} from "../../utils/loading/loading.module"; @NgModule({ @@ -29,6 +29,6 @@ import {LoadingModule} from "../../utils/loading/loading.module"; }) export class PagesModule { constructor(private iconsService: IconsService) { - this.iconsService.registerIcons([add]); + this.iconsService.registerIcons([add, edit, remove]); } } diff --git a/dashboard/portal/portals.component.html b/dashboard/portal/portals.component.html index c741e7b2..54fbeec3 100644 --- a/dashboard/portal/portals.component.html +++ b/dashboard/portal/portals.component.html @@ -69,9 +69,8 @@
    - - + +
    diff --git a/dashboard/portal/portals.module.ts b/dashboard/portal/portals.module.ts index d578f9b4..98f55248 100644 --- a/dashboard/portal/portals.module.ts +++ b/dashboard/portal/portals.module.ts @@ -10,7 +10,7 @@ import {AdminTabsModule} from "../sharedComponents/admin-tabs/admin-tabs.module" import {PageContentModule} from "../sharedComponents/page-content/page-content.module"; import {PortalsRoutingModule} from "./portals-routing.module"; import {IconsService} from "../../utils/icons/icons.service"; -import {add} from "../../utils/icons/icons"; +import {add, edit, remove} from "../../utils/icons/icons"; import {IconsModule} from "../../utils/icons/icons.module"; import {SearchInputModule} from "../../sharedComponents/search-input/search-input.module"; import {LoadingModule} from "../../utils/loading/loading.module"; @@ -26,6 +26,6 @@ import {LoadingModule} from "../../utils/loading/loading.module"; }) export class PortalsModule { constructor(private iconsService: IconsService) { - this.iconsService.registerIcons([add]); + this.iconsService.registerIcons([add, edit, remove]); } } diff --git a/dashboard/sharedComponents/admin-tabs/admin-tabs.component.ts b/dashboard/sharedComponents/admin-tabs/admin-tabs.component.ts index 2fc24a99..788d5fac 100644 --- a/dashboard/sharedComponents/admin-tabs/admin-tabs.component.ts +++ b/dashboard/sharedComponents/admin-tabs/admin-tabs.component.ts @@ -12,7 +12,7 @@ import { properties } from 'src/environments/environment';
  • Portals
  • Pages
  • Entities
  • -
  • Menu
  • +
  • Menu
  • Classes
` diff --git a/utils/string-utils.class.ts b/utils/string-utils.class.ts index 441ea639..114dcdb5 100644 --- a/utils/string-utils.class.ts +++ b/utils/string-utils.class.ts @@ -1,8 +1,9 @@ import {UrlSegment} from '@angular/router'; -import {AbstractControl, ValidatorFn, Validators} from "@angular/forms"; +import {AbstractControl, ValidationErrors, ValidatorFn, Validators} from "@angular/forms"; import {Stakeholder} from "../monitor/entities/stakeholder"; import {CommunityInfo} from "../connect/community/communityInfo"; import {properties} from "../../../environments/environment"; +import {Page} from "./entities/adminTool/page"; export class Dates { public static yearMin = 1800; @@ -247,6 +248,8 @@ export class StringUtils { '[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 routeRegex = '^[a-zA-Z0-9\/][a-zA-Z0-9\/-]*$'; + public static urlPrefix(url: string): string { if (url.startsWith("http://") || url.startsWith("https://") || url.startsWith("//")) { return ""; @@ -302,6 +305,21 @@ export class StringUtils { return Validators.pattern(StringUtils.urlRegex); } + public static validRoute(pages: any[], field: string, initial: string = null): ValidatorFn { + return (control: AbstractControl): ValidationErrors | null => { + if(control.value) { + if(!new RegExp(this.routeRegex).test(control.value)) { + return {error: 'Route should contain only letters or numbers, e.g /route or route'} + } + if(pages && pages.length > 0 && control.value !== initial) { + const forbidden = pages.filter(page => page[field].replace('/', '') === control.value.replace('/', '')).length > 0; + return forbidden ? {error: 'This route is used by an other page'} : null; + } + } + return null; + }; + } + public static sliceString(mystr, size: number): string { const sliced = String(mystr).substr(0, size); return sliced + (String(mystr).length > size ? '...' : '');