From 9216073b5bc15e134d669ec57d0ac65b0205b157 Mon Sep 17 00:00:00 2001 From: Mattia Vianelli Date: Wed, 11 Oct 2023 12:34:48 +0200 Subject: [PATCH 01/11] CST-12174 Coar form pages are now sized correctly, finishing up save button and alias for api call --- .../ldn-service-form-edit.component.html | 213 +++++++++----- .../ldn-service-form-edit.component.scss | 26 +- .../ldn-service-form-edit.component.ts | 52 +++- .../ldn-service-form.component.html | 276 ++++++++++-------- .../ldn-service-form.component.scss | 26 +- .../ldn-service-form.component.ts | 9 +- 6 files changed, 372 insertions(+), 230 deletions(-) diff --git a/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.html b/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.html index 6402e0b953..516dce4137 100644 --- a/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.html +++ b/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.html @@ -1,11 +1,11 @@ -
+
- +
- -
+ +
@@ -13,9 +13,9 @@
-
@@ -23,6 +23,7 @@  
+
-
+ +
+ + +
 
- -
- - -
+ +
+ + +
 
- -
- - -
+ +
+ + +
 
- -
- - - -
- - - -
- - - -
- - - -
- -
- -
- -
-
-
-
-
- - - -
- -
- -
- -
- + +
+
+
+
+ +
+
+ +
+
+
+
+ +
+ + + + +
+
+ +
+ + +
+ + + +
+ +
+ +
+
+
+
+ +
+ +
+
+
+
+ + {{ 'ldn-new-service.form.label.addPattern' | translate }} - {{ 'ldn-new-service.form.label.addPattern' | translate }}
 
- -
- - - -
- - - -
- -
- - - - - -
- -
- -
- -
- + +
+
+
+
+ +
+
+
+
+
+
- {{ 'ldn-new-service.form.label.addPattern' | translate }} +
+ + + + +
+
+ +
+
+ +
+ +
+ +
+
+
+
+ +
+ +
+
+
+ +
+ + {{ 'ldn-new-service.form.label.addPattern' | translate }}
 
