diff --git a/src/app/shared/domain-namespace-annotations/domain-namespace-annotations.component.html b/src/app/shared/domain-namespace-annotations/domain-namespace-annotations.component.html index 8ad48c97996027bb6261d9777beec21cf2edb7e1..4f6430f6206bf1061806261ce492092e812d77cc 100644 --- a/src/app/shared/domain-namespace-annotations/domain-namespace-annotations.component.html +++ b/src/app/shared/domain-namespace-annotations/domain-namespace-annotations.component.html @@ -21,12 +21,13 @@ <div class="grid flex flex-grow-1 mt-4 mb-2" *ngFor="let kv of keyValue"> <div class="flex grid flex-grow-1"> <div class="col-4"> - <input pInputText type="text" (focusout)="emmitValue(kv)" [(ngModel)]="kv.key" class="flex flex-grow-1" style="width: 100%" [ngClass]="{ 'border-red': isKeyNotUnique(kv.key)}"> + <input pInputText type="text" readonly="true" disabled="true" (focusout)="emmitValue(kv)" [(ngModel)]="kv.key" class="flex flex-grow-1" style="width: 100%" [ngClass]="{ 'border-red': isKeyNotUnique(kv.key)}"> </div> - <div class="col-6"> - <input pInputText type="text" (focusout)="emmitValue(kv)" [(ngModel)]="kv.value" class="flex flex-grow-1" style="width: 100%"> + <div class="col-5"> + <input pInputText type="text" readonly="true" disabled="true" (focusout)="emmitValue(kv)" [(ngModel)]="kv.value" class="flex flex-grow-1" style="width: 100%"> </div> - <div class="col-2 flex justify-content-end"> + <div class="col-3 flex justify-content-end"> + <button type="button" class="btn btn-secondary mr-2" (click)="openEditModal(kv)">Edit</button> <button type="button" class="btn btn-danger" (click)="deleteAnnotation(kv.id)">Delete</button> </div> </div> @@ -38,7 +39,7 @@ <nmaas-modal> <div class="nmaas-modal-header">{{'DOMAINS.ANNOTATIONS.ADD' | translate}}</div> - <div class="nmaas-modal-body" style="height: 200px"> + <div class="nmaas-modal-body" style="height: 100px"> <div class="grid flex flex-grow-1"> <div class="col-4"> @@ -51,10 +52,11 @@ <div class="flex grid flex-grow-1"> <div class="col-4"> - <input pInputText type="text" [(ngModel)]="newAnnotations.key" class="flex flex-grow-1" style="width: 100%" [ngClass]="{ 'border-red': isKeyNotUniqueAdd(newAnnotations.key)}"> + <input pInputText type="text" (ngModelChange)="onKeyChange($event)" + [(ngModel)]="newAnnotations.key" class="flex flex-grow-1" style="width: 100%" [ngClass]="{ 'border-red': isKeyNotUniqueAdd(newAnnotations) || !isKeyPatternCorrect }"> </div> <div class="col-6"> - <input pInputText type="text" [(ngModel)]="newAnnotations.value" class="flex flex-grow-1" style="width: 100%"> + <input pInputText type="text" [(ngModel)]="newAnnotations.value" class="flex flex-grow-1" style="width: 100%" [ngClass]="{ 'border-red': newAnnotations.value === ''}"> </div> </div> @@ -62,6 +64,37 @@ </div> <div class="nmaas-modal-footer"> <button type="button" class="btn btn-default" (click)="modal.hide()">{{'APP_CHANGE_STATE_MODAL.CANCEL_BUTTON' | translate}}</button> - <button type="button" class="btn btn-primary" (click)="closeModal()" [disabled]="isKeyNotUniqueAdd(newAnnotations.key)">{{'SHARED.ADD' | translate}}</button> + <button type="button" class="btn btn-primary" (click)="closeModal()" [disabled]="isKeyNotUniqueAdd(newAnnotations) || !isKeyPatternCorrect">{{'DOMAINS.ADD_BUTTON' | translate}}</button> </div> </nmaas-modal> + + +<nmaas-modal #editModal> + <div class="nmaas-modal-header">{{'DOMAINS.ANNOTATIONS.EDIT' | translate}}</div> + <div class="nmaas-modal-body" style="height: 100px"> + + <div class="grid flex flex-grow-1"> + <div class="col-4"> + {{'DOMAINS.ANNOTATIONS.KEY' | translate}} + </div> + <div class="col-6"> + {{'DOMAINS.ANNOTATIONS.VALUE' | translate}} + </div> + </div> + + <div class="flex grid flex-grow-1"> + <div class="col-4"> + <input pInputText type="text" (ngModelChange)="onKeyChange($event)" [(ngModel)]="editAnnotation.key" class="flex flex-grow-1" style="width: 100%" [ngClass]="{ 'border-red': isKeyNotUniqueEdit(editAnnotation) || !isKeyPatternCorrect}"> + </div> + <div class="col-6"> + <input pInputText type="text" [(ngModel)]="editAnnotation.value" class="flex flex-grow-1" style="width: 100%"> + </div> + </div> + + + </div> + <div class="nmaas-modal-footer"> + <button type="button" class="btn btn-default" (click)="editModal.hide()">{{'APP_CHANGE_STATE_MODAL.CANCEL_BUTTON' | translate}}</button> + <button type="button" class="btn btn-primary" (click)="closeModalEdit()" [disabled]="isEditAnnotationCorrect(editAnnotation) || !isKeyPatternCorrect">{{'DOMAINS.EDIT_BUTTON' | translate}}</button> + </div> +</nmaas-modal> \ No newline at end of file diff --git a/src/app/shared/domain-namespace-annotations/domain-namespace-annotations.component.ts b/src/app/shared/domain-namespace-annotations/domain-namespace-annotations.component.ts index a6f4ae407c00f1ac4692ab7151a82be572b22ff0..a1b193206f25e2102c99e810a229be2a08b4840a 100644 --- a/src/app/shared/domain-namespace-annotations/domain-namespace-annotations.component.ts +++ b/src/app/shared/domain-namespace-annotations/domain-namespace-annotations.component.ts @@ -15,6 +15,9 @@ export class DomainNamespaceAnnotationsComponent implements OnInit { @ViewChild(ModalComponent, {static: true}) public readonly modal: ModalComponent; + @ViewChild('editModal') + public readonly modalEdit: ModalComponent; + @Input() public annotationRead: Observable<DomainAnnotation[]> = of([]); @@ -34,9 +37,11 @@ export class DomainNamespaceAnnotationsComponent implements OnInit { public isKeysUnique = true; public isKeyValuePresent =true; + public isKeyPatternCorrect = true; + public newAnnotations : DomainAnnotation = new DomainAnnotation(); - public reaOnlyMap = new Map<string, boolean>(); + public editAnnotation : DomainAnnotation = new DomainAnnotation(); public constructor(private readonly domainService: DomainService) { @@ -46,9 +51,7 @@ export class DomainNamespaceAnnotationsComponent implements OnInit { console.warn("annotations", this.annotationRead) this.annotationRead.subscribe(annotation =>{ this.keyValue = annotation; - annotation.forEach(ann => { - this.reaOnlyMap.set(ann.key,true); - }) + this.checkDuplicate(); }) } @@ -59,10 +62,7 @@ export class DomainNamespaceAnnotationsComponent implements OnInit { } if(keyValue !== null) { - if(keyValue.key !== "") { - this.reaOnlyMap.set(keyValue.key, true); - } - + if(this.globalSettings) { this.domainService.updateAnnotation(keyValue).subscribe(_=> { console.warn("Updated annotation", keyValue) @@ -97,6 +97,9 @@ export class DomainNamespaceAnnotationsComponent implements OnInit { addAnnotation() { this.newAnnotations = new DomainAnnotation(); + this.newAnnotations.key ='' + this.newAnnotations.value = '' + console.log(this.newAnnotations) this.modal.show(); } @@ -114,14 +117,35 @@ export class DomainNamespaceAnnotationsComponent implements OnInit { return this.keySetNotUnique.some(val => val === key) } - public isKeyNotUniqueAdd(key: string) { - return this.keyValue.some(val => val.key === key) + public isKeyNotUniqueEdit(annotation: DomainAnnotation) { + let annotationBefore = this.keyValue.find(val => val.id === annotation.id) + if(annotation?.key === annotationBefore?.key) { + return this.keyValue.filter(val => val.key === annotation.key).length > 1 + } else { + return this.keyValue.filter(val => val.key === annotation.key).length > 0 + } + + } + + public isEditAnnotationCorrect(annotation: DomainAnnotation) { + let annotationBefore = this.keyValue.find(val => val.id === annotation.id) + if(annotation?.key === annotationBefore?.key && annotation?.value === annotationBefore?.value) { + return true; + } else { + if(annotation?.key === annotationBefore?.key) { + return this.keyValue.filter(val => val.key === annotation.key).length > 1 + } else { + return this.keyValue.filter(val => val.key === annotation.key).length > 0 + } + } } - public getReadOnlyValue(key: string) { - if(this.reaOnlyMap.has(key)){ - return this.reaOnlyMap.get(key); - } else return false; + public isKeyNotUniqueAdd(annotation: DomainAnnotation) { + if(annotation.key === '' || annotation.value === '') { + return true; + } else { + return this.keyValue.some(val => val.key === annotation.key) + } } public closeModal() { @@ -145,4 +169,36 @@ export class DomainNamespaceAnnotationsComponent implements OnInit { this.keyValue = annotation; }) } + + public openEditModal(annotation: DomainAnnotation) { + this.editAnnotation = Object.assign({}, annotation) ; + this.modalEdit.show(); + } + + public closeModalEdit() { + if(this.globalSettings) { + this.domainService.updateAnnotation(this.editAnnotation).subscribe( _ =>{ + this.editAnnotation = new DomainAnnotation(); + this.annotationRead = this.domainService.getAnnotations(); + this.triggerRefresh(); + }) + }else { + this.keyValue = this.keyValue.filter(val => val.id !== this.editAnnotation.id) + this.keyValue.push(this.editAnnotation); + this.editAnnotation = new DomainAnnotation(); + } + this.emmitValue(null) + this.modalEdit.hide(); + } + + onKeyChange(value: string) { + const pattern = /^[A-Za-z0-9_.-/]+$/; + if (!pattern.test(value)) { + // Wartość nie spełnia wzorca, więc możesz podjąć odpowiednią akcję + this.isKeyPatternCorrect = false; // Wyzerowanie wartości + } else { + this.isKeyPatternCorrect = true; + } + console.log(this.isKeyPatternCorrect) + } }