2021-03-18 10:26:08 +13:00
|
|
|
import { OptionsStateInteface } from "./store/module-options/state"
|
2021-02-23 11:30:18 +13:00
|
|
|
import { KeyManagementInterface } from "./store/module-keybinds/state"
|
2021-03-03 08:59:56 +13:00
|
|
|
import { I_OpenedDocument, I_ShortenedDocument } from "./interfaces/I_OpenedDocument"
|
2021-01-31 02:43:13 +13:00
|
|
|
import { Component, Vue } from "vue-property-decorator"
|
|
|
|
import { namespace } from "vuex-class"
|
|
|
|
import { I_Blueprint } from "src/interfaces/I_Blueprint"
|
|
|
|
import { I_NewObjectTrigger } from "src/interfaces/I_NewObjectTrigger"
|
2021-04-20 05:51:44 +12:00
|
|
|
import { uid, colors, extend } from "quasar"
|
2021-01-31 02:43:13 +13:00
|
|
|
import { I_FieldRelationship } from "src/interfaces/I_FieldRelationship"
|
2021-02-23 11:30:18 +13:00
|
|
|
import { I_KeyPressObject } from "src/interfaces/I_KeypressObject"
|
2021-06-13 08:23:20 +12:00
|
|
|
import { ProjectInterface } from "./store/module-project/state"
|
2021-01-31 02:43:13 +13:00
|
|
|
|
|
|
|
const Blueprints = namespace("blueprintsModule")
|
2021-04-26 09:01:41 +12:00
|
|
|
const AllDocuments = namespace("allDocumentsModule")
|
2021-01-31 02:43:13 +13:00
|
|
|
const OpenedDocuments = namespace("openedDocumentsModule")
|
2021-02-23 11:30:18 +13:00
|
|
|
const Keybinds = namespace("keybindsModule")
|
2021-03-18 10:26:08 +13:00
|
|
|
const Options = namespace("optionsModule")
|
|
|
|
const Dialogs = namespace("dialogsModule")
|
2021-04-13 13:32:59 +12:00
|
|
|
const FloatingWindows = namespace("floatingWindowsModule")
|
2021-06-13 08:23:20 +12:00
|
|
|
const Project = namespace("projectModule")
|
2021-01-31 02:43:13 +13:00
|
|
|
|
|
|
|
@Component
|
|
|
|
export default class BaseClass extends Vue {
|
2021-04-06 01:28:33 +12:00
|
|
|
/****************************************************************/
|
|
|
|
// UTILITY FUNCTIONS
|
|
|
|
/****************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates unique ID string
|
|
|
|
*/
|
2021-02-26 14:50:46 +13:00
|
|
|
generateUID () : string {
|
|
|
|
return uid()
|
|
|
|
}
|
|
|
|
|
2021-04-06 01:28:33 +12:00
|
|
|
/**
|
|
|
|
* Retrieves icon color for relationship searches
|
|
|
|
* If the current document has "activeTypeSearch" property, then return "primary" color instead
|
|
|
|
*/
|
|
|
|
retrieveIconColor (document: I_ShortenedDocument): string {
|
|
|
|
// @ts-ignore
|
|
|
|
return (document.activeTypeSearch) ? colors.getBrand("primary") : document.color
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-05-02 02:31:33 +12:00
|
|
|
* Async wait for XY miliseconds
|
2021-04-06 01:28:33 +12:00
|
|
|
*/
|
|
|
|
sleep (ms:number) {
|
|
|
|
return new Promise(resolve => setTimeout(resolve, ms))
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-05-02 02:31:33 +12:00
|
|
|
* Strip all tags from a string
|
2021-04-06 01:28:33 +12:00
|
|
|
*/
|
|
|
|
stripTags (input: string) {
|
|
|
|
return (input) ? input.replace(/<[^>]+>/g, "") : input
|
|
|
|
}
|
|
|
|
|
2021-06-13 08:23:20 +12:00
|
|
|
/****************************************************************/
|
|
|
|
// PROJECT
|
|
|
|
/****************************************************************/
|
|
|
|
|
|
|
|
@Project.Getter("getProjectData") SGET_getProjectData!: ProjectInterface
|
|
|
|
|
|
|
|
@Project.Getter("getProjectLoadedStatus") SGET_getProjectLoadedStatus!: boolean
|
|
|
|
@Project.Action("setProjecLoadingState") SSET_setProjecLoadingState!: (input: boolean) => void
|
|
|
|
|
|
|
|
@Project.Getter("getProjectName") SGET_getProjectName!: string
|
|
|
|
@Project.Action("setProjectName") SSET_setProjectName!: (input: string) => void
|
|
|
|
|
2021-04-13 13:32:59 +12:00
|
|
|
/****************************************************************/
|
|
|
|
// FLOATING WINDOWS
|
|
|
|
/****************************************************************/
|
|
|
|
|
|
|
|
@FloatingWindows.Getter("getAdvSearchWindowVisible") SGET_getAdvSearchWindowVisible!: string
|
|
|
|
@FloatingWindows.Mutation("setAdvSearchWindowVisible") SSET_setAdvSearchWindowVisible!: () => void
|
|
|
|
|
2021-06-13 11:24:28 +12:00
|
|
|
@FloatingWindows.Getter("getNoteCorkboardWindowVisible") SGET_getNoteCorkboardWindowVisible!: string
|
2021-05-02 02:31:33 +12:00
|
|
|
@FloatingWindows.Mutation("setNoteCorkboardWindowVisible") SSET_setNoteCorkboardWindowVisible!: () => void
|
|
|
|
|
2021-06-07 12:57:36 +12:00
|
|
|
@FloatingWindows.Getter("getDocumentPreviewVisible") SGET_getDocumentPreviewVisible!: string
|
|
|
|
@FloatingWindows.Mutation("setDocumentPreviewWindowVisible") SSET_setDocumentPreviewWindowVisible!: (input:boolean) => void
|
|
|
|
|
|
|
|
@FloatingWindows.Getter("getDocumentPreviewWindowID") SGET_getDocumentPreviewWindowID!: string
|
|
|
|
@FloatingWindows.Mutation("setDocumentPreviewWindowID") SSET_setDocumentPreviewWindowID!: (input: string) => void
|
|
|
|
|
|
|
|
openDocumentPreviewPanel (id: string) {
|
|
|
|
this.SSET_setDocumentPreviewWindowID(id)
|
|
|
|
this.SSET_setDocumentPreviewWindowVisible(true)
|
|
|
|
}
|
|
|
|
|
2021-02-23 11:30:18 +13:00
|
|
|
/****************************************************************/
|
2021-04-06 01:28:33 +12:00
|
|
|
// KEYBINDS MANAGEMENT
|
2021-02-23 11:30:18 +13:00
|
|
|
/****************************************************************/
|
|
|
|
|
|
|
|
@Keybinds.Getter("getCurrentKeyBindData") SGET_getCurrentKeyBindData!: KeyManagementInterface
|
|
|
|
|
|
|
|
@Keybinds.Mutation("registerDefaultKeybind") SSET_registerDefaultKeybind!: (input: I_KeyPressObject) => void
|
|
|
|
@Keybinds.Mutation("deregisterDefaultKeybind") SSET_deregisterDefaultKeybind!: (input: I_KeyPressObject) => void
|
|
|
|
@Keybinds.Mutation("registerUserKeybind") SSET_registerUserKeybind!: (input: I_KeyPressObject) => void
|
|
|
|
@Keybinds.Mutation("deregisterUserKeybind") SSET_deregisterUserKeybind!: (input: I_KeyPressObject) => void
|
|
|
|
@Keybinds.Mutation("updatePressedKey") SSET_updatePressedKey!: (input: I_KeyPressObject) => void
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds a humanly redable represetation of the keybind in string form
|
|
|
|
* @param keybindId - Keybind object to build the string out of
|
|
|
|
*/
|
|
|
|
retrieveKeybindString (keybind: I_KeyPressObject): string {
|
|
|
|
let keybindString = ""
|
|
|
|
|
2021-03-18 10:26:08 +13:00
|
|
|
if (!keybind) {
|
|
|
|
return keybindString
|
|
|
|
}
|
|
|
|
|
2021-02-23 11:30:18 +13:00
|
|
|
if (keybind.ctrlKey) {
|
|
|
|
keybindString += "CTRL + "
|
|
|
|
}
|
|
|
|
|
|
|
|
if (keybind.altKey) {
|
|
|
|
keybindString += "ALT + "
|
|
|
|
}
|
|
|
|
|
|
|
|
if (keybind.shiftKey) {
|
|
|
|
keybindString += "SHIFT + "
|
|
|
|
}
|
|
|
|
|
2021-03-18 10:26:08 +13:00
|
|
|
const keybinds = [37, 38, 39, 40, 9, 32, 13, 192, 189, 187, 219, 221, 220, 186, 222, 188, 190, 191, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123]
|
2021-02-23 11:30:18 +13:00
|
|
|
|
2021-03-18 10:26:08 +13:00
|
|
|
if (keybinds.includes(keybind.which)) {
|
|
|
|
if (keybind.which === 13) {
|
2021-02-23 11:30:18 +13:00
|
|
|
keybindString += "ENTER"
|
|
|
|
}
|
2021-03-18 10:26:08 +13:00
|
|
|
if (keybind.which === 9) {
|
2021-02-23 11:30:18 +13:00
|
|
|
keybindString += "TAB"
|
|
|
|
}
|
2021-03-18 10:26:08 +13:00
|
|
|
if (keybind.which === 32) {
|
2021-02-23 11:30:18 +13:00
|
|
|
keybindString += "SPACE"
|
|
|
|
}
|
2021-03-18 10:26:08 +13:00
|
|
|
if (keybind.which === 37) {
|
2021-02-23 11:30:18 +13:00
|
|
|
keybindString += "LEFT ARROW"
|
|
|
|
}
|
2021-03-18 10:26:08 +13:00
|
|
|
if (keybind.which === 38) {
|
2021-02-23 11:30:18 +13:00
|
|
|
keybindString += "UP ARROW"
|
|
|
|
}
|
2021-03-18 10:26:08 +13:00
|
|
|
if (keybind.which === 39) {
|
2021-02-23 11:30:18 +13:00
|
|
|
keybindString += "RIGHT ARROW"
|
|
|
|
}
|
2021-03-18 10:26:08 +13:00
|
|
|
if (keybind.which === 40) {
|
2021-02-23 11:30:18 +13:00
|
|
|
keybindString += "DOWN ARROW"
|
|
|
|
}
|
2021-03-18 10:26:08 +13:00
|
|
|
if (keybind.which === 192) {
|
|
|
|
keybindString += "`"
|
|
|
|
}
|
|
|
|
if (keybind.which === 189) {
|
|
|
|
keybindString += "-"
|
|
|
|
}
|
|
|
|
if (keybind.which === 187) {
|
|
|
|
keybindString += "+"
|
|
|
|
}
|
|
|
|
if (keybind.which === 219) {
|
|
|
|
keybindString += "["
|
|
|
|
}
|
|
|
|
if (keybind.which === 221) {
|
|
|
|
keybindString += "]"
|
|
|
|
}
|
|
|
|
if (keybind.which === 220) {
|
|
|
|
keybindString += "\\"
|
|
|
|
}
|
|
|
|
if (keybind.which === 186) {
|
|
|
|
keybindString += ";"
|
|
|
|
}
|
|
|
|
if (keybind.which === 222) {
|
|
|
|
keybindString += "'"
|
|
|
|
}
|
|
|
|
if (keybind.which === 188) {
|
|
|
|
keybindString += ","
|
|
|
|
}
|
|
|
|
if (keybind.which === 190) {
|
|
|
|
keybindString += "."
|
|
|
|
}
|
|
|
|
if (keybind.which === 191) {
|
|
|
|
keybindString += "/"
|
|
|
|
}
|
|
|
|
if (keybind.which === 112) {
|
|
|
|
keybindString += "F1"
|
|
|
|
}
|
|
|
|
if (keybind.which === 113) {
|
|
|
|
keybindString += "F2"
|
|
|
|
}
|
|
|
|
if (keybind.which === 114) {
|
|
|
|
keybindString += "F3"
|
|
|
|
}
|
|
|
|
if (keybind.which === 115) {
|
|
|
|
keybindString += "F4"
|
|
|
|
}
|
|
|
|
if (keybind.which === 116) {
|
|
|
|
keybindString += "F5"
|
|
|
|
}
|
|
|
|
if (keybind.which === 117) {
|
|
|
|
keybindString += "F6"
|
|
|
|
}
|
|
|
|
if (keybind.which === 118) {
|
|
|
|
keybindString += "F7"
|
|
|
|
}
|
|
|
|
if (keybind.which === 119) {
|
|
|
|
keybindString += "F8"
|
|
|
|
}
|
|
|
|
if (keybind.which === 120) {
|
|
|
|
keybindString += "F9"
|
|
|
|
}
|
|
|
|
if (keybind.which === 121) {
|
|
|
|
keybindString += "F10"
|
|
|
|
}
|
|
|
|
if (keybind.which === 122) {
|
|
|
|
keybindString += "F11"
|
|
|
|
}
|
|
|
|
if (keybind.which === 123) {
|
|
|
|
keybindString += "F12"
|
|
|
|
}
|
2021-02-23 11:30:18 +13:00
|
|
|
}
|
|
|
|
else {
|
2021-03-18 10:26:08 +13:00
|
|
|
keybindString += String.fromCharCode(keybind.which)
|
2021-02-23 11:30:18 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
if (keybind.note) {
|
|
|
|
keybindString += `<div class="text-italic keybindNote">${keybind.note}</div>`
|
|
|
|
}
|
|
|
|
|
|
|
|
return keybindString
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines if the keybind triggered the proper condition
|
|
|
|
* @param keybindId - ID of the keybind to determine what to match
|
|
|
|
*/
|
|
|
|
determineKeyBind (keybindId: string): boolean {
|
|
|
|
const currentKeybindData = this.SGET_getCurrentKeyBindData
|
|
|
|
|
|
|
|
const currentKeyPress = currentKeybindData.currentKeyPress
|
|
|
|
const pairedDefaultKeybind = currentKeybindData.defaults.find(e => e.id === keybindId)
|
|
|
|
const pairedCustomKeybind = currentKeybindData.userKeybinds.find(e => e.id === keybindId)
|
|
|
|
|
|
|
|
// Kill the script if no keybind exists of this anywhere
|
|
|
|
if (!pairedDefaultKeybind) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
const fieldToCheck = (pairedCustomKeybind) || pairedDefaultKeybind
|
|
|
|
|
|
|
|
if (
|
|
|
|
currentKeyPress.altKey === fieldToCheck.altKey &&
|
|
|
|
currentKeyPress.ctrlKey === fieldToCheck.ctrlKey &&
|
|
|
|
currentKeyPress.shiftKey === fieldToCheck.shiftKey &&
|
2021-03-18 10:26:08 +13:00
|
|
|
currentKeyPress.which === fieldToCheck.which
|
2021-02-23 11:30:18 +13:00
|
|
|
) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-31 02:43:13 +13:00
|
|
|
/****************************************************************/
|
2021-04-06 01:28:33 +12:00
|
|
|
// BLUEPRINT MANAGEMENT
|
2021-01-31 02:43:13 +13:00
|
|
|
/****************************************************************/
|
|
|
|
|
|
|
|
@Blueprints.Getter("getAllBlueprints") SGET_allBlueprints !: I_Blueprint[]
|
|
|
|
@Blueprints.Getter("getBlueprint") SGET_blueprint!: (type: string) => I_Blueprint
|
|
|
|
|
|
|
|
@Blueprints.Mutation("setAllBlueprints") SSET_allBlueprints!: (input: I_Blueprint[]) => void
|
2021-02-21 01:06:21 +13:00
|
|
|
@Blueprints.Mutation("setBlueprint") SSET_blueprint!: (input: I_Blueprint) => void
|
2021-01-31 02:43:13 +13:00
|
|
|
|
2021-02-23 11:30:18 +13:00
|
|
|
/**
|
|
|
|
* Generates a brand new route for the new object with individual ID
|
|
|
|
* @param newObject A new object to be creared
|
|
|
|
*/
|
|
|
|
addNewObjectRoute (newObject: I_NewObjectTrigger) {
|
|
|
|
const parentID = (newObject?.parent) || ""
|
2021-06-07 12:57:36 +12:00
|
|
|
const tag = (newObject?.tag) || ""
|
2021-02-23 11:30:18 +13:00
|
|
|
|
|
|
|
this.$router.push({
|
|
|
|
path: `/project/display-content/${newObject._id}/${uid()}`,
|
2021-06-07 12:57:36 +12:00
|
|
|
query: { parent: parentID, tag: tag }
|
2021-02-23 11:30:18 +13:00
|
|
|
}).catch((e: {name: string}) => {
|
2021-01-31 02:43:13 +13:00
|
|
|
const errorName : string = e.name
|
|
|
|
if (errorName === "NavigationDuplicated") {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
console.log(e)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-04-11 13:40:03 +12:00
|
|
|
/**
|
|
|
|
* Open a new route for an already existing object
|
|
|
|
* @param existingObject An already existing object passed in
|
|
|
|
*/
|
|
|
|
openExistingDocumentRouteWithEdit (existingObject:I_OpenedDocument | I_FieldRelationship) {
|
2021-04-20 05:51:44 +12:00
|
|
|
const currentDoc = this.findRequestedOrActiveDocument()
|
|
|
|
|
|
|
|
if (currentDoc && existingObject._id === currentDoc._id && !currentDoc.editMode) {
|
|
|
|
const dataCopy: I_OpenedDocument = extend(true, {}, currentDoc)
|
|
|
|
dataCopy.editMode = true
|
|
|
|
const dataPass = { doc: dataCopy, treeAction: false }
|
|
|
|
this.SSET_updateOpenedDocument(dataPass)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-04-11 13:40:03 +12:00
|
|
|
this.$router.push({
|
|
|
|
path: existingObject.url,
|
|
|
|
query: { editMode: "editMode" }
|
|
|
|
}).catch((e: {name: string}) => {
|
|
|
|
const errorName : string = e.name
|
|
|
|
if (errorName === "NavigationDuplicated") {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
console.log(e)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-02-23 11:30:18 +13:00
|
|
|
/**
|
|
|
|
* Open a new route for an already existing object
|
|
|
|
* @param existingObject An already existing object passed in
|
|
|
|
*/
|
2021-06-13 08:23:20 +12:00
|
|
|
openExistingDocumentRoute (existingObject:I_OpenedDocument | I_FieldRelationship | I_ShortenedDocument) {
|
2021-02-23 11:30:18 +13:00
|
|
|
this.$router.push({ path: existingObject.url }).catch((e: {name: string}) => {
|
2021-01-31 02:43:13 +13:00
|
|
|
const errorName : string = e.name
|
|
|
|
if (errorName === "NavigationDuplicated") {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
console.log(e)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-03-18 10:26:08 +13:00
|
|
|
/****************************************************************/
|
2021-04-06 01:28:33 +12:00
|
|
|
// OPTION MANAGEMENT
|
2021-03-18 10:26:08 +13:00
|
|
|
/****************************************************************/
|
|
|
|
|
|
|
|
@Options.Getter("getOptions") SGET_options!: OptionsStateInteface
|
|
|
|
|
|
|
|
@Options.Action("setOptions") SSET_options!: (input: OptionsStateInteface) => void
|
|
|
|
|
2021-04-21 02:51:43 +12:00
|
|
|
toggleHierarchicalTree (): void {
|
|
|
|
const optionsSnapshot: OptionsStateInteface = extend(true, {}, this.SGET_options)
|
|
|
|
|
|
|
|
optionsSnapshot.hideHierarchyTree = !optionsSnapshot.hideHierarchyTree
|
|
|
|
|
|
|
|
this.SSET_options(optionsSnapshot)
|
|
|
|
}
|
|
|
|
|
2021-04-26 09:01:41 +12:00
|
|
|
/****************************************************************/
|
|
|
|
// 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
|
|
|
|
|
2021-01-31 02:43:13 +13:00
|
|
|
/****************************************************************/
|
2021-04-06 01:28:33 +12:00
|
|
|
// OPEN DOCUMENTS MANAGEMENT
|
2021-01-31 02:43:13 +13:00
|
|
|
/****************************************************************/
|
|
|
|
|
2021-03-08 11:07:40 +13:00
|
|
|
@OpenedDocuments.Getter("getAllDocuments") SGET_allOpenedDocuments !: {
|
|
|
|
treeAction: boolean,
|
|
|
|
lastRemovedIndex: number,
|
|
|
|
timestamp: string,
|
|
|
|
docs: I_OpenedDocument[]
|
|
|
|
}
|
|
|
|
|
2021-01-31 02:43:13 +13:00
|
|
|
@OpenedDocuments.Getter("getDocument") SGET_openedDocument!: (id: string) => I_OpenedDocument
|
|
|
|
|
2021-02-28 06:00:57 +13:00
|
|
|
@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
|
|
|
|
|
2021-04-10 12:22:31 +12:00
|
|
|
@OpenedDocuments.Action("closeAllDocuments") SSET_closeAllDocuments!: () => void
|
|
|
|
@OpenedDocuments.Action("forceCloseAllDocuments") SSET_forceCloseAllDocuments!: () => void
|
|
|
|
@OpenedDocuments.Action("closeAllButCurrentDocuments") SSET_closeAllButCurrentDocuments!: (input: I_OpenedDocument) => void
|
|
|
|
@OpenedDocuments.Action("forceCloseAllButCurrentDocuments") SSET_forceCloseAllButCurrentDocuments!: (input: I_OpenedDocument) => void
|
|
|
|
|
2021-02-28 06:00:57 +13:00
|
|
|
@OpenedDocuments.Action("triggerTreeAction") SSET_triggerTreeAction!: () => void
|
|
|
|
@OpenedDocuments.Action("resetDocuments") SSET_resetDocuments!: () => void
|
2021-03-08 11:07:40 +13:00
|
|
|
@OpenedDocuments.Action("resetRemoveIndex") SSET_resetRemoveIndex!: () => void
|
2021-01-31 02:43:13 +13:00
|
|
|
|
2021-04-06 01:28:33 +12:00
|
|
|
/**
|
|
|
|
* If provided with an document, finds it among the opened list
|
|
|
|
* Otherwise retireves the currently opened document based on the currently active route
|
|
|
|
*/
|
2021-03-05 01:51:11 +13:00
|
|
|
findRequestedOrActiveDocument (doc?: I_OpenedDocument) {
|
|
|
|
if (doc) {
|
|
|
|
return (this.SGET_allOpenedDocuments.docs.find(e => e.url === doc.url)) || false
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return (this.SGET_allOpenedDocuments.docs.find(e => e.url === this.$route.path)) || false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-23 11:30:18 +13:00
|
|
|
/**
|
|
|
|
* Retrieves value of requested field. If the field doesn't exist, returns false instead
|
|
|
|
* @param document - Document object that is expected to contain the field
|
|
|
|
* @param fieldID - ID of the field to check
|
|
|
|
*/
|
2021-04-26 09:01:41 +12:00
|
|
|
retrieveFieldValue (document: I_OpenedDocument| I_ShortenedDocument, fieldID: string) : string | number | [] | false | I_FieldRelationship {
|
2021-02-23 11:30:18 +13:00
|
|
|
const fieldData = document?.extraFields
|
|
|
|
|
|
|
|
// Fizzle if field doesnt exist
|
|
|
|
if (!fieldData) {
|
|
|
|
return false
|
|
|
|
}
|
2021-01-31 02:43:13 +13:00
|
|
|
const fieldValue = fieldData.find(f => f.id === fieldID)?.value as unknown as string
|
|
|
|
return fieldValue
|
|
|
|
}
|
|
|
|
|
2021-05-14 05:51:35 +12:00
|
|
|
/**
|
|
|
|
* Retrieves value of requested field. If the field doesn't exist, returns false instead
|
|
|
|
* @param document - Document object that is expected to contain the field
|
|
|
|
* @param fieldID - ID of the field to check
|
|
|
|
*/
|
|
|
|
retrieveFieldType (document: I_OpenedDocument| I_ShortenedDocument, fieldID: string) : string | number | [] | false | I_FieldRelationship {
|
|
|
|
const fieldData = document?.extraFields
|
|
|
|
|
|
|
|
// Fizzle if field doesnt exist
|
|
|
|
if (!fieldData) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
const documentBlueprint = this.SGET_blueprint(document.type)
|
|
|
|
|
|
|
|
const fieldType = documentBlueprint.extraFields.find(f => f.id === fieldID)?.type as unknown as string
|
|
|
|
return fieldType
|
|
|
|
}
|
|
|
|
|
2021-05-14 06:51:31 +12:00
|
|
|
/**
|
|
|
|
* Retrieves value of requested field. If the field doesn't exist, returns false instead
|
|
|
|
* @param document - Document object that is expected to contain the field
|
|
|
|
* @param fieldID - ID of the field to check
|
|
|
|
*/
|
|
|
|
determineLegacyField (document: I_OpenedDocument| I_ShortenedDocument, fieldID: string) : string | number | [] | false | I_FieldRelationship {
|
|
|
|
const fieldData = document?.extraFields
|
|
|
|
|
|
|
|
// Fizzle if field doesnt exist
|
|
|
|
if (!fieldData) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
const documentBlueprint = this.SGET_blueprint(document.type)
|
|
|
|
|
|
|
|
const legacyField = documentBlueprint.extraFields.find(f => f.id === fieldID)?.isLegacy as unknown as string
|
|
|
|
return (legacyField)
|
|
|
|
}
|
|
|
|
|
2021-02-23 11:30:18 +13:00
|
|
|
/**
|
|
|
|
* Retrieves array length of requested field. If the field doesn't exist or isn't array, returns false instead
|
|
|
|
* @param document - Document object that is expected to contain the field
|
|
|
|
* @param fieldID - ID of the field to check
|
|
|
|
*/
|
|
|
|
retrieveFieldLength (document: I_OpenedDocument, fieldID: string) : number | false {
|
|
|
|
const fieldData = document?.extraFields
|
|
|
|
|
|
|
|
// Fizzle if field doesnt exist
|
|
|
|
if (!fieldData) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
const fieldValue = fieldData.find(f => f.id === fieldID)?.value
|
|
|
|
|
|
|
|
// Fizzle if the value isn't an array
|
|
|
|
if (!Array.isArray(fieldValue)) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return fieldValue.length
|
2021-01-31 02:43:13 +13:00
|
|
|
}
|
|
|
|
|
2021-03-18 10:26:08 +13:00
|
|
|
@Dialogs.Getter("getDialogsState") SGET_getDialogsState!: boolean
|
2021-07-06 02:54:02 +12:00
|
|
|
@Dialogs.Getter("getExportDialogState") SGET_getExportDialogState!: {prepickedValue: string[], prepickedDocumentTemplate: string}
|
|
|
|
@Dialogs.Mutation("setExportDialogState") SSET_setExportDialogState!: (input: string[], prepickedTemplateID?: string) => void
|
2021-03-18 10:26:08 +13:00
|
|
|
|
2021-02-23 11:30:18 +13:00
|
|
|
/**
|
|
|
|
* Refreshes the route
|
|
|
|
*/
|
2021-01-31 02:43:13 +13:00
|
|
|
refreshRoute () {
|
2021-03-18 10:26:08 +13:00
|
|
|
if (this.SGET_options.disableCloseAftertSelectQuickSearch && this.SGET_getDialogsState) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-01-31 02:43:13 +13:00
|
|
|
const remainingDocuments = this.SGET_allOpenedDocuments.docs
|
|
|
|
|
2021-03-08 11:07:40 +13:00
|
|
|
const lastIndex = this.SGET_allOpenedDocuments.lastRemovedIndex
|
|
|
|
|
|
|
|
const newIndex = (lastIndex > -1 && lastIndex < remainingDocuments.length) ? lastIndex : remainingDocuments.length - 1
|
|
|
|
|
|
|
|
if (lastIndex > -1) {
|
|
|
|
this.SSET_resetRemoveIndex()
|
|
|
|
}
|
|
|
|
|
2021-02-23 11:30:18 +13:00
|
|
|
// Assuming there are any documents in the current list
|
2021-01-31 02:43:13 +13:00
|
|
|
if (remainingDocuments.length > 0) {
|
2021-03-08 11:07:40 +13:00
|
|
|
const lastDocument = remainingDocuments[newIndex]
|
2021-01-31 02:43:13 +13:00
|
|
|
const currentRoute = this.$router.currentRoute.path
|
|
|
|
const existingDocument = this.SGET_allOpenedDocuments.docs.find(e => {
|
|
|
|
return e.url === currentRoute
|
|
|
|
})
|
|
|
|
|
|
|
|
// Prevent infite route cycling by checking if this actually exists in the open tabs
|
2021-02-23 11:30:18 +13:00
|
|
|
if (existingDocument) {
|
|
|
|
return
|
|
|
|
}
|
2021-01-31 02:43:13 +13:00
|
|
|
|
2021-02-23 11:30:18 +13:00
|
|
|
// Load a new route if the new route isnt the one we are already on
|
2021-01-31 02:43:13 +13:00
|
|
|
const newRoute = `/project/display-content/${lastDocument.type}/${lastDocument._id}`
|
|
|
|
if (currentRoute !== newRoute) {
|
|
|
|
this.$router.push({ path: newRoute }).catch(e => console.log(e))
|
|
|
|
}
|
2021-02-23 11:30:18 +13:00
|
|
|
}
|
|
|
|
// If there are no documents inthe list, just navigate to the front page of the project
|
|
|
|
else {
|
2021-01-31 02:43:13 +13:00
|
|
|
this.$router.push({ path: "/project" }).catch((e: {name: string}) => {
|
2021-02-23 11:30:18 +13:00
|
|
|
if (e && e.name !== "NavigationDuplicated") {
|
|
|
|
console.log(e)
|
|
|
|
}
|
2021-01-31 02:43:13 +13:00
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2021-02-28 06:00:57 +13:00
|
|
|
|
|
|
|
/****************************************************************/
|
2021-04-06 01:28:33 +12:00
|
|
|
// DOCUMENT LIST MANAGEMENT
|
2021-02-28 06:00:57 +13:00
|
|
|
/****************************************************************/
|
2021-04-06 01:28:33 +12:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Recursively retrieves a full hieararchical path from a full list
|
|
|
|
*/
|
2021-03-05 01:51:11 +13:00
|
|
|
getDocumentHieararchicalPath (document: I_OpenedDocument, list: I_OpenedDocument[]) {
|
|
|
|
let hierarchicalString = ""
|
2021-02-28 06:00:57 +13:00
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
const parentDoc = (this.retrieveFieldValue(document, "parentDoc"))?.value
|
2021-03-05 01:51:11 +13:00
|
|
|
|
|
|
|
const parentDocInDB = (list.find(p => p._id === parentDoc?._id))
|
|
|
|
|
|
|
|
if (!parentDoc || (parentDoc && !parentDocInDB)) {
|
2021-05-18 08:36:41 +12:00
|
|
|
const pluralBlueprintName = this.SGET_allBlueprints.find(e => e._id === document.type)?.namePlural
|
|
|
|
hierarchicalString += pluralBlueprintName
|
2021-03-05 01:51:11 +13:00
|
|
|
return hierarchicalString
|
2021-02-28 06:00:57 +13:00
|
|
|
}
|
2021-03-05 01:51:11 +13:00
|
|
|
|
2021-02-28 06:00:57 +13:00
|
|
|
const matchingDoc = list.find((doc:I_OpenedDocument) => {
|
2021-03-05 01:51:11 +13:00
|
|
|
return doc._id === parentDoc._id
|
2021-02-28 06:00:57 +13:00
|
|
|
}) as I_OpenedDocument
|
|
|
|
|
|
|
|
// @ts-ignore
|
2021-03-05 01:51:11 +13:00
|
|
|
hierarchicalString += this.retrieveFieldValue(matchingDoc, "name")
|
2021-02-28 06:00:57 +13:00
|
|
|
|
|
|
|
// @ts-ignore
|
2021-03-05 01:51:11 +13:00
|
|
|
const connectedReturn = this.getDocumentHieararchicalPath(matchingDoc, list)
|
2021-02-28 06:00:57 +13:00
|
|
|
if (connectedReturn) {
|
2021-03-05 01:51:11 +13:00
|
|
|
hierarchicalString = `${connectedReturn} > ${hierarchicalString}`
|
2021-02-28 06:00:57 +13:00
|
|
|
}
|
|
|
|
|
2021-03-05 01:51:11 +13:00
|
|
|
return hierarchicalString
|
2021-02-28 06:00:57 +13:00
|
|
|
}
|
2021-03-03 08:59:56 +13:00
|
|
|
|
2021-04-26 09:01:41 +12:00
|
|
|
mapShortDocument (doc: I_ShortenedDocument, dbDocuments: I_OpenedDocument[]) : I_ShortenedDocument {
|
|
|
|
return {
|
|
|
|
label: doc.extraFields.find(e => e.id === "name")?.value,
|
|
|
|
icon: doc.icon,
|
2021-03-18 10:26:08 +13:00
|
|
|
// @ts-ignore
|
2021-04-26 09:01:41 +12:00
|
|
|
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
|
2021-04-06 01:28:33 +12:00
|
|
|
|
2021-03-18 10:26:08 +13:00
|
|
|
}
|
2021-04-26 09:01:41 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
2021-03-18 10:26:08 +13:00
|
|
|
}
|
2021-05-15 05:06:58 +12:00
|
|
|
|
|
|
|
checkForLegacyDocuments () {
|
|
|
|
return this.SGET_allDocuments.docs.filter(doc => {
|
2021-07-06 12:40:34 +12:00
|
|
|
const localBlueprint = this.SGET_blueprint(doc.type)
|
2021-05-15 05:06:58 +12:00
|
|
|
let hasLegacyValue = false
|
2021-07-06 12:39:40 +12:00
|
|
|
|
2021-07-06 12:40:34 +12:00
|
|
|
for (const field of doc.extraFields) {
|
2021-05-15 05:06:58 +12:00
|
|
|
const pairedBlueprintField = localBlueprint.extraFields.find(e => e.id === field.id)
|
2021-07-06 12:39:40 +12:00
|
|
|
|
|
|
|
if (pairedBlueprintField && pairedBlueprintField.isLegacy && !hasLegacyValue) {
|
2021-05-15 05:06:58 +12:00
|
|
|
const value = field.value
|
|
|
|
|
|
|
|
if (!value ||
|
|
|
|
(Array.isArray(value) && value.length === 0) ||
|
|
|
|
// @ts-ignore
|
|
|
|
(value?.value?.length === 0) ||
|
|
|
|
// @ts-ignore
|
|
|
|
(value.value === null)) {
|
|
|
|
}
|
2021-07-06 12:39:40 +12:00
|
|
|
else {
|
|
|
|
hasLegacyValue = true
|
|
|
|
}
|
2021-05-15 05:06:58 +12:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return hasLegacyValue
|
|
|
|
})
|
|
|
|
}
|
2021-01-31 02:43:13 +13:00
|
|
|
}
|