From 3d93792c8084a07019fdc071bc67898299d4563d Mon Sep 17 00:00:00 2001 From: Elvanos Date: Sun, 25 Apr 2021 23:01:41 +0200 Subject: [PATCH] 0.1.6 - reworked data handling across whole app --- package.json | 2 +- src/App.vue | 4 +- src/BaseClass.ts | 128 ++-- src/components/DocumentControl.vue | 43 +- src/components/ObjectTree.vue | 137 ++-- .../dialogs/DeleteDocumentCheck.vue | 21 +- src/components/dialogs/ExistingDocument.vue | 22 +- src/components/dialogs/NewDocument.vue | 1 + src/components/dialogs/NewProjectCheck.vue | 45 +- .../fields/Field_MultiRelationship.vue | 126 ++-- .../fields/Field_SingleRelationship.vue | 594 +++++++++--------- src/components/fields/Field_Tags.vue | 8 +- src/documents/advancedSearchCheatSheet.md | 1 + src/documents/advancedSearchGuide.md | 1 + src/documents/changeLog.md | 7 + src/globals.d.ts | 4 + src/layouts/DocumentLayout.vue | 91 ++- src/pages/DocumentDisplay.vue | 78 +-- src/pages/ProjectScreen.vue | 11 +- .../databaseManager/blueprints/characters.ts | 48 ++ .../databaseManager/blueprints/guilds.ts | 2 +- .../databaseManager/blueprints/locations.ts | 3 + .../blueprints/politicalGroups.ts | 1 + .../databaseManager/blueprints/religions.ts | 2 +- .../databaseManager/documentManager.ts | 90 ++- .../databaseManager/relationshipManager.ts | 89 +-- .../projectManagement/projectManagent.ts | 7 + .../utilities/advancedDocumentFilter.ts | 7 + src/scripts/utilities/tagListBuilder.ts | 23 +- src/scripts/utilities/tipsTricks.ts | 2 +- src/store/index.ts | 2 + src/store/module-allDocuments/actions.ts | 33 + src/store/module-allDocuments/getters.ts | 33 + src/store/module-allDocuments/index.ts | 16 + src/store/module-allDocuments/mutations.ts | 163 +++++ src/store/module-allDocuments/state.ts | 41 ++ 36 files changed, 1206 insertions(+), 680 deletions(-) create mode 100644 src/store/module-allDocuments/actions.ts create mode 100644 src/store/module-allDocuments/getters.ts create mode 100644 src/store/module-allDocuments/index.ts create mode 100644 src/store/module-allDocuments/mutations.ts create mode 100644 src/store/module-allDocuments/state.ts diff --git a/package.json b/package.json index f43cac8..4191cd4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fantasiaarchive", - "version": "0.1.5", + "version": "0.1.6", "description": "A database manager for world building", "productName": "Fantasia Archive", "author": "Elvanos ", diff --git a/src/App.vue b/src/App.vue index 91fb439..4df7c3d 100644 --- a/src/App.vue +++ b/src/App.vue @@ -7,10 +7,10 @@ no-resize dark title="Advanced Search Cheatsheet" - :height="480" + :height="510" :width="425" :start-x="50" - :start-y="150" + :start-y="150" :actions="['close']" content-class="bg-gunmetal-light text-accent advSearchWindow" > diff --git a/src/BaseClass.ts b/src/BaseClass.ts index c7bcb04..fe6a695 100644 --- a/src/BaseClass.ts +++ b/src/BaseClass.ts @@ -8,9 +8,9 @@ import { I_NewObjectTrigger } from "src/interfaces/I_NewObjectTrigger" import { uid, colors, extend } from "quasar" import { I_FieldRelationship } from "src/interfaces/I_FieldRelationship" import { I_KeyPressObject } from "src/interfaces/I_KeypressObject" -import PouchDB from "pouchdb" const Blueprints = namespace("blueprintsModule") +const AllDocuments = namespace("allDocumentsModule") const OpenedDocuments = namespace("openedDocumentsModule") const Keybinds = namespace("keybindsModule") const Options = namespace("optionsModule") @@ -317,6 +317,57 @@ export default class BaseClass extends Vue { this.SSET_options(optionsSnapshot) } + /****************************************************************/ + // ALL DOCUMENTS MANAGEMENT + /****************************************************************/ + + @AllDocuments.Getter("getFirstRunState") SGET_allDocumentsFirstRunState!: boolean + + @AllDocuments.Action("markAsNonFirstRun") SSET_allDocumentsMarkAsNonFirstRun!: () => void + + @AllDocuments.Getter("getAllDocuments") SGET_allDocuments !: { + timestamp: string, + docs: I_ShortenedDocument[] + } + + @AllDocuments.Getter("getAllDocumentsWithoutCategories") SGET_allDocumentsWithoutCategories !: { + timestamp: string, + docs: I_ShortenedDocument[] + } + + @AllDocuments.Getter("getDocumentsByType") SGET_allDocumentsByType!: (documentTypeID: string) => { + timestamp: string, + id: string, + docs: I_ShortenedDocument[] + } + + @AllDocuments.Getter("getDocumentsByTypeWithoutCategories") SGET_allDocumentsByTypeWithoutCategories!: (documentTypeID: string) => { + timestamp: string, + id: string, + docs: I_ShortenedDocument[] + } + + @AllDocuments.Getter("getDocument") SGET_document!: (id: string) => I_ShortenedDocument + + @AllDocuments.Action("addDocument") SSET_addDocument!: (input: { + doc: I_ShortenedDocument + }) => void + + @AllDocuments.Action("updateDocument") SSET_updateDocument!: (input: { + doc: I_ShortenedDocument + }) => void + + @AllDocuments.Action("removeDocument") SSET_removeDocument!: (input: { + doc: I_ShortenedDocument + }) => void + + @AllDocuments.Action("mapNewDocumentType") SSET_mapNewDocumentType!: (input: { + id: string, + docs: I_ShortenedDocument[] + }) => void + + @AllDocuments.Action("resetDocuments") SSET_resetAllDocuments!: () => void + /****************************************************************/ // OPEN DOCUMENTS MANAGEMENT /****************************************************************/ @@ -372,7 +423,7 @@ export default class BaseClass extends Vue { * @param document - Document object that is expected to contain the field * @param fieldID - ID of the field to check */ - retrieveFieldValue (document: I_OpenedDocument, fieldID: string) : string | number | [] | false | I_FieldRelationship { + retrieveFieldValue (document: I_OpenedDocument| I_ShortenedDocument, fieldID: string) : string | number | [] | false | I_FieldRelationship { const fieldData = document?.extraFields // Fizzle if field doesnt exist @@ -491,46 +542,43 @@ export default class BaseClass extends Vue { return hierarchicalString } - /** - * Retieves ALL documents - */ - async retrieveAllDocuments () { - let allDocs = [] as I_ShortenedDocument[] - for (const blueprint of this.SGET_allBlueprints) { - const CurrentObjectDB = new PouchDB(blueprint._id) - - const dbRows = await CurrentObjectDB.allDocs({ include_docs: true }) - const dbDocuments = dbRows.rows.map(d => d.doc) - const formattedDocuments: I_ShortenedDocument[] = [] - - for (const singleDocument of dbDocuments) { - const doc = singleDocument as unknown as I_ShortenedDocument - const pushValue = { - label: doc.extraFields.find(e => e.id === "name")?.value, - icon: doc.icon, - id: doc._id, - url: doc.url, - type: doc.type, - extraFields: doc.extraFields, - // @ts-ignore - hierarchicalPath: this.getDocumentHieararchicalPath(doc, dbDocuments), - tags: doc.extraFields.find(e => e.id === "tags")?.value, - color: doc.extraFields.find(e => e.id === "documentColor")?.value, - bgColor: doc.extraFields.find(e => e.id === "documentBackgroundColor")?.value, - isCategory: doc.extraFields.find(e => e.id === "categorySwitch")?.value, - isMinor: doc.extraFields.find(e => e.id === "minorSwitch")?.value, - isDead: doc.extraFields.find(e => e.id === "deadSwitch")?.value - - } as unknown as I_ShortenedDocument - formattedDocuments.push(pushValue) - } - const sortedDocuments = formattedDocuments.sort((a, b) => a.label.localeCompare(b.label)) - + mapShortDocument (doc: I_ShortenedDocument, dbDocuments: I_OpenedDocument[]) : I_ShortenedDocument { + return { + label: doc.extraFields.find(e => e.id === "name")?.value, + icon: doc.icon, // @ts-ignore - allDocs = [...allDocs, ...sortedDocuments] + id: doc._id, + _id: doc._id, + url: doc.url, + type: doc.type, + extraFields: doc.extraFields, + hasEdits: false, + // @ts-ignore + hierarchicalPath: this.getDocumentHieararchicalPath(doc, dbDocuments), + tags: doc.extraFields.find(e => e.id === "tags")?.value, + color: doc.extraFields.find(e => e.id === "documentColor")?.value, + bgColor: doc.extraFields.find(e => e.id === "documentBackgroundColor")?.value, + isCategory: doc.extraFields.find(e => e.id === "categorySwitch")?.value, + isMinor: doc.extraFields.find(e => e.id === "minorSwitch")?.value, + isDead: doc.extraFields.find(e => e.id === "deadSwitch")?.value - await CurrentObjectDB.close() } - return allDocs + } + + deepFreeze (object: object) { + // Retrieve the property names defined on object + const propNames = Object.getOwnPropertyNames(object) + + // Freeze properties before freezing self + + for (const name of propNames) { + const value = object[name] + + if (value && typeof value === "object") { + this.deepFreeze(value) + } + } + + return Object.freeze(object) } } diff --git a/src/components/DocumentControl.vue b/src/components/DocumentControl.vue index 09f4097..a6d5823 100644 --- a/src/components/DocumentControl.vue +++ b/src/components/DocumentControl.vue @@ -178,7 +178,7 @@ color="primary" outline @click="toggleEditMode" - v-if="currentyEditable && SGET_allOpenedDocuments.docs.length > 0" + v-if="currentyEditable && SGET_allOpenedDocuments.docs.length > 0 && this.$route.path !== '/project'" > 0 && !this.SGET_getDialogsState) { + if (this.determineKeyBind("deleteDocument") && !this.currentlyNew && this.SGET_allOpenedDocuments.docs.length > 0 && !this.SGET_getDialogsState && this.$route.path !== "/project") { this.deleteObjectAssignUID() } // Edit document - CTRL + E - if (this.determineKeyBind("editDocument") && this.currentyEditable && this.SGET_allOpenedDocuments.docs.length > 0 && !this.SGET_getDialogsState) { + if (this.determineKeyBind("editDocument") && this.currentyEditable && this.SGET_allOpenedDocuments.docs.length > 0 && !this.SGET_getDialogsState && this.$route.path !== "/project") { this.toggleEditMode() } // Save document - CTRL + S - if (this.determineKeyBind("saveDocument") && !this.currentyEditable && this.SGET_allOpenedDocuments.docs.length > 0 && !this.SGET_getDialogsState) { + if (this.determineKeyBind("saveDocument") && !this.currentyEditable && this.SGET_allOpenedDocuments.docs.length > 0 && !this.SGET_getDialogsState && this.$route.path !== "/project") { this.saveCurrentDocument(false).catch(e => console.log(e)) } // Save document without exiting edit mode - CTRL + ALT + S - if (this.determineKeyBind("saveDocumentNoExit") && !this.currentyEditable && this.SGET_allOpenedDocuments.docs.length > 0 && !this.SGET_getDialogsState) { + if (this.determineKeyBind("saveDocumentNoExit") && !this.currentyEditable && this.SGET_allOpenedDocuments.docs.length > 0 && !this.SGET_getDialogsState && this.$route.path !== "/project") { this.saveCurrentDocument(true).catch(e => console.log(e)) } // Add new under parent - CTRL + SHIFT + N - if (this.determineKeyBind("addUnderParent") && !this.currentlyNew && this.SGET_allOpenedDocuments.docs.length > 0 && !this.SGET_getDialogsState) { + if (this.determineKeyBind("addUnderParent") && !this.currentlyNew && this.SGET_allOpenedDocuments.docs.length > 0 && !this.SGET_getDialogsState && this.$route.path !== "/project") { await this.sleep(100) this.addNewUnderParent() } - // Add new under parent - CTRL + ALT + C - if (this.determineKeyBind("copyDocument") && !this.currentlyNew && this.SGET_allOpenedDocuments.docs.length > 0 && !this.SGET_getDialogsState) { + // Copy document - CTRL + ALT + C + if (this.determineKeyBind("copyDocument") && !this.currentlyNew && this.SGET_allOpenedDocuments.docs.length > 0 && !this.SGET_getDialogsState && this.$route.path !== "/project") { await this.sleep(100) this.copyTargetDocument() } @@ -559,17 +559,22 @@ export default class DocumentControl extends BaseClass { const savedDocument: { documentCopy: I_OpenedDocument, allOpenedDocuments: I_OpenedDocument[] - } = await saveDocument(currentDoc, this.documentsCopy, editMode) + } = await saveDocument(currentDoc, this.documentsCopy, this.SGET_allDocuments.docs, editMode).catch(err => console.log(err)) // Update the opened document const dataPass = { doc: savedDocument.documentCopy, treeAction: true } this.SSET_updateOpenedDocument(dataPass) + // @ts-ignore + this.SSET_updateDocument({ doc: this.mapShortDocument(savedDocument.documentCopy, this.SGET_allDocumentsByType(savedDocument.documentCopy.type).docs) }) // Update all others for (const doc of savedDocument.allOpenedDocuments) { // Update the opened document const dataPass = { doc: doc, treeAction: true } this.SSET_updateOpenedDocument(dataPass) + + // @ts-ignore + this.SSET_updateDocument({ doc: this.mapShortDocument(doc, this.SGET_allDocumentsByType(doc.type).docs) }) } this.$q.notify({ @@ -699,4 +704,12 @@ export default class DocumentControl extends BaseClass { } } } + +html body { + &.q-body--prevent-scroll { + .documentControl { + min-width: calc(100vw - 375px); + } + } +} diff --git a/src/components/ObjectTree.vue b/src/components/ObjectTree.vue index 815988c..4e1b731 100644 --- a/src/components/ObjectTree.vue +++ b/src/components/ObjectTree.vue @@ -50,7 +50,7 @@ no-connectors ref="tree" dark - :duration="200" + :duration="0" :filter="treeFilter" :selected.sync="selectedTreeNode" :expanded.sync="expandedTreeNodes" @@ -81,7 +81,7 @@ - + @@ -290,7 +290,6 @@ import { Component, Watch } from "vue-property-decorator" import BaseClass from "src/BaseClass" import { I_OpenedDocument, I_ShortenedDocument } from "src/interfaces/I_OpenedDocument" -import PouchDB from "pouchdb" import deleteDocumentCheckDialog from "src/components/dialogs/DeleteDocumentCheck.vue" import { extend, colors } from "quasar" @@ -377,23 +376,7 @@ export default class ObjectTree extends BaseClass { this.hideTreeIconAddUnder = options.hideTreeIconAddUnder this.hideTreeIconEdit = options.hideTreeIconEdit this.hideTreeIconView = options.hideTreeIconView - this.buildCurrentObjectTree().catch((e) => { - console.log(e) - }) - } - - /****************************************************************/ - // BLUEPRINT MANAGEMENT - /****************************************************************/ - - /** - * In case any of the blueprints change, reload the whole tree - */ - @Watch("SGET_allBlueprints", { deep: true }) - reactToBluePrintRefresh () { - this.buildCurrentObjectTree().catch((e) => { - console.log(e) - }) + this.buildCurrentObjectTree() } /****************************************************************/ @@ -417,9 +400,9 @@ export default class ObjectTree extends BaseClass { * */ @Watch("SGET_allOpenedDocuments", { deep: true }) - async reactToDocumentListChange (val: { treeAction: boolean, docs: I_OpenedDocument[]}) { + reactToDocumentListChange (val: { treeAction: boolean, docs: I_OpenedDocument[]}) { if (val.treeAction) { - await this.buildCurrentObjectTree() + this.buildCurrentObjectTree() this.buildTreeExpands(val?.docs) this.lastDocsSnapShot = extend(true, [], val.docs) } @@ -430,6 +413,26 @@ export default class ObjectTree extends BaseClass { lastDocsSnapShot:I_OpenedDocument[] = [] + /** + * + */ + @Watch("SGET_allDocuments", { deep: true }) + reactToAllDocumentListChange (val: { docs: I_OpenedDocument[]}) { + if (!this.SGET_allDocumentsFirstRunState) { + this.buildCurrentObjectTree() + } + } + + /** + * + */ + @Watch("SGET_allDocumentsFirstRunState") + reactToFirstRunFinish (val: boolean) { + if (!val) { + this.buildCurrentObjectTree() + } + } + /** * Generic wrapper for adding of new object types to the tree */ @@ -562,52 +565,50 @@ export default class ObjectTree extends BaseClass { /** * Builds a brand new sparkling hearchy tree out of available data */ - async buildCurrentObjectTree () { + buildCurrentObjectTree () { const allBlueprings = this.SGET_allBlueprints let treeObject: any[] = [] let allTreeDocuments: I_ShortenedDocument[] = [] // Process all documents, build hieararchy out of the and sort them via name and custom order for (const blueprint of allBlueprings) { - const CurrentObjectDB = new PouchDB(blueprint._id) + const allDocuments = this.SGET_allDocumentsByType(blueprint._id) + let allDocumentsRows: I_ShortenedDocument[] = [] - const allDocuments = await CurrentObjectDB.allDocs({ include_docs: true }) + if (allDocuments && allDocuments.docs) { + allDocumentsRows = allDocuments.docs + .map((doc) => { + const parentDocID = doc.extraFields.find(e => e.id === "parentDoc")?.value.value as unknown as {_id: string} + const color = doc.extraFields.find(e => e.id === "documentColor")?.value as unknown as string + const bgColor = doc.extraFields.find(e => e.id === "documentBackgroundColor")?.value as unknown as string - const allDocumentsRows = allDocuments.rows - .map((singleDocument) => { - const doc = singleDocument.doc as unknown as I_ShortenedDocument - - const parentDocID = doc.extraFields.find(e => e.id === "parentDoc")?.value.value as unknown as {_id: string} - const color = doc.extraFields.find(e => e.id === "documentColor")?.value as unknown as string - const bgColor = doc.extraFields.find(e => e.id === "documentBackgroundColor")?.value as unknown as string - - const isCategory = doc.extraFields.find(e => e.id === "categorySwitch")?.value as unknown as boolean - const isMinor = doc.extraFields.find(e => e.id === "minorSwitch")?.value as unknown as boolean - const isDead = doc.extraFields.find(e => e.id === "deadSwitch")?.value as unknown as boolean - - return { - label: doc.extraFields.find(e => e.id === "name")?.value, - icon: (isCategory) ? "fas fa-folder-open" : doc.icon, - isCategory: !!(isCategory), - isMinor: isMinor, - isDead: isDead, - sticker: doc.extraFields.find(e => e.id === "order")?.value, - parentDoc: (parentDocID) ? parentDocID._id : false, - handler: this.openExistingDocumentRoute, - expandable: true, - color: color, - bgColor: bgColor, - type: doc.type, - children: [], - hasEdits: false, - isNew: false, - url: doc.url, - extraFields: (doc?.extraFields) || [], - _id: singleDocument.id, - key: singleDocument.id - } as I_ShortenedDocument - }) + const isCategory = doc.extraFields.find(e => e.id === "categorySwitch")?.value as unknown as boolean + const isMinor = doc.extraFields.find(e => e.id === "minorSwitch")?.value as unknown as boolean + const isDead = doc.extraFields.find(e => e.id === "deadSwitch")?.value as unknown as boolean + return { + label: doc.extraFields.find(e => e.id === "name")?.value, + icon: (isCategory) ? "fas fa-folder-open" : doc.icon, + isCategory: !!(isCategory), + isMinor: isMinor, + isDead: isDead, + sticker: doc.extraFields.find(e => e.id === "order")?.value, + parentDoc: (parentDocID) ? parentDocID._id : false, + handler: this.openExistingDocumentRoute, + expandable: true, + color: color, + bgColor: bgColor, + type: doc.type, + children: [], + hasEdits: false, + isNew: false, + url: doc.url, + extraFields: (doc?.extraFields) || [], + _id: doc._id, + key: doc._id + } as I_ShortenedDocument + }) + } const documentCount = allDocumentsRows.filter(e => !e.isCategory).length const categoryCount = allDocumentsRows.filter(e => e.isCategory).length const allCount = allDocumentsRows.length @@ -645,8 +646,6 @@ export default class ObjectTree extends BaseClass { } treeObject.push(treeRow) - - await CurrentObjectDB.close() } // Sort the top level of the blueprints @@ -662,7 +661,7 @@ export default class ObjectTree extends BaseClass { }) if (!this.noTags) { - const tagList = await tagListBuildFromBlueprints(this.SGET_allBlueprints) + const tagList = tagListBuildFromBlueprints(this.SGET_allDocuments.docs) let allTags = 0 let allTagsCategories = 0 @@ -735,7 +734,17 @@ export default class ObjectTree extends BaseClass { } // Assign the finished object to the render model - this.hierarchicalTree = treeObject + treeObject.forEach(cat => this.recursivelyFreezeChildren(cat.children)) + // @ts-ignore + this.hierarchicalTree = Object.freeze(treeObject) + } + + recursivelyFreezeChildren (children: {children: []}) { + Object.freeze(children) + if (children.children) { + // @ts-ignore + this.recursivelyFreezeChildren(children.children) + } } processNodeNewDocumentButton (node: { @@ -962,7 +971,7 @@ export default class ObjectTree extends BaseClass { } } - determineCatyegoryString (node: { + determineCategoryString (node: { documentCount: string categoryCount: string }) { diff --git a/src/components/dialogs/DeleteDocumentCheck.vue b/src/components/dialogs/DeleteDocumentCheck.vue index 0f2f2c8..90119db 100644 --- a/src/components/dialogs/DeleteDocumentCheck.vue +++ b/src/components/dialogs/DeleteDocumentCheck.vue @@ -42,7 +42,7 @@ import { Component, Watch, Prop } from "vue-property-decorator" import DialogBase from "src/components/dialogs/_DialogBase" -import { I_OpenedDocument } from "src/interfaces/I_OpenedDocument" +import { I_ShortenedDocument } from "src/interfaces/I_OpenedDocument" import PouchDB from "pouchdb" @Component({ @@ -53,7 +53,7 @@ export default class DeleteDocumentCheckDialog extends DialogBase { * React to dialog opening request */ @Watch("dialogTrigger") - async openDialog (val: string|false) { + openDialog (val: string|false) { if (val && (this.SGET_allOpenedDocuments.docs.length > 0 || (this.documentType.length > 0 && this.documentId.length > 0))) { if (this.SGET_getDialogsState) { return @@ -61,12 +61,9 @@ export default class DeleteDocumentCheckDialog extends DialogBase { this.SSET_setDialogState(true) this.dialogModel = true - const documentType = (this.documentType.length > 0) ? this.documentType : this.$route.params.type const documentID = (this.documentId.length > 0) ? this.documentId : this.$route.params.id - const CurrentObjectDB = new PouchDB(documentType) - this.currentDocument = await CurrentObjectDB.get(documentID) - await CurrentObjectDB.close() + this.currentDocument = this.SGET_document(documentID) } } @@ -85,25 +82,27 @@ export default class DeleteDocumentCheckDialog extends DialogBase { /** * Current document for deletion */ - currentDocument = false as unknown as I_OpenedDocument + currentDocument = false as unknown as I_ShortenedDocument /** * Delete the document */ async deleteDocument () { const documentType = (this.documentType.length > 0) ? this.documentType : this.$route.params.type - const CurrentObjectDB = new PouchDB(documentType) + window.FA_dbs[documentType] = new PouchDB(documentType) - // @ts-ignore - await CurrentObjectDB.remove(this.currentDocument) + // eslint-disable-next-line @typescript-eslint/no-unsafe-call + await window.FA_dbs[documentType].remove(this.currentDocument) const dataPass = { doc: this.currentDocument, treeAction: true } this.dialogModel = false this.SSET_setDialogState(false) + // @ts-ignore this.SSET_removeOpenedDocument(dataPass) - await CurrentObjectDB.close() + // @ts-ignore + this.SSET_removeDocument({ doc: this.mapShortDocument(this.currentDocument, this.SGET_allDocumentsByType(this.currentDocument.type)) }) } } diff --git a/src/components/dialogs/ExistingDocument.vue b/src/components/dialogs/ExistingDocument.vue index 1860aa6..d8e6a85 100644 --- a/src/components/dialogs/ExistingDocument.vue +++ b/src/components/dialogs/ExistingDocument.vue @@ -216,7 +216,6 @@ import { Component, Watch } from "vue-property-decorator" import { I_OpenedDocument, I_ShortenedDocument } from "src/interfaces/I_OpenedDocument" import { advancedDocumentFilter } from "src/scripts/utilities/advancedDocumentFilter" import { extend } from "quasar" -import PouchDB from "pouchdb" import { createNewWithParent } from "src/scripts/documentActions/createNewWithParent" import { copyDocumentName, copyDocumentTextColor, copyDocumentBackgroundColor } from "src/scripts/documentActions/uniqueFieldCopy" @@ -373,13 +372,14 @@ export default class ExistingDocumentDialog extends DialogBase { async populateExistingObjectDialog () { this.allDocumentBluePrints = this.SGET_allBlueprints - this.existingObjectsFullList = await this.retrieveAllDocuments() + this.existingObjectsFullList = this.SGET_allDocuments.docs this.preFilterDocuments() await this.$nextTick() if (this.$refs.ref_existingDocument) { /*eslint-disable */ + await this.sleep(100) // @ts-ignore this.$refs.ref_existingDocument.focus() /* eslint-enable */ @@ -449,7 +449,7 @@ export default class ExistingDocumentDialog extends DialogBase { * Either as a focus with closure of the dialog. * Or as a background tab without closing of the dialog. */ - async openExistingInput (e: I_ShortenedDocument) { + openExistingInput (e: I_ShortenedDocument) { // @ts-ignore e = (Array.isArray(e)) ? e[0] : e // Open document and close dialog @@ -461,12 +461,11 @@ export default class ExistingDocumentDialog extends DialogBase { } // Open document and DO NOT close the dialog else { - // @ts-ignore this.existingDocumentModel = [] - const CurrentObjectDB = new PouchDB(e.type) - // @ts-ignore - const retrievedObject = await CurrentObjectDB.get(e.id) + const retrievedObject = (this.SGET_openedDocument(e._id)) || this.SGET_document(e._id) + + console.log(retrievedObject) const dataPass = { doc: retrievedObject, @@ -475,7 +474,6 @@ export default class ExistingDocumentDialog extends DialogBase { // @ts-ignore this.SSET_addOpenedDocument(dataPass) - await CurrentObjectDB.close() } } @@ -484,7 +482,7 @@ export default class ExistingDocumentDialog extends DialogBase { * Either as a focus with closure of the dialog. * Or as a background tab without closing of the dialog. */ - async editExistingInput (e: I_ShortenedDocument) { + editExistingInput (e: I_ShortenedDocument) { // @ts-ignore e = (Array.isArray(e)) ? e[0] : e // Open document and close dialog @@ -499,11 +497,8 @@ export default class ExistingDocumentDialog extends DialogBase { // @ts-ignore this.existingDocumentModel = [] - const CurrentObjectDB = new PouchDB(e.type) - // @ts-ignore - const retrievedObject = await CurrentObjectDB.get(e.id) + const retrievedObject = (this.SGET_openedDocument(e._id)) || this.SGET_document(e._id) - // @ts-ignore retrievedObject.hasEdits = true const dataPass = { @@ -513,7 +508,6 @@ export default class ExistingDocumentDialog extends DialogBase { // @ts-ignore this.SSET_addOpenedDocument(dataPass) - await CurrentObjectDB.close() } } diff --git a/src/components/dialogs/NewDocument.vue b/src/components/dialogs/NewDocument.vue index b2947dc..97f2a46 100644 --- a/src/components/dialogs/NewDocument.vue +++ b/src/components/dialogs/NewDocument.vue @@ -1,5 +1,6 @@