build 0.1.3-e2

This commit is contained in:
Elvanos 2021-02-27 18:00:57 +01:00
parent 64b3eae526
commit c582e1a60e
16 changed files with 358 additions and 63 deletions

View file

@ -1,5 +1,21 @@
# Changelog
## 0.1.3
### Bugfixes
- Fixed the "Name" field disappearing upon full deletion of text
### New features
### QoL adjustments
- Added a hierarchical path to Quick opening existing document and single/multi relationship fields
- Added color support to single/multi relationship fields
- Added filtering to include or exclude documents that are considered categories in the Quick opening existing document dialog
- Improved performance by reducing the amount of time the side-tree re-renders
- Added automatic opening of hierarchical tree branches upon adding/moving documents under/among them
## 0.1.2
### Bugfixes

View file

@ -163,13 +163,26 @@ export default class BaseClass extends Vue {
// Open documents management
/****************************************************************/
@OpenedDocuments.Getter("getAllDocuments") SGET_allOpenedDocuments !: {timestamp: string, docs: I_OpenedDocument[]}
@OpenedDocuments.Getter("getAllDocuments") SGET_allOpenedDocuments !: {treeAction: boolean, timestamp: string, docs: I_OpenedDocument[]}
@OpenedDocuments.Getter("getDocument") SGET_openedDocument!: (id: string) => I_OpenedDocument
@OpenedDocuments.Mutation("addDocument") SSET_addOpenedDocument!: (input: I_OpenedDocument) => void
@OpenedDocuments.Mutation("updateDocument") SSET_updateOpenedDocument!: (input: I_OpenedDocument) => void
@OpenedDocuments.Mutation("removeDocument") SSET_removeOpenedDocument!: (input: I_OpenedDocument) => void
@OpenedDocuments.Mutation("resetDocuments") SSET_resetDocuments!: () => void
@OpenedDocuments.Action("addDocument") SSET_addOpenedDocument!: (input: {
doc: I_OpenedDocument,
treeAction: boolean
}) => void
@OpenedDocuments.Action("updateDocument") SSET_updateOpenedDocument!: (input: {
doc: I_OpenedDocument,
treeAction: boolean
}) => void
@OpenedDocuments.Action("removeDocument") SSET_removeOpenedDocument!: (input: {
doc: I_OpenedDocument,
treeAction: boolean
}) => void
@OpenedDocuments.Action("triggerTreeAction") SSET_triggerTreeAction!: () => void
@OpenedDocuments.Action("resetDocuments") SSET_resetDocuments!: () => void
/**
* Retrieves value of requested field. If the field doesn't exist, returns false instead
@ -243,4 +256,34 @@ export default class BaseClass extends Vue {
)
}
}
/****************************************************************/
// Document list management
/****************************************************************/
getDocumentHieararchicalPath (document: I_OpenedDocument, list: I_OpenedDocument[]): string {
let hierarchiString = ""
// @ts-ignore
const parentDoc = (this.retrieveFieldValue(document, "parentDoc"))?.value
if (!parentDoc) {
const singleBlueprintName = this.SGET_allBlueprints.find(e => e._id === document.type)?.nameSingular
hierarchiString += singleBlueprintName
return hierarchiString
}
const matchingDoc = list.find((doc:I_OpenedDocument) => {
// @ts-ignore
return doc.id === parentDoc._id
}) as I_OpenedDocument
// @ts-ignore
hierarchiString += this.retrieveFieldValue(matchingDoc.doc, "name")
// @ts-ignore
const connectedReturn = this.getDocumentHieararchicalPath(matchingDoc.doc, list)
if (connectedReturn) {
hierarchiString = `${connectedReturn} > ${hierarchiString}`
}
return hierarchiString
}
}

View file

