CST-12868 remove Outbound Patterns

This commit is contained in:
frabacche
2024-01-08 16:01:12 +01:00
parent ad723a67cf
commit dfe4b15539
5 changed files with 7 additions and 324 deletions

View File

@@ -220,145 +220,6 @@
<span (click)="addInboundPattern()"
class="add-pattern-link mb-2">{{ 'ldn-new-service.form.label.addPattern' | translate }}</span>
<!-- In the Outbound Patterns Labels section -->
<div class="row mb-1 mt-5" *ngIf="areControlsInitialized">
<div class="col">
<label class="font-weight-bold">{{ 'ldn-new-service.form.label.outboundPattern' | translate }} </label>
</div>
<ng-container *ngIf="!!(formModel.get('notifyServiceOutboundPatterns')['controls'][0]?.value?.pattern)">
<div class="col">
<label class="font-weight-bold">{{ '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>
<!-- In the Outbound Patterns section -->
<div *ngIf="areControlsInitialized">
<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">
<div class="row mb-1 align-items-center">
<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"
/>
<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"
/>
<div aria-labelledby="outboundItemfilterDropdownButton"
class="dropdown-menu scrollable-dropdown-menu w-100 "
ngbDropdownMenu>
<div class="scrollable-menu" role="listbox">
<button (click)="selectOutboundItemFilter('', i); $event.stopPropagation()"
class="dropdown-item collection-item text-truncate w-100" ngbDropdownItem type="button">
<span> {{'ldn-service.control-constaint-select-none' | translate}} </span>
</button>
<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>
</div>
<div
(click)="addOutboundPattern()"
class="add-pattern-link mb-4">{{ 'ldn-new-service.form.label.addPattern' | translate }}
</div>
<div class="submission-form-footer my-1 position-sticky d-flex justify-content-between" role="group">
<button (click)="openResetFormModal(resetFormModal)" class="btn btn-danger" type="button">
<span><i class="fas fa-trash"></i>&nbsp;{{ 'submission.general.discard.submit' | translate }}</span>

View File

@@ -52,7 +52,6 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
@ViewChild('resetFormModal', {static: true}) resetFormModal: TemplateRef<any>;
public inboundPatterns: string[] = notifyPatterns;
public outboundPatterns: string[] = notifyPatterns;
public isNewService: boolean;
public areControlsInitialized: boolean;
itemfiltersRD$: Observable<RemoteData<PaginatedList<Itemfilter>>>;
@@ -66,21 +65,16 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
@Input() public ldnUrl: string;
@Input() public score: number;
@Input() public inboundPattern: string;
@Input() public outboundPattern: string;
@Input() public constraint: string;
@Input() public automatic: boolean;
@Input() public headerKey: string;
@Output() submitForm: EventEmitter<any> = new EventEmitter();
@Output() cancelForm: EventEmitter<any> = new EventEmitter();
markedForDeletionInboundPattern: number[] = [];
markedForDeletionOutboundPattern: number[] = [];
selectedOutboundPatterns: string[];
selectedInboundPatterns: string[];
selectedInboundItemfilters: string[];
selectedOutboundItemfilters: string[];
protected serviceId: string;
private deletedInboundPatterns: number[] = [];
private deletedOutboundPatterns: number[] = [];
private modalRef: any;
private service: LdnService;
private selectPatternDefaultLabeli18Key = 'ldn-service.form.label.placeholder.default-select';
@@ -106,7 +100,6 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
url: ['', Validators.required],
ldnUrl: ['', Validators.required],
score: ['', [Validators.required, Validators.pattern('^0*(\.[0-9]+)?$|^1(\.0+)?$')]], inboundPattern: [''],
outboundPattern: [''],
constraintPattern: [''],
enabled: [''],
type: LDN_SERVICE.value,
@@ -120,7 +113,6 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
this.serviceId = params.serviceId;
this.isNewService = segment[0].path === 'new';
this.formModel.addControl('notifyServiceInboundPatterns', this.formBuilder.array([this.createInboundPatternFormGroup()]));
this.formModel.addControl('notifyServiceOutboundPatterns', this.formBuilder.array([this.createOutboundPatternFormGroup()]));
this.areControlsInitialized = true;
if (this.serviceId && !this.isNewService) {
this.fetchServiceData(this.serviceId);
@@ -154,14 +146,13 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
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 && score !== 0) || this.formModel.get('score').invalid) {
this.closeModal();
return;
}
if (!hasInboundPattern || !hasOutboundPattern) {
if (!hasInboundPattern) {
this.notificationService.warning(this.translateService.get('ldn-service-notification.created.warning.title'));
this.closeModal();
return;
@@ -176,14 +167,6 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
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, enabled: true};
const ldnServiceData = this.ldnServicesService.create(values);
@@ -242,8 +225,7 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
type: this.service.type,
enabled: this.service.enabled
});
this.filterPatternObjectsAndPickLabel('notifyServiceInboundPatterns', false);
this.filterPatternObjectsAndPickLabel('notifyServiceOutboundPatterns', true);
this.filterPatternObjectsAndPickLabel('notifyServiceInboundPatterns');
}
},
);
@@ -252,25 +234,16 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
/**
* Filters pattern objects, initializes form groups, assigns labels, and adds them to the specified form array so the correct string is shown in the dropdown..
* @param formArrayName - The name of the form array to be populated
* @param isOutbound - A boolean indicating whether the patterns are outbound (true) or inbound (false)
*/
filterPatternObjectsAndPickLabel(formArrayName: string, isOutbound: boolean) {
filterPatternObjectsAndPickLabel(formArrayName: string) {
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();
}
patternFormGroup = this.initializeInboundPatternFormGroup();
const newPatternObjWithLabel = Object.assign(new NotifyServicePattern(), {
...patternObj,
patternLabel: this.translateService.instant('ldn-service.form.pattern.' + patternObj?.pattern + '.label')
@@ -298,9 +271,6 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
this.createReplaceOperation(patchOperations, 'score', '/score');
this.handlePatterns(patchOperations, 'notifyServiceInboundPatterns');
this.handlePatterns(patchOperations, 'notifyServiceOutboundPatterns');
this.deletedInboundPatterns.forEach(index => {
const removeOperation: Operation = {
op: 'remove',
@@ -309,14 +279,6 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
patchOperations.push(removeOperation);
});
this.deletedOutboundPatterns.forEach(index => {
const removeOperation: Operation = {
op: 'remove',
path: `notifyServiceOutboundPatterns[${index}]`
};
patchOperations.push(removeOperation);
});
return patchOperations;
}
@@ -335,36 +297,6 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
notifyServiceInboundPatternsArray.push(this.createInboundPatternFormGroup());
}
/**
* Adds a new outbound pattern form group to the array of outbound patterns in the form
*/
addOutboundPattern() {
const notifyServiceOutboundPatternsArray = this.formModel.get('notifyServiceOutboundPatterns') as FormArray;
notifyServiceOutboundPatternsArray.push(this.createOutboundPatternFormGroup());
}
/**
* Selects an outbound pattern by updating its values based on the provided pattern value and index
* @param patternValue - The selected pattern value
* @param index - The index of the outbound pattern in the array
*/
selectOutboundPattern(patternValue: string, index: number): void {
const patternArray = (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')});
}
/**
* Selects an outbound item filter by updating its value based on the provided filter value and index
* @param filterValue - The selected filter value
* @param index - The index of the inbound pattern in the array
*/
selectOutboundItemFilter(filterValue: string, index: number) {
const filterArray = (this.formModel.get('notifyServiceOutboundPatterns') as FormArray);
filterArray.controls[index].patchValue({constraint: filterValue});
}
/**
* Selects an inbound pattern by updating its values based on the provided pattern value and index
* @param patternValue - The selected pattern value
@@ -450,7 +382,6 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
*/
patchService() {
this.deleteMarkedInboundPatterns();
this.deleteMarkedOutboundPatterns();
const patchOperations = this.generatePatchOperations();
this.formModel.markAllAsTouched();
@@ -460,17 +391,12 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
return;
}
const notifyServiceOutboundPatterns = this.formModel.get('notifyServiceOutboundPatterns') as FormArray;
const notifyServiceInboundPatterns = this.formModel.get('notifyServiceInboundPatterns') as FormArray;
const deletedInboundPatternsLength = this.deletedInboundPatterns.length;
const deletedOutboundPatternsLength = this.deletedOutboundPatterns.length;
// If no inbound or outbound patterns are specified, close the modal and return
// If no inbound patterns are specified, close the modal and return
// notify the user that no patterns are specified
if (
(notifyServiceOutboundPatterns.length === deletedOutboundPatternsLength ) ||
(notifyServiceInboundPatterns.length === deletedInboundPatternsLength)) {
if (notifyServiceInboundPatterns.length === deletedInboundPatternsLength) {
this.notificationService.warning(this.translateService.get('ldn-service-notification.created.warning.title'));
this.deletedOutboundPatterns = [];
this.deletedInboundPatterns = [];
this.closeModal();
return;
@@ -522,27 +448,6 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
}
}
/**
* Marks the specified outbound pattern for deletion
* @param index - The index of the outbound pattern in the array
*/
markForOutboundPatternDeletion(index: number) {
if (!this.markedForDeletionOutboundPattern.includes(index)) {
this.markedForDeletionOutboundPattern.push(index);
}
}
/**
* Unmarks the specified outbound pattern for deletion
* @param index - The index of the outbound pattern in the array
*/
unmarkForOutboundPatternDeletion(index: number) {
const i = this.markedForDeletionOutboundPattern.indexOf(index);
if (i !== -1) {
this.markedForDeletionOutboundPattern.splice(i, 1);
}
}
/**
* Deletes marked inbound patterns from the form model
*/
@@ -565,29 +470,6 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
this.markedForDeletionInboundPattern = [];
}
/**
* Deletes marked outbound patterns from the form model
*/
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 = [];
}
/**
* Creates a replace operation and adds it to the patch operations if the form control is dirty
* @param patchOperations - The array to store patch operations
@@ -645,25 +527,6 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
this.router.navigateByUrl('admin/ldn/services');
}
/**
* Creates a form group for outbound patterns
* @returns The form group for outbound patterns
*/
private createOutboundPatternFormGroup(): FormGroup {
const outBoundFormGroup = {
pattern: '',
patternLabel: this.translateService.instant(this.selectPatternDefaultLabeli18Key),
constraint: '',
isNew: true
};
if (this.isNewService) {
delete outBoundFormGroup.isNew;
}
return this.formBuilder.group(outBoundFormGroup);
}
/**
* Creates a form group for inbound patterns
* @returns The form group for inbound patterns
@@ -684,18 +547,6 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
return this.formBuilder.group(inBoundFormGroup);
}
/**
* Initializes an existing form group for outbound patterns
* @returns The initialized form group for outbound patterns
*/
private initializeOutboundPatternFormGroup(): FormGroup {
return this.formBuilder.group({
pattern: '',
patternLabel: '',
constraint: '',
});
}
/**
* Initializes an existing form group for inbound patterns
* @returns The initialized form group for inbound patterns

View File

@@ -26,13 +26,6 @@ export const mockLdnService: LdnService = {
automatic: 'true',
},
],
notifyServiceOutboundPatterns: [
{
pattern: 'patternC',
constraint: 'itemFilterC',
automatic: 'true',
},
],
type: LDN_SERVICE,
_links: {
self: {
@@ -68,13 +61,6 @@ export const mockLdnServices: LdnService[] = [{
automatic: 'true',
},
],
notifyServiceOutboundPatterns: [
{
pattern: 'patternC',
constraint: 'itemFilterC',
automatic: 'true',
},
],
type: LDN_SERVICE,
_links: {
self: {
@@ -105,13 +91,6 @@ export const mockLdnServices: LdnService[] = [{
automatic: 'true',
},
],
notifyServiceOutboundPatterns: [
{
pattern: 'patternC',
constraint: 'itemFilterC',
automatic: 'true',
},
],
type: LDN_SERVICE,
_links: {
self: {

View File

@@ -44,9 +44,6 @@ export class LdnService extends CacheableObject {
@autoserialize
notifyServiceInboundPatterns?: NotifyServicePattern[];
@autoserialize
notifyServiceOutboundPatterns?: NotifyServicePattern[];
@deserialize
_links: {
self: {

View File

@@ -1002,8 +1002,6 @@
"ldn-new-service.form.error.score": "Please enter a valid score (between 0 and 1). Use the “.” as decimal separator",
"ldn-new-service.form.label.inboundPattern": "Inbound Pattern",
"ldn-new-service.form.label.outboundPattern": "Outbound Patterns",
"ldn-new-service.form.label.placeholder.outboundPattern": "Select an Outbound Pattern",
"ldn-new-service.form.label.addPattern": "+ Add more",
"ldn-new-service.form.label.removeItemFilter": "Remove",
"ldn-register-new-service.breadcrumbs": "New Service",
@@ -1023,7 +1021,7 @@
"ldn-service-notification.created.success.body": "The service has been created",
"ldn-service-notification.created.failure.title": "Failed Create",
"ldn-service-notification.created.failure.body": "The service has not been created",
"ldn-service-notification.created.warning.title": "Please select at least one Inbound Pattern and one Outbound Pattern",
"ldn-service-notification.created.warning.title": "Please select at least one Inbound Pattern",
"ldn-enable-service.notification.success.title": "Successful status updated",
"ldn-enable-service.notification.success.content": "The service status has been updated",
"ldn-service-delete.notification.success.title": "Successful Deletion",
@@ -1043,9 +1041,6 @@
"ldn-edit-service.form.label.selectItemFilter": "No Item Filter",
"ldn-edit-service.form.label.automatic": "Automatic",
"ldn-edit-service.form.label.addInboundPattern": "+ Add more",
"ldn-edit-service.form.label.outboundPattern": "Outbound Pattern",
"ldn-edit-service.form.label.noOutboundPatternSelected": "No Outbound Pattern",
"ldn-edit-service.form.label.addOutboundPattern": "+ Add more",
"ldn-edit-service.form.label.submit": "Save",
"ldn-edit-service.breadcrumbs": "Edit Service",
"ldn-service.control-constaint-select-none": "Select none",