fantasia-archive/src/components/dialogs/ExistingDocument.vue

281 lines
8.2 KiB
Vue
Raw Normal View History

2021-02-26 14:50:46 +13:00
<template>
<q-dialog
2021-03-18 10:26:08 +13:00
no-route-dismiss
2021-02-26 14:50:46 +13:00
v-model="dialogModel"
@hide="triggerDialogClose"
>
<q-card
dark
class="existingDocumentPopup"
>
<q-card-section class="row items-center">
<h6 class="text-center q-my-sm">Open existing document</h6>
</q-card-section>
2021-02-28 06:00:57 +13:00
<q-card-section class="column items-center">
<div class="q-mb-lg">
2021-03-18 10:26:08 +13:00
<q-checkbox dark color="primary" v-model="includeCategories" label="Include categories in the list?" />
2021-02-28 06:00:57 +13:00
</div>
2021-02-26 14:50:46 +13:00
<q-select
2021-02-28 06:00:57 +13:00
style="width: 400px;"
2021-02-26 14:50:46 +13:00
ref="ref_existingDocument"
dense
class="existingDocumentSelect"
2021-02-26 14:50:46 +13:00
dark
2021-02-28 06:00:57 +13:00
menu-anchor="bottom middle"
menu-self="top middle"
2021-02-26 14:50:46 +13:00
:options="filteredExistingInput"
use-input
2021-03-18 10:26:08 +13:00
multiple
filled
input-debounce="200"
2021-02-26 14:50:46 +13:00
v-model="existingDocumentModel"
@filter="filterExistingSelect"
@input="openExistingInput"
>
<template v-slot:option="{ itemProps, itemEvents, opt }">
<q-item
2021-03-18 10:26:08 +13:00
:class="{'hasTextShadow': textShadow}"
2021-02-26 14:50:46 +13:00
v-bind="itemProps"
v-on="itemEvents"
:style="`color: ${opt.color}`"
>
2021-03-04 13:27:07 +13:00
<q-item-section avatar>
<q-icon
:style="`color: ${retrieveIconColor(opt)}`"
:name="(opt.isCategory) ? 'fas fa-folder-open' : opt.icon"
/>
</q-item-section>
2021-02-26 14:50:46 +13:00
<q-item-section>
<q-item-label v-html="opt.label" ></q-item-label>
<q-item-label caption class="text-cultured" v-html="opt.hierarchicalPath"></q-item-label>
<q-item-label caption class="text-cultured" v-if="opt.tags">
<q-chip
v-for="(input,index) in opt.tags" :key="index"
outline
style="opacity: 0.8;"
size="12px"
2021-03-04 13:27:07 +13:00
class="text-cultured"
v-html="`${input}`"
>
</q-chip>
</q-item-label>
2021-02-26 14:50:46 +13:00
</q-item-section>
<q-btn
tabindex="-1"
round
flat
dense
dark
color="primary"
class="z-1 q-ml-md"
icon="mdi-plus"
size="md"
@click.stop.prevent="addNewItemUnderSelected(opt)"
>
<q-tooltip
:delay="300"
>
Add a new document belonging under {{ stripTags(opt.label) }}
2021-02-26 14:50:46 +13:00
</q-tooltip>
</q-btn>
</q-item>
</template>
</q-select>
</q-card-section>
<q-card-section>
2021-03-04 13:27:07 +13:00
<q-card-actions align="around" class="q-mb-sm">
<q-btn flat label="Close" color="accent" v-close-popup />
2021-02-26 14:50:46 +13:00
</q-card-actions>
</q-card-section>
</q-card>
</q-dialog>
</template>
<script lang="ts">
import { Component, Watch } from "vue-property-decorator"
2021-03-06 08:08:55 +13:00
import { I_ShortenedDocument } from "src/interfaces/I_OpenedDocument"
import { advancedDocumentFilter } from "src/scripts/utilities/advancedDocumentFilter"
import { extend } from "quasar"
2021-03-18 10:26:08 +13:00
import PouchDB from "pouchdb"
2021-02-26 14:50:46 +13:00
import DialogBase from "src/components/dialogs/_DialogBase"
2021-03-18 10:26:08 +13:00
import { I_Blueprint } from "src/interfaces/I_Blueprint"
2021-02-26 14:50:46 +13:00
@Component({
components: { }
})
export default class ExistingDocumentDialog extends DialogBase {
@Watch("dialogTrigger")
openDialog (val: string|false) {
if (val) {
if (this.SGET_getDialogsState) {
return
}
2021-03-18 10:26:08 +13:00
this.isCloseAbleViaKeybind = false
2021-02-26 14:50:46 +13:00
this.SSET_setDialogState(true)
this.dialogModel = true
2021-03-18 10:26:08 +13:00
this.reloadOptions()
2021-02-26 14:50:46 +13:00
this.populateExistingObjectDialog().catch(e => console.log(e))
}
}
2021-02-28 06:00:57 +13:00
existingObjectsBackupList = [] as I_ShortenedDocument[]
2021-02-26 14:50:46 +13:00
existingObjectList = [] as I_ShortenedDocument[]
2021-03-18 10:26:08 +13:00
allDocumentBluePrints = [] as I_Blueprint[]
2021-02-26 14:50:46 +13:00
async populateExistingObjectDialog () {
2021-03-18 10:26:08 +13:00
this.allDocumentBluePrints = this.SGET_allBlueprints
2021-03-05 01:51:11 +13:00
2021-03-18 10:26:08 +13:00
const allDocs = await this.retrieveAllDocuments()
2021-02-26 14:50:46 +13:00
2021-02-28 06:00:57 +13:00
this.existingObjectsBackupList = allDocs
this.filterDocuments()
2021-02-26 14:50:46 +13:00
2021-03-04 13:27:07 +13:00
await this.$nextTick()
if (this.$refs.ref_existingDocument) {
/*eslint-disable */
// @ts-ignore
this.$refs.ref_existingDocument.focus()
/* eslint-enable */
}
2021-03-18 10:26:08 +13:00
this.isCloseAbleViaKeybind = true
2021-02-26 14:50:46 +13:00
}
2021-03-18 10:26:08 +13:00
existingDocumentModel = []
2021-02-26 14:50:46 +13:00
filteredExistingInput = null as unknown as I_ShortenedDocument[]
2021-03-04 13:27:07 +13:00
async refocusSelect () {
await this.$nextTick()
/*eslint-disable */
// @ts-ignore
this.$refs.ref_existingDocument.setOptionIndex(-1)
// @ts-ignore
this.$refs.ref_existingDocument.moveOptionSelection(1, true)
/* eslint-enable */
}
2021-02-26 14:50:46 +13:00
filterExistingSelect (val: string, update: (e: () => void) => void) {
if (val === "") {
update(() => {
this.filteredExistingInput = this.existingObjectList
2021-03-04 13:27:07 +13:00
if (this.$refs.ref_existingDocument && this.filteredExistingInput.length > 0) {
this.refocusSelect().catch(e => console.log(e))
2021-02-26 14:50:46 +13:00
}
})
return
}
update(() => {
const needle = val.toLowerCase()
const listCopy : I_ShortenedDocument[] = extend(true, [], this.existingObjectList)
2021-03-18 10:26:08 +13:00
this.filteredExistingInput = advancedDocumentFilter(needle, listCopy, this.allDocumentBluePrints, this.existingObjectsBackupList)
2021-03-04 13:27:07 +13:00
if (this.$refs.ref_existingDocument && this.filteredExistingInput.length > 0) {
this.refocusSelect().catch(e => console.log(e))
2021-02-26 14:50:46 +13:00
}
})
}
2021-03-18 10:26:08 +13:00
async openExistingInput (e: I_ShortenedDocument[]) {
if (!this.disableCloseAftertSelectQuickSearch) {
this.dialogModel = false
// @ts-ignore
this.openExistingDocumentRoute(e[0])
this.existingDocumentModel = []
}
else {
// @ts-ignore
this.existingDocumentModel = []
const CurrentObjectDB = new PouchDB(e[0].type)
// @ts-ignore
const retrievedObject = await CurrentObjectDB.get(e[0].id)
const dataPass = {
doc: retrievedObject,
treeAction: false
}
// @ts-ignore
this.SSET_addOpenedDocument(dataPass)
}
2021-02-26 14:50:46 +13:00
}
addNewItemUnderSelected (parent: any) {
const routeObject = {
_id: parent.type,
parent: parent.id
}
// @ts-ignore
this.addNewObjectRoute(routeObject)
}
2021-02-28 06:00:57 +13:00
2021-03-18 10:26:08 +13:00
disableCloseAftertSelectQuickSearch = false
closeWithSameClick = false
textShadow = false
@Watch("SGET_options", { immediate: true, deep: true })
onSettingsChange () {
this.reloadOptions()
}
reloadOptions () {
const options = this.SGET_options
this.closeWithSameClick = options.allowQuickPopupSameKeyClose
this.disableCloseAftertSelectQuickSearch = options.disableCloseAftertSelectQuickSearch
this.includeCategories = !options.disableQuickSearchCategoryPrecheck
this.textShadow = options.textShadow
}
2021-02-28 06:00:57 +13:00
includeCategories = true
@Watch("includeCategories")
reactToCheckboxChange () {
this.filterDocuments()
}
filterDocuments () {
this.existingObjectList = this.existingObjectsBackupList.filter(e => !((!this.includeCategories && e.isCategory)))
}
2021-03-18 10:26:08 +13:00
isCloseAbleViaKeybind = false
/**
* Local keybinds
*/
@Watch("SGET_getCurrentKeyBindData", { deep: true })
processKeyPush () {
// Keybind cheatsheet
if (this.determineKeyBind("quickExistingDocument") && this.dialogModel && this.closeWithSameClick && this.isCloseAbleViaKeybind && this.SGET_getDialogsState) {
this.dialogModel = false
this.SSET_setDialogState(false)
// @ts-ignore
this.existingDocumentModel = null
}
}
2021-02-26 14:50:46 +13:00
}
</script>
<style lang="scss" scoped>
.existingDocumentPopup {
min-width: 600px;
margin-top: 100px;
align-self: flex-start;
h6 {
display: block;
text-align: center;
width: 100%;
}
}
</style>