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",