1
0

CST-12455 Edit page logic is working now finishing up the styling for the page

This commit is contained in:
Mattia Vianelli
2023-11-15 12:48:53 +01:00
parent 35c45850e7
commit 778a06724b
2 changed files with 483 additions and 459 deletions

View File

@@ -108,7 +108,8 @@
class="small-text">{{ selectedInboundPatterns ? ('ldn-service.form.pattern.' + selectedInboundPatterns + '.description' | translate) : ('' | translate) }}</div> class="small-text">{{ selectedInboundPatterns ? ('ldn-service.form.pattern.' + selectedInboundPatterns + '.description' | translate) : ('' | translate) }}</div>
<!-- TODO: infinite scroll with 3 selects --> <!-- TODO: infinite scroll with 3 selects -->
<div aria-labelledby="inboundPatternDropdownButton" ngbDropdownMenu> <div aria-labelledby="inboundPatternDropdownButton" ngbDropdownMenu>
<button (click)="selectInboundPattern(pattern, i); $event.stopPropagation()" *ngFor="let pattern of inboundPatterns; let internalIndex = index" <button (click)="selectInboundPattern(pattern, i); $event.stopPropagation()"
*ngFor="let pattern of inboundPatterns; let internalIndex = index"
ngbDropdownItem ngbDropdownItem
type="button"> type="button">
<div>{{ 'ldn-service.form.pattern.' + pattern + '.label' | translate }}</div> <div>{{ 'ldn-service.form.pattern.' + pattern + '.label' | translate }}</div>
@@ -121,7 +122,7 @@
</div> </div>
<div class="col"> <div class="col">
<ng-container *ngIf="getInboundPatternControlNames(i)"> <ng-container *ngIf="!!(formModel.get('notifyServiceInboundPatterns')['controls'][i].value.pattern)">
<div #inboundItemfilterDropdown="ngbDropdown" class="w-100" id="constraint{{i}}" ngbDropdown> <div #inboundItemfilterDropdown="ngbDropdown" class="w-100" id="constraint{{i}}" ngbDropdown>
<div class="position-relative right-addon" role="combobox"> <div class="position-relative right-addon" role="combobox">
<i aria-hidden="true" class="position-absolute scrollable-dropdown-toggle" <i aria-hidden="true" class="position-absolute scrollable-dropdown-toggle"
@@ -142,7 +143,8 @@
class="small-text">{{ selectedInboundItemfilters ? ('ldn-service.form.pattern.' + selectedInboundItemfilters + '.description' | translate) : ('' | translate) }}</div> class="small-text">{{ selectedInboundItemfilters ? ('ldn-service.form.pattern.' + selectedInboundItemfilters + '.description' | translate) : ('' | translate) }}</div>
<!-- TODO: infinite scroll with 3 selects --> <!-- TODO: infinite scroll with 3 selects -->
<div aria-labelledby="inboundItemfilterDropdownButton" ngbDropdownMenu> <div aria-labelledby="inboundItemfilterDropdownButton" ngbDropdownMenu>
<button (click)="selectInboundItemFilter(constraint.id, i); $event.stopPropagation()" *ngFor="let constraint of (itemfiltersRD$ | async)?.payload?.page; let internalIndex = index" <button (click)="selectInboundItemFilter(constraint.id, i); $event.stopPropagation()"
*ngFor="let constraint of (itemfiltersRD$ | async)?.payload?.page; let internalIndex = index"
ngbDropdownItem ngbDropdownItem
type="button"> type="button">
<div>{{ constraint.id }}</div> <div>{{ constraint.id }}</div>
@@ -154,7 +156,7 @@
</div> </div>
<div <div
[style.visibility]="formModel.get('notifyServiceInboundPatterns')['controls'][i].value ? 'visible' : 'hidden'" [style.visibility]="formModel.get('notifyServiceInboundPatterns')['controls'][i].value.pattern ? 'visible' : 'hidden'"
class="col-sm-1"> class="col-sm-1">
<input formControlName="automatic" hidden id="automatic{{i}}" name="automatic{{i}}" <input formControlName="automatic" hidden id="automatic{{i}}" name="automatic{{i}}"
type="checkbox"> type="checkbox">
@@ -236,7 +238,8 @@
class="small-text">{{ selectedOutboundPatterns ? ('ldn-service.form.pattern.' + selectedOutboundPatterns + '.description' | translate) : ('' | translate) }}</div> class="small-text">{{ selectedOutboundPatterns ? ('ldn-service.form.pattern.' + selectedOutboundPatterns + '.description' | translate) : ('' | translate) }}</div>
<!-- TODO: infinite scroll with 3-5 selects --> <!-- TODO: infinite scroll with 3-5 selects -->
<div aria-labelledby="outboundPatternDropdownButton" ngbDropdownMenu> <div aria-labelledby="outboundPatternDropdownButton" ngbDropdownMenu>
<button (click)="selectOutboundPattern(pattern, i); $event.stopPropagation()" *ngFor="let pattern of outboundPatterns; let internalIndex = index" <button (click)="selectOutboundPattern(pattern, i); $event.stopPropagation()"
*ngFor="let pattern of outboundPatterns; let internalIndex = index"
ngbDropdownItem ngbDropdownItem
type="button"> type="button">
<div>{{ 'ldn-service.form.pattern.' + pattern + '.label' | translate }}</div> <div>{{ 'ldn-service.form.pattern.' + pattern + '.label' | translate }}</div>
@@ -247,14 +250,37 @@
</div> </div>
</div> </div>
</div> </div>
<!-- Main label TODO: update itemfilter dropdown -->
<div class="col"> <div class="col">
<ng-container *ngIf="getOutboundPatternControlNames(i)"> <ng-container *ngIf="!!(formModel.get('notifyServiceOutboundPatterns')['controls'][i].value.pattern)">
<select formControlName="constraint" id="constraint{{i}}" name="constraint{{i}}"> <div #outboundItemfilterDropdown="ngbDropdown" class="w-100" id="constraint{{i}}" ngbDropdown>
<option value="">{{ 'ldn-new-service.form.label.placeholder.selectedItemFilter' | translate }}</option> <div class="position-relative right-addon" role="combobox">
<option *ngFor="let itemFilter of (itemfiltersRD$ | async)?.payload?.page" <i aria-hidden="true" class="position-absolute scrollable-dropdown-toggle"
[value]="itemFilter.id">{{ itemFilter.id }}</option> ngbDropdownToggle></i>
</select> <input
(click)="outboundItemfilterDropdown.open();"
[readonly]="true"
[value]="selectedOutboundItemfilters"
class="form-control w-100 scrollable-dropdown-input"
formControlName="constraint"
id="outboundItemfilterDropdown"
ngbDropdownAnchor
type="text"
/>
<div>{{ selectedOutboundItemfilters ? ('ldn-service.form.pattern.' + selectedOutboundItemfilters + '.label' | translate) : ('ldn-new-service.form.label.placeholder.outboundPattern' | translate) }}</div>
<div
class="small-text">{{ selectedOutboundItemfilters ? ('ldn-service.form.pattern.' + selectedOutboundItemfilters + '.description' | translate) : ('' | translate) }}</div>
<!-- TODO: infinite scroll with 3 selects -->
<div aria-labelledby="outboundItemfilterDropdownButton" ngbDropdownMenu>
<button (click)="selectOutboundItemFilter(constraint.id, i); $event.stopPropagation()"
*ngFor="let constraint of (itemfiltersRD$ | async)?.payload?.page; let internalIndex = index"
ngbDropdownItem
type="button">
<div>{{ constraint.id }}</div>
</button>
</div>
</div>
</div>
</ng-container> </ng-container>
</div> </div>

