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

feat: compute default values for template parameter #5092

Merged
merged 6 commits into from
Apr 2, 2020
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
feat(ui): completion for template param key
  • Loading branch information
richardlt committed Mar 31, 2020
commit fce8b18e6a8e50ec5096f20386d19b390407b1b8
6 changes: 1 addition & 5 deletions cli/cdsctl/workflow_init.go
Original file line number Diff line number Diff line change
@@ -438,11 +438,7 @@ func workflowInitRun(c cli.Values) error {
}

// Check if the project is linked to a repository
proj, err := client.ProjectGet(pkey, func(r *http.Request) {
q := r.URL.Query()
q.Set("withKeys", "true")
r.URL.RawQuery = q.Encode()
})
proj, err := client.ProjectGet(pkey, cdsclient.WithKeys())
if err != nil {
return fmt.Errorf("unable to get project: %v", err)
}
4 changes: 2 additions & 2 deletions engine/api/templates.go
Original file line number Diff line number Diff line change
@@ -646,9 +646,9 @@ func (api *API) getTemplateInstancesHandler() service.Handler {

var ps sdk.Projects
if isMaintainer(ctx) {
ps, err = project.LoadAll(ctx, api.mustDB(), api.Cache)
ps, err = project.LoadAll(ctx, api.mustDB(), api.Cache, project.LoadOptions.WithKeys)
} else {
ps, err = project.LoadAllByGroupIDs(ctx, api.mustDB(), api.Cache, getAPIConsumer(ctx).GetGroupIDs())
ps, err = project.LoadAllByGroupIDs(ctx, api.mustDB(), api.Cache, getAPIConsumer(ctx).GetGroupIDs(), project.LoadOptions.WithKeys)
}
if err != nil {
return err
9 changes: 9 additions & 0 deletions sdk/cdsclient/interface.go
Original file line number Diff line number Diff line change
@@ -489,6 +489,15 @@ func WithPermissions() RequestModifier {
}
}

// WithKeys allow a provider to retrieve a project with its keys.
func WithKeys() RequestModifier {
return func(r *http.Request) {
q := r.URL.Query()
q.Set("withKeys", "true")
r.URL.RawQuery = q.Encode()
}
}

func Format(format string) RequestModifier {
return func(r *http.Request) {
q := r.URL.Query()
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ import {
ViewChild
} from '@angular/core';
import { ModalTemplate, SuiActiveModal, SuiModalService, TemplateModalConfig } from '@richardlt/ng2-semantic-ui';
import { Project } from 'app/model/project.model';
import { LoadOpts, Project } from 'app/model/project.model';
import { WorkflowTemplate, WorkflowTemplateInstance } from 'app/model/workflow-template.model';
import { Workflow } from 'app/model/workflow.model';
import { ProjectService } from 'app/service/project/project.service';
@@ -26,7 +26,7 @@ import { finalize } from 'rxjs/operators';
changeDetection: ChangeDetectionStrategy.OnPush
})
export class WorkflowTemplateApplyModalComponent implements OnChanges {
@ViewChild('workflowTemplateApplyModal', {static: false}) workflowTemplateApplyModal: ModalTemplate<boolean, boolean, void>;
@ViewChild('workflowTemplateApplyModal', { static: false }) workflowTemplateApplyModal: ModalTemplate<boolean, boolean, void>;
modal: SuiActiveModal<boolean, boolean, void>;
open: boolean;

@@ -79,19 +79,19 @@ export class WorkflowTemplateApplyModalComponent implements OnChanges {

load() {
if (this.workflowTemplate && this.workflowTemplateInstance) {
this._projectService.getProject(this.workflowTemplateInstance.project.key, null)
this._projectService.getProject(this.workflowTemplateInstance.project.key, [new LoadOpts('withKeys', 'keys')])
.pipe(finalize(() => this._cd.markForCheck()))
.subscribe(p => {
this.project = p;
this.loadAudits()
});
this.project = p;
this.loadAudits()
});
return
} else if (this.workflow) {
// retrieve workflow template and instance from given workflow
let s = this.workflow.from_template.split('@');
s = s[0].split('/');

forkJoin<WorkflowTemplate, WorkflowTemplateInstance> (
forkJoin<WorkflowTemplate, WorkflowTemplateInstance>(
this._templateService.get(s[0], s.splice(1, s.length - 1).join('/')),
this._templateService.getInstance(this.workflow.project_key, this.workflow.name)
).subscribe(res => {
Original file line number Diff line number Diff line change
@@ -5,7 +5,8 @@ import {
EventEmitter,
Input,
OnInit,
Output
Output,
ViewChild
} from '@angular/core';
import { FormControl } from '@angular/forms';
import { Project } from 'app/model/project.model';
@@ -16,6 +17,9 @@ import {
WorkflowTemplateInstance
} from 'app/model/workflow-template.model';
import { RepoManagerService } from 'app/service/repomanager/project.repomanager.service';
import { ThemeStore } from 'app/service/theme/theme.store';
import { AutoUnsubscribe } from 'app/shared/decorator/autoUnsubscribe';
import { Subscription } from 'rxjs';
import { finalize, first } from 'rxjs/operators';

@Component({
@@ -24,7 +28,10 @@ import { finalize, first } from 'rxjs/operators';
styleUrls: ['./workflow-template.param-form.scss'],
changeDetection: ChangeDetectionStrategy.OnPush
})
@AutoUnsubscribe()
export class WorkflowTemplateParamFormComponent implements OnInit {
@ViewChild('codemirror', { static: false }) codemirror: any;

_project: Project;
@Input('project') set project(data: Project) {
this._project = data;
@@ -38,13 +45,18 @@ export class WorkflowTemplateParamFormComponent implements OnInit {
@Output() paramChange = new EventEmitter<ParamData>();

vcsNames: Array<string>;
sshKeys: Array<string>;
pgpKeys: Array<string>;
parameterValues: any;
loading: boolean;
result: WorkflowTemplateApplyResult;
codeMirrorConfig: any;
themeSubscription: Subscription;

constructor(
private _repoManagerService: RepoManagerService, private _cd: ChangeDetectorRef
private _repoManagerService: RepoManagerService,
private _cd: ChangeDetectorRef,
private _theme: ThemeStore
) {
this.codeMirrorConfig = this.codeMirrorConfig = {
matchBrackets: true,
@@ -54,6 +66,15 @@ export class WorkflowTemplateParamFormComponent implements OnInit {
autoRefresh: true,
lineNumbers: true,
};

this.themeSubscription = this._theme.get()
.pipe(finalize(() => this._cd.markForCheck()))
.subscribe(t => {
this.codeMirrorConfig.theme = t === 'night' ? 'darcula' : 'default';
if (this.codemirror && this.codemirror.instance) {
this.codemirror.instance.setOption('theme', this.codeMirrorConfig.theme);
}
});
}

ngOnInit(): void {
@@ -65,6 +86,11 @@ export class WorkflowTemplateParamFormComponent implements OnInit {
this.vcsNames = this.project.vcs_servers.map(vcs => vcs.name);
}

if (this.project && this.project.keys) {
this.sshKeys = this.project.keys.filter(k => k.type === 'ssh').map(k => k.name);
this.pgpKeys = this.project.keys.filter(k => k.type === 'pgp').map(k => k.name);
}

this.parameterValues = {};
if (this.workflowTemplate && this.workflowTemplate.parameters) {
this.workflowTemplate.parameters.forEach(parameter => {
Original file line number Diff line number Diff line change
@@ -10,29 +10,45 @@
{{parameter.key}}<span *ngIf="parameter.required">*</span>
</div>
<div class="eight wide field" [ngSwitch]="parameter.type">
<input *ngSwitchDefault type="text" name="parameter-{{parameter.key}}" [(ngModel)]="parameterValues[parameter.key]"
(change)="changeParam()">
<sm-checkbox *ngSwitchCase="'boolean'" name="parameter-{{parameter.key}}" [control]="parameterValues[parameter.key]"
type="toggle" label=" " (change)="changeParam()"></sm-checkbox>
<input *ngSwitchDefault type="text" name="parameter-{{parameter.key}}"
[(ngModel)]="parameterValues[parameter.key]" (change)="changeParam()">
<sm-checkbox *ngSwitchCase="'boolean'" name="parameter-{{parameter.key}}"
[control]="parameterValues[parameter.key]" type="toggle" label=" " (change)="changeParam()">
</sm-checkbox>
<sui-select *ngSwitchCase="'repository'" class="selection" name="parameter-{{parameter.key}}"
placeholder="{{'workflow_wizard_select_repo_man' | translate}}" [options]="vcsNames"
isSearchable="true" [(ngModel)]="parameterValues[parameter.key]" (selectedOptionChange)="fetchRepos(parameter.key, $event)"
#select>
isSearchable="true" [(ngModel)]="parameterValues[parameter.key]"
(selectedOptionChange)="fetchRepos(parameter.key, $event)" #select>
<sui-select-option *ngFor="let vcs of select.filteredOptions" [value]="vcs">
</sui-select-option>
</sui-select>
<codemirror *ngSwitchCase="'json'" name="parameter-{{parameter.key}}" [(ngModel)]="parameterValues[parameter.key]"
[config]="codeMirrorConfig" (change)="changeParam()">
<codemirror *ngSwitchCase="'json'" name="parameter-{{parameter.key}}"
[(ngModel)]="parameterValues[parameter.key]" [config]="codeMirrorConfig"
(change)="changeParam()" #codemirror>
</codemirror>
<sui-select *ngSwitchCase="'ssh-key'" class="selection" name="parameter-{{parameter.key}}"
placeholder="{{'workflow_template_param_select_key' | translate}}" [options]="sshKeys"
isSearchable="true" [(ngModel)]="parameterValues[parameter.key]" #select>
<sui-select-option *ngFor="let key of select.filteredOptions" [value]="key">
</sui-select-option>
</sui-select>
<sui-select *ngSwitchCase="'pgp-key'" class="selection" name="parameter-{{parameter.key}}"
placeholder="{{'workflow_template_param_select_key' | translate}}" [options]="pgpKeys"
isSearchable="true" [(ngModel)]="parameterValues[parameter.key]" #select>
<sui-select-option *ngFor="let key of select.filteredOptions" [value]="key">
</sui-select-option>
</sui-select>
</div>
</div>
<div class="wide fields" *ngIf="parameter.type === 'repository'">
<div class="eight wide field"></div>
<div class="four wide field">
<sui-select class="selection" name="parameter-{{parameter.key}}-repo" [(ngModel)]="parameterValues[parameter.key + '-repository']"
<sui-select class="selection" name="parameter-{{parameter.key}}-repo"
[(ngModel)]="parameterValues[parameter.key + '-repository']"
[options]="parameterValues[parameter.key + '-repositories']" [isSearchable]="true"
[optionsFilter]="filterRepo" (selectedOptionChange)="changeParam()" #repositorySelect>
<sui-select-option *ngFor="let repository of repositorySelect.filteredOptions" [value]="repository">
<sui-select-option *ngFor="let repository of repositorySelect.filteredOptions"
[value]="repository">
</sui-select-option>
</sui-select>
</div>
Original file line number Diff line number Diff line change
@@ -3,4 +3,5 @@
position: absolute;
top: 2px;
right: -1px;
z-index: 10; // to be over code mirror editor
}
1 change: 1 addition & 0 deletions ui/src/assets/i18n/en.json
Original file line number Diff line number Diff line change
@@ -926,6 +926,7 @@
"workflow_template_help_edit_from": "Current workflow template is synchronized from URL. You can't edit it.",
"workflow_template_import_from_url": "Import from URL",
"workflow_template_imported_from_url": "Imported from URL",
"workflow_template_param_select_key": "Select a key",
"workflow_warning_deprecated_yaml": "Yaml workflow configuration is deprecated",
"application_repository_help_line_1": "Your application was not imported from your code.",
"pipeline_repository_help_line_1": "Your pipeline was not imported from your code.",
1 change: 1 addition & 0 deletions ui/src/assets/i18n/fr.json
Original file line number Diff line number Diff line change
@@ -928,6 +928,7 @@
"workflow_template_update_title": "Mise à jour du workflow à partir du modèle",
"workflow_template": "Modèle de workflow",
"workflow_templates": "Modèles de workflow",
"workflow_template_param_select_key": "Sélectionnez une clé",
"workflow_update_name_error": "Nom de workflow invalide. Pattern autorisé : ^[a-zA-Z0-9._-]{1,}$",
"workflow_ascode_updated": "Brouillon mis à jour",
"workflow_updated": "Workflow mis à jour",