Skip to content

Commit

Permalink
fix (ui): update checkbox (#741)
Browse files Browse the repository at this point in the history
close #724
close #723
  • Loading branch information
yesnault authored and sguiheux committed Jun 20, 2017
1 parent cc6ab4c commit d47cd45
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 31 deletions.
1 change: 1 addition & 0 deletions ui/src/app/shared/action/step/step.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {Component, Input, EventEmitter, Output} from '@angular/core';
import {Action} from '../../../model/action.model';
import {Parameter} from '../../../model/parameter.model';
import {StepEvent} from './step.event';

@Component({
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/shared/action/step/step.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@
(valueUpdating)="action.hasChanged = true"></app-parameter-value>
</div>
</div>
</div>
</div>
3 changes: 1 addition & 2 deletions ui/src/app/shared/parameter/list/parameter.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<tr *ngFor="let p of getDataForCurrentPage()" class="ui form">
<td>
<div class="ui fluid input" *ngIf="mode === 'edit'">
<input class="ui input" [(ngModel)]="p.name" (keydown)="p.hasChanged = true" [disabled]="p.updating">
<input class="ui input" [(ngModel)]="p.name" (keydown)="p.hasChanged = true" [disabled]="p.updating">
</div>
<span class="help" *ngIf="mode === 'launcher'" (mouseenter)="popup.show($event, {position: 'right center', on: 'hover'})">
<i class="help circle outline icon"></i>
Expand Down Expand Up @@ -63,7 +63,6 @@
<app-delete-button (event)="sendEvent('delete', p)" [loading]="p.updating"></app-delete-button>
</ng-template>
</ng-container>

</td>
</tr>
</tbody>
Expand Down
26 changes: 16 additions & 10 deletions ui/src/app/shared/parameter/value/parameter.value.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@ declare var CodeMirror: any;
templateUrl: './parameter.value.html',
styleUrls: ['./parameter.value.scss']
})
export class ParameterValueComponent implements OnInit {
export class ParameterValueComponent {

editableValue: string|number|boolean;
@Input() type: string;
@Input() value: string|number|boolean;
@Input('value')
set value (data: string|number|boolean) {
this.editableValue = this.castValue(data);
};

@Input() editList = true;
@Input() edit = true;
@Input() suggest: Array<string> = new Array<string>();
Expand Down Expand Up @@ -65,18 +70,19 @@ export class ParameterValueComponent implements OnInit {
};
}

ngOnInit(): void {
castValue(data: string|number|boolean): string|number|boolean {
if (this.type === 'boolean') {
this.value = (this.value === 'true');
return (data === 'true' || data === true);
}
if (this.type === 'list' && !this.editList) {
this.list = (<string>this.value).split(';');
this.value = this.list[0];
this.list = (<string>data).split(';');
return this.list[0];
}
return data;
}

valueChanged(): void {
this.valueChange.emit(this.value);
this.valueChange.emit(this.editableValue);
}

sendValueChanged(): void {
Expand All @@ -85,15 +91,15 @@ export class ParameterValueComponent implements OnInit {

changeCodeMirror(): void {
this.valueChanged();
let firstLine = String(this.value).split('\n')[0];
let firstLine = String(this.editableValue).split('\n')[0];

if (firstLine.indexOf('FROM') !== -1) {
this.codeMirrorConfig.mode = 'dockerfile';
} else if (firstLine.indexOf('#!/usr/bin/perl') !== -1) {
this.codeMirrorConfig.mode = 'perl';
} else if (firstLine.indexOf('#!/usr/bin/python') !== -1) {
this.codeMirrorConfig.mode = 'python';
} else if (String(this.value).indexOf('c:\\') !== -1) {
} else if (String(this.editableValue).indexOf('c:\\') !== -1) {
this.codeMirrorConfig.mode = 'powershell';
} else if (firstLine.indexOf('#!/bin/bash') !== -1) {
this.codeMirrorConfig.mode = 'bash';
Expand Down Expand Up @@ -123,7 +129,7 @@ export class ParameterValueComponent implements OnInit {
}

valueRepoChanged(name): void {
this.value = this.selectedRepoManager.name + '##' + name;
this.editableValue = this.selectedRepoManager.name + '##' + name;
this.valueChanged();
}

Expand Down
28 changes: 14 additions & 14 deletions ui/src/app/shared/parameter/value/parameter.value.html
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<ng-container [ngSwitch]="type" *ngIf="edit">
<div *ngSwitchCase="'number'" class="ui fluid input">
<input type="number" [(ngModel)]="value" (change)="valueChanged()" (keydown)="sendValueChanged()" name="value">
<input type="number" [(ngModel)]="editableValue" (change)="valueChanged()" (keydown)="sendValueChanged()" name="value">
</div>
<div *ngSwitchCase="'text'" class="ui form">
<codemirror [(ngModel)]="value" [config]="codeMirrorConfig" (change)="changeCodeMirror($event)" #codeMirror (keydown)="sendValueChanged()"></codemirror>
<codemirror [(ngModel)]="editableValue" [config]="codeMirrorConfig" (change)="changeCodeMirror($event)" #codeMirror (keydown)="sendValueChanged()"></codemirror>
</div>
<div *ngSwitchCase="'boolean'" class="ui checkbox">
<input type="checkbox" [(ngModel)]="value" (change)="valueChanged()" (keydown)="sendValueChanged()" name="value">
<input type="checkbox" [(ngModel)]="editableValue" (change)="valueChanged();sendValueChanged()" name="value">
<label>{{ ' '}}</label>
</div>
<div *ngSwitchCase="'list'">
<div class="ui fluid input" *ngIf="editList">
<input type="text" [(ngModel)]="value" (change)="valueChanged()" (keydown)="sendValueChanged()" name="value" placeholder="value1;value2;value3">
<input type="text" [(ngModel)]="editableValue" (change)="valueChanged()" (keydown)="sendValueChanged()" name="value" placeholder="value1;value2;value3">
</div>
<div *ngIf="!editList">
<sm-select class="search fluid"
[(model)]="value"
[(model)]="editableValue"
[options]="{'fullTextSearch': true}"
(modelChange)="valueChanged()"
(keydown)="sendValueChanged()"
Expand All @@ -27,7 +27,7 @@
<div *ngSwitchCase="'env'">
<sm-select class="search fluid"
[options]="{'fullTextSearch': true}"
[(model)]="value"
[(model)]="editableValue"
(modelChange)="valueChanged()"
(onChange)="sendValueChanged()">
<option *ngFor="let env of project?.environments" value="{{env.name}}">{{env.name}}</option>
Expand All @@ -36,7 +36,7 @@
<div *ngSwitchCase="'pipeline'">
<sm-select class="search fluid"
[options]="{'fullTextSearch': true}"
[(model)]="value"
[(model)]="editableValue"
(modelChange)="valueChanged()"
(onChange)="sendValueChanged()">
<option *ngFor="let pip of project?.pipelines" value="{{pip.name}}">{{pip.name}}</option>
Expand All @@ -58,23 +58,23 @@
[disabled]="loadingRepos">
<option *ngFor="let r of repositories" value="{{r.fullname}}">{{r.fullname}}</option>
</sm-select>
<input *ngIf="selectedRepoManager && selectedRepoManager.name === 'Git Url'" type="text" [(ngModel)]="value" (change)="valueChanged()" (keydown)="sendValueChanged()" name="value" placeholder="{{'parameter_git_url' | translate }}">
<input *ngIf="selectedRepoManager && selectedRepoManager.name === 'Git Url'" type="text" [(ngModel)]="editableValue" (change)="valueChanged()" (keydown)="sendValueChanged()" name="value" placeholder="{{'parameter_git_url' | translate }}">
</div>
<div *ngSwitchDefault>
<input auto-complete autocomplete="off" type="text" [(ngModel)]="value"
<input auto-complete autocomplete="off" type="text" [(ngModel)]="editableValue"
(change)="valueChanged()" (keydown)="sendValueChanged()" name="value" [source]="suggest" [min-chars]="3"
[no-match-found-text]="false">
</div>
</ng-container>
<ng-container [ngSwitch]="type" *ngIf="!edit">
<div *ngSwitchCase="'text'" class="ui form">
<textarea readonly rows="{{_sharedService.getTextAreaheight(value)}}">{{value}}</textarea>
<textarea readonly rows="{{_sharedService.getTextAreaheight(editableValue)}}">{{editableValue}}</textarea>
</div>
<div *ngSwitchCase="'boolean'" class="ui checkbox">
<input disabled type="checkbox" [(ngModel)]="value" (change)="valueChanged()" (keydown)="sendValueChanged()" name="value">
<label>{{ ' '}}</label>
<input disabled type="checkbox" [(ngModel)]="editableValue" (change)="valueChanged()" (keydown)="sendValueChanged()" name="value">
<label>{{' '}}</label>
</div>
<div *ngSwitchDefault class="ui fluid input">
{{value}}
{{editableValue}}
</div>
</ng-container>
</ng-container>
2 changes: 1 addition & 1 deletion ui/src/app/views/pipeline/show/pipeline.show.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
flex-direction: column;
align-content: stretch;
height: 100%;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export class PipelineStageComponent implements OnInit, DoCheck {
this._toast.success('', this._translate.instant('stage_job_updated'));
job.action.loading = false;
job.action.hasChanged = false;

}, () => {
job.action.loading = false;
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<h3>{{ 'stage_jobs_title' | translate}}</h3>
<div class="ui grid">
<div class="ui grid spacebottom">
<div class="three wide column">
<div class="ui vertical steps">
<div class="step" *ngFor="let job of editableStage.jobs; let i = index"
Expand Down Expand Up @@ -30,4 +30,3 @@ <h3>{{ 'stage_jobs_title' | translate}}</h3>
(actionEvent)="jobEvent($event)"></app-action>
</div>
</div>

Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
margin-top: 10px;
}

.spacebottom {
padding-bottom: 50px !important;
}

pre {
word-break: break-word;
}
}
22 changes: 22 additions & 0 deletions ui/src/app/views/settings/action/edit/action.edit.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,28 @@ export class ActionEditComponent implements OnInit {

actionEvent(event: ActionEvent): void {
event.action.loading = true;

if (event.action.actions) {
event.action.actions.forEach(a => {
if (a.parameters) {
a.parameters.forEach(p => {
if (p.type === 'boolean' && !p.value) {
p.value = 'false';
}
p.value = p.value.toString();
});
}
});
}
if (event.action.parameters) {
event.action.parameters.forEach(p => {
if (p.type === 'boolean' && !p.value) {
p.value = 'false';
}
p.value = p.value.toString();
});
}

switch (event.type) {
case 'update':
this._actionService.updateAction(this.action.name, event.action).subscribe( action => {
Expand Down

0 comments on commit d47cd45

Please sign in to comment.