CST-12455_coar-7sync Refactor after branch sync

This commit is contained in:
Mattia Vianelli
2023-11-16 19:36:56 +01:00
parent 18367bab58
commit 6303d4c7e6
22 changed files with 1921 additions and 1894 deletions

View File

@@ -6,29 +6,29 @@ import {LdnServiceNewComponent} from './ldn-service-new/ldn-service-new.componen
import {LdnServiceFormEditComponent} from './ldn-service-form-edit/ldn-service-form-edit.component'; import {LdnServiceFormEditComponent} from './ldn-service-form-edit/ldn-service-form-edit.component';
@NgModule({ @NgModule({
imports: [ imports: [
RouterModule.forChild([ RouterModule.forChild([
{ {
path: '', path: '',
pathMatch: 'full', pathMatch: 'full',
component: LdnServicesOverviewComponent, component: LdnServicesOverviewComponent,
resolve: {breadcrumb: I18nBreadcrumbResolver}, resolve: {breadcrumb: I18nBreadcrumbResolver},
data: {title: 'ldn-registered-services.title', breadcrumbKey: 'ldn-registered-services.new'}, data: {title: 'ldn-registered-services.title', breadcrumbKey: 'ldn-registered-services.new'},
}, },
{ {
path: 'new', path: 'new',
resolve: {breadcrumb: I18nBreadcrumbResolver}, resolve: {breadcrumb: I18nBreadcrumbResolver},
component: LdnServiceNewComponent, component: LdnServiceNewComponent,
data: {title: 'ldn-register-new-service.title', breadcrumbKey: 'ldn-register-new-service'} data: {title: 'ldn-register-new-service.title', breadcrumbKey: 'ldn-register-new-service'}
}, },
{ {
path: 'edit/:serviceId', path: 'edit/:serviceId',
resolve: {breadcrumb: I18nBreadcrumbResolver}, resolve: {breadcrumb: I18nBreadcrumbResolver},
component: LdnServiceFormEditComponent, component: LdnServiceFormEditComponent,
data: {title: 'ldn-edit-service.title', breadcrumbKey: 'ldn-edit-service'} data: {title: 'ldn-edit-service.title', breadcrumbKey: 'ldn-edit-service'}
}, },
]), ]),
] ]
}) })
export class AdminLdnServicesRoutingModule { export class AdminLdnServicesRoutingModule {

View File

@@ -11,19 +11,19 @@ import {LdnItemfiltersService} from './ldn-services-data/ldn-itemfilters-data.se
@NgModule({ @NgModule({
imports: [ imports: [
CommonModule, CommonModule,
SharedModule, SharedModule,
AdminLdnServicesRoutingModule, AdminLdnServicesRoutingModule,
FormsModule FormsModule
], ],
declarations: [ declarations: [
LdnServicesOverviewComponent, LdnServicesOverviewComponent,
LdnServiceNewComponent, LdnServiceNewComponent,
LdnServiceFormComponent, LdnServiceFormComponent,
LdnServiceFormEditComponent, LdnServiceFormEditComponent,
], ],
providers: [LdnItemfiltersService] providers: [LdnItemfiltersService]
}) })
export class AdminLdnServicesModule { export class AdminLdnServicesModule {
} }

View File

@@ -1,397 +1,414 @@
<div class="container"> <div class="container">
<form (ngSubmit)="onSubmit()" [formGroup]="formModel"> <form (ngSubmit)="onSubmit()" [formGroup]="formModel">
<div class="d-flex"> <div class="d-flex">
<h2 class="flex-grow-1">{{ 'ldn-edit-registered-service.title' | translate }}</h2> <h2 class="flex-grow-1">{{ 'ldn-edit-registered-service.title' | translate }}</h2>
</div>
<!-- In the toggle section -->
<div class="toggle-switch-container">
<label class="status-label" for="enabled">{{ 'ldn-service-status' | translate }}</label>
<div>
<input formControlName="enabled" hidden id="enabled" name="enabled" type="checkbox">
<div (click)="toggleEnabled()" [class.checked]="formModel.get('enabled').value" class="toggle-switch">
<div class="slider"></div>
</div> </div>
</div> <!-- In the toggle section -->
</div> <div class="toggle-switch-container">
<label class="status-label" for="enabled">{{ 'ldn-service-status' | translate }}</label>
<div class="mb-5"> <div>
<label for="name">{{ 'ldn-new-service.form.label.name' | translate }}</label> <input formControlName="enabled" hidden id="enabled" name="enabled" type="checkbox">
<input [class.invalid-field]="formModel.get('name').invalid && formModel.get('name').touched" <div (click)="toggleEnabled()" [class.checked]="formModel.get('enabled').value" class="toggle-switch">
[placeholder]="'ldn-new-service.form.placeholder.name' | translate" formControlName="name" id="name" <div class="slider"></div>
name="name"
type="text"
class="form-control">
<div *ngIf="formModel.get('name').invalid && formModel.get('name').touched" class="error-text">
{{ 'ldn-new-service.form.error.name' | translate }}
</div>
</div>
<!-- In the description section -->
<div class="mb-5 mt-5 d-flex flex-column">
<label for="description">{{ 'ldn-new-service.form.label.description' | translate }}</label>
<textarea [placeholder]="'ldn-new-service.form.placeholder.description' | translate"
formControlName="description" id="description" name="description" class="form-control"></textarea>
</div>
<!-- In the url section -->
<div class="mb-5 mt-5">
<label for="url">{{ 'ldn-new-service.form.label.url' | translate }}</label>
<input [class.invalid-field]="formModel.get('url').invalid && formModel.get('url').touched"
[placeholder]="'ldn-new-service.form.placeholder.url' | translate" formControlName="url" id="url"
name="url"
type="text"
class="form-control">
<div *ngIf="formModel.get('url').invalid && formModel.get('url').touched" class="error-text">
{{ 'ldn-new-service.form.error.url' | translate }}
</div>
</div>
<!-- In the ldnUrl section -->
<div class="mb-5 mt-5">
<label for="ldnUrl">{{ 'ldn-new-service.form.label.ldnUrl' | translate }}</label>
<input [class.invalid-field]="formModel.get('ldnUrl').invalid && formModel.get('ldnUrl').touched"
[placeholder]="'ldn-new-service.form.placeholder.ldnUrl' | translate" formControlName="ldnUrl"
id="ldnUrl"
name="ldnUrl"
type="text"
class="form-control">
<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="row mb-1 mt-5">
<div class="col">
<label>{{ 'ldn-new-service.form.label.inboundPattern' | translate }} </label>
</div>
<ng-container *ngIf="!!(formModel.get('notifyServiceInboundPatterns')['controls'][0]?.value?.pattern)">
<div class="col">
<label>{{ 'ldn-new-service.form.label.ItemFilter' | translate }}</label>
</div>
<div class="col-sm-1">
<label class="">{{ 'ldn-new-service.form.label.automatic' | translate }}</label>
</div>
</ng-container>
<div class="col-sm-2">
</div>
</div>
<div *ngFor="let patternGroup of formModel.get('notifyServiceInboundPatterns')['controls']; let i = index"
[class.marked-for-deletion]="markedForDeletionInboundPattern.includes(i)"
formGroupName="notifyServiceInboundPatterns">
<ng-container [formGroupName]="i">
<div class="row mb-1">
<div class="col">
<div #inboundPatternDropdown="ngbDropdown" class="w-80" display="dynamic" id="additionalInboundPattern{{i}}"
ngbDropdown placement="bottom-start">
<div class="position-relative right-addon" role="combobox">
<i aria-hidden="true" class="position-absolute scrollable-dropdown-toggle"
ngbDropdownToggle></i>
<input
(click)="inboundPatternDropdown.open();"
[readonly]="true"
class="form-control w-80 scrollable-dropdown-input"
formControlName="patternLabel"
id="inboundPatternDropdownButton"
ngbDropdownAnchor
type="text"
/>
<!-- TODO: infinite scroll with 3 selects -->
<div aria-labelledby="inboundPatternDropdownButton" ngbDropdownMenu class="dropdown-menu scrollable-dropdown-menu w-100 " >
<div class="scrollable-menu" role="listbox">
<button (click)="selectInboundPattern(pattern, i); $event.stopPropagation()" class="dropdown-item collection-item text-truncate w-100"
*ngFor="let pattern of inboundPatterns; let internalIndex = index"
ngbDropdownItem
type="button"
[title]="'ldn-service.form.pattern.' + pattern + '.description' | translate">
<div>{{ 'ldn-service.form.pattern.' + pattern + '.label' | translate }}</div>
<div
class="small-text">{{ 'ldn-service.form.pattern.' + pattern + '.description' | translate }}</div>
</button>
</div>
</div> </div>
</div>
</div> </div>
</div> </div>
<div class="col"> <div class="mb-5">
<ng-container *ngIf="!!(formModel.get('notifyServiceInboundPatterns')['controls'][i].value.pattern)"> <label for="name">{{ 'ldn-new-service.form.label.name' | translate }}</label>
<div #inboundItemfilterDropdown="ngbDropdown" class="w-100" id="constraint{{i}}" ngbDropdown <input [class.invalid-field]="formModel.get('name').invalid && formModel.get('name').touched"
placement="bottom-start"> [placeholder]="'ldn-new-service.form.placeholder.name' | translate" class="form-control" formControlName="name"
<div class="position-relative right-addon" role="combobox"> id="name"
<i aria-hidden="true" class="position-absolute scrollable-dropdown-toggle" name="name"
ngbDropdownToggle></i> type="text">
<input <div *ngIf="formModel.get('name').invalid && formModel.get('name').touched" class="error-text">
(click)="inboundItemfilterDropdown.open();" {{ 'ldn-new-service.form.error.name' | translate }}
[readonly]="true" </div>
[value]="selectedInboundItemfilters" </div>
class="form-control w-100 scrollable-dropdown-input"
formControlName="constraint" <!-- In the description section -->
id="inboundItemfilterDropdown" <div class="mb-5 mt-5 d-flex flex-column">
ngbDropdownAnchor <label for="description">{{ 'ldn-new-service.form.label.description' | translate }}</label>
type="text" <textarea [placeholder]="'ldn-new-service.form.placeholder.description' | translate"
/> class="form-control" formControlName="description" id="description" name="description"></textarea>
<!-- TODO: infinite scroll with 3 selects --> </div>
<div aria-labelledby="inboundItemfilterDropdownButton" ngbDropdownMenu class="dropdown-menu scrollable-dropdown-menu w-100 " >
<div class="scrollable-menu" role="listbox"> <!-- In the url section -->
<button (click)="selectInboundItemFilter(constraint.id, i); $event.stopPropagation()" class="dropdown-item collection-item text-truncate w-100" <div class="mb-5 mt-5">
*ngFor="let constraint of (itemfiltersRD$ | async)?.payload?.page; let internalIndex = index" <label for="url">{{ 'ldn-new-service.form.label.url' | translate }}</label>
ngbDropdownItem <input [class.invalid-field]="formModel.get('url').invalid && formModel.get('url').touched"
type="button"> [placeholder]="'ldn-new-service.form.placeholder.url' | translate" class="form-control" formControlName="url"
<div>{{ constraint.id }}</div> id="url"
</button> name="url"
</div> type="text">
</div> <div *ngIf="formModel.get('url').invalid && formModel.get('url').touched" class="error-text">
{{ 'ldn-new-service.form.error.url' | translate }}
</div>
</div>
<!-- In the ldnUrl section -->
<div class="mb-5 mt-5">
<label for="ldnUrl">{{ 'ldn-new-service.form.label.ldnUrl' | translate }}</label>
<input [class.invalid-field]="formModel.get('ldnUrl').invalid && formModel.get('ldnUrl').touched"
[placeholder]="'ldn-new-service.form.placeholder.ldnUrl' | translate" class="form-control"
formControlName="ldnUrl"
id="ldnUrl"
name="ldnUrl"
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="row mb-1 mt-5">
<div class="col">
<label>{{ 'ldn-new-service.form.label.inboundPattern' | translate }} </label>
</div>
<ng-container *ngIf="!!(formModel.get('notifyServiceInboundPatterns')['controls'][0]?.value?.pattern)">
<div class="col">
<label>{{ 'ldn-new-service.form.label.ItemFilter' | translate }}</label>
</div>
<div class="col-sm-1">
<label class="">{{ 'ldn-new-service.form.label.automatic' | translate }}</label>
</div> </div>
</div>
</ng-container> </ng-container>
</div> <div class="col-sm-2">
<div
[style.visibility]="formModel.get('notifyServiceInboundPatterns')['controls'][i].value.pattern ? 'visible' : 'hidden'"
class="col-sm-1">
<input formControlName="automatic" hidden id="automatic{{i}}" name="automatic{{i}}"
type="checkbox">
<div (click)="toggleAutomatic(i)"
[class.checked]="formModel.get('notifyServiceInboundPatterns.' + i + '.automatic').value"
class="toggle-switch">
<div class="slider"></div>
</div> </div>
</div>
<div class="col-sm-2">
<div class="btn-group">
<button (click)="markForInboundPatternDeletion(i)" class="btn btn-outline-dark trash-button"
type="button">
<i class="fas fa-trash"></i>
</button>
<button (click)="unmarkForInboundPatternDeletion(i)" *ngIf="markedForDeletionInboundPattern.includes(i)"
class="btn btn-warning "
type="button">
<i class="fas fa-undo"></i>
</button>
</div>
</div> </div>
</div>
</ng-container> <div *ngFor="let patternGroup of formModel.get('notifyServiceInboundPatterns')['controls']; let i = index"
</div> [class.marked-for-deletion]="markedForDeletionInboundPattern.includes(i)"
formGroupName="notifyServiceInboundPatterns">
<ng-container [formGroupName]="i">
<span (click)="addInboundPattern()" <div class="row mb-1">
class="add-pattern-link mb-2">{{ 'ldn-new-service.form.label.addPattern' | translate }}</span> <div class="col">
<div #inboundPatternDropdown="ngbDropdown" class="w-80" display="dynamic"
id="additionalInboundPattern{{i}}"
<div class="row mb-1 mt-5"> ngbDropdown placement="bottom-start">
<div class="col"> <div class="position-relative right-addon" role="combobox">
<label>{{ 'ldn-new-service.form.label.outboundPattern' | translate }} </label> <i aria-hidden="true" class="position-absolute scrollable-dropdown-toggle"
</div> ngbDropdownToggle></i>
<ng-container *ngIf="!!(formModel.get('notifyServiceOutboundPatterns')['controls'][0]?.value?.pattern)"> <input
<div class="col"> (click)="inboundPatternDropdown.open();"
<label>{{ 'ldn-new-service.form.label.ItemFilter' | translate }}</label> [readonly]="true"
</div> class="form-control w-80 scrollable-dropdown-input"
</ng-container> formControlName="patternLabel"
<div class="col-sm-1 "> id="inboundPatternDropdownButton"
<label class="label-box-2" style="visibility: hidden;"> ngbDropdownAnchor
{{ 'ldn-new-service.form.label.automatic' | translate }} type="text"
</label> />
</div> <!-- TODO: infinite scroll with 3 selects -->
<div class="col-sm-2 "> <div aria-labelledby="inboundPatternDropdownButton" class="dropdown-menu scrollable-dropdown-menu w-100 "
</div> ngbDropdownMenu>
</div> <div class="scrollable-menu" role="listbox">
<button (click)="selectInboundPattern(pattern, i); $event.stopPropagation()"
<div *ngFor="let patternGroup of formModel.get('notifyServiceOutboundPatterns')['controls']; let i = index" *ngFor="let pattern of inboundPatterns; let internalIndex = index"
[class.marked-for-deletion]="markedForDeletionOutboundPattern.includes(i)" [title]="'ldn-service.form.pattern.' + pattern + '.description' | translate"
formGroupName="notifyServiceOutboundPatterns"> class="dropdown-item collection-item text-truncate w-100"
ngbDropdownItem
<ng-container [formGroupName]="i"> type="button">
<div>{{ 'ldn-service.form.pattern.' + pattern + '.label' | translate }}</div>
<!-- Input elements in a separate row --> <div
<div class="row mb-1"> class="small-text">{{ 'ldn-service.form.pattern.' + pattern + '.description' | translate }}</div>
<div class="col"> </button>
<div #outboundPatternDropdown="ngbDropdown" class="w-100" id="additionalOutboundPattern{{i}}" ngbDropdown </div>
placement="bottom-start"> </div>
<div class="position-relative right-addon" role="combobox"> </div>
<i aria-hidden="true" class="position-absolute scrollable-dropdown-toggle" </div>
ngbDropdownToggle></i> </div>
<input
(click)="outboundPatternDropdown.open();" <div class="col">
[readonly]="true" <ng-container
[value]="selectedOutboundPatterns" *ngIf="!!(formModel.get('notifyServiceInboundPatterns')['controls'][i].value.pattern)">
class="form-control w-100 scrollable-dropdown-input" <div #inboundItemfilterDropdown="ngbDropdown" class="w-100" id="constraint{{i}}" ngbDropdown
formControlName="patternLabel" placement="bottom-start">
id="outboundPatternDropdownButton" <div class="position-relative right-addon" role="combobox">
ngbDropdownAnchor <i aria-hidden="true" class="position-absolute scrollable-dropdown-toggle"
type="text" ngbDropdownToggle></i>
/> <input
<!-- TODO: infinite scroll with 3-5 selects --> (click)="inboundItemfilterDropdown.open();"
<div aria-labelledby="outboundPatternDropdownButton" ngbDropdownMenu class="dropdown-menu scrollable-dropdown-menu w-100 " > [readonly]="true"
<div class="scrollable-menu" role="listbox"> [value]="selectedInboundItemfilters"
<button (click)="selectOutboundPattern(pattern, i); $event.stopPropagation()" class="dropdown-item collection-item text-truncate w-100" class="form-control w-100 scrollable-dropdown-input"
*ngFor="let pattern of outboundPatterns; let internalIndex = index" formControlName="constraint"
ngbDropdownItem id="inboundItemfilterDropdown"
type="button" ngbDropdownAnchor
[title]="'ldn-service.form.pattern.' + pattern + '.description' | translate"> type="text"
<div>{{ 'ldn-service.form.pattern.' + pattern + '.label' | translate }}</div> />
<div <!-- TODO: infinite scroll with 3 selects -->
class="small-text">{{ 'ldn-service.form.pattern.' + pattern + '.description' | translate }}</div> <div aria-labelledby="inboundItemfilterDropdownButton" class="dropdown-menu scrollable-dropdown-menu w-100 "
</button> ngbDropdownMenu>
</div> <div class="scrollable-menu" role="listbox">
</div> <button (click)="selectInboundItemFilter(constraint.id, i); $event.stopPropagation()"
</div> *ngFor="let constraint of (itemfiltersRD$ | async)?.payload?.page; let internalIndex = index"
</div> class="dropdown-item collection-item text-truncate w-100"
</div> ngbDropdownItem
<div class="col"> type="button">
<ng-container *ngIf="!!(formModel.get('notifyServiceOutboundPatterns')['controls'][i].value.pattern)"> <div>{{ constraint.id }}</div>
<div #outboundItemfilterDropdown="ngbDropdown" class="w-100" id="constraint{{i}}" ngbDropdown </button>
placement="bottom-start"> </div>
<div class="position-relative right-addon" role="combobox"> </div>
<i aria-hidden="true" class="position-absolute scrollable-dropdown-toggle" </div>
ngbDropdownToggle></i> </div>
<input </ng-container>
(click)="outboundItemfilterDropdown.open();" </div>
[readonly]="true"
[value]="selectedOutboundItemfilters" <div
class="form-control w-100 scrollable-dropdown-input" [style.visibility]="formModel.get('notifyServiceInboundPatterns')['controls'][i].value.pattern ? 'visible' : 'hidden'"
formControlName="constraint" class="col-sm-1">
id="outboundItemfilterDropdown" <input formControlName="automatic" hidden id="automatic{{i}}" name="automatic{{i}}"
ngbDropdownAnchor type="checkbox">
type="text" <div (click)="toggleAutomatic(i)"
/> [class.checked]="formModel.get('notifyServiceInboundPatterns.' + i + '.automatic').value"
<!-- TODO: infinite scroll with 3 selects --> class="toggle-switch">
<div aria-labelledby="outboundItemfilterDropdownButton" ngbDropdownMenu class="dropdown-menu scrollable-dropdown-menu w-100 " > <div class="slider"></div>
<div class="scrollable-menu" role="listbox"> </div>
<button (click)="selectOutboundItemFilter(constraint.id, i); $event.stopPropagation()" class="dropdown-item collection-item text-truncate w-100" </div>
*ngFor="let constraint of (itemfiltersRD$ | async)?.payload?.page; let internalIndex = index"
ngbDropdownItem
type="button"> <div class="col-sm-2">
<div>{{ constraint.id }}</div> <div class="btn-group">
</button> <button (click)="markForInboundPatternDeletion(i)" class="btn btn-outline-dark trash-button"
type="button">
<i class="fas fa-trash"></i>
</button>
<button (click)="unmarkForInboundPatternDeletion(i)"
*ngIf="markedForDeletionInboundPattern.includes(i)"
class="btn btn-warning "
type="button">
<i class="fas fa-undo"></i>
</button>
</div>
</div> </div>
</div>
</div> </div>
</div>
</ng-container> </ng-container>
</div>
<div [style.visibility]="'hidden'" class="col-sm-1">
<input hidden id="automatic{{i}}" name="automatic{{i}}" type="checkbox">
<div
class="toggle-switch">
<div class="slider"></div>
</div>
</div>
<div class="col-sm-2">
<div class="btn-group">
<button (click)="markForOutboundPatternDeletion(i)" class="btn btn-outline-dark trash-button" type="button">
<i class="fas fa-trash"></i>
</button>
<button (click)="unmarkForOutboundPatternDeletion(i)" *ngIf="markedForDeletionOutboundPattern.includes(i)"
class="btn btn-warning "
type="button">
<i class="fas fa-undo"></i>
</button></div>
</div>
</div> </div>
</ng-container>
</div>
<span
(click)="addOutboundPattern()" <span (click)="addInboundPattern()"
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>
<div class="row mb-1 mt-5">
<div class="col">
<label>{{ 'ldn-new-service.form.label.outboundPattern' | translate }} </label>
</div>
<ng-container *ngIf="!!(formModel.get('notifyServiceOutboundPatterns')['controls'][0]?.value?.pattern)">
<div class="col">
<label>{{ 'ldn-new-service.form.label.ItemFilter' | translate }}</label>
</div>
</ng-container>
<div class="col-sm-1 ">
<label class="label-box-2" style="visibility: hidden;">
{{ 'ldn-new-service.form.label.automatic' | translate }}
</label>
</div>
<div class="col-sm-2 ">
</div>
</div>
<div *ngFor="let patternGroup of formModel.get('notifyServiceOutboundPatterns')['controls']; let i = index"
[class.marked-for-deletion]="markedForDeletionOutboundPattern.includes(i)"
formGroupName="notifyServiceOutboundPatterns">
<ng-container [formGroupName]="i">
<!-- Input elements in a separate row -->
<div class="row mb-1">
<div class="col">
<div #outboundPatternDropdown="ngbDropdown" class="w-100" id="additionalOutboundPattern{{i}}"
ngbDropdown
placement="bottom-start">
<div class="position-relative right-addon" role="combobox">
<i aria-hidden="true" class="position-absolute scrollable-dropdown-toggle"
ngbDropdownToggle></i>
<input
(click)="outboundPatternDropdown.open();"
[readonly]="true"
[value]="selectedOutboundPatterns"
class="form-control w-100 scrollable-dropdown-input"
formControlName="patternLabel"
id="outboundPatternDropdownButton"
ngbDropdownAnchor
type="text"
/>
<!-- TODO: infinite scroll with 3-5 selects -->
<div aria-labelledby="outboundPatternDropdownButton" class="dropdown-menu scrollable-dropdown-menu w-100 "
ngbDropdownMenu>
<div class="scrollable-menu" role="listbox">
<button (click)="selectOutboundPattern(pattern, i); $event.stopPropagation()"
*ngFor="let pattern of outboundPatterns; let internalIndex = index"
[title]="'ldn-service.form.pattern.' + pattern + '.description' | translate"
class="dropdown-item collection-item text-truncate w-100"
ngbDropdownItem
type="button">
<div>{{ 'ldn-service.form.pattern.' + pattern + '.label' | translate }}</div>
<div
class="small-text">{{ 'ldn-service.form.pattern.' + pattern + '.description' | translate }}</div>
</button>
</div>
</div>
</div>
</div>
</div>
<div class="col">
<ng-container
*ngIf="!!(formModel.get('notifyServiceOutboundPatterns')['controls'][i].value.pattern)">
<div #outboundItemfilterDropdown="ngbDropdown" class="w-100" id="constraint{{i}}"
ngbDropdown
placement="bottom-start">
<div class="position-relative right-addon" role="combobox">
<i aria-hidden="true" class="position-absolute scrollable-dropdown-toggle"
ngbDropdownToggle></i>
<input
(click)="outboundItemfilterDropdown.open();"
[readonly]="true"
[value]="selectedOutboundItemfilters"
class="form-control w-100 scrollable-dropdown-input"
formControlName="constraint"
id="outboundItemfilterDropdown"
ngbDropdownAnchor
type="text"
/>
<!-- TODO: infinite scroll with 3 selects -->
<div aria-labelledby="outboundItemfilterDropdownButton" class="dropdown-menu scrollable-dropdown-menu w-100 "
ngbDropdownMenu>
<div class="scrollable-menu" role="listbox">
<button (click)="selectOutboundItemFilter(constraint.id, i); $event.stopPropagation()"
*ngFor="let constraint of (itemfiltersRD$ | async)?.payload?.page; let internalIndex = index"
class="dropdown-item collection-item text-truncate w-100"
ngbDropdownItem
type="button">
<div>{{ constraint.id }}</div>
</button>
</div>
</div>
</div>
</div>
</ng-container>
</div>
<div [style.visibility]="'hidden'" class="col-sm-1">
<input hidden id="automatic{{i}}" name="automatic{{i}}" type="checkbox">
<div
class="toggle-switch">
<div class="slider"></div>
</div>
</div>
<div class="col-sm-2">
<div class="btn-group">
<button (click)="markForOutboundPatternDeletion(i)"
class="btn btn-outline-dark trash-button" type="button">
<i class="fas fa-trash"></i>
</button>
<button (click)="unmarkForOutboundPatternDeletion(i)"
*ngIf="markedForDeletionOutboundPattern.includes(i)"
class="btn btn-warning "
type="button">
<i class="fas fa-undo"></i>
</button>
</div>
</div>
</div>
</ng-container>
</div>
<span
(click)="addOutboundPattern()"
class="add-pattern-link mb-2">{{ 'ldn-new-service.form.label.addPattern' | translate }}
</span> </span>
<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>
</button> </button>
<div class="d-flex"> <div class="d-flex">
<button (click)="openResetFormModal(resetFormModal)" class="btn btn-danger" type="button"> <button (click)="openResetFormModal(resetFormModal)" class="btn btn-danger" type="button">
<span><i class="fas fa-trash"></i> {{ 'submission.general.discard.submit' | translate }}</span> <span><i class="fas fa-trash"></i> {{ 'submission.general.discard.submit' | translate }}</span>
</button> </button>
</div> </div>
</div> </div>
</form> </form>
</div> </div>
<ng-template #confirmModal> <ng-template #confirmModal>
<div> <div>
<div class="modal-header"> <div class="modal-header">
<div> <div>
<h4>{{'service.overview.edit.modal' | translate }}</h4> <h4>{{'service.overview.edit.modal' | translate }}</h4>
</div> </div>
<button (click)="closeModal()" aria-label="Close" <button (click)="closeModal()" aria-label="Close"
class="close" type="button"> class="close" type="button">
<span aria-hidden="true">×</span> <span aria-hidden="true">×</span>
</button> </button>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<div> <div>
{{ 'service.overview.edit.body' | translate }} {{ 'service.overview.edit.body' | translate }}
</div> </div>
<div class="mt-4"> <div class="mt-4">
<button (click)="closeModal()" class="btn btn-danger mr-2" <button (click)="closeModal()" class="btn btn-danger mr-2"
id="delete-confirm">{{ 'service.detail.return' | translate }} id="delete-confirm">{{ 'service.detail.return' | translate }}
</button> </button>
<button (click)="patchService()" <button (click)="patchService()"
class="btn btn-primary custom-btn">{{ 'service.detail.update' | translate }} class="btn btn-primary custom-btn">{{ 'service.detail.update' | translate }}
</button> </button>
</div> </div>
</div>
</div> </div>
</div>
</ng-template> </ng-template>
<ng-template #resetFormModal> <ng-template #resetFormModal>
<div> <div>
<div class="modal-header"> <div class="modal-header">
<div> <div>
<h4>{{'service.overview.reset-form.modal' | translate }}</h4> <h4>{{'service.overview.reset-form.modal' | translate }}</h4>
</div> </div>
<button (click)="closeModal()" aria-label="Close" <button (click)="closeModal()" aria-label="Close"
class="close" type="button"> class="close" type="button">
<span aria-hidden="true">×</span> <span aria-hidden="true">×</span>
</button> </button>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<div> <div>
{{ 'service.overview.reset-form.body' | translate }} {{ 'service.overview.reset-form.body' | translate }}
</div> </div>
<div class="mt-4"> <div class="mt-4">
<button (click)="closeModal()" class="mr-2 btn btn-danger" <button (click)="closeModal()" class="mr-2 btn btn-danger"
id="reset-delete">{{ 'service.overview.reset-form.reset-confirm' | translate }} id="reset-delete">{{ 'service.overview.reset-form.reset-confirm' | translate }}
</button> </button>
<button (click)="resetFormAndLeave()" <button (click)="resetFormAndLeave()"
class="btn btn-primary custom-btn" class="btn btn-primary custom-btn"
id="reset-confirm">{{ 'service.overview.reset-form.reset-return' | translate }} id="reset-confirm">{{ 'service.overview.reset-form.reset-return' | translate }}
</button> </button>
</div> </div>
</div>
</div> </div>
</div>
</ng-template> </ng-template>

View File

@@ -18,62 +18,62 @@ import {RouteService} from '../../../core/services/route.service';
import {provideMockStore} from '@ngrx/store/testing'; import {provideMockStore} from '@ngrx/store/testing';
describe('LdnServiceFormEditComponent', () => { describe('LdnServiceFormEditComponent', () => {
let component: LdnServiceFormEditComponent; let component: LdnServiceFormEditComponent;
let fixture: ComponentFixture<LdnServiceFormEditComponent>; let fixture: ComponentFixture<LdnServiceFormEditComponent>;
let ldnServicesService: any; let ldnServicesService: any;
let ldnItemfiltersService: any; let ldnItemfiltersService: any;
let cdRefStub: any; let cdRefStub: any;
let modalService: any; let modalService: any;
const translateServiceStub = { const translateServiceStub = {
get: () => of('translated-text'), get: () => of('translated-text'),
onLangChange: new EventEmitter(), onLangChange: new EventEmitter(),
onTranslationChange: new EventEmitter(), onTranslationChange: new EventEmitter(),
onDefaultLangChange: new EventEmitter() onDefaultLangChange: new EventEmitter()
};
beforeEach(async () => {
ldnServicesService = {
update: () => ({}),
}; };
ldnItemfiltersService = {
findAll: () => of(['item1', 'item2']), beforeEach(async () => {
}; ldnServicesService = {
cdRefStub = Object.assign({ update: () => ({}),
detectChanges: () => fixture.detectChanges() };
ldnItemfiltersService = {
findAll: () => of(['item1', 'item2']),
};
cdRefStub = Object.assign({
detectChanges: () => fixture.detectChanges()
});
modalService = {
open: () => {/*comment*/
}
};
await TestBed.configureTestingModule({
imports: [ReactiveFormsModule, TranslateModule.forRoot()],
declarations: [LdnServiceFormEditComponent],
providers: [
{provide: LdnServicesService, useValue: ldnServicesService},
{provide: LdnItemfiltersService, useValue: ldnItemfiltersService},
{provide: Router, useValue: new RouterStub()},
{provide: ActivatedRoute, useValue: new MockActivatedRoute()},
{provide: ChangeDetectorRef, useValue: cdRefStub},
{provide: NgbModal, useValue: modalService},
{provide: NotificationsService, useValue: NotificationsServiceStub},
{provide: TranslateService, useValue: translateServiceStub},
{provide: PaginationService, useValue: {}},
FormBuilder,
RouteService,
provideMockStore({}),
]
})
.compileComponents();
fixture = TestBed.createComponent(LdnServiceFormEditComponent);
component = fixture.componentInstance;
fixture.detectChanges();
}); });
modalService = {
open: () => {/*comment*/
}
};
await TestBed.configureTestingModule({ it('should create', () => {
imports: [ReactiveFormsModule, TranslateModule.forRoot()], expect(component).toBeTruthy();
declarations: [LdnServiceFormEditComponent], });
providers: [
{provide: LdnServicesService, useValue: ldnServicesService},
{provide: LdnItemfiltersService, useValue: ldnItemfiltersService},
{provide: Router, useValue: new RouterStub()},
{provide: ActivatedRoute, useValue: new MockActivatedRoute()},
{provide: ChangeDetectorRef, useValue: cdRefStub},
{provide: NgbModal, useValue: modalService},
{provide: NotificationsService, useValue: NotificationsServiceStub},
{provide: TranslateService, useValue: translateServiceStub},
{provide: PaginationService, useValue: {}},
FormBuilder,
RouteService,
provideMockStore({}),
]
})
.compileComponents();
fixture = TestBed.createComponent(LdnServiceFormEditComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
}); });

View File

@@ -22,478 +22,478 @@ import {PaginationComponentOptions} from '../../../shared/pagination/pagination-
import {NotifyServicePattern} from "../ldn-services-model/ldn-service-patterns.model"; import {NotifyServicePattern} from "../ldn-services-model/ldn-service-patterns.model";
@Component({ @Component({
selector: 'ds-ldn-service-form-edit', selector: 'ds-ldn-service-form-edit',
templateUrl: './ldn-service-form-edit.component.html', templateUrl: './ldn-service-form-edit.component.html',
styleUrls: ['./ldn-service-form-edit.component.scss'], styleUrls: ['./ldn-service-form-edit.component.scss'],
animations: [ animations: [
trigger('toggleAnimation', [ trigger('toggleAnimation', [
state('true', style({})), state('true', style({})),
state('false', style({})), state('false', style({})),
transition('true <=> false', animate('300ms ease-in')), transition('true <=> false', animate('300ms ease-in')),
]), ]),
], ],
}) })
export class LdnServiceFormEditComponent implements OnInit { export class LdnServiceFormEditComponent implements OnInit {
formModel: FormGroup; formModel: FormGroup;
@ViewChild('confirmModal', {static: true}) confirmModal: TemplateRef<any>; @ViewChild('confirmModal', {static: true}) confirmModal: TemplateRef<any>;
@ViewChild('resetFormModal', {static: true}) resetFormModal: TemplateRef<any>; @ViewChild('resetFormModal', {static: true}) resetFormModal: TemplateRef<any>;
public inboundPatterns: string[] = notifyPatterns; public inboundPatterns: string[] = notifyPatterns;
public outboundPatterns: string[] = notifyPatterns; public outboundPatterns: string[] = notifyPatterns;
itemfiltersRD$: Observable<RemoteData<PaginatedList<Itemfilter>>>; itemfiltersRD$: Observable<RemoteData<PaginatedList<Itemfilter>>>;
config: FindListOptions = Object.assign(new FindListOptions(), { config: FindListOptions = Object.assign(new FindListOptions(), {
elementsPerPage: 20 elementsPerPage: 20
}); });
pageConfig: PaginationComponentOptions = Object.assign(new PaginationComponentOptions(), { pageConfig: PaginationComponentOptions = Object.assign(new PaginationComponentOptions(), {
id: 'po', id: 'po',
pageSize: 20 pageSize: 20
}); });
@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 ldnUrl: string; @Input() public ldnUrl: string;
@Input() public score: number; @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;
@Input() public automatic: boolean; @Input() public automatic: boolean;
@Input() public headerKey: string; @Input() public headerKey: string;
markedForDeletionInboundPattern: number[] = []; markedForDeletionInboundPattern: number[] = [];
markedForDeletionOutboundPattern: number[] = []; markedForDeletionOutboundPattern: number[] = [];
selectedOutboundPatterns: string[]; selectedOutboundPatterns: string[];
selectedInboundItemfilters: string[]; selectedInboundItemfilters: string[];
selectedOutboundItemfilters: string[]; selectedOutboundItemfilters: string[];
selectedInboundPatterns: string[]; selectedInboundPatterns: string[];
protected serviceId: string; protected serviceId: string;
private deletedInboundPatterns: number[] = []; private deletedInboundPatterns: number[] = [];
private deletedOutboundPatterns: number[] = []; private deletedOutboundPatterns: number[] = [];
private modalRef: any; private modalRef: any;
private service: LdnService; private service: LdnService;
constructor( constructor(
protected ldnServicesService: LdnServicesService, protected ldnServicesService: LdnServicesService,
private ldnItemfiltersService: LdnItemfiltersService, private ldnItemfiltersService: LdnItemfiltersService,
private formBuilder: FormBuilder, private formBuilder: FormBuilder,
private router: Router, private router: Router,
private route: ActivatedRoute, private route: ActivatedRoute,
private cdRef: ChangeDetectorRef, private cdRef: ChangeDetectorRef,
protected modalService: NgbModal, protected modalService: NgbModal,
private notificationService: NotificationsService, private notificationService: NotificationsService,
private translateService: TranslateService, private translateService: TranslateService,
protected paginationService: PaginationService protected paginationService: PaginationService
) { ) {
this.formModel = this.formBuilder.group({ this.formModel = this.formBuilder.group({
id: [''], id: [''],
name: ['', Validators.required], name: ['', Validators.required],
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: [''], score: ['', [Validators.required, Validators.pattern('^0*(\.[0-9]+)?$|^1(\.0+)?$')]], inboundPattern: [''],
outboundPattern: [''], outboundPattern: [''],
constraintPattern: [''], constraintPattern: [''],
enabled: [''], enabled: [''],
notifyServiceInboundPatterns: this.formBuilder.array([this.createInboundPatternFormGroup()]), notifyServiceInboundPatterns: this.formBuilder.array([this.createInboundPatternFormGroup()]),
notifyServiceOutboundPatterns: this.formBuilder.array([this.createOutboundPatternFormGroup()]), notifyServiceOutboundPatterns: this.formBuilder.array([this.createOutboundPatternFormGroup()]),
type: LDN_SERVICE.value, type: LDN_SERVICE.value,
}); });
} }
ngOnInit(): void { ngOnInit(): void {
this.route.params.subscribe((params) => { this.route.params.subscribe((params) => {
this.serviceId = params.serviceId; this.serviceId = params.serviceId;
if (this.serviceId) { if (this.serviceId) {
this.fetchServiceData(this.serviceId); this.fetchServiceData(this.serviceId);
} }
}); });
this.setItemfilters(); this.setItemfilters();
} }
setItemfilters() { setItemfilters() {
this.itemfiltersRD$ = this.ldnItemfiltersService.findAll().pipe( this.itemfiltersRD$ = this.ldnItemfiltersService.findAll().pipe(
getFirstCompletedRemoteData()); getFirstCompletedRemoteData());
} }
fetchServiceData(serviceId: string): void { fetchServiceData(serviceId: string): void {
this.ldnServicesService.findById(serviceId).pipe( this.ldnServicesService.findById(serviceId).pipe(
getFirstCompletedRemoteData() getFirstCompletedRemoteData()
).subscribe( ).subscribe(
(data: RemoteData<LdnService>) => { (data: RemoteData<LdnService>) => {
if (data.hasSucceeded) { if (data.hasSucceeded) {
this.service = data.payload; this.service = data.payload;
this.formModel.patchValue({ this.formModel.patchValue({
id: this.service.id, id: this.service.id,
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, score: this.service.score, ldnUrl: this.service.ldnUrl,
type: this.service.type, type: this.service.type,
enabled: this.service.enabled enabled: this.service.enabled
}); });
this.filterPatternObjectsAndPickLabel('notifyServiceInboundPatterns', false) this.filterPatternObjectsAndPickLabel('notifyServiceInboundPatterns', false)
this.filterPatternObjectsAndPickLabel('notifyServiceOutboundPatterns', true) this.filterPatternObjectsAndPickLabel('notifyServiceOutboundPatterns', true)
/*const inboundPatternsArray = this.formModel.get('notifyServiceInboundPatterns') as FormArray; /*const inboundPatternsArray = this.formModel.get('notifyServiceInboundPatterns') as FormArray;
inboundPatternsArray.clear(); inboundPatternsArray.clear();
console.log(" outside (pattern: any)") console.log(" outside (pattern: any)")
this.service.notifyServiceInboundPatterns.forEach((patternObj: NotifyServicePattern) => { this.service.notifyServiceInboundPatterns.forEach((patternObj: NotifyServicePattern) => {
const patternFormGroup = this.initializeInboundPatternFormGroup(); const patternFormGroup = this.initializeInboundPatternFormGroup();
const newPatternObjWithLabel = Object.assign(new NotifyServicePattern(), {...patternObj,patternLabel: this.translateService.instant('ldn-service.form.pattern.' + patternObj.pattern + '.label')}) const newPatternObjWithLabel = Object.assign(new NotifyServicePattern(), {...patternObj,patternLabel: this.translateService.instant('ldn-service.form.pattern.' + patternObj.pattern + '.label')})
patternFormGroup.patchValue(newPatternObjWithLabel);
console.log("(pattern: any)")
inboundPatternsArray.push(patternFormGroup);
this.cdRef.detectChanges();
})*/;
/*const outboundPatternsArray = this.formModel.get('notifyServiceOutboundPatterns') as FormArray;
outboundPatternsArray.clear();
this.service.notifyServiceOutboundPatterns.forEach((pattern: any) => {
const patternFormGroup = this.initializeOutboundPatternFormGroup();
patternFormGroup.patchValue(pattern);
outboundPatternsArray.push(patternFormGroup);
this.cdRef.detectChanges();
});*/
}
},
);
}
filterPatternObjectsAndPickLabel(formArrayName: string, isOutbound: boolean) {
const PatternsArray = this.formModel.get(formArrayName) as FormArray;
PatternsArray.clear();
let servicesToUse;
if (isOutbound) {
servicesToUse = this.service.notifyServiceOutboundPatterns
} else {
servicesToUse = this.service.notifyServiceInboundPatterns
}
servicesToUse.forEach((patternObj: NotifyServicePattern) => {
let patternFormGroup;
if (isOutbound) {
patternFormGroup = this.initializeOutboundPatternFormGroup();
} else {
patternFormGroup = this.initializeInboundPatternFormGroup();
}
const newPatternObjWithLabel = Object.assign(new NotifyServicePattern(), {
...patternObj,
patternLabel: this.translateService.instant('ldn-service.form.pattern.' + patternObj?.pattern + '.label')
})
patternFormGroup.patchValue(newPatternObjWithLabel); patternFormGroup.patchValue(newPatternObjWithLabel);
console.log("(pattern: any)") console.log("(pattern: any)")
PatternsArray.push(patternFormGroup);
inboundPatternsArray.push(patternFormGroup);
this.cdRef.detectChanges(); this.cdRef.detectChanges();
})*/; })
/*const outboundPatternsArray = this.formModel.get('notifyServiceOutboundPatterns') as FormArray;
outboundPatternsArray.clear();
this.service.notifyServiceOutboundPatterns.forEach((pattern: any) => {
const patternFormGroup = this.initializeOutboundPatternFormGroup();
patternFormGroup.patchValue(pattern);
outboundPatternsArray.push(patternFormGroup);
this.cdRef.detectChanges();
});*/
}
},
);
}
filterPatternObjectsAndPickLabel(formArrayName: string, isOutbound: boolean) {
const PatternsArray = this.formModel.get(formArrayName) as FormArray;
PatternsArray.clear();
let servicesToUse;
if (isOutbound) {
servicesToUse = this.service.notifyServiceOutboundPatterns
} else {
servicesToUse = this.service.notifyServiceInboundPatterns
} }
servicesToUse.forEach((patternObj: NotifyServicePattern) => { generatePatchOperations(): any[] {
let patternFormGroup; const patchOperations: any[] = [];
if (isOutbound) {
patternFormGroup = this.initializeOutboundPatternFormGroup();
} else {
patternFormGroup = this.initializeInboundPatternFormGroup();
}
const newPatternObjWithLabel = Object.assign(new NotifyServicePattern(), {
...patternObj,
patternLabel: this.translateService.instant('ldn-service.form.pattern.' + patternObj?.pattern + '.label')
})
patternFormGroup.patchValue(newPatternObjWithLabel);
console.log("(pattern: any)")
PatternsArray.push(patternFormGroup); this.createReplaceOperation(patchOperations, 'name', '/name');
this.cdRef.detectChanges(); this.createReplaceOperation(patchOperations, 'description', '/description');
}) this.createReplaceOperation(patchOperations, 'ldnUrl', '/ldnurl');
this.createReplaceOperation(patchOperations, 'url', '/url');
}
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.createReplaceOperation(patchOperations, 'score', '/score'); this.createReplaceOperation(patchOperations, 'score', '/score');
this.handlePatterns(patchOperations, 'notifyServiceInboundPatterns'); this.handlePatterns(patchOperations, 'notifyServiceInboundPatterns');
this.handlePatterns(patchOperations, 'notifyServiceOutboundPatterns'); this.handlePatterns(patchOperations, 'notifyServiceOutboundPatterns');
this.deletedInboundPatterns.forEach(index => { this.deletedInboundPatterns.forEach(index => {
const removeOperation: Operation = { const removeOperation: Operation = {
op: 'remove', op: 'remove',
path: `notifyServiceInboundPatterns[${index}]` path: `notifyServiceInboundPatterns[${index}]`
}; };
patchOperations.push(removeOperation); 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());
}
selectOutboundPattern(patternValue: string, index: number): void {
const patternArray = (this.formModel.get('notifyServiceOutboundPatterns') as FormArray)
console.log((this.formModel.get('notifyServiceOutboundPatterns') as FormArray))
patternArray.controls[index].patchValue({pattern: patternValue})
patternArray.controls[index].patchValue({patternLabel: this.translateService.instant('ldn-service.form.pattern.' + patternValue + '.label')})
}
selectOutboundItemFilter(filterValue: string, index: number) {
const filterArray = (this.formModel.get('notifyServiceOutboundPatterns') as FormArray)
console.log((this.formModel.get('notifyServiceOutboundPatterns') as FormArray))
filterArray.controls[index].patchValue({constraint: filterValue})
}
selectInboundPattern(patternValue: string, index: number): void {
const patternArray = (this.formModel.get('notifyServiceInboundPatterns') as FormArray)
console.log((this.formModel.get('notifyServiceInboundPatterns') as FormArray))
patternArray.controls[index].patchValue({pattern: patternValue})
patternArray.controls[index].patchValue({patternLabel: this.translateService.instant('ldn-service.form.pattern.' + patternValue + '.label')})
}
selectInboundItemFilter(filterValue: string, index: number): void {
const filterArray = (this.formModel.get('notifyServiceInboundPatterns') as FormArray)
console.log((this.formModel.get('notifyServiceInboundPatterns') as FormArray))
filterArray.controls[index].patchValue({constraint: filterValue})
}
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.deleteMarkedInboundPatterns();
this.deleteMarkedOutboundPatterns();
const patchOperations = this.generatePatchOperations();
this.ldnServicesService.patch(this.service, patchOperations).pipe(
getFirstCompletedRemoteData()
).subscribe(
(rd: RemoteData<LdnService>) => {
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() { this.deletedOutboundPatterns.forEach(index => {
this.sendBack(); const removeOperation: Operation = {
this.closeModal(); op: 'remove',
} path: `notifyServiceOutboundPatterns[${index}]`
};
patchOperations.push(removeOperation);
});
markForInboundPatternDeletion(index: number) { return patchOperations;
if (!this.markedForDeletionInboundPattern.includes(index)) {
this.markedForDeletionInboundPattern.push(index);
} }
}
unmarkForInboundPatternDeletion(index: number) { onSubmit() {
const i = this.markedForDeletionInboundPattern.indexOf(index); this.openConfirmModal(this.confirmModal);
if (i !== -1) {
this.markedForDeletionInboundPattern.splice(i, 1);
} }
}
markForOutboundPatternDeletion(index: number) { addInboundPattern() {
if (!this.markedForDeletionOutboundPattern.includes(index)) { const notifyServiceInboundPatternsArray = this.formModel.get('notifyServiceInboundPatterns') as FormArray;
this.markedForDeletionOutboundPattern.push(index); notifyServiceInboundPatternsArray.push(this.createInboundPatternFormGroup());
} }
}
unmarkForOutboundPatternDeletion(index: number) { addOutboundPattern() {
const i = this.markedForDeletionOutboundPattern.indexOf(index); const notifyServiceOutboundPatternsArray = this.formModel.get('notifyServiceOutboundPatterns') as FormArray;
if (i !== -1) { notifyServiceOutboundPatternsArray.push(this.createOutboundPatternFormGroup());
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.markedForDeletionInboundPattern) { selectOutboundPattern(patternValue: string, index: number): void {
if (index >= 0 && index < patternsArray.length) { const patternArray = (this.formModel.get('notifyServiceOutboundPatterns') as FormArray)
const patternGroup = patternsArray.at(index) as FormGroup; console.log((this.formModel.get('notifyServiceOutboundPatterns') as FormArray))
const patternValue = patternGroup.value; patternArray.controls[index].patchValue({pattern: patternValue})
if (patternValue.isNew) { patternArray.controls[index].patchValue({patternLabel: this.translateService.instant('ldn-service.form.pattern.' + patternValue + '.label')})
patternsArray.removeAt(index);
} else { }
this.deletedInboundPatterns.push(index);
selectOutboundItemFilter(filterValue: string, index: number) {
const filterArray = (this.formModel.get('notifyServiceOutboundPatterns') as FormArray)
console.log((this.formModel.get('notifyServiceOutboundPatterns') as FormArray))
filterArray.controls[index].patchValue({constraint: filterValue})
}
selectInboundPattern(patternValue: string, index: number): void {
const patternArray = (this.formModel.get('notifyServiceInboundPatterns') as FormArray)
console.log((this.formModel.get('notifyServiceInboundPatterns') as FormArray))
patternArray.controls[index].patchValue({pattern: patternValue})
patternArray.controls[index].patchValue({patternLabel: this.translateService.instant('ldn-service.form.pattern.' + patternValue + '.label')})
}
selectInboundItemFilter(filterValue: string, index: number): void {
const filterArray = (this.formModel.get('notifyServiceInboundPatterns') as FormArray)
console.log((this.formModel.get('notifyServiceInboundPatterns') as FormArray))
filterArray.controls[index].patchValue({constraint: filterValue})
}
toggleAutomatic(i: number) {
const automaticControl = this.formModel.get(`notifyServiceInboundPatterns.${i}.automatic`);
if (automaticControl) {
automaticControl.setValue(!automaticControl.value);
} }
}
} }
this.markedForDeletionInboundPattern = []; toggleEnabled() {
} const newStatus = !this.formModel.get('enabled').value;
const patchOperation: Operation = {
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) {
const patternGroup = patternsArray.at(index) as FormGroup;
const patternValue = patternGroup.value;
if (patternValue.isNew) {
patternsArray.removeAt(index);
} else {
this.deletedOutboundPatterns.push(index);
}
}
}
this.markedForDeletionOutboundPattern = [];
}
setValueForControlInOutboundArray(formArrayName: string, index: number, value: string) {
console.log(formArrayName)
const formArray = this.formModel.get(formArrayName) as FormArray;
console.warn('inside setValueForControlInOutboundArray', formArray);
formArray.at(index).setValue(value);
}
setValueForControlInInboundArray(formArrayName: string, index: number, value: string) {
console.log(formArrayName)
const formArray = this.formModel.get(formArrayName) as FormArray;
console.warn('inside setValueForControlInInboundArray', formArray);
formArray.at(index).setValue(value);
}
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 {
console.log(this.formModel)
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.touched) {
delete patternValue?.patternLabel;
if (patternValue.isNew) {
delete patternValue.isNew;
const addOperation = {
op: 'add',
path: `${formArrayName}/-`,
value: patternValue,
};
patchOperations.push(addOperation);
} else {
const replaceOperation = {
op: 'replace', op: 'replace',
path: `${formArrayName}[${i}]`, path: '/enabled',
value: patternValue, value: newStatus,
}; };
patchOperations.push(replaceOperation);
} this.ldnServicesService.patch(this.service, [patchOperation]).pipe(
} getFirstCompletedRemoteData()
).subscribe(
() => {
this.formModel.get('enabled').setValue(newStatus);
this.cdRef.detectChanges();
}
);
} }
}
private sendBack() {
this.router.navigateByUrl('admin/ldn/services');
}
private createOutboundPatternFormGroup(): FormGroup { closeModal() {
return this.formBuilder.group({ this.modalRef.close();
pattern: '', this.cdRef.detectChanges();
patternLabel: 'Select a pattern', }
constraint: '',
isNew: true,
});
}
private createInboundPatternFormGroup(): FormGroup { openConfirmModal(content) {
return this.formBuilder.group({ this.modalRef = this.modalService.open(content);
pattern: '', }
patternLabel: 'Select a pattern',
constraint: '',
automatic: false,
isNew: true
});
}
private initializeOutboundPatternFormGroup(): FormGroup { openResetFormModal(content) {
return this.formBuilder.group({ this.modalRef = this.modalService.open(content);
pattern: '', }
patternLabel: '',
constraint: '',
});
}
private initializeInboundPatternFormGroup(): FormGroup { patchService() {
return this.formBuilder.group({ this.deleteMarkedInboundPatterns();
pattern: '', this.deleteMarkedOutboundPatterns();
patternLabel: '',
constraint: '', const patchOperations = this.generatePatchOperations();
automatic: '',
});
} this.ldnServicesService.patch(this.service, patchOperations).pipe(
getFirstCompletedRemoteData()
).subscribe(
(rd: RemoteData<LdnService>) => {
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() {
this.sendBack();
this.closeModal();
}
markForInboundPatternDeletion(index: number) {
if (!this.markedForDeletionInboundPattern.includes(index)) {
this.markedForDeletionInboundPattern.push(index);
}
}
unmarkForInboundPatternDeletion(index: number) {
const i = this.markedForDeletionInboundPattern.indexOf(index);
if (i !== -1) {
this.markedForDeletionInboundPattern.splice(i, 1);
}
}
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.markedForDeletionInboundPattern) {
if (index >= 0 && index < patternsArray.length) {
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) {
const patternGroup = patternsArray.at(index) as FormGroup;
const patternValue = patternGroup.value;
if (patternValue.isNew) {
patternsArray.removeAt(index);
} else {
this.deletedOutboundPatterns.push(index);
}
}
}
this.markedForDeletionOutboundPattern = [];
}
setValueForControlInOutboundArray(formArrayName: string, index: number, value: string) {
console.log(formArrayName)
const formArray = this.formModel.get(formArrayName) as FormArray;
console.warn('inside setValueForControlInOutboundArray', formArray);
formArray.at(index).setValue(value);
}
setValueForControlInInboundArray(formArrayName: string, index: number, value: string) {
console.log(formArrayName)
const formArray = this.formModel.get(formArrayName) as FormArray;
console.warn('inside setValueForControlInInboundArray', formArray);
formArray.at(index).setValue(value);
}
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 {
console.log(this.formModel)
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.touched) {
delete patternValue?.patternLabel;
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: '',
patternLabel: 'Select a pattern',
constraint: '',
isNew: true,
});
}
private createInboundPatternFormGroup(): FormGroup {
return this.formBuilder.group({
pattern: '',
patternLabel: 'Select a pattern',
constraint: '',
automatic: false,
isNew: true
});
}
private initializeOutboundPatternFormGroup(): FormGroup {
return this.formBuilder.group({
pattern: '',
patternLabel: '',
constraint: '',
});
}
private initializeInboundPatternFormGroup(): FormGroup {
return this.formBuilder.group({
pattern: '',
patternLabel: '',
constraint: '',
automatic: '',
});
}
} }

View File

@@ -1,359 +1,366 @@
<div class="container"> <div class="container">
<form (ngSubmit)="onSubmit()" [formGroup]="formModel"> <form (ngSubmit)="onSubmit()" [formGroup]="formModel">
<div class="d-flex"> <div class="d-flex">
<h2 class="flex-grow-1">{{ 'ldn-create-service.title' | translate }}</h2> <h2 class="flex-grow-1">{{ 'ldn-create-service.title' | translate }}</h2>
</div>
<!-- In the name section -->
<div class="mb-5 ">
<label for="name">{{ 'ldn-new-service.form.label.name' | translate }}</label>
<input [class.invalid-field]="formModel.get('name').invalid && formModel.get('name').touched"
[placeholder]="'ldn-new-service.form.placeholder.name' | translate" formControlName="name" id="name"
name="name"
type="text"
class="form-control">
<div *ngIf="formModel.get('name').invalid && formModel.get('name').touched" class="error-text">
{{ 'ldn-new-service.form.error.name' | translate }}
</div>
</div>
<!-- In the description section -->
<div class="mb-5 mt-5 d-flex flex-column">
<label for="description">{{ 'ldn-new-service.form.label.description' | translate }}</label>
<textarea [placeholder]="'ldn-new-service.form.placeholder.description' | translate"
formControlName="description" id="description" name="description" class="form-control"></textarea>
</div>
<!-- In the url section -->
<div class="mb-5 mt-5">
<label for="url">{{ 'ldn-new-service.form.label.url' | translate }}</label>
<input [class.invalid-field]="formModel.get('url').invalid && formModel.get('url').touched"
[placeholder]="'ldn-new-service.form.placeholder.url' | translate" formControlName="url" id="url"
name="url"
type="text"
class="form-control">
<div *ngIf="formModel.get('url').invalid && formModel.get('url').touched" class="error-text">
{{ 'ldn-new-service.form.error.url' | translate }}
</div>
</div>
<!-- In the ldnUrl section -->
<div class="mb-5 mt-5">
<label for="ldnUrl">{{ 'ldn-new-service.form.label.ldnUrl' | translate }}</label>
<input [class.invalid-field]="formModel.get('ldnUrl').invalid && formModel.get('ldnUrl').touched"
[placeholder]="'ldn-new-service.form.placeholder.ldnUrl' | translate" formControlName="ldnUrl"
id="ldnUrl"
name="ldnUrl"
type="text"
class="form-control">
<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>
<!-- In the Inbound Patterns section -->
<div class="rowmb-2 mt-5">
<div class="col">
<label>{{ 'ldn-new-service.form.label.inboundPattern' | translate }} </label>
</div>
<ng-container *ngIf="!!(formModel.get('notifyServiceInboundPatterns')['controls'][0]?.value?.pattern)">
<div class="col">
<label>{{ 'ldn-new-service.form.label.ItemFilter' | translate }}</label>
</div> </div>
<div class="col-sm-1"> <!-- In the name section -->
<label class="">{{ 'ldn-new-service.form.label.automatic' | translate }}</label> <div class="mb-5 ">
</div> <label for="name">{{ 'ldn-new-service.form.label.name' | translate }}</label>
</ng-container> <input [class.invalid-field]="formModel.get('name').invalid && formModel.get('name').touched"
<div class="col-sm-2"> [placeholder]="'ldn-new-service.form.placeholder.name' | translate" class="form-control" formControlName="name"
</div> id="name"
</div> name="name"
type="text">
<div *ngFor="let patternGroup of formModel.get('notifyServiceInboundPatterns')['controls']; let i = index" <div *ngIf="formModel.get('name').invalid && formModel.get('name').touched" class="error-text">
formGroupName="notifyServiceInboundPatterns"> {{ 'ldn-new-service.form.error.name' | translate }}
<ng-container [formGroupName]="i">
<div class="row mb-1">
<div class="col">
<select #inboundPattern formControlName="pattern" id="additionalInboundPattern{{i}}"
name="additionalInboundPattern{{i}}" required>
<option value="">{{ 'ldn-new-service.form.label.placeholder.inboundPattern' | translate }}</option>
<option *ngFor="let pattern of inboundPatterns"
[value]="pattern">{{ 'ldn-service.form.pattern.' + pattern + '.label' | translate }} </option>
</select>
<div *ngIf="!patternSelected()" class="error-text">
{{ 'ldn-new-service.form.error.patterns' | translate }}
</div> </div>
</div> </div>
<!-- In the description section -->
<div class="mb-5 mt-5 d-flex flex-column">
<label for="description">{{ 'ldn-new-service.form.label.description' | translate }}</label>
<textarea [placeholder]="'ldn-new-service.form.placeholder.description' | translate"
class="form-control" formControlName="description" id="description" name="description"></textarea>
</div>
<div class="col"> <!-- In the url section -->
<ng-container *ngIf="!!(formModel.get('notifyServiceInboundPatterns')['controls'][i].value.pattern)"> <div class="mb-5 mt-5">
<div #inboundItemfilterDropdown="ngbDropdown" class="w-100" id="constraint{{i}}" ngbDropdown <label for="url">{{ 'ldn-new-service.form.label.url' | translate }}</label>
placement="bottom-start"> <input [class.invalid-field]="formModel.get('url').invalid && formModel.get('url').touched"
<div class="position-relative right-addon" role="combobox"> [placeholder]="'ldn-new-service.form.placeholder.url' | translate" class="form-control" formControlName="url"
<i aria-hidden="true" class="position-absolute scrollable-dropdown-toggle" id="url"
ngbDropdownToggle></i> name="url"
<input type="text">
(click)="inboundItemfilterDropdown.open();" <div *ngIf="formModel.get('url').invalid && formModel.get('url').touched" class="error-text">
[readonly]="true" {{ 'ldn-new-service.form.error.url' | translate }}
[value]="selectedInboundItemfilters" </div>
class="form-control w-100 scrollable-dropdown-input" </div>
formControlName="constraint"
id="inboundItemfilterDropdown"
ngbDropdownAnchor <!-- In the ldnUrl section -->
type="text" <div class="mb-5 mt-5">
/> <label for="ldnUrl">{{ 'ldn-new-service.form.label.ldnUrl' | translate }}</label>
<!-- TODO: infinite scroll with 3 selects --> <input [class.invalid-field]="formModel.get('ldnUrl').invalid && formModel.get('ldnUrl').touched"
<div aria-labelledby="inboundItemfilterDropdownButton" ngbDropdownMenu class="dropdown-menu scrollable-dropdown-menu w-100 " > [placeholder]="'ldn-new-service.form.placeholder.ldnUrl' | translate" class="form-control"
<div class="scrollable-menu" role="listbox"> formControlName="ldnUrl"
<button (click)="selectInboundItemFilter(constraint.id, i); $event.stopPropagation() " class="dropdown-item collection-item text-truncate w-100" id="ldnUrl"
*ngFor="let constraint of (itemfiltersRD$ | async)?.payload?.page; let internalIndex = index" name="ldnUrl"
ngbDropdownItem type="text">
type="button"> <div *ngIf="formModel.get('ldnUrl').invalid && formModel.get('ldnUrl').touched" class="error-text">
<div>{{ constraint.id }}</div> {{ 'ldn-new-service.form.error.ldnurl' | translate }}
</button> </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>
<!-- In the Inbound Patterns section -->
<div class="rowmb-2 mt-5">
<div class="col">
<label>{{ 'ldn-new-service.form.label.inboundPattern' | translate }} </label>
</div>
<ng-container *ngIf="!!(formModel.get('notifyServiceInboundPatterns')['controls'][0]?.value?.pattern)">
<div class="col">
<label>{{ 'ldn-new-service.form.label.ItemFilter' | translate }}</label>
</div>
<div class="col-sm-1">
<label class="">{{ 'ldn-new-service.form.label.automatic' | translate }}</label>
</div>
</ng-container>
<div class="col-sm-2">
</div>
</div>
<div *ngFor="let patternGroup of formModel.get('notifyServiceInboundPatterns')['controls']; let i = index"
formGroupName="notifyServiceInboundPatterns">
<ng-container [formGroupName]="i">
<div class="row mb-1">
<div class="col">
<select #inboundPattern formControlName="pattern" id="additionalInboundPattern{{i}}"
name="additionalInboundPattern{{i}}" required>
<option value="">{{ 'ldn-new-service.form.label.placeholder.inboundPattern' | translate }}</option>
<option *ngFor="let pattern of inboundPatterns"
[value]="pattern">{{ 'ldn-service.form.pattern.' + pattern + '.label' | translate }} </option>
</select>
<div *ngIf="!patternSelected()" class="error-text">
{{ 'ldn-new-service.form.error.patterns' | translate }}
</div>
</div> </div>
</div>
</div>
</div>
</ng-container>
</div>
<div
[style.visibility]="formModel.get('notifyServiceInboundPatterns')['controls'][i]?.value?.pattern ? 'visible' : 'hidden'"
class="col-sm-1">
<input formControlName="automatic" hidden id="automatic{{i}}" name="automatic{{i}}"
type="checkbox">
<div (click)="toggleAutomatic(i)"
[class.checked]="formModel.get('notifyServiceInboundPatterns.' + i + '.automatic').value"
class="toggle-switch">
<div class="slider"></div>
</div>
</div>
<div class="col-sm-1">
<button (click)="removeInboundPattern(i)" class="btn btn-outline-dark trash-button">
<i class="fas fa-trash"></i>
</button>
</div>
</div>
</ng-container>
</div>
<span (click)="addInboundPattern()"
class="add-pattern-link mb-4">{{ 'ldn-new-service.form.label.addPattern' | translate }}</span>
<div class="col">
<ng-container
*ngIf="!!(formModel.get('notifyServiceInboundPatterns')['controls'][i].value.pattern)">
<div #inboundItemfilterDropdown="ngbDropdown" class="w-100" id="constraint{{i}}" ngbDropdown
placement="bottom-start">
<div class="position-relative right-addon" role="combobox">
<i aria-hidden="true" class="position-absolute scrollable-dropdown-toggle"
ngbDropdownToggle></i>
<input
(click)="inboundItemfilterDropdown.open();"
[readonly]="true"
[value]="selectedInboundItemfilters"
class="form-control w-100 scrollable-dropdown-input"
formControlName="constraint"
id="inboundItemfilterDropdown"
ngbDropdownAnchor
type="text"
/>
<!-- TODO: infinite scroll with 3 selects -->
<div aria-labelledby="inboundItemfilterDropdownButton" class="dropdown-menu scrollable-dropdown-menu w-100 "
ngbDropdownMenu>
<div class="scrollable-menu" role="listbox">
<button (click)="selectInboundItemFilter(constraint.id, i); $event.stopPropagation() "
*ngFor="let constraint of (itemfiltersRD$ | async)?.payload?.page; let internalIndex = index"
class="dropdown-item collection-item text-truncate w-100"
ngbDropdownItem
type="button">
<div>{{ constraint.id }}</div>
</button>
</div>
</div>
</div>
</div>
</ng-container>
</div>
<!-- In the Outbound Patterns section -->
<div class="rowmb-1 mt-5">
<div class="col">
<label>{{ 'ldn-new-service.form.label.outboundPattern' | translate }}</label>
</div>
<ng-container *ngIf="!!(formModel.get('notifyServiceOutboundPatterns')['controls'][0]?.value?.pattern)">
<div class="col">
<label class="">{{ 'ldn-new-service.form.label.ItemFilter' | translate }}</label>
</div>
</ng-container>
<div class="col-sm1 ">
<label class="label-box-2" style="visibility: hidden;">
{{ 'ldn-new-service.form.label.automatic' | translate }}
</label>
</div>
<div class="col-sm-2 ">
</div>
</div>
<div *ngFor="let patternGroup of formModel.get('notifyServiceOutboundPatterns')['controls']; let i = index"
formGroupName="notifyServiceOutboundPatterns">
<ng-container [formGroupName]="i">
<!-- Input elements in a separate row -->
<div class="row mb-1">
<div class="col">
<div #outboundPatternDropdown="ngbDropdown" class="w-100" id="additionalOutboundPattern{{i}}" ngbDropdown
placement="bottom-start">
<div class="position-relative right-addon" role="combobox">
<i aria-hidden="true" class="position-absolute scrollable-dropdown-toggle"
ngbDropdownToggle></i>
<input
(click)="outboundPatternDropdown.open();"
[readonly]="true"
[value]="selectedOutboundPatterns"
class="form-control w-100 scrollable-dropdown-input"
formControlName="patternLabel"
id="outboundPatternDropdownButton"
ngbDropdownAnchor
type="text"
/>
<!-- TODO: infinite scroll with 3 selects -->
<div aria-labelledby="outboundPatternDropdownButton" ngbDropdownMenu class="dropdown-menu scrollable-dropdown-menu w-100 " >
<div class="scrollable-menu" role="listbox">
<button (click)="selectOutboundPattern(pattern, i); $event.stopPropagation()" class="dropdown-item collection-item text-truncate w-100"
*ngFor="let pattern of outboundPatterns" ngbDropdownItem
type="button"
[title]="'ldn-service.form.pattern.' + pattern + '.description' | translate">
<div>{{ 'ldn-service.form.pattern.' + pattern + '.label' | translate }}</div>
<div <div
class="small-text">{{ 'ldn-service.form.pattern.' + pattern + '.description' | translate }}</div> [style.visibility]="formModel.get('notifyServiceInboundPatterns')['controls'][i]?.value?.pattern ? 'visible' : 'hidden'"
</button> class="col-sm-1">
</div> <input formControlName="automatic" hidden id="automatic{{i}}" name="automatic{{i}}"
</div> type="checkbox">
</div> <div (click)="toggleAutomatic(i)"
</div> [class.checked]="formModel.get('notifyServiceInboundPatterns.' + i + '.automatic').value"
</div> class="toggle-switch">
<div class="slider"></div>
</div>
</div>
<div class="col-sm-1">
<button (click)="removeInboundPattern(i)" class="btn btn-outline-dark trash-button">
<i class="fas fa-trash"></i>
</button>
</div>
<div class="col">
<ng-container *ngIf="!!(formModel.get('notifyServiceOutboundPatterns')['controls'][i].value.pattern)">
<div #outboundItemfilterDropdown="ngbDropdown" class="w-100" id="constraint{{i}}" ngbDropdown
placement="bottom-start">
<div class="position-relative right-addon" role="combobox">
<i aria-hidden="true" class="position-absolute scrollable-dropdown-toggle"
ngbDropdownToggle></i>
<input
(click)="outboundItemfilterDropdown.open();"
[readonly]="true"
[value]="selectedOutboundItemfilters"
class="form-control w-100 scrollable-dropdown-input"
formControlName="constraint"
id="outboundItemfilterDropdown"
ngbDropdownAnchor
type="text"
/>
<!-- TODO: infinite scroll with 3 selects -->
<div aria-labelledby="outboundItemfilterDropdownButton" ngbDropdownMenu class="dropdown-menu scrollable-dropdown-menu w-100 " >
<div class="scrollable-menu" role="listbox">
<button (click)="selectOutboundItemFilter(constraint.id, i); $event.stopPropagation()" class="dropdown-item collection-item text-truncate w-100"
*ngFor="let constraint of (itemfiltersRD$ | async)?.payload?.page; let internalIndex = index"
ngbDropdownItem
type="button">
<div>{{ constraint.id }}</div>
</button>
</div>
</div>
</div> </div>
</div>
</ng-container> </ng-container>
</div>
<div [style.visibility]="'hidden'" class="col-sm-1">
<input hidden id="automatic{{i}}" name="automatic{{i}}"
type="checkbox">
<div
class="toggle-switch">
<div class="slider"></div>
</div>
</div>
<div class="col-sm-1">
<button (click)="removeOutboundPattern(i)" class="btn btn-outline-dark trash-button">
<i class="fas fa-trash"></i>
</button>
</div>
</div> </div>
</ng-container>
</div> <span (click)="addInboundPattern()"
class="add-pattern-link mb-4">{{ 'ldn-new-service.form.label.addPattern' | translate }}</span>
<span (click)="addOutboundPattern()"
class="add-pattern-link mb-4">{{ 'ldn-new-service.form.label.addPattern' | translate }} <!-- In the Outbound Patterns section -->
<div class="rowmb-1 mt-5">
<div class="col">
<label>{{ 'ldn-new-service.form.label.outboundPattern' | translate }}</label>
</div>
<ng-container *ngIf="!!(formModel.get('notifyServiceOutboundPatterns')['controls'][0]?.value?.pattern)">
<div class="col">
<label class="">{{ 'ldn-new-service.form.label.ItemFilter' | translate }}</label>
</div>
</ng-container>
<div class="col-sm1 ">
<label class="label-box-2" style="visibility: hidden;">
{{ 'ldn-new-service.form.label.automatic' | translate }}
</label>
</div>
<div class="col-sm-2 ">
</div>
</div>
<div *ngFor="let patternGroup of formModel.get('notifyServiceOutboundPatterns')['controls']; let i = index"
formGroupName="notifyServiceOutboundPatterns">
<ng-container [formGroupName]="i">
<!-- Input elements in a separate row -->
<div class="row mb-1">
<div class="col">
<div #outboundPatternDropdown="ngbDropdown" class="w-100" id="additionalOutboundPattern{{i}}"
ngbDropdown
placement="bottom-start">
<div class="position-relative right-addon" role="combobox">
<i aria-hidden="true" class="position-absolute scrollable-dropdown-toggle"
ngbDropdownToggle></i>
<input
(click)="outboundPatternDropdown.open();"
[readonly]="true"
[value]="selectedOutboundPatterns"
class="form-control w-100 scrollable-dropdown-input"
formControlName="patternLabel"
id="outboundPatternDropdownButton"
ngbDropdownAnchor
type="text"
/>
<!-- TODO: infinite scroll with 3 selects -->
<div aria-labelledby="outboundPatternDropdownButton" class="dropdown-menu scrollable-dropdown-menu w-100 "
ngbDropdownMenu>
<div class="scrollable-menu" role="listbox">
<button (click)="selectOutboundPattern(pattern, i); $event.stopPropagation()"
*ngFor="let pattern of outboundPatterns"
[title]="'ldn-service.form.pattern.' + pattern + '.description' | translate" class="dropdown-item collection-item text-truncate w-100"
ngbDropdownItem
type="button">
<div>{{ 'ldn-service.form.pattern.' + pattern + '.label' | translate }}</div>
<div
class="small-text">{{ 'ldn-service.form.pattern.' + pattern + '.description' | translate }}</div>
</button>
</div>
</div>
</div>
</div>
</div>
<div class="col">
<ng-container
*ngIf="!!(formModel.get('notifyServiceOutboundPatterns')['controls'][i].value.pattern)">
<div #outboundItemfilterDropdown="ngbDropdown" class="w-100" id="constraint{{i}}"
ngbDropdown
placement="bottom-start">
<div class="position-relative right-addon" role="combobox">
<i aria-hidden="true" class="position-absolute scrollable-dropdown-toggle"
ngbDropdownToggle></i>
<input
(click)="outboundItemfilterDropdown.open();"
[readonly]="true"
[value]="selectedOutboundItemfilters"
class="form-control w-100 scrollable-dropdown-input"
formControlName="constraint"
id="outboundItemfilterDropdown"
ngbDropdownAnchor
type="text"
/>
<!-- TODO: infinite scroll with 3 selects -->
<div aria-labelledby="outboundItemfilterDropdownButton" class="dropdown-menu scrollable-dropdown-menu w-100 "
ngbDropdownMenu>
<div class="scrollable-menu" role="listbox">
<button (click)="selectOutboundItemFilter(constraint.id, i); $event.stopPropagation()"
*ngFor="let constraint of (itemfiltersRD$ | async)?.payload?.page; let internalIndex = index"
class="dropdown-item collection-item text-truncate w-100"
ngbDropdownItem
type="button">
<div>{{ constraint.id }}</div>
</button>
</div>
</div>
</div>
</div>
</ng-container>
</div>
<div [style.visibility]="'hidden'" class="col-sm-1">
<input hidden id="automatic{{i}}" name="automatic{{i}}"
type="checkbox">
<div
class="toggle-switch">
<div class="slider"></div>
</div>
</div>
<div class="col-sm-1">
<button (click)="removeOutboundPattern(i)" class="btn btn-outline-dark trash-button">
<i class="fas fa-trash"></i>
</button>
</div>
</div>
</ng-container>
</div>
<span (click)="addOutboundPattern()"
class="add-pattern-link mb-4">{{ 'ldn-new-service.form.label.addPattern' | translate }}
</span> </span>
<div class="mb-4"> <div class="mb-4">
&nbsp; &nbsp;
</div> </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>
</button> </button>
<div class="d-flex"> <div class="d-flex">
<button (click)="this.openResetFormModal(this.resetFormModal)" class="btn btn-danger" type="button"> <button (click)="this.openResetFormModal(this.resetFormModal)" class="btn btn-danger" type="button">
<span><i class="fas fa-trash"></i> {{ 'submission.general.discard.submit' | translate }}</span> <span><i class="fas fa-trash"></i> {{ 'submission.general.discard.submit' | translate }}</span>
</button> </button>
</div> </div>
</div> </div>
</form> </form>
</div> </div>
<ng-template #confirmModal> <ng-template #confirmModal>
<div> <div>
<div class="modal-header"> <div class="modal-header">
<div> <div>
<h4>{{'service.overview.create.modal' | translate }}</h4> <h4>{{'service.overview.create.modal' | translate }}</h4>
</div> </div>
<button (click)="closeModal()" aria-label="Close" <button (click)="closeModal()" aria-label="Close"
class="close" type="button"> class="close" type="button">
<span aria-hidden="true">×</span> <span aria-hidden="true">×</span>
</button> </button>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<div> <div>
{{ 'service.create.body' | translate }} {{ 'service.create.body' | translate }}
</div> </div>
<div class="mt-4"> <div class="mt-4">
<button (click)="closeModal()" class="btn btn-danger" <button (click)="closeModal()" class="btn btn-danger"
id="delete-confirm">{{ 'service.refuse.create' | translate }} id="delete-confirm">{{ 'service.refuse.create' | translate }}
</button> </button>
<button (click)="createService()" <button (click)="createService()"
class="btn btn-primary mr-2 custom-btn">{{ 'service.confirm.create' | translate }} class="btn btn-primary mr-2 custom-btn">{{ 'service.confirm.create' | translate }}
</button> </button>
</div> </div>
</div>
</div> </div>
</div>
</ng-template> </ng-template>
<ng-template #resetFormModal> <ng-template #resetFormModal>
<div> <div>
<div class="modal-header"> <div class="modal-header">
<div> <div>
<h4>{{'service.create.reset-form.modal' | translate }}</h4> <h4>{{'service.create.reset-form.modal' | translate }}</h4>
</div> </div>
<button (click)="closeModal()" aria-label="Close" <button (click)="closeModal()" aria-label="Close"
class="close" type="button"> class="close" type="button">
<span aria-hidden="true">×</span> <span aria-hidden="true">×</span>
</button> </button>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<div> <div>
{{ 'service.create.reset-form.body' | translate }} {{ 'service.create.reset-form.body' | translate }}
</div> </div>
<div class="mt-4"> <div class="mt-4">
<button (click)="resetFormAndLeave()" <button (click)="resetFormAndLeave()"
class="btn btn-primary mr-2 custom-btn" class="btn btn-primary mr-2 custom-btn"
id="reset-confirm">{{ 'service.overview.reset-form.reset-return' | translate }} id="reset-confirm">{{ 'service.overview.reset-form.reset-return' | translate }}
</button> </button>
<button (click)="closeModal()" class="btn btn-danger" <button (click)="closeModal()" class="btn btn-danger"
id="reset-delete">{{ 'service.overview.reset-form.reset-confirm' | translate }} id="reset-delete">{{ 'service.overview.reset-form.reset-confirm' | translate }}
</button> </button>
</div> </div>
</div>
</div> </div>
</div>
</ng-template> </ng-template>

View File

@@ -17,69 +17,69 @@ import {of} from 'rxjs';
import {EventEmitter} from '@angular/core'; import {EventEmitter} from '@angular/core';
describe('LdnServiceFormComponent', () => { describe('LdnServiceFormComponent', () => {
let component: LdnServiceFormComponent; let component: LdnServiceFormComponent;
let fixture: ComponentFixture<LdnServiceFormComponent>; let fixture: ComponentFixture<LdnServiceFormComponent>;
let ldnServicesService: any; let ldnServicesService: any;
let ldnItemfiltersService: any; let ldnItemfiltersService: any;
let notificationsService: any; let notificationsService: any;
const itemFiltersRdPL$ = createSuccessfulRemoteDataObject$(createPaginatedList([new Itemfilter()])); const itemFiltersRdPL$ = createSuccessfulRemoteDataObject$(createPaginatedList([new Itemfilter()]));
const translateServiceStub = { const translateServiceStub = {
get: () => of('translated-text'), get: () => of('translated-text'),
onLangChange: new EventEmitter(), onLangChange: new EventEmitter(),
onTranslationChange: new EventEmitter(), onTranslationChange: new EventEmitter(),
onDefaultLangChange: new EventEmitter() onDefaultLangChange: new EventEmitter()
}; };
beforeEach(async () => { beforeEach(async () => {
ldnItemfiltersService = jasmine.createSpyObj('ldnItemfiltersService', { ldnItemfiltersService = jasmine.createSpyObj('ldnItemfiltersService', {
findAll: jasmine.createSpy('findAll'), findAll: jasmine.createSpy('findAll'),
});
ldnServicesService = jasmine.createSpyObj('ldnServicesService', {
create: jasmine.createSpy('create'),
});
notificationsService = jasmine.createSpyObj('notificationsService', {
success: jasmine.createSpy('success'),
error: jasmine.createSpy('error'),
});
await TestBed.configureTestingModule({
imports: [
ReactiveFormsModule,
RouterTestingModule,
NgbModalModule,
TranslateModule.forRoot()
],
providers: [
{provide: LdnItemfiltersService, useValue: ldnItemfiltersService},
{provide: LdnServicesService, useValue: ldnServicesService},
{provide: NotificationsService, useValue: notificationsService},
{provide: TranslateService, useValue: translateServiceStub},
{provide: Router, useValue: new RouterStub()},
{
provide: NgbModal, useValue: {
open: () => {/*comment*/
}
}
},
FormBuilder
],
declarations: [LdnServiceFormComponent]
})
.compileComponents();
}); });
ldnServicesService = jasmine.createSpyObj('ldnServicesService', { beforeEach(() => {
create: jasmine.createSpy('create'), fixture = TestBed.createComponent(LdnServiceFormComponent);
component = fixture.componentInstance;
ldnItemfiltersService.findAll.and.returnValue(itemFiltersRdPL$);
fixture.detectChanges();
}); });
notificationsService = jasmine.createSpyObj('notificationsService', { it('should create', () => {
success: jasmine.createSpy('success'), expect(component).toBeTruthy();
error: jasmine.createSpy('error'),
}); });
await TestBed.configureTestingModule({
imports: [
ReactiveFormsModule,
RouterTestingModule,
NgbModalModule,
TranslateModule.forRoot()
],
providers: [
{provide: LdnItemfiltersService, useValue: ldnItemfiltersService},
{provide: LdnServicesService, useValue: ldnServicesService},
{provide: NotificationsService, useValue: notificationsService},
{provide: TranslateService, useValue: translateServiceStub},
{provide: Router, useValue: new RouterStub()},
{
provide: NgbModal, useValue: {
open: () => {/*comment*/
}
}
},
FormBuilder
],
declarations: [LdnServiceFormComponent]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(LdnServiceFormComponent);
component = fixture.componentInstance;
ldnItemfiltersService.findAll.and.returnValue(itemFiltersRdPL$);
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
}); });

View File

@@ -21,255 +21,258 @@ import {NgbModal} from '@ng-bootstrap/ng-bootstrap';
@Component({ @Component({
selector: 'ds-ldn-service-form', selector: 'ds-ldn-service-form',
templateUrl: './ldn-service-form.component.html', templateUrl: './ldn-service-form.component.html',
styleUrls: ['./ldn-service-form.component.scss'], styleUrls: ['./ldn-service-form.component.scss'],
animations: [ animations: [
trigger('toggleAnimation', [ trigger('toggleAnimation', [
state('true', style({})), state('true', style({})),
state('false', style({})), state('false', style({})),
transition('true <=> false', animate('300ms ease-in')), transition('true <=> false', animate('300ms ease-in')),
]), ]),
], ],
}) })
export class LdnServiceFormComponent implements OnInit { export class LdnServiceFormComponent implements OnInit {
formModel: FormGroup; formModel: FormGroup;
@ViewChild('confirmModal', {static: true}) confirmModal: TemplateRef<any>; @ViewChild('confirmModal', {static: true}) confirmModal: TemplateRef<any>;
@ViewChild('resetFormModal', {static: true}) resetFormModal: TemplateRef<any>; @ViewChild('resetFormModal', {static: true}) resetFormModal: TemplateRef<any>;
public inboundPatterns: string[] = notifyPatterns; public inboundPatterns: string[] = notifyPatterns;
public outboundPatterns: string[] = notifyPatterns; public outboundPatterns: string[] = notifyPatterns;
itemfiltersRD$: Observable<RemoteData<PaginatedList<Itemfilter>>>; itemfiltersRD$: Observable<RemoteData<PaginatedList<Itemfilter>>>;
config: FindListOptions = Object.assign(new FindListOptions(), { config: FindListOptions = Object.assign(new FindListOptions(), {
elementsPerPage: 20 elementsPerPage: 20
}); });
pageConfig: PaginationComponentOptions = Object.assign(new PaginationComponentOptions(), { pageConfig: PaginationComponentOptions = Object.assign(new PaginationComponentOptions(), {
id: 'po', id: 'po',
pageSize: 20 pageSize: 20
}); });
@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 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;
@Input() public constraint: string; @Input() public constraint: string;
@Input() public automatic: boolean; @Input() public automatic: boolean;
@Input() public headerKey: string; @Input() public headerKey: string;
@Output() submitForm: EventEmitter<any> = new EventEmitter(); @Output() submitForm: EventEmitter<any> = new EventEmitter();
@Output() cancelForm: EventEmitter<any> = new EventEmitter(); @Output() cancelForm: EventEmitter<any> = new EventEmitter();
selectedOutboundPatterns: string[]; selectedOutboundPatterns: string[];
selectedInboundPatterns: string[]; selectedInboundPatterns: string[];
selectedInboundItemfilters: string[]; selectedInboundItemfilters: string[];
selectedOutboundItemfilters: string[]; selectedOutboundItemfilters: string[];
private modalRef: any;
hasInboundPattern: boolean; hasInboundPattern: boolean;
hasOutboundPattern: boolean; hasOutboundPattern: boolean;
isScoreValid: boolean; isScoreValid: boolean;
private modalRef: any;
constructor( constructor(
private ldnServicesService: LdnServicesService, private ldnServicesService: LdnServicesService,
private ldnItemfiltersService: LdnItemfiltersService, private ldnItemfiltersService: LdnItemfiltersService,
private formBuilder: FormBuilder, private formBuilder: FormBuilder,
private router: Router, private router: Router,
private notificationsService: NotificationsService, private notificationsService: NotificationsService,
private translateService: TranslateService, private translateService: TranslateService,
private cdRef: ChangeDetectorRef, private cdRef: ChangeDetectorRef,
protected modalService: NgbModal, protected modalService: NgbModal,
) { ) {
this.formModel = this.formBuilder.group({ this.formModel = this.formBuilder.group({
enabled: true, enabled: true,
id: [''], id: [''],
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], score: ['', [Validators.required, Validators.pattern('^0*(\.[0-9]+)?$|^1(\.0+)?$')]], ldnUrl: ['', Validators.required],
inboundPattern: [''], inboundPattern: [''],
outboundPattern: [''], outboundPattern: [''],
constraintPattern: [''], constraintPattern: [''],
notifyServiceInboundPatterns: this.formBuilder.array([this.createInboundPatternFormGroup()]), notifyServiceInboundPatterns: this.formBuilder.array([this.createInboundPatternFormGroup()]),
notifyServiceOutboundPatterns: this.formBuilder.array([this.createOutboundPatternFormGroup()]), notifyServiceOutboundPatterns: this.formBuilder.array([this.createOutboundPatternFormGroup()]),
type: LDN_SERVICE.value, type: LDN_SERVICE.value,
}); });
}
ngOnInit(): void {
console.log(notifyPatterns)
this.setItemfilters();
}
setItemfilters() {
this.itemfiltersRD$ = this.ldnItemfiltersService.findAll().pipe(
getFirstCompletedRemoteData());
}
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('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;
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;
} }
this.formModel.value.notifyServiceInboundPatterns = this.formModel.value.notifyServiceInboundPatterns.map((pattern: { ngOnInit(): void {
pattern: string; console.log(notifyPatterns)
patternLabel: string this.setItemfilters();
}) => {
const {patternLabel, ...rest} = pattern;
return rest;
});
this.formModel.value.notifyServiceOutboundPatterns = this.formModel.value.notifyServiceOutboundPatterns.map((pattern: { }
pattern: string;
patternLabel: string
}) => {
const {patternLabel, ...rest} = pattern;
return rest;
});
const values = this.formModel.value; setItemfilters() {
this.itemfiltersRD$ = this.ldnItemfiltersService.findAll().pipe(
getFirstCompletedRemoteData());
}
const ldnServiceData = this.ldnServicesService.create(values); onSubmit() {
this.openConfirmModal(this.confirmModal);
}
ldnServiceData.pipe( openConfirmModal(content) {
getFirstCompletedRemoteData() this.modalRef = this.modalService.open(content);
).subscribe((rd: RemoteData<LdnService>) => { }
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(); openResetFormModal(content) {
this.closeModal(); this.modalRef = this.modalService.open(content);
} else { }
this.notificationsService.error(this.translateService.get('ldn-service-notification.created.failure.title'),
this.translateService.get('ldn-service-notification.created.failure.body')); 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;
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;
}
this.formModel.value.notifyServiceInboundPatterns = this.formModel.value.notifyServiceInboundPatterns.map((pattern: {
pattern: string;
patternLabel: string
}) => {
const {patternLabel, ...rest} = pattern;
return rest;
});
this.formModel.value.notifyServiceOutboundPatterns = this.formModel.value.notifyServiceOutboundPatterns.map((pattern: {
pattern: string;
patternLabel: string
}) => {
const {patternLabel, ...rest} = pattern;
return rest;
});
const values = this.formModel.value;
const ldnServiceData = this.ldnServicesService.create(values);
ldnServiceData.pipe(
getFirstCompletedRemoteData()
).subscribe((rd: RemoteData<LdnService>) => {
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('ldn-service-notification.created.failure.title'),
this.translateService.get('ldn-service-notification.created.failure.body'));
this.closeModal(); this.closeModal();
} }
}); });
} }
checkPatterns(formArray: FormArray): boolean {
for (let i = 0; i < formArray.length; i++) { checkPatterns(formArray: FormArray): boolean {
for (let i = 0; i < formArray.length; i++) {
const pattern = formArray.at(i).get('pattern').value; const pattern = formArray.at(i).get('pattern').value;
if (pattern) { if (pattern) {
return true; return true;
} }
} }
return false; return false;
}
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);
} }
}
selectOutboundPattern(patternValue: string, index: number): void { resetFormAndLeave() {
const patternArray = (this.formModel.get('notifyServiceOutboundPatterns') as FormArray) this.sendBack();
console.log((this.formModel.get('notifyServiceOutboundPatterns') as FormArray)) this.closeModal();
patternArray.controls[index].patchValue({pattern: patternValue}) }
patternArray.controls[index].patchValue({patternLabel: this.translateService.instant('ldn-service.form.pattern.' + patternValue + '.label')})
} closeModal() {
this.modalRef.close();
this.cdRef.detectChanges();
}
selectInboundPattern(patternValue: string, index: number): void { addInboundPattern() {
const patternArray = (this.formModel.get('notifyServiceInboundPatterns') as FormArray) const notifyServiceInboundPatternsArray = this.formModel.get('notifyServiceInboundPatterns') as FormArray;
console.log((this.formModel.get('notifyServiceInboundPatterns') as FormArray)) notifyServiceInboundPatternsArray.push(this.createInboundPatternFormGroup());
patternArray.controls[index].patchValue({pattern: patternValue}) }
patternArray.controls[index].patchValue({patternLabel: this.translateService.instant('ldn-service.form.pattern.' + patternValue + '.label')})
} removeInboundPattern(index: number) {
const notifyServiceInboundPatternsArray = this.formModel.get('notifyServiceInboundPatterns') as FormArray;
notifyServiceInboundPatternsArray.removeAt(index);
}
selectInboundItemFilter(filterValue: string, index: number): void { addOutboundPattern() {
const filterArray = (this.formModel.get('notifyServiceInboundPatterns') as FormArray) const notifyServiceOutboundPatternsArray = this.formModel.get('notifyServiceOutboundPatterns') as FormArray;
console.log((this.formModel.get('notifyServiceInboundPatterns') as FormArray)) notifyServiceOutboundPatternsArray.push(this.createOutboundPatternFormGroup());
filterArray.controls[index].patchValue({constraint: filterValue}) }
}
selectOutboundItemFilter(filterValue: string, index: number) { removeOutboundPattern(index: number) {
const filterArray = (this.formModel.get('notifyServiceOutboundPatterns') as FormArray) const notifyServiceOutboundPatternsArray = this.formModel.get('notifyServiceOutboundPatterns') as FormArray;
console.log((this.formModel.get('notifyServiceOutboundPatterns') as FormArray)) notifyServiceOutboundPatternsArray.removeAt(index);
filterArray.controls[index].patchValue({constraint: filterValue}) }
}
private sendBack() { toggleAutomatic(i: number) {
this.router.navigateByUrl('admin/ldn/services'); const automaticControl = this.formModel.get(`notifyServiceInboundPatterns.${i}.automatic`);
} if (automaticControl) {
automaticControl.setValue(!automaticControl.value);
}
}
private createOutboundPatternFormGroup(): FormGroup { selectOutboundPattern(patternValue: string, index: number): void {
return this.formBuilder.group({ const patternArray = (this.formModel.get('notifyServiceOutboundPatterns') as FormArray)
pattern: [''], console.log((this.formModel.get('notifyServiceOutboundPatterns') as FormArray))
constraint: [''], patternArray.controls[index].patchValue({pattern: patternValue})
patternLabel: 'Select a Pattern', patternArray.controls[index].patchValue({patternLabel: this.translateService.instant('ldn-service.form.pattern.' + patternValue + '.label')})
});
}
private createInboundPatternFormGroup(): FormGroup { }
return this.formBuilder.group({
pattern: [''], selectInboundPattern(patternValue: string, index: number): void {
constraint: [''], const patternArray = (this.formModel.get('notifyServiceInboundPatterns') as FormArray)
automatic: false, console.log((this.formModel.get('notifyServiceInboundPatterns') as FormArray))
patternLabel: 'Select a Pattern', patternArray.controls[index].patchValue({pattern: patternValue})
}); patternArray.controls[index].patchValue({patternLabel: this.translateService.instant('ldn-service.form.pattern.' + patternValue + '.label')})
}
}
selectInboundItemFilter(filterValue: string, index: number): void {
const filterArray = (this.formModel.get('notifyServiceInboundPatterns') as FormArray)
console.log((this.formModel.get('notifyServiceInboundPatterns') as FormArray))
filterArray.controls[index].patchValue({constraint: filterValue})
}
selectOutboundItemFilter(filterValue: string, index: number) {
const filterArray = (this.formModel.get('notifyServiceOutboundPatterns') as FormArray)
console.log((this.formModel.get('notifyServiceOutboundPatterns') as FormArray))
filterArray.controls[index].patchValue({constraint: filterValue})
}
private sendBack() {
this.router.navigateByUrl('admin/ldn/services');
}
private createOutboundPatternFormGroup(): FormGroup {
return this.formBuilder.group({
pattern: [''],
constraint: [''],
patternLabel: 'Select a Pattern',
});
}
private createInboundPatternFormGroup(): FormGroup {
return this.formBuilder.group({
pattern: [''],
constraint: [''],
automatic: false,
patternLabel: 'Select a Pattern',
});
}
} }

