Skip to content

Commit

Permalink
fix(ui): cannot add a worker model without required info #4816 (#4933)
Browse files Browse the repository at this point in the history
  • Loading branch information
bnjjj authored Jan 30, 2020
1 parent d39462a commit 4932951
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
import {
ChangeDetectionStrategy, ChangeDetectorRef,
Component,
EventEmitter,
Input,
OnInit,
Output,
ViewChild
} from '@angular/core';
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core';
import { Group } from 'app/model/group.model';
import { AuthentifiedUser } from 'app/model/user.model';
import { ModelPattern, WorkerModel } from 'app/model/worker-model.model';
Expand All @@ -26,7 +18,7 @@ import { Subscription } from 'rxjs/Subscription';
})
@AutoUnsubscribe()
export class WorkerModelFormComponent implements OnInit {
@ViewChild('codeMirror', {static: false}) codemirror: any;
@ViewChild('codeMirror', { static: false }) codemirror: any;

_workerModel: WorkerModel;
@Input() set workerModel(wm: WorkerModel) {
Expand Down Expand Up @@ -109,6 +101,37 @@ pattern_name: basic_unix`;
.subscribe((wmStr) => this.workerModelAsCode = wmStr);
}

canSave(): boolean {
if (!this.workerModel.editable) {
return false;
}

let minimal_required_info = !!this.workerModel.name && !!this.workerModel.group_id && !!this.workerModel.type;
if (!minimal_required_info) {
return false;
}

switch (this.workerModel.type) {
case 'docker':
let minimal_info_docker = !!this.workerModel.model_docker.image
&& !!this.workerModel.model_docker.shell && !!this.workerModel.model_docker.cmd;
if (!minimal_info_docker) {
return false;
}
break;
case 'host':
case 'openstack':
case 'vsphere':
let minimal_info_vm = !!this.workerModel.model_virtual_machine.image && !!this.workerModel.model_virtual_machine.cmd;
if (!minimal_info_vm) {
return false;
}
break;
}

return true;
}

filterPatterns(type: string) {
this.patternsFiltered = this.patterns.filter((pattern) => pattern.type === type);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,8 @@ <h4 *ngIf="workerModel.last_spawn_err_log">{{ 'worker_model_error_log' | transla
<div *ngIf="workerModel.editable" class="field">
<app-delete-button *ngIf="workerModel.id" class="left floated" (event)="clickDelete()"
[loading]="deleteLoading"></app-delete-button>
<button class="ui green right floated button" [class.loading]="loading" (click)="clickSave()">
<button class="ui green right floated button" [class.loading]="loading"
[class.disabled]="!canSave()" (click)="clickSave()">
<i class="save icon"></i>{{ 'btn_save' | translate }}
</button>
</div>
Expand Down

0 comments on commit 4932951

Please sign in to comment.