Finalize support for offline/online sync logic
This commit is contained in:
parent
36ea67a9d6
commit
36d97c9eca
@ -202,15 +202,27 @@ export class ApiService {
|
||||
|
||||
public async syncOfflineData() {
|
||||
const dirtyRecords = await this.db.getDirtyRecords();
|
||||
await new Promise(async (res, rej) => {
|
||||
const uuidMap = await new Promise(async (res, rej) => {
|
||||
this.post('/offline/sync', { dirtyRecords }).subscribe({
|
||||
next: async result => {
|
||||
console.log('sync result', result);
|
||||
res();
|
||||
res(result.data);
|
||||
},
|
||||
error: rej,
|
||||
});
|
||||
});
|
||||
|
||||
// For now, we're not going to handle this great.
|
||||
// Rather, we're going to wait until the server supports proper versioning and date-based offline updates.
|
||||
// In the meantime, just purge everything and reload.
|
||||
await this.prefetchOfflineData(true);
|
||||
|
||||
const offlineKV = await this.db.getKeyValue('needs_online_sync');
|
||||
offlineKV.data = false;
|
||||
await offlineKV.save();
|
||||
|
||||
// Pre-fetch menu items
|
||||
await this.getMenuItems();
|
||||
}
|
||||
|
||||
public async prefetchOfflineData(overwriteLocalData = false) {
|
||||
|
@ -109,7 +109,6 @@ export class Page extends Model<IPage> implements IPage {
|
||||
}
|
||||
|
||||
public fillFromRecord(record: any) {
|
||||
console.log('page fill from record', record);
|
||||
this.UUID = record.UUID;
|
||||
this.Name = record.Name;
|
||||
this.OrgUserId = record.OrgUserId;
|
||||
@ -117,7 +116,6 @@ export class Page extends Model<IPage> implements IPage {
|
||||
this.IsVisibleInMenu = record.IsVisibleInMenu;
|
||||
this.ParentId = record.ParentId;
|
||||
this.NodeIds = record.NodeIds;
|
||||
console.log('setting node ids', this.NodeIds, record.NodeIds);
|
||||
this.CreatedAt = String(record.CreatedAt);
|
||||
this.UpdatedAt = String(record.UpdatedAt);
|
||||
this.Active = record.Active;
|
||||
|
@ -168,7 +168,6 @@ export class EditorService {
|
||||
}
|
||||
|
||||
async savePage(page: PageRecord): Promise<void> {
|
||||
console.log('saving page', page);
|
||||
await new Promise(async (res, rej) => {
|
||||
const existingLocalPage = await this.db.pages.where({ UUID: page.UUID }).first() as Page;
|
||||
const saveData = page.toSave();
|
||||
@ -381,7 +380,6 @@ export class EditorService {
|
||||
|
||||
if ( localPage ) {
|
||||
localPage.NodeIds.push(result.data.UUID);
|
||||
console.log('saving local page data', result.data.UUID);
|
||||
await localPage.save();
|
||||
}
|
||||
|
||||
@ -446,7 +444,6 @@ export class EditorService {
|
||||
baseHost.PageId = this.currentPage.UUID;
|
||||
|
||||
const host = await this.saveNodeToPage(this.currentPage, baseHost);
|
||||
console.log('added node to page', host);
|
||||
|
||||
let placed = false;
|
||||
if ( position === 'before' && positionNodeId ) {
|
||||
|
Loading…
Reference in New Issue
Block a user