@ -2,7 +2,7 @@
<q-header
elevated
class="bg-dark text-cultured"
class="bg-dark text-cultured appHeader"
>
<div class="appHeaderInner">
@ -39,10 +39,15 @@ export default class AppHeader extends BaseClass {
</script>
<style lang="scss" scoped>
.appHeader {
}
.appHeaderInner {
display: flex;
width: 100%;
min-height: 40px;
-webkit-app-region: drag;
width: calc(100% - 147px);
.appControl {
width: 375px;

View file

@ -127,12 +127,13 @@
import { Component, Watch } from "vue-property-decorator"
import BaseClass from "src/BaseClass"
import { I_ShortenedDocument } from "src/interfaces/I_OpenedDocument"
import { I_OpenedDocument, I_ShortenedDocument } from "src/interfaces/I_OpenedDocument"
import { I_NewObjectTrigger } from "src/interfaces/I_NewObjectTrigger"
import PouchDB from "pouchdb"
import { engageBlueprints, retrieveAllBlueprints } from "src/scripts/databaseManager/blueprintManager"
// import { cleanDatabases } from "src/scripts/databaseManager/cleaner"
import { I_Blueprint } from "src/interfaces/I_Blueprint"
import { extend } from "quasar"
@Component({
components: { }
@ -219,10 +220,19 @@ export default class ObjectTree extends BaseClass {
*
*/
@Watch("SGET_allOpenedDocuments", { deep: true })
async reactToDocumentListChange () {
await this.buildCurrentObjectTree()
async reactToDocumentListChange (val: { treeAction: boolean, docs: I_OpenedDocument[]}) {
if (val.treeAction) {
await this.buildCurrentObjectTree()
this.buildTreeExpands(val?.docs)
this.lastDocsSnapShot = extend(true, [], val.docs)
}
else if (val.docs.length !== this.lastDocsSnapShot.length) {
this.lastDocsSnapShot = extend(true, [], val.docs)
}
}
lastDocsSnapShot:I_OpenedDocument[] = []
/**
* Generic wrapper for adding of new object types to the tree
*/
@ -236,11 +246,6 @@ export default class ObjectTree extends BaseClass {
*/
hierarchicalTree: {children: I_ShortenedDocument[], icon: string, label: string}[] = []
/**
* Determines if the tree should expand fully at first or not
*/
firstTimeExpand = true
/**
* A resetter for the currently selected node
*/
@ -294,6 +299,12 @@ export default class ObjectTree extends BaseClass {
return 0
})
// Put the number value on top of the list and alphabetical below them
input = [
...input.filter(e => e.extraFields.find(e => e.id === "order")?.value),
...input.filter(e => !e.extraFields.find(e => e.id === "order")?.value)
]
input.forEach((e, i) => {
// Run recursive if the node has any children
if (e.children.length > 0) {
@ -426,13 +437,6 @@ export default class ObjectTree extends BaseClass {
// Assign the finished object to the render model
this.hierarchicalTree = treeObject
// Expand all on first load
if (this.firstTimeExpand) {
this.firstTimeExpand = false
// await this.$nextTick()
// this.$refs.tree.expandAll()
}
}
processNodeNewDocumentButton (node: {
@ -459,6 +463,81 @@ export default class ObjectTree extends BaseClass {
}
}
buildTreeExpands (newDocs: I_OpenedDocument[]) {
const expandIDs: string[] = []
// Check for parent changes
newDocs.forEach(s => {
const oldParentDoc = this.lastDocsSnapShot.find(doc => doc._id === s._id)
// Fizzle if the parent doesn't exist in the old version
if (!oldParentDoc) {
return false
}
const oldParentDocField = this.retrieveFieldValue(oldParentDoc, "parentDoc")
// @ts-ignore
const oldParentDocID = (oldParentDocField?.value) ? oldParentDocField.value.value : ""
const newParentDocField = this.retrieveFieldValue(s, "parentDoc")
// @ts-ignore
const newParentDocID = (newParentDocField?.value) ? newParentDocField.value.value : ""
if ((newParentDocID !== oldParentDocID) || (newParentDocID && oldParentDoc.isNew)) {
expandIDs.push(newParentDocID)
}
})
// Process top level documents
newDocs.forEach(s => {
const newParentDocField = this.retrieveFieldValue(s, "parentDoc")
// @ts-ignore
const newParentDocID = (newParentDocField?.value) ? newParentDocField.value.value : false
if (!newParentDocID) {
expandIDs.push(s.type)
}
})
// @ts-ignore
const nodesToExpand = [...new Set([
...this.expandedTreeNodes,
...expandIDs
])] as unknown as string[]
nodesToExpand.forEach(s => {
this.recursivelyExpandNode(s)
})
}
recursivelyExpandNode (nodeID: string) {
const treeDOM = this.$refs.tree as unknown as {
setExpanded: (key:string, state: boolean)=> void
getNodeByKey: (key:string)=> void
}
// @ts-ignore
this.expandedTreeNodes = [...new Set([
...this.expandedTreeNodes,
nodeID
])]
const currentTreeNode = (treeDOM.getNodeByKey(nodeID)) as unknown as {parentDoc: string, type: string}
// Dig into the upper hierarchy
if (currentTreeNode?.parentDoc) {
this.recursivelyExpandNode(currentTreeNode.parentDoc)
}
// If we are at the top of the tree, expand the top category
else if (currentTreeNode?.type) {
// @ts-ignore
this.expandedTreeNodes = [...new Set([
...this.expandedTreeNodes,
currentTreeNode.type
])]
}
}
processNodeLabelMiddleClick (node: {
key: string
_id: string
@ -552,8 +631,6 @@ export default class ObjectTree extends BaseClass {
}
.treeButton {
.q-focus-helper{}
&--add {
.q-icon {
font-size: 20px;

View file

@ -172,6 +172,7 @@ export default class AppControl extends BaseClass {
&__buttons {
height: 40px;
-webkit-app-region: no-drag;
}
}
</style>

View file

@ -2,7 +2,7 @@
<q-btn-group
flat
class="appWindowButtons"
class="appWindowButtons bg-dark"
>
<projectCloseCheckDialog
@ -106,12 +106,14 @@ export default class AppWindowButtons extends BaseClass {
<style lang="scss" scoped>
.appWindowButtons {
border-radius: 0;
position: fixed;
right: 0;
top: 0;
height: 40px;
z-index: 99999999;
color: #fff;
-webkit-app-region: no-drag;
}
</style>

View file

@ -105,7 +105,8 @@ export default class TopTabs extends BaseClass {
}
closeDocument (input: I_OpenedDocument) {
this.SSET_removeOpenedDocument(input)
const dataPass = { doc: input, treeAction: false }
this.SSET_removeOpenedDocument(dataPass)
this.documentCloseDialogConfirm = false
setTimeout(() => {
this.refreshRoute()
@ -222,6 +223,8 @@ export default class TopTabs extends BaseClass {
<style lang="scss">
.tabsWrapper {
-webkit-app-region: no-drag;
.q-tabs__arrow {
text-shadow: none !important;
}

View file

@ -12,12 +12,17 @@
<h6 class="text-center q-my-sm">Open existing document</h6>
</q-card-section>
<q-card-section class="row items-center">
<q-card-section class="column items-center">
<div class="q-mb-lg">
<q-checkbox dark v-model="includeCategories" label="Include categories in the list?" />
</div>
<q-select
style="width: 400px;"
ref="ref_existingDocument"
style="flex-grow: 1;"
dense
dark
menu-anchor="bottom middle"
menu-self="top middle"
:options="filteredExistingInput"
use-input
outlined
@ -40,6 +45,7 @@
</q-item-section>
<q-item-section>
<q-item-label v-html="opt.label" ></q-item-label>
<q-item-label caption class="text-cultured">{{opt.hierarchicalPath}}</q-item-label>
</q-item-section>
<q-btn
tabindex="-1"
@ -99,6 +105,7 @@ export default class ExistingDocumentDialog extends DialogBase {
}
}
existingObjectsBackupList = [] as I_ShortenedDocument[]
existingObjectList = [] as I_ShortenedDocument[]
async populateExistingObjectDialog () {
@ -115,15 +122,19 @@ export default class ExistingDocumentDialog extends DialogBase {
id: doc._id,
url: doc.url,
type: doc.type,
// @ts-ignore
hierarchicalPath: this.getDocumentHieararchicalPath(doc, dbDocuments.rows),
color: doc.extraFields.find(e => e.id === "documentColor")?.value,
isCategory: doc.extraFields.find(e => e.id === "categorySwitch")?.value
} as unknown as I_ShortenedDocument
}).sort((a, b) => a.label.localeCompare(b.label))
})
.sort((a, b) => a.label.localeCompare(b.label))
// @ts-ignore
allDocs = [...allDocs, ...formattedDocuments]
}
this.existingObjectList = allDocs
this.existingObjectsBackupList = allDocs
this.filterDocuments()
this.$nextTick(function () {
/*eslint-disable */
@ -190,6 +201,17 @@ export default class ExistingDocumentDialog extends DialogBase {
// @ts-ignore
this.addNewObjectRoute(routeObject)
}
includeCategories = true
@Watch("includeCategories")
reactToCheckboxChange () {
this.filterDocuments()
}
filterDocuments () {
this.existingObjectList = this.existingObjectsBackupList.filter(e => !((!this.includeCategories && e.isCategory)))
}
}
</script>

View file

@ -42,6 +42,10 @@
<div class="flex" v-if="editMode">
<q-select
menu-anchor="bottom middle"
menu-self="top middle"
class="multiRelashionshipSelect"
dark
style="flex-grow: 1;"
dense
:options="filteredInput"
@ -60,7 +64,10 @@
v-on="itemEvents"
>
<q-item-section>
<q-item-label v-html="opt.label" ></q-item-label>
<q-item-label
:style="`color: ${opt.color}`"
v-html="opt.label" ></q-item-label>
<q-item-label caption class="text-cultured">{{opt.hierarchicalPath}}</q-item-label>
</q-item-section>
<q-tooltip v-if='opt.disable'>
This option is unavailable for selection as it is already paired to another.
@ -193,7 +200,9 @@ export default class Field_SingleRelationship extends BaseClass {
if (this.inputDataBluePrint?.relationshipSettings && this.currentId.length > 0) {
const CurrentObjectDB = new PouchDB(this.inputDataBluePrint.relationshipSettings.connectedObjectType)
const allObjects = (await CurrentObjectDB.allDocs({ include_docs: true })).rows.map((doc) => {
const allDbObjects = (await CurrentObjectDB.allDocs({ include_docs: true })).rows
const allObjects = allDbObjects.map((doc) => {
const objectDoc = doc.doc as unknown as I_ShortenedDocument
const pairedField = (this.inputDataBluePrint?.relationshipSettings?.connectedField) || ""
@ -216,7 +225,11 @@ export default class Field_SingleRelationship extends BaseClass {
url: `/project/display-content/${objectDoc.type}/${objectDoc._id}`,
label: objectDoc.extraFields.find(e => e.id === "name")?.value,
isCategory: objectDoc.extraFields.find(e => e.id === "categorySwitch")?.value,
pairedField: pairedField
color: objectDoc.extraFields.find(e => e.id === "documentColor")?.value,
pairedField: pairedField,
// @ts-ignore
hierarchicalPath: this.getDocumentHieararchicalPath(objectDoc, allDbObjects)
}
}) as unknown as I_FieldRelationship[]
@ -289,4 +302,5 @@ table {
color: #000;
opacity: 0.8;
}
</style>

View file

@ -39,6 +39,10 @@
<div class="flex" v-if="editMode">
<q-select
class="singleRelashionshipSelect"
menu-anchor="bottom middle"
menu-self="top middle"
dark
style="flex-grow: 1;"
dense
:options="filteredInput"
@ -55,7 +59,10 @@
v-on="itemEvents"
>
<q-item-section>
<q-item-label v-html="opt.label" ></q-item-label>
<q-item-label
:style="`color: ${opt.color}`"
v-html="opt.label" ></q-item-label>
<q-item-label caption class="text-cultured">{{opt.hierarchicalPath}}</q-item-label>
</q-item-section>
<q-tooltip v-if='opt.disable'>
This option is unavailable for selection as it is already paired to another.
@ -187,7 +194,9 @@ export default class Field_SingleRelationship extends BaseClass {
if (this.inputDataBluePrint?.relationshipSettings && this.currentId.length > 0) {
const CurrentObjectDB = new PouchDB(this.inputDataBluePrint.relationshipSettings.connectedObjectType)
const allObjects = (await CurrentObjectDB.allDocs({ include_docs: true })).rows.map((doc) => {
const allDbObjects = (await CurrentObjectDB.allDocs({ include_docs: true })).rows
const allObjects = allDbObjects.map((doc) => {
const objectDoc = doc.doc as unknown as I_ShortenedDocument
const pairedField = (this.inputDataBluePrint?.relationshipSettings?.connectedField) || ""
@ -210,8 +219,11 @@ export default class Field_SingleRelationship extends BaseClass {
disable: isDisabled,
url: `/project/display-content/${objectDoc.type}/${objectDoc._id}`,
label: objectDoc.extraFields.find(e => e.id === "name")?.value,
color: objectDoc.extraFields.find(e => e.id === "documentColor")?.value,
isCategory: objectDoc.extraFields.find(e => e.id === "categorySwitch")?.value,
pairedField: pairedField
pairedField: pairedField,
// @ts-ignore
hierarchicalPath: this.getDocumentHieararchicalPath(objectDoc, allDbObjects)
}
}) as unknown as I_FieldRelationship[]

View file

@ -60,3 +60,19 @@ body {
.q-toggle__inner--truthy .q-toggle__thumb {
left: calc(100% - 30px);
}
.singleRelashionshipSelect,
.multiRelashionshipSelect {
&.q-field--dark .q-field__control::before {
border: 1px solid rgba(0, 0, 0, 0.24);
}
.q-field__input,
.q-field__native span {
color: #000 !important;
}
}
.q-menu .q-item {
transition: none !important;
}

View file

@ -23,6 +23,7 @@ export interface I_ShortenedDocument{
url: string
expandable?: boolean
_id: string
isCategory?: boolean
parentDoc: string | false
children: I_ShortenedDocument[]
extraFields: I_ExtraDocumentFields[]

View file

@ -69,7 +69,7 @@
<Field_Text
class="inputWrapper"
v-if="(field.type === 'text' && retrieveFieldValue(currentData,field.id) || field.type === 'text' && retrieveFieldLength(currentData,field.id) === 0) && fieldLimiter(field.id)"
v-if="field.type === 'text' && fieldLimiter(field.id)"
:inputDataBluePrint="field"
:inputDataValue="retrieveFieldValue(currentData, field.id)"
:isNew="currentData.isNew"
@ -262,7 +262,8 @@ export default class PageDocumentDisplay extends BaseClass {
const dataCopy: I_OpenedDocument = extend(true, {}, this.currentData)
// Attempts to add current document to list
this.SSET_addOpenedDocument(dataCopy)
const dataPass = { doc: dataCopy, treeAction: false }
this.SSET_addOpenedDocument(dataPass)
}
reactToFieldUpdate (inputData: string, field: I_ExtraFields) {
@ -274,7 +275,8 @@ export default class PageDocumentDisplay extends BaseClass {
const dataCopy: I_OpenedDocument = extend(true, {}, this.currentData)
this.SSET_updateOpenedDocument(dataCopy)
const dataPass = { doc: dataCopy, treeAction: false }
this.SSET_updateOpenedDocument(dataPass)
}
// FIELD - Number
@ -285,7 +287,8 @@ export default class PageDocumentDisplay extends BaseClass {
const dataCopy: I_OpenedDocument = extend(true, {}, this.currentData)
this.SSET_updateOpenedDocument(dataCopy)
const dataPass = { doc: dataCopy, treeAction: false }
this.SSET_updateOpenedDocument(dataPass)
}
// FIELD - Switch
@ -296,7 +299,8 @@ export default class PageDocumentDisplay extends BaseClass {
const dataCopy: I_OpenedDocument = extend(true, {}, this.currentData)
this.SSET_updateOpenedDocument(dataCopy)
const dataPass = { doc: dataCopy, treeAction: false }
this.SSET_updateOpenedDocument(dataPass)
if (field.id === "categorySwitch") {
const localCopy: I_Blueprint = (extend(true, {}, this.bluePrintData))
@ -319,7 +323,8 @@ export default class PageDocumentDisplay extends BaseClass {
const dataCopy: I_OpenedDocument = extend(true, {}, this.currentData)
this.SSET_updateOpenedDocument(dataCopy)
const dataPass = { doc: dataCopy, treeAction: false }
this.SSET_updateOpenedDocument(dataPass)
}
// FIELD - List
@ -329,7 +334,8 @@ export default class PageDocumentDisplay extends BaseClass {
this.currentData.extraFields[indexToUpdate].value = inputData
const dataCopy: I_OpenedDocument = extend(true, {}, this.currentData)
this.SSET_updateOpenedDocument(dataCopy)
const dataPass = { doc: dataCopy, treeAction: false }
this.SSET_updateOpenedDocument(dataPass)
}
// FIELD - Simple select
@ -340,7 +346,8 @@ export default class PageDocumentDisplay extends BaseClass {
const dataCopy: I_OpenedDocument = extend(true, {}, this.currentData)
this.SSET_updateOpenedDocument(dataCopy)
const dataPass = { doc: dataCopy, treeAction: false }
this.SSET_updateOpenedDocument(dataPass)
}
// FIELD - Multi select
@ -351,7 +358,8 @@ export default class PageDocumentDisplay extends BaseClass {
const dataCopy: I_OpenedDocument = extend(true, {}, this.currentData)
this.SSET_updateOpenedDocument(dataCopy)
const dataPass = { doc: dataCopy, treeAction: false }
this.SSET_updateOpenedDocument(dataPass)
}
// FIELD - Single relationship
@ -362,7 +370,8 @@ export default class PageDocumentDisplay extends BaseClass {
const dataCopy: I_OpenedDocument = extend(true, {}, this.currentData)
this.SSET_updateOpenedDocument(dataCopy)
const dataPass = { doc: dataCopy, treeAction: false }
this.SSET_updateOpenedDocument(dataPass)
}
// FIELD - Multi relationship
@ -373,7 +382,8 @@ export default class PageDocumentDisplay extends BaseClass {
const dataCopy: I_OpenedDocument = extend(true, {}, this.currentData)
this.SSET_updateOpenedDocument(dataCopy)
const dataPass = { doc: dataCopy, treeAction: false }
this.SSET_updateOpenedDocument(dataPass)
}
// FIELD - Wysiwyg
@ -384,7 +394,8 @@ export default class PageDocumentDisplay extends BaseClass {
const dataCopy: I_OpenedDocument = extend(true, {}, this.currentData)
this.SSET_updateOpenedDocument(dataCopy)
const dataPass = { doc: dataCopy, treeAction: false }
this.SSET_updateOpenedDocument(dataPass)
}
}
@ -392,7 +403,8 @@ export default class PageDocumentDisplay extends BaseClass {
this.editMode = true
this.currentData.editMode = true
const dataCopy: I_OpenedDocument = extend(true, {}, this.currentData)
this.SSET_updateOpenedDocument(dataCopy)
const dataPass = { doc: dataCopy, treeAction: false }
this.SSET_updateOpenedDocument(dataPass)
}
async saveDocument () {
@ -449,7 +461,10 @@ export default class PageDocumentDisplay extends BaseClass {
if (toUpdateIndex) {
const docCopy: I_OpenedDocument = extend(true, {}, this.SGET_openedDocument(doc._id))
docCopy.extraFields[toUpdateIndex] = doc.extraFields[toUpdateIndex]
this.SSET_updateOpenedDocument(docCopy)
// Tree action here due to how parentDoc field works
const dataPass = { doc: docCopy, treeAction: true }
this.SSET_updateOpenedDocument(dataPass)
}
})
}
@ -473,7 +488,9 @@ export default class PageDocumentDisplay extends BaseClass {
if (toUpdateIndex) {
const docCopy: I_OpenedDocument = extend(true, {}, this.SGET_openedDocument(doc._id))
docCopy.extraFields[toUpdateIndex] = doc.extraFields[toUpdateIndex]
this.SSET_updateOpenedDocument(docCopy)
const dataPass = { doc: docCopy, treeAction: false }
this.SSET_updateOpenedDocument(dataPass)
}
})
}
@ -481,7 +498,8 @@ export default class PageDocumentDisplay extends BaseClass {
await CurrentObjectDB.put(documentCopy)
// Update the opened document
this.SSET_updateOpenedDocument(documentCopy)
const dataPass = { doc: documentCopy, treeAction: true }
this.SSET_updateOpenedDocument(dataPass)
}
deleteConfirmationDialog = false
@ -534,7 +552,8 @@ export default class PageDocumentDisplay extends BaseClass {
const dataCopy: I_OpenedDocument = extend(true, {}, this.currentData)
this.SSET_removeOpenedDocument(dataCopy)
const dataPass = { doc: dataCopy, treeAction: true }
this.SSET_removeOpenedDocument(dataPass)
}
currentData = false as unknown as I_OpenedDocument

View file

@ -3,9 +3,46 @@ import { StateInterface } from "../index"
import { OpenDocumentsStateInterface } from "./state"
const actions: ActionTree<OpenDocumentsStateInterface, StateInterface> = {
// someAction (context) {
// }
addDocument (state, input) {
state.commit("addDocument", input)
setTimeout(() => {
state.commit("resetTreeAction")
}, 200)
},
updateDocument (state, input) {
state.commit("updateDocument", input)
setTimeout(() => {
state.commit("resetTreeAction")
}, 200)
},
removeDocument (state, input) {
state.commit("removeDocument", input)
setTimeout(() => {
state.commit("resetTreeAction")
}, 200)
},
resetDocuments (state) {
state.commit("resetDocuments")
setTimeout(() => {
state.commit("resetTreeAction")
}, 200)
},
triggerTreeAction (state) {
state.commit("triggerTreeAction")
setTimeout(() => {
state.commit("resetTreeAction")
}, 200)
}
}
export default actions

View file

@ -5,31 +5,56 @@ import { I_OpenedDocument } from "./../../interfaces/I_OpenedDocument"
import { uid } from "quasar"
const mutation: MutationTree<OpenDocumentsStateInterface> = {
addDocument (state: OpenDocumentsStateInterface, input: I_OpenedDocument) {
addDocument (state: OpenDocumentsStateInterface, input: {
doc: I_OpenedDocument,
treeAction: boolean
}) {
if (!state.documents.docs.find(doc => {
return doc.type === input.type && doc._id === input._id
return doc.type === input.doc.type && doc._id === input.doc._id
})) {
state.documents.docs.push(input)
state.documents.docs.push(input.doc)
state.documents.treeAction = input.treeAction
state.documents.timestamp = uid()
}
},
updateDocument (state: OpenDocumentsStateInterface, input: I_OpenedDocument) {
const toUpdateDocIndex = state.documents.docs.findIndex(doc => doc.type === input.type && doc._id === input._id)
updateDocument (state: OpenDocumentsStateInterface, input: {
doc: I_OpenedDocument,
treeAction: boolean
}) {
const toUpdateDocIndex = state.documents.docs.findIndex(doc => doc.type === input.doc.type && doc._id === input.doc._id)
state.documents.docs[toUpdateDocIndex] = input
state.documents.docs[toUpdateDocIndex] = input.doc
state.documents.treeAction = input.treeAction
state.documents.timestamp = uid()
},
removeDocument (state: OpenDocumentsStateInterface, input: I_OpenedDocument) {
const toRemoveIndex = state.documents.docs.findIndex(doc => doc.type === input.type && doc._id === input._id)
removeDocument (state: OpenDocumentsStateInterface, input: {
doc: I_OpenedDocument,
treeAction: boolean
}) {
const toRemoveIndex = state.documents.docs.findIndex(doc => doc.type === input.doc.type && doc._id === input.doc._id)
state.documents.docs.splice(toRemoveIndex, 1)
state.documents.treeAction = input.treeAction
state.documents.timestamp = uid()
},
resetTreeAction (state: OpenDocumentsStateInterface) {
state.documents.treeAction = false
},
triggerTreeAction (state: OpenDocumentsStateInterface) {
state.documents.treeAction = true
},
resetDocuments (state: OpenDocumentsStateInterface) {
state.documents.docs = []
state.documents.treeAction = true
state.documents.timestamp = uid()
setTimeout(() => {
state.documents.treeAction = false
}, 200)
}
}

View file

@ -3,6 +3,7 @@ import { I_OpenedDocument } from "./../../interfaces/I_OpenedDocument"
export interface OpenDocumentsStateInterface {
documents: {
timestamp: string,
treeAction: boolean,
docs: I_OpenedDocument[]
}
}
@ -11,6 +12,7 @@ function state (): OpenDocumentsStateInterface {
return {
documents: {
timestamp: "",
treeAction: false,
docs: []
}
}