View File

@@ -3,23 +3,23 @@ import {ComponentFixture, TestBed} from '@angular/core/testing';
import {LdnServiceNewComponent} from './ldn-service-new.component'; import {LdnServiceNewComponent} from './ldn-service-new.component';
describe('LdnServiceNewComponent', () => { describe('LdnServiceNewComponent', () => {
let component: LdnServiceNewComponent; let component: LdnServiceNewComponent;
let fixture: ComponentFixture<LdnServiceNewComponent>; let fixture: ComponentFixture<LdnServiceNewComponent>;
beforeEach(async () => { beforeEach(async () => {
await TestBed.configureTestingModule({ await TestBed.configureTestingModule({
declarations: [LdnServiceNewComponent] declarations: [LdnServiceNewComponent]
}) })
.compileComponents(); .compileComponents();
}); });
beforeEach(() => { beforeEach(() => {
fixture = TestBed.createComponent(LdnServiceNewComponent); fixture = TestBed.createComponent(LdnServiceNewComponent);
component = fixture.componentInstance; component = fixture.componentInstance;
fixture.detectChanges(); fixture.detectChanges();
}); });
it('should create', () => { it('should create', () => {
expect(component).toBeTruthy(); expect(component).toBeTruthy();
}); });
}); });

View File

@@ -1,9 +1,9 @@
import {Component} from '@angular/core'; import {Component} from '@angular/core';
@Component({ @Component({
selector: 'ds-ldn-service-new', selector: 'ds-ldn-service-new',
templateUrl: './ldn-service-new.component.html', templateUrl: './ldn-service-new.component.html',
styleUrls: ['./ldn-service-new.component.scss'] styleUrls: ['./ldn-service-new.component.scss']
}) })
export class LdnServiceNewComponent { export class LdnServiceNewComponent {
} }

