From c320659f7e55c562f3e494b244cba1e1621a58f7 Mon Sep 17 00:00:00 2001 From: Michiel Stornebrink Date: Tue, 20 Dec 2022 23:00:36 +0100 Subject: [PATCH 01/26] Add a few typescript interfaces --- .../interfacing/patch-replace.interface.ts | 5 +++++ .../interfacing/patch-response.interface.ts | 18 ++++++++++++++++++ .../shared/interfacing/resource.interface.ts | 7 +++++++ 3 files changed, 30 insertions(+) create mode 100644 src/app/shared/interfacing/patch-replace.interface.ts create mode 100644 src/app/shared/interfacing/patch-response.interface.ts create mode 100644 src/app/shared/interfacing/resource.interface.ts diff --git a/src/app/shared/interfacing/patch-replace.interface.ts b/src/app/shared/interfacing/patch-replace.interface.ts new file mode 100644 index 000000000..c92c6a218 --- /dev/null +++ b/src/app/shared/interfacing/patch-replace.interface.ts @@ -0,0 +1,5 @@ +export interface PatchReplace { + op: 'replace', + path: string, + value: string | null, +} diff --git a/src/app/shared/interfacing/patch-response.interface.ts b/src/app/shared/interfacing/patch-response.interface.ts new file mode 100644 index 000000000..29d5ce898 --- /dev/null +++ b/src/app/shared/interfacing/patch-response.interface.ts @@ -0,0 +1,18 @@ +import { PatchReplace } from "./patch-replace.interface" + +export interface PatchResponse { + content: T, + patches: Array, + notifications: { + errors: Array, + warnings: Array, + infos: Array, + successes: Array, + invariants: Array, + signals: Array, + }, + invariantRulesHold: boolean, + isCommitted: boolean, + sessionRefreshAdvice: boolean, + navTo: string | null, +} diff --git a/src/app/shared/interfacing/resource.interface.ts b/src/app/shared/interfacing/resource.interface.ts new file mode 100644 index 000000000..7842d9905 --- /dev/null +++ b/src/app/shared/interfacing/resource.interface.ts @@ -0,0 +1,7 @@ +import { Observable } from "rxjs"; +import { PatchReplace } from "./patch-replace.interface"; +import { PatchResponse } from "./patch-response.interface"; + +export interface Resource { + patch(patches: Array): Observable> +} From d4599ff06a31180256aadc16441d5353f19ca4a4 Mon Sep 17 00:00:00 2001 From: Michiel Stornebrink Date: Tue, 20 Dec 2022 23:01:06 +0100 Subject: [PATCH 02/26] Add ReactiveFormsModule --- src/app/shared/shared.module.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/app/shared/shared.module.ts b/src/app/shared/shared.module.ts index 7f39c7ee2..b363b2e15 100644 --- a/src/app/shared/shared.module.ts +++ b/src/app/shared/shared.module.ts @@ -1,6 +1,6 @@ import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; -import { FormsModule } from '@angular/forms'; +import { ReactiveFormsModule, FormsModule } from '@angular/forms'; // Components import { AtomicAlphanumericComponent } from './atomic-components/atomic-alphanumeric/atomic-alphanumeric.component'; @@ -58,6 +58,7 @@ import { ButtonModule } from 'primeng/button'; ], imports: [ CommonModule, + ReactiveFormsModule, FormsModule, InputTextModule, InputSwitchModule, From 6d1556c3101df0ac166641e12aabea525d89e31a Mon Sep 17 00:00:00 2001 From: Michiel Stornebrink Date: Tue, 20 Dec 2022 23:06:38 +0100 Subject: [PATCH 03/26] Change Alphanumeric component input field to FormControl field Call patch() on value changes --- .../atomic-alphanumeric.component.html | 11 ++----- .../atomic-alphanumeric.component.ts | 32 +++++++++++++++++-- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/app/shared/atomic-components/atomic-alphanumeric/atomic-alphanumeric.component.html b/src/app/shared/atomic-components/atomic-alphanumeric/atomic-alphanumeric.component.html index 25f7d05e6..0e81efc0a 100644 --- a/src/app/shared/atomic-components/atomic-alphanumeric/atomic-alphanumeric.component.html +++ b/src/app/shared/atomic-components/atomic-alphanumeric/atomic-alphanumeric.component.html @@ -1,14 +1,7 @@
- +
@@ -25,7 +18,7 @@ type="text" class="min-w-10rem w-full" pInputText - [(ngModel)]="newItem" + [formControl]="newItem" placeholder="Add text" [required]="isNewItemInputRequired()" /> diff --git a/src/app/shared/atomic-components/atomic-alphanumeric/atomic-alphanumeric.component.ts b/src/app/shared/atomic-components/atomic-alphanumeric/atomic-alphanumeric.component.ts index 6543dc515..d71c760bd 100644 --- a/src/app/shared/atomic-components/atomic-alphanumeric/atomic-alphanumeric.component.ts +++ b/src/app/shared/atomic-components/atomic-alphanumeric/atomic-alphanumeric.component.ts @@ -1,5 +1,8 @@ -import { Component } from '@angular/core'; +import { Component, Input } from '@angular/core'; import { BaseAtomicComponent } from '../BaseAtomicComponent.class'; +import { FormControl } from '@angular/forms'; +import { debounceTime, distinctUntilChanged, tap } from 'rxjs'; +import { Resource } from '../../interfacing/resource.interface'; @Component({ selector: 'app-atomic-alphanumeric', @@ -7,9 +10,34 @@ import { BaseAtomicComponent } from '../BaseAtomicComponent.class'; styleUrls: ['./atomic-alphanumeric.component.css'], }) export class AtomicAlphanumericComponent extends BaseAtomicComponent { - newItem!: string; + value!: FormControl; + newItem: FormControl = new FormControl('', {nonNullable: true}); + + @Input() + resource!: Resource; + + @Input() + propertyName!: string; isNewItemInputRequired() { return this.isTot && this.property?.length === 0; } + + override ngOnInit(): void { + super.ngOnInit(); + this.value = new FormControl(this.requireArray(this.property)[0], {nonNullable: false}); + this.value.valueChanges + .pipe( + debounceTime(300), + distinctUntilChanged(), + tap(x => console.log(x)), + ) + .subscribe( + x => this.resource.patch([{ + op: 'replace', + path: this.propertyName, + value: x, + }]).subscribe() + ); + } } From c45d8751956a10f6fae2864a859211b9a332d3b8 Mon Sep 17 00:00:00 2001 From: Michiel Stornebrink Date: Tue, 20 Dec 2022 23:07:43 +0100 Subject: [PATCH 04/26] Implement patch() for ProjectEditComponent --- .../project-administration/backend.service.ts | 5 ++-- .../project-edit/project-edit.component.ts | 28 +++++++++---------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/app/project-administration/backend.service.ts b/src/app/project-administration/backend.service.ts index ace8d404e..89abba96f 100644 --- a/src/app/project-administration/backend.service.ts +++ b/src/app/project-administration/backend.service.ts @@ -1,6 +1,7 @@ import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Observable } from 'rxjs'; +import { PatchResponse } from '../shared/interfacing/patch-response.interface'; import { ActiveProjectsInterface } from './active-projects/active-projects.interface'; import { IBackendService } from './backend.service.interface'; import { ListAllInterfacesInterface } from './list-all-interfaces/list-all-interfaces.interface'; @@ -32,8 +33,8 @@ export class BackendService implements IBackendService { return this.http.get('resource/SESSION/1/List_32_all_32_interfaces'); } - public patchProject(id: string, data: any): Observable { - return this.http.patch(`resource/Project/${id}/New_47_edit_32_project`, data); + public patchProject(id: string, data: any): Observable> { + return this.http.patch>(`resource/Project/${id}/New_47_edit_32_project`, data); } public patchPerson(id: string, data: any): Observable { diff --git a/src/app/project-administration/project-edit/project-edit.component.ts b/src/app/project-administration/project-edit/project-edit.component.ts index 828f0e341..101d485a2 100644 --- a/src/app/project-administration/project-edit/project-edit.component.ts +++ b/src/app/project-administration/project-edit/project-edit.component.ts @@ -1,6 +1,9 @@ import { Component, OnInit } from '@angular/core'; import { ActivatedRoute, ParamMap } from '@angular/router'; -import { Observable, switchMap } from 'rxjs'; +import { from, Observable, switchMap, tap } from 'rxjs'; +import { PatchReplace } from 'src/app/shared/interfacing/patch-replace.interface'; +import { PatchResponse } from 'src/app/shared/interfacing/patch-response.interface'; +import { Resource } from 'src/app/shared/interfacing/resource.interface'; import { BackendService } from '../backend.service'; import { ProjectInterface } from '../project/project.interface'; @@ -9,7 +12,7 @@ import { ProjectInterface } from '../project/project.interface'; templateUrl: './project-edit.component.html', styleUrls: ['./project-edit.component.scss'], }) -export class ProjectEditComponent implements OnInit { +export class ProjectEditComponent implements OnInit, Resource { public data$!: Observable; public projectId!: string; @@ -27,17 +30,14 @@ export class ProjectEditComponent implements OnInit { ); } - patchProject(property: any, path: string) { - let body = [ - { - op: 'replace', - path: path, - value: property, - }, - ]; - - this.service.patchProject(this.projectId, body).subscribe(() => { - this.data$ = this.service.getProject(this.projectId); - }); + patch(patches: PatchReplace[]): Observable> { + return this.service.patchProject(this.projectId, patches) + .pipe( + tap(x => { + if (x.isCommitted) { + this.data$ = from([x.content]) + } + }), + ); } } From 97764b107ffef8d3b77d7503f4f8db8ff31f3e6f Mon Sep 17 00:00:00 2001 From: Michiel Stornebrink Date: Tue, 20 Dec 2022 23:09:55 +0100 Subject: [PATCH 05/26] Test with resource and propertyName input bindings --- .../project-edit/project-edit.component.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/app/project-administration/project-edit/project-edit.component.html b/src/app/project-administration/project-edit/project-edit.component.html index bb3505161..fa6f286e0 100644 --- a/src/app/project-administration/project-edit/project-edit.component.html +++ b/src/app/project-administration/project-edit/project-edit.component.html @@ -8,6 +8,8 @@
{{ data.Name }}
Date: Tue, 20 Dec 2022 23:10:46 +0100 Subject: [PATCH 06/26] Cleanup unused propertyEvent binding --- .../person/person.component.html | 4 ---- .../project-edit/project-edit.component.html | 21 ++----------------- .../BaseAtomicComponent.class.ts | 10 +-------- .../atomic-bigalphanumeric.component.html | 1 - .../atomic-boolean.component.html | 2 +- .../atomic-date/atomic-date.component.html | 2 -- .../atomic-datetime.component.html | 2 -- 7 files changed, 4 insertions(+), 38 deletions(-) diff --git a/src/app/project-administration/person/person.component.html b/src/app/project-administration/person/person.component.html index 8799ee9db..63af801b3 100644 --- a/src/app/project-administration/person/person.component.html +++ b/src/app/project-administration/person/person.component.html @@ -13,7 +13,6 @@
{{ data.First_32_name }} {{ data.Last_32_name }}
isUni isTot crud="cRUd" - (propertyEvent)="patchPerson($event, '/First_32_name')" >
@@ -26,7 +25,6 @@
{{ data.First_32_name }} {{ data.Last_32_name }}
isUni isTot crud="cRUd" - (propertyEvent)="patchPerson($event, '/Last_32_name')" > @@ -39,7 +37,6 @@
{{ data.First_32_name }} {{ data.Last_32_name }}
isUni isTot crud="cRUd" - (propertyEvent)="patchPerson($event, '/Status')" > @@ -52,7 +49,6 @@
{{ data.First_32_name }} {{ data.Last_32_name }}
isUni isTot crud="cRUd" - (propertyEvent)="patchPerson($event, '/Email')" > diff --git a/src/app/project-administration/project-edit/project-edit.component.html b/src/app/project-administration/project-edit/project-edit.component.html index fa6f286e0..5acc17a7e 100644 --- a/src/app/project-administration/project-edit/project-edit.component.html +++ b/src/app/project-administration/project-edit/project-edit.component.html @@ -14,7 +14,6 @@
{{ data.Name }}
isUni isTot crud="CRUD" - (propertyEvent)="patchProject($event, '/Name')" > @@ -26,7 +25,6 @@
{{ data.Name }}
isUni isTot crud="CRUD" - (propertyEvent)="patchProject($event, '/Description')" > @@ -38,7 +36,6 @@
{{ data.Name }}
isUni isTot crud="CRUD" - (propertyEvent)="patchProject($event, '/Start_32_date')" > @@ -50,32 +47,19 @@
{{ data.Name }}
isUni isTot crud="CRUD" - (propertyEvent)="patchProject($event, '/Status')" >
- +
- +
@@ -86,7 +70,6 @@
{{ data.Name }}
isUni isTot crud="CRUD" - (propertyEvent)="patchProject($event, '/Project_32_members')" >
diff --git a/src/app/shared/atomic-components/BaseAtomicComponent.class.ts b/src/app/shared/atomic-components/BaseAtomicComponent.class.ts index ab8b4aac3..c1d7a8765 100644 --- a/src/app/shared/atomic-components/BaseAtomicComponent.class.ts +++ b/src/app/shared/atomic-components/BaseAtomicComponent.class.ts @@ -1,4 +1,4 @@ -import { Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges } from '@angular/core'; +import { Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core'; @Component({ template: '', @@ -28,7 +28,6 @@ export abstract class BaseAtomicComponent implements OnInit, OnChanges { return this._isTot; } @Input() crud: string = 'crud'; - @Output() propertyEvent = new EventEmitter | null>(); ngOnInit(): void { this.setCRUDPermissions(this.crud); @@ -45,13 +44,6 @@ export abstract class BaseAtomicComponent implements OnInit, OnChanges { this.setCRUDPermissions(changes['crud'].currentValue); } - public changeProperty(): void { - if (this.oldProperty == this.data) { - return; - } - this.propertyEvent.emit(this.data); - } - private setCRUDPermissions(crud: string) { let c = crud[0]; let r = crud[1]; diff --git a/src/app/shared/atomic-components/atomic-bigalphanumeric/atomic-bigalphanumeric.component.html b/src/app/shared/atomic-components/atomic-bigalphanumeric/atomic-bigalphanumeric.component.html index 1e4938988..a711972c5 100644 --- a/src/app/shared/atomic-components/atomic-bigalphanumeric/atomic-bigalphanumeric.component.html +++ b/src/app/shared/atomic-components/atomic-bigalphanumeric/atomic-bigalphanumeric.component.html @@ -5,7 +5,6 @@ pInputTextarea [(ngModel)]="property" [required]="isTot" - (blur)="changeProperty()" maxlength="64000" class="w-full min-w-10rem" > diff --git a/src/app/shared/atomic-components/atomic-boolean/atomic-boolean.component.html b/src/app/shared/atomic-components/atomic-boolean/atomic-boolean.component.html index ecdb3f165..5a33af5d6 100644 --- a/src/app/shared/atomic-components/atomic-boolean/atomic-boolean.component.html +++ b/src/app/shared/atomic-components/atomic-boolean/atomic-boolean.component.html @@ -5,7 +5,7 @@ *ngIf="isUni && canRead" [(ngModel)]="property" [disabled]="!canUpdate" - (click)="getState(); changeProperty()" + (click)="getState()" > diff --git a/src/app/shared/atomic-components/atomic-date/atomic-date.component.html b/src/app/shared/atomic-components/atomic-date/atomic-date.component.html index ba4e46bd8..8d7715edc 100644 --- a/src/app/shared/atomic-components/atomic-date/atomic-date.component.html +++ b/src/app/shared/atomic-components/atomic-date/atomic-date.component.html @@ -6,8 +6,6 @@ [dateFormat]="format" [(ngModel)]="property" (ngModelChange)="onDateChange($event)" - (onSelect)="changeProperty()" - (onClear)="changeProperty()" > diff --git a/src/app/shared/atomic-components/atomic-datetime/atomic-datetime.component.html b/src/app/shared/atomic-components/atomic-datetime/atomic-datetime.component.html index 909103f4d..9825252bf 100644 --- a/src/app/shared/atomic-components/atomic-datetime/atomic-datetime.component.html +++ b/src/app/shared/atomic-components/atomic-datetime/atomic-datetime.component.html @@ -8,8 +8,6 @@ [readonlyInput]="true" [showTime]="true" (ngModelChange)="onDateChange($event)" - (onSelect)="changeProperty()" - (onClear)="changeProperty()" > From a3f98c71005e16293f0908cec069550eef1b8786 Mon Sep 17 00:00:00 2001 From: Michiel Stornebrink Date: Tue, 20 Dec 2022 23:23:19 +0100 Subject: [PATCH 07/26] Bugfix --- src/app/shared/atomic-components/BaseAtomicComponent.class.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/app/shared/atomic-components/BaseAtomicComponent.class.ts b/src/app/shared/atomic-components/BaseAtomicComponent.class.ts index c1d7a8765..095a3d6e1 100644 --- a/src/app/shared/atomic-components/BaseAtomicComponent.class.ts +++ b/src/app/shared/atomic-components/BaseAtomicComponent.class.ts @@ -41,7 +41,9 @@ export abstract class BaseAtomicComponent implements OnInit, OnChanges { if (changes.hasOwnProperty('isUni')) { this.isUni = changes['isUni'].firstChange; } - this.setCRUDPermissions(changes['crud'].currentValue); + if (changes.hasOwnProperty('crud')) { + this.setCRUDPermissions(changes['crud'].currentValue); + } } private setCRUDPermissions(crud: string) { From 01c76871baa011fbb2cb97544c03fcc064dc2a5a Mon Sep 17 00:00:00 2001 From: Michiel Stornebrink Date: Tue, 20 Dec 2022 23:28:35 +0100 Subject: [PATCH 08/26] Use value null for empty string --- .../atomic-alphanumeric/atomic-alphanumeric.component.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/app/shared/atomic-components/atomic-alphanumeric/atomic-alphanumeric.component.ts b/src/app/shared/atomic-components/atomic-alphanumeric/atomic-alphanumeric.component.ts index d71c760bd..3abf6d096 100644 --- a/src/app/shared/atomic-components/atomic-alphanumeric/atomic-alphanumeric.component.ts +++ b/src/app/shared/atomic-components/atomic-alphanumeric/atomic-alphanumeric.component.ts @@ -1,7 +1,7 @@ import { Component, Input } from '@angular/core'; import { BaseAtomicComponent } from '../BaseAtomicComponent.class'; import { FormControl } from '@angular/forms'; -import { debounceTime, distinctUntilChanged, tap } from 'rxjs'; +import { debounceTime, distinctUntilChanged, map, tap } from 'rxjs'; import { Resource } from '../../interfacing/resource.interface'; @Component({ @@ -30,7 +30,8 @@ export class AtomicAlphanumericComponent extends BaseAtomicComponent { .pipe( debounceTime(300), distinctUntilChanged(), - tap(x => console.log(x)), + map(x => x === '' ? null : x), // transform empty string to null value + tap(x => console.log(x)), // TODO: remove this line ) .subscribe( x => this.resource.patch([{ From 31362d7e306cd8c5fbb14b406f12c799cb954d37 Mon Sep 17 00:00:00 2001 From: LiWeiYeh Date: Wed, 21 Dec 2022 14:31:13 +0100 Subject: [PATCH 09/26] linting --- .../project-edit/project-edit.component.ts | 15 +++++---- .../BaseAtomicComponent.class.ts | 2 -- .../atomic-alphanumeric.component.ts | 30 ++++++++++-------- .../interfacing/patch-replace.interface.ts | 6 ++-- .../interfacing/patch-response.interface.ts | 31 ++++++++++--------- .../shared/interfacing/resource.interface.ts | 8 ++--- 6 files changed, 47 insertions(+), 45 deletions(-) diff --git a/src/app/project-administration/project-edit/project-edit.component.ts b/src/app/project-administration/project-edit/project-edit.component.ts index 101d485a2..a55e6260f 100644 --- a/src/app/project-administration/project-edit/project-edit.component.ts +++ b/src/app/project-administration/project-edit/project-edit.component.ts @@ -31,13 +31,12 @@ export class ProjectEditComponent implements OnInit, Resource } patch(patches: PatchReplace[]): Observable> { - return this.service.patchProject(this.projectId, patches) - .pipe( - tap(x => { - if (x.isCommitted) { - this.data$ = from([x.content]) - } - }), - ); + return this.service.patchProject(this.projectId, patches).pipe( + tap((x) => { + if (x.isCommitted) { + this.data$ = from([x.content]); + } + }), + ); } } diff --git a/src/app/shared/atomic-components/BaseAtomicComponent.class.ts b/src/app/shared/atomic-components/BaseAtomicComponent.class.ts index 095a3d6e1..2f6326fd5 100644 --- a/src/app/shared/atomic-components/BaseAtomicComponent.class.ts +++ b/src/app/shared/atomic-components/BaseAtomicComponent.class.ts @@ -6,7 +6,6 @@ import { Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/cor export abstract class BaseAtomicComponent implements OnInit, OnChanges { @Input() property: T | Array | null = null; public data: Array = []; - private oldProperty: Array = []; public canCreate!: boolean; public canRead!: boolean; public canUpdate!: boolean; @@ -32,7 +31,6 @@ export abstract class BaseAtomicComponent implements OnInit, OnChanges { ngOnInit(): void { this.setCRUDPermissions(this.crud); // TODO: unneeded when ng formcontrols work - this.oldProperty = this.requireArray(this.property); this.data = this.requireArray(this.property); } diff --git a/src/app/shared/atomic-components/atomic-alphanumeric/atomic-alphanumeric.component.ts b/src/app/shared/atomic-components/atomic-alphanumeric/atomic-alphanumeric.component.ts index 3abf6d096..8f4487eb7 100644 --- a/src/app/shared/atomic-components/atomic-alphanumeric/atomic-alphanumeric.component.ts +++ b/src/app/shared/atomic-components/atomic-alphanumeric/atomic-alphanumeric.component.ts @@ -1,4 +1,4 @@ -import { Component, Input } from '@angular/core'; +import { Component, Input, OnInit } from '@angular/core'; import { BaseAtomicComponent } from '../BaseAtomicComponent.class'; import { FormControl } from '@angular/forms'; import { debounceTime, distinctUntilChanged, map, tap } from 'rxjs'; @@ -9,12 +9,13 @@ import { Resource } from '../../interfacing/resource.interface'; templateUrl: './atomic-alphanumeric.component.html', styleUrls: ['./atomic-alphanumeric.component.css'], }) -export class AtomicAlphanumericComponent extends BaseAtomicComponent { +export class AtomicAlphanumericComponent extends BaseAtomicComponent implements OnInit { value!: FormControl; - newItem: FormControl = new FormControl('', {nonNullable: true}); + newItem: FormControl = new FormControl('', { nonNullable: true }); @Input() - resource!: Resource; + // TODO: change unknown type + resource!: Resource; @Input() propertyName!: string; @@ -25,20 +26,23 @@ export class AtomicAlphanumericComponent extends BaseAtomicComponent { override ngOnInit(): void { super.ngOnInit(); - this.value = new FormControl(this.requireArray(this.property)[0], {nonNullable: false}); + this.value = new FormControl(this.data[0], { nonNullable: false }); this.value.valueChanges .pipe( debounceTime(300), distinctUntilChanged(), - map(x => x === '' ? null : x), // transform empty string to null value - tap(x => console.log(x)), // TODO: remove this line + map((x) => (x === '' ? null : x)), // transform empty string to null value ) - .subscribe( - x => this.resource.patch([{ - op: 'replace', - path: this.propertyName, - value: x, - }]).subscribe() + .subscribe((x) => + this.resource + .patch([ + { + op: 'replace', + path: this.propertyName, + value: x, + }, + ]) + .subscribe(), ); } } diff --git a/src/app/shared/interfacing/patch-replace.interface.ts b/src/app/shared/interfacing/patch-replace.interface.ts index c92c6a218..c0ee3a9eb 100644 --- a/src/app/shared/interfacing/patch-replace.interface.ts +++ b/src/app/shared/interfacing/patch-replace.interface.ts @@ -1,5 +1,5 @@ export interface PatchReplace { - op: 'replace', - path: string, - value: string | null, + op: 'replace'; + path: string; + value: string | null; } diff --git a/src/app/shared/interfacing/patch-response.interface.ts b/src/app/shared/interfacing/patch-response.interface.ts index 29d5ce898..184f4f3da 100644 --- a/src/app/shared/interfacing/patch-response.interface.ts +++ b/src/app/shared/interfacing/patch-response.interface.ts @@ -1,18 +1,19 @@ -import { PatchReplace } from "./patch-replace.interface" +import { PatchReplace } from './patch-replace.interface'; export interface PatchResponse { - content: T, - patches: Array, - notifications: { - errors: Array, - warnings: Array, - infos: Array, - successes: Array, - invariants: Array, - signals: Array, - }, - invariantRulesHold: boolean, - isCommitted: boolean, - sessionRefreshAdvice: boolean, - navTo: string | null, + content: T; + patches: Array; + // TODO: change unknown types + notifications: { + errors: Array; + warnings: Array; + infos: Array; + successes: Array; + invariants: Array; + signals: Array; + }; + invariantRulesHold: boolean; + isCommitted: boolean; + sessionRefreshAdvice: boolean; + navTo: string | null; } diff --git a/src/app/shared/interfacing/resource.interface.ts b/src/app/shared/interfacing/resource.interface.ts index 7842d9905..f6a710e63 100644 --- a/src/app/shared/interfacing/resource.interface.ts +++ b/src/app/shared/interfacing/resource.interface.ts @@ -1,7 +1,7 @@ -import { Observable } from "rxjs"; -import { PatchReplace } from "./patch-replace.interface"; -import { PatchResponse } from "./patch-response.interface"; +import { Observable } from 'rxjs'; +import { PatchReplace } from './patch-replace.interface'; +import { PatchResponse } from './patch-response.interface'; export interface Resource { - patch(patches: Array): Observable> + patch(patches: Array): Observable>; } From a205f8282a0ca070549577966107c7ccab128864 Mon Sep 17 00:00:00 2001 From: Michiel Stornebrink Date: Wed, 21 Dec 2022 19:43:54 +0100 Subject: [PATCH 10/26] Remove comment that was for statement removed in previous commit --- src/app/shared/atomic-components/BaseAtomicComponent.class.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/app/shared/atomic-components/BaseAtomicComponent.class.ts b/src/app/shared/atomic-components/BaseAtomicComponent.class.ts index 2f6326fd5..df39924b7 100644 --- a/src/app/shared/atomic-components/BaseAtomicComponent.class.ts +++ b/src/app/shared/atomic-components/BaseAtomicComponent.class.ts @@ -30,7 +30,6 @@ export abstract class BaseAtomicComponent implements OnInit, OnChanges { ngOnInit(): void { this.setCRUDPermissions(this.crud); - // TODO: unneeded when ng formcontrols work this.data = this.requireArray(this.property); } From e2a8c44d730503eea01edb808be3a06f6035dffe Mon Sep 17 00:00:00 2001 From: Michiel Stornebrink Date: Wed, 21 Dec 2022 10:06:06 +0100 Subject: [PATCH 11/26] Rearrange class attributes --- .../BaseAtomicComponent.class.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/app/shared/atomic-components/BaseAtomicComponent.class.ts b/src/app/shared/atomic-components/BaseAtomicComponent.class.ts index df39924b7..0eba2042b 100644 --- a/src/app/shared/atomic-components/BaseAtomicComponent.class.ts +++ b/src/app/shared/atomic-components/BaseAtomicComponent.class.ts @@ -4,12 +4,11 @@ import { Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/cor template: '', }) export abstract class BaseAtomicComponent implements OnInit, OnChanges { - @Input() property: T | Array | null = null; + @Input() + property: T | Array | null = null; + public data: Array = []; - public canCreate!: boolean; - public canRead!: boolean; - public canUpdate!: boolean; - public canDelete!: boolean; + private _isUni: boolean = false; @Input() set isUni(attribute: boolean | '') { @@ -18,6 +17,7 @@ export abstract class BaseAtomicComponent implements OnInit, OnChanges { get isUni(): boolean { return this._isUni; } + private _isTot: boolean = false; @Input() set isTot(attribute: boolean | '') { @@ -26,7 +26,14 @@ export abstract class BaseAtomicComponent implements OnInit, OnChanges { get isTot(): boolean { return this._isTot; } - @Input() crud: string = 'crud'; + + @Input() + crud: string = 'crud'; + + public canCreate!: boolean; + public canRead!: boolean; + public canUpdate!: boolean; + public canDelete!: boolean; ngOnInit(): void { this.setCRUDPermissions(this.crud); From 4d89ba7d96e570c0cc6d7ee800aa525f154f57fc Mon Sep 17 00:00:00 2001 From: Michiel Stornebrink Date: Wed, 21 Dec 2022 10:23:52 +0100 Subject: [PATCH 12/26] Refactor determining CRUD rights. Make it simpler --- .../BaseAtomicComponent.class.ts | 34 +++++++------------ .../atomic-alphanumeric.component.html | 4 +-- .../atomic-bigalphanumeric.component.html | 4 +-- .../atomic-boolean.component.html | 6 ++-- .../atomic-date/atomic-date.component.html | 4 +-- .../atomic-datetime.component.html | 4 +-- .../atomic-password.component.html | 6 ++-- 7 files changed, 27 insertions(+), 35 deletions(-) diff --git a/src/app/shared/atomic-components/BaseAtomicComponent.class.ts b/src/app/shared/atomic-components/BaseAtomicComponent.class.ts index 0eba2042b..9d663237c 100644 --- a/src/app/shared/atomic-components/BaseAtomicComponent.class.ts +++ b/src/app/shared/atomic-components/BaseAtomicComponent.class.ts @@ -28,15 +28,22 @@ export abstract class BaseAtomicComponent implements OnInit, OnChanges { } @Input() - crud: string = 'crud'; + crud: string = 'cRud'; - public canCreate!: boolean; - public canRead!: boolean; - public canUpdate!: boolean; - public canDelete!: boolean; + public canCreate(): boolean { + return this.crud.includes('C'); + } + public canRead(): boolean { + return this.crud.includes('R'); + } + public canUpdate(): boolean { + return this.crud.includes('U'); + } + public canDelete(): boolean { + return this.crud.includes('D'); + } ngOnInit(): void { - this.setCRUDPermissions(this.crud); this.data = this.requireArray(this.property); } @@ -45,21 +52,6 @@ export abstract class BaseAtomicComponent implements OnInit, OnChanges { if (changes.hasOwnProperty('isUni')) { this.isUni = changes['isUni'].firstChange; } - if (changes.hasOwnProperty('crud')) { - this.setCRUDPermissions(changes['crud'].currentValue); - } - } - - private setCRUDPermissions(crud: string) { - let c = crud[0]; - let r = crud[1]; - let u = crud[2]; - let d = crud[3]; - - this.canCreate = c == c.toUpperCase(); - this.canRead = r == r.toUpperCase(); - this.canUpdate = u == u.toUpperCase(); - this.canDelete = d == d.toUpperCase(); } public requireArray(property: T | Array | null) { diff --git a/src/app/shared/atomic-components/atomic-alphanumeric/atomic-alphanumeric.component.html b/src/app/shared/atomic-components/atomic-alphanumeric/atomic-alphanumeric.component.html index 0e81efc0a..3d9b4b4ee 100644 --- a/src/app/shared/atomic-components/atomic-alphanumeric/atomic-alphanumeric.component.html +++ b/src/app/shared/atomic-components/atomic-alphanumeric/atomic-alphanumeric.component.html @@ -1,5 +1,5 @@ -
-
+
+
diff --git a/src/app/shared/atomic-components/atomic-bigalphanumeric/atomic-bigalphanumeric.component.html b/src/app/shared/atomic-components/atomic-bigalphanumeric/atomic-bigalphanumeric.component.html index a711972c5..c5486e079 100644 --- a/src/app/shared/atomic-components/atomic-bigalphanumeric/atomic-bigalphanumeric.component.html +++ b/src/app/shared/atomic-components/atomic-bigalphanumeric/atomic-bigalphanumeric.component.html @@ -1,5 +1,5 @@ -
-
+
+