|
|
@ -1,6 +1,4 @@ |
|
|
|
<script setup lang="ts"> |
|
|
|
<script setup lang="ts"> |
|
|
|
import type { TableType } from 'nocodb-sdk' |
|
|
|
|
|
|
|
import type { ComputedRef } from 'vue' |
|
|
|
|
|
|
|
import { computed, inject } from 'vue' |
|
|
|
import { computed, inject } from 'vue' |
|
|
|
import Draggable from 'vuedraggable' |
|
|
|
import Draggable from 'vuedraggable' |
|
|
|
import { ActiveViewInj, FieldsInj, IsLockedInj, MetaInj, ReloadViewDataHookInj } from '~/context' |
|
|
|
import { ActiveViewInj, FieldsInj, IsLockedInj, MetaInj, ReloadViewDataHookInj } from '~/context' |
|
|
@ -39,8 +37,8 @@ const { |
|
|
|
showAll, |
|
|
|
showAll, |
|
|
|
hideAll, |
|
|
|
hideAll, |
|
|
|
saveOrUpdate, |
|
|
|
saveOrUpdate, |
|
|
|
sortedFields, |
|
|
|
// sortedFields, |
|
|
|
} = useViewColumns(activeView, meta as ComputedRef<TableType>, false, () => reloadDataHook?.trigger()) |
|
|
|
} = useViewColumns(activeView, meta, false, () => reloadDataHook?.trigger()) |
|
|
|
|
|
|
|
|
|
|
|
watch( |
|
|
|
watch( |
|
|
|
() => (activeView?.value as any)?.id, |
|
|
|
() => (activeView?.value as any)?.id, |
|
|
@ -61,17 +59,20 @@ watch( |
|
|
|
|
|
|
|
|
|
|
|
const onMove = (event: unknown) => { |
|
|
|
const onMove = (event: unknown) => { |
|
|
|
// todo : sync with server |
|
|
|
// todo : sync with server |
|
|
|
// if (!sortedFields?.value) return |
|
|
|
if (!fields?.value) return |
|
|
|
// if (sortedFields?.value.length - 1 === event.moved.newIndex) { |
|
|
|
|
|
|
|
// sortedFields.value[event.moved.newIndex].order = sortedFields.value[event.moved.newIndex - 1].order + 1 |
|
|
|
if (fields.value.length < 2) return |
|
|
|
// } else if (event.moved.newIndex === 0) { |
|
|
|
|
|
|
|
// sortedFields.value[event.moved.newIndex].order = sortedFields.value[1].order / 2 |
|
|
|
if (fields?.value.length - 1 === event.moved.newIndex) { |
|
|
|
// } else { |
|
|
|
fields.value[event.moved.newIndex].order = (fields.value[event.moved.newIndex - 1].order || 1) + 1 |
|
|
|
// sortedFields.value[event.moved.newIndex].order = |
|
|
|
} else if (event.moved.newIndex === 0) { |
|
|
|
// (sortedFields?.value[event.moved.newIndex - 1].order + sortedFields?.value[event.moved.newIndex + 1].order) / 2 |
|
|
|
fields.value[event.moved.newIndex].order = (fields?.value[1].order || 1) / 2 |
|
|
|
// // ); |
|
|
|
} else { |
|
|
|
// } |
|
|
|
fields.value[event.moved.newIndex].order = |
|
|
|
// saveOrUpdate(sortedFields[event.moved.newIndex], event.moved.newIndex); |
|
|
|
((fields?.value[event.moved.newIndex - 1].order || 1) + (fields?.value[event.moved.newIndex + 1].order || 1)) / 2 |
|
|
|
|
|
|
|
// ); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
saveOrUpdate(fields.value[event.moved.newIndex], event.moved.newIndex) |
|
|
|
$e('a:fields:reorder') |
|
|
|
$e('a:fields:reorder') |
|
|
|
} |
|
|
|
} |
|
|
|
</script> |
|
|
|
</script> |
|
|
@ -93,9 +94,9 @@ const onMove = (event: unknown) => { |
|
|
|
<template #overlay> |
|
|
|
<template #overlay> |
|
|
|
<div class="pt-0 min-w-[280px] bg-white shadow" @click.stop> |
|
|
|
<div class="pt-0 min-w-[280px] bg-white shadow" @click.stop> |
|
|
|
<div class="nc-fields-list py-1"> |
|
|
|
<div class="nc-fields-list py-1"> |
|
|
|
<Draggable :list="sortedFields" @change="onMove($event)"> |
|
|
|
<Draggable :list="fields" @change="onMove($event)"> |
|
|
|
<template #item="{ element: field }"> |
|
|
|
<template #item="{ element: field }"> |
|
|
|
<div :key="field.id" class="px-2 py-1 flex" @click.stop> |
|
|
|
<div v-show="filteredFieldList.includes(field)" :key="field.id" class="px-2 py-1 flex" @click.stop> |
|
|
|
<a-checkbox v-model:checked="field.show" class="flex-shrink" @change="saveOrUpdate(field, i)"> |
|
|
|
<a-checkbox v-model:checked="field.show" class="flex-shrink" @change="saveOrUpdate(field, i)"> |
|
|
|
<span class="text-xs">{{ field.title }}</span> |
|
|
|
<span class="text-xs">{{ field.title }}</span> |
|
|
|
</a-checkbox> |
|
|
|
</a-checkbox> |
|
|
|