|
|
@ -8,14 +8,17 @@ import { |
|
|
|
IsKanbanInj, |
|
|
|
IsKanbanInj, |
|
|
|
ReadonlyInj, |
|
|
|
ReadonlyInj, |
|
|
|
computed, |
|
|
|
computed, |
|
|
|
|
|
|
|
enumColor, |
|
|
|
h, |
|
|
|
h, |
|
|
|
inject, |
|
|
|
inject, |
|
|
|
onMounted, |
|
|
|
onMounted, |
|
|
|
|
|
|
|
reactive, |
|
|
|
ref, |
|
|
|
ref, |
|
|
|
useEventListener, |
|
|
|
useEventListener, |
|
|
|
|
|
|
|
useMetas, |
|
|
|
useProject, |
|
|
|
useProject, |
|
|
|
useSelectedCellKeyupListener, |
|
|
|
useSelectedCellKeyupListener, |
|
|
|
watch, enumColor, useMetas, |
|
|
|
watch, |
|
|
|
} from '#imports' |
|
|
|
} from '#imports' |
|
|
|
import MdiCloseCircle from '~icons/mdi/close-circle' |
|
|
|
import MdiCloseCircle from '~icons/mdi/close-circle' |
|
|
|
|
|
|
|
|
|
|
@ -28,8 +31,6 @@ const { modelValue } = defineProps<Props>() |
|
|
|
|
|
|
|
|
|
|
|
const emit = defineEmits(['update:modelValue']) |
|
|
|
const emit = defineEmits(['update:modelValue']) |
|
|
|
|
|
|
|
|
|
|
|
const emptyOption = Symbol('emptyOption') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const { isMysql } = useProject() |
|
|
|
const { isMysql } = useProject() |
|
|
|
|
|
|
|
|
|
|
|
const column = inject(ColumnInj)! |
|
|
|
const column = inject(ColumnInj)! |
|
|
@ -54,11 +55,7 @@ const { $api } = useNuxtApp() |
|
|
|
|
|
|
|
|
|
|
|
const { getMeta } = useMetas() |
|
|
|
const { getMeta } = useMetas() |
|
|
|
|
|
|
|
|
|
|
|
const tempVal = ref<string>() |
|
|
|
const tempVal = reactive([]) |
|
|
|
|
|
|
|
|
|
|
|
const isOptionMissing = computed(() => { |
|
|
|
|
|
|
|
return (options.value ?? []).every((op) => op.title !== searchVal.value) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const options = computed<(SelectOptionType & { value?: string })[]>(() => { |
|
|
|
const options = computed<(SelectOptionType & { value?: string })[]>(() => { |
|
|
|
if (column?.value.colOptions) { |
|
|
|
if (column?.value.colOptions) { |
|
|
@ -73,6 +70,10 @@ const options = computed<(SelectOptionType & { value?: string })[]>(() => { |
|
|
|
return [] |
|
|
|
return [] |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const isOptionMissing = computed(() => { |
|
|
|
|
|
|
|
return (options.value ?? []).every((op) => op.title !== searchVal.value) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
const vModel = computed({ |
|
|
|
const vModel = computed({ |
|
|
|
get: () => { |
|
|
|
get: () => { |
|
|
|
const selected = selectedIds.value.reduce((acc, id) => { |
|
|
|
const selected = selectedIds.value.reduce((acc, id) => { |
|
|
@ -83,7 +84,7 @@ const vModel = computed({ |
|
|
|
return acc |
|
|
|
return acc |
|
|
|
}, [] as string[]) |
|
|
|
}, [] as string[]) |
|
|
|
|
|
|
|
|
|
|
|
if (tempVal.value) selected.push(tempVal.value) |
|
|
|
if (tempVal.length) selected.push(...tempVal) |
|
|
|
|
|
|
|
|
|
|
|
return selected |
|
|
|
return selected |
|
|
|
}, |
|
|
|
}, |
|
|
@ -112,18 +113,18 @@ const selectedTitles = computed(() => |
|
|
|
: [], |
|
|
|
: [], |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
const handleKeys = async (e: KeyboardEvent) => { |
|
|
|
// const handleKeys = async (e: KeyboardEvent) => { |
|
|
|
switch (e.key) { |
|
|
|
// switch (e.key) { |
|
|
|
case 'Escape': |
|
|
|
// case 'Escape': |
|
|
|
e.preventDefault() |
|
|
|
// e.preventDefault() |
|
|
|
isOpen.value = false |
|
|
|
// isOpen.value = false |
|
|
|
break |
|
|
|
// break |
|
|
|
case 'Enter': |
|
|
|
// case 'Enter': |
|
|
|
e.stopPropagation() |
|
|
|
// e.stopPropagation() |
|
|
|
await addIfMissingAndSave() |
|
|
|
// await addIfMissingAndSave() |
|
|
|
break |
|
|
|
// break |
|
|
|
} |
|
|
|
// } |
|
|
|
} |
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
const handleClose = (e: MouseEvent) => { |
|
|
|
const handleClose = (e: MouseEvent) => { |
|
|
|
if (aselect.value && !aselect.value.$el.contains(e.target)) { |
|
|
|
if (aselect.value && !aselect.value.$el.contains(e.target)) { |
|
|
@ -177,20 +178,26 @@ useSelectedCellKeyupListener(active, (e) => { |
|
|
|
isOpen.value = true |
|
|
|
isOpen.value = true |
|
|
|
} |
|
|
|
} |
|
|
|
break |
|
|
|
break |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
isOpen.value = true |
|
|
|
|
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const activeOptCreateInProgress = ref(0) |
|
|
|
|
|
|
|
|
|
|
|
async function addIfMissingAndSave() { |
|
|
|
async function addIfMissingAndSave() { |
|
|
|
if (!searchVal) return false |
|
|
|
if (!searchVal) return false |
|
|
|
try { |
|
|
|
try { |
|
|
|
tempVal.value = searchVal.value |
|
|
|
tempVal.push(searchVal.value) |
|
|
|
const newOptValue = searchVal?.value |
|
|
|
const newOptValue = searchVal?.value |
|
|
|
|
|
|
|
searchVal.value = '' |
|
|
|
|
|
|
|
activeOptCreateInProgress.value++ |
|
|
|
if (newOptValue && !options.value.some((o) => o.title === newOptValue)) { |
|
|
|
if (newOptValue && !options.value.some((o) => o.title === newOptValue)) { |
|
|
|
const newOptions = [...options.value] |
|
|
|
const newOptions = [...options.value] |
|
|
|
newOptions.push({ |
|
|
|
newOptions.push({ |
|
|
|
title: newOptValue, value: newOptValue, |
|
|
|
title: newOptValue, |
|
|
|
|
|
|
|
value: newOptValue, |
|
|
|
color: enumColor.light[(options.value.length + 1) % enumColor.light.length], |
|
|
|
color: enumColor.light[(options.value.length + 1) % enumColor.light.length], |
|
|
|
}) |
|
|
|
}) |
|
|
|
column.value.colOptions = { options: newOptions.map(({ value: _, ...rest }) => rest) } |
|
|
|
column.value.colOptions = { options: newOptions.map(({ value: _, ...rest }) => rest) } |
|
|
@ -198,20 +205,25 @@ async function addIfMissingAndSave() { |
|
|
|
await $api.dbTableColumn.update(column.value?.id as string, { |
|
|
|
await $api.dbTableColumn.update(column.value?.id as string, { |
|
|
|
...column.value, |
|
|
|
...column.value, |
|
|
|
}) |
|
|
|
}) |
|
|
|
await getMeta(column.value.fk_model_id!, true) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vModel.value = [...vModel.value] |
|
|
|
activeOptCreateInProgress.value-- |
|
|
|
searchVal.value = '' |
|
|
|
if (!activeOptCreateInProgress.value) { |
|
|
|
|
|
|
|
await getMeta(column.value.fk_model_id!, true) |
|
|
|
|
|
|
|
vModel.value = [...vModel.value]; |
|
|
|
|
|
|
|
tempVal.splice(0, tempVal.length); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
activeOptCreateInProgress.value-- |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
|
// todo: handle error message |
|
|
|
// todo: handle error message |
|
|
|
console.log(e) |
|
|
|
console.log(e) |
|
|
|
|
|
|
|
activeOptCreateInProgress.value-- |
|
|
|
} finally { |
|
|
|
} finally { |
|
|
|
tempVal.value = '' |
|
|
|
// tempVal.value = '' |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const search = () => { |
|
|
|
const search = () => { |
|
|
|
searchVal.value = aselect.value?.$el?.querySelector('.ant-select-selection-search-input')?.value |
|
|
|
searchVal.value = aselect.value?.$el?.querySelector('.ant-select-selection-search-input')?.value |
|
|
|
} |
|
|
|
} |
|
|
@ -226,7 +238,7 @@ const search = () => { |
|
|
|
class="w-full" |
|
|
|
class="w-full" |
|
|
|
:bordered="false" |
|
|
|
:bordered="false" |
|
|
|
:show-arrow="!readOnly" |
|
|
|
:show-arrow="!readOnly" |
|
|
|
show-search |
|
|
|
:show-search="active || editable" |
|
|
|
:open="isOpen" |
|
|
|
:open="isOpen" |
|
|
|
:disabled="readOnly" |
|
|
|
:disabled="readOnly" |
|
|
|
:class="{ '!ml-[-8px]': readOnly }" |
|
|
|
:class="{ '!ml-[-8px]': readOnly }" |
|
|
@ -260,7 +272,9 @@ const search = () => { |
|
|
|
<a-select-option v-if="searchVal && isOptionMissing" :key="searchVal" :value="searchVal"> |
|
|
|
<a-select-option v-if="searchVal && isOptionMissing" :key="searchVal" :value="searchVal"> |
|
|
|
<div class="flex gap-2 text-gray-500 items-center"> |
|
|
|
<div class="flex gap-2 text-gray-500 items-center"> |
|
|
|
<MdiPlusThick class="min-w-4" /> |
|
|
|
<MdiPlusThick class="min-w-4" /> |
|
|
|
<div class="text-xs whitespace-normal"> Create new option named <strong>{{ searchVal }}</strong></div> |
|
|
|
<div class="text-xs whitespace-normal"> |
|
|
|
|
|
|
|
Create new option named <strong>{{ searchVal }}</strong> |
|
|
|
|
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</a-select-option> |
|
|
|
</a-select-option> |
|
|
|
|
|
|
|
|
|
|
|