Skip to content
Snippets Groups Projects
Unverified Commit dd6737dc authored by Łukasz Łopatowski's avatar Łukasz Łopatowski Committed by GitHub
Browse files

Merge pull request #205 from...

Merge pull request #205 from nmaas-platform/149-handle-namespace-creation-during-domain-provisioning-1

update domain annotations
parents 62c4806e 18d8f579
No related branches found
No related tags found
No related merge requests found
...@@ -21,12 +21,13 @@ ...@@ -21,12 +21,13 @@
<div class="grid flex flex-grow-1 mt-4 mb-2" *ngFor="let kv of keyValue"> <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="flex grid flex-grow-1">
<div class="col-4"> <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>
<div class="col-6"> <div class="col-5">
<input pInputText type="text" (focusout)="emmitValue(kv)" [(ngModel)]="kv.value" class="flex flex-grow-1" style="width: 100%"> <input pInputText type="text" readonly="true" disabled="true" (focusout)="emmitValue(kv)" [(ngModel)]="kv.value" class="flex flex-grow-1" style="width: 100%">
</div> </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> <button type="button" class="btn btn-danger" (click)="deleteAnnotation(kv.id)">Delete</button>
</div> </div>
</div> </div>
...@@ -38,7 +39,7 @@ ...@@ -38,7 +39,7 @@
<nmaas-modal> <nmaas-modal>
<div class="nmaas-modal-header">{{'DOMAINS.ANNOTATIONS.ADD' | translate}}</div> <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="grid flex flex-grow-1">
<div class="col-4"> <div class="col-4">
...@@ -51,10 +52,11 @@ ...@@ -51,10 +52,11 @@
<div class="flex grid flex-grow-1"> <div class="flex grid flex-grow-1">
<div class="col-4"> <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>
<div class="col-6"> <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>
...@@ -62,6 +64,37 @@ ...@@ -62,6 +64,37 @@
</div> </div>
<div class="nmaas-modal-footer"> <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-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> </div>
</nmaas-modal> </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
...@@ -15,6 +15,9 @@ export class DomainNamespaceAnnotationsComponent implements OnInit { ...@@ -15,6 +15,9 @@ export class DomainNamespaceAnnotationsComponent implements OnInit {
@ViewChild(ModalComponent, {static: true}) @ViewChild(ModalComponent, {static: true})
public readonly modal: ModalComponent; public readonly modal: ModalComponent;
@ViewChild('editModal')
public readonly modalEdit: ModalComponent;
@Input() @Input()
public annotationRead: Observable<DomainAnnotation[]> = of([]); public annotationRead: Observable<DomainAnnotation[]> = of([]);
...@@ -34,9 +37,11 @@ export class DomainNamespaceAnnotationsComponent implements OnInit { ...@@ -34,9 +37,11 @@ export class DomainNamespaceAnnotationsComponent implements OnInit {
public isKeysUnique = true; public isKeysUnique = true;
public isKeyValuePresent =true; public isKeyValuePresent =true;
public isKeyPatternCorrect = true;
public newAnnotations : DomainAnnotation = new DomainAnnotation(); public newAnnotations : DomainAnnotation = new DomainAnnotation();
public reaOnlyMap = new Map<string, boolean>(); public editAnnotation : DomainAnnotation = new DomainAnnotation();
public constructor(private readonly domainService: DomainService) { public constructor(private readonly domainService: DomainService) {
...@@ -46,9 +51,7 @@ export class DomainNamespaceAnnotationsComponent implements OnInit { ...@@ -46,9 +51,7 @@ export class DomainNamespaceAnnotationsComponent implements OnInit {
console.warn("annotations", this.annotationRead) console.warn("annotations", this.annotationRead)
this.annotationRead.subscribe(annotation =>{ this.annotationRead.subscribe(annotation =>{
this.keyValue = annotation; this.keyValue = annotation;
annotation.forEach(ann => { this.checkDuplicate();
this.reaOnlyMap.set(ann.key,true);
})
}) })
} }
...@@ -59,10 +62,7 @@ export class DomainNamespaceAnnotationsComponent implements OnInit { ...@@ -59,10 +62,7 @@ export class DomainNamespaceAnnotationsComponent implements OnInit {
} }
if(keyValue !== null) { if(keyValue !== null) {
if(keyValue.key !== "") {
this.reaOnlyMap.set(keyValue.key, true);
}
if(this.globalSettings) { if(this.globalSettings) {
this.domainService.updateAnnotation(keyValue).subscribe(_=> { this.domainService.updateAnnotation(keyValue).subscribe(_=> {
console.warn("Updated annotation", keyValue) console.warn("Updated annotation", keyValue)
...@@ -97,6 +97,9 @@ export class DomainNamespaceAnnotationsComponent implements OnInit { ...@@ -97,6 +97,9 @@ export class DomainNamespaceAnnotationsComponent implements OnInit {
addAnnotation() { addAnnotation() {
this.newAnnotations = new DomainAnnotation(); this.newAnnotations = new DomainAnnotation();
this.newAnnotations.key =''
this.newAnnotations.value = ''
console.log(this.newAnnotations)
this.modal.show(); this.modal.show();
} }
...@@ -114,14 +117,35 @@ export class DomainNamespaceAnnotationsComponent implements OnInit { ...@@ -114,14 +117,35 @@ export class DomainNamespaceAnnotationsComponent implements OnInit {
return this.keySetNotUnique.some(val => val === key) return this.keySetNotUnique.some(val => val === key)
} }
public isKeyNotUniqueAdd(key: string) { public isKeyNotUniqueEdit(annotation: DomainAnnotation) {
return this.keyValue.some(val => val.key === key) 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) { public isKeyNotUniqueAdd(annotation: DomainAnnotation) {
if(this.reaOnlyMap.has(key)){ if(annotation.key === '' || annotation.value === '') {
return this.reaOnlyMap.get(key); return true;
} else return false; } else {
return this.keyValue.some(val => val.key === annotation.key)
}
} }
public closeModal() { public closeModal() {
...@@ -145,4 +169,36 @@ export class DomainNamespaceAnnotationsComponent implements OnInit { ...@@ -145,4 +169,36 @@ export class DomainNamespaceAnnotationsComponent implements OnInit {
this.keyValue = annotation; 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% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment