Add ability to load page version in editor service and show in version modal
This commit is contained in:
parent
b2eb33f6a0
commit
cd37ea1df1
@ -19,7 +19,7 @@
|
|||||||
</ion-item>
|
</ion-item>
|
||||||
</ion-list>
|
</ion-list>
|
||||||
<div class="preview">
|
<div class="preview">
|
||||||
<app-editor [pageId]="pageId" *ngIf="selectedVersion" [hosted]="true" [readonly]="true" #editor></app-editor>
|
<app-editor [pageId]="pageId" *ngIf="selectedVersion" [hosted]="true" [readonly]="true" [version]="selectedVersion.versionNum" #editor></app-editor>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
@ -26,10 +26,7 @@ export class VersionModalComponent implements OnInit {
|
|||||||
|
|
||||||
async ngOnInit() {
|
async ngOnInit() {
|
||||||
this.pageVersions = await this.editorService.loadPageVersions(this.pageId);
|
this.pageVersions = await this.editorService.loadPageVersions(this.pageId);
|
||||||
this.selectedVersion = this.pageVersions[0];
|
this.onVersionClick(this.pageVersions[0]);
|
||||||
setTimeout(() => {
|
|
||||||
this.onVersionClick(this.pageVersions[0]);
|
|
||||||
}, 100);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dismiss() {
|
dismiss() {
|
||||||
@ -38,8 +35,10 @@ export class VersionModalComponent implements OnInit {
|
|||||||
|
|
||||||
async onVersionClick(version: PageVersionRecord) {
|
async onVersionClick(version: PageVersionRecord) {
|
||||||
this.selectedVersion = version;
|
this.selectedVersion = version;
|
||||||
if ( this.editor ) {
|
setTimeout(() => {
|
||||||
this.editor.ionViewDidEnter();
|
if ( this.editor ) {
|
||||||
}
|
this.editor.ionViewDidEnter();
|
||||||
|
}
|
||||||
|
}, 300);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ export class EditorPage implements OnInit {
|
|||||||
|
|
||||||
ionViewDidEnter() {
|
ionViewDidEnter() {
|
||||||
if ( this.pageId ) {
|
if ( this.pageId ) {
|
||||||
this.editorService.startEditing(this.pageId);
|
this.editorService.startEditing(this.pageId, this.version);
|
||||||
} else if ( !this.hosted ) {
|
} else if ( !this.hosted ) {
|
||||||
this.router.navigate(['/home']);
|
this.router.navigate(['/home']);
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,7 @@ export class EditorService {
|
|||||||
protected ready$: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
|
protected ready$: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
|
||||||
protected subs: Subscription[] = [];
|
protected subs: Subscription[] = [];
|
||||||
protected saving = false;
|
protected saving = false;
|
||||||
|
protected currentPageVersion?: number;
|
||||||
public forceReadonly = false;
|
public forceReadonly = false;
|
||||||
protected saveTriggered = false;
|
protected saveTriggered = false;
|
||||||
public notAvailable = false;
|
public notAvailable = false;
|
||||||
@ -110,14 +111,15 @@ export class EditorService {
|
|||||||
return inst;
|
return inst;
|
||||||
}
|
}
|
||||||
|
|
||||||
async startEditing(pageId: string) {
|
async startEditing(pageId: string, version?: number) {
|
||||||
if ( this.currentPage ) {
|
if ( this.currentPage ) {
|
||||||
await this.stopEditing();
|
await this.stopEditing();
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.currentPage = await this.loadPage(pageId);
|
this.currentPageVersion = version;
|
||||||
this.currentNodes = await this.loadNodes(pageId);
|
this.currentPage = await this.loadPage(pageId, version);
|
||||||
|
this.currentNodes = await this.loadNodes(pageId, version);
|
||||||
this.notAvailable = false;
|
this.notAvailable = false;
|
||||||
await this.ready$.next(true);
|
await this.ready$.next(true);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -556,7 +558,7 @@ export class EditorService {
|
|||||||
delete this.nodeIdToEditorContract[nodeId];
|
delete this.nodeIdToEditorContract[nodeId];
|
||||||
}
|
}
|
||||||
|
|
||||||
async loadPage(pageId: string): Promise<PageRecord> {
|
async loadPage(pageId: string, version?: number): Promise<PageRecord> {
|
||||||
return new Promise(async (res, rej) => {
|
return new Promise(async (res, rej) => {
|
||||||
const existingLocalPage = await this.db.pages.where({ UUID: pageId }).first() as Page;
|
const existingLocalPage = await this.db.pages.where({ UUID: pageId }).first() as Page;
|
||||||
|
|
||||||
@ -570,7 +572,7 @@ export class EditorService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If we're online, fetch the page record and store it locally
|
// If we're online, fetch the page record and store it locally
|
||||||
this.api.get(`/page/${pageId}`).subscribe({
|
this.api.get(`/page/${pageId}${version ? '?version=' + version : ''}`).subscribe({
|
||||||
next: async result => {
|
next: async result => {
|
||||||
const page = new PageRecord(result.data);
|
const page = new PageRecord(result.data);
|
||||||
|
|
||||||
@ -632,7 +634,7 @@ export class EditorService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async loadNodes(pageId: string): Promise<HostRecord[]> {
|
async loadNodes(pageId: string, version?: number): Promise<HostRecord[]> {
|
||||||
return new Promise(async (res, rej) => {
|
return new Promise(async (res, rej) => {
|
||||||
const existingNodes = await this.db.pageNodes.where({ PageId: pageId }).toArray() as PageNode[];
|
const existingNodes = await this.db.pageNodes.where({ PageId: pageId }).toArray() as PageNode[];
|
||||||
|
|
||||||
@ -650,7 +652,7 @@ export class EditorService {
|
|||||||
return res(inflateRecords(parsedRecords));
|
return res(inflateRecords(parsedRecords));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.api.get(`/page/${pageId}/nodes`).subscribe({
|
this.api.get(`/page/${pageId}/nodes${version ? '?version=' + version : ''}`).subscribe({
|
||||||
next: async result => {
|
next: async result => {
|
||||||
// If we got resolved records, delete the local ones to replace them
|
// If we got resolved records, delete the local ones to replace them
|
||||||
await this.db.pageNodes.where({ PageId: pageId }).delete();
|
await this.db.pageNodes.where({ PageId: pageId }).delete();
|
||||||
|
Loading…
Reference in New Issue
Block a user