From 045a9151b53734a444d04bfec5bd751a31352253 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Thu, 27 Jun 2019 18:49:55 +0200 Subject: [PATCH] State. --- .../workflow-transition.component.ts | 3 ++ .../workflows/workflows-page.component.html | 40 ++++++++++--------- .../workflows/workflows-page.component.ts | 27 ++++++------- .../app/shared/services/workflows.service.ts | 5 +++ .../app/shared/state/workflows.state.spec.ts | 4 +- .../app/shared/state/workflows.state.ts | 11 ++--- 6 files changed, 51 insertions(+), 39 deletions(-) diff --git a/src/Squidex/app/features/settings/pages/workflows/workflow-transition.component.ts b/src/Squidex/app/features/settings/pages/workflows/workflow-transition.component.ts index 9d5260627..46e02f769 100644 --- a/src/Squidex/app/features/settings/pages/workflows/workflow-transition.component.ts +++ b/src/Squidex/app/features/settings/pages/workflows/workflow-transition.component.ts @@ -25,6 +25,9 @@ export class WorkflowTransitionComponent { @Input() public roles: RoleDto[]; + @Input() + public disabled: boolean; + @Output() public update = new EventEmitter(); diff --git a/src/Squidex/app/features/settings/pages/workflows/workflows-page.component.html b/src/Squidex/app/features/settings/pages/workflows/workflows-page.component.html index 9c8ec9858..97ca153bc 100644 --- a/src/Squidex/app/features/settings/pages/workflows/workflows-page.component.html +++ b/src/Squidex/app/features/settings/pages/workflows/workflows-page.component.html @@ -10,7 +10,7 @@ - + @@ -20,23 +20,25 @@ - - - - - - + + + + + + + + \ No newline at end of file diff --git a/src/Squidex/app/features/settings/pages/workflows/workflows-page.component.ts b/src/Squidex/app/features/settings/pages/workflows/workflows-page.component.ts index e3aa8571a..c7e38ab74 100644 --- a/src/Squidex/app/features/settings/pages/workflows/workflows-page.component.ts +++ b/src/Squidex/app/features/settings/pages/workflows/workflows-page.component.ts @@ -11,6 +11,7 @@ import { MathHelper, RolesState, WorkflowDto, + WorkflowsState, WorkflowStep, WorkflowStepValues, WorkflowTransition, @@ -28,31 +29,29 @@ export class WorkflowsPageComponent implements OnInit { public workflow: WorkflowDto; constructor( - public readonly rolesState: RolesState + public readonly rolesState: RolesState, + public readonly workflowsState: WorkflowsState ) { } public ngOnInit() { - this.rolesState.load(); + this.workflowsState.load() + .subscribe(workflow => { + this.workflow = workflow; + }); - this.workflow = - new WorkflowDto() - .setStep('Archived', { color: '#eb3142', noUpdate: true }) - .setStep('Draft', { color: '#8091a5' }) - .setStep('Published', { color: '#4bb958', isLocked: true }) - .setTransition('Archived', 'Draft') - .setTransition('Draft', 'Archived') - .setTransition('Draft', 'Published') - .setTransition('Published', 'Draft') - .setTransition('Published', 'Archived'); + this.rolesState.load(); } public reload() { - return; + this.workflowsState.load(true) + .subscribe(workflow => { + this.workflow = workflow; + }); } public save() { - return; + this.workflowsState.save(this.workflow); } public addStep() { diff --git a/src/Squidex/app/shared/services/workflows.service.ts b/src/Squidex/app/shared/services/workflows.service.ts index 3fd8ae479..9e7f5cdbc 100644 --- a/src/Squidex/app/shared/services/workflows.service.ts +++ b/src/Squidex/app/shared/services/workflows.service.ts @@ -10,6 +10,7 @@ import { Observable, of } from 'rxjs'; import { compareStringsAsc, + hasAnyLink, Resource, ResourceLinks, Version, @@ -22,6 +23,8 @@ export type WorkflowPayload = { workflow: WorkflowDto; } & Resource; export class WorkflowDto { public readonly _links: ResourceLinks; + public readonly canUpdate: boolean; + public static DEFAULT = new WorkflowDto() .setStep('Archived', { color: '#eb3142', noUpdate: true }) @@ -43,6 +46,8 @@ export class WorkflowDto { this.transitions.sort((a, b) => compareStringsAsc(a.to, b.to)); this._links = links; + + this.canUpdate = hasAnyLink(links, 'update'); } public getOpenSteps(step: WorkflowStep) { diff --git a/src/Squidex/app/shared/state/workflows.state.spec.ts b/src/Squidex/app/shared/state/workflows.state.spec.ts index c4e52dcaa..41810332e 100644 --- a/src/Squidex/app/shared/state/workflows.state.spec.ts +++ b/src/Squidex/app/shared/state/workflows.state.spec.ts @@ -87,9 +87,11 @@ describe('WorkflowsState', () => { workflowsService.setup(x => x.putWorkflow(app, oldWorkflow, request, version)) .returns(() => of(versioned(newVersion, updated))).verifiable(); - workflowsState.save().subscribe(); + workflowsState.save(oldWorkflow.workflow).subscribe(); expectNewWorkflows(updated); + + dialogs.verify(x => x.notifyInfo(It.isAnyString()), Times.once()); }); function expectNewWorkflows(updated: WorkflowPayload) { diff --git a/src/Squidex/app/shared/state/workflows.state.ts b/src/Squidex/app/shared/state/workflows.state.ts index 2829f06f7..b43a558e0 100644 --- a/src/Squidex/app/shared/state/workflows.state.ts +++ b/src/Squidex/app/shared/state/workflows.state.ts @@ -13,6 +13,7 @@ import { tap } from 'rxjs/operators'; import { DialogService, + shareMapSubscribed, shareSubscribed, State, Version @@ -53,7 +54,7 @@ export class WorkflowsState extends State { super({ version: Version.EMPTY }); } - public load(isReload = false): Observable { + public load(isReload = false): Observable { if (!isReload) { this.resetState(); } @@ -66,15 +67,15 @@ export class WorkflowsState extends State { this.replaceWorkflow(payload, version); }), - shareSubscribed(this.dialogs)); + shareMapSubscribed(this.dialogs, x => x.payload.workflow)); } - public save(): Observable { - const workflow = this.snapshot.workflow!; - + public save(workflow: WorkflowDto): Observable { return this.workflowsService.putWorkflow(this.appName, workflow, workflow.serialize(), this.version).pipe( tap(({ version, payload }) => { this.replaceWorkflow(payload, version); + + this.dialogs.notifyInfo('Workflow has been saved.'); }), shareSubscribed(this.dialogs)); }