View File

@@ -5,63 +5,63 @@ import {PaginatedList} from '../../../core/data/paginated-list.model';
import {Observable, of} from 'rxjs'; import {Observable, of} from 'rxjs';
// Create a mock data object for a single LDN notify service // Create a mock data object for a single LDN notify service
export const mockLdnService: LdnService = { export const mockLdnService: LdnService = {
id: 1, id: 1,
name: 'Service Name', name: 'Service Name',
description: 'Service Description', description: 'Service Description',
url: 'Service URL', url: 'Service URL',
ldnUrl: 'Service LDN URL', ldnUrl: 'Service LDN URL',
notifyServiceInboundPatterns: [ notifyServiceInboundPatterns: [
{ {
pattern: 'patternA', pattern: 'patternA',
constraint: 'itemFilterA', constraint: 'itemFilterA',
automatic: false, automatic: false,
},
{
pattern: 'patternB',
constraint: 'itemFilterB',
automatic: true,
},
],
notifyServiceOutboundPatterns: [
{
pattern: 'patternC',
constraint: 'itemFilterC',
},
],
type: LDN_SERVICE,
_links: {
self: {
href: 'http://localhost/api/ldn/ldnservices/1',
},
}, },
{
pattern: 'patternB',
constraint: 'itemFilterB',
automatic: true,
},
],
notifyServiceOutboundPatterns: [
{
pattern: 'patternC',
constraint: 'itemFilterC',
},
],
type: LDN_SERVICE,
_links: {
self: {
href: 'http://localhost/api/ldn/ldnservices/1',
},
},
}; };
const mockLdnServices = { const mockLdnServices = {
payload: { payload: {
elementsPerPage: 20, elementsPerPage: 20,
totalPages: 1, totalPages: 1,
totalElements: 1, totalElements: 1,
currentPage: 1, currentPage: 1,
first: undefined, first: undefined,
prev: undefined, prev: undefined,
next: undefined, next: undefined,
last: undefined, last: undefined,
page: [mockLdnService], page: [mockLdnService],
type: LDN_SERVICE, type: LDN_SERVICE,
self: undefined, self: undefined,
getPageLength: function () { getPageLength: function () {
return this.page.length; return this.page.length;
},
_links: {
self: {
href: 'http://localhost/api/ldn/ldnservices/1',
},
page: [],
},
}, },
_links: { hasSucceeded: true,
self: { msToLive: 0,
href: 'http://localhost/api/ldn/ldnservices/1',
},
page: [],
},
},
hasSucceeded: true,
msToLive: 0,
}; };

