Skip to content

Commit

Permalink
feat(ui): remove ngsemantic ascode modal and ng-semantic run workflow…
Browse files Browse the repository at this point in the history
… modal (#6212)
  • Loading branch information
sguiheux authored Jun 16, 2022
1 parent 073a9b1 commit 912290b
Show file tree
Hide file tree
Showing 30 changed files with 318 additions and 355 deletions.
8 changes: 6 additions & 2 deletions engine/api/application/application_importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"strings"

"github.com/ovh/cds/engine/api/repositoriesmanager"
"github.com/ovh/cds/engine/api/vcs"
"github.com/ovh/cds/engine/gorpmapper"
"github.com/ovh/cds/sdk"
)
Expand Down Expand Up @@ -68,8 +69,11 @@ func Import(ctx context.Context, db gorpmapper.SqlExecutorWithTx, proj sdk.Proje
//Set repositories manager
app.VCSServer = repomanager
if app.VCSServer != "" && app.RepositoryFullname != "" {
if _, err := repositoriesmanager.LoadProjectVCSServerLinkByProjectKeyAndVCSServerName(ctx, db, proj.Key, app.VCSServer); err != nil {
return sdk.NewError(sdk.ErrNoReposManager, err)
if _, err := vcs.LoadVCSByProject(ctx, db, proj.Key, app.VCSServer); err != nil {
// Check old way
if _, err := repositoriesmanager.LoadProjectVCSServerLinkByProjectKeyAndVCSServerName(ctx, db, proj.Key, app.VCSServer); err != nil {
return sdk.NewError(sdk.ErrNoReposManager, err)
}
}

if err := repositoriesmanager.InsertForApplication(db, app); err != nil {
Expand Down
1 change: 1 addition & 0 deletions engine/api/repositoriesmanager/dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ func LoadAllProjectVCSServerLinksByProjectKey(ctx context.Context, db gorp.SqlEx
return getAllProjectVCSServerLinks(ctx, db, query)
}

// DEPRECATED
func LoadProjectVCSServerLinkByProjectKeyAndVCSServerName(ctx context.Context, db gorp.SqlExecutor, projectKey, rmName string) (sdk.ProjectVCSServerLink, error) {
var query = gorpmapping.NewQuery(`
SELECT project_vcs_server_link.*
Expand Down
21 changes: 5 additions & 16 deletions ui/src/app/shared/ascode/save-modal/ascode.save-modal.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Input, OnDestroy, ViewChild } from '@angular/core';
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Input, OnDestroy } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { Store } from '@ngxs/store';
import { ModalTemplate, SuiActiveModal, SuiModalService, TemplateModalConfig } from '@richardlt/ng2-semantic-ui';
import { EventService } from 'app/event.service';
import { Application } from 'app/model/application.model';
import { Environment } from 'app/model/environment.model';
Expand All @@ -20,6 +19,7 @@ import { EventState } from 'app/store/event.state';
import { Subscription } from 'rxjs';
import { filter, finalize, first, map } from 'rxjs/operators';
import { ParamData } from '../save-form/ascode.save-form.component';
import { NzModalRef } from 'ng-zorro-antd/modal';

@Component({
selector: 'app-ascode-save-modal',
Expand All @@ -28,10 +28,6 @@ import { ParamData } from '../save-form/ascode.save-form.component';
})
@AutoUnsubscribe()
export class AsCodeSaveModalComponent implements OnDestroy {
@ViewChild('updateAsCodeModal')
public myModalTemplate: ModalTemplate<boolean, boolean, void>;
modal: SuiActiveModal<boolean, boolean, void>;
modalConfig: TemplateModalConfig<boolean, boolean, void>;

@Input() project: Project;
@Input() workflow: Workflow;
Expand All @@ -48,7 +44,7 @@ export class AsCodeSaveModalComponent implements OnDestroy {
displayCloseButton = false;

constructor(
private _modalService: SuiModalService,
private _modal: NzModalRef,
private _cd: ChangeDetectorRef,
private _toast: ToastService,
private _translate: TranslateService,
Expand All @@ -62,11 +58,7 @@ export class AsCodeSaveModalComponent implements OnDestroy {

ngOnDestroy(): void {} // Should be set to use @AutoUnsubscribe with AOT

show(data: any, type: string) {
this.loading = false;
this.dataToSave = data;
this.dataType = type;

ngOnInit(): void {
if (this.workflow && this.workflow.workflow_data.node.context) {
let rootAppID = this.workflow.workflow_data.node.context.application_id;
if (rootAppID) {
Expand All @@ -76,14 +68,11 @@ export class AsCodeSaveModalComponent implements OnDestroy {
}
}
}

this.modalConfig = new TemplateModalConfig<boolean, boolean, void>(this.myModalTemplate);
this.modal = this._modalService.open(this.modalConfig);
}

close() {
delete this.parameters;
this.modal.approve(true);
this._modal.destroy();
}

save(): void {
Expand Down
51 changes: 24 additions & 27 deletions ui/src/app/shared/ascode/save-modal/ascode.save-modal.html
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
<ng-template let-context let-modal="modal" #updateAsCodeModal>
<div class="header">{{ 'ascode_modal_title' | translate }}</div>
<div class="content">
<div *ngIf="repositoryFullname" class="ui blue message">
A pull request will be created to the repository {{repositoryFullname}}.<br>
Notice that you can't push on the default branch of your git repository.
</div>
<app-ascode-save-form [project]="project" [workflow]="workflow" [operation]="asCodeOperation"
(paramChange)="onParamChange($event)">
</app-ascode-save-form>
</div>
<div class="actions">
<ng-container *ngIf="!displayCloseButton">
<div class="ui blue button" [class.loading]="loading" [class.disabled]="loading" (click)="close()">
{{'common_cancel' | translate}}
</div>
<div class="ui green button" [class.loading]="loading"
[class.disabled]="loading || !canSave"
<div class="content">
<nz-alert *ngIf="repositoryFullname" nzType="info" [nzMessage]="infoPr"></nz-alert>
<ng-template #infoPr>
A pull request will be created to the repository {{repositoryFullname}}.<br>
Notice that you can't push on the default branch of your git repository.
</ng-template>
<app-ascode-save-form [project]="project" [workflow]="workflow" [operation]="asCodeOperation" (paramChange)="onParamChange($event)"></app-ascode-save-form>
</div>
<div *nzModalFooter>
<ng-container *ngIf="!displayCloseButton">
<button nz-button [nzLoading]="loading" [disabled]="loading" (click)="close()">
Cancel
</button>
<button nz-button nzType="primary" [nzLoading]="loading"
[disabled]="loading || !canSave"
(click)="save()">
{{'btn_save' | translate}}</div>
</ng-container>
<ng-container *ngIf="displayCloseButton">
<div class="ui blue button" (click)="close()">
{{'common_close' | translate}}
</div>
</ng-container>
</div>
</ng-template>
Save
</button>
</ng-container>
<ng-container *ngIf="displayCloseButton">
<button nz-button (click)="close()">
Close
</button>
</ng-container>
</div>
2 changes: 1 addition & 1 deletion ui/src/app/shared/parameter/list/parameter.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<nz-table nzShowPagination [nzData]="parameters" nzPageSize="5" #paramsList *ngIf="ready && parameters?.length > 0" [nzFrontPagination]="mode === 'job'?false:true">
<nz-table [nzSize]="mode === 'launcher' || mode === 'job'?'small':'default'" nzShowPagination [nzData]="parameters" nzPageSize="5" #paramsList *ngIf="ready && parameters?.length > 0" [nzFrontPagination]="mode === 'job' || mode === 'launcher'?false:true">
<thead>
<tr *ngIf="mode !== 'launcher' && mode !== 'job'">
<th nzWidth="200px">Name</th>
Expand Down
11 changes: 10 additions & 1 deletion ui/src/app/shared/variable/value/variable.value.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@ import { SharedService } from 'app/shared/shared.service';
changeDetection: ChangeDetectionStrategy.OnPush
})
export class VariableValueComponent implements OnInit {
@Input() type: string;
_type: string;
@Input() set type (t: string) {
this._type = t;
if (t === 'boolean') {
this.value = this.value === 'true';
}
}
get type(): string{
return this._type;
}
@Input() value: string | number | boolean;
@Input() disabled: boolean;
@Output() valueChange = new EventEmitter<string | number | boolean>();
Expand Down
7 changes: 3 additions & 4 deletions ui/src/app/shared/variable/value/variable.value.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
</div>

<!-- Boolean -->
<div class="ui checkbox" *ngSwitchCase="'boolean'">
<input type="checkbox" [(ngModel)]="value" (change)="valueChanged()" (keydown)="sendValueChanged()" [disabled]="disabled" name="value">
<label>{{ ' '}}</label>
</div>
<ng-container *ngSwitchCase="'boolean'">
<label nz-checkbox [(ngModel)]="value" (ngModelChange)="valueChanged()" [nzDisabled]="disabled" name="value"></label>
</ng-container>

<!-- Password -->
<div *ngSwitchCase="'password'">
Expand Down
44 changes: 25 additions & 19 deletions ui/src/app/shared/workflow/node/run/node.run.param.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import { AfterViewInit, ChangeDetectionStrategy, ChangeDetectorRef, Component, OnDestroy, ViewChild } from '@angular/core';
import {
AfterViewInit,
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
OnDestroy,
OnInit,
ViewChild
} from '@angular/core';
import { Router } from '@angular/router';
import { Store } from '@ngxs/store';
import { ModalTemplate, SuiActiveModal, SuiModalService, TemplateModalConfig } from '@richardlt/ng2-semantic-ui';
import { ModalTemplate, SuiActiveModal, TemplateModalConfig } from '@richardlt/ng2-semantic-ui';
import { Parameter } from 'app/model/parameter.model';
import { Pipeline } from 'app/model/pipeline.model';
import { Commit } from 'app/model/repositories.model';
Expand All @@ -16,6 +24,7 @@ import { WorkflowState } from 'app/store/workflow.state';
import cloneDeep from 'lodash-es/cloneDeep';
import { debounceTime, finalize, first } from 'rxjs/operators';
import { Subscription } from 'rxjs/Subscription';
import { NzModalRef } from 'ng-zorro-antd/modal';

declare let CodeMirror: any;

Expand All @@ -26,7 +35,7 @@ declare let CodeMirror: any;
changeDetection: ChangeDetectionStrategy.OnPush
})
@AutoUnsubscribe()
export class WorkflowNodeRunParamComponent implements AfterViewInit, OnDestroy {
export class WorkflowNodeRunParamComponent implements OnInit, AfterViewInit, OnDestroy {
@ViewChild('runWithParamModal')
runWithParamModal: ModalTemplate<boolean, boolean, void>;
modal: SuiActiveModal<boolean, boolean, void>;
Expand Down Expand Up @@ -62,11 +71,10 @@ export class WorkflowNodeRunParamComponent implements AfterViewInit, OnDestroy {
readOnly = false;
linkedToRepo = false;
nodeTypeEnum = WNodeType;
open: boolean;
themeSubscription: Subscription;

constructor(
private _modalService: SuiModalService,
private _modal: NzModalRef,
private _workflowRunService: WorkflowRunService,
private _router: Router,
private _appWorkflowService: ApplicationWorkflowService,
Expand Down Expand Up @@ -96,11 +104,7 @@ export class WorkflowNodeRunParamComponent implements AfterViewInit, OnDestroy {
});
}

show(): void {
if (this.open) {
return;
}
this.open = true;
ngOnInit(): void {
this.nodeToRun = cloneDeep(this._store.selectSnapshot(WorkflowState.nodeSnapshot));
this.currentNodeRun = this._store.selectSnapshot(WorkflowState.nodeRunSnapshot);
this.currentWorkflowRun = this._store.selectSnapshot(WorkflowState.workflowRunSnapshot);
Expand Down Expand Up @@ -202,14 +206,6 @@ export class WorkflowNodeRunParamComponent implements AfterViewInit, OnDestroy {
this.payloadString = JSON.stringify(currentPayload, undefined, 4);
}

this.modal = this._modalService.open(config);
this.modal.onApprove(() => {
this.open = false;
});
this.modal.onDeny(() => {
this.open = false;
});

this.codeMirrorConfig = Object.assign({}, this.codeMirrorConfig, { readOnly: this.readOnly });

if (!this.nodeToRun || !this.nodeToRun.context || !this.nodeToRun.context.application_id) {
Expand Down Expand Up @@ -343,6 +339,12 @@ export class WorkflowNodeRunParamComponent implements AfterViewInit, OnDestroy {
}

run(resync: boolean, onlyFailedJobs: boolean): void {
if (resync && this.workflow?.from_repository) {
return;
}
if (onlyFailedJobs && this.currentNodeRun?.status !== 'Fail') {
return;
}
if (this.payloadString && this.payloadString !== '') {
this.reindent();
if (this.invalidJSON) {
Expand Down Expand Up @@ -370,7 +372,7 @@ export class WorkflowNodeRunParamComponent implements AfterViewInit, OnDestroy {
this._workflowRunService.runWorkflow(this.projectKey, this.workflow.name, request).subscribe(wr => {
this.loading = false;
this._cd.detectChanges();
this.modal.approve(true);
this.close();
this._router.navigate(['/project', this.projectKey, 'workflow', this.workflow.name, 'run', wr.num]);
});
}
Expand Down Expand Up @@ -455,4 +457,8 @@ export class WorkflowNodeRunParamComponent implements AfterViewInit, OnDestroy {
specialChars: ''
});
}

close(): void {
this._modal.destroy();
}
}
Loading

0 comments on commit 912290b

Please sign in to comment.