diff --git a/src/Squidex/app/features/content/pages/content/content-page.component.ts b/src/Squidex/app/features/content/pages/content/content-page.component.ts index f8a5fd83a..2fdc5edd0 100644 --- a/src/Squidex/app/features/content/pages/content/content-page.component.ts +++ b/src/Squidex/app/features/content/pages/content/content-page.component.ts @@ -12,7 +12,9 @@ import { Observable, Subscription } from 'rxjs'; import { ContentCreated, + ContentPublished, ContentRemoved, + ContentUnpublished, ContentUpdated, ContentVersionSelected } from './../messages'; @@ -38,6 +40,8 @@ import { templateUrl: './content-page.component.html' }) export class ContentPageComponent extends AppComponentBase implements CanComponentDeactivate, OnDestroy, OnInit { + private contentPublishedSubscription: Subscription; + private contentUnpublishedSubscription: Subscription; private contentDeletedSubscription: Subscription; private contentVersionSelectedSubscription: Subscription; @@ -63,6 +67,8 @@ export class ContentPageComponent extends AppComponentBase implements CanCompone public ngOnDestroy() { this.contentVersionSelectedSubscription.unsubscribe(); + this.contentUnpublishedSubscription.unsubscribe(); + this.contentPublishedSubscription.unsubscribe(); this.contentDeletedSubscription.unsubscribe(); } @@ -77,6 +83,22 @@ export class ContentPageComponent extends AppComponentBase implements CanCompone this.loadVersion(message.version); }); + this.contentPublishedSubscription = + this.messageBus.of(ContentPublished) + .subscribe(message => { + if (this.content && message.content.id === this.content.id) { + this.content = this.content.replaceVersion(message.content.version); + } + }); + + this.contentUnpublishedSubscription = + this.messageBus.of(ContentUnpublished) + .subscribe(message => { + if (this.content && message.content.id === this.content.id) { + this.content = this.content.replaceVersion(message.content.version); + } + }); + this.contentDeletedSubscription = this.messageBus.of(ContentRemoved) .subscribe(message => { diff --git a/src/Squidex/app/features/content/pages/contents/contents-page.component.ts b/src/Squidex/app/features/content/pages/contents/contents-page.component.ts index 617eb42b8..057eeb839 100644 --- a/src/Squidex/app/features/content/pages/contents/contents-page.component.ts +++ b/src/Squidex/app/features/content/pages/contents/contents-page.component.ts @@ -12,7 +12,9 @@ import { Subscription } from 'rxjs'; import { ContentCreated, + ContentPublished, ContentRemoved, + ContentUnpublished, ContentUpdated } from './../messages'; @@ -118,6 +120,8 @@ export class ContentsPageComponent extends AppComponentBase implements OnDestroy .switchMap(app => this.contentsService.publishContent(app, this.schema.name, content.id, content.version)) .subscribe(() => { this.contentItems = this.contentItems.replaceBy('id', content.publish(this.authService.user!.token)); + + this.emitContentPublished(content); }, error => { this.notifyError(error); }); @@ -128,6 +132,8 @@ export class ContentsPageComponent extends AppComponentBase implements OnDestroy .switchMap(app => this.contentsService.unpublishContent(app, this.schema.name, content.id, content.version)) .subscribe(() => { this.contentItems = this.contentItems.replaceBy('id', content.unpublish(this.authService.user!.token)); + + this.emitContentUnpublished(content); }, error => { this.notifyError(error); }); @@ -216,6 +222,14 @@ export class ContentsPageComponent extends AppComponentBase implements OnDestroy this.languageSelected = language; } + private emitContentPublished(content: ContentDto) { + this.messageBus.emit(new ContentPublished(content)); + } + + private emitContentUnpublished(content: ContentDto) { + this.messageBus.emit(new ContentUnpublished(content)); + } + private emitContentRemoved(content: ContentDto) { this.messageBus.emit(new ContentRemoved(content)); } diff --git a/src/Squidex/app/features/content/pages/messages.ts b/src/Squidex/app/features/content/pages/messages.ts index 9834b95b2..9414c9c30 100644 --- a/src/Squidex/app/features/content/pages/messages.ts +++ b/src/Squidex/app/features/content/pages/messages.ts @@ -33,4 +33,18 @@ export class ContentVersionSelected { public readonly version: number ) { } +} + +export class ContentPublished { + constructor( + public readonly content: ContentDto + ) { + } +} + +export class ContentUnpublished { + constructor( + public readonly content: ContentDto + ) { + } } \ No newline at end of file diff --git a/src/Squidex/app/shared/services/contents.service.spec.ts b/src/Squidex/app/shared/services/contents.service.spec.ts index a4ba51572..305b76ee1 100644 --- a/src/Squidex/app/shared/services/contents.service.spec.ts +++ b/src/Squidex/app/shared/services/contents.service.spec.ts @@ -79,6 +79,13 @@ describe('ContentDto', () => { expect(content_2.data).toBe(newData); }); + + it('should replace version', () => { + const content_1 = new ContentDto('1', 'Published', creator, creator, creation, creation, { data: 1 }, version); + const content_2 = content_1.replaceVersion(new Version('2')); + + expect(content_2.version).toEqual(new Version('2')); + }); }); describe('ContentsService', () => { diff --git a/src/Squidex/app/shared/services/contents.service.ts b/src/Squidex/app/shared/services/contents.service.ts index c01637faf..714cb7751 100644 --- a/src/Squidex/app/shared/services/contents.service.ts +++ b/src/Squidex/app/shared/services/contents.service.ts @@ -69,6 +69,16 @@ export class ContentDto { return this.changeStatus('Draft', user, now); } + public replaceVersion(version: Version): ContentDto { + return new ContentDto( + this.id, + this.status, + this.createdBy, this.lastModifiedBy, + this.created, this.lastModified, + this.data, + version); + } + private changeStatus(status: string, user: string, now?: DateTime): ContentDto { return new ContentDto( this.id,