mirror of https://github.com/ctk-hq/ctk
deploy dialog component
parent
faef5050ed
commit
1d5c792ae1
@ -0,0 +1,133 @@
|
|||||||
|
<h1 mat-dialog-title><span>Deploy Config</span></h1>
|
||||||
|
<mat-dialog-content>
|
||||||
|
<mat-tab-group animationDuration="0ms">
|
||||||
|
<mat-tab label="General">
|
||||||
|
<form [formGroup]="formGeneral" fxLayout="column">
|
||||||
|
<mat-form-field appearance="outline">
|
||||||
|
<mat-label>Mode</mat-label>
|
||||||
|
<input matInput formControlName="mode" />
|
||||||
|
</mat-form-field>
|
||||||
|
|
||||||
|
<mat-form-field appearance="outline">
|
||||||
|
<mat-label>Replicas</mat-label>
|
||||||
|
<input matInput formControlName="replicas" />
|
||||||
|
</mat-form-field>
|
||||||
|
|
||||||
|
<div [formGroup]="formGeneral['controls']['update_config']" fxLayout="column" fxGrap="10px">
|
||||||
|
<h3><span>Update config</span></h3>
|
||||||
|
<mat-form-field appearance="outline">
|
||||||
|
<mat-label>Parallelism</mat-label>
|
||||||
|
<input matInput formControlName="parallelism" />
|
||||||
|
</mat-form-field>
|
||||||
|
|
||||||
|
<mat-form-field appearance="outline">
|
||||||
|
<mat-label>Delay</mat-label>
|
||||||
|
<input matInput formControlName="delay" />
|
||||||
|
</mat-form-field>
|
||||||
|
|
||||||
|
<mat-form-field appearance="outline">
|
||||||
|
<mat-label>Order</mat-label>
|
||||||
|
<input matInput formControlName="order" />
|
||||||
|
</mat-form-field>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="splitter mg-b-15"></div>
|
||||||
|
|
||||||
|
<mat-form-field appearance="outline">
|
||||||
|
<mat-label>Rollback config</mat-label>
|
||||||
|
<input matInput formControlName="rollback_config" />
|
||||||
|
</mat-form-field>
|
||||||
|
|
||||||
|
<div [formGroup]="formGeneral['controls']['restart_policy']" fxLayout="column" fxGrap="10px">
|
||||||
|
<h3><span>Restart policy</span></h3>
|
||||||
|
<mat-form-field appearance="outline">
|
||||||
|
<mat-label>Condition</mat-label>
|
||||||
|
<input matInput formControlName="condition" />
|
||||||
|
</mat-form-field>
|
||||||
|
|
||||||
|
<mat-form-field appearance="outline">
|
||||||
|
<mat-label>Delay</mat-label>
|
||||||
|
<input matInput formControlName="delay" />
|
||||||
|
</mat-form-field>
|
||||||
|
|
||||||
|
<mat-form-field appearance="outline">
|
||||||
|
<mat-label>Parallelism</mat-label>
|
||||||
|
<input matInput formControlName="parallelism" />
|
||||||
|
</mat-form-field>
|
||||||
|
|
||||||
|
<mat-form-field appearance="outline">
|
||||||
|
<mat-label>Window</mat-label>
|
||||||
|
<input matInput formControlName="window" />
|
||||||
|
</mat-form-field>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="splitter mg-b-15"></div>
|
||||||
|
|
||||||
|
<mat-form-field appearance="outline">
|
||||||
|
<mat-label>Endpoint mode</mat-label>
|
||||||
|
<input matInput formControlName="endpoint_mode" />
|
||||||
|
</mat-form-field>
|
||||||
|
|
||||||
|
<mat-form-field appearance="outline">
|
||||||
|
<mat-label>Max replicas per node</mat-label>
|
||||||
|
<input matInput formControlName="max_replicas_per_node" />
|
||||||
|
</mat-form-field>
|
||||||
|
|
||||||
|
<div [formGroup]="formGeneral['controls']['resources']['controls']['limits']" fxLayout="column" fxGrap="10px">
|
||||||
|
<h3><span>Limits</span></h3>
|
||||||
|
<mat-form-field appearance="outline">
|
||||||
|
<mat-label>Cpus</mat-label>
|
||||||
|
<input matInput formControlName="cpus" />
|
||||||
|
</mat-form-field>
|
||||||
|
|
||||||
|
<mat-form-field appearance="outline">
|
||||||
|
<mat-label>Memory</mat-label>
|
||||||
|
<input matInput formControlName="memory" />
|
||||||
|
</mat-form-field>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div [formGroup]="formGeneral['controls']['resources']['controls']['reservations']" fxLayout="column" fxGrap="10px">
|
||||||
|
<h3><span>Limits</span></h3>
|
||||||
|
<mat-form-field appearance="outline">
|
||||||
|
<mat-label>Cpus</mat-label>
|
||||||
|
<input matInput formControlName="cpus" />
|
||||||
|
</mat-form-field>
|
||||||
|
|
||||||
|
<mat-form-field appearance="outline">
|
||||||
|
<mat-label>Memory</mat-label>
|
||||||
|
<input matInput formControlName="memory" />
|
||||||
|
</mat-form-field>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</mat-tab>
|
||||||
|
<mat-tab label="Placement" [formGroup]="formGeneral">
|
||||||
|
<div fxLayout="column">
|
||||||
|
<mat-form-field fxFill appearance="outline">
|
||||||
|
<mat-label>Command</mat-label>
|
||||||
|
<textarea
|
||||||
|
matInput
|
||||||
|
cdkTextareaAutosize
|
||||||
|
#autosize="cdkTextareaAutosize"
|
||||||
|
formControlName="placement"></textarea>
|
||||||
|
</mat-form-field>
|
||||||
|
<h2 mat-dialog-title>Preferences</h2>
|
||||||
|
<key-value #preferences [keyValueArray]="currentPreferences"></key-value>
|
||||||
|
</div>
|
||||||
|
</mat-tab>
|
||||||
|
|
||||||
|
<mat-tab label="Labels">
|
||||||
|
<h2 mat-dialog-title>Labels</h2>
|
||||||
|
<key-value #labels [keyValueArray]="currentLabels"></key-value>
|
||||||
|
</mat-tab>
|
||||||
|
</mat-tab-group>
|
||||||
|
</mat-dialog-content>
|
||||||
|
|
||||||
|
<mat-dialog-actions class="dialog-actions">
|
||||||
|
<check-circle></check-circle>
|
||||||
|
<button mat-button (click)="closeModal()">
|
||||||
|
Cancel
|
||||||
|
</button>
|
||||||
|
<button mat-raised-button color="success" (click)="onSave()" [disabled]="formGeneral.invalid">
|
||||||
|
Save
|
||||||
|
</button>
|
||||||
|
</mat-dialog-actions>
|
||||||
@ -0,0 +1,25 @@
|
|||||||
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { DeployDialogComponent } from './deploy-dialog.component';
|
||||||
|
|
||||||
|
describe('DeployDialogComponent', () => {
|
||||||
|
let component: DeployDialogComponent;
|
||||||
|
let fixture: ComponentFixture<DeployDialogComponent>;
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
declarations: [ DeployDialogComponent ]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(DeployDialogComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -0,0 +1,87 @@
|
|||||||
|
import { Component, OnInit, ViewChild, Inject } from '@angular/core'
|
||||||
|
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'
|
||||||
|
import { FormControl, Validators, FormGroup, FormBuilder, AbstractControl } from '@angular/forms'
|
||||||
|
import { KeyValueComponent } from '../../common/key-value/key-value/key-value.component'
|
||||||
|
import { Service, ServiceDeploy } from '../../../store/models'
|
||||||
|
import { CheckCircleComponent } from '../../widgets/check-circle/check-circle.component'
|
||||||
|
import { Store } from '@ngrx/store'
|
||||||
|
import * as ProjectActions from './../../../store/project.actions'
|
||||||
|
import { EventEmitterService } from 'src/app/core/services/event-emitter.service'
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-deploy-dialog',
|
||||||
|
templateUrl: './deploy-dialog.component.html',
|
||||||
|
styleUrls: ['./deploy-dialog.component.scss']
|
||||||
|
})
|
||||||
|
export class DeployDialogComponent implements OnInit {
|
||||||
|
@ViewChild(CheckCircleComponent) checkCircle: CheckCircleComponent
|
||||||
|
@ViewChild('preferences') preferences: KeyValueComponent
|
||||||
|
@ViewChild('labels') labels: KeyValueComponent
|
||||||
|
|
||||||
|
formGeneral: FormGroup
|
||||||
|
currentPreferences: [] = []
|
||||||
|
currentLabels: [] = []
|
||||||
|
constructor(public dialogRef: MatDialogRef<DeployDialogComponent>, private formBuilder: FormBuilder, @Inject(MAT_DIALOG_DATA) public data: Service, private store: Store, private eventEmitterService: EventEmitterService,) { }
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
this.formGeneral = this.formBuilder.group({
|
||||||
|
mode: new FormControl(''),
|
||||||
|
replicas: new FormControl(''),
|
||||||
|
update_config: this.formBuilder.group({
|
||||||
|
parallelism: new FormControl('', [Validators.pattern('^[0-9]+$')]),
|
||||||
|
delay: new FormControl(''),
|
||||||
|
order: new FormControl('')
|
||||||
|
}),
|
||||||
|
rollback_config: new FormControl(''),
|
||||||
|
restart_policy: this.formBuilder.group({
|
||||||
|
condition: new FormControl(''),
|
||||||
|
delay: new FormControl(''),
|
||||||
|
parallelism: new FormControl('', [Validators.pattern('^[0-9]+$')]),
|
||||||
|
window: new FormControl(''),
|
||||||
|
}),
|
||||||
|
endpoint_mode: new FormControl(''),
|
||||||
|
placement: new FormControl(''),
|
||||||
|
max_replicas_per_node: new FormControl('', [Validators.pattern('^[0-9]+$')]),
|
||||||
|
resources: this.formBuilder.group({
|
||||||
|
limits: this.formBuilder.group({
|
||||||
|
cpus: new FormControl(''),
|
||||||
|
memory: new FormControl('')
|
||||||
|
}),
|
||||||
|
reservations: this.formBuilder.group({
|
||||||
|
cpus: new FormControl(''),
|
||||||
|
memory: new FormControl('')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
if(this.data.deploy) {
|
||||||
|
this.data.deploy.labels.forEach(val => this.currentLabels.push(val))
|
||||||
|
this.data.deploy.placement.preferences.forEach(val => this.currentPreferences.push(val))
|
||||||
|
|
||||||
|
this.formGeneral.patchValue({
|
||||||
|
...this.data.deploy,
|
||||||
|
placement: this.data.deploy.placement.constraints.join(',')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onSave(): void {
|
||||||
|
const fields: ServiceDeploy = {
|
||||||
|
...this.formGeneral.getRawValue(),
|
||||||
|
placement: {
|
||||||
|
constraints: this.formGeneral.get('placement').value.split(','),
|
||||||
|
preferences: this.preferences.getKeyValuePaies()
|
||||||
|
},
|
||||||
|
labels: this.labels.getKeyValuePaies(),
|
||||||
|
}
|
||||||
|
|
||||||
|
this.store.dispatch(ProjectActions.UpdateService({data: {...this.data, deploy: fields}}))
|
||||||
|
this.checkCircle.showCircle()
|
||||||
|
this.eventEmitterService.broadcast('save:project', {})
|
||||||
|
}
|
||||||
|
|
||||||
|
closeModal(): void {
|
||||||
|
this.dialogRef.close()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue