Skip to content

Commit

Permalink
update domain annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
kbeyro committed Mar 12, 2024
1 parent fcdacb8 commit 4cbc696
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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">
Expand All @@ -51,17 +52,49 @@

<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>


</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>
Original file line number Diff line number Diff line change
Expand Up @@ -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([]);

Expand All @@ -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) {

Expand All @@ -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();
})
}

Expand All @@ -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)
Expand Down Expand Up @@ -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();
}

Expand All @@ -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() {
Expand All @@ -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)
}
}

0 comments on commit 4cbc696

Please sign in to comment.