+ + diff --git a/src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.scss b/src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.scss index 92ac744aed..eb6c97c90a 100644 --- a/src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.scss +++ b/src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.scss @@ -1,14 +1,9 @@ form { - display: flex; - flex-direction: column; - align-items: flex-start; max-width: 800px; font-size: 14px; - margin-left: 300px; + margin-left: 100px; + position: relative; - & > * { - width: 100%; - } } input[type="text"], @@ -105,6 +100,23 @@ textarea { cursor: pointer; } +.label-box{ + margin-left:11px; +} + +.label-box-2{ + margin-left:14px; +} + +.label-box-3{ + margin-left:5px; +} + +form button.btn.btn-primary[type="submit"] { + position: absolute; + bottom: 0px; + right: -10px; +} diff --git a/src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts b/src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts index 608a7ada23..b5a1ce8cf2 100644 --- a/src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts +++ b/src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts @@ -130,19 +130,20 @@ export class LdnServiceFormComponent implements OnInit { notifyServiceInboundPatternsArray.push(this.createInboundPatternFormGroup()); } - removeInboundPattern(patternGroup: FormGroup) { + removeInboundPattern(index: number) { const notifyServiceInboundPatternsArray = this.formModel.get('notifyServiceInboundPatterns') as FormArray; - notifyServiceInboundPatternsArray.removeAt(notifyServiceInboundPatternsArray.controls.indexOf(patternGroup)); + notifyServiceInboundPatternsArray.removeAt(index); } + addOutboundPattern() { const notifyServiceOutboundPatternsArray = this.formModel.get('notifyServiceOutboundPatterns') as FormArray; notifyServiceOutboundPatternsArray.push(this.createOutboundPatternFormGroup()); } - removeOutboundPattern(patternGroup: FormGroup) { + removeOutboundPattern(index: number) { const notifyServiceOutboundPatternsArray = this.formModel.get('notifyServiceOutboundPatterns') as FormArray; - notifyServiceOutboundPatternsArray.removeAt(notifyServiceOutboundPatternsArray.controls.indexOf(patternGroup)); + notifyServiceOutboundPatternsArray.removeAt(index); } private createOutboundPatternFormGroup(): FormGroup { From 8de0e76b72e39f3ce5a34eaadaadfc72e7fbf0ba Mon Sep 17 00:00:00 2001 From: Mattia Vianelli Date: Wed, 11 Oct 2023 15:35:28 +0200 Subject: [PATCH 02/11] CST-12174 Ldn services are now retrieved with the remotadata object --- .../ldn-services-data.service.ts | 52 +++++--- .../ldn-services-directory.component.html | 2 +- .../ldn-services-directory.component.ts | 25 +++- .../ldn-service.resource-type.ts | 2 +- .../ldn-services-model/ldn-services.model.ts | 3 + .../ldn-service-bulk-delete.service.ts | 117 ------------------ src/app/core/core.module.ts | 5 +- 7 files changed, 66 insertions(+), 140 deletions(-) delete mode 100644 src/app/admin/admin-ldn-services/ldn-services-services/ldn-service-bulk-delete.service.ts diff --git a/src/app/admin/admin-ldn-services/ldn-services-data/ldn-services-data.service.ts b/src/app/admin/admin-ldn-services/ldn-services-data/ldn-services-data.service.ts index 43755adb3c..09670cc064 100644 --- a/src/app/admin/admin-ldn-services/ldn-services-data/ldn-services-data.service.ts +++ b/src/app/admin/admin-ldn-services/ldn-services-data/ldn-services-data.service.ts @@ -24,25 +24,45 @@ import { hasValue } from '../../../shared/empty.util'; import { LdnService } from '../ldn-services-model/ldn-services.model'; import { LdnServiceConstraint } from '../ldn-services-model/ldn-service-constraint.model'; + import { PatchData, PatchDataImpl } from '../../../core/data/base/patch-data'; + import { ChangeAnalyzer } from '../../../core/data/change-analyzer'; +import { Operation } from 'fast-json-patch'; +import { RestRequestMethod } from 'src/app/core/data/rest-request-method'; -@Injectable() -@dataService(LDN_SERVICE) -export class LdnServicesService extends IdentifiableDataService implements FindAllData, DeleteData { - private findAllData: FindAllDataImpl; // Corrected the type - private deleteData: DeleteDataImpl; // Corrected the type + @Injectable() + @dataService(LDN_SERVICE) + export class LdnServicesService extends IdentifiableDataService implements FindAllData, DeleteData, PatchData { + private findAllData: FindAllDataImpl; + private deleteData: DeleteDataImpl; + private patchData: PatchDataImpl; + private comparator: ChangeAnalyzer; - constructor( - protected requestService: RequestService, - protected rdbService: RemoteDataBuildService, - protected objectCache: ObjectCacheService, - protected halService: HALEndpointService, - protected notificationsService: NotificationsService, - ) { - super('ldnservices', requestService, rdbService, objectCache, halService); + constructor( + protected requestService: RequestService, + protected rdbService: RemoteDataBuildService, + protected objectCache: ObjectCacheService, + protected halService: HALEndpointService, + protected notificationsService: NotificationsService, + ) { + super('ldnservices', requestService, rdbService, objectCache, halService); - this.findAllData = new FindAllDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, this.responseMsToLive); - this.deleteData = new DeleteDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, notificationsService, this.responseMsToLive, this.constructIdEndpoint); - } + this.findAllData = new FindAllDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, this.responseMsToLive); + this.deleteData = new DeleteDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, notificationsService, this.responseMsToLive, this.constructIdEndpoint); + this.patchData = new PatchDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, this.comparator, this.responseMsToLive, this.constructIdEndpoint); + } + + patch(object: LdnService, operations: Operation[]): Observable> { + throw new Error('Method not implemented.'); + } + update(object: LdnService): Observable> { + throw new Error('Method not implemented.'); + } + commitUpdates(method?: RestRequestMethod): void { + throw new Error('Method not implemented.'); + } + createPatchFromCache(object: LdnService): Observable { + throw new Error('Method not implemented.'); + } findAll(options?: FindListOptions, useCachedVersionIfAvailable?: boolean, reRequestOnStale?: boolean, ...linksToFollow: FollowLinkConfig[]): Observable>> { return this.findAllData.findAll(options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow); diff --git a/src/app/admin/admin-ldn-services/ldn-services-directory/ldn-services-directory.component.html b/src/app/admin/admin-ldn-services/ldn-services-directory/ldn-services-directory.component.html index e3795d6e96..4c9b3c3f04 100644 --- a/src/app/admin/admin-ldn-services/ldn-services-directory/ldn-services-directory.component.html +++ b/src/app/admin/admin-ldn-services/ldn-services-directory/ldn-services-directory.component.html @@ -23,7 +23,7 @@ - + {{ ldnService.name }} {{ ldnService.description }} diff --git a/src/app/admin/admin-ldn-services/ldn-services-directory/ldn-services-directory.component.ts b/src/app/admin/admin-ldn-services/ldn-services-directory/ldn-services-directory.component.ts index 9d19ad56c7..345f5182aa 100644 --- a/src/app/admin/admin-ldn-services/ldn-services-directory/ldn-services-directory.component.ts +++ b/src/app/admin/admin-ldn-services/ldn-services-directory/ldn-services-directory.component.ts @@ -12,6 +12,7 @@ import { PaginationService } from 'src/app/core/pagination/pagination.service'; import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; import { hasValue } from '../../../shared/empty.util'; import { HttpClient } from '@angular/common/http'; +import { getFirstCompletedRemoteData } from "../../../core/shared/operators"; @Component({ selector: 'ds-ldn-services-directory', templateUrl: './ldn-services-directory.component.html', @@ -33,8 +34,12 @@ export class LdnServicesOverviewComponent implements OnInit, OnDestroy { isProcessingSub: Subscription; private modalRef: any; + + + constructor( protected processLdnService: LdnServicesService, + private ldnServicesService: LdnServicesService, protected paginationService: PaginationService, protected modalService: NgbModal, public ldnDirectoryService: LdnDirectoryService, @@ -44,9 +49,9 @@ export class LdnServicesOverviewComponent implements OnInit, OnDestroy { } ngOnInit(): void { - /*this.ldnDirectoryService.listLdnServices();*/ - this.findAllServices(); + this.setLdnServices2(); this.setLdnServices(); + /*this.ldnDirectoryService.listLdnServices();*/ /*this.ldnServicesRD$.subscribe(data => { console.log('searchByLdnUrl()', data); });*/ @@ -62,10 +67,22 @@ export class LdnServicesOverviewComponent implements OnInit, OnDestroy { } setLdnServices() { + this.ldnServicesService.findAll().pipe(getFirstCompletedRemoteData()).subscribe((remoteData) => { + + if (remoteData.hasSucceeded) { + const ldnservices = remoteData.payload.page; + console.log(ldnservices); + } else { + console.error('Error fetching LDN services:', remoteData.errorMessage); + } + }); + } + + setLdnServices2() { this.ldnServicesRD$ = this.paginationService.getFindListOptions(this.pageConfig.id, this.config).pipe( - switchMap((config) => this.processLdnService.findAll(config, true, false)) + switchMap((config) => this.ldnServicesService.findAll(config, true, false)) + ); - console.log(); } ngOnDestroy(): void { diff --git a/src/app/admin/admin-ldn-services/ldn-services-model/ldn-service.resource-type.ts b/src/app/admin/admin-ldn-services/ldn-services-model/ldn-service.resource-type.ts index 937fac255d..e5684e8c34 100644 --- a/src/app/admin/admin-ldn-services/ldn-services-model/ldn-service.resource-type.ts +++ b/src/app/admin/admin-ldn-services/ldn-services-model/ldn-service.resource-type.ts @@ -6,4 +6,4 @@ */ import { ResourceType } from '../../../core/shared/resource-type'; -export const LDN_SERVICE = new ResourceType('ldnservices'); +export const LDN_SERVICE = new ResourceType('ldnservice'); diff --git a/src/app/admin/admin-ldn-services/ldn-services-model/ldn-services.model.ts b/src/app/admin/admin-ldn-services/ldn-services-model/ldn-services.model.ts index bdb8bc5123..ec28193a93 100644 --- a/src/app/admin/admin-ldn-services/ldn-services-model/ldn-services.model.ts +++ b/src/app/admin/admin-ldn-services/ldn-services-model/ldn-services.model.ts @@ -26,6 +26,9 @@ export class LdnService extends CacheableObject { @autoserialize url: string; + @autoserialize + enabled: boolean; + @autoserialize ldnUrl: string; diff --git a/src/app/admin/admin-ldn-services/ldn-services-services/ldn-service-bulk-delete.service.ts b/src/app/admin/admin-ldn-services/ldn-services-services/ldn-service-bulk-delete.service.ts deleted file mode 100644 index 6805cd7f93..0000000000 --- a/src/app/admin/admin-ldn-services/ldn-services-services/ldn-service-bulk-delete.service.ts +++ /dev/null @@ -1,117 +0,0 @@ -import { Injectable } from '@angular/core'; -import { BehaviorSubject, count, from } from 'rxjs'; -import { LdnServicesService } from '../ldn-services-data/ldn-services-data.service'; -import { NotificationsService } from '../../../shared/notifications/notifications.service'; -import { TranslateService } from '@ngx-translate/core'; -import { isNotEmpty } from '../../../shared/empty.util'; -import { concatMap, filter, tap } from 'rxjs/operators'; -import { getFirstCompletedRemoteData } from '../../../core/shared/operators'; -import { RemoteData } from '../../../core/data/remote-data'; -import { LdnService } from '../ldn-services-model/ldn-services.model'; -@Injectable({ - providedIn: 'root' -}) -/** - * Service to facilitate removing ldn services in bulk. - */ -export class LdnServicesBulkDeleteService { - - /** - * Array to track the services to be deleted - */ - ldnServicesToDelete: string[] = []; - - /** - * Behavior subject to track whether the delete is processing - * @protected - */ - protected isProcessingBehaviorSubject: BehaviorSubject = new BehaviorSubject(false); - - constructor( - protected processLdnService: LdnServicesService, - protected notificationsService: NotificationsService, - protected translateService: TranslateService - ) { - } - - /** - * Add or remove a process id to/from the list - * If the id is already present it will be removed, otherwise it will be added. - * - * @param notifyServiceName - The process id to add or remove - */ - toggleDelete(notifyServiceName: string) { - if (this.isToBeDeleted(notifyServiceName)) { - this.ldnServicesToDelete.splice(this.ldnServicesToDelete.indexOf(notifyServiceName), 1); - } else { - this.ldnServicesToDelete.push(notifyServiceName); - } - } - - /** - * Checks if the provided service id is present in the to be deleted list - * @param notifyServiceName - */ - isToBeDeleted(notifyServiceName: string) { - return this.ldnServicesToDelete.includes(notifyServiceName); - } - - /** - * Clear the list of services to be deleted - */ - clearAllServices() { - this.ldnServicesToDelete.splice(0); - } - - /** - * Get the amount of processes selected for deletion - */ - getAmountOfSelectedServices() { - return this.ldnServicesToDelete.length; - } - - /** - * Returns a behavior subject to indicate whether the bulk delete is processing - */ - isProcessing$() { - return this.isProcessingBehaviorSubject; - } - - /** - * Returns whether there currently are values selected for deletion - */ - hasSelected(): boolean { - return isNotEmpty(this.ldnServicesToDelete); - } - - /** - * Delete all selected processes one by one - * When the deletion for a process fails, an error notification will be shown with the process id, - * but it will continue deleting the other processes. - * At the end it will show a notification stating the amount of successful deletes - * The successfully deleted processes will be removed from the list of selected values, the failed ones will be retained. - */ - deleteSelectedLdnServices() { - this.isProcessingBehaviorSubject.next(true); - - from([...this.ldnServicesToDelete]).pipe( - concatMap((notifyServiceName) => { - return this.processLdnService.delete(notifyServiceName).pipe( - getFirstCompletedRemoteData(), - tap((rd: RemoteData) => { - if (rd.hasFailed) { - this.notificationsService.error(this.translateService.get('process.bulk.delete.error.head'), this.translateService.get('process.bulk.delete.error.body', {processId: notifyServiceName})); - } else { - this.toggleDelete(notifyServiceName); - } - }) - ); - }), - filter((rd: RemoteData) => rd.hasSucceeded), - count(), - ).subscribe((value) => { - this.notificationsService.success(this.translateService.get('process.bulk.delete.success', {count: value})); - this.isProcessingBehaviorSubject.next(false); - }); - } -} diff --git a/src/app/core/core.module.ts b/src/app/core/core.module.ts index e1b1fc8811..1990bde77e 100644 --- a/src/app/core/core.module.ts +++ b/src/app/core/core.module.ts @@ -188,6 +188,7 @@ import { BulkAccessConditionOptions } from './config/models/bulk-access-conditio import { SuggestionTarget } from './suggestion-notifications/reciter-suggestions/models/suggestion-target.model'; import { SuggestionSource } from './suggestion-notifications/reciter-suggestions/models/suggestion-source.model'; import { LdnServicesService } from '../admin/admin-ldn-services/ldn-services-data/ldn-services-data.service'; +import { LdnService } from '../admin/admin-ldn-services/ldn-services-model/ldn-services.model'; /** * When not in production, endpoint responses can be mocked for testing purposes @@ -392,7 +393,9 @@ export const models = ItemRequest, BulkAccessConditionOptions, SuggestionTarget, - SuggestionSource + SuggestionSource, + LdnService + ]; @NgModule({ From 1c376b296413434a23d256268346741b071b082c Mon Sep 17 00:00:00 2001 From: Mattia Vianelli Date: Tue, 17 Oct 2023 16:28:36 +0200 Subject: [PATCH 03/11] CST-12174 Implemented data-service for the api calls --- .../admin-ldn-services.module.ts | 2 + .../ldn-service-form-edit.component.html | 6 +- .../ldn-service-form-edit.component.ts | 669 +++++++++--------- .../ldn-service-form.component.html | 2 +- .../ldn-service-form.component.ts | 313 ++++---- .../ldn-services-data.service.ts | 104 +-- .../ldn-services-directory.component.html | 6 +- .../ldn-services-directory.component.ts | 255 +++---- .../ldn-services-guard.service.ts | 2 +- .../ldn-service-constraint.model.ts | 26 - .../ldn-service-patterns.model.ts | 13 + .../ldn-service.constrain.model.ts | 3 + .../ldn-service.resource-type.ts | 1 + .../ldn-services-model/ldn-services.model.ts | 21 +- src/app/admin/admin-routing-paths.ts | 8 +- 15 files changed, 704 insertions(+), 727 deletions(-) delete mode 100644 src/app/admin/admin-ldn-services/ldn-services-model/ldn-service-constraint.model.ts create mode 100644 src/app/admin/admin-ldn-services/ldn-services-model/ldn-service-patterns.model.ts create mode 100644 src/app/admin/admin-ldn-services/ldn-services-model/ldn-service.constrain.model.ts diff --git a/src/app/admin/admin-ldn-services/admin-ldn-services.module.ts b/src/app/admin/admin-ldn-services/admin-ldn-services.module.ts index 1fd67d53b9..c3642ea88d 100644 --- a/src/app/admin/admin-ldn-services/admin-ldn-services.module.ts +++ b/src/app/admin/admin-ldn-services/admin-ldn-services.module.ts @@ -6,6 +6,7 @@ import { SharedModule } from '../../shared/shared.module'; import { LdnServiceNewComponent } from './ldn-service-new/ldn-service-new.component'; import { LdnServiceFormComponent } from './ldn-service-form/ldn-service-form.component'; import { LdnServiceFormEditComponent } from './ldn-service-form-edit/ldn-service-form-edit.component'; +import { FormsModule } from '@angular/forms'; @@ -14,6 +15,7 @@ import { LdnServiceFormEditComponent } from './ldn-service-form-edit/ldn-service CommonModule, SharedModule, AdminLdnServicesRoutingModule, + FormsModule ], declarations: [ LdnServicesOverviewComponent, diff --git a/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.html b/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.html index 516dce4137..988e0a53a1 100644 --- a/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.html +++ b/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.html @@ -112,7 +112,7 @@
-
@@ -176,7 +176,7 @@
-
@@ -215,7 +215,7 @@ {{ 'service.overview.delete.body' | translate }}
- -
diff --git a/src/app/admin/admin-ldn-services/ldn-services-directory/ldn-services-directory.component.ts b/src/app/admin/admin-ldn-services/ldn-services-directory/ldn-services-directory.component.ts index 345f5182aa..933dff8901 100644 --- a/src/app/admin/admin-ldn-services/ldn-services-directory/ldn-services-directory.component.ts +++ b/src/app/admin/admin-ldn-services/ldn-services-directory/ldn-services-directory.component.ts @@ -1,5 +1,4 @@ -import { ChangeDetectorRef, Component, OnDestroy, OnInit, TemplateRef, ViewChild } from '@angular/core'; -import { LdnDirectoryService } from '../ldn-services-services/ldn-directory.service'; +import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnDestroy, OnInit, TemplateRef, ViewChild } from '@angular/core'; import { Observable, Subscription } from 'rxjs'; import { RemoteData } from '../../../core/data/remote-data'; import { PaginatedList } from '../../../core/data/paginated-list.model'; @@ -11,170 +10,122 @@ import { LdnServicesService } from 'src/app/admin/admin-ldn-services/ldn-service import { PaginationService } from 'src/app/core/pagination/pagination.service'; import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; import { hasValue } from '../../../shared/empty.util'; -import { HttpClient } from '@angular/common/http'; -import { getFirstCompletedRemoteData } from "../../../core/shared/operators"; +import { Operation } from 'fast-json-patch'; +import { getFirstCompletedRemoteData } from '../../../core/shared/operators'; +import { NotificationsService } from '../../../shared/notifications/notifications.service'; +import { TranslateService } from '@ngx-translate/core'; +import { Router } from '@angular/router'; + @Component({ - selector: 'ds-ldn-services-directory', - templateUrl: './ldn-services-directory.component.html', - styleUrls: ['./ldn-services-directory.component.scss'], + selector: 'ds-ldn-services-directory', + templateUrl: './ldn-services-directory.component.html', + styleUrls: ['./ldn-services-directory.component.scss'], + changeDetection: ChangeDetectionStrategy.Default }) export class LdnServicesOverviewComponent implements OnInit, OnDestroy { - selectedServiceId: number | null = null; - servicesData: any[] = []; - @ViewChild('deleteModal', {static: true}) deleteModal: TemplateRef; - ldnServicesRD$: Observable>>; - config: FindListOptions = Object.assign(new FindListOptions(), { - elementsPerPage: 20 + selectedServiceId: string | number | null = null; + servicesData: any[] = []; + @ViewChild('deleteModal', {static: true}) deleteModal: TemplateRef; + ldnServicesRD$: Observable>>; + config: FindListOptions = Object.assign(new FindListOptions(), { + elementsPerPage: 20 + }); + pageConfig: PaginationComponentOptions = Object.assign(new PaginationComponentOptions(), { + id: 'po', + pageSize: 20 + }); + isProcessingSub: Subscription; + private modalRef: any; + + constructor( + protected ldnServicesService: LdnServicesService, + protected paginationService: PaginationService, + protected modalService: NgbModal, + private cdRef: ChangeDetectorRef, + private notificationService: NotificationsService, + private translateService: TranslateService, + private router: Router, + ) { + } + + ngOnInit(): void { + this.setLdnServices(); + } + + setLdnServices() { + this.ldnServicesRD$ = this.paginationService.getFindListOptions(this.pageConfig.id, this.config).pipe( + switchMap((config) => this.ldnServicesService.findAll(config, true, false).pipe( + getFirstCompletedRemoteData() + )) + ); + + this.ldnServicesRD$.subscribe((rd: RemoteData>) => { + console.log(rd); + if (rd.hasSucceeded) { + this.notificationService.success(this.translateService.get('notification.loaded.success')); + } else { + this.notificationService.error(this.translateService.get('notification.loaded.failure')); + } }); - pageConfig: PaginationComponentOptions = Object.assign(new PaginationComponentOptions(), { - id: 'po', - pageSize: 20 - }); - isProcessingSub: Subscription; - private modalRef: any; + } - - - - constructor( - protected processLdnService: LdnServicesService, - private ldnServicesService: LdnServicesService, - protected paginationService: PaginationService, - protected modalService: NgbModal, - public ldnDirectoryService: LdnDirectoryService, - private http: HttpClient, - private cdRef: ChangeDetectorRef - ) { + ngOnDestroy(): void { + this.paginationService.clearPagination(this.pageConfig.id); + if (hasValue(this.isProcessingSub)) { + this.isProcessingSub.unsubscribe(); } + } - ngOnInit(): void { - this.setLdnServices2(); - this.setLdnServices(); - /*this.ldnDirectoryService.listLdnServices();*/ - /*this.ldnServicesRD$.subscribe(data => { - console.log('searchByLdnUrl()', data); - });*/ + openDeleteModal(content) { + this.modalRef = this.modalService.open(content); + } - /*this.ldnServicesRD$.pipe( - tap(data => { - console.log('ldnServicesRD$ data:', data); - }) - ).subscribe(() => { - this.searchByLdnUrl(); - });*/ + closeModal() { + this.modalRef.close(); + this.cdRef.detectChanges(); + } - } + selectServiceToDelete(serviceId: number) { + this.selectedServiceId = serviceId; + this.openDeleteModal(this.deleteModal); + } - setLdnServices() { - this.ldnServicesService.findAll().pipe(getFirstCompletedRemoteData()).subscribe((remoteData) => { - - if (remoteData.hasSucceeded) { - const ldnservices = remoteData.payload.page; - console.log(ldnservices); - } else { - console.error('Error fetching LDN services:', remoteData.errorMessage); - } - }); - } - - setLdnServices2() { - this.ldnServicesRD$ = this.paginationService.getFindListOptions(this.pageConfig.id, this.config).pipe( - switchMap((config) => this.ldnServicesService.findAll(config, true, false)) - - ); - } - - ngOnDestroy(): void { - this.paginationService.clearPagination(this.pageConfig.id); - if (hasValue(this.isProcessingSub)) { - this.isProcessingSub.unsubscribe(); + deleteSelected(serviceId: string, ldnServicesService: LdnServicesService): void { + if (this.selectedServiceId !== null) { + ldnServicesService.delete(serviceId).pipe(getFirstCompletedRemoteData()).subscribe((rd: RemoteData) => { + if (rd.hasSucceeded) { + this.servicesData = this.servicesData.filter(service => service.id !== serviceId); + this.cdRef.detectChanges(); + this.closeModal(); + this.notificationService.success(this.translateService.get('notification.created.success')); + } else { + this.notificationService.error(this.translateService.get('notification.created.failure')); + this.cdRef.detectChanges(); } + }); } - - openDeleteModal(content) { - this.modalRef = this.modalService.open(content); - } - - closeModal() { - this.modalRef.close(); - this.cdRef.detectChanges(); - } + } - findAllServices(): void { - this.retrieveAll().subscribe( - (response) => { - this.servicesData = response._embedded.ldnservices; - console.log('ServicesData =', this.servicesData); - this.cdRef.detectChanges(); - }, - (error) => { - console.error('Error:', error); - } - ); - } - - retrieveAll(): Observable { - const url = 'http://localhost:8080/server/api/ldn/ldnservices'; - return this.http.get(url); - } - - - - - deleteSelected() { - if (this.selectedServiceId !== null) { - const deleteUrl = `http://localhost:8080/server/api/ldn/ldnservices/${this.selectedServiceId}`; - this.http.delete(deleteUrl).subscribe( - () => { - this.closeModal(); - this.findAllServices(); - }, - (error) => { - console.error('Error deleting service:', error); - } - ); + toggleStatus(ldnService: any, ldnServicesService: LdnServicesService): void { + const newStatus = !ldnService.enabled; + let status = ldnService.enabled; + const patchOperation: Operation = { + op: 'replace', + path: '/enabled', + value: newStatus, + }; + ldnServicesService.patch(ldnService, [patchOperation]).pipe(getFirstCompletedRemoteData()).subscribe( + () => { + if (status !== newStatus) { + this.notificationService.success(this.translateService.get('ldn-enable-service.notification.success.title'), + this.translateService.get('ldn-enable-service.notification.success.content')); + } else { + this.notificationService.error(this.translateService.get('ldn-enable-service.notification.error.title'), + this.translateService.get('ldn-enable-service.notification.error.content')); + } } - } - - selectServiceToDelete(serviceId: number) { - this.selectedServiceId = serviceId; - this.openDeleteModal(this.deleteModal); - } - - toggleStatus(ldnService: any): void { - const newStatus = !ldnService.enabled; - - const apiUrl = `http://localhost:8080/server/api/ldn/ldnservices/${ldnService.id}`; - const patchOperation = { - op: 'replace', - path: '/enabled', - value: newStatus, - }; - - this.http.patch(apiUrl, [patchOperation]).subscribe( - () => { - console.log('Status updated successfully.'); - ldnService.enabled = newStatus; - this.cdRef.detectChanges(); - }, - (error) => { - console.error('Error updating status:', error); - } - ); - } - - fetchServiceData(serviceId: string): void { - const apiUrl = `http://localhost:8080/server/api/ldn/ldnservices/${serviceId}`; - - this.http.get(apiUrl).subscribe( - (data: any) => { - console.log(data); - }, - (error) => { - console.error('Error fetching service data:', error); - } - ); - } + ); + } } diff --git a/src/app/admin/admin-ldn-services/ldn-services-guard/ldn-services-guard.service.ts b/src/app/admin/admin-ldn-services/ldn-services-guard/ldn-services-guard.service.ts index 85235b4370..21123ede4a 100644 --- a/src/app/admin/admin-ldn-services/ldn-services-guard/ldn-services-guard.service.ts +++ b/src/app/admin/admin-ldn-services/ldn-services-guard/ldn-services-guard.service.ts @@ -1,7 +1,7 @@ import { Injectable } from '@angular/core'; import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree } from '@angular/router'; import { Observable } from 'rxjs'; -import { map } from 'rxjs/operators'; + @Injectable({ providedIn: 'root' diff --git a/src/app/admin/admin-ldn-services/ldn-services-model/ldn-service-constraint.model.ts b/src/app/admin/admin-ldn-services/ldn-services-model/ldn-service-constraint.model.ts deleted file mode 100644 index 704a3e7d8c..0000000000 --- a/src/app/admin/admin-ldn-services/ldn-services-model/ldn-service-constraint.model.ts +++ /dev/null @@ -1,26 +0,0 @@ - -/** - * A cosntrain that can be used when running a service - */ -export class LdnServiceConstraint { - /** - * The name of the constrain - */ - name: string; - - /** - * The value of the constrain - */ - value: string; -} - -export const EndorsmentConstrain = [ - { - name: 'Type 1 Item', - value: 'Type1' - }, - { - name: 'Type 2 Item', - value: 'Type2' - }, -]; diff --git a/src/app/admin/admin-ldn-services/ldn-services-model/ldn-service-patterns.model.ts b/src/app/admin/admin-ldn-services/ldn-services-model/ldn-service-patterns.model.ts new file mode 100644 index 0000000000..1e67ccfeee --- /dev/null +++ b/src/app/admin/admin-ldn-services/ldn-services-model/ldn-service-patterns.model.ts @@ -0,0 +1,13 @@ +import { autoserialize } from 'cerialize'; + +/** + * notify service patterns + */ +export class NotifyServicePattern { + @autoserialize + pattern: string; + @autoserialize + constraint: string; + @autoserialize + automatic: string; +} diff --git a/src/app/admin/admin-ldn-services/ldn-services-model/ldn-service.constrain.model.ts b/src/app/admin/admin-ldn-services/ldn-services-model/ldn-service.constrain.model.ts new file mode 100644 index 0000000000..6eda194443 --- /dev/null +++ b/src/app/admin/admin-ldn-services/ldn-services-model/ldn-service.constrain.model.ts @@ -0,0 +1,3 @@ +export class ldnServiceConstrain { + void: any; +} diff --git a/src/app/admin/admin-ldn-services/ldn-services-model/ldn-service.resource-type.ts b/src/app/admin/admin-ldn-services/ldn-services-model/ldn-service.resource-type.ts index e5684e8c34..859ecb739e 100644 --- a/src/app/admin/admin-ldn-services/ldn-services-model/ldn-service.resource-type.ts +++ b/src/app/admin/admin-ldn-services/ldn-services-model/ldn-service.resource-type.ts @@ -7,3 +7,4 @@ import { ResourceType } from '../../../core/shared/resource-type'; export const LDN_SERVICE = new ResourceType('ldnservice'); +export const LDN_SERVICE_CONSTRAINT = new ResourceType('ldnservice'); diff --git a/src/app/admin/admin-ldn-services/ldn-services-model/ldn-services.model.ts b/src/app/admin/admin-ldn-services/ldn-services-model/ldn-services.model.ts index ec28193a93..82731b3cb1 100644 --- a/src/app/admin/admin-ldn-services/ldn-services-model/ldn-services.model.ts +++ b/src/app/admin/admin-ldn-services/ldn-services-model/ldn-services.model.ts @@ -1,12 +1,16 @@ import { ResourceType } from '../../../core/shared/resource-type'; import { CacheableObject } from '../../../core/cache/cacheable-object.model'; -import { autoserialize, deserialize } from 'cerialize'; +import { autoserialize, deserialize, deserializeAs, inheritSerialization } from 'cerialize'; import { LDN_SERVICE } from './ldn-service.resource-type'; import { excludeFromEquals } from '../../../core/utilities/equals.decorators'; import { typedObject } from '../../../core/cache/builders/build-decorators'; +import { NotifyServicePattern } from './ldn-service-patterns.model'; + + @typedObject +@inheritSerialization(CacheableObject) export class LdnService extends CacheableObject { static type = LDN_SERVICE; @@ -15,7 +19,10 @@ export class LdnService extends CacheableObject { type: ResourceType; @autoserialize - id?: number; + id: number; + + @deserializeAs('id') + uuid: string; @autoserialize name: string; @@ -49,13 +56,3 @@ export class LdnService extends CacheableObject { return this._links.self.href; } } - - -class NotifyServicePattern { - @autoserialize - pattern: string; - @autoserialize - constraint?: string; - @autoserialize - automatic?: boolean; -} diff --git a/src/app/admin/admin-routing-paths.ts b/src/app/admin/admin-routing-paths.ts index df0459ff53..511680bfd8 100644 --- a/src/app/admin/admin-routing-paths.ts +++ b/src/app/admin/admin-routing-paths.ts @@ -4,6 +4,8 @@ import { getAdminModuleRoute } from '../app-routing-paths'; export const REGISTRIES_MODULE_PATH = 'registries'; export const NOTIFICATIONS_MODULE_PATH = 'notifications'; +export const LDN_PATH = 'ldn'; + export function getRegistriesModuleRoute() { return new URLCombiner(getAdminModuleRoute(), REGISTRIES_MODULE_PATH).toString(); } @@ -12,4 +14,8 @@ export function getNotificationsModuleRoute() { return new URLCombiner(getAdminModuleRoute(), NOTIFICATIONS_MODULE_PATH).toString(); } -export const LDN_PATH = 'ldn'; +export function getLdnServicesModuleRoute() { + return new URLCombiner(getAdminModuleRoute(), LDN_PATH).toString(); +} + + From ba0b110647e23a736341c1d3609c9ed9c0340e19 Mon Sep 17 00:00:00 2001 From: Mattia Vianelli Date: Tue, 17 Oct 2023 17:46:47 +0200 Subject: [PATCH 04/11] CST-12174 added resetForm and leave edit for edit-form and overview page --- .../ldn-service-form-edit.component.html | 34 +++++++++++++++++++ .../ldn-service-form-edit.component.ts | 10 ++++++ 2 files changed, 44 insertions(+) diff --git a/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.html b/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.html index 988e0a53a1..9f5515960b 100644 --- a/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.html +++ b/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.html @@ -194,6 +194,11 @@
+
+ +
@@ -224,3 +229,32 @@ + + + +
+ + + + +
+
diff --git a/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.ts b/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.ts index bd184ea174..4a5187a5d7 100644 --- a/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.ts +++ b/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.ts @@ -29,6 +29,7 @@ import { getFirstCompletedRemoteData } from '../../../core/shared/operators'; export class LdnServiceFormEditComponent implements OnInit { formModel: FormGroup; @ViewChild('confirmModal', {static: true}) confirmModal: TemplateRef; + @ViewChild('resetFormModal', {static: true}) resetFormModal: TemplateRef; public inboundPatterns: object[] = notifyPatterns; public outboundPatterns: object[] = notifyPatterns; @@ -286,6 +287,10 @@ export class LdnServiceFormEditComponent implements OnInit { this.modalRef = this.modalService.open(content); } + openResetFormModal(content) { + this.modalRef = this.modalService.open(content); + } + patchService() { const patchOperations = this.generatePatchOperations(); @@ -347,6 +352,11 @@ export class LdnServiceFormEditComponent implements OnInit { this.router.navigateByUrl('admin/ldn/services'); } + resetFormAndLeave() { + this.sendBack(); + this.closeModal(); + } + private createOutboundPatternFormGroup(): FormGroup { return this.formBuilder.group({ pattern: '', From 2eb71604eeab4906de39da3d4b744b03bd04e28e Mon Sep 17 00:00:00 2001 From: Mattia Vianelli Date: Wed, 18 Oct 2023 18:46:06 +0200 Subject: [PATCH 05/11] CST-12174 created new remotadata service for itemfilters, pages are updated in real time when editing/creating/deleting services related stuff, added modals to confirm/reset --- .../admin-ldn-services.module.ts | 4 +- .../ldn-service-form-edit.component.html | 21 +++-- .../ldn-service-form-edit.component.ts | 53 ++++++++--- .../ldn-service-form.component.html | 76 ++++++++++++++-- .../ldn-service-form.component.ts | 91 ++++++++++++++----- .../ldn-itemfilters-data.service.ts | 48 ++++++++++ .../ldn-services-data.service.ts | 3 + .../ldn-services-directory.component.ts | 15 ++- .../ldn-service-itemfilters.ts | 32 +++++++ .../ldn-service.resource-type.ts | 4 +- .../ldn-services-model/ldn-services.model.ts | 2 +- .../ldn-directory.service.ts | 47 ++-------- src/app/core/core.module.ts | 6 +- 13 files changed, 304 insertions(+), 98 deletions(-) create mode 100644 src/app/admin/admin-ldn-services/ldn-services-data/ldn-itemfilters-data.service.ts create mode 100644 src/app/admin/admin-ldn-services/ldn-services-model/ldn-service-itemfilters.ts diff --git a/src/app/admin/admin-ldn-services/admin-ldn-services.module.ts b/src/app/admin/admin-ldn-services/admin-ldn-services.module.ts index c3642ea88d..c82250fcec 100644 --- a/src/app/admin/admin-ldn-services/admin-ldn-services.module.ts +++ b/src/app/admin/admin-ldn-services/admin-ldn-services.module.ts @@ -7,6 +7,7 @@ import { LdnServiceNewComponent } from './ldn-service-new/ldn-service-new.compon import { LdnServiceFormComponent } from './ldn-service-form/ldn-service-form.component'; import { LdnServiceFormEditComponent } from './ldn-service-form-edit/ldn-service-form-edit.component'; import { FormsModule } from '@angular/forms'; +import { LdnItemfiltersService } from './ldn-services-data/ldn-itemfilters-data.service'; @@ -22,6 +23,7 @@ import { FormsModule } from '@angular/forms'; LdnServiceNewComponent, LdnServiceFormComponent, LdnServiceFormEditComponent, - ] + ], + providers: [LdnItemfiltersService] }) export class AdminLdnServicesModule { } diff --git a/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.html b/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.html index 9f5515960b..5d33d21505 100644 --- a/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.html +++ b/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.html @@ -1,4 +1,4 @@ -
+
@@ -95,8 +95,8 @@
@@ -159,12 +159,13 @@
- + + +
@@ -249,7 +250,7 @@ {{ 'service.overview.reset-form.body' | translate }}
-
@@ -149,12 +149,13 @@
- - + +
@@ -182,6 +183,69 @@  
+
+ +
+ + +
+ + + + +
+
+ + + +
+ + + + +
+
+ diff --git a/src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts b/src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts index bfee1467d7..25b7ab70d5 100644 --- a/src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts +++ b/src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts @@ -1,4 +1,13 @@ -import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; +import { + ChangeDetectorRef, + Component, + EventEmitter, + Input, + OnInit, + Output, + TemplateRef, + ViewChild +} from '@angular/core'; import { FormArray, FormBuilder, FormGroup, Validators } from '@angular/forms'; import { Router } from '@angular/router'; @@ -12,6 +21,13 @@ import { RemoteData } from '../../../core/data/remote-data'; import { LdnService } from '../ldn-services-model/ldn-services.model'; import { NotificationsService } from '../../../shared/notifications/notifications.service'; import { TranslateService } from '@ngx-translate/core'; +import { PaginatedList } from '../../../core/data/paginated-list.model'; +import { Itemfilter } from '../ldn-services-model/ldn-service-itemfilters'; +import { Observable } from 'rxjs'; +import { FindListOptions } from '../../../core/data/find-list-options.model'; +import { PaginationComponentOptions } from '../../../shared/pagination/pagination-component-options.model'; +import { LdnItemfiltersService } from '../ldn-services-data/ldn-itemfilters-data.service'; +import { NgbModal } from "@ng-bootstrap/ng-bootstrap"; @Component({ @@ -28,11 +44,21 @@ import { TranslateService } from '@ngx-translate/core'; }) export class LdnServiceFormComponent implements OnInit { formModel: FormGroup; + private modalRef: any; + @ViewChild('confirmModal', {static: true}) confirmModal: TemplateRef; + @ViewChild('resetFormModal', {static: true}) resetFormModal: TemplateRef; public inboundPatterns: object[] = notifyPatterns; public outboundPatterns: object[] = notifyPatterns; - public itemFilterList: any[]; + itemfiltersRD$: Observable>>; + config: FindListOptions = Object.assign(new FindListOptions(), { + elementsPerPage: 20 + }); + pageConfig: PaginationComponentOptions = Object.assign(new PaginationComponentOptions(), { + id: 'po', + pageSize: 20 + }); @@ -51,11 +77,14 @@ export class LdnServiceFormComponent implements OnInit { constructor( private ldnServicesService: LdnServicesService, - private ldnDirectoryService: LdnDirectoryService, + private ldnItemfiltersService: LdnItemfiltersService, private formBuilder: FormBuilder, private router: Router, private notificationsService: NotificationsService, - private translateService: TranslateService + private translateService: TranslateService, + private cdRef: ChangeDetectorRef, + protected modalService: NgbModal, + ) { this.formModel = this.formBuilder.group({ @@ -75,15 +104,19 @@ export class LdnServiceFormComponent implements OnInit { } ngOnInit(): void { - this.ldnDirectoryService.getItemFilters().subscribe((itemFilters) => { - console.log(itemFilters); - this.itemFilterList = itemFilters._embedded.itemfilters.map((filter: { id: string; }) => ({ - name: filter.id - })); - }); + this.setItemfilters(); } - + setItemfilters() { + this.itemfiltersRD$ = this.ldnItemfiltersService.findAll().pipe( + getFirstCompletedRemoteData()); + console.log(this.itemfiltersRD$); + this.itemfiltersRD$.subscribe((rd: RemoteData>) => { + if (rd.hasSucceeded) { + console.log(rd); + } + }); + } /*createLdnService(values: any) { this.formModel.get('name').markAsTouched(); this.formModel.get('url').markAsTouched(); @@ -106,7 +139,7 @@ export class LdnServiceFormComponent implements OnInit { ).subscribe((rd: RemoteData) => { if (rd.hasSucceeded) { this.notificationsService.success(this.translateService.get('notification.created.success')); - this.submitForm.emit(values); + this.onSubmit.emit(values); } else { this.notificationsService.error(this.translateService.get('notification.created.failure', )); this.cancelForm.emit(); @@ -116,6 +149,17 @@ export class LdnServiceFormComponent implements OnInit { }*/ onSubmit() { + this.openConfirmModal(this.confirmModal); + } + + openConfirmModal(content) { + this.modalRef = this.modalService.open(content); + } + + openResetFormModal(content) { + this.modalRef = this.modalService.open(content); + } + createService(){ this.formModel.get('name').markAsTouched(); this.formModel.get('url').markAsTouched(); this.formModel.get('ldnUrl').markAsTouched(); @@ -125,6 +169,7 @@ export class LdnServiceFormComponent implements OnInit { const ldnUrl = this.formModel.get('ldnUrl').value; if (!name || !url || !ldnUrl) { + this.closeModal(); return; } @@ -133,26 +178,28 @@ export class LdnServiceFormComponent implements OnInit { const ldnServiceData = this.ldnServicesService.create(values); ldnServiceData.pipe( - getFirstCompletedRemoteData() - ).subscribe((ldnNewService) => { - console.log(ldnNewService); - }); - - ldnServiceData.pipe( - getFirstCompletedRemoteData() + getFirstCompletedRemoteData() ).subscribe((rd: RemoteData) => { if (rd.hasSucceeded) { this.notificationsService.success(this.translateService.get('notification.created.success')); - this.submitForm.emit(); this.sendBack(); } else { this.notificationsService.error(this.translateService.get('notification.created.failure')); - this.cancelForm.emit(); } }); } + resetFormAndLeave() { + this.sendBack(); + this.closeModal(); + } + + closeModal() { + this.modalRef.close(); + this.cdRef.detectChanges(); + } + addInboundPattern() { const notifyServiceInboundPatternsArray = this.formModel.get('notifyServiceInboundPatterns') as FormArray; notifyServiceInboundPatternsArray.push(this.createInboundPatternFormGroup()); @@ -184,6 +231,8 @@ export class LdnServiceFormComponent implements OnInit { this.router.navigateByUrl('admin/ldn/services'); } + + private createOutboundPatternFormGroup(): FormGroup { return this.formBuilder.group({ pattern: [''], diff --git a/src/app/admin/admin-ldn-services/ldn-services-data/ldn-itemfilters-data.service.ts b/src/app/admin/admin-ldn-services/ldn-services-data/ldn-itemfilters-data.service.ts new file mode 100644 index 0000000000..692e1a5db9 --- /dev/null +++ b/src/app/admin/admin-ldn-services/ldn-services-data/ldn-itemfilters-data.service.ts @@ -0,0 +1,48 @@ +import { Injectable } from '@angular/core'; +import { dataService } from '../../../core/data/base/data-service.decorator'; +import { LDN_SERVICE_CONSTRAINT_FILTERS } from '../ldn-services-model/ldn-service.resource-type'; +import { IdentifiableDataService } from '../../../core/data/base/identifiable-data.service'; +import { FindAllData, FindAllDataImpl } from '../../../core/data/base/find-all-data'; + +import { RequestService } from '../../../core/data/request.service'; +import { RemoteDataBuildService } from '../../../core/cache/builders/remote-data-build.service'; +import { ObjectCacheService } from '../../../core/cache/object-cache.service'; +import { HALEndpointService } from '../../../core/shared/hal-endpoint.service'; +import { NotificationsService } from '../../../shared/notifications/notifications.service'; +import { FindListOptions } from '../../../core/data/find-list-options.model'; +import { FollowLinkConfig } from '../../../shared/utils/follow-link-config.model'; +import { Observable } from 'rxjs'; +import { RemoteData } from '../../../core/data/remote-data'; +import { Itemfilter } from '../ldn-services-model/ldn-service-itemfilters'; +import { PaginatedList } from '../../../core/data/paginated-list.model'; + + + +/** + * A service responsible for fetching/sending data from/to the REST API on the itemfilters endpoint + */ +@Injectable() +@dataService(LDN_SERVICE_CONSTRAINT_FILTERS) +export class LdnItemfiltersService extends IdentifiableDataService implements FindAllData { + private findAllData: FindAllDataImpl; + + constructor( + protected requestService: RequestService, + protected rdbService: RemoteDataBuildService, + protected objectCache: ObjectCacheService, + protected halService: HALEndpointService, + protected notificationsService: NotificationsService, + ) { + super('itemfilters', requestService, rdbService, objectCache, halService); + + this.findAllData = new FindAllDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, this.responseMsToLive); + } + + getEndpoint() { + return this.halService.getEndpoint(this.linkPath); + } + + findAll(options?: FindListOptions, useCachedVersionIfAvailable?: boolean, reRequestOnStale?: boolean, ...linksToFollow: FollowLinkConfig[]): Observable>> { + return this.findAllData.findAll(options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow); + } +} diff --git a/src/app/admin/admin-ldn-services/ldn-services-data/ldn-services-data.service.ts b/src/app/admin/admin-ldn-services/ldn-services-data/ldn-services-data.service.ts index 83098f7f7c..d2ef16fada 100644 --- a/src/app/admin/admin-ldn-services/ldn-services-data/ldn-services-data.service.ts +++ b/src/app/admin/admin-ldn-services/ldn-services-data/ldn-services-data.service.ts @@ -32,6 +32,9 @@ import { ldnServiceConstrain } from '../ldn-services-model/ldn-service.constrain import { getFirstCompletedRemoteData } from 'src/app/core/shared/operators'; import { hasValue } from 'src/app/shared/empty.util'; +/** + * A service responsible for fetching/sending data from/to the REST API on the ldnservices endpoint + */ @Injectable() @dataService(LDN_SERVICE) export class LdnServicesService extends IdentifiableDataService implements FindAllData, DeleteData, PatchData, CreateData { diff --git a/src/app/admin/admin-ldn-services/ldn-services-directory/ldn-services-directory.component.ts b/src/app/admin/admin-ldn-services/ldn-services-directory/ldn-services-directory.component.ts index 933dff8901..9bc0602787 100644 --- a/src/app/admin/admin-ldn-services/ldn-services-directory/ldn-services-directory.component.ts +++ b/src/app/admin/admin-ldn-services/ldn-services-directory/ldn-services-directory.component.ts @@ -5,13 +5,13 @@ import { PaginatedList } from '../../../core/data/paginated-list.model'; import { FindListOptions } from '../../../core/data/find-list-options.model'; import { LdnService } from '../ldn-services-model/ldn-services.model'; import { PaginationComponentOptions } from '../../../shared/pagination/pagination-component-options.model'; -import { switchMap } from 'rxjs/operators'; +import { map, switchMap } from 'rxjs/operators'; import { LdnServicesService } from 'src/app/admin/admin-ldn-services/ldn-services-data/ldn-services-data.service'; import { PaginationService } from 'src/app/core/pagination/pagination.service'; import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; import { hasValue } from '../../../shared/empty.util'; import { Operation } from 'fast-json-patch'; -import { getFirstCompletedRemoteData } from '../../../core/shared/operators'; +import { getAllCompletedRemoteData, getFirstCompletedRemoteData } from '../../../core/shared/operators'; import { NotificationsService } from '../../../shared/notifications/notifications.service'; import { TranslateService } from '@ngx-translate/core'; import { Router } from '@angular/router'; @@ -55,8 +55,9 @@ export class LdnServicesOverviewComponent implements OnInit, OnDestroy { setLdnServices() { this.ldnServicesRD$ = this.paginationService.getFindListOptions(this.pageConfig.id, this.config).pipe( - switchMap((config) => this.ldnServicesService.findAll(config, true, false).pipe( + switchMap((config) => this.ldnServicesService.findAll(config, false, false).pipe( getFirstCompletedRemoteData() + )) ); @@ -96,6 +97,14 @@ export class LdnServicesOverviewComponent implements OnInit, OnDestroy { ldnServicesService.delete(serviceId).pipe(getFirstCompletedRemoteData()).subscribe((rd: RemoteData) => { if (rd.hasSucceeded) { this.servicesData = this.servicesData.filter(service => service.id !== serviceId); + this.ldnServicesRD$ = this.ldnServicesRD$.pipe( + map((remoteData: RemoteData>) => { + if (remoteData.hasSucceeded) { + remoteData.payload.page = remoteData.payload.page.filter(service => service.id.toString() !== serviceId); + } + return remoteData; + }) + ); this.cdRef.detectChanges(); this.closeModal(); this.notificationService.success(this.translateService.get('notification.created.success')); diff --git a/src/app/admin/admin-ldn-services/ldn-services-model/ldn-service-itemfilters.ts b/src/app/admin/admin-ldn-services/ldn-services-model/ldn-service-itemfilters.ts new file mode 100644 index 0000000000..865fa0b3ea --- /dev/null +++ b/src/app/admin/admin-ldn-services/ldn-services-model/ldn-service-itemfilters.ts @@ -0,0 +1,32 @@ +import { autoserialize, inheritSerialization, deserialize } from 'cerialize'; +import { LDN_SERVICE_CONSTRAINT_FILTER } from './ldn-service.resource-type'; +import { CacheableObject } from '../../../core/cache/cacheable-object.model'; +import { HALLink } from '../../../core/shared/hal-link.model'; +import { typedObject } from '../../../core/cache/builders/build-decorators'; +import { excludeFromEquals } from '../../../core/utilities/equals.decorators'; +import { ResourceType } from '../../../core/shared/resource-type'; + +/** A single filter value and its properties. */ +@typedObject +@inheritSerialization(CacheableObject) +export class Itemfilter extends CacheableObject { + static type = LDN_SERVICE_CONSTRAINT_FILTER; + + @excludeFromEquals + @autoserialize + type: ResourceType; + + @autoserialize + id: string; + + @deserialize + _links: { + self: { + href: string; + }; + }; + + get self(): string { + return this._links.self.href; + } +} diff --git a/src/app/admin/admin-ldn-services/ldn-services-model/ldn-service.resource-type.ts b/src/app/admin/admin-ldn-services/ldn-services-model/ldn-service.resource-type.ts index 859ecb739e..05a881e7e7 100644 --- a/src/app/admin/admin-ldn-services/ldn-services-model/ldn-service.resource-type.ts +++ b/src/app/admin/admin-ldn-services/ldn-services-model/ldn-service.resource-type.ts @@ -7,4 +7,6 @@ import { ResourceType } from '../../../core/shared/resource-type'; export const LDN_SERVICE = new ResourceType('ldnservice'); -export const LDN_SERVICE_CONSTRAINT = new ResourceType('ldnservice'); +export const LDN_SERVICE_CONSTRAINT_FILTERS = new ResourceType('itemfilters'); + +export const LDN_SERVICE_CONSTRAINT_FILTER = new ResourceType('itemfilter'); diff --git a/src/app/admin/admin-ldn-services/ldn-services-model/ldn-services.model.ts b/src/app/admin/admin-ldn-services/ldn-services-model/ldn-services.model.ts index 82731b3cb1..e0725b5851 100644 --- a/src/app/admin/admin-ldn-services/ldn-services-model/ldn-services.model.ts +++ b/src/app/admin/admin-ldn-services/ldn-services-model/ldn-services.model.ts @@ -8,7 +8,7 @@ import { NotifyServicePattern } from './ldn-service-patterns.model'; - +/** An LdnService and its properties. */ @typedObject @inheritSerialization(CacheableObject) export class LdnService extends CacheableObject { diff --git a/src/app/admin/admin-ldn-services/ldn-services-services/ldn-directory.service.ts b/src/app/admin/admin-ldn-services/ldn-services-services/ldn-directory.service.ts index 5ed32f5bb7..3499759f03 100644 --- a/src/app/admin/admin-ldn-services/ldn-services-services/ldn-directory.service.ts +++ b/src/app/admin/admin-ldn-services/ldn-services-services/ldn-directory.service.ts @@ -1,57 +1,26 @@ import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; -import { Observable, tap } from 'rxjs'; -import { LdnService } from '../ldn-services-model/ldn-services.model'; +import { map, Observable } from 'rxjs'; +import { LdnServicesService } from "../ldn-services-data/ldn-services-data.service"; @Injectable({ providedIn: 'root', }) export class LdnDirectoryService { - private baseUrl = 'http://localhost:8080/server/api/ldn/ldnservices'; private itemFilterEndpoint = 'http://localhost:8080/server/api/config/itemfilters'; - constructor(private http: HttpClient) {} + constructor(private http: HttpClient, + private ldnServicesService: LdnServicesService) {} + public getItemFilters(): Observable { - - public listLdnServices(): Observable { - const endpoint = `${this.baseUrl}`; - return this.http.get(endpoint).pipe( - tap(data => { - console.log('listLdnServices() Data:', data); + return this.ldnServicesService.findAll().pipe( + map((servicesData) => { + return servicesData; }) ); } - public getLdnServiceById(id: string): Observable { - const endpoint = `${this.baseUrl}/${id}`; - return this.http.get(endpoint); - } - - public createLdnService(ldnService: LdnService): Observable { - return this.http.post(this.baseUrl, ldnService); - } - - public updateLdnService(id: string, ldnService: LdnService): Observable { - const endpoint = `${this.baseUrl}/${id}`; - return this.http.put(endpoint, ldnService); - } - - public deleteLdnService(id: string): Observable { - const endpoint = `${this.baseUrl}/${id}`; - return this.http.delete(endpoint); - } - - public searchLdnServicesByLdnUrl(ldnUrl: string): Observable { - const endpoint = `${this.baseUrl}/search/byLdnUrl?ldnUrl=${ldnUrl}`; - return this.http.get(endpoint); - } - - public getItemFilters(): Observable { - const itemFiltersEndpoint = `${this.itemFilterEndpoint}`; - return this.http.get(itemFiltersEndpoint); - } - } diff --git a/src/app/core/core.module.ts b/src/app/core/core.module.ts index 1990bde77e..88da00f02c 100644 --- a/src/app/core/core.module.ts +++ b/src/app/core/core.module.ts @@ -189,6 +189,8 @@ import { SuggestionTarget } from './suggestion-notifications/reciter-suggestions import { SuggestionSource } from './suggestion-notifications/reciter-suggestions/models/suggestion-source.model'; import { LdnServicesService } from '../admin/admin-ldn-services/ldn-services-data/ldn-services-data.service'; import { LdnService } from '../admin/admin-ldn-services/ldn-services-model/ldn-services.model'; +import { LdnItemfiltersService } from '../admin/admin-ldn-services/ldn-services-data/ldn-itemfilters-data.service'; +import { Itemfilter } from "../admin/admin-ldn-services/ldn-services-model/ldn-service-itemfilters"; /** * When not in production, endpoint responses can be mocked for testing purposes @@ -313,6 +315,7 @@ const PROVIDERS = [ OrcidHistoryDataService, SupervisionOrderDataService, LdnServicesService, + LdnItemfiltersService ]; /** @@ -394,7 +397,8 @@ export const models = BulkAccessConditionOptions, SuggestionTarget, SuggestionSource, - LdnService + LdnService, + Itemfilter ]; From 5cca15daecef150e3b2b5d30883768d52390db7b Mon Sep 17 00:00:00 2001 From: Mattia Vianelli Date: Tue, 24 Oct 2023 12:56:31 +0200 Subject: [PATCH 06/11] CST-12174 Updated delete services to mark for deletion --- .../ldn-service-form-edit.component.html | 52 ++++--- .../ldn-service-form-edit.component.scss | 21 ++- .../ldn-service-form-edit.component.ts | 133 ++++++++---------- .../ldn-service-form.component.html | 50 ++++--- .../ldn-service-form.component.scss | 9 +- .../ldn-service-form.component.ts | 54 +++---- .../ldn-services-directory.component.html | 2 + .../ldn-services-directory.component.ts | 36 ++--- .../ldn-service-coar-patterns.ts | 4 - src/assets/i18n/en.json5 | 27 +++- 10 files changed, 203 insertions(+), 185 deletions(-) diff --git a/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.html b/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.html index 5d33d21505..3781a059ec 100644 --- a/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.html +++ b/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.html @@ -1,5 +1,8 @@ +
- +
+

{{ 'ldn-edit-registered-service.title' | translate }}

+
@@ -81,7 +84,9 @@ -
+ + +
-
@@ -193,22 +202,25 @@
 
- - -
- +
+ +
- +
@@ -251,11 +264,12 @@
+ class="btn btn-primary mr-2 custom-btn" id="reset-confirm">{{ 'service.overview.reset-form.reset-return' | translate }}
+ diff --git a/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.scss b/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.scss index db9073a47b..df8146330f 100644 --- a/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.scss +++ b/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.scss @@ -1,7 +1,6 @@ form { max-width: 800px; font-size: 14px; - margin-left: 100px; position: relative; } @@ -98,6 +97,8 @@ textarea { .toggle-switch { cursor: pointer; + margin-top: 3px; + margin-right: 3px } .label-box{ @@ -114,13 +115,21 @@ textarea { form button.btn.btn-primary[type="submit"] { position: absolute; - bottom: 0px; - right: -10px; + right: 8px; +} + +.submission-form-footer { + border-radius: var(--bs-card-border-radius); + bottom: 0; + background-color: var(--bs-gray-400); + padding: calc(var(--bs-spacer) / 2); + z-index: var(--ds-submission-footer-z-index); +} + +.marked-for-deletion { + background-color: #ffcccc; } - - - diff --git a/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.ts b/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.ts index eb8c4f40ca..39cfb6ac6c 100644 --- a/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.ts +++ b/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.ts @@ -58,9 +58,13 @@ export class LdnServiceFormEditComponent implements OnInit { @Input() public headerKey: string; private originalInboundPatterns: any[] = []; private originalOutboundPatterns: any[] = []; + private deletedInboundPatterns: number[] = []; + private deletedOutboundPatterns: number[] = []; private modalRef: any; private service: LdnService; protected serviceId: string; + markedForDeletion: number[] = []; + constructor( protected ldnServicesService: LdnServicesService, @@ -104,13 +108,7 @@ export class LdnServiceFormEditComponent implements OnInit { setItemfilters() { this.itemfiltersRD$ = this.ldnItemfiltersService.findAll().pipe( getFirstCompletedRemoteData()); - console.log(this.itemfiltersRD$); - this.itemfiltersRD$.subscribe((rd: RemoteData>) => { - if (rd.hasSucceeded) { - console.log(rd); - } - }); -} + } @@ -155,13 +153,8 @@ export class LdnServiceFormEditComponent implements OnInit { }); this.originalInboundPatterns = [...this.service.notifyServiceInboundPatterns]; this.originalOutboundPatterns = [...this.service.notifyServiceOutboundPatterns]; - } else { - console.error('Error fetching service data:', data.errorMessage); } }, - (error) => { - console.error('Error fetching service data:', error); - } ); } @@ -174,9 +167,24 @@ export class LdnServiceFormEditComponent implements OnInit { this.createReplaceOperation(patchOperations, 'url', '/url'); this.handlePatterns(patchOperations, 'notifyServiceInboundPatterns'); - this.handlePatterns(patchOperations, 'notifyServiceOutboundPatterns'); + this.deletedInboundPatterns.forEach(index => { + const removeOperation: Operation = { + op: 'remove', + path: `notifyServiceInboundPatterns[${index}]` + }; + patchOperations.push(removeOperation); + }); + + this.deletedOutboundPatterns.forEach(index => { + const removeOperation: Operation = { + op: 'remove', + path: `notifyServiceOutboundPatterns[${index}]` + }; + patchOperations.push(removeOperation); + }); + return patchOperations; } @@ -189,43 +197,6 @@ export class LdnServiceFormEditComponent implements OnInit { notifyServiceInboundPatternsArray.push(this.createInboundPatternFormGroup()); } - removeInboundPattern(index: number): void { - const patternsArray = this.formModel.get('notifyServiceInboundPatterns') as FormArray; - const patternGroup = patternsArray.at(index) as FormGroup; - const patternValue = patternGroup.value; - - if (index < 0 || index >= patternsArray.length || patternValue.isNew) { - patternsArray.removeAt(index); - return; - } - - const patchOperation: Operation = { - op: 'remove', - path: `notifyServiceInboundPatterns[${index}]` - }; - - this.ldnServicesService.patch(this.service, [patchOperation]).pipe( - getFirstCompletedRemoteData() - ).subscribe( - (data: RemoteData) => { - if (data.hasSucceeded) { - this.notificationService.success(this.translateService.get('ldn-service.notification.remove-inbound-pattern.success.title'), - this.translateService.get('ldn-service.notification.remove-inbound-pattern.success.content')); - } else { - this.notificationService.error(this.translateService.get('ldn-service.notification.remove-inbound-pattern.error.title'), - this.translateService.get('ldn-service.notification.remove-inbound-pattern.error.content')); - } - patternsArray.removeAt(index); - this.cdRef.detectChanges(); - }, - (error) => { - console.error('Error removing pattern:', error); - } - ); - } - - - addOutboundPattern() { const notifyServiceOutboundPatternsArray = this.formModel.get('notifyServiceOutboundPatterns') as FormArray; notifyServiceOutboundPatternsArray.push(this.createOutboundPatternFormGroup()); @@ -241,29 +212,11 @@ export class LdnServiceFormEditComponent implements OnInit { return; } - const patchOperation: Operation = { - op: 'remove', - path: `notifyServiceOutboundPatterns[${index}]` - }; - this.ldnServicesService.patch(this.service, [patchOperation]).pipe( - getFirstCompletedRemoteData() - ).subscribe( - (data: RemoteData) => { - if (data.hasSucceeded) { - this.notificationService.success(this.translateService.get('ldn-service.notification.remove-outbound-pattern.success.title'), - this.translateService.get('ldn-service.notification.remove-outbound-pattern.success.content')); - } else { - this.notificationService.error(this.translateService.get('ldn-service.notification.remove-outbound-pattern.error.title'), - this.translateService.get('ldn-service.notification.remove-outbound-pattern.error.content')); - } - patternsArray.removeAt(index); - this.cdRef.detectChanges(); - }, - (error) => { - console.error('Error removing pattern:', error); - } - ); + this.deletedOutboundPatterns.push(index); + + patternsArray.removeAt(index); + this.cdRef.detectChanges(); } @@ -276,7 +229,6 @@ export class LdnServiceFormEditComponent implements OnInit { toggleEnabled() { const newStatus = !this.formModel.get('enabled').value; - const serviceId = this.formModel.get('id').value; const patchOperation: Operation = { op: 'replace', @@ -288,12 +240,9 @@ export class LdnServiceFormEditComponent implements OnInit { getFirstCompletedRemoteData() ).subscribe( () => { - console.log('Status updated successfully.'); + this.formModel.get('enabled').setValue(newStatus); this.cdRef.detectChanges(); - }, - (error) => { - console.error('Error updating status:', error); } ); } @@ -313,8 +262,10 @@ export class LdnServiceFormEditComponent implements OnInit { } patchService() { + this.deleteMarkedPatterns(); const patchOperations = this.generatePatchOperations(); + this.ldnServicesService.patch(this.service, patchOperations).pipe( getFirstCompletedRemoteData() ).subscribe( @@ -328,9 +279,9 @@ export class LdnServiceFormEditComponent implements OnInit { (error) => { this.notificationService.error(this.translateService.get('admin.registries.services-formats.modify.failure.head'), this.translateService.get('admin.registries.services-formats.modify.failure.content')); - console.error('Error updating service:', error); } ); + } private createReplaceOperation(patchOperations: any[], formControlName: string, path: string): void { @@ -411,4 +362,30 @@ export class LdnServiceFormEditComponent implements OnInit { automatic: '', }); } + markForDeletion(index: number) { + if (!this.markedForDeletion.includes(index)) { + this.markedForDeletion.push(index); + } + } + + unmarkForDeletion(index: number) { + const i = this.markedForDeletion.indexOf(index); + if (i !== -1) { + this.markedForDeletion.splice(i, 1); + } + } + + deleteMarkedPatterns() { + this.markedForDeletion.sort((a, b) => b - a); + const patternsArray = this.formModel.get('notifyServiceInboundPatterns') as FormArray; + + for (const index of this.markedForDeletion) { + if (index >= 0 && index < patternsArray.length) { + this.deletedInboundPatterns.push(index); + patternsArray.removeAt(index); + } + } + + this.markedForDeletion = []; + } } diff --git a/src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.html b/src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.html index 4e9f7b8208..b82b05af77 100644 --- a/src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.html +++ b/src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.html @@ -1,5 +1,8 @@ +
- +
+

{{ 'ldn-create-service.title' | translate }}

+
@@ -71,7 +74,7 @@ -
+
-
@@ -177,26 +180,33 @@
{{ 'ldn-new-service.form.label.addPattern' | translate }} + class="add-pattern-link">{{ 'ldn-new-service.form.label.addPattern' | translate }} -
+
 
- -
- -
- + + + + +
- +
@@ -239,9 +250,10 @@
+ class="btn btn-primary mr-2 custom-btn" id="reset-confirm">{{ 'service.overview.reset-form.reset-return' | translate }} +
diff --git a/src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.scss b/src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.scss index eb6c97c90a..523653381b 100644 --- a/src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.scss +++ b/src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.scss @@ -1,7 +1,6 @@ form { max-width: 800px; font-size: 14px; - margin-left: 100px; position: relative; } @@ -118,7 +117,13 @@ form button.btn.btn-primary[type="submit"] { right: -10px; } - +.submission-form-footer { + border-radius: var(--bs-card-border-radius); + bottom: 0; + background-color: var(--bs-gray-400); + padding: calc(var(--bs-spacer) / 2); + z-index: var(--ds-submission-footer-z-index); +} diff --git a/src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts b/src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts index 25b7ab70d5..7e9a1e148f 100644 --- a/src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts +++ b/src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts @@ -13,7 +13,6 @@ import { Router } from '@angular/router'; import { LdnServicesService } from '../ldn-services-data/ldn-services-data.service'; import { notifyPatterns } from '../ldn-services-patterns/ldn-service-coar-patterns'; -import { LdnDirectoryService } from '../ldn-services-services/ldn-directory.service'; import { LDN_SERVICE } from '../ldn-services-model/ldn-service.resource-type'; import { animate, state, style, transition, trigger } from '@angular/animations'; import { getFirstCompletedRemoteData } from '../../../core/shared/operators'; @@ -27,7 +26,7 @@ import { Observable } from 'rxjs'; import { FindListOptions } from '../../../core/data/find-list-options.model'; import { PaginationComponentOptions } from '../../../shared/pagination/pagination-component-options.model'; import { LdnItemfiltersService } from '../ldn-services-data/ldn-itemfilters-data.service'; -import { NgbModal } from "@ng-bootstrap/ng-bootstrap"; +import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; @Component({ @@ -110,43 +109,11 @@ export class LdnServiceFormComponent implements OnInit { setItemfilters() { this.itemfiltersRD$ = this.ldnItemfiltersService.findAll().pipe( getFirstCompletedRemoteData()); - console.log(this.itemfiltersRD$); this.itemfiltersRD$.subscribe((rd: RemoteData>) => { if (rd.hasSucceeded) { - console.log(rd); } }); } - /*createLdnService(values: any) { - this.formModel.get('name').markAsTouched(); - this.formModel.get('url').markAsTouched(); - this.formModel.get('ldnUrl').markAsTouched(); - - const ldnServiceData = this.ldnServicesService.create(this.formModel.value); - - ldnServiceData.subscribe((ldnNewService) => { - console.log(ldnNewService); - const name = ldnNewService.payload.name; - const url = ldnNewService.payload.url; - const ldnUrl = ldnNewService.payload.ldnUrl; - - if (!name || !url || !ldnUrl) { - return; - } - - ldnServiceData.pipe( - getFirstCompletedRemoteData() - ).subscribe((rd: RemoteData) => { - if (rd.hasSucceeded) { - this.notificationsService.success(this.translateService.get('notification.created.success')); - this.onSubmit.emit(values); - } else { - this.notificationsService.error(this.translateService.get('notification.created.failure', )); - this.cancelForm.emit(); - } - }); - }); - }*/ onSubmit() { this.openConfirmModal(this.confirmModal); @@ -159,7 +126,7 @@ export class LdnServiceFormComponent implements OnInit { openResetFormModal(content) { this.modalRef = this.modalService.open(content); } - createService(){ + createService() { this.formModel.get('name').markAsTouched(); this.formModel.get('url').markAsTouched(); this.formModel.get('ldnUrl').markAsTouched(); @@ -175,21 +142,34 @@ export class LdnServiceFormComponent implements OnInit { const values = this.formModel.value; + const inboundPatternValue = this.formModel.get('inboundPattern').value; + const outboundPatternValue = this.formModel.get('outboundPattern').value; + + if (inboundPatternValue === '') { + values.notifyServiceInboundPatterns = []; + } + if (outboundPatternValue === '') { + values.notifyServiceOutboundPatterns = []; + } + const ldnServiceData = this.ldnServicesService.create(values); ldnServiceData.pipe( getFirstCompletedRemoteData() ).subscribe((rd: RemoteData) => { if (rd.hasSucceeded) { - this.notificationsService.success(this.translateService.get('notification.created.success')); + this.notificationsService.success(this.translateService.get('ldn-service-notification.created.success.title')); + (this.translateService.get('ldn-service-notification.created.success.title'), + this.translateService.get('ldn-service-notification.created.success.body')); this.sendBack(); + this.closeModal(); } else { this.notificationsService.error(this.translateService.get('notification.created.failure')); } }); - } + resetFormAndLeave() { this.sendBack(); this.closeModal(); diff --git a/src/app/admin/admin-ldn-services/ldn-services-directory/ldn-services-directory.component.html b/src/app/admin/admin-ldn-services/ldn-services-directory/ldn-services-directory.component.html index 9396ac44ae..6753c6e90c 100644 --- a/src/app/admin/admin-ldn-services/ldn-services-directory/ldn-services-directory.component.html +++ b/src/app/admin/admin-ldn-services/ldn-services-directory/ldn-services-directory.component.html @@ -34,6 +34,7 @@ +
@@ -41,6 +42,7 @@ class="btn btn-outline-dark"> +
diff --git a/src/app/admin/admin-ldn-services/ldn-services-directory/ldn-services-directory.component.ts b/src/app/admin/admin-ldn-services/ldn-services-directory/ldn-services-directory.component.ts index 9bc0602787..91904d6bc5 100644 --- a/src/app/admin/admin-ldn-services/ldn-services-directory/ldn-services-directory.component.ts +++ b/src/app/admin/admin-ldn-services/ldn-services-directory/ldn-services-directory.component.ts @@ -11,10 +11,10 @@ import { PaginationService } from 'src/app/core/pagination/pagination.service'; import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; import { hasValue } from '../../../shared/empty.util'; import { Operation } from 'fast-json-patch'; -import { getAllCompletedRemoteData, getFirstCompletedRemoteData } from '../../../core/shared/operators'; +import { getFirstCompletedRemoteData } from '../../../core/shared/operators'; import { NotificationsService } from '../../../shared/notifications/notifications.service'; import { TranslateService } from '@ngx-translate/core'; -import { Router } from '@angular/router'; + @Component({ selector: 'ds-ldn-services-directory', @@ -38,6 +38,7 @@ export class LdnServicesOverviewComponent implements OnInit, OnDestroy { isProcessingSub: Subscription; private modalRef: any; + constructor( protected ldnServicesService: LdnServicesService, protected paginationService: PaginationService, @@ -45,7 +46,6 @@ export class LdnServicesOverviewComponent implements OnInit, OnDestroy { private cdRef: ChangeDetectorRef, private notificationService: NotificationsService, private translateService: TranslateService, - private router: Router, ) { } @@ -57,18 +57,8 @@ export class LdnServicesOverviewComponent implements OnInit, OnDestroy { this.ldnServicesRD$ = this.paginationService.getFindListOptions(this.pageConfig.id, this.config).pipe( switchMap((config) => this.ldnServicesService.findAll(config, false, false).pipe( getFirstCompletedRemoteData() - )) ); - - this.ldnServicesRD$.subscribe((rd: RemoteData>) => { - console.log(rd); - if (rd.hasSucceeded) { - this.notificationService.success(this.translateService.get('notification.loaded.success')); - } else { - this.notificationService.error(this.translateService.get('notification.loaded.failure')); - } - }); } ngOnDestroy(): void { @@ -107,9 +97,11 @@ export class LdnServicesOverviewComponent implements OnInit, OnDestroy { ); this.cdRef.detectChanges(); this.closeModal(); - this.notificationService.success(this.translateService.get('notification.created.success')); + this.notificationService.success(this.translateService.get('ldn-service-delete.notification.success.title'), + this.translateService.get('ldn-service-delete.notification.success.content')); } else { - this.notificationService.error(this.translateService.get('notification.created.failure')); + this.notificationService.error(this.translateService.get('ldn-service-delete.notification.error.title'), + this.translateService.get('ldn-service-delete.notification.error.content')); this.cdRef.detectChanges(); } }); @@ -117,24 +109,32 @@ export class LdnServicesOverviewComponent implements OnInit, OnDestroy { } + + toggleStatus(ldnService: any, ldnServicesService: LdnServicesService): void { const newStatus = !ldnService.enabled; - let status = ldnService.enabled; + const originalStatus = ldnService.enabled; + const patchOperation: Operation = { op: 'replace', path: '/enabled', value: newStatus, }; + ldnServicesService.patch(ldnService, [patchOperation]).pipe(getFirstCompletedRemoteData()).subscribe( - () => { - if (status !== newStatus) { + (rd: RemoteData) => { + if (rd.hasSucceeded) { + ldnService.enabled = newStatus; this.notificationService.success(this.translateService.get('ldn-enable-service.notification.success.title'), this.translateService.get('ldn-enable-service.notification.success.content')); } else { + ldnService.enabled = originalStatus; this.notificationService.error(this.translateService.get('ldn-enable-service.notification.error.title'), this.translateService.get('ldn-enable-service.notification.error.content')); } } ); } + + } diff --git a/src/app/admin/admin-ldn-services/ldn-services-patterns/ldn-service-coar-patterns.ts b/src/app/admin/admin-ldn-services/ldn-services-patterns/ldn-service-coar-patterns.ts index 14d227c131..7b0c25e832 100644 --- a/src/app/admin/admin-ldn-services/ldn-services-patterns/ldn-service-coar-patterns.ts +++ b/src/app/admin/admin-ldn-services/ldn-services-patterns/ldn-service-coar-patterns.ts @@ -67,7 +67,3 @@ export const notifyPatterns = [ ]; -const pattern = notifyPatterns[0]; -console.log(`Pattern Name: ${pattern.name}`); -console.log(`Pattern Description: ${pattern.description}`); -console.log(`Pattern Category: ${pattern.category}`); diff --git a/src/assets/i18n/en.json5 b/src/assets/i18n/en.json5 index 7a68fc60c8..7cded8573d 100644 --- a/src/assets/i18n/en.json5 +++ b/src/assets/i18n/en.json5 @@ -917,9 +917,15 @@ "ldn-service.overview.table.clickToEnable": "Click to enable", "ldn-service.overview.table.clickToDisable": "Click to disable", + "ldn-edit-registered-service.title": "Edit Service", + "ldn-create-service.title": "Create service", + "service.overview.create.modal": "Create Service", + "service.overview.create.body": "Please confirm the creation of this service", "ldn-service-status": "Status", + "service.confirm.create": "Create", + "service.refuse.create": "Discard", "ldn-register-new-service.title": "Register a new service", - "ldn-new-service.form.label.submit": "Submit", + "ldn-new-service.form.label.submit": "Save", "ldn-new-service.form.label.name": "Name", "ldn-new-service.form.label.description": "Description", "ldn-new-service.form.label.url": "Service URL", @@ -939,6 +945,23 @@ "ldn-new-service.form.label.removeItemFilter": "Remove", "ldn-register-new-service.breadcrumbs": "New Service", "service.overview.delete.body": "Are you sure you want to delete this service?", + "service.overview.edit.body": "Are you sure you want to confirm those service changes?", + "service.overview.edit.modal": "Edit Service", + "service.detail.update": "Edit Service", + "service.detail.return": "Cancel", + "service.overview.reset-form.body": "Are you sure you want to discard those changes and leave?", + "service.overview.reset-form.modal": "Discard Service Changes", + "service.overview.reset-form.reset-confirm":"Discard", + "admin.registries.services-formats.modify.success.head": "Successful Edit", + "admin.registries.services-formats.modify.success.content": "The service has been edited", + "ldn-service-notification.created.success.title": "Successful Create", + "ldn-service-notification.created.success.body": "The service has been created", + "ldn-enable-service.notification.success.title": "Successful status updated", + "ldn-enable-service.notification.success.content": "The service status has been updated", + "ldn-service-delete.notification.success.title": "Successful Deletion", + "ldn-service-delete.notification.success.content": "The service has been deleted", + "ldn-service-delete.notification.error.title": "Failed Deletion", + "ldn-service-delete.notification.error.content": "The service has not been deleted", "service.overview.delete": "Delete service", "ldn-edit-service.title": "Edit service", "ldn-edit-service.form.label.name": "Name", @@ -954,7 +977,7 @@ "ldn-edit-service.form.label.outboundPattern": "Outbound Pattern", "ldn-edit-service.form.label.noOutboundPatternSelected": "No Outbound Pattern", "ldn-edit-service.form.label.addOutboundPattern": "+ Add more", - "ldn-edit-service.form.label.submit": "Submit", + "ldn-edit-service.form.label.submit": "Save", "ldn-edit-service.breadcrumbs": "Edit Service", From 0963a320810bf091938644b144e0d2692ca8c9f0 Mon Sep 17 00:00:00 2001 From: Mattia Vianelli Date: Tue, 24 Oct 2023 12:59:21 +0200 Subject: [PATCH 07/11] CST-12174 Updated delete services to mark for deletion --- .../admin-ldn-services-routing.module.ts | 48 +- .../admin-ldn-services.module.ts | 30 +- .../ldn-service-form-edit.component.html | 484 ++++++------- .../ldn-service-form-edit.component.scss | 18 +- .../ldn-service-form-edit.component.spec.ts | 28 +- .../ldn-service-form-edit.component.ts | 682 +++++++++--------- .../ldn-service-form.component.html | 453 ++++++------ .../ldn-service-form.component.scss | 20 +- .../ldn-service-form.component.spec.ts | 32 +- .../ldn-service-form.component.ts | 346 +++++---- .../ldn-service-new.component.spec.ts | 32 +- .../ldn-service-new.component.ts | 29 +- .../ldnServicesRD$-mock.ts | 6 +- .../ldn-itemfilters-data.service.ts | 13 +- .../ldn-services-data.service.ts | 141 ++-- .../ldn-services-directory.component.html | 37 +- .../ldn-services-directory.component.spec.ts | 32 +- .../ldn-services-directory.component.ts | 212 +++--- .../ldn-services-guard.service.ts | 40 +- .../ldn-services.guard.spec.ts | 18 +- .../ldn-service-itemfilters.ts | 3 +- .../ldn-service-patterns.model.ts | 12 +- .../ldn-service-status.model.ts | 6 +- .../ldn-service.constrain.model.ts | 2 +- .../ldn-services-model/ldn-services.model.ts | 1 - .../ldn-directory.service.spec.ts | 18 +- .../ldn-directory.service.ts | 24 +- .../ldn-service-bulk-delete.service.spec.ts | 18 +- 28 files changed, 1388 insertions(+), 1397 deletions(-) diff --git a/src/app/admin/admin-ldn-services/admin-ldn-services-routing.module.ts b/src/app/admin/admin-ldn-services/admin-ldn-services-routing.module.ts index 4f05bca9e3..2d3c68f7cb 100644 --- a/src/app/admin/admin-ldn-services/admin-ldn-services-routing.module.ts +++ b/src/app/admin/admin-ldn-services/admin-ldn-services-routing.module.ts @@ -7,30 +7,30 @@ import { LdnServiceNewComponent } from './ldn-service-new/ldn-service-new.compon import { LdnServiceFormEditComponent } from './ldn-service-form-edit/ldn-service-form-edit.component'; @NgModule({ - imports: [ - RouterModule.forChild([ - { - path: '', - pathMatch: 'full', - component: LdnServicesOverviewComponent, - resolve: { breadcrumb: I18nBreadcrumbResolver }, - data: { title: 'ldn-registered-services.title', breadcrumbKey: 'ldn-registered-services.new' }, - canActivate: [LdnServicesGuard] - }, - { - path: 'new', - resolve: { breadcrumb: I18nBreadcrumbResolver }, - component: LdnServiceNewComponent, - data: { title: 'ldn-register-new-service.title', breadcrumbKey: 'ldn-register-new-service' } - }, - { - path: 'edit/:serviceId', - resolve: { breadcrumb: I18nBreadcrumbResolver }, - component: LdnServiceFormEditComponent, - data: { title: 'ldn-edit-service.title', breadcrumbKey: 'ldn-edit-service' } - }, - ]), - ] + imports: [ + RouterModule.forChild([ + { + path: '', + pathMatch: 'full', + component: LdnServicesOverviewComponent, + resolve: {breadcrumb: I18nBreadcrumbResolver}, + data: {title: 'ldn-registered-services.title', breadcrumbKey: 'ldn-registered-services.new'}, + canActivate: [LdnServicesGuard] + }, + { + path: 'new', + resolve: {breadcrumb: I18nBreadcrumbResolver}, + component: LdnServiceNewComponent, + data: {title: 'ldn-register-new-service.title', breadcrumbKey: 'ldn-register-new-service'} + }, + { + path: 'edit/:serviceId', + resolve: {breadcrumb: I18nBreadcrumbResolver}, + component: LdnServiceFormEditComponent, + data: {title: 'ldn-edit-service.title', breadcrumbKey: 'ldn-edit-service'} + }, + ]), + ] }) export class AdminLdnServicesRoutingModule { diff --git a/src/app/admin/admin-ldn-services/admin-ldn-services.module.ts b/src/app/admin/admin-ldn-services/admin-ldn-services.module.ts index c82250fcec..9ca3775a9e 100644 --- a/src/app/admin/admin-ldn-services/admin-ldn-services.module.ts +++ b/src/app/admin/admin-ldn-services/admin-ldn-services.module.ts @@ -10,20 +10,20 @@ import { FormsModule } from '@angular/forms'; import { LdnItemfiltersService } from './ldn-services-data/ldn-itemfilters-data.service'; - @NgModule({ - imports: [ - CommonModule, - SharedModule, - AdminLdnServicesRoutingModule, - FormsModule - ], - declarations: [ - LdnServicesOverviewComponent, - LdnServiceNewComponent, - LdnServiceFormComponent, - LdnServiceFormEditComponent, - ], - providers: [LdnItemfiltersService] + imports: [ + CommonModule, + SharedModule, + AdminLdnServicesRoutingModule, + FormsModule + ], + declarations: [ + LdnServicesOverviewComponent, + LdnServiceNewComponent, + LdnServiceFormComponent, + LdnServiceFormEditComponent, + ], + providers: [LdnItemfiltersService] }) -export class AdminLdnServicesModule { } +export class AdminLdnServicesModule { +} diff --git a/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.html b/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.html index 3781a059ec..bcd597845d 100644 --- a/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.html +++ b/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.html @@ -1,275 +1,277 @@
-
-
-

{{ 'ldn-edit-registered-service.title' | translate }}

-
- -
- -
- -
-
-
-
-
- -
- - -
- -
-   -
- - -
- - -
- -
-   -
- - -
- - -
- -
-   -
- - -
- - -
- -
-   -
- -
-
- -
-
- -
-
- -
-
-
-
- -
- - - - - - -
-
- + +
+

{{ 'ldn-edit-registered-service.title' | translate }}

+
+ +
+ +
+ +
+
+
+
-
- - - +
+ +
-
- -
-
-
+
+  
- -
- - + +
+ +
-
- -
- - - {{ 'ldn-new-service.form.label.addPattern' | translate }} - -
-   -
- -
-
- -
-
- -
-
- -
-
-
-
- -
- - - - -
-
- +
+  
-
- - + + +
+ + +
+ +
+   +
+ + +
+ + +
+ +
+   +
+ +
+
+ +
+
+ +
+
+ +
+
+
+
+ +
+ + + + +
+
+ +
+ +
+ + + +
+ +
+ +
+
+
+
+ + +
+ + +
+
+
-
- -
-
-
+ + {{ 'ldn-new-service.form.label.addPattern' | translate }} + +
+  
-
- +
+
+ +
+
+ +
+
+ +
+
+
-
- -
- {{ 'ldn-new-service.form.label.addPattern' | translate }} +
+ + + + +
+
+ +
+
+ + + +
+ +
+ +
+
+
+
+ +
+ +
+
+
+
+ + {{ 'ldn-new-service.form.label.addPattern' | translate }} -
-   -
- - +
+   +
+ +
-
+
- + - -
-
+
- + - -
diff --git a/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.scss b/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.scss index df8146330f..b686e6533b 100644 --- a/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.scss +++ b/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.scss @@ -27,12 +27,13 @@ textarea { resize: none; } -.add-pattern-link{ +.add-pattern-link { color: #0048ff; cursor: pointer; margin-left: 10px; } -.remove-pattern-link{ + +.remove-pattern-link { color: #e34949; cursor: pointer; margin-left: 10px; @@ -75,7 +76,6 @@ textarea { } - .toggle-switch .slider { width: 22px; height: 22px; @@ -101,16 +101,16 @@ textarea { margin-right: 3px } -.label-box{ - margin-left:11px; +.label-box { + margin-left: 11px; } -.label-box-2{ - margin-left:14px; +.label-box-2 { + margin-left: 14px; } -.label-box-3{ - margin-left:5px; +.label-box-3 { + margin-left: 5px; } form button.btn.btn-primary[type="submit"] { diff --git a/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.spec.ts b/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.spec.ts index 8320ec9042..332d43cae3 100644 --- a/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.spec.ts +++ b/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.spec.ts @@ -3,21 +3,21 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { LdnServiceFormEditComponent } from './ldn-service-form-edit.component'; describe('LdnServiceFormEditComponent', () => { - let component: LdnServiceFormEditComponent; - let fixture: ComponentFixture; + let component: LdnServiceFormEditComponent; + let fixture: ComponentFixture; - beforeEach(async () => { - await TestBed.configureTestingModule({ - declarations: [ LdnServiceFormEditComponent ] - }) - .compileComponents(); + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [LdnServiceFormEditComponent] + }) + .compileComponents(); - fixture = TestBed.createComponent(LdnServiceFormEditComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + fixture = TestBed.createComponent(LdnServiceFormEditComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); - it('should create', () => { - expect(component).toBeTruthy(); - }); + it('should create', () => { + expect(component).toBeTruthy(); + }); }); diff --git a/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.ts b/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.ts index 39cfb6ac6c..93622f9df0 100644 --- a/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.ts +++ b/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.ts @@ -21,371 +21,365 @@ import { FindListOptions } from '../../../core/data/find-list-options.model'; import { PaginationComponentOptions } from '../../../shared/pagination/pagination-component-options.model'; @Component({ - selector: 'ds-ldn-service-form-edit', - templateUrl: './ldn-service-form-edit.component.html', - styleUrls: ['./ldn-service-form-edit.component.scss'], - animations: [ - trigger('toggleAnimation', [ - state('true', style({})), - state('false', style({})), - transition('true <=> false', animate('300ms ease-in')), - ]), - ], + selector: 'ds-ldn-service-form-edit', + templateUrl: './ldn-service-form-edit.component.html', + styleUrls: ['./ldn-service-form-edit.component.scss'], + animations: [ + trigger('toggleAnimation', [ + state('true', style({})), + state('false', style({})), + transition('true <=> false', animate('300ms ease-in')), + ]), + ], }) export class LdnServiceFormEditComponent implements OnInit { - formModel: FormGroup; - @ViewChild('confirmModal', {static: true}) confirmModal: TemplateRef; - @ViewChild('resetFormModal', {static: true}) resetFormModal: TemplateRef; + formModel: FormGroup; + @ViewChild('confirmModal', {static: true}) confirmModal: TemplateRef; + @ViewChild('resetFormModal', {static: true}) resetFormModal: TemplateRef; - public inboundPatterns: object[] = notifyPatterns; - public outboundPatterns: object[] = notifyPatterns; - itemfiltersRD$: Observable>>; - config: FindListOptions = Object.assign(new FindListOptions(), { - elementsPerPage: 20 - }); - pageConfig: PaginationComponentOptions = Object.assign(new PaginationComponentOptions(), { - id: 'po', - pageSize: 20 - }); - @Input() public name: string; - @Input() public description: string; - @Input() public url: string; - @Input() public ldnUrl: string; - @Input() public inboundPattern: string; - @Input() public outboundPattern: string; - @Input() public constraint: string; - @Input() public automatic: boolean; - @Input() public headerKey: string; - private originalInboundPatterns: any[] = []; - private originalOutboundPatterns: any[] = []; - private deletedInboundPatterns: number[] = []; - private deletedOutboundPatterns: number[] = []; - private modalRef: any; - private service: LdnService; - protected serviceId: string; - markedForDeletion: number[] = []; - - - constructor( - protected ldnServicesService: LdnServicesService, - private ldnItemfiltersService: LdnItemfiltersService, - private formBuilder: FormBuilder, - private router: Router, - private route: ActivatedRoute, - private cdRef: ChangeDetectorRef, - protected modalService: NgbModal, - private notificationService: NotificationsService, - private translateService: TranslateService, - protected paginationService: PaginationService - ) { - - this.formModel = this.formBuilder.group({ - id: [''], - name: ['', Validators.required], - description: ['', Validators.required], - url: ['', Validators.required], - ldnUrl: ['', Validators.required], - inboundPattern: [''], - outboundPattern: [''], - constraintPattern: [''], - enabled: [''], - notifyServiceInboundPatterns: this.formBuilder.array([this.createInboundPatternFormGroup()]), - notifyServiceOutboundPatterns: this.formBuilder.array([this.createOutboundPatternFormGroup()]), - type: LDN_SERVICE.value, + public inboundPatterns: object[] = notifyPatterns; + public outboundPatterns: object[] = notifyPatterns; + itemfiltersRD$: Observable>>; + config: FindListOptions = Object.assign(new FindListOptions(), { + elementsPerPage: 20 }); - } - - ngOnInit(): void { - this.route.params.subscribe((params) => { - this.serviceId = params.serviceId; - if (this.serviceId) { - this.fetchServiceData(this.serviceId); - } + pageConfig: PaginationComponentOptions = Object.assign(new PaginationComponentOptions(), { + id: 'po', + pageSize: 20 }); - this.setItemfilters(); - } + @Input() public name: string; + @Input() public description: string; + @Input() public url: string; + @Input() public ldnUrl: string; + @Input() public inboundPattern: string; + @Input() public outboundPattern: string; + @Input() public constraint: string; + @Input() public automatic: boolean; + @Input() public headerKey: string; + markedForDeletion: number[] = []; + protected serviceId: string; + private originalInboundPatterns: any[] = []; + private originalOutboundPatterns: any[] = []; + private deletedInboundPatterns: number[] = []; + private deletedOutboundPatterns: number[] = []; + private modalRef: any; + private service: LdnService; - setItemfilters() { - this.itemfiltersRD$ = this.ldnItemfiltersService.findAll().pipe( - getFirstCompletedRemoteData()); - } + constructor( + protected ldnServicesService: LdnServicesService, + private ldnItemfiltersService: LdnItemfiltersService, + private formBuilder: FormBuilder, + private router: Router, + private route: ActivatedRoute, + private cdRef: ChangeDetectorRef, + protected modalService: NgbModal, + private notificationService: NotificationsService, + private translateService: TranslateService, + protected paginationService: PaginationService + ) { + + this.formModel = this.formBuilder.group({ + id: [''], + name: ['', Validators.required], + description: ['', Validators.required], + url: ['', Validators.required], + ldnUrl: ['', Validators.required], + inboundPattern: [''], + outboundPattern: [''], + constraintPattern: [''], + enabled: [''], + notifyServiceInboundPatterns: this.formBuilder.array([this.createInboundPatternFormGroup()]), + notifyServiceOutboundPatterns: this.formBuilder.array([this.createOutboundPatternFormGroup()]), + type: LDN_SERVICE.value, + }); + } + + ngOnInit(): void { + this.route.params.subscribe((params) => { + this.serviceId = params.serviceId; + if (this.serviceId) { + this.fetchServiceData(this.serviceId); + } + }); + this.setItemfilters(); + } + + setItemfilters() { + this.itemfiltersRD$ = this.ldnItemfiltersService.findAll().pipe( + getFirstCompletedRemoteData()); + } + fetchServiceData(serviceId: string): void { + this.ldnServicesService.findById(serviceId).pipe( + getFirstCompletedRemoteData() + ).subscribe( + (data: RemoteData) => { + if (data.hasSucceeded) { + this.service = data.payload; + this.formModel.patchValue({ + id: this.service.id, + name: this.service.name, + description: this.service.description, + url: this.service.url, + ldnUrl: this.service.ldnUrl, + type: this.service.type, + enabled: this.service.enabled + }); - fetchServiceData(serviceId: string): void { - this.ldnServicesService.findById(serviceId).pipe( - getFirstCompletedRemoteData() - ).subscribe( - (data: RemoteData) => { - if (data.hasSucceeded) { - this.service = data.payload; + const inboundPatternsArray = this.formModel.get('notifyServiceInboundPatterns') as FormArray; + inboundPatternsArray.clear(); - this.formModel.patchValue({ - id: this.service.id, - name: this.service.name, - description: this.service.description, - url: this.service.url, - ldnUrl: this.service.ldnUrl, - type: this.service.type, - enabled: this.service.enabled - }); + this.service.notifyServiceInboundPatterns.forEach((pattern: any) => { + const patternFormGroup = this.initializeInboundPatternFormGroup(); + patternFormGroup.patchValue(pattern); + inboundPatternsArray.push(patternFormGroup); + this.cdRef.detectChanges(); + }); - const inboundPatternsArray = this.formModel.get('notifyServiceInboundPatterns') as FormArray; - inboundPatternsArray.clear(); + const outboundPatternsArray = this.formModel.get('notifyServiceOutboundPatterns') as FormArray; + outboundPatternsArray.clear(); - this.service.notifyServiceInboundPatterns.forEach((pattern: any) => { - const patternFormGroup = this.initializeInboundPatternFormGroup(); - patternFormGroup.patchValue(pattern); - inboundPatternsArray.push(patternFormGroup); - this.cdRef.detectChanges(); - }); + this.service.notifyServiceOutboundPatterns.forEach((pattern: any) => { + const patternFormGroup = this.initializeOutboundPatternFormGroup(); + patternFormGroup.patchValue(pattern); + outboundPatternsArray.push(patternFormGroup); - const outboundPatternsArray = this.formModel.get('notifyServiceOutboundPatterns') as FormArray; - outboundPatternsArray.clear(); + this.cdRef.detectChanges(); + }); + this.originalInboundPatterns = [...this.service.notifyServiceInboundPatterns]; + this.originalOutboundPatterns = [...this.service.notifyServiceOutboundPatterns]; + } + }, + ); + } - this.service.notifyServiceOutboundPatterns.forEach((pattern: any) => { - const patternFormGroup = this.initializeOutboundPatternFormGroup(); - patternFormGroup.patchValue(pattern); - outboundPatternsArray.push(patternFormGroup); + generatePatchOperations(): any[] { + const patchOperations: any[] = []; - this.cdRef.detectChanges(); - }); - this.originalInboundPatterns = [...this.service.notifyServiceInboundPatterns]; - this.originalOutboundPatterns = [...this.service.notifyServiceOutboundPatterns]; + this.createReplaceOperation(patchOperations, 'name', '/name'); + this.createReplaceOperation(patchOperations, 'description', '/description'); + this.createReplaceOperation(patchOperations, 'ldnUrl', '/ldnurl'); + this.createReplaceOperation(patchOperations, 'url', '/url'); + + this.handlePatterns(patchOperations, 'notifyServiceInboundPatterns'); + this.handlePatterns(patchOperations, 'notifyServiceOutboundPatterns'); + + this.deletedInboundPatterns.forEach(index => { + const removeOperation: Operation = { + op: 'remove', + path: `notifyServiceInboundPatterns[${index}]` + }; + patchOperations.push(removeOperation); + }); + + this.deletedOutboundPatterns.forEach(index => { + const removeOperation: Operation = { + op: 'remove', + path: `notifyServiceOutboundPatterns[${index}]` + }; + patchOperations.push(removeOperation); + }); + + return patchOperations; + } + + onSubmit() { + this.openConfirmModal(this.confirmModal); + } + + addInboundPattern() { + const notifyServiceInboundPatternsArray = this.formModel.get('notifyServiceInboundPatterns') as FormArray; + notifyServiceInboundPatternsArray.push(this.createInboundPatternFormGroup()); + } + + addOutboundPattern() { + const notifyServiceOutboundPatternsArray = this.formModel.get('notifyServiceOutboundPatterns') as FormArray; + notifyServiceOutboundPatternsArray.push(this.createOutboundPatternFormGroup()); + } + + removeOutboundPattern(index: number): void { + const patternsArray = this.formModel.get('notifyServiceOutboundPatterns') as FormArray; + const patternGroup = patternsArray.at(index) as FormGroup; + const patternValue = patternGroup.value; + + if (index < 0 || index >= patternsArray.length || patternValue.isNew) { + patternsArray.removeAt(index); + return; } - }, - ); - } - - generatePatchOperations(): any[] { - const patchOperations: any[] = []; - - this.createReplaceOperation(patchOperations, 'name', '/name'); - this.createReplaceOperation(patchOperations, 'description', '/description'); - this.createReplaceOperation(patchOperations, 'ldnUrl', '/ldnurl'); - this.createReplaceOperation(patchOperations, 'url', '/url'); - - this.handlePatterns(patchOperations, 'notifyServiceInboundPatterns'); - this.handlePatterns(patchOperations, 'notifyServiceOutboundPatterns'); - - this.deletedInboundPatterns.forEach(index => { - const removeOperation: Operation = { - op: 'remove', - path: `notifyServiceInboundPatterns[${index}]` - }; - patchOperations.push(removeOperation); - }); - - this.deletedOutboundPatterns.forEach(index => { - const removeOperation: Operation = { - op: 'remove', - path: `notifyServiceOutboundPatterns[${index}]` - }; - patchOperations.push(removeOperation); - }); - - return patchOperations; - } - - onSubmit() { - this.openConfirmModal(this.confirmModal); - } - - addInboundPattern() { - const notifyServiceInboundPatternsArray = this.formModel.get('notifyServiceInboundPatterns') as FormArray; - notifyServiceInboundPatternsArray.push(this.createInboundPatternFormGroup()); - } - - addOutboundPattern() { - const notifyServiceOutboundPatternsArray = this.formModel.get('notifyServiceOutboundPatterns') as FormArray; - notifyServiceOutboundPatternsArray.push(this.createOutboundPatternFormGroup()); - } - - removeOutboundPattern(index: number): void { - const patternsArray = this.formModel.get('notifyServiceOutboundPatterns') as FormArray; - const patternGroup = patternsArray.at(index) as FormGroup; - const patternValue = patternGroup.value; - - if (index < 0 || index >= patternsArray.length || patternValue.isNew) { - patternsArray.removeAt(index); - return; - } - this.deletedOutboundPatterns.push(index); + this.deletedOutboundPatterns.push(index); - patternsArray.removeAt(index); - this.cdRef.detectChanges(); - } - - - toggleAutomatic(i: number) { - const automaticControl = this.formModel.get(`notifyServiceInboundPatterns.${i}.automatic`); - if (automaticControl) { - automaticControl.setValue(!automaticControl.value); - } - } - - toggleEnabled() { - const newStatus = !this.formModel.get('enabled').value; - - const patchOperation: Operation = { - op: 'replace', - path: '/enabled', - value: newStatus, - }; - - this.ldnServicesService.patch(this.service, [patchOperation]).pipe( - getFirstCompletedRemoteData() - ).subscribe( - () => { - - this.formModel.get('enabled').setValue(newStatus); - this.cdRef.detectChanges(); - } - ); - } - - - closeModal() { - this.modalRef.close(); - this.cdRef.detectChanges(); - } - - openConfirmModal(content) { - this.modalRef = this.modalService.open(content); - } - - openResetFormModal(content) { - this.modalRef = this.modalService.open(content); - } - - patchService() { - this.deleteMarkedPatterns(); - const patchOperations = this.generatePatchOperations(); - - - this.ldnServicesService.patch(this.service, patchOperations).pipe( - getFirstCompletedRemoteData() - ).subscribe( - () => { - - this.closeModal(); - this.sendBack(); - this.notificationService.success(this.translateService.get('admin.registries.services-formats.modify.success.head'), - this.translateService.get('admin.registries.services-formats.modify.success.content')); - }, - (error) => { - this.notificationService.error(this.translateService.get('admin.registries.services-formats.modify.failure.head'), - this.translateService.get('admin.registries.services-formats.modify.failure.content')); - } - ); - - } - - private createReplaceOperation(patchOperations: any[], formControlName: string, path: string): void { - if (this.formModel.get(formControlName).dirty) { - patchOperations.push({ - op: 'replace', - path, - value: this.formModel.get(formControlName).value, - }); - } - } - - private handlePatterns(patchOperations: any[], formArrayName: string): void { - const patternsArray = this.formModel.get(formArrayName) as FormArray; - - for (let i = 0; i < patternsArray.length; i++) { - const patternGroup = patternsArray.at(i) as FormGroup; - const patternValue = patternGroup.value; - - if (patternGroup.dirty) { - if (patternValue.isNew) { - delete patternValue.isNew; - const addOperation = { - op: 'add', - path: `${formArrayName}/-`, - value: patternValue, - }; - patchOperations.push(addOperation); - } else { - const replaceOperation = { - op: 'replace', - path: `${formArrayName}[${i}]`, - value: patternValue, - }; - patchOperations.push(replaceOperation); - } - } - } - } - - private sendBack() { - this.router.navigateByUrl('admin/ldn/services'); - } - - resetFormAndLeave() { - this.sendBack(); - this.closeModal(); - } - - private createOutboundPatternFormGroup(): FormGroup { - return this.formBuilder.group({ - pattern: '', - constraint: '', - isNew: true, - }); - } - - private createInboundPatternFormGroup(): FormGroup { - return this.formBuilder.group({ - pattern: '', - constraint: '', - automatic: false, - isNew: true - }); - } - - private initializeOutboundPatternFormGroup(): FormGroup { - return this.formBuilder.group({ - pattern: '', - constraint: '', - }); - } - - private initializeInboundPatternFormGroup(): FormGroup { - return this.formBuilder.group({ - pattern: '', - constraint: '', - automatic: '', - }); - } - markForDeletion(index: number) { - if (!this.markedForDeletion.includes(index)) { - this.markedForDeletion.push(index); - } - } - - unmarkForDeletion(index: number) { - const i = this.markedForDeletion.indexOf(index); - if (i !== -1) { - this.markedForDeletion.splice(i, 1); - } - } - - deleteMarkedPatterns() { - this.markedForDeletion.sort((a, b) => b - a); - const patternsArray = this.formModel.get('notifyServiceInboundPatterns') as FormArray; - - for (const index of this.markedForDeletion) { - if (index >= 0 && index < patternsArray.length) { - this.deletedInboundPatterns.push(index); patternsArray.removeAt(index); - } + this.cdRef.detectChanges(); } - this.markedForDeletion = []; - } + + toggleAutomatic(i: number) { + const automaticControl = this.formModel.get(`notifyServiceInboundPatterns.${i}.automatic`); + if (automaticControl) { + automaticControl.setValue(!automaticControl.value); + } + } + + toggleEnabled() { + const newStatus = !this.formModel.get('enabled').value; + + const patchOperation: Operation = { + op: 'replace', + path: '/enabled', + value: newStatus, + }; + + this.ldnServicesService.patch(this.service, [patchOperation]).pipe( + getFirstCompletedRemoteData() + ).subscribe( + () => { + + this.formModel.get('enabled').setValue(newStatus); + this.cdRef.detectChanges(); + } + ); + } + + + closeModal() { + this.modalRef.close(); + this.cdRef.detectChanges(); + } + + openConfirmModal(content) { + this.modalRef = this.modalService.open(content); + } + + openResetFormModal(content) { + this.modalRef = this.modalService.open(content); + } + + patchService() { + this.deleteMarkedPatterns(); + const patchOperations = this.generatePatchOperations(); + + + this.ldnServicesService.patch(this.service, patchOperations).pipe( + getFirstCompletedRemoteData() + ).subscribe( + () => { + + this.closeModal(); + this.sendBack(); + this.notificationService.success(this.translateService.get('admin.registries.services-formats.modify.success.head'), + this.translateService.get('admin.registries.services-formats.modify.success.content')); + } + ); + + } + + resetFormAndLeave() { + this.sendBack(); + this.closeModal(); + } + + markForDeletion(index: number) { + if (!this.markedForDeletion.includes(index)) { + this.markedForDeletion.push(index); + } + } + + unmarkForDeletion(index: number) { + const i = this.markedForDeletion.indexOf(index); + if (i !== -1) { + this.markedForDeletion.splice(i, 1); + } + } + + deleteMarkedPatterns() { + this.markedForDeletion.sort((a, b) => b - a); + const patternsArray = this.formModel.get('notifyServiceInboundPatterns') as FormArray; + + for (const index of this.markedForDeletion) { + if (index >= 0 && index < patternsArray.length) { + this.deletedInboundPatterns.push(index); + patternsArray.removeAt(index); + } + } + + this.markedForDeletion = []; + } + + private createReplaceOperation(patchOperations: any[], formControlName: string, path: string): void { + if (this.formModel.get(formControlName).dirty) { + patchOperations.push({ + op: 'replace', + path, + value: this.formModel.get(formControlName).value, + }); + } + } + + private handlePatterns(patchOperations: any[], formArrayName: string): void { + const patternsArray = this.formModel.get(formArrayName) as FormArray; + + for (let i = 0; i < patternsArray.length; i++) { + const patternGroup = patternsArray.at(i) as FormGroup; + const patternValue = patternGroup.value; + + if (patternGroup.dirty) { + if (patternValue.isNew) { + delete patternValue.isNew; + const addOperation = { + op: 'add', + path: `${formArrayName}/-`, + value: patternValue, + }; + patchOperations.push(addOperation); + } else { + const replaceOperation = { + op: 'replace', + path: `${formArrayName}[${i}]`, + value: patternValue, + }; + patchOperations.push(replaceOperation); + } + } + } + } + + private sendBack() { + this.router.navigateByUrl('admin/ldn/services'); + } + + private createOutboundPatternFormGroup(): FormGroup { + return this.formBuilder.group({ + pattern: '', + constraint: '', + isNew: true, + }); + } + + private createInboundPatternFormGroup(): FormGroup { + return this.formBuilder.group({ + pattern: '', + constraint: '', + automatic: false, + isNew: true + }); + } + + private initializeOutboundPatternFormGroup(): FormGroup { + return this.formBuilder.group({ + pattern: '', + constraint: '', + }); + } + + private initializeInboundPatternFormGroup(): FormGroup { + return this.formBuilder.group({ + pattern: '', + constraint: '', + automatic: '', + }); + } } diff --git a/src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.html b/src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.html index b82b05af77..f1afa886f1 100644 --- a/src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.html +++ b/src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.html @@ -1,263 +1,266 @@
-
-
-

{{ 'ldn-create-service.title' | translate }}

-
- -
- - -
- -
-   -
- - -
- - -
- -
-   -
- - -
- - -
- -
-   -
- - -
- - -
- -
-   -
- - -
-
- -
-
- -
-
- -
-
-
-
- -
- - - - -
-
- + +
+

{{ 'ldn-create-service.title' | translate }}

+
+ +
+ +
- -
- - - +
+  
-
- -
-
-
+ +
+ +
-
- +
+  
-
- -
- {{ 'ldn-new-service.form.label.addPattern' | translate }} - - -
-   -
- - -
-
- -
-
- -
-
-
-
-
-
- -
- - - - -
-
- + +
+ +
-
- - + +
+   +
+ + +
+ + +
+ +
+   +
+ + +
+
+ +
+
+ +
+
+ +
+
+
+
+ +
+ + + + +
+
+ +
+ + +
+ + + +
+ +
+ +
+
+
+
+ +
+ +
+
-
- -
-
-
+ {{ 'ldn-new-service.form.label.addPattern' | translate }} + + +
+  
-
- + +
+
+ +
+
+ +
+
+
+
+
-
- -
+
- {{ 'ldn-new-service.form.label.addPattern' | translate }} + + + +
+
+ +
+
+ + + +
+ +
+ +
+
+
+
+ +
+ +
+
+
+ +
+ + {{ 'ldn-new-service.form.label.addPattern' | translate }} -
-   -
+
+   +
- + - +
-
+
- + - -
-
+
- + - -
diff --git a/src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.scss b/src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.scss index 523653381b..f0fdcd81a2 100644 --- a/src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.scss +++ b/src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.scss @@ -27,12 +27,13 @@ textarea { resize: none; } -.add-pattern-link{ +.add-pattern-link { color: #0048ff; cursor: pointer; margin-left: 10px; } -.remove-pattern-link{ + +.remove-pattern-link { color: #e34949; cursor: pointer; margin-left: 10px; @@ -75,7 +76,6 @@ textarea { } - .toggle-switch .slider { width: 22px; height: 22px; @@ -99,21 +99,21 @@ textarea { cursor: pointer; } -.label-box{ - margin-left:11px; +.label-box { + margin-left: 11px; } -.label-box-2{ - margin-left:14px; +.label-box-2 { + margin-left: 14px; } -.label-box-3{ - margin-left:5px; +.label-box-3 { + margin-left: 5px; } form button.btn.btn-primary[type="submit"] { position: absolute; - bottom: 0px; + bottom: 0; right: -10px; } diff --git a/src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.spec.ts b/src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.spec.ts index 3ae834d642..757b617091 100644 --- a/src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.spec.ts +++ b/src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.spec.ts @@ -3,23 +3,23 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { LdnServiceFormComponent } from './ldn-service-form.component'; describe('LdnServiceFormComponent', () => { - let component: LdnServiceFormComponent; - let fixture: ComponentFixture; + let component: LdnServiceFormComponent; + let fixture: ComponentFixture; - beforeEach(async () => { - await TestBed.configureTestingModule({ - declarations: [ LdnServiceFormComponent ] - }) - .compileComponents(); - }); + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [LdnServiceFormComponent] + }) + .compileComponents(); + }); - beforeEach(() => { - fixture = TestBed.createComponent(LdnServiceFormComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + beforeEach(() => { + fixture = TestBed.createComponent(LdnServiceFormComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); - it('should create', () => { - expect(component).toBeTruthy(); - }); + it('should create', () => { + expect(component).toBeTruthy(); + }); }); diff --git a/src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts b/src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts index 7e9a1e148f..ff42ffb4dc 100644 --- a/src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts +++ b/src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts @@ -30,203 +30,193 @@ import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; @Component({ - selector: 'ds-ldn-service-form', - templateUrl: './ldn-service-form.component.html', - styleUrls: ['./ldn-service-form.component.scss'], - animations: [ - trigger('toggleAnimation', [ - state('true', style({})), - state('false', style({})), - transition('true <=> false', animate('300ms ease-in')), - ]), - ], + selector: 'ds-ldn-service-form', + templateUrl: './ldn-service-form.component.html', + styleUrls: ['./ldn-service-form.component.scss'], + animations: [ + trigger('toggleAnimation', [ + state('true', style({})), + state('false', style({})), + transition('true <=> false', animate('300ms ease-in')), + ]), + ], }) export class LdnServiceFormComponent implements OnInit { - formModel: FormGroup; - private modalRef: any; - @ViewChild('confirmModal', {static: true}) confirmModal: TemplateRef; - @ViewChild('resetFormModal', {static: true}) resetFormModal: TemplateRef; - - - public inboundPatterns: object[] = notifyPatterns; - public outboundPatterns: object[] = notifyPatterns; - itemfiltersRD$: Observable>>; - config: FindListOptions = Object.assign(new FindListOptions(), { - elementsPerPage: 20 - }); - pageConfig: PaginationComponentOptions = Object.assign(new PaginationComponentOptions(), { - id: 'po', - pageSize: 20 - }); - - - - @Input() public name: string; - @Input() public description: string; - @Input() public url: string; - @Input() public ldnUrl: string; - @Input() public inboundPattern: string; - @Input() public outboundPattern: string; - @Input() public constraint: string; - @Input() public automatic: boolean; - - @Input() public headerKey: string; - @Output() submitForm: EventEmitter = new EventEmitter(); - @Output() cancelForm: EventEmitter = new EventEmitter(); - - constructor( - private ldnServicesService: LdnServicesService, - private ldnItemfiltersService: LdnItemfiltersService, - private formBuilder: FormBuilder, - private router: Router, - private notificationsService: NotificationsService, - private translateService: TranslateService, - private cdRef: ChangeDetectorRef, - protected modalService: NgbModal, - - ) { - - this.formModel = this.formBuilder.group({ - enabled: true, - id: [''], - name: ['', Validators.required], - description: [''], - url: ['', Validators.required], - ldnUrl: ['', Validators.required], - inboundPattern: [''], - outboundPattern: [''], - constraintPattern: [''], - notifyServiceInboundPatterns: this.formBuilder.array([this.createInboundPatternFormGroup()]), - notifyServiceOutboundPatterns: this.formBuilder.array([this.createOutboundPatternFormGroup()]), - type: LDN_SERVICE.value, + formModel: FormGroup; + @ViewChild('confirmModal', {static: true}) confirmModal: TemplateRef; + @ViewChild('resetFormModal', {static: true}) resetFormModal: TemplateRef; + public inboundPatterns: object[] = notifyPatterns; + public outboundPatterns: object[] = notifyPatterns; + itemfiltersRD$: Observable>>; + config: FindListOptions = Object.assign(new FindListOptions(), { + elementsPerPage: 20 }); - } - - ngOnInit(): void { - this.setItemfilters(); - - } - setItemfilters() { - this.itemfiltersRD$ = this.ldnItemfiltersService.findAll().pipe( - getFirstCompletedRemoteData()); - this.itemfiltersRD$.subscribe((rd: RemoteData>) => { - if (rd.hasSucceeded) { - } + pageConfig: PaginationComponentOptions = Object.assign(new PaginationComponentOptions(), { + id: 'po', + pageSize: 20 }); - } + @Input() public name: string; + @Input() public description: string; + @Input() public url: string; + @Input() public ldnUrl: string; + @Input() public inboundPattern: string; + @Input() public outboundPattern: string; + @Input() public constraint: string; + @Input() public automatic: boolean; + @Input() public headerKey: string; + @Output() submitForm: EventEmitter = new EventEmitter(); + @Output() cancelForm: EventEmitter = new EventEmitter(); + private modalRef: any; - onSubmit() { - this.openConfirmModal(this.confirmModal); - } + constructor( + private ldnServicesService: LdnServicesService, + private ldnItemfiltersService: LdnItemfiltersService, + private formBuilder: FormBuilder, + private router: Router, + private notificationsService: NotificationsService, + private translateService: TranslateService, + private cdRef: ChangeDetectorRef, + protected modalService: NgbModal, + ) { - openConfirmModal(content) { - this.modalRef = this.modalService.open(content); - } - - openResetFormModal(content) { - this.modalRef = this.modalService.open(content); - } - createService() { - this.formModel.get('name').markAsTouched(); - this.formModel.get('url').markAsTouched(); - this.formModel.get('ldnUrl').markAsTouched(); - - const name = this.formModel.get('name').value; - const url = this.formModel.get('url').value; - const ldnUrl = this.formModel.get('ldnUrl').value; - - if (!name || !url || !ldnUrl) { - this.closeModal(); - return; + this.formModel = this.formBuilder.group({ + enabled: true, + id: [''], + name: ['', Validators.required], + description: [''], + url: ['', Validators.required], + ldnUrl: ['', Validators.required], + inboundPattern: [''], + outboundPattern: [''], + constraintPattern: [''], + notifyServiceInboundPatterns: this.formBuilder.array([this.createInboundPatternFormGroup()]), + notifyServiceOutboundPatterns: this.formBuilder.array([this.createOutboundPatternFormGroup()]), + type: LDN_SERVICE.value, + }); } - const values = this.formModel.value; + ngOnInit(): void { + this.setItemfilters(); - const inboundPatternValue = this.formModel.get('inboundPattern').value; - const outboundPatternValue = this.formModel.get('outboundPattern').value; - - if (inboundPatternValue === '') { - values.notifyServiceInboundPatterns = []; - } - if (outboundPatternValue === '') { - values.notifyServiceOutboundPatterns = []; } - const ldnServiceData = this.ldnServicesService.create(values); + setItemfilters() { + this.itemfiltersRD$ = this.ldnItemfiltersService.findAll().pipe( + getFirstCompletedRemoteData()); + } - ldnServiceData.pipe( - getFirstCompletedRemoteData() - ).subscribe((rd: RemoteData) => { - if (rd.hasSucceeded) { - this.notificationsService.success(this.translateService.get('ldn-service-notification.created.success.title')); - (this.translateService.get('ldn-service-notification.created.success.title'), - this.translateService.get('ldn-service-notification.created.success.body')); + onSubmit() { + this.openConfirmModal(this.confirmModal); + } + + openConfirmModal(content) { + this.modalRef = this.modalService.open(content); + } + + openResetFormModal(content) { + this.modalRef = this.modalService.open(content); + } + + createService() { + this.formModel.get('name').markAsTouched(); + this.formModel.get('url').markAsTouched(); + this.formModel.get('ldnUrl').markAsTouched(); + + const name = this.formModel.get('name').value; + const url = this.formModel.get('url').value; + const ldnUrl = this.formModel.get('ldnUrl').value; + + if (!name || !url || !ldnUrl) { + this.closeModal(); + return; + } + + const values = this.formModel.value; + + const inboundPatternValue = this.formModel.get('inboundPattern').value; + const outboundPatternValue = this.formModel.get('outboundPattern').value; + + if (inboundPatternValue === '') { + values.notifyServiceInboundPatterns = []; + } + if (outboundPatternValue === '') { + values.notifyServiceOutboundPatterns = []; + } + + const ldnServiceData = this.ldnServicesService.create(values); + + ldnServiceData.pipe( + getFirstCompletedRemoteData() + ).subscribe((rd: RemoteData) => { + if (rd.hasSucceeded) { + this.notificationsService.success(this.translateService.get('ldn-service-notification.created.success.title')); + (this.translateService.get('ldn-service-notification.created.success.title'), + this.translateService.get('ldn-service-notification.created.success.body')); + this.sendBack(); + this.closeModal(); + } else { + this.notificationsService.error(this.translateService.get('notification.created.failure')); + } + }); + } + + + resetFormAndLeave() { this.sendBack(); this.closeModal(); - } else { - this.notificationsService.error(this.translateService.get('notification.created.failure')); - } - }); - } - - - resetFormAndLeave() { - this.sendBack(); - this.closeModal(); - } - - closeModal() { - this.modalRef.close(); - this.cdRef.detectChanges(); - } - - addInboundPattern() { - const notifyServiceInboundPatternsArray = this.formModel.get('notifyServiceInboundPatterns') as FormArray; - notifyServiceInboundPatternsArray.push(this.createInboundPatternFormGroup()); - } - - removeInboundPattern(index: number) { - const notifyServiceInboundPatternsArray = this.formModel.get('notifyServiceInboundPatterns') as FormArray; - notifyServiceInboundPatternsArray.removeAt(index); - } - - addOutboundPattern() { - const notifyServiceOutboundPatternsArray = this.formModel.get('notifyServiceOutboundPatterns') as FormArray; - notifyServiceOutboundPatternsArray.push(this.createOutboundPatternFormGroup()); - } - - removeOutboundPattern(index: number) { - const notifyServiceOutboundPatternsArray = this.formModel.get('notifyServiceOutboundPatterns') as FormArray; - notifyServiceOutboundPatternsArray.removeAt(index); - } - - toggleAutomatic(i: number) { - const automaticControl = this.formModel.get(`notifyServiceInboundPatterns.${i}.automatic`); - if (automaticControl) { - automaticControl.setValue(!automaticControl.value); } - } - private sendBack() { - this.router.navigateByUrl('admin/ldn/services'); - } + closeModal() { + this.modalRef.close(); + this.cdRef.detectChanges(); + } + + addInboundPattern() { + const notifyServiceInboundPatternsArray = this.formModel.get('notifyServiceInboundPatterns') as FormArray; + notifyServiceInboundPatternsArray.push(this.createInboundPatternFormGroup()); + } + + removeInboundPattern(index: number) { + const notifyServiceInboundPatternsArray = this.formModel.get('notifyServiceInboundPatterns') as FormArray; + notifyServiceInboundPatternsArray.removeAt(index); + } + + addOutboundPattern() { + const notifyServiceOutboundPatternsArray = this.formModel.get('notifyServiceOutboundPatterns') as FormArray; + notifyServiceOutboundPatternsArray.push(this.createOutboundPatternFormGroup()); + } + + removeOutboundPattern(index: number) { + const notifyServiceOutboundPatternsArray = this.formModel.get('notifyServiceOutboundPatterns') as FormArray; + notifyServiceOutboundPatternsArray.removeAt(index); + } + + toggleAutomatic(i: number) { + const automaticControl = this.formModel.get(`notifyServiceInboundPatterns.${i}.automatic`); + if (automaticControl) { + automaticControl.setValue(!automaticControl.value); + } + } + + private sendBack() { + this.router.navigateByUrl('admin/ldn/services'); + } + private createOutboundPatternFormGroup(): FormGroup { + return this.formBuilder.group({ + pattern: [''], + constraint: [''], + }); + } - private createOutboundPatternFormGroup(): FormGroup { - return this.formBuilder.group({ - pattern: [''], - constraint: [''], - }); - } - - private createInboundPatternFormGroup(): FormGroup { - return this.formBuilder.group({ - pattern: [''], - constraint: [''], - automatic: false - }); - } + private createInboundPatternFormGroup(): FormGroup { + return this.formBuilder.group({ + pattern: [''], + constraint: [''], + automatic: false + }); + } } diff --git a/src/app/admin/admin-ldn-services/ldn-service-new/ldn-service-new.component.spec.ts b/src/app/admin/admin-ldn-services/ldn-service-new/ldn-service-new.component.spec.ts index 4994823004..d49d393195 100644 --- a/src/app/admin/admin-ldn-services/ldn-service-new/ldn-service-new.component.spec.ts +++ b/src/app/admin/admin-ldn-services/ldn-service-new/ldn-service-new.component.spec.ts @@ -3,23 +3,23 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { LdnServiceNewComponent } from './ldn-service-new.component'; describe('LdnServiceNewComponent', () => { - let component: LdnServiceNewComponent; - let fixture: ComponentFixture; + let component: LdnServiceNewComponent; + let fixture: ComponentFixture; - beforeEach(async () => { - await TestBed.configureTestingModule({ - declarations: [ LdnServiceNewComponent ] - }) - .compileComponents(); - }); + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [LdnServiceNewComponent] + }) + .compileComponents(); + }); - beforeEach(() => { - fixture = TestBed.createComponent(LdnServiceNewComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + beforeEach(() => { + fixture = TestBed.createComponent(LdnServiceNewComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); - it('should create', () => { - expect(component).toBeTruthy(); - }); + it('should create', () => { + expect(component).toBeTruthy(); + }); }); diff --git a/src/app/admin/admin-ldn-services/ldn-service-new/ldn-service-new.component.ts b/src/app/admin/admin-ldn-services/ldn-service-new/ldn-service-new.component.ts index daf1653cd1..e92c06dc26 100644 --- a/src/app/admin/admin-ldn-services/ldn-service-new/ldn-service-new.component.ts +++ b/src/app/admin/admin-ldn-services/ldn-service-new/ldn-service-new.component.ts @@ -4,25 +4,24 @@ import { LdnService } from "../ldn-services-model/ldn-services.model"; import { ActivatedRoute } from "@angular/router"; import { ProcessDataService } from "../../../core/data/processes/process-data.service"; import { LinkService } from "../../../core/cache/builders/link.service"; -import { getFirstSucceededRemoteDataPayload } from "../../../core/shared/operators"; @Component({ - selector: 'ds-ldn-service-new', - templateUrl: './ldn-service-new.component.html', - styleUrls: ['./ldn-service-new.component.scss'] + selector: 'ds-ldn-service-new', + templateUrl: './ldn-service-new.component.html', + styleUrls: ['./ldn-service-new.component.scss'] }) export class LdnServiceNewComponent implements OnInit { - /** - * Emits preselected process if there is one - */ - ldnService$?: Observable; + /** + * Emits preselected process if there is one + */ + ldnService$?: Observable; - constructor(private route: ActivatedRoute, private processService: ProcessDataService, private linkService: LinkService) { - } + constructor(private route: ActivatedRoute, private processService: ProcessDataService, private linkService: LinkService) { + } - /** - * If there's an id parameter, use this the process with this identifier as presets for the form - */ - ngOnInit() { - } + /** + * If there's an id parameter, use this the process with this identifier as presets for the form + */ + ngOnInit() { + } } diff --git a/src/app/admin/admin-ldn-services/ldn-service-serviceMock/ldnServicesRD$-mock.ts b/src/app/admin/admin-ldn-services/ldn-service-serviceMock/ldnServicesRD$-mock.ts index fccb374b5f..b1a954b9d6 100644 --- a/src/app/admin/admin-ldn-services/ldn-service-serviceMock/ldnServicesRD$-mock.ts +++ b/src/app/admin/admin-ldn-services/ldn-service-serviceMock/ldnServicesRD$-mock.ts @@ -37,8 +37,6 @@ export const mockLdnService: LdnService = { }; - - const mockLdnServices = { payload: { elementsPerPage: 20, @@ -52,7 +50,7 @@ const mockLdnServices = { page: [mockLdnService], type: LDN_SERVICE, self: undefined, - getPageLength: function() { + getPageLength: function () { return this.page.length; }, _links: { @@ -67,7 +65,5 @@ const mockLdnServices = { }; - - // Create a mock ldnServicesRD$ observable export const mockLdnServicesRD$: Observable>> = of((mockLdnServices as unknown) as RemoteData>); diff --git a/src/app/admin/admin-ldn-services/ldn-services-data/ldn-itemfilters-data.service.ts b/src/app/admin/admin-ldn-services/ldn-services-data/ldn-itemfilters-data.service.ts index 692e1a5db9..babb00c959 100644 --- a/src/app/admin/admin-ldn-services/ldn-services-data/ldn-itemfilters-data.service.ts +++ b/src/app/admin/admin-ldn-services/ldn-services-data/ldn-itemfilters-data.service.ts @@ -17,7 +17,6 @@ import { Itemfilter } from '../ldn-services-model/ldn-service-itemfilters'; import { PaginatedList } from '../../../core/data/paginated-list.model'; - /** * A service responsible for fetching/sending data from/to the REST API on the itemfilters endpoint */ @@ -38,11 +37,11 @@ export class LdnItemfiltersService extends IdentifiableDataService i this.findAllData = new FindAllDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, this.responseMsToLive); } - getEndpoint() { - return this.halService.getEndpoint(this.linkPath); - } + getEndpoint() { + return this.halService.getEndpoint(this.linkPath); + } - findAll(options?: FindListOptions, useCachedVersionIfAvailable?: boolean, reRequestOnStale?: boolean, ...linksToFollow: FollowLinkConfig[]): Observable>> { - return this.findAllData.findAll(options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow); - } + findAll(options?: FindListOptions, useCachedVersionIfAvailable?: boolean, reRequestOnStale?: boolean, ...linksToFollow: FollowLinkConfig[]): Observable>> { + return this.findAllData.findAll(options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow); + } } diff --git a/src/app/admin/admin-ldn-services/ldn-services-data/ldn-services-data.service.ts b/src/app/admin/admin-ldn-services/ldn-services-data/ldn-services-data.service.ts index d2ef16fada..35f9bee04f 100644 --- a/src/app/admin/admin-ldn-services/ldn-services-data/ldn-services-data.service.ts +++ b/src/app/admin/admin-ldn-services/ldn-services-data/ldn-services-data.service.ts @@ -38,90 +38,89 @@ import { hasValue } from 'src/app/shared/empty.util'; @Injectable() @dataService(LDN_SERVICE) export class LdnServicesService extends IdentifiableDataService implements FindAllData, DeleteData, PatchData, CreateData { - createData: CreateDataImpl; - private findAllData: FindAllDataImpl; - private deleteData: DeleteDataImpl; - private patchData: PatchDataImpl; - private comparator: ChangeAnalyzer; + createData: CreateDataImpl; + private findAllData: FindAllDataImpl; + private deleteData: DeleteDataImpl; + private patchData: PatchDataImpl; + private comparator: ChangeAnalyzer; - constructor( - protected requestService: RequestService, - protected rdbService: RemoteDataBuildService, - protected objectCache: ObjectCacheService, - protected halService: HALEndpointService, - protected notificationsService: NotificationsService, - ) { - super('ldnservices', requestService, rdbService, objectCache, halService); + constructor( + protected requestService: RequestService, + protected rdbService: RemoteDataBuildService, + protected objectCache: ObjectCacheService, + protected halService: HALEndpointService, + protected notificationsService: NotificationsService, + ) { + super('ldnservices', requestService, rdbService, objectCache, halService); - this.findAllData = new FindAllDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, this.responseMsToLive); - this.deleteData = new DeleteDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, notificationsService, this.responseMsToLive, this.constructIdEndpoint); - this.patchData = new PatchDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, this.comparator, this.responseMsToLive, this.constructIdEndpoint); - this.createData = new CreateDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, notificationsService, this.responseMsToLive); - } + this.findAllData = new FindAllDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, this.responseMsToLive); + this.deleteData = new DeleteDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, notificationsService, this.responseMsToLive, this.constructIdEndpoint); + this.patchData = new PatchDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, this.comparator, this.responseMsToLive, this.constructIdEndpoint); + this.createData = new CreateDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, notificationsService, this.responseMsToLive); + } - create(object: LdnService): Observable> { - return this.createData.create(object); - } + create(object: LdnService): Observable> { + return this.createData.create(object); + } - patch(object: LdnService, operations: Operation[]): Observable> { - return this.patchData.patch(object, operations); - } + patch(object: LdnService, operations: Operation[]): Observable> { + return this.patchData.patch(object, operations); + } - update(object: LdnService): Observable> { - return this.patchData.update(object); - } + update(object: LdnService): Observable> { + return this.patchData.update(object); + } - commitUpdates(method?: RestRequestMethod): void { - return this.patchData.commitUpdates(method); - } + commitUpdates(method?: RestRequestMethod): void { + return this.patchData.commitUpdates(method); + } - createPatchFromCache(object: LdnService): Observable { - return this.patchData.createPatchFromCache(object); - } + createPatchFromCache(object: LdnService): Observable { + return this.patchData.createPatchFromCache(object); + } - findAll(options?: FindListOptions, useCachedVersionIfAvailable?: boolean, reRequestOnStale?: boolean, ...linksToFollow: FollowLinkConfig[]): Observable>> { - return this.findAllData.findAll(options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow); - } + findAll(options?: FindListOptions, useCachedVersionIfAvailable?: boolean, reRequestOnStale?: boolean, ...linksToFollow: FollowLinkConfig[]): Observable>> { + return this.findAllData.findAll(options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow); + } - public delete(objectId: string, copyVirtualMetadata?: string[]): Observable> { - return this.deleteData.delete(objectId, copyVirtualMetadata); - } + public delete(objectId: string, copyVirtualMetadata?: string[]): Observable> { + return this.deleteData.delete(objectId, copyVirtualMetadata); + } - public deleteByHref(href: string, copyVirtualMetadata?: string[]): Observable> { - return this.deleteData.deleteByHref(href, copyVirtualMetadata); - } + public deleteByHref(href: string, copyVirtualMetadata?: string[]): Observable> { + return this.deleteData.deleteByHref(href, copyVirtualMetadata); + } - public invoke(serviceName: string, serviceId: string, parameters: ldnServiceConstrain[], files: File[]): Observable> { - const requestId = this.requestService.generateRequestId(); - this.getBrowseEndpoint().pipe( - take(1), - map((endpoint: string) => new URLCombiner(endpoint, serviceName, 'processes', serviceId).toString()), - map((endpoint: string) => { - const body = this.getInvocationFormData(parameters, files); - return new MultipartPostRequest(requestId, endpoint, body); - }) - ).subscribe((request: RestRequest) => this.requestService.send(request)); + public invoke(serviceName: string, serviceId: string, parameters: ldnServiceConstrain[], files: File[]): Observable> { + const requestId = this.requestService.generateRequestId(); + this.getBrowseEndpoint().pipe( + take(1), + map((endpoint: string) => new URLCombiner(endpoint, serviceName, 'processes', serviceId).toString()), + map((endpoint: string) => { + const body = this.getInvocationFormData(parameters, files); + return new MultipartPostRequest(requestId, endpoint, body); + }) + ).subscribe((request: RestRequest) => this.requestService.send(request)); - return this.rdbService.buildFromRequestUUID(requestId); - } + return this.rdbService.buildFromRequestUUID(requestId); + } + public ldnServiceWithNameExistsAndCanExecute(scriptName: string): Observable { + return this.findById(scriptName).pipe( + getFirstCompletedRemoteData(), + map((rd: RemoteData) => { + return hasValue(rd.payload); + }), + ); + } - private getInvocationFormData(constrain: ldnServiceConstrain[], files: File[]): FormData { - const form: FormData = new FormData(); - form.set('properties', JSON.stringify(constrain)); - files.forEach((file: File) => { - form.append('file', file); - }); - return form; - } - - public ldnServiceWithNameExistsAndCanExecute(scriptName: string): Observable { - return this.findById(scriptName).pipe( - getFirstCompletedRemoteData(), - map((rd: RemoteData) => { - return hasValue(rd.payload); - }), - ); - } + private getInvocationFormData(constrain: ldnServiceConstrain[], files: File[]): FormData { + const form: FormData = new FormData(); + form.set('properties', JSON.stringify(constrain)); + files.forEach((file: File) => { + form.append('file', file); + }); + return form; + } } diff --git a/src/app/admin/admin-ldn-services/ldn-services-directory/ldn-services-directory.component.html b/src/app/admin/admin-ldn-services/ldn-services-directory/ldn-services-directory.component.html index 6753c6e90c..45c2106468 100644 --- a/src/app/admin/admin-ldn-services/ldn-services-directory/ldn-services-directory.component.html +++ b/src/app/admin/admin-ldn-services/ldn-services-directory/ldn-services-directory.component.html @@ -15,34 +15,34 @@
- - - - - - + + + + + + @@ -72,7 +72,8 @@
-
diff --git a/src/app/admin/admin-ldn-services/ldn-services-directory/ldn-services-directory.component.spec.ts b/src/app/admin/admin-ldn-services/ldn-services-directory/ldn-services-directory.component.spec.ts index bedcabb271..0999c82c19 100644 --- a/src/app/admin/admin-ldn-services/ldn-services-directory/ldn-services-directory.component.spec.ts +++ b/src/app/admin/admin-ldn-services/ldn-services-directory/ldn-services-directory.component.spec.ts @@ -3,23 +3,23 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ServicesDirectoryComponent } from './services-directory.component'; describe('ServicesDirectoryComponent', () => { - let component: ServicesDirectoryComponent; - let fixture: ComponentFixture; + let component: ServicesDirectoryComponent; + let fixture: ComponentFixture; - beforeEach(async () => { - await TestBed.configureTestingModule({ - declarations: [ ServicesDirectoryComponent ] - }) - .compileComponents(); - }); + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ServicesDirectoryComponent] + }) + .compileComponents(); + }); - beforeEach(() => { - fixture = TestBed.createComponent(ServicesDirectoryComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + beforeEach(() => { + fixture = TestBed.createComponent(ServicesDirectoryComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); - it('should create', () => { - expect(component).toBeTruthy(); - }); + it('should create', () => { + expect(component).toBeTruthy(); + }); }); diff --git a/src/app/admin/admin-ldn-services/ldn-services-directory/ldn-services-directory.component.ts b/src/app/admin/admin-ldn-services/ldn-services-directory/ldn-services-directory.component.ts index 91904d6bc5..3db9231ac2 100644 --- a/src/app/admin/admin-ldn-services/ldn-services-directory/ldn-services-directory.component.ts +++ b/src/app/admin/admin-ldn-services/ldn-services-directory/ldn-services-directory.component.ts @@ -1,4 +1,12 @@ -import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnDestroy, OnInit, TemplateRef, ViewChild } from '@angular/core'; +import { + ChangeDetectionStrategy, + ChangeDetectorRef, + Component, + OnDestroy, + OnInit, + TemplateRef, + ViewChild +} from '@angular/core'; import { Observable, Subscription } from 'rxjs'; import { RemoteData } from '../../../core/data/remote-data'; import { PaginatedList } from '../../../core/data/paginated-list.model'; @@ -11,130 +19,128 @@ import { PaginationService } from 'src/app/core/pagination/pagination.service'; import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; import { hasValue } from '../../../shared/empty.util'; import { Operation } from 'fast-json-patch'; -import { getFirstCompletedRemoteData } from '../../../core/shared/operators'; +import { getFirstCompletedRemoteData } from '../../../core/shared/operators'; import { NotificationsService } from '../../../shared/notifications/notifications.service'; import { TranslateService } from '@ngx-translate/core'; @Component({ - selector: 'ds-ldn-services-directory', - templateUrl: './ldn-services-directory.component.html', - styleUrls: ['./ldn-services-directory.component.scss'], - changeDetection: ChangeDetectionStrategy.Default + selector: 'ds-ldn-services-directory', + templateUrl: './ldn-services-directory.component.html', + styleUrls: ['./ldn-services-directory.component.scss'], + changeDetection: ChangeDetectionStrategy.Default }) export class LdnServicesOverviewComponent implements OnInit, OnDestroy { - selectedServiceId: string | number | null = null; - servicesData: any[] = []; - @ViewChild('deleteModal', {static: true}) deleteModal: TemplateRef; - ldnServicesRD$: Observable>>; - config: FindListOptions = Object.assign(new FindListOptions(), { - elementsPerPage: 20 - }); - pageConfig: PaginationComponentOptions = Object.assign(new PaginationComponentOptions(), { - id: 'po', - pageSize: 20 - }); - isProcessingSub: Subscription; - private modalRef: any; + selectedServiceId: string | number | null = null; + servicesData: any[] = []; + @ViewChild('deleteModal', {static: true}) deleteModal: TemplateRef; + ldnServicesRD$: Observable>>; + config: FindListOptions = Object.assign(new FindListOptions(), { + elementsPerPage: 20 + }); + pageConfig: PaginationComponentOptions = Object.assign(new PaginationComponentOptions(), { + id: 'po', + pageSize: 20 + }); + isProcessingSub: Subscription; + private modalRef: any; - constructor( - protected ldnServicesService: LdnServicesService, - protected paginationService: PaginationService, - protected modalService: NgbModal, - private cdRef: ChangeDetectorRef, - private notificationService: NotificationsService, - private translateService: TranslateService, - ) { - } - - ngOnInit(): void { - this.setLdnServices(); - } - - setLdnServices() { - this.ldnServicesRD$ = this.paginationService.getFindListOptions(this.pageConfig.id, this.config).pipe( - switchMap((config) => this.ldnServicesService.findAll(config, false, false).pipe( - getFirstCompletedRemoteData() - )) - ); - } - - ngOnDestroy(): void { - this.paginationService.clearPagination(this.pageConfig.id); - if (hasValue(this.isProcessingSub)) { - this.isProcessingSub.unsubscribe(); + constructor( + protected ldnServicesService: LdnServicesService, + protected paginationService: PaginationService, + protected modalService: NgbModal, + private cdRef: ChangeDetectorRef, + private notificationService: NotificationsService, + private translateService: TranslateService, + ) { } - } - openDeleteModal(content) { - this.modalRef = this.modalService.open(content); - } + ngOnInit(): void { + this.setLdnServices(); + } - closeModal() { - this.modalRef.close(); - this.cdRef.detectChanges(); - } + setLdnServices() { + this.ldnServicesRD$ = this.paginationService.getFindListOptions(this.pageConfig.id, this.config).pipe( + switchMap((config) => this.ldnServicesService.findAll(config, false, false).pipe( + getFirstCompletedRemoteData() + )) + ); + } - selectServiceToDelete(serviceId: number) { - this.selectedServiceId = serviceId; - this.openDeleteModal(this.deleteModal); - } + ngOnDestroy(): void { + this.paginationService.clearPagination(this.pageConfig.id); + if (hasValue(this.isProcessingSub)) { + this.isProcessingSub.unsubscribe(); + } + } - deleteSelected(serviceId: string, ldnServicesService: LdnServicesService): void { - if (this.selectedServiceId !== null) { - ldnServicesService.delete(serviceId).pipe(getFirstCompletedRemoteData()).subscribe((rd: RemoteData) => { - if (rd.hasSucceeded) { - this.servicesData = this.servicesData.filter(service => service.id !== serviceId); - this.ldnServicesRD$ = this.ldnServicesRD$.pipe( - map((remoteData: RemoteData>) => { - if (remoteData.hasSucceeded) { - remoteData.payload.page = remoteData.payload.page.filter(service => service.id.toString() !== serviceId); + openDeleteModal(content) { + this.modalRef = this.modalService.open(content); + } + + closeModal() { + this.modalRef.close(); + this.cdRef.detectChanges(); + } + + selectServiceToDelete(serviceId: number) { + this.selectedServiceId = serviceId; + this.openDeleteModal(this.deleteModal); + } + + deleteSelected(serviceId: string, ldnServicesService: LdnServicesService): void { + if (this.selectedServiceId !== null) { + ldnServicesService.delete(serviceId).pipe(getFirstCompletedRemoteData()).subscribe((rd: RemoteData) => { + if (rd.hasSucceeded) { + this.servicesData = this.servicesData.filter(service => service.id !== serviceId); + this.ldnServicesRD$ = this.ldnServicesRD$.pipe( + map((remoteData: RemoteData>) => { + if (remoteData.hasSucceeded) { + remoteData.payload.page = remoteData.payload.page.filter(service => service.id.toString() !== serviceId); + } + return remoteData; + }) + ); + this.cdRef.detectChanges(); + this.closeModal(); + this.notificationService.success(this.translateService.get('ldn-service-delete.notification.success.title'), + this.translateService.get('ldn-service-delete.notification.success.content')); + } else { + this.notificationService.error(this.translateService.get('ldn-service-delete.notification.error.title'), + this.translateService.get('ldn-service-delete.notification.error.content')); + this.cdRef.detectChanges(); } - return remoteData; - }) - ); - this.cdRef.detectChanges(); - this.closeModal(); - this.notificationService.success(this.translateService.get('ldn-service-delete.notification.success.title'), - this.translateService.get('ldn-service-delete.notification.success.content')); - } else { - this.notificationService.error(this.translateService.get('ldn-service-delete.notification.error.title'), - this.translateService.get('ldn-service-delete.notification.error.content')); - this.cdRef.detectChanges(); + }); } - }); } - } + toggleStatus(ldnService: any, ldnServicesService: LdnServicesService): void { + const newStatus = !ldnService.enabled; + const originalStatus = ldnService.enabled; + const patchOperation: Operation = { + op: 'replace', + path: '/enabled', + value: newStatus, + }; - toggleStatus(ldnService: any, ldnServicesService: LdnServicesService): void { - const newStatus = !ldnService.enabled; - const originalStatus = ldnService.enabled; - - const patchOperation: Operation = { - op: 'replace', - path: '/enabled', - value: newStatus, - }; - - ldnServicesService.patch(ldnService, [patchOperation]).pipe(getFirstCompletedRemoteData()).subscribe( - (rd: RemoteData) => { - if (rd.hasSucceeded) { - ldnService.enabled = newStatus; - this.notificationService.success(this.translateService.get('ldn-enable-service.notification.success.title'), - this.translateService.get('ldn-enable-service.notification.success.content')); - } else { - ldnService.enabled = originalStatus; - this.notificationService.error(this.translateService.get('ldn-enable-service.notification.error.title'), - this.translateService.get('ldn-enable-service.notification.error.content')); - } - } - ); - } + ldnServicesService.patch(ldnService, [patchOperation]).pipe(getFirstCompletedRemoteData()).subscribe( + (rd: RemoteData) => { + if (rd.hasSucceeded) { + ldnService.enabled = newStatus; + this.notificationService.success(this.translateService.get('ldn-enable-service.notification.success.title'), + this.translateService.get('ldn-enable-service.notification.success.content')); + } else { + ldnService.enabled = originalStatus; + this.notificationService.error(this.translateService.get('ldn-enable-service.notification.error.title'), + this.translateService.get('ldn-enable-service.notification.error.content')); + } + } + ); + } } diff --git a/src/app/admin/admin-ldn-services/ldn-services-guard/ldn-services-guard.service.ts b/src/app/admin/admin-ldn-services/ldn-services-guard/ldn-services-guard.service.ts index 21123ede4a..8919f06357 100644 --- a/src/app/admin/admin-ldn-services/ldn-services-guard/ldn-services-guard.service.ts +++ b/src/app/admin/admin-ldn-services/ldn-services-guard/ldn-services-guard.service.ts @@ -4,26 +4,28 @@ import { Observable } from 'rxjs'; @Injectable({ - providedIn: 'root' + providedIn: 'root' }) export class LdnServicesGuard implements CanActivate { - constructor( - //private notifyInfoService: NotifyInfoService, - private router: Router - ) {} - canActivate( - route: ActivatedRouteSnapshot, - state: RouterStateSnapshot): Observable | Promise | boolean | UrlTree { - return true; - /*return this.notifyInfoService.isCoarConfigEnabled().pipe( - map(coarLdnEnabled => { - if (coarLdnEnabled) { - return true; - } else { - return this.router.parseUrl('/404'); - } - }) - );*/ - } + constructor( + //private notifyInfoService: NotifyInfoService, + private router: Router + ) { + } + + canActivate( + route: ActivatedRouteSnapshot, + state: RouterStateSnapshot): Observable | Promise | boolean | UrlTree { + return true; + /*return this.notifyInfoService.isCoarConfigEnabled().pipe( + map(coarLdnEnabled => { + if (coarLdnEnabled) { + return true; + } else { + return this.router.parseUrl('/404'); + } + }) + );*/ + } } diff --git a/src/app/admin/admin-ldn-services/ldn-services-guard/ldn-services.guard.spec.ts b/src/app/admin/admin-ldn-services/ldn-services-guard/ldn-services.guard.spec.ts index 30af31cab8..9b66ad6788 100644 --- a/src/app/admin/admin-ldn-services/ldn-services-guard/ldn-services.guard.spec.ts +++ b/src/app/admin/admin-ldn-services/ldn-services-guard/ldn-services.guard.spec.ts @@ -3,15 +3,15 @@ import { TestBed } from '@angular/core/testing'; import { LdnServicesGuard } from './ldn-services-guard.service'; describe('LdnServicesGuard', () => { - let guard: LdnServicesGuard; + let guard: LdnServicesGuard; - beforeEach(() => { - TestBed.configureTestingModule({}); - guard = TestBed.inject(LdnServicesGuard); - }); + beforeEach(() => { + TestBed.configureTestingModule({}); + guard = TestBed.inject(LdnServicesGuard); + }); - it('should be created', () => { - // @ts-ignore - expect(guard).toBeTruthy(); - }); + it('should be created', () => { + // @ts-ignore + expect(guard).toBeTruthy(); + }); }); diff --git a/src/app/admin/admin-ldn-services/ldn-services-model/ldn-service-itemfilters.ts b/src/app/admin/admin-ldn-services/ldn-services-model/ldn-service-itemfilters.ts index 865fa0b3ea..6aceada3df 100644 --- a/src/app/admin/admin-ldn-services/ldn-services-model/ldn-service-itemfilters.ts +++ b/src/app/admin/admin-ldn-services/ldn-services-model/ldn-service-itemfilters.ts @@ -1,7 +1,6 @@ -import { autoserialize, inheritSerialization, deserialize } from 'cerialize'; +import { autoserialize, deserialize, inheritSerialization } from 'cerialize'; import { LDN_SERVICE_CONSTRAINT_FILTER } from './ldn-service.resource-type'; import { CacheableObject } from '../../../core/cache/cacheable-object.model'; -import { HALLink } from '../../../core/shared/hal-link.model'; import { typedObject } from '../../../core/cache/builders/build-decorators'; import { excludeFromEquals } from '../../../core/utilities/equals.decorators'; import { ResourceType } from '../../../core/shared/resource-type'; diff --git a/src/app/admin/admin-ldn-services/ldn-services-model/ldn-service-patterns.model.ts b/src/app/admin/admin-ldn-services/ldn-services-model/ldn-service-patterns.model.ts index 1e67ccfeee..1103056e47 100644 --- a/src/app/admin/admin-ldn-services/ldn-services-model/ldn-service-patterns.model.ts +++ b/src/app/admin/admin-ldn-services/ldn-services-model/ldn-service-patterns.model.ts @@ -4,10 +4,10 @@ import { autoserialize } from 'cerialize'; * notify service patterns */ export class NotifyServicePattern { - @autoserialize - pattern: string; - @autoserialize - constraint: string; - @autoserialize - automatic: string; + @autoserialize + pattern: string; + @autoserialize + constraint: string; + @autoserialize + automatic: string; } diff --git a/src/app/admin/admin-ldn-services/ldn-services-model/ldn-service-status.model.ts b/src/app/admin/admin-ldn-services/ldn-services-model/ldn-service-status.model.ts index 040e4d37b8..d9e45d91a9 100644 --- a/src/app/admin/admin-ldn-services/ldn-services-model/ldn-service-status.model.ts +++ b/src/app/admin/admin-ldn-services/ldn-services-model/ldn-service-status.model.ts @@ -2,7 +2,7 @@ * List of services statuses */ export enum LdnServiceStatus { - UNKOWN, - DISABLED, - ENABLED, + UNKOWN, + DISABLED, + ENABLED, } diff --git a/src/app/admin/admin-ldn-services/ldn-services-model/ldn-service.constrain.model.ts b/src/app/admin/admin-ldn-services/ldn-services-model/ldn-service.constrain.model.ts index 6eda194443..69a9baf273 100644 --- a/src/app/admin/admin-ldn-services/ldn-services-model/ldn-service.constrain.model.ts +++ b/src/app/admin/admin-ldn-services/ldn-services-model/ldn-service.constrain.model.ts @@ -1,3 +1,3 @@ export class ldnServiceConstrain { - void: any; + void: any; } diff --git a/src/app/admin/admin-ldn-services/ldn-services-model/ldn-services.model.ts b/src/app/admin/admin-ldn-services/ldn-services-model/ldn-services.model.ts index e0725b5851..8631ef2451 100644 --- a/src/app/admin/admin-ldn-services/ldn-services-model/ldn-services.model.ts +++ b/src/app/admin/admin-ldn-services/ldn-services-model/ldn-services.model.ts @@ -7,7 +7,6 @@ import { typedObject } from '../../../core/cache/builders/build-decorators'; import { NotifyServicePattern } from './ldn-service-patterns.model'; - /** An LdnService and its properties. */ @typedObject @inheritSerialization(CacheableObject) diff --git a/src/app/admin/admin-ldn-services/ldn-services-services/ldn-directory.service.spec.ts b/src/app/admin/admin-ldn-services/ldn-services-services/ldn-directory.service.spec.ts index e24508e942..ab4f78dc6b 100644 --- a/src/app/admin/admin-ldn-services/ldn-services-services/ldn-directory.service.spec.ts +++ b/src/app/admin/admin-ldn-services/ldn-services-services/ldn-directory.service.spec.ts @@ -3,15 +3,15 @@ import { TestBed } from '@angular/core/testing'; import { LdnDirectoryService } from './ldn-directory.service'; describe('LdnDirectoryService', () => { - let service: LdnDirectoryService; + let service: LdnDirectoryService; - beforeEach(() => { - TestBed.configureTestingModule({}); - service = TestBed.inject(LdnDirectoryService); - }); + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(LdnDirectoryService); + }); - it('should be created', () => { - // @ts-ignore - expect(service).toBeTruthy(); - }); + it('should be created', () => { + // @ts-ignore + expect(service).toBeTruthy(); + }); }); diff --git a/src/app/admin/admin-ldn-services/ldn-services-services/ldn-directory.service.ts b/src/app/admin/admin-ldn-services/ldn-services-services/ldn-directory.service.ts index 3499759f03..92446b4677 100644 --- a/src/app/admin/admin-ldn-services/ldn-services-services/ldn-directory.service.ts +++ b/src/app/admin/admin-ldn-services/ldn-services-services/ldn-directory.service.ts @@ -4,22 +4,24 @@ import { map, Observable } from 'rxjs'; import { LdnServicesService } from "../ldn-services-data/ldn-services-data.service"; @Injectable({ - providedIn: 'root', + providedIn: 'root', }) export class LdnDirectoryService { - private itemFilterEndpoint = 'http://localhost:8080/server/api/config/itemfilters'; + private itemFilterEndpoint = 'http://localhost:8080/server/api/config/itemfilters'; - constructor(private http: HttpClient, - private ldnServicesService: LdnServicesService) {} - public getItemFilters(): Observable { + constructor(private http: HttpClient, + private ldnServicesService: LdnServicesService) { + } - return this.ldnServicesService.findAll().pipe( - map((servicesData) => { - return servicesData; - }) - ); - } + public getItemFilters(): Observable { + + return this.ldnServicesService.findAll().pipe( + map((servicesData) => { + return servicesData; + }) + ); + } } diff --git a/src/app/admin/admin-ldn-services/ldn-services-services/ldn-service-bulk-delete.service.spec.ts b/src/app/admin/admin-ldn-services/ldn-services-services/ldn-service-bulk-delete.service.spec.ts index 38e1a4de2b..922b63a871 100644 --- a/src/app/admin/admin-ldn-services/ldn-services-services/ldn-service-bulk-delete.service.spec.ts +++ b/src/app/admin/admin-ldn-services/ldn-services-services/ldn-service-bulk-delete.service.spec.ts @@ -3,15 +3,15 @@ import { TestBed } from '@angular/core/testing'; import { LdnServicesBulkDeleteService } from './ldn-service-bulk-delete.service'; describe('LdnServiceBulkDeleteService', () => { - let service: LdnServicesBulkDeleteService; + let service: LdnServicesBulkDeleteService; - beforeEach(() => { - TestBed.configureTestingModule({}); - service = TestBed.inject(LdnServicesBulkDeleteService); - }); + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(LdnServicesBulkDeleteService); + }); - it('should be created', () => { - // @ts-ignore - expect(service).toBeTruthy(); - }); + it('should be created', () => { + // @ts-ignore + expect(service).toBeTruthy(); + }); }); From e2ad9fe7072f785c2756b3ddcdca77ca48d991ff Mon Sep 17 00:00:00 2001 From: Mattia Vianelli Date: Tue, 24 Oct 2023 13:27:27 +0200 Subject: [PATCH 08/11] CST-12174 Updated delete services to mark for deletion on outboundpatterns as well --- .../admin-ldn-services-routing.module.ts | 2 - .../ldn-service-form-edit.component.html | 17 +++--- .../ldn-service-form-edit.component.ts | 53 ++++++++++++++----- 3 files changed, 51 insertions(+), 21 deletions(-) diff --git a/src/app/admin/admin-ldn-services/admin-ldn-services-routing.module.ts b/src/app/admin/admin-ldn-services/admin-ldn-services-routing.module.ts index 2d3c68f7cb..43dc4f3462 100644 --- a/src/app/admin/admin-ldn-services/admin-ldn-services-routing.module.ts +++ b/src/app/admin/admin-ldn-services/admin-ldn-services-routing.module.ts @@ -2,7 +2,6 @@ import { NgModule } from '@angular/core'; import { RouterModule } from '@angular/router'; import { I18nBreadcrumbResolver } from 'src/app/core/breadcrumbs/i18n-breadcrumb.resolver'; import { LdnServicesOverviewComponent } from './ldn-services-directory/ldn-services-directory.component'; -import { LdnServicesGuard } from './ldn-services-guard/ldn-services-guard.service'; import { LdnServiceNewComponent } from './ldn-service-new/ldn-service-new.component'; import { LdnServiceFormEditComponent } from './ldn-service-form-edit/ldn-service-form-edit.component'; @@ -15,7 +14,6 @@ import { LdnServiceFormEditComponent } from './ldn-service-form-edit/ldn-service component: LdnServicesOverviewComponent, resolve: {breadcrumb: I18nBreadcrumbResolver}, data: {title: 'ldn-registered-services.title', breadcrumbKey: 'ldn-registered-services.new'}, - canActivate: [LdnServicesGuard] }, { path: 'new', diff --git a/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.html b/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.html index bcd597845d..330e055b37 100644 --- a/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.html +++ b/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.html @@ -84,7 +84,7 @@ -
+
-
- +
diff --git a/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.ts b/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.ts index 93622f9df0..d642963532 100644 --- a/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.ts +++ b/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.ts @@ -56,7 +56,8 @@ export class LdnServiceFormEditComponent implements OnInit { @Input() public constraint: string; @Input() public automatic: boolean; @Input() public headerKey: string; - markedForDeletion: number[] = []; + markedForDeletionInboundPattern: number[] = []; + markedForDeletionOutboundPattern: number[] = []; protected serviceId: string; private originalInboundPatterns: any[] = []; private originalOutboundPatterns: any[] = []; @@ -259,7 +260,8 @@ export class LdnServiceFormEditComponent implements OnInit { } patchService() { - this.deleteMarkedPatterns(); + this.deleteMarkedInboundPatterns(); + this.deleteMarkedOutboundPatterns(); const patchOperations = this.generatePatchOperations(); @@ -282,31 +284,58 @@ export class LdnServiceFormEditComponent implements OnInit { this.closeModal(); } - markForDeletion(index: number) { - if (!this.markedForDeletion.includes(index)) { - this.markedForDeletion.push(index); + markForInboundPatternDeletion(index: number) { + if (!this.markedForDeletionInboundPattern.includes(index)) { + this.markedForDeletionInboundPattern.push(index); } } - unmarkForDeletion(index: number) { - const i = this.markedForDeletion.indexOf(index); + unmarkForInboundPatternDeletion(index: number) { + const i = this.markedForDeletionInboundPattern.indexOf(index); if (i !== -1) { - this.markedForDeletion.splice(i, 1); + this.markedForDeletionInboundPattern.splice(i, 1); } } - deleteMarkedPatterns() { - this.markedForDeletion.sort((a, b) => b - a); + markForOutboundPatternDeletion(index: number) { + if (!this.markedForDeletionOutboundPattern.includes(index)) { + this.markedForDeletionOutboundPattern.push(index); + } + } + + unmarkForOutboundPatternDeletion(index: number) { + const i = this.markedForDeletionOutboundPattern.indexOf(index); + if (i !== -1) { + this.markedForDeletionOutboundPattern.splice(i, 1); + } + } + + deleteMarkedInboundPatterns() { + this.markedForDeletionInboundPattern.sort((a, b) => b - a); const patternsArray = this.formModel.get('notifyServiceInboundPatterns') as FormArray; - for (const index of this.markedForDeletion) { + for (const index of this.markedForDeletionInboundPattern) { if (index >= 0 && index < patternsArray.length) { this.deletedInboundPatterns.push(index); patternsArray.removeAt(index); } } - this.markedForDeletion = []; + this.markedForDeletionInboundPattern = []; + } + + deleteMarkedOutboundPatterns() { + this.markedForDeletionOutboundPattern.sort((a, b) => b - a); + const patternsArray = this.formModel.get('notifyServiceOutboundPatterns') as FormArray; + + for (const index of this.markedForDeletionOutboundPattern) { + if (index >= 0 && index < patternsArray.length) { + this.deletedOutboundPatterns.push(index); + patternsArray.removeAt(index); + } + } + + this.markedForDeletionOutboundPattern = []; } private createReplaceOperation(patchOperations: any[], formControlName: string, path: string): void { From 4ecaeabe40148aeef573e9fff44c03b48cb9f417 Mon Sep 17 00:00:00 2001 From: Mattia Vianelli Date: Tue, 24 Oct 2023 13:27:46 +0200 Subject: [PATCH 09/11] CST-12174 removed not needed guards --- .../ldn-services-guard.service.ts | 31 ------------------- .../ldn-services.guard.spec.ts | 17 ---------- 2 files changed, 48 deletions(-) delete mode 100644 src/app/admin/admin-ldn-services/ldn-services-guard/ldn-services-guard.service.ts delete mode 100644 src/app/admin/admin-ldn-services/ldn-services-guard/ldn-services.guard.spec.ts diff --git a/src/app/admin/admin-ldn-services/ldn-services-guard/ldn-services-guard.service.ts b/src/app/admin/admin-ldn-services/ldn-services-guard/ldn-services-guard.service.ts deleted file mode 100644 index 8919f06357..0000000000 --- a/src/app/admin/admin-ldn-services/ldn-services-guard/ldn-services-guard.service.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { Injectable } from '@angular/core'; -import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree } from '@angular/router'; -import { Observable } from 'rxjs'; - - -@Injectable({ - providedIn: 'root' -}) -export class LdnServicesGuard implements CanActivate { - - constructor( - //private notifyInfoService: NotifyInfoService, - private router: Router - ) { - } - - canActivate( - route: ActivatedRouteSnapshot, - state: RouterStateSnapshot): Observable | Promise | boolean | UrlTree { - return true; - /*return this.notifyInfoService.isCoarConfigEnabled().pipe( - map(coarLdnEnabled => { - if (coarLdnEnabled) { - return true; - } else { - return this.router.parseUrl('/404'); - } - }) - );*/ - } -} diff --git a/src/app/admin/admin-ldn-services/ldn-services-guard/ldn-services.guard.spec.ts b/src/app/admin/admin-ldn-services/ldn-services-guard/ldn-services.guard.spec.ts deleted file mode 100644 index 9b66ad6788..0000000000 --- a/src/app/admin/admin-ldn-services/ldn-services-guard/ldn-services.guard.spec.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { TestBed } from '@angular/core/testing'; - -import { LdnServicesGuard } from './ldn-services-guard.service'; - -describe('LdnServicesGuard', () => { - let guard: LdnServicesGuard; - - beforeEach(() => { - TestBed.configureTestingModule({}); - guard = TestBed.inject(LdnServicesGuard); - }); - - it('should be created', () => { - // @ts-ignore - expect(guard).toBeTruthy(); - }); -}); From ce3ba35866bcc334e7601db47b7dc4debb1faef0 Mon Sep 17 00:00:00 2001 From: Mattia Vianelli Date: Tue, 24 Oct 2023 13:44:15 +0200 Subject: [PATCH 10/11] CST-12174 added isNew Check for patterns deeltion --- .../ldn-service-form-edit.component.ts | 37 ++++++++----------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.ts b/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.ts index d642963532..fa460afbca 100644 --- a/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.ts +++ b/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.ts @@ -200,23 +200,6 @@ export class LdnServiceFormEditComponent implements OnInit { notifyServiceOutboundPatternsArray.push(this.createOutboundPatternFormGroup()); } - removeOutboundPattern(index: number): void { - const patternsArray = this.formModel.get('notifyServiceOutboundPatterns') as FormArray; - const patternGroup = patternsArray.at(index) as FormGroup; - const patternValue = patternGroup.value; - - if (index < 0 || index >= patternsArray.length || patternValue.isNew) { - patternsArray.removeAt(index); - return; - } - - - this.deletedOutboundPatterns.push(index); - - patternsArray.removeAt(index); - this.cdRef.detectChanges(); - } - toggleAutomatic(i: number) { const automaticControl = this.formModel.get(`notifyServiceInboundPatterns.${i}.automatic`); @@ -316,22 +299,34 @@ export class LdnServiceFormEditComponent implements OnInit { for (const index of this.markedForDeletionInboundPattern) { if (index >= 0 && index < patternsArray.length) { - this.deletedInboundPatterns.push(index); - patternsArray.removeAt(index); + const patternGroup = patternsArray.at(index) as FormGroup; + const patternValue = patternGroup.value; + if (patternValue.isNew) { + patternsArray.removeAt(index); + } else { + this.deletedInboundPatterns.push(index); + } } } this.markedForDeletionInboundPattern = []; } + deleteMarkedOutboundPatterns() { this.markedForDeletionOutboundPattern.sort((a, b) => b - a); const patternsArray = this.formModel.get('notifyServiceOutboundPatterns') as FormArray; for (const index of this.markedForDeletionOutboundPattern) { if (index >= 0 && index < patternsArray.length) { - this.deletedOutboundPatterns.push(index); - patternsArray.removeAt(index); + const patternGroup = patternsArray.at(index) as FormGroup; + const patternValue = patternGroup.value; + if (patternValue.isNew) { + patternsArray.removeAt(index); + } else { + + this.deletedOutboundPatterns.push(index); + } } } From d877d6f8827901e42ab7ad59f4ad402ea02fe814 Mon Sep 17 00:00:00 2001 From: Mattia Vianelli Date: Tue, 24 Oct 2023 14:05:50 +0200 Subject: [PATCH 11/11] CST-12174 small layout fix --- .../ldn-service-form-edit.component.html | 9 +++++---- .../ldn-service-form/ldn-service-form.component.ts | 6 +++--- src/assets/i18n/en.json5 | 1 + 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.html b/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.html index 330e055b37..368b312cd1 100644 --- a/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.html +++ b/src/app/admin/admin-ldn-services/ldn-service-form-edit/ldn-service-form-edit.component.html @@ -267,12 +267,13 @@ {{ 'service.overview.reset-form.body' | translate }}
- - +
diff --git a/src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts b/src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts index ff42ffb4dc..6b908cdae2 100644 --- a/src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts +++ b/src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts @@ -149,9 +149,9 @@ export class LdnServiceFormComponent implements OnInit { getFirstCompletedRemoteData() ).subscribe((rd: RemoteData) => { if (rd.hasSucceeded) { - this.notificationsService.success(this.translateService.get('ldn-service-notification.created.success.title')); - (this.translateService.get('ldn-service-notification.created.success.title'), - this.translateService.get('ldn-service-notification.created.success.body')); + this.notificationsService.success(this.translateService.get('ldn-service-notification.created.success.title'), + this.translateService.get('ldn-service-notification.created.success.body')); + this.sendBack(); this.closeModal(); } else { diff --git a/src/assets/i18n/en.json5 b/src/assets/i18n/en.json5 index 7cded8573d..40f0150022 100644 --- a/src/assets/i18n/en.json5 +++ b/src/assets/i18n/en.json5 @@ -962,6 +962,7 @@ "ldn-service-delete.notification.success.content": "The service has been deleted", "ldn-service-delete.notification.error.title": "Failed Deletion", "ldn-service-delete.notification.error.content": "The service has not been deleted", + "service.overview.reset-form.reset-return": "Return", "service.overview.delete": "Delete service", "ldn-edit-service.title": "Edit service", "ldn-edit-service.form.label.name": "Name",
{{ 'service.overview.table.name' | translate }}{{ 'service.overview.table.description' | translate }}{{ 'service.overview.table.status' | translate }}{{ 'service.overview.table.actions' | translate }}
{{ 'service.overview.table.name' | translate }}{{ 'service.overview.table.description' | translate }}{{ 'service.overview.table.status' | translate }}{{ 'service.overview.table.actions' | translate }}
{{ ldnService.name }} {{ ldnService.description }} - + {{ ldnService.enabled ? ('ldn-service.overview.table.enabled' | translate) : ('ldn-service.overview.table.disabled' | translate) }}
- - -
+ + +