View File

@@ -23,25 +23,25 @@ import {PaginatedList} from '../../../core/data/paginated-list.model';
@Injectable() @Injectable()
@dataService(LDN_SERVICE_CONSTRAINT_FILTERS) @dataService(LDN_SERVICE_CONSTRAINT_FILTERS)
export class LdnItemfiltersService extends IdentifiableDataService<Itemfilter> implements FindAllData<Itemfilter> { export class LdnItemfiltersService extends IdentifiableDataService<Itemfilter> implements FindAllData<Itemfilter> {
private findAllData: FindAllDataImpl<Itemfilter>; private findAllData: FindAllDataImpl<Itemfilter>;
constructor( constructor(
protected requestService: RequestService, protected requestService: RequestService,
protected rdbService: RemoteDataBuildService, protected rdbService: RemoteDataBuildService,
protected objectCache: ObjectCacheService, protected objectCache: ObjectCacheService,
protected halService: HALEndpointService, protected halService: HALEndpointService,
protected notificationsService: NotificationsService, protected notificationsService: NotificationsService,
) { ) {
super('itemfilters', requestService, rdbService, objectCache, halService); super('itemfilters', requestService, rdbService, objectCache, halService);
this.findAllData = new FindAllDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, this.responseMsToLive); this.findAllData = new FindAllDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, this.responseMsToLive);
} }
getEndpoint() { getEndpoint() {
return this.halService.getEndpoint(this.linkPath); return this.halService.getEndpoint(this.linkPath);
} }
findAll(options?: FindListOptions, useCachedVersionIfAvailable?: boolean, reRequestOnStale?: boolean, ...linksToFollow: FollowLinkConfig<Itemfilter>[]): Observable<RemoteData<PaginatedList<Itemfilter>>> { findAll(options?: FindListOptions, useCachedVersionIfAvailable?: boolean, reRequestOnStale?: boolean, ...linksToFollow: FollowLinkConfig<Itemfilter>[]): Observable<RemoteData<PaginatedList<Itemfilter>>> {
return this.findAllData.findAll(options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow); return this.findAllData.findAll(options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
} }
} }

