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 568f3ed46f..67eada6b7b 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,284 +1,293 @@
-
-
-

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

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

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

+
+ +
+ +
+ +
+
+
+
-
- - -
+
+ + +
+ {{ 'ldn-new-service.form.error.name' | translate }} +
+
-
-   -
+ +
+ + +
- -
- - -
- -
-   -
- - -
- - -
- -
-   -
- - -
- - -
- -
-   -
- -
-
- -
-
- -
-
- -
-
-
-
- -
- - + +
+ + +
+ {{ 'ldn-new-service.form.error.url' | translate }} +
+
-
-
- -
+ +
+ + +
+ {{ 'ldn-new-service.form.error.ldnurl' | translate }} +
+
-
- - - -
- -
- -
-
-
-
+ +
+ + +
+ {{ 'ldn-new-service.form.error.score' | 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 0b244d76db..d2bdbaeea2 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 @@ -47,6 +47,12 @@ textarea { color: #000000; } +.error-text { + color: red; + font-size: 0.8em; + margin-top: 5px; +} + .toggle-switch { display: flex; align-items: center; 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 fa460afbca..d4592a0d18 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 @@ -51,6 +51,7 @@ export class LdnServiceFormEditComponent implements OnInit { @Input() public description: string; @Input() public url: string; @Input() public ldnUrl: string; + @Input() public score: number; @Input() public inboundPattern: string; @Input() public outboundPattern: string; @Input() public constraint: string; @@ -85,6 +86,7 @@ export class LdnServiceFormEditComponent implements OnInit { description: ['', Validators.required], url: ['', Validators.required], ldnUrl: ['', Validators.required], + score: ['', [Validators.required, Validators.pattern('^0*(\.[0-9]+)?$|^1(\.0+)?$')]], inboundPattern: [''], outboundPattern: [''], constraintPattern: [''], @@ -124,6 +126,7 @@ export class LdnServiceFormEditComponent implements OnInit { name: this.service.name, description: this.service.description, url: this.service.url, + score: this.service.score, ldnUrl: this.service.ldnUrl, type: this.service.type, enabled: this.service.enabled @@ -163,6 +166,8 @@ export class LdnServiceFormEditComponent implements OnInit { this.createReplaceOperation(patchOperations, 'description', '/description'); this.createReplaceOperation(patchOperations, 'ldnUrl', '/ldnurl'); this.createReplaceOperation(patchOperations, 'url', '/url'); + this.createReplaceOperation(patchOperations, 'score', '/score'); + this.handlePatterns(patchOperations, 'notifyServiceInboundPatterns'); this.handlePatterns(patchOperations, 'notifyServiceOutboundPatterns'); @@ -250,16 +255,18 @@ export class LdnServiceFormEditComponent implements OnInit { 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')); - } - ); - + ).subscribe((rd: RemoteData) => { + if (rd.hasSucceeded) { + 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')); + } else { + this.notificationService.error(this.translateService.get('admin.registries.services-formats.modify.failure.head'), + this.translateService.get('admin.registries.services-formats.modify.failure.content')); + this.closeModal(); + } + }); } resetFormAndLeave() { 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 f1afa886f1..1baa5c5066 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,266 +1,273 @@
-
-
-

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

-
- -
- - -
+ +
+

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

+
+ +
+ + +
+ {{ 'ldn-new-service.form.error.name' | translate }} +
+
-
-   -
- -
- - -
+ +
+ + +
-
-   -
- -
- - -
+ +
+ + +
+ {{ 'ldn-new-service.form.error.url' | translate }} +
+
-
-   -
- -
- - -
+ +
+ + +
+ {{ 'ldn-new-service.form.error.ldnurl' | translate }} +
+
+ +
+ + +
+ {{ 'ldn-new-service.form.error.score' | translate }} +
+
-
-   -
+ +
+
+ +
+
+ +
+
+ +
+
+
+
- -
-
- +
+ + + + +
+
+ +
+ {{ 'ldn-new-service.form.error.patterns' | 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.error.patterns' | 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 f0fdcd81a2..eb5a70c7ee 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,8 +1,6 @@ form { - max-width: 800px; font-size: 14px; position: relative; - } input[type="text"], @@ -49,6 +47,12 @@ textarea { color: #000000; } +.error-text { + color: red; + font-size: 0.8em; + margin-top: 5px; +} + .toggle-switch { display: flex; align-items: center; 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 a2c4919a4d..6a37880ff7 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 @@ -58,6 +58,7 @@ export class LdnServiceFormComponent implements OnInit { @Input() public name: string; @Input() public description: string; @Input() public url: string; + @Input() public score: string; @Input() public ldnUrl: string; @Input() public inboundPattern: string; @Input() public outboundPattern: string; @@ -67,6 +68,9 @@ export class LdnServiceFormComponent implements OnInit { @Output() submitForm: EventEmitter = new EventEmitter(); @Output() cancelForm: EventEmitter = new EventEmitter(); private modalRef: any; + hasInboundPattern: boolean; + hasOutboundPattern: boolean; + isScoreValid: boolean; constructor( private ldnServicesService: LdnServicesService, @@ -85,6 +89,7 @@ export class LdnServiceFormComponent implements OnInit { name: ['', Validators.required], description: [''], url: ['', Validators.required], + score: ['', [Validators.required, Validators.pattern('^0*(\.[0-9]+)?$|^1(\.0+)?$')]], ldnUrl: ['', Validators.required], inboundPattern: [''], outboundPattern: [''], @@ -119,14 +124,21 @@ export class LdnServiceFormComponent implements OnInit { createService() { this.formModel.get('name').markAsTouched(); + this.formModel.get('score').markAsTouched(); this.formModel.get('url').markAsTouched(); this.formModel.get('ldnUrl').markAsTouched(); + this.formModel.get('notifyServiceInboundPatterns').markAsTouched(); + this.formModel.get('notifyServiceOutboundPatterns').markAsTouched(); const name = this.formModel.get('name').value; const url = this.formModel.get('url').value; + const score = this.formModel.get('score').value; const ldnUrl = this.formModel.get('ldnUrl').value; - if (!name || !url || !ldnUrl) { + const hasInboundPattern = this.checkPatterns(this.formModel.get('notifyServiceInboundPatterns') as FormArray); + const hasOutboundPattern = this.checkPatterns(this.formModel.get('notifyServiceOutboundPatterns') as FormArray); + + if (!name || !url || !ldnUrl || !score || (!hasInboundPattern && !hasOutboundPattern)) { this.closeModal(); return; } @@ -144,15 +156,26 @@ export class LdnServiceFormComponent implements OnInit { if (rd.hasSucceeded) { 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 { - this.notificationsService.error(this.translateService.get('notification.created.failure')); + this.notificationsService.error(this.translateService.get('ldn-service-notification.created.failure.title'), + this.translateService.get('ldn-service-notification.created.failure.body')); + this.closeModal(); } }); } + checkPatterns(formArray: FormArray): boolean { + for (let i = 0; i < formArray.length; i++) { + const pattern = formArray.at(i).get('pattern').value; + if (pattern) { + return true; + } + } + return false; + } + resetFormAndLeave() { this.sendBack(); @@ -191,6 +214,22 @@ export class LdnServiceFormComponent implements OnInit { } } + patternSelected(): boolean { + for (let pattern of this.formModel.get('notifyServiceInboundPatterns').value) { + if (pattern.pattern !== '') { + return true; + } + } + + for (let pattern of this.formModel.get('notifyServiceOutboundPatterns').value) { + if (pattern.pattern !== '') { + return true; + } + } + + return false; + } + private sendBack() { this.router.navigateByUrl('admin/ldn/services'); } 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 8631ef2451..26163f6234 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 @@ -32,6 +32,9 @@ export class LdnService extends CacheableObject { @autoserialize url: string; + @autoserialize + score: number; + @autoserialize enabled: boolean; diff --git a/src/assets/i18n/en.json5 b/src/assets/i18n/en.json5 index d4d3cb77fa..ca762bfad8 100644 --- a/src/assets/i18n/en.json5 +++ b/src/assets/i18n/en.json5 @@ -941,6 +941,12 @@ "ldn-new-service.form.label.placeholder.selectedItemFilter": "No Item Filter Selected", "ldn-new-service.form.label.ItemFilter": "Item Filter", "ldn-new-service.form.label.automatic": "Automatic", + "ldn-new-service.form.error.name": "Name is required", + "ldn-new-service.form.error.url": "URL is required", + "ldn-new-service.form.error.ldnurl": "LDN URL is required", + "ldn-new-service.form.error.patterns": "At least a pattern is required", + "ldn-new-service.form.error.score": "Please enter a valid score (between 0 and 1). Use the “.” as decimal separator", + "ldn-new-service.form.label.outboundPattern": "Outbound Patterns", "ldn-new-service.form.label.placeholder.outboundPattern": "Select an Outbound Pattern", "ldn-new-service.form.label.addPattern": "+ Add more",