View File

@@ -1,491 +1,489 @@
import { ChangeDetectorRef, Component, Input, OnInit, TemplateRef, ViewChild } from '@angular/core'; import {ChangeDetectorRef, Component, Input, OnInit, TemplateRef, ViewChild} from '@angular/core';
import {AbstractControl, FormArray, FormBuilder, FormGroup, Validators} from '@angular/forms'; import {FormArray, FormBuilder, FormGroup, Validators} from '@angular/forms';
import { LDN_SERVICE } from '../ldn-services-model/ldn-service.resource-type'; import {LDN_SERVICE} from '../ldn-services-model/ldn-service.resource-type';
import { ActivatedRoute, Router } from '@angular/router'; import {ActivatedRoute, Router} from '@angular/router';
import { LdnServicesService } from '../ldn-services-data/ldn-services-data.service'; import {LdnServicesService} from '../ldn-services-data/ldn-services-data.service';
import { notifyPatterns } from '../ldn-services-patterns/ldn-service-coar-patterns'; import {notifyPatterns} from '../ldn-services-patterns/ldn-service-coar-patterns';
import { animate, state, style, transition, trigger } from '@angular/animations'; import {animate, state, style, transition, trigger} from '@angular/animations';
import {NgbDropdownConfig, NgbModal} from '@ng-bootstrap/ng-bootstrap'; import {NgbModal} from '@ng-bootstrap/ng-bootstrap';
import { NotificationsService } from '../../../shared/notifications/notifications.service'; import {NotificationsService} from '../../../shared/notifications/notifications.service';
import { TranslateService } from '@ngx-translate/core'; import {TranslateService} from '@ngx-translate/core';
import { LdnService } from '../ldn-services-model/ldn-services.model'; import {LdnService} from '../ldn-services-model/ldn-services.model';
import { RemoteData } from 'src/app/core/data/remote-data'; import {RemoteData} from 'src/app/core/data/remote-data';
import { Operation } from 'fast-json-patch'; import {Operation} from 'fast-json-patch';
import { getFirstCompletedRemoteData } from '../../../core/shared/operators'; import {getFirstCompletedRemoteData} from '../../../core/shared/operators';
import { LdnItemfiltersService } from '../ldn-services-data/ldn-itemfilters-data.service'; import {LdnItemfiltersService} from '../ldn-services-data/ldn-itemfilters-data.service';
import { Itemfilter } from '../ldn-services-model/ldn-service-itemfilters'; import {Itemfilter} from '../ldn-services-model/ldn-service-itemfilters';
import { PaginatedList } from '../../../core/data/paginated-list.model'; import {PaginatedList} from '../../../core/data/paginated-list.model';
import { Observable } from 'rxjs'; import {Observable} from 'rxjs';
import { PaginationService } from '../../../core/pagination/pagination.service'; import {PaginationService} from '../../../core/pagination/pagination.service';
import { FindListOptions } from '../../../core/data/find-list-options.model'; import {FindListOptions} from '../../../core/data/find-list-options.model';
import { PaginationComponentOptions } from '../../../shared/pagination/pagination-component-options.model'; import {PaginationComponentOptions} from '../../../shared/pagination/pagination-component-options.model';
import {pattern} from "isbot";
@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(), {
id: 'po',
pageSize: 20
});
@Input() public name: string;
@Input() public description: string;
@Input() public url: string;
@Input() public ldnUrl: string;
@Input() public inboundPattern: string;
@Input() public outboundPattern: string;
@Input() public constraint: string;
@Input() public automatic: boolean;
@Input() public headerKey: string;
markedForDeletionInboundPattern: number[] = [];
markedForDeletionOutboundPattern: number[] = [];
selectedOutboundPatterns: string[];
selectedInboundItemfilters: string[];
selectedOutboundItemfilters: string[];
selectedInboundPatterns: string[];
protected serviceId: string;
private deletedInboundPatterns: number[] = [];
private deletedOutboundPatterns: number[] = [];
private modalRef: any;
private service: LdnService;
constructor(
protected ldnServicesService: LdnServicesService,
private ldnItemfiltersService: LdnItemfiltersService,
private formBuilder: FormBuilder,
private router: Router,
private route: ActivatedRoute,
private cdRef: ChangeDetectorRef,
protected modalService: NgbModal,
private notificationService: NotificationsService,
private translateService: TranslateService,
protected paginationService: PaginationService
) {
this.formModel = this.formBuilder.group({
id: [''],
name: ['', Validators.required],
description: ['', Validators.required],
url: ['', Validators.required],
ldnUrl: ['', Validators.required],
inboundPattern: [''],
outboundPattern: [''],
constraintPattern: [''],
enabled: [''],
notifyServiceInboundPatterns: this.formBuilder.array([this.createInboundPatternFormGroup()]),
notifyServiceOutboundPatterns: this.formBuilder.array([this.createOutboundPatternFormGroup()]),
type: LDN_SERVICE.value,
}); });
pageConfig: PaginationComponentOptions = Object.assign(new PaginationComponentOptions(), { }
id: 'po',
pageSize: 20
});
@Input() public name: string;
@Input() public description: string;
@Input() public url: string;
@Input() public ldnUrl: string;
@Input() public inboundPattern: string;
@Input() public outboundPattern: string;
@Input() public constraint: string;
@Input() public automatic: boolean;
@Input() public headerKey: string;
markedForDeletionInboundPattern: number[] = [];
markedForDeletionOutboundPattern: number[] = [];
protected serviceId: string;
private originalInboundPatterns: any[] = [];
private originalOutboundPatterns: any[] = [];
private deletedInboundPatterns: number[] = [];
private deletedOutboundPatterns: number[] = [];
private modalRef: any;
private service: LdnService;
selectedOutboundPatterns: string[];
selectedInboundItemfilters: any;
selectedInboundPatterns: string[];
constructor( ngOnInit(): void {
protected ldnServicesService: LdnServicesService, console.log((this.formModel.get('notifyServiceOutboundPatterns') as FormArray))
private ldnItemfiltersService: LdnItemfiltersService,
private formBuilder: FormBuilder,
private router: Router,
private route: ActivatedRoute,
private cdRef: ChangeDetectorRef,
protected modalService: NgbModal,
private notificationService: NotificationsService,
private translateService: TranslateService,
protected paginationService: PaginationService
) {
this.formModel = this.formBuilder.group({
id: [''],
name: ['', Validators.required],
description: ['', Validators.required],
url: ['', Validators.required],
ldnUrl: ['', Validators.required],
inboundPattern: [''],
outboundPattern: [''],
constraintPattern: [''],
enabled: [''],
notifyServiceInboundPatterns: this.formBuilder.array([this.createInboundPatternFormGroup()]),
notifyServiceOutboundPatterns: this.formBuilder.array([this.createOutboundPatternFormGroup()]),
type: LDN_SERVICE.value,
});
}
ngOnInit(): void {
console.log((this.formModel.get('notifyServiceOutboundPatterns') as FormArray))
console.log((this.formModel.get('notifyServiceInboundPatterns') as FormArray))
this.route.params.subscribe((params) => {
this.serviceId = params.serviceId;
if (this.serviceId) {
this.fetchServiceData(this.serviceId);
}
});
this.setItemfilters();
}
setItemfilters() {
this.itemfiltersRD$ = this.ldnItemfiltersService.findAll().pipe(
getFirstCompletedRemoteData());
}
fetchServiceData(serviceId: string): void {
this.ldnServicesService.findById(serviceId).pipe(
getFirstCompletedRemoteData()
).subscribe(
(data: RemoteData<LdnService>) => {
if (data.hasSucceeded) {
this.service = data.payload;
this.formModel.patchValue({
id: this.service.id,
name: this.service.name,
description: this.service.description,
url: this.service.url,
ldnUrl: this.service.ldnUrl,
type: this.service.type,
enabled: this.service.enabled
});
const inboundPatternsArray = this.formModel.get('notifyServiceInboundPatterns') as FormArray;
inboundPatternsArray.clear();
this.service.notifyServiceInboundPatterns.forEach((pattern: any) => {
const patternFormGroup = this.initializeInboundPatternFormGroup();
patternFormGroup.patchValue(pattern);
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();
});
this.originalInboundPatterns = [...this.service.notifyServiceInboundPatterns];
this.originalOutboundPatterns = [...this.service.notifyServiceOutboundPatterns];
}
},
);
}
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.handlePatterns(patchOperations, 'notifyServiceInboundPatterns');
this.handlePatterns(patchOperations, 'notifyServiceOutboundPatterns');
this.deletedInboundPatterns.forEach(index => {
const removeOperation: Operation = {
op: 'remove',
path: `notifyServiceInboundPatterns[${index}]`
};
patchOperations.push(removeOperation);
});
this.deletedOutboundPatterns.forEach(index => {
const removeOperation: Operation = {
op: 'remove',
path: `notifyServiceOutboundPatterns[${index}]`
};
patchOperations.push(removeOperation);
});
return patchOperations;
}
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 {
// this.selectedOutboundPatterns = patternValue;
const patternArray = (this.formModel.get('notifyServiceOutboundPatterns') as FormArray)
console.log((this.formModel.get('notifyServiceOutboundPatterns') as FormArray))
patternArray.controls[index].patchValue({pattern: patternValue} )
//console.log(patternArray);
//this.getPatternControlNames(index)
}
selectInboundItemFilter(filterValue: string, index: number): void {
// this.selectedOutboundPatterns = patternValue;
const filterArray = (this.formModel.get('notifyServiceInboundPatterns') as FormArray)
console.log((this.formModel.get('notifyServiceInboundPatterns') as FormArray)) console.log((this.formModel.get('notifyServiceInboundPatterns') as FormArray))
filterArray.controls[index].patchValue({constraint: filterValue} ) this.route.params.subscribe((params) => {
this.serviceId = params.serviceId;
if (this.serviceId) {
this.fetchServiceData(this.serviceId);
}
});
this.setItemfilters();
}
setItemfilters() {
this.itemfiltersRD$ = this.ldnItemfiltersService.findAll().pipe(
getFirstCompletedRemoteData());
}
fetchServiceData(serviceId: string): void {
this.ldnServicesService.findById(serviceId).pipe(
getFirstCompletedRemoteData()
).subscribe(
(data: RemoteData<LdnService>) => {
if (data.hasSucceeded) {
this.service = data.payload;
this.formModel.patchValue({
id: this.service.id,
name: this.service.name,
description: this.service.description,
url: this.service.url,
ldnUrl: this.service.ldnUrl,
type: this.service.type,
enabled: this.service.enabled
});
const inboundPatternsArray = this.formModel.get('notifyServiceInboundPatterns') as FormArray;
inboundPatternsArray.clear();
this.service.notifyServiceInboundPatterns.forEach((pattern: any) => {
const patternFormGroup = this.initializeInboundPatternFormGroup();
patternFormGroup.patchValue(pattern);
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();
});
}
},
);
}
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.handlePatterns(patchOperations, 'notifyServiceInboundPatterns');
this.handlePatterns(patchOperations, 'notifyServiceOutboundPatterns');
this.deletedInboundPatterns.forEach(index => {
const removeOperation: Operation = {
op: 'remove',
path: `notifyServiceInboundPatterns[${index}]`
};
patchOperations.push(removeOperation);
});
this.deletedOutboundPatterns.forEach(index => {
const removeOperation: Operation = {
op: 'remove',
path: `notifyServiceOutboundPatterns[${index}]`
};
patchOperations.push(removeOperation);
});
return patchOperations;
}
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 {
// this.selectedOutboundPatterns = patternValue;
const patternArray = (this.formModel.get('notifyServiceOutboundPatterns') as FormArray)
console.log((this.formModel.get('notifyServiceOutboundPatterns') as FormArray))
patternArray.controls[index].patchValue({pattern: patternValue})
//console.log(patternArray); //console.log(patternArray);
//this.getPatternControlNames(index) //this.getPatternControlNames(index)
} }
selectInboundPattern(patternValue: string, index: number): void { selectOutboundItemFilter(filterValue: string, index: number) {
// this.selectedOutboundPatterns = patternValue; const filterArray = (this.formModel.get('notifyServiceOutboundPatterns') as FormArray)
const patternArray = (this.formModel.get('notifyServiceInboundPatterns') as FormArray) console.log((this.formModel.get('notifyServiceOutboundPatterns') as FormArray))
console.log((this.formModel.get('notifyServiceInboundPatterns') as FormArray)) filterArray.controls[index].patchValue({constraint: filterValue})
patternArray.controls[index].patchValue({pattern: patternValue} ) }
//console.log(patternArray); selectInboundPattern(patternValue: string, index: number): void {
//this.getPatternControlNames(index) // this.selectedOutboundPatterns = patternValue;
const patternArray = (this.formModel.get('notifyServiceInboundPatterns') as FormArray)
console.log((this.formModel.get('notifyServiceInboundPatterns') as FormArray))
patternArray.controls[index].patchValue({pattern: patternValue})
//console.log(patternArray);
//this.getPatternControlNames(index)
}
selectInboundItemFilter(filterValue: string, index: number): void {
// this.selectedOutboundPatterns = patternValue;
const filterArray = (this.formModel.get('notifyServiceInboundPatterns') as FormArray)
console.log((this.formModel.get('notifyServiceInboundPatterns') as FormArray))
filterArray.controls[index].patchValue({constraint: filterValue})
//console.log(patternArray);
//this.getPatternControlNames(index)
}
getOutboundPatternControlNames(index: number) {
const patternArrayValue = (this.formModel.get('notifyServiceOutboundPatterns') as FormArray).controls[index]?.value
console.log(patternArrayValue)
return patternArrayValue
}
getInboundPatternControlNames(index: number) {
const patternArrayValue = (this.formModel.get('notifyServiceInboundPatterns') as FormArray).controls[index]?.value
console.log(patternArrayValue)
return patternArrayValue
}
//TODO: make a method that checks if user selected one value for the
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,
};
getOutboundPatternControlNames(index: number) { this.ldnServicesService.patch(this.service, [patchOperation]).pipe(
const patternArrayValue = (this.formModel.get('notifyServiceOutboundPatterns') as FormArray).controls[index]?.value getFirstCompletedRemoteData()
console.log(patternArrayValue) ).subscribe(
return patternArrayValue () => {
}
getInboundPatternControlNames(index: number) { this.formModel.get('enabled').setValue(newStatus);
const patternArrayValue = (this.formModel.get('notifyServiceInboundPatterns') as FormArray).controls[index]?.value
console.log(patternArrayValue)
return patternArrayValue
}
//TODO: make a method that checks if user selected one value for the
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(); 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( closeModal() {
getFirstCompletedRemoteData() this.modalRef.close();
).subscribe( this.cdRef.detectChanges();
() => { }
this.closeModal(); openConfirmModal(content) {
this.sendBack(); this.modalRef = this.modalService.open(content);
this.notificationService.success(this.translateService.get('admin.registries.services-formats.modify.success.head'), }
this.translateService.get('admin.registries.services-formats.modify.success.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(
() => {
resetFormAndLeave() {
this.sendBack();
this.closeModal(); 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'));
}
);
markForInboundPatternDeletion(index: number) { }
if (!this.markedForDeletionInboundPattern.includes(index)) {
this.markedForDeletionInboundPattern.push(index); 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);
} }
}
} }
unmarkForInboundPatternDeletion(index: number) { this.markedForDeletionInboundPattern = [];
const i = this.markedForDeletionInboundPattern.indexOf(index); }
if (i !== -1) {
this.markedForDeletionInboundPattern.splice(i, 1);
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);
} }
}
} }
markForOutboundPatternDeletion(index: number) { this.markedForDeletionOutboundPattern = [];
if (!this.markedForDeletionOutboundPattern.includes(index)) { }
this.markedForDeletionOutboundPattern.push(index);
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;
debugger
if (patternGroup.touched) {
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);
} }
}
} }
}
unmarkForOutboundPatternDeletion(index: number) { private sendBack() {
const i = this.markedForDeletionOutboundPattern.indexOf(index); this.router.navigateByUrl('admin/ldn/services');
if (i !== -1) { }
this.markedForDeletionOutboundPattern.splice(i, 1);
}
}
deleteMarkedInboundPatterns() { private createOutboundPatternFormGroup(): FormGroup {
this.markedForDeletionInboundPattern.sort((a, b) => b - a); return this.formBuilder.group({
const patternsArray = this.formModel.get('notifyServiceInboundPatterns') as FormArray; pattern: '',
constraint: '',
isNew: true,
});
}
for (const index of this.markedForDeletionInboundPattern) { private createInboundPatternFormGroup(): FormGroup {
if (index >= 0 && index < patternsArray.length) { return this.formBuilder.group({
const patternGroup = patternsArray.at(index) as FormGroup; pattern: '',
const patternValue = patternGroup.value; constraint: '',
if (patternValue.isNew) { automatic: false,
patternsArray.removeAt(index); isNew: true
} else { });
this.deletedInboundPatterns.push(index); }
}
}
}
this.markedForDeletionInboundPattern = []; private initializeOutboundPatternFormGroup(): FormGroup {
} return this.formBuilder.group({
pattern: '',
constraint: '',
});
}
private initializeInboundPatternFormGroup(): FormGroup {
return this.formBuilder.group({
pattern: '',
constraint: '',
automatic: '',
});
}
deleteMarkedOutboundPatterns() { //setValueForControlInOutboundArray(formArrayName: string, index: number, value: string) {
this.markedForDeletionOutboundPattern.sort((a, b) => b - a); // const formArray = this.formModel.get(formArrayName) as FormArray;
const patternsArray = this.formModel.get('notifyServiceOutboundPatterns') as FormArray; //console.warn('inside setValueForControlInOutboundArray', formArray);
//formArray.at(index).setValue(value);
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 = [];
}
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;
debugger
if (patternGroup.touched) {
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: '',
constraint: '',
isNew: true,
});
}
private createInboundPatternFormGroup(): FormGroup {
return this.formBuilder.group({
pattern: '',
constraint: '',
automatic: false,
isNew: true
});
}
private initializeOutboundPatternFormGroup(): FormGroup {
return this.formBuilder.group({
pattern: '',
constraint: '',
});
}
private initializeInboundPatternFormGroup(): FormGroup {
return this.formBuilder.group({
pattern: '',
constraint: '',
automatic: '',
});
}
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);
}
//setValueForControlInOutboundArray(formArrayName: string, index: number, value: string) {
// const formArray = this.formModel.get(formArrayName) as FormArray;
//console.warn('inside setValueForControlInOutboundArray', formArray);
//formArray.at(index).setValue(value);
//}
} }