View File

@@ -40,99 +40,99 @@ import {RequestParam} from '../../../core/cache/models/request-param.model';
@Injectable() @Injectable()
@dataService(LDN_SERVICE) @dataService(LDN_SERVICE)
export class LdnServicesService extends IdentifiableDataService<LdnService> implements FindAllData<LdnService>, DeleteData<LdnService>, PatchData<LdnService>, CreateData<LdnService> { export class LdnServicesService extends IdentifiableDataService<LdnService> implements FindAllData<LdnService>, DeleteData<LdnService>, PatchData<LdnService>, CreateData<LdnService> {
createData: CreateDataImpl<LdnService>; createData: CreateDataImpl<LdnService>;
private findAllData: FindAllDataImpl<LdnService>; private findAllData: FindAllDataImpl<LdnService>;
private deleteData: DeleteDataImpl<LdnService>; private deleteData: DeleteDataImpl<LdnService>;
private patchData: PatchDataImpl<LdnService>; private patchData: PatchDataImpl<LdnService>;
private comparator: ChangeAnalyzer<LdnService>; private comparator: ChangeAnalyzer<LdnService>;
private searchData: SearchDataImpl<LdnService>; private searchData: SearchDataImpl<LdnService>;
private findByPatternEndpoint = 'byInboundPattern'; private findByPatternEndpoint = 'byInboundPattern';
constructor( constructor(
protected requestService: RequestService, protected requestService: RequestService,
protected rdbService: RemoteDataBuildService, protected rdbService: RemoteDataBuildService,
protected objectCache: ObjectCacheService, protected objectCache: ObjectCacheService,
protected halService: HALEndpointService, protected halService: HALEndpointService,
protected notificationsService: NotificationsService, protected notificationsService: NotificationsService,
) { ) {
super('ldnservices', requestService, rdbService, objectCache, halService); super('ldnservices', requestService, rdbService, objectCache, halService);
this.findAllData = new FindAllDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, this.responseMsToLive); this.findAllData = new FindAllDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, this.responseMsToLive);
this.searchData = new SearchDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, this.responseMsToLive); this.searchData = new SearchDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, this.responseMsToLive);
this.deleteData = new DeleteDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, notificationsService, this.responseMsToLive, this.constructIdEndpoint); 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.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.createData = new CreateDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, notificationsService, this.responseMsToLive);
} }
create(object: LdnService): Observable<RemoteData<LdnService>> { create(object: LdnService): Observable<RemoteData<LdnService>> {
return this.createData.create(object); return this.createData.create(object);
} }
patch(object: LdnService, operations: Operation[]): Observable<RemoteData<LdnService>> { patch(object: LdnService, operations: Operation[]): Observable<RemoteData<LdnService>> {
return this.patchData.patch(object, operations); return this.patchData.patch(object, operations);
} }
update(object: LdnService): Observable<RemoteData<LdnService>> { update(object: LdnService): Observable<RemoteData<LdnService>> {
return this.patchData.update(object); return this.patchData.update(object);
} }
commitUpdates(method?: RestRequestMethod): void { commitUpdates(method?: RestRequestMethod): void {
return this.patchData.commitUpdates(method); return this.patchData.commitUpdates(method);
} }
createPatchFromCache(object: LdnService): Observable<Operation[]> { createPatchFromCache(object: LdnService): Observable<Operation[]> {
return this.patchData.createPatchFromCache(object); return this.patchData.createPatchFromCache(object);
} }
findAll(options?: FindListOptions, useCachedVersionIfAvailable?: boolean, reRequestOnStale?: boolean, ...linksToFollow: FollowLinkConfig<LdnService>[]): Observable<RemoteData<PaginatedList<LdnService>>> { findAll(options?: FindListOptions, useCachedVersionIfAvailable?: boolean, reRequestOnStale?: boolean, ...linksToFollow: FollowLinkConfig<LdnService>[]): Observable<RemoteData<PaginatedList<LdnService>>> {
return this.findAllData.findAll(options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow); return this.findAllData.findAll(options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
} }
findByInboundPattern(pattern: string, options?: FindListOptions, useCachedVersionIfAvailable?: boolean, reRequestOnStale?: boolean, ...linksToFollow: FollowLinkConfig<LdnService>[]): Observable<RemoteData<PaginatedList<LdnService>>> { findByInboundPattern(pattern: string, options?: FindListOptions, useCachedVersionIfAvailable?: boolean, reRequestOnStale?: boolean, ...linksToFollow: FollowLinkConfig<LdnService>[]): Observable<RemoteData<PaginatedList<LdnService>>> {
const params = [new RequestParam('pattern', pattern)]; const params = [new RequestParam('pattern', pattern)];
const findListOptions = Object.assign(new FindListOptions(), options, {searchParams: params}); const findListOptions = Object.assign(new FindListOptions(), options, {searchParams: params});
return this.searchData.searchBy(this.findByPatternEndpoint, findListOptions, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow); return this.searchData.searchBy(this.findByPatternEndpoint, findListOptions, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
} }
public delete(objectId: string, copyVirtualMetadata?: string[]): Observable<RemoteData<NoContent>> { public delete(objectId: string, copyVirtualMetadata?: string[]): Observable<RemoteData<NoContent>> {
return this.deleteData.delete(objectId, copyVirtualMetadata); return this.deleteData.delete(objectId, copyVirtualMetadata);
} }
public deleteByHref(href: string, copyVirtualMetadata?: string[]): Observable<RemoteData<NoContent>> { public deleteByHref(href: string, copyVirtualMetadata?: string[]): Observable<RemoteData<NoContent>> {
return this.deleteData.deleteByHref(href, copyVirtualMetadata); return this.deleteData.deleteByHref(href, copyVirtualMetadata);
} }
public invoke(serviceName: string, serviceId: string, parameters: LdnServiceConstrain[], files: File[]): Observable<RemoteData<LdnService>> { public invoke(serviceName: string, serviceId: string, parameters: LdnServiceConstrain[], files: File[]): Observable<RemoteData<LdnService>> {
const requestId = this.requestService.generateRequestId(); const requestId = this.requestService.generateRequestId();
this.getBrowseEndpoint().pipe( this.getBrowseEndpoint().pipe(
take(1), take(1),
map((endpoint: string) => new URLCombiner(endpoint, serviceName, 'processes', serviceId).toString()), map((endpoint: string) => new URLCombiner(endpoint, serviceName, 'processes', serviceId).toString()),
map((endpoint: string) => { map((endpoint: string) => {
const body = this.getInvocationFormData(parameters, files); const body = this.getInvocationFormData(parameters, files);
return new MultipartPostRequest(requestId, endpoint, body); return new MultipartPostRequest(requestId, endpoint, body);
}) })
).subscribe((request: RestRequest) => this.requestService.send(request)); ).subscribe((request: RestRequest) => this.requestService.send(request));
return this.rdbService.buildFromRequestUUID<LdnService>(requestId); return this.rdbService.buildFromRequestUUID<LdnService>(requestId);
} }
public ldnServiceWithNameExistsAndCanExecute(scriptName: string): Observable<boolean> { public ldnServiceWithNameExistsAndCanExecute(scriptName: string): Observable<boolean> {
return this.findById(scriptName).pipe( return this.findById(scriptName).pipe(
getFirstCompletedRemoteData(), getFirstCompletedRemoteData(),
map((rd: RemoteData<LdnService>) => { map((rd: RemoteData<LdnService>) => {
return hasValue(rd.payload); return hasValue(rd.payload);
}), }),
); );
} }
private getInvocationFormData(constrain: LdnServiceConstrain[], files: File[]): FormData { private getInvocationFormData(constrain: LdnServiceConstrain[], files: File[]): FormData {
const form: FormData = new FormData(); const form: FormData = new FormData();
form.set('properties', JSON.stringify(constrain)); form.set('properties', JSON.stringify(constrain));
files.forEach((file: File) => { files.forEach((file: File) => {
form.append('file', file); form.append('file', file);
}); });
return form; return form;
} }
} }

