+
+ You have not created the subscription. Therefore you cannot change the plan.
+
+
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 6dc4b5e49..b181af1f4 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
@@ -13,7 +13,8 @@ import { Observable, Subscription } from 'rxjs';
import {
ContentCreated,
ContentDeleted,
- ContentUpdated
+ ContentUpdated,
+ ContentVersionSelected
} from './../messages';
import {
@@ -38,6 +39,7 @@ import {
})
export class ContentPageComponent extends AppComponentBase implements CanComponentDeactivate, OnDestroy, OnInit {
private contentDeletedSubscription: Subscription;
+ private contentVersionSelectedSubscription: Subscription;
private version = new Version('');
private content: ContentDto;
@@ -63,6 +65,7 @@ export class ContentPageComponent extends AppComponentBase implements CanCompone
}
public ngOnDestroy() {
+ this.contentVersionSelectedSubscription.unsubscribe();
this.contentDeletedSubscription.unsubscribe();
}
@@ -71,6 +74,12 @@ export class ContentPageComponent extends AppComponentBase implements CanCompone
this.languages = routeData['appLanguages'];
+ this.contentVersionSelectedSubscription =
+ this.messageBus.of(ContentVersionSelected)
+ .subscribe(message => {
+ this.loadVersion(message.version);
+ });
+
this.contentDeletedSubscription =
this.messageBus.of(ContentDeleted)
.subscribe(message => {
@@ -146,6 +155,22 @@ export class ContentPageComponent extends AppComponentBase implements CanCompone
}
}
+ private loadVersion(version: number) {
+ if (!this.isNewMode && this.content) {
+ this.appNameOnce()
+ .switchMap(app => this.contentsService.getVersionData(app, this.schema.name, this.contentId!, new Version(version.toString())))
+ .subscribe(dto => {
+ this.content = this.content.setData(dto);
+
+ this.emitContentUpdated(this.content);
+ this.notifyInfo('Content version loaded successfully.');
+ this.populateContentForm();
+ }, error => {
+ this.notifyError(error);
+ });
+ }
+ }
+
private back() {
this.router.navigate(['../'], { relativeTo: this.route, replaceUrl: true });
}
diff --git a/src/Squidex/app/features/content/pages/messages.ts b/src/Squidex/app/features/content/pages/messages.ts
index 569c201ad..13a340fcd 100644
--- a/src/Squidex/app/features/content/pages/messages.ts
+++ b/src/Squidex/app/features/content/pages/messages.ts
@@ -30,7 +30,6 @@ export class ContentDeleted {
export class ContentVersionSelected {
constructor(
- public readonly id: string,
public readonly version: number
) {
}
diff --git a/src/Squidex/app/shared/services/contents.service.spec.ts b/src/Squidex/app/shared/services/contents.service.spec.ts
index 41eaa39cc..849c9f77e 100644
--- a/src/Squidex/app/shared/services/contents.service.spec.ts
+++ b/src/Squidex/app/shared/services/contents.service.spec.ts
@@ -51,6 +51,15 @@ describe('ContentDto', () => {
expect(content_2.lastModified).toEqual(now);
expect(content_2.lastModifiedBy).toEqual('me');
});
+
+ it('should update data property when setting data', () => {
+ const newData = {};
+
+ const content_1 = new ContentDto('1', true, false, 'other', 'other', DateTime.now(), DateTime.now(), { data: 1 }, null);
+ const content_2 = content_1.setData(newData);
+
+ expect(content_2.data).toBe(newData);
+ });
});
describe('ContentsService', () => {
@@ -270,6 +279,27 @@ describe('ContentsService', () => {
new Version('11')));
}));
+ it('should make get request to get versioned content data',
+ inject([ContentsService, HttpTestingController], (contentsService: ContentsService, httpMock: HttpTestingController) => {
+
+ const response = {};
+
+ let data: any | null = null;
+
+ contentsService.getVersionData('my-app', 'my-schema', 'content1', version).subscribe(result => {
+ data = result;
+ });
+
+ const req = httpMock.expectOne('http://service/p/api/content/my-app/my-schema/content1/1');
+
+ expect(req.request.method).toEqual('GET');
+ expect(req.request.headers.get('If-Match')).toBe(version.value);
+
+ req.flush(response);
+
+ expect(data).toBe(response);
+ }));
+
it('should make put request to update content',
inject([ContentsService, HttpTestingController], (contentsService: ContentsService, httpMock: HttpTestingController) => {
diff --git a/src/Squidex/app/shared/services/contents.service.ts b/src/Squidex/app/shared/services/contents.service.ts
index a4cad43c3..0e70d45a9 100644
--- a/src/Squidex/app/shared/services/contents.service.ts
+++ b/src/Squidex/app/shared/services/contents.service.ts
@@ -41,6 +41,19 @@ export class ContentDto {
) {
}
+ public setData(data: any): ContentDto {
+ return new ContentDto(
+ this.id,
+ this.isPublished,
+ this.isDeleted,
+ this.createdBy,
+ this.lastModifiedBy,
+ this.created,
+ this.lastModified,
+ data,
+ this.version);
+ }
+
public publish(user: string, now?: DateTime): ContentDto {
return new ContentDto(
this.id,
@@ -204,6 +217,13 @@ export class ContentsService {
.pretifyError('Failed to delete content. Please reload.');
}
+ public getVersionData(appName: string, schemaName: string, id: string, version?: Version): Observable
{
+ const url = this.apiUrl.buildUrl(`/api/content/${appName}/${schemaName}/${id}/${version.value}`);
+
+ return HTTP.getVersioned(this.http, url, version)
+ .pretifyError('Failed to load data. Please reload.');
+ }
+
public publishContent(appName: string, schemaName: string, id: string, version?: Version): Observable {
const url = this.apiUrl.buildUrl(`/api/content/${appName}/${schemaName}/${id}/publish`);