Skip to content

Commit

Permalink
feat(ui): add store on workflow edit page (#4027)
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Coenen <[email protected]>
  • Loading branch information
bnjjj authored Mar 18, 2019
1 parent fcf66ba commit 34fba71
Show file tree
Hide file tree
Showing 64 changed files with 2,653 additions and 2,732 deletions.
12 changes: 0 additions & 12 deletions ui/src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,16 @@ import { Pipeline } from './model/pipeline.model';
import { Project } from './model/project.model';
import { User } from './model/user.model';
import { ApplicationService } from './service/application/application.service';
import { ApplicationStore } from './service/application/application.store';
import { AuthentificationStore } from './service/auth/authentification.store';
import { PipelineService } from './service/pipeline/pipeline.service';
import { PipelineStore } from './service/pipeline/pipeline.store';
import { ProjectService } from './service/project/project.service';
import { ProjectStore } from './service/project/project.store';
import { SharedModule } from './shared/shared.module';
import { NgxsStoreModule } from './store/store.module';

describe('App: CDS', () => {

let injector: Injector;
let authStore: AuthentificationStore;
let projectStore: ProjectStore;
let applicationStore: ApplicationStore;
let pipelineStore: PipelineStore;

beforeEach(() => {
TestBed.configureTestingModule({
Expand All @@ -55,17 +49,11 @@ describe('App: CDS', () => {

injector = getTestBed();
authStore = injector.get(AuthentificationStore);
projectStore = injector.get(ProjectStore);
applicationStore = injector.get(ApplicationStore);
pipelineStore = injector.get(PipelineStore);
});

afterEach(() => {
injector = undefined;
authStore = undefined;
projectStore = undefined;
applicationStore = undefined;
pipelineStore = undefined;
});


Expand Down
73 changes: 41 additions & 32 deletions ui/src/app/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ActivatedRoute } from '@angular/router';
import { TranslateService } from '@ngx-translate/core';
import { Store } from '@ngxs/store';
import { cloneDeep } from 'lodash';
import { filter, first } from 'rxjs/operators';
import { filter } from 'rxjs/operators';
import { Subscription } from 'rxjs/Subscription';
import { Broadcast, BroadcastEvent } from './model/broadcast.model';
import { Event, EventType } from './model/event.model';
Expand All @@ -16,14 +16,15 @@ import { BroadcastStore } from './service/broadcast/broadcast.store';
import { RouterService, TimelineStore } from './service/services.module';
import { WorkflowRunService } from './service/workflow/run/workflow.run.service';
import { WorkflowEventStore } from './service/workflow/workflow.event.store';
import { WorkflowStore } from './service/workflow/workflow.store';
import { ToastService } from './shared/toast/ToastService';
import { DeleteFromCacheApplication, ExternalChangeApplication, ResyncApplication } from './store/applications.action';
import { ApplicationsState, ApplicationsStateModel } from './store/applications.state';
import { DeleteFromCachePipeline, ExternalChangePipeline, ResyncPipeline } from './store/pipelines.action';
import { PipelinesState, PipelinesStateModel } from './store/pipelines.state';
import * as projectActions from './store/project.action';
import { ProjectState, ProjectStateModel } from './store/project.state';
import { DeleteFromCacheWorkflow, ExternalChangeWorkflow, ResyncWorkflow } from './store/workflows.action';
import { WorkflowsState, WorkflowsStateModel } from './store/workflows.state';

@Injectable()
export class AppService {
Expand All @@ -40,7 +41,6 @@ export class AppService {
private _authStore: AuthentificationStore,
private _translate: TranslateService,
private _workflowEventStore: WorkflowEventStore,
private _wfStore: WorkflowStore,
private _broadcastStore: BroadcastStore,
private _timelineStore: TimelineStore,
private _toast: ToastService,
Expand Down Expand Up @@ -214,8 +214,8 @@ export class AppService {
if (!event || !event.type_event) {
return
}
let pipKey = event.project_key + '-' + event.pipeline_name;

const pipKey = event.project_key + '-' + event.pipeline_name;
this.store.selectOnce(PipelinesState).subscribe((pips: PipelinesStateModel) => {
if (!pips || !pips.pipelines || !pips.pipelines[pipKey]) {
return;
Expand Down Expand Up @@ -260,37 +260,46 @@ export class AppService {
if (!event || !event.type_event) {
return
}
let wfKey = event.project_key + '-' + event.workflow_name;
this._wfStore.getWorkflows(event.project_key).pipe(first()).subscribe(wfs => {
if (!wfs) {
return;
}

if (!wfs.get(wfKey)) {
return;
}

if (event.type_event === EventType.WORKFLOW_DELETE) {
this._wfStore.removeFromStore(wfKey);
this.store.dispatch(new projectActions.DeleteWorkflowInProject({ workflowName: event.workflow_name }));
return;
}
this.store.selectOnce(WorkflowsState)
.pipe(filter((wfs) => wfs != null))
.subscribe((wfs: WorkflowsStateModel) => {
const wfKey = event.project_key + '-' + event.workflow_name;
if (!wfs || !wfs.workflows || !wfs.workflows[wfKey]) {
return;
}
if (event.type_event === EventType.WORKFLOW_DELETE) {
this.store.dispatch(new DeleteFromCacheWorkflow({
projectKey: event.project_key,
workflowName: event.workflow_name
}));
this.store.dispatch(new projectActions.DeleteWorkflowInProject({ workflowName: event.workflow_name }));
return;
}

// update workflow
if (this.routeParams['key'] && this.routeParams['key'] === event.project_key
&& this.routeParams['workflowName'] === event.workflow_name) {
if (event.username !== this._authStore.getUser().username) {
this._wfStore.externalModification(wfKey);
this._toast.info('', this._translate.instant('warning_workflow', { username: event.username }));
return
// update workflow
if (this.routeParams['key'] && this.routeParams['key'] === event.project_key
&& this.routeParams['workflowName'] === event.workflow_name) {
if (event.username !== this._authStore.getUser().username) {
this.store.dispatch(new ExternalChangeWorkflow({
projectKey: event.project_key,
workflowName: event.workflow_name
}));
this._toast.info('', this._translate.instant('warning_workflow', { username: event.username }));
return;
}
} else {
this.store.dispatch(new DeleteFromCacheWorkflow({
projectKey: event.project_key,
workflowName: event.workflow_name
}));
return;
}
} else {
this._wfStore.removeFromStore(wfKey);
return;
}

this._wfStore.resync(event.project_key, event.workflow_name);
});
this.store.dispatch(new ResyncWorkflow({
projectKey: event.project_key,
workflowName: event.workflow_name
}));
});
}

updateWorkflowRunCache(event: Event): void {
Expand Down
5 changes: 5 additions & 0 deletions ui/src/app/model/workflow.model.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { notificationTypes, UserNotificationSettings } from 'app/model/notification.model';
import { Application } from './application.model';
import { AuditWorkflow } from './audit.model';
import { Environment } from './environment.model';
import { GroupPermission } from './group.model';
import { ProjectIntegration } from './integration.model';
Expand Down Expand Up @@ -48,6 +49,10 @@ export class Workflow {
workflow_data: WorkflowData;
as_code_events: Array<AsCodeEvents>;

preview: Workflow;
asCode: string;
audits: AuditWorkflow[];

// UI params
externalChange: boolean;
forceRefresh: boolean;
Expand Down
Loading

0 comments on commit 34fba71

Please sign in to comment.