View File

@@ -1,84 +1,84 @@
<div class="container"> <div class="container">
<div class="d-flex"> <div class="d-flex">
<h2 class="flex-grow-1">{{ 'ldn-registered-services.title' | translate }}</h2> <h2 class="flex-grow-1">{{ 'ldn-registered-services.title' | translate }}</h2>
</div> </div>
<div class="d-flex justify-content-end"> <div class="d-flex justify-content-end">
<button class="btn btn-success" routerLink="/admin/ldn/services/new"><i <button class="btn btn-success" routerLink="/admin/ldn/services/new"><i
class="fas fa-plus pr-2"></i>{{ 'process.overview.new' | translate }}</button> class="fas fa-plus pr-2"></i>{{ 'process.overview.new' | translate }}</button>
</div> </div>
<ds-pagination *ngIf="(ldnServicesRD$ | async)?.payload?.totalElements > 0" <ds-pagination *ngIf="(ldnServicesRD$ | async)?.payload?.totalElements > 0"
[collectionSize]="(ldnServicesRD$ | async)?.payload?.totalElements" [collectionSize]="(ldnServicesRD$ | async)?.payload?.totalElements"
[hideGear]="true" [hideGear]="true"
[hidePagerWhenSinglePage]="true" [hidePagerWhenSinglePage]="true"
[pageInfoState]="(ldnServicesRD$ | async)?.payload" [pageInfoState]="(ldnServicesRD$ | async)?.payload"
[paginationOptions]="pageConfig"> [paginationOptions]="pageConfig">
<div class="table-responsive"> <div class="table-responsive">
<table class="table table-striped table-hover"> <table class="table table-striped table-hover">
<thead> <thead>
<tr> <tr>
<th scope="col">{{ 'service.overview.table.name' | translate }}</th> <th scope="col">{{ 'service.overview.table.name' | translate }}</th>
<th scope="col">{{ 'service.overview.table.description' | translate }}</th> <th scope="col">{{ 'service.overview.table.description' | translate }}</th>
<th scope="col">{{ 'service.overview.table.status' | translate }}</th> <th scope="col">{{ 'service.overview.table.status' | translate }}</th>
<th scope="col">{{ 'service.overview.table.actions' | translate }}</th> <th scope="col">{{ 'service.overview.table.actions' | translate }}</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr *ngFor="let ldnService of (ldnServicesRD$ | async)?.payload?.page"> <tr *ngFor="let ldnService of (ldnServicesRD$ | async)?.payload?.page">
<td>{{ ldnService.name }}</td> <td>{{ ldnService.name }}</td>
<td>{{ ldnService.description }}</td> <td>{{ ldnService.description }}</td>
<td> <td>
<span (click)="toggleStatus(ldnService, ldnServicesService)" <span (click)="toggleStatus(ldnService, ldnServicesService)"
[ngClass]="{ 'status-enabled': ldnService.enabled, 'status-disabled': !ldnService.enabled }" [ngClass]="{ 'status-enabled': ldnService.enabled, 'status-disabled': !ldnService.enabled }"
[title]="ldnService.enabled ? ('ldn-service.overview.table.clickToDisable' | translate) : ('ldn-service.overview.table.clickToEnable' | translate)" [title]="ldnService.enabled ? ('ldn-service.overview.table.clickToDisable' | translate) : ('ldn-service.overview.table.clickToEnable' | translate)"
class="status-indicator"> class="status-indicator">
{{ ldnService.enabled ? ('ldn-service.overview.table.enabled' | translate) : ('ldn-service.overview.table.disabled' | translate) }} {{ ldnService.enabled ? ('ldn-service.overview.table.enabled' | translate) : ('ldn-service.overview.table.disabled' | translate) }}
</span> </span>
</td> </td>
<td> <td>
<div class="btn-group"> <div class="btn-group">
<button (click)="selectServiceToDelete(ldnService.id)" class="btn btn-outline-danger"> <button (click)="selectServiceToDelete(ldnService.id)" class="btn btn-outline-danger">
<i class="fas fa-trash"></i> <i class="fas fa-trash"></i>
</button> </button>
<button [routerLink]="['/admin/ldn/services/edit/', ldnService.id]" <button [routerLink]="['/admin/ldn/services/edit/', ldnService.id]"
class="btn btn-outline-dark"> class="btn btn-outline-dark">
<i class="fas fa-edit"></i> <i class="fas fa-edit"></i>
</button> </button>
</div> </div>
</td> </td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
</div> </div>
</ds-pagination> </ds-pagination>
</div> </div>
<ng-template #deleteModal> <ng-template #deleteModal>
<div> <div>
<div class="modal-header"> <div class="modal-header">
<div> <div>
<h4>{{'service.overview.delete.header' | translate }}</h4> <h4>{{'service.overview.delete.header' | translate }}</h4>
</div> </div>
<button (click)="closeModal()" aria-label="Close" <button (click)="closeModal()" aria-label="Close"
class="close" type="button"> class="close" type="button">
<span aria-hidden="true">×</span> <span aria-hidden="true">×</span>
</button> </button>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<div> <div>
{{ 'service.overview.delete.body' | translate }} {{ 'service.overview.delete.body' | translate }}
</div> </div>
<div class="mt-4"> <div class="mt-4">
<button (click)="closeModal()" <button (click)="closeModal()"
class="btn btn-primary mr-2">{{ 'service.detail.delete.cancel' | translate }}</button> class="btn btn-primary mr-2">{{ 'service.detail.delete.cancel' | translate }}</button>
<button (click)="deleteSelected(this.selectedServiceId.toString(), ldnServicesService)" <button (click)="deleteSelected(this.selectedServiceId.toString(), ldnServicesService)"
class="btn btn-danger" class="btn btn-danger"
id="delete-confirm">{{ 'service.overview.delete' | translate }} id="delete-confirm">{{ 'service.overview.delete' | translate }}
</button> </button>
</div> </div>
</div>
</div> </div>
</div>
</ng-template> </ng-template>

