Finalize support for offline/online sync logic
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-02 11:16:46 -06:00
parent 36ea67a9d6
commit 36d97c9eca
Signed by: garrettmills
GPG Key ID: D2BF5FBA8298F246
3 changed files with 14 additions and 7 deletions

View File

@ -202,15 +202,27 @@ export class ApiService {
public async syncOfflineData() { public async syncOfflineData() {
const dirtyRecords = await this.db.getDirtyRecords(); 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({ this.post('/offline/sync', { dirtyRecords }).subscribe({
next: async result => { next: async result => {
console.log('sync result', result); console.log('sync result', result);
res(); res(result.data);
}, },
error: rej, 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) { public async prefetchOfflineData(overwriteLocalData = false) {

View File

@ -109,7 +109,6 @@ export class Page extends Model<IPage> implements IPage {
} }
public fillFromRecord(record: any) { public fillFromRecord(record: any) {
console.log('page fill from record', record);
this.UUID = record.UUID; this.UUID = record.UUID;
this.Name = record.Name; this.Name = record.Name;
this.OrgUserId = record.OrgUserId; this.OrgUserId = record.OrgUserId;
@ -117,7 +116,6 @@ export class Page extends Model<IPage> implements IPage {
this.IsVisibleInMenu = record.IsVisibleInMenu; this.IsVisibleInMenu = record.IsVisibleInMenu;
this.ParentId = record.ParentId; this.ParentId = record.ParentId;
this.NodeIds = record.NodeIds; this.NodeIds = record.NodeIds;
console.log('setting node ids', this.NodeIds, record.NodeIds);
this.CreatedAt = String(record.CreatedAt); this.CreatedAt = String(record.CreatedAt);
this.UpdatedAt = String(record.UpdatedAt); this.UpdatedAt = String(record.UpdatedAt);
this.Active = record.Active; this.Active = record.Active;

View File

@ -168,7 +168,6 @@ export class EditorService {
} }
async savePage(page: PageRecord): Promise<void> { async savePage(page: PageRecord): Promise<void> {
console.log('saving page', page);
await new Promise(async (res, rej) => { await new Promise(async (res, rej) => {
const existingLocalPage = await this.db.pages.where({ UUID: page.UUID }).first() as Page; const existingLocalPage = await this.db.pages.where({ UUID: page.UUID }).first() as Page;
const saveData = page.toSave(); const saveData = page.toSave();
@ -381,7 +380,6 @@ export class EditorService {
if ( localPage ) { if ( localPage ) {
localPage.NodeIds.push(result.data.UUID); localPage.NodeIds.push(result.data.UUID);
console.log('saving local page data', result.data.UUID);
await localPage.save(); await localPage.save();
} }
@ -446,7 +444,6 @@ export class EditorService {
baseHost.PageId = this.currentPage.UUID; baseHost.PageId = this.currentPage.UUID;
const host = await this.saveNodeToPage(this.currentPage, baseHost); const host = await this.saveNodeToPage(this.currentPage, baseHost);
console.log('added node to page', host);
let placed = false; let placed = false;
if ( position === 'before' && positionNodeId ) { if ( position === 'before' && positionNodeId ) {