Browse Source

Error when saving content with Edit Content screen open. Closes #116

pull/118/head
Sebastian Stehle 9 years ago
parent
commit
522b122bb0
  1. 22
      src/Squidex/app/features/content/pages/content/content-page.component.ts
  2. 14
      src/Squidex/app/features/content/pages/contents/contents-page.component.ts
  3. 14
      src/Squidex/app/features/content/pages/messages.ts
  4. 7
      src/Squidex/app/shared/services/contents.service.spec.ts
  5. 10
      src/Squidex/app/shared/services/contents.service.ts

22
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 => {

14
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));
}

14
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
) {
}
}

7
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', () => {

10
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,

Loading…
Cancel
Save