View File

@@ -11,44 +11,44 @@ import {PaginationServiceStub} from '../../../shared/testing/pagination-service.
import {of} from 'rxjs'; import {of} from 'rxjs';
describe('LdnServicesOverviewComponent', () => { describe('LdnServicesOverviewComponent', () => {
let component: LdnServicesOverviewComponent; let component: LdnServicesOverviewComponent;
let fixture: ComponentFixture<LdnServicesOverviewComponent>; let fixture: ComponentFixture<LdnServicesOverviewComponent>;
const translateServiceStub = { const translateServiceStub = {
get: () => of('translated-text'), get: () => of('translated-text'),
onLangChange: new EventEmitter(), onLangChange: new EventEmitter(),
onTranslationChange: new EventEmitter(), onTranslationChange: new EventEmitter(),
onDefaultLangChange: new EventEmitter() onDefaultLangChange: new EventEmitter()
}; };
beforeEach(async () => { beforeEach(async () => {
await TestBed.configureTestingModule({ await TestBed.configureTestingModule({
imports: [TranslateModule.forRoot()], imports: [TranslateModule.forRoot()],
declarations: [LdnServicesOverviewComponent], declarations: [LdnServicesOverviewComponent],
providers: [ providers: [
{provide: LdnServicesService, useValue: {}}, {provide: LdnServicesService, useValue: {}},
{provide: PaginationService, useValue: new PaginationServiceStub()}, {provide: PaginationService, useValue: new PaginationServiceStub()},
{ {
provide: NgbModal, useValue: { provide: NgbModal, useValue: {
open: () => {/*comment*/ open: () => {/*comment*/
} }
} }
}, },
{provide: ChangeDetectorRef, useValue: {}}, {provide: ChangeDetectorRef, useValue: {}},
{provide: NotificationsService, useValue: NotificationsServiceStub}, {provide: NotificationsService, useValue: NotificationsServiceStub},
{provide: TranslateService, useValue: translateServiceStub}, {provide: TranslateService, useValue: translateServiceStub},
] ]
}) })
.compileComponents(); .compileComponents();
}); });
beforeEach(() => { beforeEach(() => {
fixture = TestBed.createComponent(LdnServicesOverviewComponent); fixture = TestBed.createComponent(LdnServicesOverviewComponent);
component = fixture.componentInstance; component = fixture.componentInstance;
fixture.detectChanges(); fixture.detectChanges();
}); });
it('should create', () => { it('should create', () => {
expect(component).toBeTruthy(); expect(component).toBeTruthy();
}); });
}); });

