Skip to content

Commit

Permalink
feat(api,sdk,ui): advanced parameters (#3163)
Browse files Browse the repository at this point in the history
  • Loading branch information
yesnault authored and fsamin committed Aug 8, 2018
1 parent e355468 commit 7582c23
Show file tree
Hide file tree
Showing 16 changed files with 113 additions and 51 deletions.
17 changes: 0 additions & 17 deletions engine/api/action/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,23 +114,6 @@ func InsertAction(tx gorp.SqlExecutor, a *sdk.Action, public bool) error {
return nil
}

// LoadPipelineActionByID retrieves and action by its id but check project and pipeline
func LoadPipelineActionByID(db gorp.SqlExecutor, project, pip string, actionID int64) (*sdk.Action, error) {
query := `
SELECT action.id, action.name, action.description, action.type, action.last_modified, action.enabled, action.deprecated
FROM action
JOIN pipeline_action ON pipeline_action.action_id = $1
JOIN pipeline_stage ON pipeline_stage.id = pipeline_action.pipeline_stage_id
JOIN pipeline ON pipeline.id = pipeline_stage.pipeline_id
JOIN project ON project.id = pipeline.project_id
WHERE action.id = $1 AND pipeline.name = $2 AND project.projectkey = $3`
a, err := loadActions(db, query, actionID, pip, project)
if err != nil {
return nil, err
}
return &a[0], nil
}

// LoadPublicAction load an action from database
func LoadPublicAction(db gorp.SqlExecutor, name string) (*sdk.Action, error) {
query := `SELECT id, name, description, type, last_modified, enabled, deprecated FROM action WHERE lower(action.name) = lower($1) AND public = true`
Expand Down
15 changes: 8 additions & 7 deletions engine/api/action/children.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ func insertChildActionParameter(db gorp.SqlExecutor, edgeID, parentID, childID i
name,
type,
value,
description) VALUES ($1, $2, $3, $4, $5)`
description,
advanced) VALUES ($1, $2, $3, $4, $5, $6)`

if _, err := db.Exec(query, edgeID, param.Name, string(param.Type), param.Value, param.Description); err != nil {
if _, err := db.Exec(query, edgeID, param.Name, string(param.Type), param.Value, param.Description, param.Advanced); err != nil {
return err
}
return nil
Expand Down Expand Up @@ -127,7 +128,7 @@ func loadActionChildren(db gorp.SqlExecutor, actionID int64) ([]sdk.Action, erro
func loadChildActionParameterValue(db gorp.SqlExecutor, edgeID int64) ([]sdk.Parameter, error) {
var params []sdk.Parameter

query := `SELECT name, type, value, description FROM action_edge_parameter
query := `SELECT name, type, value, description, advanced FROM action_edge_parameter
WHERE action_edge_id = $1 ORDER BY name`
rows, err := db.Query(query, edgeID)
if err != nil {
Expand All @@ -138,12 +139,14 @@ func loadChildActionParameterValue(db gorp.SqlExecutor, edgeID int64) ([]sdk.Par
for rows.Next() {
var p sdk.Parameter
var pType, val string
err = rows.Scan(&p.Name, &pType, &val, &p.Description)
if err != nil {
var advanced bool

if err := rows.Scan(&p.Name, &pType, &val, &p.Description, &advanced); err != nil {
return nil, err
}
p.Type = pType
p.Value = val
p.Advanced = advanced

params = append(params, p)
}
Expand All @@ -153,7 +156,6 @@ func loadChildActionParameterValue(db gorp.SqlExecutor, edgeID int64) ([]sdk.Par

// Replace action parameter with value configured by user when he created the child action
func replaceChildActionParameters(a *sdk.Action, params []sdk.Parameter) {

// So for each _existing_ parameter in child action
for i := range a.Parameters {
// search parameter matching the name
Expand All @@ -164,7 +166,6 @@ func replaceChildActionParameters(a *sdk.Action, params []sdk.Parameter) {
}
}
}

// New parameter will have their default value
}

Expand Down
18 changes: 9 additions & 9 deletions engine/api/action/parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
func LoadActionParameters(db gorp.SqlExecutor, actionID int64) ([]sdk.Parameter, error) {
var req []sdk.Parameter

query := `SELECT name, type, value, description FROM action_parameter WHERE action_id = $1 ORDER BY name`
query := `SELECT name, type, value, description, advanced FROM action_parameter WHERE action_id = $1 ORDER BY name`
rows, err := db.Query(query, actionID)
if err != nil {
return nil, err
Expand All @@ -22,15 +22,16 @@ func LoadActionParameters(db gorp.SqlExecutor, actionID int64) ([]sdk.Parameter,
var r sdk.Parameter
var t, val string
var d []byte
err = rows.Scan(&r.Name, &t, &val, &d)
if err != nil {
var advanced bool
if err := rows.Scan(&r.Name, &t, &val, &d, &advanced); err != nil {
return nil, err
}
if d != nil {
r.Description = string(d)
}
r.Type = t
r.Value = val
r.Advanced = advanced

req = append(req, r)
}
Expand All @@ -44,11 +45,11 @@ func InsertActionParameter(db gorp.SqlExecutor, actionID int64, r sdk.Parameter)
return sdk.ErrNoDirectSecretUse
}

query := `INSERT INTO action_parameter (action_id, name, type, value, description) VALUES ($1, $2, $3, $4, $5)`
_, err := db.Exec(query, actionID, r.Name, string(r.Type), r.Value, r.Description)
query := `INSERT INTO action_parameter (action_id, name, type, value, description, advanced) VALUES ($1, $2, $3, $4, $5, $6)`
_, err := db.Exec(query, actionID, r.Name, string(r.Type), r.Value, r.Description, r.Advanced)
if err != nil {
log.Warning("InsertActionParameter> Error while insert action parameter: %s while insert actionID(%d), r.Name(%s), r.Type(%s), r.Description(%s)",
err.Error(), actionID, r.Name, string(r.Type), r.Description)
log.Warning("InsertActionParameter> Error while insert action parameter: %s while insert actionID(%d), r.Name(%s), r.Type(%s), r.Description(%s), r.Advanced(%t)",
err.Error(), actionID, r.Name, string(r.Type), r.Description, r.Advanced)
return err
}

Expand All @@ -59,8 +60,7 @@ func InsertActionParameter(db gorp.SqlExecutor, actionID int64, r sdk.Parameter)
func DeleteActionParameters(db gorp.SqlExecutor, actionID int64) error {
query := `DELETE FROM action_parameter WHERE action_id = $1`

_, err := db.Exec(query, actionID)
if err != nil {
if _, err := db.Exec(query, actionID); err != nil {
return err
}

Expand Down
10 changes: 10 additions & 0 deletions engine/sql/119_parameter_advanced.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- +migrate Up
ALTER TABLE action_edge_parameter ADD COLUMN advanced BOOLEAN NOT NULL DEFAULT false;
ALTER TABLE action_parameter ADD COLUMN advanced BOOLEAN NOT NULL DEFAULT false;
update action_parameter set advanced = false;
update action_edge_parameter set advanced = false;

-- +migrate Down

ALTER TABLE action_edge_parameter DROP COLUMN advanced;
ALTER TABLE action_parameter DROP COLUMN advanced;
12 changes: 10 additions & 2 deletions sdk/exportentities/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,17 @@ func NewAction(act sdk.Action) (a Action) {
a.Version = ActionVersion1
a.Description = act.Description
a.Parameters = make(map[string]ParameterValue, len(act.Parameters))
for _, v := range act.Parameters {
a.Parameters[v.Name] = ParameterValue{
for k, v := range act.Parameters {
param := ParameterValue{
Type: string(v.Type),
DefaultValue: v.Value,
Description: v.Description,
}
// no need to export it if "Advanced" is false
if v.Advanced {
param.Advanced = &act.Parameters[k].Advanced
}
a.Parameters[v.Name] = param
}
a.Steps = newSteps(act)
a.Requirements = newRequirements(act.Requirements)
Expand Down Expand Up @@ -554,6 +559,9 @@ func (act *Action) Action() (*sdk.Action, error) {
if param.Type == "" {
param.Type = sdk.StringParameter
}
if v.Advanced != nil && *v.Advanced {
param.Advanced = true
}
a.Parameters[i] = param
i++
}
Expand Down
1 change: 1 addition & 0 deletions sdk/exportentities/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type (
Type string `json:"type,omitempty" yaml:"type,omitempty"`
DefaultValue string `json:"default,omitempty" yaml:"default,omitempty"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
Advanced *bool `json:"advanced,omitempty" yaml:"advanced,omitempty"`
}
)

Expand Down
1 change: 1 addition & 0 deletions sdk/parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type Parameter struct {
Type string `json:"type"`
Value string `json:"value"`
Description string `json:"description,omitempty" yaml:"desc,omitempty"`
Advanced bool `json:"advanced,omitempty" yaml:"advanced,omitempty"`
}

// NewStringParameter creates a Parameter from a string with <name>=<value> format
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/action_enabled.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ parameters:
type: string
description: Tag to identify uploaded artifacts. Default tag value is CDS run
version number. (Optional)
advanced: true
requirements:
- binary: bash
steps:
Expand Down
2 changes: 2 additions & 0 deletions ui/src/app/model/parameter.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export class Parameter {
type: string;
value: string;
description: string;
advanced: boolean;

// flag to know if variable data has changed
hasChanged: boolean;
Expand All @@ -28,6 +29,7 @@ export class Parameter {
pa.type = parameter.type;
pa.description = parameter.description;
pa.value = parameter.value.toString();
pa.advanced = parameter.advanced;
return pa;
}
return parameter;
Expand Down
1 change: 0 additions & 1 deletion ui/src/app/shared/action/step/form/step.form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export class ActionStepFormComponent implements OnInit {
@Input() publicActions: Array<Action>;
showAddStep: boolean;
@Output() create = new EventEmitter<StepEvent>();

step: Action;

constructor() { }
Expand Down
14 changes: 13 additions & 1 deletion ui/src/app/shared/action/step/step.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,20 @@ import {StepEvent} from './step.event';
})
export class ActionStepComponent {

_step: Action;
withAdvanced: boolean;
@Input('step')
set step(step: Action) {
this._step = step;
if (step && step.parameters) {
this.withAdvanced = step.parameters.some((parameter) => parameter.advanced);
}
}
get step(): Action {
return this._step;
}

@Input() action: Action;
@Input() step: Action;
@Input() edit: boolean;
@Input() suggest: Array<string>;
@Input() keys: AllKeys;
Expand Down
55 changes: 41 additions & 14 deletions ui/src/app/shared/action/step/step.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,11 @@
{{ 'common_disabled_f' | translate }}
</div>
</ng-container>

<ng-container *ngIf="step.optional">
<div class="five wide field">
{{ 'action_optional' | translate }}
</div>
</ng-container>

<ng-container *ngIf="step.always_executed">
<div class="five wide field">
{{ 'action_always_executed' | translate }}
Expand All @@ -74,18 +72,47 @@
</div>
</div>
<div class="ui stackable grid" *ngIf="collapsed">

<div class="row" *ngFor="let p of step.parameters">
<div class="two wide column">
<label>
<b>{{p.name}}</b>
<span *ngIf="p.description" suiPopup [popupText]="p.description" popupPlacement="right center">
<i class="info circle icon"></i>
</span>
</label>
</div>
<div class="fourteen wide column">
<app-parameter-value [edit]="edit" [type]="p.type" [keys]="keys" [(value)]="p.value" [editList]="false" [suggest]="suggest"
(valueUpdating)="action.hasChanged = true" [ref]="originalParam.get(p.name)"></app-parameter-value>
</div>
<ng-container *ngIf="!p.advanced">
<div class="two wide column">
<label>
<b>{{p.name}}</b>
<span *ngIf="p.description" suiPopup [popupText]="p.description" popupPlacement="right center">
<i class="info circle icon"></i>
</span>
</label>
</div>
<div class="fourteen wide column">
<app-parameter-value [edit]="edit" [type]="p.type" [keys]="keys" [(value)]="p.value" [editList]="false" [suggest]="suggest"
(valueUpdating)="action.hasChanged = true" [ref]="originalParam.get(p.name)"></app-parameter-value>
</div>
</ng-container>
</div>

<div class="sixteen wide right aligned field pointing" *ngIf="withAdvanced" (click)="collapsed_advanced = !collapsed_advanced">
{{'parameters_advanced' | translate}}
<i class="caret down icon" *ngIf="collapsed_advanced"></i>
<i class="caret right icon" *ngIf="!collapsed_advanced"></i>
</div>

<ng-container *ngIf="withAdvanced && collapsed_advanced">
<div class="row" *ngFor="let p of step.parameters">
<ng-container *ngIf="p.advanced">
<div class="two wide column">
<label>
<b>{{p.name}}</b>
<span *ngIf="p.description" suiPopup [popupText]="p.description" popupPlacement="right center">
<i class="info circle icon"></i>
</span>
</label>
</div>
<div class="fourteen wide column">
<app-parameter-value [edit]="edit" [type]="p.type" [keys]="keys" [(value)]="p.value" [editList]="false" [suggest]="suggest"
(valueUpdating)="action.hasChanged = true" [ref]="originalParam.get(p.name)"></app-parameter-value>
</div>
</ng-container>
</div>
</ng-container>

</div>
6 changes: 6 additions & 0 deletions ui/src/app/shared/parameter/form/parameter.form.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
<label>{{'parameter_description' | translate}}</label>
<textarea [(ngModel)]="newParameter.description" name="description" rows="{{ _sharedService.getTextAreaheight(newParameter.description)}}"></textarea>
</div>
<div class="two wide field">
<div class="ui checkbox">
<input type="checkbox" name="advanced" [(ngModel)]="newParameter.advanced">
<label></label>
</div>
</div>
<div class="two wide center field">
<button class="ui blue button" [disabled]="!newParameter.name"><i class="plus icon"></i>{{ 'btn_add' | translate}}</button>
</div>
Expand Down
7 changes: 7 additions & 0 deletions ui/src/app/shared/parameter/list/parameter.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<th class="two wide" *ngIf="mode !=='launcher' && mode !== 'job'">{{ 'parameter_type' | translate }}</th>
<th class="wide" [class.four]="mode !== 'launcher' && mode !== 'job'" [class.eight]="mode === 'launcher' || mode === 'job'">{{ 'parameter_value' | translate }}</th>
<th class="four wide" *ngIf="mode !== 'launcher' && mode !== 'job'">{{ 'parameter_description' | translate }}</th>
<th class="two wide" *ngIf="mode === 'edit'">{{ 'parameter_advanced' | translate }}</th>
<th class="two wide"></th>
</tr>
</thead>
Expand Down Expand Up @@ -63,6 +64,12 @@
</textarea>
<span *ngIf="mode === 'launcher' && (!p.description && p.description === '')">{{'common_no_description' | translate}}</span>
</td>
<td class="center" *ngIf="mode === 'edit'">
<div class="ui checkbox">
<input type="checkbox" name="advanced" [(ngModel)]="p.advanced">
<label></label>
</div>
</td>
<td class="center" *ngIf="mode !== 'launcher' && mode !== 'job'">
<ng-container *ngIf="mode === 'edit'">
<div *ngIf="p.hasChanged && !hideSave;then save;else remove"></div>
Expand Down
2 changes: 2 additions & 0 deletions ui/src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,8 @@
"parameter_type": "Type",
"parameter_updated": "Parameter updated",
"parameter_value": "Value",
"parameter_advanced": "Advanced parameter",
"parameters_advanced": "Advanced parameters",

"permission_added": "Permission added",
"permission_deleted": "Permission deleted",
Expand Down
2 changes: 2 additions & 0 deletions ui/src/assets/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,8 @@
"parameter_type": "Type",
"parameter_updated": "Paramètre mis à jour",
"parameter_value": "Valeur",
"parameter_advanced": "Paramètre avancé",
"parameters_advanced": "Paramètres avancés",

"permission_added": "Permission ajoutée",
"permission_deleted": "Permission supprimée",
Expand Down

0 comments on commit 7582c23

Please sign in to comment.