refactor: use settings store to load dropdown items
This commit is contained in:
parent
73f227f76b
commit
d1220c0c6f
@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<Dropdown :options="dropdownItems.doc || []" v-bind="$attrs">
|
<Dropdown :options="dropdownItems" v-bind="$attrs">
|
||||||
<template v-slot="{ open }">
|
<template v-slot="{ open }">
|
||||||
<button
|
<button
|
||||||
class="flex h-12 items-center rounded-md py-2 duration-300 ease-in-out"
|
class="flex h-12 items-center rounded-md py-2 duration-300 ease-in-out"
|
||||||
@ -51,8 +51,9 @@ import CRMLogo from '@/components/Icons/CRMLogo.vue'
|
|||||||
import Apps from '@/components/Apps.vue'
|
import Apps from '@/components/Apps.vue'
|
||||||
import { sessionStore } from '@/stores/session'
|
import { sessionStore } from '@/stores/session'
|
||||||
import { usersStore } from '@/stores/users'
|
import { usersStore } from '@/stores/users'
|
||||||
|
import { getSettings } from '@/stores/settings'
|
||||||
import { showSettings } from '@/composables/settings'
|
import { showSettings } from '@/composables/settings'
|
||||||
import { createDocumentResource, Dropdown } from 'frappe-ui'
|
import { Dropdown } from 'frappe-ui'
|
||||||
import { useStorage } from '@vueuse/core'
|
import { useStorage } from '@vueuse/core'
|
||||||
import { computed, markRaw, onMounted } from 'vue'
|
import { computed, markRaw, onMounted } from 'vue'
|
||||||
|
|
||||||
@ -63,6 +64,7 @@ const props = defineProps({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const { settings } = getSettings()
|
||||||
const { logout } = sessionStore()
|
const { logout } = sessionStore()
|
||||||
const { getUser } = usersStore()
|
const { getUser } = usersStore()
|
||||||
|
|
||||||
@ -70,46 +72,45 @@ const user = computed(() => getUser() || {})
|
|||||||
|
|
||||||
const theme = useStorage('theme', 'light')
|
const theme = useStorage('theme', 'light')
|
||||||
|
|
||||||
const dropdownItems = createDocumentResource({
|
const dropdownItems = computed(() => {
|
||||||
doctype: 'FCRM Settings',
|
if (!settings.value?.dropdown_items) return []
|
||||||
name: 'FCRM Settings',
|
|
||||||
fields: ['dropdown_items'],
|
|
||||||
auto: true,
|
|
||||||
transform: (data) => {
|
|
||||||
let items = data.dropdown_items
|
|
||||||
|
|
||||||
let _dropdownItems = [
|
let items = settings.value.dropdown_items
|
||||||
{
|
|
||||||
group: 'Dropdown Items',
|
let _dropdownItems = [
|
||||||
|
{
|
||||||
|
group: 'Dropdown Items',
|
||||||
|
hideLabel: true,
|
||||||
|
items: [],
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
items.forEach((item) => {
|
||||||
|
if (item.hidden) return
|
||||||
|
if (item.type !== 'Separator') {
|
||||||
|
_dropdownItems[_dropdownItems.length - 1].items.push(
|
||||||
|
dropdownItemObj(item),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
_dropdownItems.push({
|
||||||
|
group: '',
|
||||||
hideLabel: true,
|
hideLabel: true,
|
||||||
items: [],
|
items: [],
|
||||||
},
|
})
|
||||||
]
|
}
|
||||||
|
})
|
||||||
|
|
||||||
items.forEach((item) => {
|
return _dropdownItems
|
||||||
if (item.hidden) return
|
|
||||||
if (item.type !== 'Separator') {
|
|
||||||
_dropdownItems[_dropdownItems.length - 1].items.push(
|
|
||||||
dropdownItemObj(item),
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
_dropdownItems.push({
|
|
||||||
group: '',
|
|
||||||
hideLabel: true,
|
|
||||||
items: [],
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
return _dropdownItems
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
function dropdownItemObj(item) {
|
function dropdownItemObj(item) {
|
||||||
let openInNewWindow = item.open_in_new_window
|
let openInNewWindow = item.open_in_new_window
|
||||||
|
|
||||||
let icon = item.icon || 'external-link'
|
let icon = item.icon || 'external-link'
|
||||||
item.icon = icon.startsWith('<svg') ? markRaw({ template: icon }) : icon
|
if (typeof icon === 'string' && icon.startsWith('<svg')) {
|
||||||
|
icon = markRaw({ template: icon })
|
||||||
|
}
|
||||||
|
item.icon = icon
|
||||||
|
|
||||||
if (item.is_standard) {
|
if (item.is_standard) {
|
||||||
return getStandardItem(item)
|
return getStandardItem(item)
|
||||||
@ -142,7 +143,7 @@ function getStandardItem(item) {
|
|||||||
}
|
}
|
||||||
case 'toggle_theme':
|
case 'toggle_theme':
|
||||||
return {
|
return {
|
||||||
icon: computed(() => (theme.value === 'dark' ? 'sun' : item.icon)),
|
icon: theme.value === 'dark' ? 'sun' : item.icon,
|
||||||
label: __(item.label),
|
label: __(item.label),
|
||||||
onClick: toggleTheme,
|
onClick: toggleTheme,
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user