View File

@@ -1,11 +1,11 @@
import { import {
ChangeDetectionStrategy, ChangeDetectionStrategy,
ChangeDetectorRef, ChangeDetectorRef,
Component, Component,
OnDestroy, OnDestroy,
OnInit, OnInit,
TemplateRef, TemplateRef,
ViewChild ViewChild
} from '@angular/core'; } from '@angular/core';
import {Observable, Subscription} from 'rxjs'; import {Observable, Subscription} from 'rxjs';
import {RemoteData} from '../../../core/data/remote-data'; import {RemoteData} from '../../../core/data/remote-data';
@@ -25,122 +25,122 @@ import {TranslateService} from '@ngx-translate/core';
@Component({ @Component({
selector: 'ds-ldn-services-directory', selector: 'ds-ldn-services-directory',
templateUrl: './ldn-services-directory.component.html', templateUrl: './ldn-services-directory.component.html',
styleUrls: ['./ldn-services-directory.component.scss'], styleUrls: ['./ldn-services-directory.component.scss'],
changeDetection: ChangeDetectionStrategy.Default changeDetection: ChangeDetectionStrategy.Default
}) })
export class LdnServicesOverviewComponent implements OnInit, OnDestroy { export class LdnServicesOverviewComponent implements OnInit, OnDestroy {
selectedServiceId: string | number | null = null; selectedServiceId: string | number | null = null;
servicesData: any[] = []; servicesData: any[] = [];
@ViewChild('deleteModal', {static: true}) deleteModal: TemplateRef<any>; @ViewChild('deleteModal', {static: true}) deleteModal: TemplateRef<any>;
ldnServicesRD$: Observable<RemoteData<PaginatedList<LdnService>>>; ldnServicesRD$: Observable<RemoteData<PaginatedList<LdnService>>>;
config: FindListOptions = Object.assign(new FindListOptions(), { config: FindListOptions = Object.assign(new FindListOptions(), {
elementsPerPage: 20 elementsPerPage: 20
}); });
pageConfig: PaginationComponentOptions = Object.assign(new PaginationComponentOptions(), { pageConfig: PaginationComponentOptions = Object.assign(new PaginationComponentOptions(), {
id: 'po', id: 'po',
pageSize: 20 pageSize: 20
}); });
isProcessingSub: Subscription; isProcessingSub: Subscription;
private modalRef: any; private modalRef: any;
constructor( constructor(
protected ldnServicesService: LdnServicesService, protected ldnServicesService: LdnServicesService,
protected paginationService: PaginationService, protected paginationService: PaginationService,
protected modalService: NgbModal, protected modalService: NgbModal,
private cdRef: ChangeDetectorRef, private cdRef: ChangeDetectorRef,
private notificationService: NotificationsService, private notificationService: NotificationsService,
private translateService: TranslateService, 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();
} }
}
openDeleteModal(content) { ngOnInit(): void {
this.modalRef = this.modalService.open(content); this.setLdnServices();
}
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<LdnService>) => {
if (rd.hasSucceeded) {
this.servicesData = this.servicesData.filter(service => service.id !== serviceId);
this.ldnServicesRD$ = this.ldnServicesRD$.pipe(
map((remoteData: RemoteData<PaginatedList<LdnService>>) => {
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();
}
});
} }
}
setLdnServices() {
this.ldnServicesRD$ = this.paginationService.getFindListOptions(this.pageConfig.id, this.config).pipe(
switchMap((config) => this.ldnServicesService.findAll(config, false, false).pipe(
getFirstCompletedRemoteData()
))
);
}
toggleStatus(ldnService: any, ldnServicesService: LdnServicesService): void { ngOnDestroy(): void {
const newStatus = !ldnService.enabled; this.paginationService.clearPagination(this.pageConfig.id);
const originalStatus = ldnService.enabled; if (hasValue(this.isProcessingSub)) {
this.isProcessingSub.unsubscribe();
const patchOperation: Operation = {
op: 'replace',
path: '/enabled',
value: newStatus,
};
ldnServicesService.patch(ldnService, [patchOperation]).pipe(getFirstCompletedRemoteData()).subscribe(
(rd: RemoteData<LdnService>) => {
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'));
} }
} }
);
} 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<LdnService>) => {
if (rd.hasSucceeded) {
this.servicesData = this.servicesData.filter(service => service.id !== serviceId);
this.ldnServicesRD$ = this.ldnServicesRD$.pipe(
map((remoteData: RemoteData<PaginatedList<LdnService>>) => {
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();
}
});
}
}
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<LdnService>) => {
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'));
}
}
);
}
} }

View File

@@ -9,23 +9,23 @@ import {ResourceType} from '../../../core/shared/resource-type';
@typedObject @typedObject
@inheritSerialization(CacheableObject) @inheritSerialization(CacheableObject)
export class Itemfilter extends CacheableObject { export class Itemfilter extends CacheableObject {
static type = LDN_SERVICE_CONSTRAINT_FILTER; static type = LDN_SERVICE_CONSTRAINT_FILTER;
@excludeFromEquals @excludeFromEquals
@autoserialize @autoserialize
type: ResourceType; type: ResourceType;
@autoserialize @autoserialize
id: string; id: string;
@deserialize @deserialize
_links: { _links: {
self: { self: {
href: string; href: string;
};
}; };
};
get self(): string { get self(): string {
return this._links.self.href; return this._links.self.href;
} }
} }

View File

@@ -4,10 +4,10 @@ import {autoserialize} from 'cerialize';
* notify service patterns * notify service patterns
*/ */
export class NotifyServicePattern { export class NotifyServicePattern {
@autoserialize @autoserialize
pattern: string; pattern: string;
@autoserialize @autoserialize
constraint: string; constraint: string;
@autoserialize @autoserialize
automatic: string; automatic: string;
} }

View File

@@ -2,7 +2,7 @@
* List of services statuses * List of services statuses
*/ */
export enum LdnServiceStatus { export enum LdnServiceStatus {
UNKOWN, UNKOWN,
DISABLED, DISABLED,
ENABLED, ENABLED,
} }

View File

@@ -1,3 +1,3 @@
export class LdnServiceConstrain { export class LdnServiceConstrain {
void: any; void: any;
} }

View File

@@ -2,9 +2,9 @@
* List of parameter types used for scripts * List of parameter types used for scripts
*/ */
export enum LdnServiceConstrainType { export enum LdnServiceConstrainType {
STRING = 'String', STRING = 'String',
DATE = 'date', DATE = 'date',
BOOLEAN = 'boolean', BOOLEAN = 'boolean',
FILE = 'InputStream', FILE = 'InputStream',
OUTPUT = 'OutputStream' OUTPUT = 'OutputStream'
} }

View File

@@ -1,30 +1,30 @@
export const notifyPatterns = [ export const notifyPatterns = [
'ack-accept', 'ack-accept',
'ack-reject', 'ack-reject',
'ack-tentative-accept', 'ack-tentative-accept',
'ack-tentative-reject', 'ack-tentative-reject',
'announce-endorsement', 'announce-endorsement',
'announce-ingest', 'announce-ingest',
'announce-relationship', 'announce-relationship',
'announce-review', 'announce-review',
'announce-service-result', 'announce-service-result',
'request-endorsement', 'request-endorsement',
'request-ingest', 'request-ingest',
'request-review', 'request-review',
'undo-offer', 'undo-offer',
]; ];