fix: removed auto save logic from view settings component and added functionality to save it in View Settings along with filters & sort
This commit is contained in:
parent
ffe942d80f
commit
25e92fed45
@ -7,14 +7,14 @@
|
|||||||
</template>
|
</template>
|
||||||
</Button>
|
</Button>
|
||||||
</template>
|
</template>
|
||||||
<template #body>
|
<template #body="{ close }">
|
||||||
<div
|
<div
|
||||||
class="my-2 rounded-lg border border-gray-100 bg-white p-1.5 shadow-xl"
|
class="my-2 rounded-lg border border-gray-100 bg-white p-1.5 shadow-xl"
|
||||||
>
|
>
|
||||||
<div v-if="!edit">
|
<div v-if="!edit">
|
||||||
<Draggable
|
<Draggable
|
||||||
:list="columns"
|
:list="columns"
|
||||||
@end="updateColumnDetails"
|
@end="apply"
|
||||||
item-key="key"
|
item-key="key"
|
||||||
class="list-group"
|
class="list-group"
|
||||||
>
|
>
|
||||||
@ -64,11 +64,22 @@
|
|||||||
</Button>
|
</Button>
|
||||||
</template>
|
</template>
|
||||||
</Autocomplete>
|
</Autocomplete>
|
||||||
|
<Button
|
||||||
|
v-if="columnsUpdated"
|
||||||
|
class="w-full !justify-start !text-gray-600"
|
||||||
|
variant="ghost"
|
||||||
|
@click="reset(close)"
|
||||||
|
label="Reset Changes"
|
||||||
|
>
|
||||||
|
<template #prefix>
|
||||||
|
<ReloadIcon class="h-4" />
|
||||||
|
</template>
|
||||||
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
v-if="!is_default"
|
v-if="!is_default"
|
||||||
class="w-full !justify-start !text-gray-600"
|
class="w-full !justify-start !text-gray-600"
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
@click="resetToDefault"
|
@click="resetToDefault(close)"
|
||||||
label="Reset to Default"
|
label="Reset to Default"
|
||||||
>
|
>
|
||||||
<template #prefix>
|
<template #prefix>
|
||||||
@ -131,7 +142,8 @@ import NestedPopover from '@/components/NestedPopover.vue'
|
|||||||
import Autocomplete from '@/components/frappe-ui/Autocomplete.vue'
|
import Autocomplete from '@/components/frappe-ui/Autocomplete.vue'
|
||||||
import Draggable from 'vuedraggable'
|
import Draggable from 'vuedraggable'
|
||||||
import { computed, defineModel, ref } from 'vue'
|
import { computed, defineModel, ref } from 'vue'
|
||||||
import { FeatherIcon, FormControl, call } from 'frappe-ui'
|
import { FeatherIcon, FormControl } from 'frappe-ui'
|
||||||
|
import { watchOnce } from '@vueuse/core'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
doctype: {
|
doctype: {
|
||||||
@ -140,6 +152,15 @@ const props = defineProps({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const emit = defineEmits(['update'])
|
||||||
|
const columnsUpdated = ref(false)
|
||||||
|
|
||||||
|
const oldValues = ref({
|
||||||
|
columns: [],
|
||||||
|
rows: [],
|
||||||
|
isDefault: false,
|
||||||
|
})
|
||||||
|
|
||||||
const list = defineModel()
|
const list = defineModel()
|
||||||
const edit = ref(false)
|
const edit = ref(false)
|
||||||
const column = ref({
|
const column = ref({
|
||||||
@ -179,7 +200,7 @@ const fields = computed(() => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
async function addColumn(c) {
|
function addColumn(c) {
|
||||||
let _column = {
|
let _column = {
|
||||||
label: c.label,
|
label: c.label,
|
||||||
type: c.type,
|
type: c.type,
|
||||||
@ -188,8 +209,7 @@ async function addColumn(c) {
|
|||||||
}
|
}
|
||||||
columns.value.push(_column)
|
columns.value.push(_column)
|
||||||
rows.value.push(c.value)
|
rows.value.push(c.value)
|
||||||
await updateColumnDetails()
|
apply(true)
|
||||||
list.value.reload()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeColumn(c) {
|
function removeColumn(c) {
|
||||||
@ -197,7 +217,7 @@ function removeColumn(c) {
|
|||||||
if (c.key !== 'name') {
|
if (c.key !== 'name') {
|
||||||
rows.value = rows.value.filter((row) => row !== c.key)
|
rows.value = rows.value.filter((row) => row !== c.key)
|
||||||
}
|
}
|
||||||
updateColumnDetails()
|
apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
function editColumn(c) {
|
function editColumn(c) {
|
||||||
@ -215,7 +235,7 @@ function updateColumn(c) {
|
|||||||
if (columns.value[index].old) {
|
if (columns.value[index].old) {
|
||||||
delete columns.value[index].old
|
delete columns.value[index].old
|
||||||
}
|
}
|
||||||
updateColumnDetails()
|
apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
function cancelUpdate() {
|
function cancelUpdate() {
|
||||||
@ -225,25 +245,42 @@ function cancelUpdate() {
|
|||||||
delete column.value.old
|
delete column.value.old
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updateColumnDetails() {
|
function reset(close) {
|
||||||
is_default.value = false
|
apply(true, false, true)
|
||||||
await call(
|
close()
|
||||||
'crm.fcrm.doctype.crm_view_settings.crm_view_settings.update',
|
|
||||||
{
|
|
||||||
doctype: props.doctype,
|
|
||||||
columns: columns.value,
|
|
||||||
rows: rows.value,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function resetToDefault() {
|
function resetToDefault(close) {
|
||||||
await call(
|
apply(true, true)
|
||||||
'crm.fcrm.doctype.crm_view_settings.crm_view_settings.reset_to_default',
|
close()
|
||||||
{
|
|
||||||
doctype: props.doctype,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
list.value.reload()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function apply(reload = false, isDefault = false, reset = false) {
|
||||||
|
is_default.value = isDefault
|
||||||
|
columnsUpdated.value = true
|
||||||
|
let obj = {
|
||||||
|
columns: reset ? oldValues.value.columns : columns.value,
|
||||||
|
rows: reset ? oldValues.value.rows : rows.value,
|
||||||
|
isDefault: reset ? oldValues.value.isDefault : isDefault,
|
||||||
|
reload,
|
||||||
|
reset,
|
||||||
|
}
|
||||||
|
emit('update', obj)
|
||||||
|
|
||||||
|
if (reload) {
|
||||||
|
setTimeout(() => {
|
||||||
|
is_default.value = reset ? oldValues.value.isDefault : isDefault
|
||||||
|
columnsUpdated.value = !reset
|
||||||
|
}, 100)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
watchOnce(
|
||||||
|
() => list.value.data,
|
||||||
|
(val) => {
|
||||||
|
oldValues.value.columns = JSON.parse(JSON.stringify(val.columns))
|
||||||
|
oldValues.value.rows = JSON.parse(JSON.stringify(val.rows))
|
||||||
|
oldValues.value.isDefault = val.is_default
|
||||||
|
}
|
||||||
|
)
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user