Skip to content

Commit

Permalink
fix(ui): fix payload autocompletion #4503
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Coenen <benjamin.coenen@corp.ovh.com>
  • Loading branch information
bnjjj committed Aug 6, 2019
1 parent 8e6f08a commit 8269b71
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 39 deletions.
38 changes: 20 additions & 18 deletions ui/src/app/shared/workflow/node/run/node.run.param.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Input, OnInit, ViewChild } from '@angular/core';
import { AfterViewInit, ChangeDetectionStrategy, ChangeDetectorRef, Component, Input, OnInit, ViewChild } from '@angular/core';
import { Router } from '@angular/router';
import { TranslateService } from '@ngx-translate/core';
import { ModalTemplate, SuiActiveModal, SuiModalService, TemplateModalConfig } from '@richardlt/ng2-semantic-ui';
Expand Down Expand Up @@ -26,12 +26,12 @@ declare var CodeMirror: any;
changeDetection: ChangeDetectionStrategy.OnPush
})
@AutoUnsubscribe()
export class WorkflowNodeRunParamComponent implements OnInit {
@ViewChild('runWithParamModal', {static: false})
export class WorkflowNodeRunParamComponent implements OnInit, AfterViewInit {
@ViewChild('runWithParamModal', { static: false })
runWithParamModal: ModalTemplate<boolean, boolean, void>;
modal: SuiActiveModal<boolean, boolean, void>;

@ViewChild('textareaCodeMirror', {static: false}) codemirror: any;
@ViewChild('textareaCodeMirror', { static: false }) codemirror: any;

@Input() workflowRun: WorkflowRun;
_nodeRun: WorkflowNodeRun;
Expand Down Expand Up @@ -114,15 +114,17 @@ export class WorkflowNodeRunParamComponent implements OnInit {

ngOnInit(): void {
this.linkedToRepo = WNode.linkedToRepo(this._nodeToRun, this.workflow);
}

ngAfterViewInit() {
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);
}
});
this.codeMirrorConfig.theme = t === 'night' ? 'darcula' : 'default';
if (this.codemirror && this.codemirror.instance) {
this.codemirror.instance.setOption('theme', this.codeMirrorConfig.theme);
}
});
}

show(): void {
Expand Down Expand Up @@ -407,25 +409,25 @@ export class WorkflowNodeRunParamComponent implements OnInit {
});
}

changeCodeMirror(eventRoot: Event): void {
changeCodeMirror(codemirror: any, eventRoot: Event): void {
let num = this.num;
if (!this.codemirror || !this.codemirror.instance) {
return
if (!codemirror || !codemirror.instance) {
return;
}
if (eventRoot.type === 'click') {
this.showHint(this.codemirror.instance, null);
this.showHint(codemirror.instance);
}

if (!this._keyUpListener) {
this._keyUpListener = this.codemirror.instance.on('keyup', (cm, event) => {
this._keyUpListener = codemirror.instance.on('keyup', (cm, event) => {
if (!cm.state.completionActive && event.keyCode !== 32) {
this.showHint(cm, event);
this.showHint(cm);
}
});
}

if (!this._completionListener) {
this._completionListener = this.codemirror.instance.on('endCompletion', (cm, event) => {
this._completionListener = codemirror.instance.on('endCompletion', () => {
if (!this.linkedToRepo) {
return;
}
Expand Down Expand Up @@ -453,8 +455,8 @@ export class WorkflowNodeRunParamComponent implements OnInit {
}
}

showHint(cm, event) {
CodeMirror.showHint(this.codemirror.instance, CodeMirror.hint.payload, {
showHint(cm) {
CodeMirror.showHint(cm, CodeMirror.hint.payload, {
completeSingle: true,
closeCharacters: / /,
payloadCompletionList: {
Expand Down
36 changes: 15 additions & 21 deletions ui/src/app/shared/workflow/node/run/node.run.param.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,29 @@
<div class="header">
{{'workflow_run_with_parameters' | translate}}
<div class="extra" *ngIf="num">
<button
type="button"
class="ui small green button"
suiPopup
[popupText]="'workflow_run_resync_help' | translate"
[class.loading]="loading"
[disabled]="loading"
(click)="resync()">
{{ 'workflow_resync' | translate }}
<button type="button" class="ui small green button" suiPopup
[popupText]="'workflow_run_resync_help' | translate" [class.loading]="loading" [disabled]="loading"
(click)="resync()">
{{ 'workflow_resync' | translate }}
</button>
<a href="https://ovh.github.io/cds/docs/concepts/workflow/" target="_blank"><i class="pointing help circle outline icon"></i></a>
<a href="https://ovh.github.io/cds/docs/concepts/workflow/" target="_blank"><i
class="pointing help circle outline icon"></i></a>
</div>
</div>
<div class="content">
<div class="ui form">
<ng-container *ngIf="_nodeToRun && _nodeToRun.type === nodeTypeEnum.PIPELINE && parameters?.length > 0 ">
<h3>{{ 'workflow_node_context_pipeline_parameter' | translate}}</h3>
<app-parameter-list [project]="project" [parameters]="parameters"
[paramsRef]="workflow.pipelines[_nodeToRun.context.pipeline_id]?.parameters" mode="launcher"
[suggest]="[]"></app-parameter-list>
[paramsRef]="workflow.pipelines[_nodeToRun.context.pipeline_id]?.parameters" mode="launcher"
[suggest]="[]"></app-parameter-list>
</ng-container>
<h3 *ngIf="!readOnly">{{ 'workflow_node_context_payload' | translate}}</h3>
<h3 *ngIf="readOnly">{{ 'workflow_node_context_payload_read_only' | translate}}</h3>
<ng-container *ngIf="!loadingBranches">
<codemirror
[class.invalid]="invalidJSON"
[(ngModel)]="payloadString"
[config]="codeMirrorConfig"
(click)="changeCodeMirror($event)"
(change)="changeCodeMirror($event)"
#textareaCodeMirror>
<codemirror [class.invalid]="invalidJSON" [(ngModel)]="payloadString" [config]="codeMirrorConfig"
(click)="changeCodeMirror(textareaCodeMirror, $event)"
(change)="changeCodeMirror(textareaCodeMirror, $event)" #textareaCodeMirror>
</codemirror>
</ng-container>
<ng-container *ngIf="loadingBranches">
Expand Down Expand Up @@ -67,7 +59,9 @@ <h3>{{ 'pipeline_parent_commit_to_deploy' | translate}}</h3>
</div>
</div>
<div class="actions">
<button class="ui button" [disabled]="loading" (click)="modal.approve(false)">{{'common_cancel' | translate}}</button>
<button class="ui green button" [class.loading]="loading" [disabled]="loading" (click)="run()" autofocus>{{'common_run' | translate}}</button>
<button class="ui button" [disabled]="loading"
(click)="modal.approve(false)">{{'common_cancel' | translate}}</button>
<button class="ui green button" [class.loading]="loading" [disabled]="loading" (click)="run()"
autofocus>{{'common_run' | translate}}</button>
</div>
</ng-template>

0 comments on commit 8269b71

Please sign in to comment.