From 573367e90822c7943313508ccfafb7e78636109a Mon Sep 17 00:00:00 2001 From: mpetrov Date: Thu, 11 Jul 2024 17:39:32 +0300 Subject: [PATCH 1/2] Made title read only on LwM2M resorces --- .../resource/resources-library.component.html | 2 +- .../resource/resources-library.component.ts | 38 +++++++++++-------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/ui-ngx/src/app/modules/home/pages/admin/resource/resources-library.component.html b/ui-ngx/src/app/modules/home/pages/admin/resource/resources-library.component.html index 76625326b4..c42d94d51c 100644 --- a/ui-ngx/src/app/modules/home/pages/admin/resource/resources-library.component.html +++ b/ui-ngx/src/app/modules/home/pages/admin/resource/resources-library.component.html @@ -58,7 +58,7 @@ resource.title - + {{ 'resource.title-required' | translate }} diff --git a/ui-ngx/src/app/modules/home/pages/admin/resource/resources-library.component.ts b/ui-ngx/src/app/modules/home/pages/admin/resource/resources-library.component.ts index 54dfc9340e..049e53caf8 100644 --- a/ui-ngx/src/app/modules/home/pages/admin/resource/resources-library.component.ts +++ b/ui-ngx/src/app/modules/home/pages/admin/resource/resources-library.component.ts @@ -59,22 +59,7 @@ export class ResourcesLibraryComponent extends EntityComponent impleme ngOnInit() { super.ngOnInit(); - this.entityForm.get('resourceType').valueChanges.pipe( - startWith(ResourceType.JS_MODULE), - filter(() => this.isAdd), - takeUntil(this.destroy$) - ).subscribe((type) => { - if (type === this.resourceType.LWM2M_MODEL) { - this.entityForm.get('title').disable({emitEvent: false}); - this.entityForm.patchValue({title: ''}, {emitEvent: false}); - } else { - this.entityForm.get('title').enable({emitEvent: false}); - } - this.entityForm.patchValue({ - data: null, - fileName: null - }, {emitEvent: false}); - }); + this.observeResourceTypeChange(); } ngOnDestroy() { @@ -153,4 +138,25 @@ export class ResourcesLibraryComponent extends EntityComponent impleme horizontalPosition: 'right' })); } + + private observeResourceTypeChange(): void { + this.entityForm.get('resourceType').valueChanges.pipe( + startWith(ResourceType.JS_MODULE), + filter(() => this.isAdd), + takeUntil(this.destroy$) + ).subscribe((type: ResourceType) => this.onResourceTypeChange(type)); + } + + private onResourceTypeChange(type: ResourceType): void { + if (type === this.resourceType.LWM2M_MODEL) { + this.entityForm.get('title').disable({emitEvent: false}); + this.entityForm.patchValue({title: ''}, {emitEvent: false}); + } else { + this.entityForm.get('title').enable({emitEvent: false}); + } + this.entityForm.patchValue({ + data: null, + fileName: null + }, {emitEvent: false}); + } } From 1587fdc216f43a36f4167b8ee09af8341c1a0313 Mon Sep 17 00:00:00 2001 From: mpetrov Date: Tue, 23 Jul 2024 11:59:29 +0300 Subject: [PATCH 2/2] edited due to suggestions --- .../pages/admin/resource/resources-library.component.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ui-ngx/src/app/modules/home/pages/admin/resource/resources-library.component.ts b/ui-ngx/src/app/modules/home/pages/admin/resource/resources-library.component.ts index 049e53caf8..66aa0bbab6 100644 --- a/ui-ngx/src/app/modules/home/pages/admin/resource/resources-library.component.ts +++ b/ui-ngx/src/app/modules/home/pages/admin/resource/resources-library.component.ts @@ -29,7 +29,7 @@ import { ResourceTypeMIMETypes, ResourceTypeTranslationMap } from '@shared/models/resource.models'; -import { filter, startWith, takeUntil } from 'rxjs/operators'; +import { startWith, takeUntil } from 'rxjs/operators'; import { ActionNotificationShow } from '@core/notification/notification.actions'; import { isDefinedAndNotNull } from '@core/utils'; import { getCurrentAuthState } from '@core/auth/auth.selectors'; @@ -59,7 +59,9 @@ export class ResourcesLibraryComponent extends EntityComponent impleme ngOnInit() { super.ngOnInit(); - this.observeResourceTypeChange(); + if (this.isAdd) { + this.observeResourceTypeChange(); + } } ngOnDestroy() { @@ -142,7 +144,6 @@ export class ResourcesLibraryComponent extends EntityComponent impleme private observeResourceTypeChange(): void { this.entityForm.get('resourceType').valueChanges.pipe( startWith(ResourceType.JS_MODULE), - filter(() => this.isAdd), takeUntil(this.destroy$) ).subscribe((type: ResourceType) => this.onResourceTypeChange(type)); }