From 94c6a66dff27e4c23acd72deb16012b837c8ab6d Mon Sep 17 00:00:00 2001 From: garrettmills Date: Tue, 16 Mar 2021 10:39:06 -0500 Subject: [PATCH] Improve version modal previews and remove debugging logging --- src/app/app.module.ts | 1 - .../components/editor/code/code.component.ts | 2 +- .../editor/database/database.component.ts | 7 ++-- .../boolean/boolean-editor.component.ts | 1 - .../page-link/page-link-editor.component.ts | 2 -- .../editor/files/files.component.ts | 2 -- .../nodes/form-input/form-input.component.ts | 2 -- .../components/nodes/norm/norm.component.ts | 2 -- .../version-modal/version-modal.component.ts | 6 ++-- .../components/wysiwyg/wysiwyg.component.ts | 3 -- src/app/service/api.service.ts | 33 ++++++++++++++----- src/app/service/db/database.service.ts | 2 -- src/app/service/editor.service.ts | 1 - src/app/structures/HostRecord.ts | 2 ++ 14 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 08dcd34..ca795c7 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -57,7 +57,6 @@ export function getBaseHref(platformLocation: PlatformLocation): string { useValue: { highlight(code: string, lang: string, callback?: (error: any, code: string) => void): string { const highlighted = hljs.highlight(lang, code, true); - console.log('highlighed', highlighted); if ( callback ) { callback(null, highlighted.value); diff --git a/src/app/components/editor/code/code.component.ts b/src/app/components/editor/code/code.component.ts index 795548b..63de0fe 100644 --- a/src/app/components/editor/code/code.component.ts +++ b/src/app/components/editor/code/code.component.ts @@ -152,7 +152,7 @@ export class CodeComponent extends EditorNodeContract implements OnInit { res(); }).catch(rej); } else { - this.api.getCodium(this.page.UUID, this.node.UUID, this.node.Value.Value).then(data => { + this.api.getCodium(this.page.UUID, this.node.UUID, this.node.Value.Value, this.node.associatedTypeVersionNum).then(data => { this.dbRecord = data; this.initialValue = this.dbRecord.code; this.editorValue = this.dbRecord.code; diff --git a/src/app/components/editor/database/database.component.ts b/src/app/components/editor/database/database.component.ts index 9fc380f..03d4afc 100644 --- a/src/app/components/editor/database/database.component.ts +++ b/src/app/components/editor/database/database.component.ts @@ -139,7 +139,6 @@ export class DatabaseComponent extends EditorNodeContract implements OnInit { } onRowDragEnd($event) { - console.log($event, this); if ( !this.isInitialLoad && this.editorService.canEdit() ) { this.dirty = true; this.triggerSaveDebounce(); @@ -369,7 +368,8 @@ export class DatabaseComponent extends EditorNodeContract implements OnInit { this.node.value = this.dbRecord.UUID; } else { try { - this.dbRecord = await this.api.getDatabase(this.page.UUID, this.node.UUID, this.node.Value.Value); + this.dbRecord = await this.api.getDatabase( + this.page.UUID, this.node.UUID, this.node.Value.Value, this.node.associatedTypeVersionNum); this.dbName = this.dbRecord.Name; this.notAvailableOffline = false; } catch (e: unknown) { @@ -382,7 +382,8 @@ export class DatabaseComponent extends EditorNodeContract implements OnInit { } // Load the columns - const columns = await this.api.getDatabaseColumns(this.page.UUID, this.node.UUID, this.node.Value.Value); + const columns = await this.api.getDatabaseColumns( + this.page.UUID, this.node.UUID, this.node.Value.Value, this.node.associatedTypeVersionNum); this.setColumns(columns, false); const rows = await this.api.getDatabaseEntries(this.page.UUID, this.node.UUID, this.node.Value.Value); diff --git a/src/app/components/editor/database/editors/boolean/boolean-editor.component.ts b/src/app/components/editor/database/editors/boolean/boolean-editor.component.ts index 1b4184c..9e09356 100644 --- a/src/app/components/editor/database/editors/boolean/boolean-editor.component.ts +++ b/src/app/components/editor/database/editors/boolean/boolean-editor.component.ts @@ -39,7 +39,6 @@ export class BooleanEditorComponent implements ICellEditorAngularComp, AfterView agInit(params: ICellEditorParams): void { this.params = params; this.value = this.params.value; - console.log('bool params', {params}); // @ts-ignore const values = params.colDef.additionalData.labelType.split('_'); diff --git a/src/app/components/editor/database/editors/page-link/page-link-editor.component.ts b/src/app/components/editor/database/editors/page-link/page-link-editor.component.ts index 0990542..0c59af4 100644 --- a/src/app/components/editor/database/editors/page-link/page-link-editor.component.ts +++ b/src/app/components/editor/database/editors/page-link/page-link-editor.component.ts @@ -25,8 +25,6 @@ export class PageLinkEditorComponent implements OnInit { // @ts-ignore this.pages = params._pagesData || []; - console.log('page link editor comp', this); - setTimeout(() => { this.selectable.open(); }); diff --git a/src/app/components/editor/files/files.component.ts b/src/app/components/editor/files/files.component.ts index ab85d18..e8bd448 100644 --- a/src/app/components/editor/files/files.component.ts +++ b/src/app/components/editor/files/files.component.ts @@ -50,8 +50,6 @@ export class FilesComponent extends EditorNodeContract implements OnInit { this.node.Value = {}; } - console.log('files load', this) - if ( !this.node.Value.Value && !this.readonly ) { this.dbRecord = await this.api.createFileGroup(this.page.UUID, this.node.UUID); this.fileRecords = this.dbRecord.files; diff --git a/src/app/components/nodes/form-input/form-input.component.ts b/src/app/components/nodes/form-input/form-input.component.ts index c98ef43..f83c3d4 100644 --- a/src/app/components/nodes/form-input/form-input.component.ts +++ b/src/app/components/nodes/form-input/form-input.component.ts @@ -46,7 +46,6 @@ export class FormInputComponent extends EditorNodeContract implements OnInit { ngOnInit() { this.editorService = this.editorService.getEditor(this.editorUUID); this.editorService.registerNodeEditor(this.nodeId, this).then(() => { - console.log('form input node', this.node); if ( !this.node.AdditionalData ) { this.node.AdditionalData = {}; } @@ -68,7 +67,6 @@ export class FormInputComponent extends EditorNodeContract implements OnInit { const db = await this.dbApi.getDatabase(this.node.AdditionalData.selectSourceDatabaseId); if ( db ) { const data = await db.data(); - console.log('loaded db data', data, this.node.AdditionalData); this.selectChoices = data.map(x => { return { display: x.data[this.node.AdditionalData.selectDatabaseDisplayColumnId], diff --git a/src/app/components/nodes/norm/norm.component.ts b/src/app/components/nodes/norm/norm.component.ts index ab9cba9..a0d8807 100644 --- a/src/app/components/nodes/norm/norm.component.ts +++ b/src/app/components/nodes/norm/norm.component.ts @@ -36,8 +36,6 @@ export class NormComponent extends EditorNodeContract implements OnInit, OnDestr super(); this.contents = this.initialValue; this.savedValue = this.initialValue; - - console.log('Norm editor component', this); } public isDark() { diff --git a/src/app/components/version-modal/version-modal.component.ts b/src/app/components/version-modal/version-modal.component.ts index 3bcb762..a67b1bd 100644 --- a/src/app/components/version-modal/version-modal.component.ts +++ b/src/app/components/version-modal/version-modal.component.ts @@ -20,13 +20,11 @@ export class VersionModalComponent implements OnInit { protected alerts: AlertController, protected modals: ModalController, protected editorService: EditorService, - ) { - console.log('version modal', this); - } + ) { } async ngOnInit() { this.pageVersions = await this.editorService.loadPageVersions(this.pageId); - this.onVersionClick(this.pageVersions[0]); + await this.onVersionClick(this.pageVersions[0]); } dismiss(reload = false) { diff --git a/src/app/components/wysiwyg/wysiwyg.component.ts b/src/app/components/wysiwyg/wysiwyg.component.ts index c030939..4745dc9 100644 --- a/src/app/components/wysiwyg/wysiwyg.component.ts +++ b/src/app/components/wysiwyg/wysiwyg.component.ts @@ -262,7 +262,6 @@ export class WysiwygComponent implements OnInit { } const target = this.getPathToElement(mutation.target); - console.log({mutation, target, type: mutation.type, data: mutation.target.textContent}); const innerHTML = this.editable.nativeElement.innerHTML; @@ -304,11 +303,9 @@ export class WysiwygComponent implements OnInit { applyRemoteContentMutation(mutation: MutationBroadcast) { this.applyingRemoteMutation = true; - console.log('got remote content mutation', mutation); if ( this.editable ) { const target = this.getElementFromPath(mutation.path); - console.log(target); if ( target ) { if ( mutation.type === 'characterData' ) { this.ignoreNextMutation = true; diff --git a/src/app/service/api.service.ts b/src/app/service/api.service.ts index d27bdd3..9a804ec 100644 --- a/src/app/service/api.service.ts +++ b/src/app/service/api.service.ts @@ -318,7 +318,6 @@ export class ApiService { const uuidMap = await new Promise(async (res, rej) => { this.post('/offline/sync', { dirtyRecords }).subscribe({ next: async result => { - console.log('sync result', result); res(result.data); }, error: rej, @@ -812,14 +811,14 @@ export class ApiService { }); } - public getCodium(PageId: string, NodeId: string, CodiumId: string): Promise { + public getCodium(PageId: string, NodeId: string, CodiumId: string, version?: number): Promise { return new Promise(async (res, rej) => { const existingLocalCodiums = await this.db.codiums.where({ UUID: CodiumId }).toArray(); const existingLocalCodium = existingLocalCodiums.length > 0 ? existingLocalCodiums[0] as Codium : undefined; // If offline, try to load it from the local DB if ( this.isOffline ) { - if ( existingLocalCodium ) { + if ( existingLocalCodium && !version ) { return res(existingLocalCodium.getSaveRecord()); } else { return rej(new ResourceNotAvailableOfflineError()); @@ -827,8 +826,12 @@ export class ApiService { } // If online, fetch the codium and store/update it locally - this.get(`/code/${PageId}/${NodeId}/get/${CodiumId}`).subscribe({ + this.get(`/code/${PageId}/${NodeId}/get/${CodiumId}?version=${version}`).subscribe({ next: async result => { + if ( version ) { + return res(result.data); + } + if ( existingLocalCodium ) { existingLocalCodium.fillFromRecord(result.data); @@ -915,20 +918,28 @@ export class ApiService { }); } - public getDatabaseColumns(PageId: string, NodeId: string, DatabaseId: string): Promise { + public getDatabaseColumns(PageId: string, NodeId: string, DatabaseId: string, databaseVersion?: number): Promise { return new Promise(async (res, rej) => { // If offline, fetch the columns from the local database if ( this.isOffline ) { + if ( databaseVersion ) { + return rej(new ResourceNotAvailableOfflineError()); + } + const columns = (await this.db.databaseColumns.where({ DatabaseId }).toArray()) as DatabaseColumn[]; return res(columns.filter(x => !x.deleted).map(x => x.getSaveRecord())); } // If online, fetch the columns and sync the local database - this.get(`/db/${PageId}/${NodeId}/get/${DatabaseId}/columns`).subscribe({ + this.get(`/db/${PageId}/${NodeId}/get/${DatabaseId}/columns?database_version=${databaseVersion}`).subscribe({ next: async results => { // Resolve this first, so the UI doesn't need to wait for the db sync to render res(results.data); + if ( databaseVersion ) { + return; + } + for ( const def of results.data ) { const existingColumnDef = await this.db.databaseColumns.where({ DatabaseId, UUID: def.UUID, @@ -992,21 +1003,25 @@ export class ApiService { }); } - public getDatabase(PageId: string, NodeId: string, DatabaseId: string): Promise { + public getDatabase(PageId: string, NodeId: string, DatabaseId: string, version?: number): Promise { return new Promise(async (res, rej) => { const existingLocalDatabases = await this.db.databases.where({ UUID: DatabaseId }).toArray(); const existingLocalDatabase = existingLocalDatabases.length > 0 ? existingLocalDatabases[0] as Database : undefined; if ( this.isOffline ) { - if ( existingLocalDatabase ) { + if ( existingLocalDatabase && !version ) { return res(existingLocalDatabase.getSaveRecord()); } else { return rej(new ResourceNotAvailableOfflineError()); } } - this.get(`/db/${PageId}/${NodeId}/get/${DatabaseId}`).subscribe({ + this.get(`/db/${PageId}/${NodeId}/get/${DatabaseId}?version=${version}`).subscribe({ next: async result => { + if ( version ) { + return res(result.data); + } + if ( existingLocalDatabase ) { existingLocalDatabase.fillFromRecord(result.data); diff --git a/src/app/service/db/database.service.ts b/src/app/service/db/database.service.ts index 516fc74..689f149 100644 --- a/src/app/service/db/database.service.ts +++ b/src/app/service/db/database.service.ts @@ -54,8 +54,6 @@ export class DatabaseService extends Dexie { } this.initialized = true; - console.log('db', this); - const staticClass = this.constructor as typeof DatabaseService; const schema: any = {}; diff --git a/src/app/service/editor.service.ts b/src/app/service/editor.service.ts index 52acf06..223932f 100644 --- a/src/app/service/editor.service.ts +++ b/src/app/service/editor.service.ts @@ -119,7 +119,6 @@ export class EditorService { protected session: SessionService, ) { this.instanceUUID = uuid_v4(); - console.log('editor service', this); } getEditor(uuid?: string) { diff --git a/src/app/structures/HostRecord.ts b/src/app/structures/HostRecord.ts index c6a1877..7eca79e 100644 --- a/src/app/structures/HostRecord.ts +++ b/src/app/structures/HostRecord.ts @@ -9,6 +9,7 @@ export default class HostRecord { public UpdatedAt: string; public Value: any; public AdditionalData: any; + public associatedTypeVersionNum?: number; public get UUID(): string { return this.privUUID; @@ -31,6 +32,7 @@ export default class HostRecord { load(data: any) { this.type = data.Type; this.privUUID = data.UUID; + this.associatedTypeVersionNum = data.associated_type_version_num; [ 'CreatedAt',