Merged in CST-12179 (pull request #980)

CST-12179

Approved-by: Stefano Maffei
This commit is contained in:
Mattia Vianelli
2023-11-16 15:56:33 +00:00
committed by Stefano Maffei
8 changed files with 574 additions and 493 deletions

View File

@@ -14,57 +14,65 @@
</div> </div>
</div> </div>
<div class="mb-2"> <div class="mb-5">
<label for="name">{{ 'ldn-new-service.form.label.name' | translate }}</label> <label for="name">{{ 'ldn-new-service.form.label.name' | translate }}</label>
<input [class.invalid-field]="formModel.get('name').invalid && formModel.get('name').touched" <input [class.invalid-field]="formModel.get('name').invalid && formModel.get('name').touched"
[placeholder]="'ldn-new-service.form.placeholder.name' | translate" formControlName="name" id="name" [placeholder]="'ldn-new-service.form.placeholder.name' | translate" formControlName="name" id="name"
name="name" name="name"
type="text"> type="text">
<div *ngIf="formModel.get('name').invalid && formModel.get('name').touched" class="error-text">
{{ 'ldn-new-service.form.error.name' | translate }}
</div> </div>
<div class="mb-4">
&nbsp;
</div> </div>
<!-- In the description section --> <!-- In the description section -->
<div class="mb-2 d-flex flex-column"> <div class="mb-5 mt-5 d-flex flex-column">
<label for="description">{{ 'ldn-new-service.form.label.description' | translate }}</label> <label for="description">{{ 'ldn-new-service.form.label.description' | translate }}</label>
<textarea [placeholder]="'ldn-new-service.form.placeholder.description' | translate" <textarea [placeholder]="'ldn-new-service.form.placeholder.description' | translate"
formControlName="description" id="description" name="description"></textarea> formControlName="description" id="description" name="description"></textarea>
</div> </div>
<div class="mb-4">
&nbsp;
</div>
<!-- In the url section --> <!-- In the url section -->
<div class="mb-2"> <div class="mb-5 mt-5">
<label for="url">{{ 'ldn-new-service.form.label.url' | translate }}</label> <label for="url">{{ 'ldn-new-service.form.label.url' | translate }}</label>
<input [class.invalid-field]="formModel.get('url').invalid && formModel.get('url').touched" <input [class.invalid-field]="formModel.get('url').invalid && formModel.get('url').touched"
[placeholder]="'ldn-new-service.form.placeholder.url' | translate" formControlName="url" id="url" [placeholder]="'ldn-new-service.form.placeholder.url' | translate" formControlName="url" id="url"
name="url" name="url"
type="text"> type="text">
<div *ngIf="formModel.get('url').invalid && formModel.get('url').touched" class="error-text">
{{ 'ldn-new-service.form.error.url' | translate }}
</div>
</div> </div>
<div class="mb-4">
&nbsp;
</div>
<!-- In the ldnUrl section --> <!-- In the ldnUrl section -->
<div class="mb-2"> <div class="mb-5 mt-5">
<label for="ldnUrl">{{ 'ldn-new-service.form.label.ldnUrl' | translate }}</label> <label for="ldnUrl">{{ 'ldn-new-service.form.label.ldnUrl' | translate }}</label>
<input [class.invalid-field]="formModel.get('ldnUrl').invalid && formModel.get('ldnUrl').touched" <input [class.invalid-field]="formModel.get('ldnUrl').invalid && formModel.get('ldnUrl').touched"
[placeholder]="'ldn-new-service.form.placeholder.ldnUrl' | translate" formControlName="ldnUrl" [placeholder]="'ldn-new-service.form.placeholder.ldnUrl' | translate" formControlName="ldnUrl"
id="ldnUrl" id="ldnUrl"
name="ldnUrl" name="ldnUrl"
type="text"> type="text">
<div *ngIf="formModel.get('ldnUrl').invalid && formModel.get('ldnUrl').touched" class="error-text">
{{ 'ldn-new-service.form.error.ldnurl' | translate }}
</div>
</div> </div>
<div class="mb-4"> <!-- In the score section -->
&nbsp; <div class="mb-2">
<label for="score">{{ 'ldn-new-service.form.label.score' | translate }}</label>
<input [class.invalid-field]="formModel.get('score').invalid && formModel.get('score').touched"
[placeholder]="'ldn-new-service.form.placeholder.score' | translate" formControlName="score"
id="score"
name="score"
type="text">
<div *ngIf="formModel.get('score').invalid && formModel.get('score').touched" class="error-text">
{{ 'ldn-new-service.form.error.score' | translate }}
</div>
</div> </div>
<div class="row">
<div class="row mb-1 mt-5">
<div class="col"> <div class="col">
<label>{{ 'ldn-new-service.form.label.inboundPattern' | translate }} </label> <label>{{ 'ldn-new-service.form.label.inboundPattern' | translate }} </label>
</div> </div>
@@ -74,12 +82,13 @@
<div class="col-sm1 "> <div class="col-sm1 ">
<label class="label-box-2">{{ 'ldn-new-service.form.label.automatic' | translate }}</label> <label class="label-box-2">{{ 'ldn-new-service.form.label.automatic' | translate }}</label>
</div> </div>
<div class="col-sm-1"> <div class="col-sm-2">
</div> </div>
</div> </div>
<div *ngFor="let patternGroup of formModel.get('notifyServiceInboundPatterns')['controls']; let i = index" <div *ngFor="let patternGroup of formModel.get('notifyServiceInboundPatterns')['controls']; let i = index"
formGroupName="notifyServiceInboundPatterns" [class.marked-for-deletion]="markedForDeletionInboundPattern.includes(i)"> [class.marked-for-deletion]="markedForDeletionInboundPattern.includes(i)"
formGroupName="notifyServiceInboundPatterns">
<ng-container [formGroupName]="i"> <ng-container [formGroupName]="i">
@@ -90,7 +99,7 @@
name="additionalInboundPattern{{i}}" required> name="additionalInboundPattern{{i}}" required>
<option value="">{{ 'ldn-new-service.form.label.placeholder.inboundPattern' | translate }}</option> <option value="">{{ 'ldn-new-service.form.label.placeholder.inboundPattern' | translate }}</option>
<option *ngFor="let pattern of inboundPatterns" <option *ngFor="let pattern of inboundPatterns"
[ngValue]="pattern.name">{{ pattern.name }}</option> [value]="pattern">{{ 'ldn-service.form.pattern.' + pattern + '.label' | translate }} </option>
</select> </select>
</div> </div>
@@ -116,19 +125,19 @@
<div class="col-sm-2"> <div class="col-sm-2">
<button (click)="markForInboundPatternDeletion(i)" class="btn btn-outline-dark" <div class="btn-group">
<button (click)="markForInboundPatternDeletion(i)" class="btn btn-outline-dark trash-button"
type="button"> type="button">
<i class="fas fa-trash"></i> <i class="fas fa-trash"></i>
</button> </button>
<button (click)="unmarkForInboundPatternDeletion(i)" *ngIf="markedForDeletionInboundPattern.includes(i)"
class="btn btn-warning"
<button (click)="unmarkForInboundPatternDeletion(i)" *ngIf="markedForDeletionInboundPattern.includes(i)" class="btn btn-warning ml-2"
type="button"> type="button">
<i class="fas fa-undo"></i> <i class="fas fa-undo"></i>
</button> </button>
</div> </div>
</div> </div>
</div>
</ng-container> </ng-container>
</div> </div>
@@ -136,26 +145,26 @@
<span (click)="addInboundPattern()" <span (click)="addInboundPattern()"
class="add-pattern-link mb-2">{{ 'ldn-new-service.form.label.addPattern' | translate }}</span> class="add-pattern-link mb-2">{{ 'ldn-new-service.form.label.addPattern' | translate }}</span>
<div class="mb-4">
&nbsp;
</div>
<div class="row"> <div class="row mb-1 mt-5">
<div class="col"> <div class="col">
<label>{{ 'ldn-new-service.form.label.outboundPattern' | translate }} </label> <label>{{ 'ldn-new-service.form.label.outboundPattern' | translate }} </label>
</div> </div>
<div class="col"> <div class="col">
<label class="label-box-3">{{ 'ldn-new-service.form.label.ItemFilter' | translate }}</label> <label class="label-box">{{ 'ldn-new-service.form.label.ItemFilter' | translate }}</label>
</div> </div>
<div class="col-sm-1 "> <div class="col-sm1 ">
<label class="label-box-2"></label> <label class="label-box-2" style="visibility: hidden;">
{{ 'ldn-new-service.form.label.automatic' | translate }}
</label>
</div> </div>
<div class="col-sm-1 "> <div class="col-sm-2">
</div> </div>
</div> </div>
<div *ngFor="let patternGroup of formModel.get('notifyServiceOutboundPatterns')['controls']; let i = index" <div *ngFor="let patternGroup of formModel.get('notifyServiceOutboundPatterns')['controls']; let i = index"
formGroupName="notifyServiceOutboundPatterns" [class.marked-for-deletion]="markedForDeletionOutboundPattern.includes(i)"> [class.marked-for-deletion]="markedForDeletionOutboundPattern.includes(i)"
formGroupName="notifyServiceOutboundPatterns">
<ng-container [formGroupName]="i"> <ng-container [formGroupName]="i">
@@ -167,7 +176,7 @@
required> required>
<option value="">{{ 'ldn-new-service.form.label.placeholder.outboundPattern' | translate }}</option> <option value="">{{ 'ldn-new-service.form.label.placeholder.outboundPattern' | translate }}</option>
<option *ngFor="let pattern of outboundPatterns" <option *ngFor="let pattern of outboundPatterns"
[ngValue]="pattern.name">{{ pattern.name }}</option> [value]="pattern">{{ 'ldn-service.form.pattern.' + pattern + '.label' | translate }} </option>
</select> </select>
</div> </div>
<div class="col"> <div class="col">
@@ -189,15 +198,19 @@
</div> </div>
<div class="col-sm-2"> <div class="col-sm-2">
<button (click)="markForOutboundPatternDeletion(i)" class="btn btn-outline-dark trash-button" type="button"> <div class="btn-group">
<button (click)="markForOutboundPatternDeletion(i)" class="btn btn-outline-dark trash-button"
type="button">
<i class="fas fa-trash"></i> <i class="fas fa-trash"></i>
</button> </button>
<button (click)="unmarkForOutboundPatternDeletion(i)" *ngIf="markedForDeletionOutboundPattern.includes(i)" class="btn btn-warning ml-2" <button (click)="unmarkForOutboundPatternDeletion(i)" *ngIf="markedForDeletionOutboundPattern.includes(i)"
class="btn btn-warning"
type="button"> type="button">
<i class="fas fa-undo"></i> <i class="fas fa-undo"></i>
</button> </button>
</div> </div>
</div> </div>
</div>
</ng-container> </ng-container>
</div> </div>
@@ -205,10 +218,6 @@
(click)="addOutboundPattern()" (click)="addOutboundPattern()"
class="add-pattern-link mb-2">{{ 'ldn-new-service.form.label.addPattern' | translate }} class="add-pattern-link mb-2">{{ 'ldn-new-service.form.label.addPattern' | translate }}
</span> </span>
<div class="mb-5">
&nbsp;
</div>
<div aria-label="Basic example" class="submission-form-footer mt-1 mb-1 position-sticky" role="group"> <div aria-label="Basic example" class="submission-form-footer mt-1 mb-1 position-sticky" role="group">
<button class="btn btn-primary" type="submit"> <button class="btn btn-primary" type="submit">
<span><i class="fas fa-save"></i> {{ 'ldn-new-service.form.label.submit' | translate }}</span> <span><i class="fas fa-save"></i> {{ 'ldn-new-service.form.label.submit' | translate }}</span>

View File

@@ -47,6 +47,12 @@ textarea {
color: #000000; color: #000000;
} }
.error-text {
color: red;
font-size: 0.8em;
margin-top: 5px;
}
.toggle-switch { .toggle-switch {
display: flex; display: flex;
align-items: center; align-items: center;

View File

@@ -51,6 +51,7 @@ export class LdnServiceFormEditComponent implements OnInit {
@Input() public description: string; @Input() public description: string;
@Input() public url: string; @Input() public url: string;
@Input() public ldnUrl: string; @Input() public ldnUrl: string;
@Input() public score: number;
@Input() public inboundPattern: string; @Input() public inboundPattern: string;
@Input() public outboundPattern: string; @Input() public outboundPattern: string;
@Input() public constraint: string; @Input() public constraint: string;
@@ -85,6 +86,7 @@ export class LdnServiceFormEditComponent implements OnInit {
description: ['', Validators.required], description: ['', Validators.required],
url: ['', Validators.required], url: ['', Validators.required],
ldnUrl: ['', Validators.required], ldnUrl: ['', Validators.required],
score: ['', [Validators.required, Validators.pattern('^0*(\.[0-9]+)?$|^1(\.0+)?$')]],
inboundPattern: [''], inboundPattern: [''],
outboundPattern: [''], outboundPattern: [''],
constraintPattern: [''], constraintPattern: [''],
@@ -124,6 +126,7 @@ export class LdnServiceFormEditComponent implements OnInit {
name: this.service.name, name: this.service.name,
description: this.service.description, description: this.service.description,
url: this.service.url, url: this.service.url,
score: this.service.score,
ldnUrl: this.service.ldnUrl, ldnUrl: this.service.ldnUrl,
type: this.service.type, type: this.service.type,
enabled: this.service.enabled enabled: this.service.enabled
@@ -163,6 +166,8 @@ export class LdnServiceFormEditComponent implements OnInit {
this.createReplaceOperation(patchOperations, 'description', '/description'); this.createReplaceOperation(patchOperations, 'description', '/description');
this.createReplaceOperation(patchOperations, 'ldnUrl', '/ldnurl'); this.createReplaceOperation(patchOperations, 'ldnUrl', '/ldnurl');
this.createReplaceOperation(patchOperations, 'url', '/url'); this.createReplaceOperation(patchOperations, 'url', '/url');
this.createReplaceOperation(patchOperations, 'score', '/score');
this.handlePatterns(patchOperations, 'notifyServiceInboundPatterns'); this.handlePatterns(patchOperations, 'notifyServiceInboundPatterns');
this.handlePatterns(patchOperations, 'notifyServiceOutboundPatterns'); this.handlePatterns(patchOperations, 'notifyServiceOutboundPatterns');
@@ -250,16 +255,18 @@ export class LdnServiceFormEditComponent implements OnInit {
this.ldnServicesService.patch(this.service, patchOperations).pipe( this.ldnServicesService.patch(this.service, patchOperations).pipe(
getFirstCompletedRemoteData() getFirstCompletedRemoteData()
).subscribe( ).subscribe((rd: RemoteData<LdnService>) => {
() => { if (rd.hasSucceeded) {
this.closeModal(); this.closeModal();
this.sendBack(); this.sendBack();
this.notificationService.success(this.translateService.get('admin.registries.services-formats.modify.success.head'), this.notificationService.success(this.translateService.get('admin.registries.services-formats.modify.success.head'),
this.translateService.get('admin.registries.services-formats.modify.success.content')); 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() { resetFormAndLeave() {

View File

@@ -4,58 +4,66 @@
<h2 class="flex-grow-1">{{ 'ldn-create-service.title' | translate }}</h2> <h2 class="flex-grow-1">{{ 'ldn-create-service.title' | translate }}</h2>
</div> </div>
<!-- In the name section --> <!-- In the name section -->
<div class="mb-2"> <div class="mb-5">
<label for="name">{{ 'ldn-new-service.form.label.name' | translate }}</label> <label for="name">{{ 'ldn-new-service.form.label.name' | translate }}</label>
<input [class.invalid-field]="formModel.get('name').invalid && formModel.get('name').touched" <input [class.invalid-field]="formModel.get('name').invalid && formModel.get('name').touched"
[placeholder]="'ldn-new-service.form.placeholder.name' | translate" formControlName="name" id="name" [placeholder]="'ldn-new-service.form.placeholder.name' | translate" formControlName="name" id="name"
name="name" name="name"
type="text"> type="text">
<div *ngIf="formModel.get('name').invalid && formModel.get('name').touched" class="error-text">
{{ 'ldn-new-service.form.error.name' | translate }}
</div>
</div> </div>
<div class="mb-4">
&nbsp;
</div>
<!-- In the description section --> <!-- In the description section -->
<div class="mb-2 d-flex flex-column"> <div class="mb-5 mt-5 d-flex flex-column">
<label for="description">{{ 'ldn-new-service.form.label.description' | translate }}</label> <label for="description">{{ 'ldn-new-service.form.label.description' | translate }}</label>
<textarea [placeholder]="'ldn-new-service.form.placeholder.description' | translate" <textarea [placeholder]="'ldn-new-service.form.placeholder.description' | translate"
formControlName="description" id="description" name="description"></textarea> formControlName="description" id="description" name="description"></textarea>
</div> </div>
<div class="mb-4">
&nbsp;
</div>
<!-- In the url section --> <!-- In the url section -->
<div class="mb-2"> <div class="mb-5 mt-5">
<label for="url">{{ 'ldn-new-service.form.label.url' | translate }}</label> <label for="url">{{ 'ldn-new-service.form.label.url' | translate }}</label>
<input [class.invalid-field]="formModel.get('url').invalid && formModel.get('url').touched" <input [class.invalid-field]="formModel.get('url').invalid && formModel.get('url').touched"
[placeholder]="'ldn-new-service.form.placeholder.url' | translate" formControlName="url" id="url" [placeholder]="'ldn-new-service.form.placeholder.url' | translate" formControlName="url" id="url"
name="url" name="url"
type="text"> type="text">
<div *ngIf="formModel.get('url').invalid && formModel.get('url').touched" class="error-text">
{{ 'ldn-new-service.form.error.url' | translate }}
</div>
</div> </div>
<div class="mb-4">
&nbsp;
</div>
<!-- In the ldnUrl section --> <!-- In the ldnUrl section -->
<div class="mb-2"> <div class="mb-5 mt-5">
<label for="ldnUrl">{{ 'ldn-new-service.form.label.ldnUrl' | translate }}</label> <label for="ldnUrl">{{ 'ldn-new-service.form.label.ldnUrl' | translate }}</label>
<input [class.invalid-field]="formModel.get('ldnUrl').invalid && formModel.get('ldnUrl').touched" <input [class.invalid-field]="formModel.get('ldnUrl').invalid && formModel.get('ldnUrl').touched"
[placeholder]="'ldn-new-service.form.placeholder.ldnUrl' | translate" formControlName="ldnUrl" [placeholder]="'ldn-new-service.form.placeholder.ldnUrl' | translate" formControlName="ldnUrl"
id="ldnUrl" id="ldnUrl"
name="ldnUrl" name="ldnUrl"
type="text"> type="text">
<div *ngIf="formModel.get('ldnUrl').invalid && formModel.get('ldnUrl').touched" class="error-text">
{{ 'ldn-new-service.form.error.ldnurl' | translate }}
</div>
</div>
<!-- In the score section -->
<div class="mb-2">
<label for="score">{{ 'ldn-new-service.form.label.score' | translate }}</label>
<input [class.invalid-field]="formModel.get('score').invalid && formModel.get('score').touched"
[placeholder]="'ldn-new-service.form.placeholder.score' | translate" formControlName="score"
id="score"
name="score"
type="text">
<div *ngIf="formModel.get('score').invalid && formModel.get('score').touched" class="error-text">
{{ 'ldn-new-service.form.error.score' | translate }}
</div> </div>
<div class="mb-4">
&nbsp;
</div> </div>
<!-- In the Inbound Patterns section --> <!-- In the Inbound Patterns section -->
<div class="row"> <div class="row mb-2 mt-5">
<div class="col"> <div class="col">
<label>{{ 'ldn-new-service.form.label.inboundPattern' | translate }} </label> <label>{{ 'ldn-new-service.form.label.inboundPattern' | translate }} </label>
</div> </div>
@@ -65,7 +73,7 @@
<div class="col-sm1 "> <div class="col-sm1 ">
<label class="label-box-2">{{ 'ldn-new-service.form.label.automatic' | translate }}</label> <label class="label-box-2">{{ 'ldn-new-service.form.label.automatic' | translate }}</label>
</div> </div>
<div class="col-sm-1"> <div class="col-sm-2">
</div> </div>
</div> </div>
@@ -81,8 +89,11 @@
name="additionalInboundPattern{{i}}" required> name="additionalInboundPattern{{i}}" required>
<option value="">{{ 'ldn-new-service.form.label.placeholder.inboundPattern' | translate }}</option> <option value="">{{ 'ldn-new-service.form.label.placeholder.inboundPattern' | translate }}</option>
<option *ngFor="let pattern of inboundPatterns" <option *ngFor="let pattern of inboundPatterns"
[ngValue]="pattern.name">{{ pattern.name }}</option> [value]="pattern">{{ 'ldn-service.form.pattern.' + pattern + '.label' | translate }} </option>
</select> </select>
<div *ngIf="!patternSelected()" class="error-text">
{{ 'ldn-new-service.form.error.patterns' | translate }}
</div>
</div> </div>
@@ -116,24 +127,22 @@
</div> </div>
<span (click)="addInboundPattern()" <span (click)="addInboundPattern()"
class="add-pattern-link mb-2">{{ 'ldn-new-service.form.label.addPattern' | translate }}</span> class="add-pattern-link mb-4">{{ 'ldn-new-service.form.label.addPattern' | translate }}</span>
<div class="mb-4">
&nbsp;
</div>
<!-- In the Outbound Patterns section --> <!-- In the Outbound Patterns section -->
<div class="row"> <div class="row mb-1 mt-5">
<div class="col"> <div class="col">
<label>{{ 'ldn-new-service.form.label.outboundPattern' | translate }} </label> <label>{{ 'ldn-new-service.form.label.outboundPattern' | translate }} </label>
</div> </div>
<div class="col"> <div class="col">
<label class="label-box">{{ 'ldn-new-service.form.label.ItemFilter' | translate }}</label> <label class="label-box">{{ 'ldn-new-service.form.label.ItemFilter' | translate }}</label>
</div> </div>
<div class="col-sm-1 "> <div class="col-sm1 ">
<label class="label-box-2" style="visibility: hidden;">
{{ 'ldn-new-service.form.label.automatic' | translate }}
</label>
</div> </div>
<div class="col-sm-1 "> <div class="col-sm-2">
</div> </div>
</div> </div>
@@ -150,8 +159,11 @@
required> required>
<option value="">{{ 'ldn-new-service.form.label.placeholder.outboundPattern' | translate }}</option> <option value="">{{ 'ldn-new-service.form.label.placeholder.outboundPattern' | translate }}</option>
<option *ngFor="let pattern of outboundPatterns" <option *ngFor="let pattern of outboundPatterns"
[ngValue]="pattern.name">{{ pattern.name }}</option> [value]="pattern">{{ 'ldn-service.form.pattern.' + pattern + '.label' | translate }}</option>
</select> </select>
<div *ngIf="!patternSelected()" class="error-text">
{{ 'ldn-new-service.form.error.patterns' | translate }}
</div>
</div> </div>
<div class="col"> <div class="col">
<ng-container *ngIf="outboundPattern.value"> <ng-container *ngIf="outboundPattern.value">
@@ -182,11 +194,8 @@
</div> </div>
<span (click)="addOutboundPattern()" <span (click)="addOutboundPattern()"
class="add-pattern-link">{{ 'ldn-new-service.form.label.addPattern' | translate }} class="add-pattern-link mb-4">{{ 'ldn-new-service.form.label.addPattern' | translate }}
</span> </span>
<div class="mb-4">
&nbsp;
</div>
<div aria-label="Basic example" class="submission-form-footer mt-1 mb-1 position-sticky" role="group"> <div aria-label="Basic example" class="submission-form-footer mt-1 mb-1 position-sticky" role="group">
<button class="btn btn-primary" type="submit"> <button class="btn btn-primary" type="submit">
@@ -198,8 +207,6 @@
</button> </button>
</div> </div>
</div> </div>
</form> </form>
</div> </div>
<ng-template #confirmModal> <ng-template #confirmModal>

View File

@@ -1,8 +1,6 @@
form { form {
max-width: 800px;
font-size: 14px; font-size: 14px;
position: relative; position: relative;
} }
input[type="text"], input[type="text"],
@@ -49,6 +47,12 @@ textarea {
color: #000000; color: #000000;
} }
.error-text {
color: red;
font-size: 0.8em;
margin-top: 5px;
}
.toggle-switch { .toggle-switch {
display: flex; display: flex;
align-items: center; align-items: center;

View File

@@ -58,6 +58,7 @@ export class LdnServiceFormComponent implements OnInit {
@Input() public name: string; @Input() public name: string;
@Input() public description: string; @Input() public description: string;
@Input() public url: string; @Input() public url: string;
@Input() public score: string;
@Input() public ldnUrl: string; @Input() public ldnUrl: string;
@Input() public inboundPattern: string; @Input() public inboundPattern: string;
@Input() public outboundPattern: string; @Input() public outboundPattern: string;
@@ -67,6 +68,9 @@ export class LdnServiceFormComponent implements OnInit {
@Output() submitForm: EventEmitter<any> = new EventEmitter(); @Output() submitForm: EventEmitter<any> = new EventEmitter();
@Output() cancelForm: EventEmitter<any> = new EventEmitter(); @Output() cancelForm: EventEmitter<any> = new EventEmitter();
private modalRef: any; private modalRef: any;
hasInboundPattern: boolean;
hasOutboundPattern: boolean;
isScoreValid: boolean;
constructor( constructor(
private ldnServicesService: LdnServicesService, private ldnServicesService: LdnServicesService,
@@ -85,6 +89,7 @@ export class LdnServiceFormComponent implements OnInit {
name: ['', Validators.required], name: ['', Validators.required],
description: [''], description: [''],
url: ['', Validators.required], url: ['', Validators.required],
score: ['', [Validators.required, Validators.pattern('^0*(\.[0-9]+)?$|^1(\.0+)?$')]],
ldnUrl: ['', Validators.required], ldnUrl: ['', Validators.required],
inboundPattern: [''], inboundPattern: [''],
outboundPattern: [''], outboundPattern: [''],
@@ -119,14 +124,21 @@ export class LdnServiceFormComponent implements OnInit {
createService() { createService() {
this.formModel.get('name').markAsTouched(); this.formModel.get('name').markAsTouched();
this.formModel.get('score').markAsTouched();
this.formModel.get('url').markAsTouched(); this.formModel.get('url').markAsTouched();
this.formModel.get('ldnUrl').markAsTouched(); this.formModel.get('ldnUrl').markAsTouched();
this.formModel.get('notifyServiceInboundPatterns').markAsTouched();
this.formModel.get('notifyServiceOutboundPatterns').markAsTouched();
const name = this.formModel.get('name').value; const name = this.formModel.get('name').value;
const url = this.formModel.get('url').value; const url = this.formModel.get('url').value;
const score = this.formModel.get('score').value;
const ldnUrl = this.formModel.get('ldnUrl').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(); this.closeModal();
return; return;
} }
@@ -144,15 +156,26 @@ export class LdnServiceFormComponent implements OnInit {
if (rd.hasSucceeded) { if (rd.hasSucceeded) {
this.notificationsService.success(this.translateService.get('ldn-service-notification.created.success.title'), this.notificationsService.success(this.translateService.get('ldn-service-notification.created.success.title'),
this.translateService.get('ldn-service-notification.created.success.body')); this.translateService.get('ldn-service-notification.created.success.body'));
this.sendBack(); this.sendBack();
this.closeModal(); this.closeModal();
} else { } 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() { resetFormAndLeave() {
this.sendBack(); 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() { private sendBack() {
this.router.navigateByUrl('admin/ldn/services'); this.router.navigateByUrl('admin/ldn/services');
} }

View File

@@ -32,6 +32,9 @@ export class LdnService extends CacheableObject {
@autoserialize @autoserialize
url: string; url: string;
@autoserialize
score: number;
@autoserialize @autoserialize
enabled: boolean; enabled: boolean;

View File

@@ -941,6 +941,12 @@
"ldn-new-service.form.label.placeholder.selectedItemFilter": "No Item Filter Selected", "ldn-new-service.form.label.placeholder.selectedItemFilter": "No Item Filter Selected",
"ldn-new-service.form.label.ItemFilter": "Item Filter", "ldn-new-service.form.label.ItemFilter": "Item Filter",
"ldn-new-service.form.label.automatic": "Automatic", "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.outboundPattern": "Outbound Patterns",
"ldn-new-service.form.label.placeholder.outboundPattern": "Select an Outbound Pattern", "ldn-new-service.form.label.placeholder.outboundPattern": "Select an Outbound Pattern",
"ldn-new-service.form.label.addPattern": "+ Add more", "ldn-new-service.form.label.addPattern": "+ Add more",