Add interface logic for reverting page to previous version
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is passing

This commit is contained in:
Garrett Mills 2020-11-06 12:43:13 -06:00
parent cd37ea1df1
commit 4c0fbc7594
Signed by: garrettmills
GPG Key ID: D2BF5FBA8298F246
6 changed files with 90 additions and 4 deletions

View File

@ -1,6 +1,14 @@
<div class="container">
<div class="header">
<div class="title">Page Versions</div>
<button
*ngIf="selectedVersion && !selectedVersion.currentVersion"
title="Revert to this version"
class="revert"
(click)="revertToVersion()"
>
Revert
</button>
<button title="Close" class="close" (click)="dismiss()">
<i class="fa fa-times"></i>
</button>

View File

@ -19,6 +19,11 @@
background: #ff6666;
color: white;
}
.revert {
color: red;
background: #eaeaea;
}
}
.contents {

View File

@ -29,8 +29,30 @@ export class VersionModalComponent implements OnInit {
this.onVersionClick(this.pageVersions[0]);
}
dismiss() {
this.modals.dismiss();
dismiss(reload = false) {
this.modals.dismiss(reload);
}
async revertToVersion() {
const alert = await this.alerts.create({
header: 'Revert page?',
message: `This will revert the current version of the page to version ${this.selectedVersion.versionNum}. Continue?`,
buttons: [
{
text: 'Keep It',
role: 'cancel',
},
{
text: 'Revert It',
handler: async () => {
await this.editorService.revertPageToVersion(this.pageId, this.selectedVersion.versionNum);
this.dismiss(true);
},
},
],
});
await alert.present();
}
async onVersionClick(version: PageVersionRecord) {

View File

@ -168,6 +168,12 @@ export class EditorPage implements OnInit {
cssClass: 'modal-big',
});
modal.onDidDismiss().then(reload => {
if ( reload ) {
this.editorService.startEditing(this.pageId);
}
});
await modal.present();
}
}

View File

@ -11,8 +11,8 @@ import {Database} from './db/Database';
import {DatabaseColumn} from './db/DatabaseColumn';
import {DatabaseEntry} from './db/DatabaseEntry';
import {FileGroup} from './db/FileGroup';
import {Page} from "./db/Page";
import {PageNode} from "./db/PageNode";
import {Page} from './db/Page';
import {PageNode} from './db/PageNode';
export class ResourceNotAvailableOfflineError extends Error {
constructor(msg = 'This resource is not yet available offline on this device.') {

View File

@ -634,6 +634,51 @@ export class EditorService {
});
}
async revertPageToVersion(pageId: string, versionNum: number): Promise<PageRecord> {
return new Promise(async (res, rej) => {
const existingLocalPage = await this.db.pages.where({ UUID: pageId }).first() as Page;
if ( this.api.isOffline ) {
return rej(new ResourceNotAvailableOfflineError());
}
this.api.post(`/page/${pageId}/versions/revert`, { version_num: versionNum }).subscribe({
next: async result => {
const page = new PageRecord(result.data);
if ( existingLocalPage ) {
existingLocalPage.fillFromRecord(result.data);
existingLocalPage.needsServerUpdate = 0;
await existingLocalPage.save();
} else {
const newLocalPage = new Page(
page.UUID,
page.Name,
page.OrgUserId,
page.IsPublic,
page.IsVisibleInMenu,
page.ParentId,
page.NodeIds,
String(page.CreatedAt),
String(page.UpdatedAt),
true,
page.CreatedUserId,
page.UpdateUserId,
page.ChildPageIds,
result.data.noDelete,
result.data.virtual,
);
await newLocalPage.save();
}
res(page);
},
error: rej,
});
});
}
async loadNodes(pageId: string, version?: number): Promise<HostRecord[]> {
return new Promise(async (res, rej) => {
const existingNodes = await this.db.pageNodes.where({ PageId: pageId }).toArray() as PageNode[];