Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add domain namespace annotation editor #178

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ describe('Component: AppInstance', () => {
enabled: true,
pvStorageSizeLimit: 20
}
]
],
annotations: []
};

const appInstance: AppInstanceExtended = {
Expand Down
2 changes: 2 additions & 0 deletions src/app/appmarket/domains/domain/domain.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ <h3>{{ 'DOMAIN_DETAILS.TITLE' | translate }}</h3>
</div>
</div>

<app-domain-namespace-annotations [annotationRead]="domain.annotations"></app-domain-namespace-annotations>

<div class="panel panel-default">
<div class="panel-heading">{{ 'DOMAIN_DETAILS.APP_STATUS' | translate }}</div>
<div class="panel-body">
Expand Down
2 changes: 2 additions & 0 deletions src/app/model/domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {DomainDcnDetails} from './domaindcndetails';
import {DomainTechDetails} from './domaintechdetails';
import {DomainApplicationStatePerDomain} from './domainapplicationstateperdomain';
import {DomainGroup} from './domaingroup';
import {KeyValue} from './key-value';

export class Domain {
public id: number = undefined;
Expand All @@ -13,4 +14,5 @@ export class Domain {
public applicationStatePerDomain: DomainApplicationStatePerDomain[] = [];
public groups: DomainGroup[] = [];
public deleted: boolean;
public annotations: KeyValue[] = [];
}
4 changes: 4 additions & 0 deletions src/app/model/key-value.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export class KeyValue {
key;
value;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe('DomainFilterComponent', () => {
domainTechDetails: undefined,
applicationStatePerDomain: [],
groups: [],
annotations: [],
}

const domain1: Domain = {
Expand All @@ -38,6 +39,7 @@ describe('DomainFilterComponent', () => {
domainTechDetails: undefined,
applicationStatePerDomain: [],
groups: [],
annotations: [],
};

const domain2: Domain = {
Expand All @@ -50,6 +52,7 @@ describe('DomainFilterComponent', () => {
domainTechDetails: undefined,
applicationStatePerDomain: [],
groups: [],
annotations: [],
};

beforeEach(waitForAsync(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.border-red {
border: 1px solid red;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<div class="panel panel-default" >
<div class="panel-heading">
<div style="display: flex; justify-content: start; align-items: center">
<div>
{{"Domain namespace annotations creation"}}
</div>
</div>
</div>
<div class="panel-body">
<div style="display: flex; justify-content: end">
<button type="button" class="btn btn-success" (click)="addAnnotation()">{{"Add annotation"}}</button>
</div>
<div class="grid flex flex-grow-1">
<div class="col-4">
{{'KEY'}}
<!-- <div *ngIf="isKeysUnique === false"><em class="pi pi-exclamation-circle" style="color: red"></em></div>-->
</div>
<div class="col-6">
{{'VALUE'}}
</div>
</div>
<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()" [(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()" [(ngModel)]="kv.value" class="flex flex-grow-1" style="width: 100%">
</div>
<div class="col-2 flex justify-content-end">
<button type="button" class="btn btn-danger" (click)="deleteAnnotation(kv.key)">Delete</button>
</div>
</div>
</div>
</div>

</div>


<nmaas-modal>
<div class="nmaas-modal-header">{{'DOMAINS.LIST.GROUP' | translate}}</div>
<div class="nmaas-modal-body" style="height: 300px">

</div>
<div class="nmaas-modal-footer">

</div>
</nmaas-modal>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { DomainNamespaceAnnotationsComponent } from './domain-namespace-annotations.component';
import {TranslateFakeLoader, TranslateLoader, TranslateModule} from '@ngx-translate/core';

describe('DomainNamespaceAnnotationsComponent', () => {
let component: DomainNamespaceAnnotationsComponent;
let fixture: ComponentFixture<DomainNamespaceAnnotationsComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ DomainNamespaceAnnotationsComponent ],
imports: [
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useClass: TranslateFakeLoader
}
})
]
})
.compileComponents();

fixture = TestBed.createComponent(DomainNamespaceAnnotationsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
import {KeyValue} from '../../model/key-value';

@Component({
selector: 'app-domain-namespace-annotations',
templateUrl: './domain-namespace-annotations.component.html',
styleUrls: ['./domain-namespace-annotations.component.css']
})
export class DomainNamespaceAnnotationsComponent implements OnInit {

@Input()
public annotationRead: KeyValue[];

@Output()
public annotations: EventEmitter<KeyValue[]> = new EventEmitter<KeyValue[]>();

public keyValue: KeyValue[] = []

private keySetNotUnique: string[] = [];

public isKeysUnique = true;

constructor() {
}

ngOnInit(): void {
}

public emmitValue() {
this.checkDuplicate()
if ( this.isKeysUnique) {
this.annotations.emit(this.keyValue);
}
}

public checkDuplicate() {
const keySet = new Set<string>();
this.keyValue.forEach(kv => {
if (keySet.has(kv.key)) {
console.error("duplicated keys in annotations")
this.isKeysUnique = false;
this.keySetNotUnique.push(kv.key)
} else {
keySet.add(kv.key)
}
})
if (this.keyValue.length === keySet.size) {
this.isKeysUnique = true;
this.keySetNotUnique = [];
}
console.warn("after checking", this.isKeysUnique, keySet)
}

showModal() {

}

addAnnotation() {
this.keyValue.push(new KeyValue())
}

deleteAnnotation(key: any) {
this.keyValue = this.keyValue.filter(val => val.key !== key)
}

public isKeyNotUnique(key: string) {
return this.keySetNotUnique.some(val => val === key)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ describe('AppInstallmodalComponent', () => {
domainTechDetails: undefined,
applicationStatePerDomain: [],
groups: [],
annotations: [],
}

beforeEach(waitForAsync(() => {
Expand Down
7 changes: 5 additions & 2 deletions src/app/shared/shared.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import {TooltipModule} from 'primeng/tooltip';
import {DropdownModule} from 'primeng/dropdown';
import {SortableHeaderDirective} from '../service/sort-domain.directive';
import {InputTextModule} from 'primeng/inputtext';
import { DomainNamespaceAnnotationsComponent } from './domain-namespace-annotations/domain-namespace-annotations.component';

@NgModule({
imports: [
Expand Down Expand Up @@ -118,7 +119,8 @@ import {InputTextModule} from 'primeng/inputtext';
ModalProvideSshKeyComponent,
ContactComponent,
PreferencesComponent,
SortableHeaderDirective
SortableHeaderDirective,
DomainNamespaceAnnotationsComponent
],
providers: [
PasswordValidator,
Expand Down Expand Up @@ -168,7 +170,8 @@ import {InputTextModule} from 'primeng/inputtext';
SshKeysComponent,
ModalProvideSshKeyComponent,
PreferencesComponent,
SortableHeaderDirective
SortableHeaderDirective,
DomainNamespaceAnnotationsComponent
]
})
export class SharedModule {
Expand Down