mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
190 lines
5.6 KiB
190 lines
5.6 KiB
2 years ago
|
<script setup lang="ts">
|
||
2 years ago
|
import type { ColumnType, GalleryType } from 'nocodb-sdk'
|
||
|
import { UITypes, ViewTypes, isVirtualCol } from 'nocodb-sdk'
|
||
2 years ago
|
import Draggable from 'vuedraggable'
|
||
2 years ago
|
import type { SelectProps } from 'ant-design-vue'
|
||
2 years ago
|
import {
|
||
|
ActiveViewInj,
|
||
|
FieldsInj,
|
||
|
IsLockedInj,
|
||
|
IsPublicInj,
|
||
|
MetaInj,
|
||
|
ReloadViewDataHookInj,
|
||
|
computed,
|
||
|
inject,
|
||
|
ref,
|
||
|
useNuxtApp,
|
||
|
useViewColumns,
|
||
|
watch,
|
||
|
} from '#imports'
|
||
2 years ago
|
import CellIcon from '~/components/smartsheet-header/CellIcon.vue'
|
||
|
import VirtualCellIcon from '~/components/smartsheet-header/VirtualCellIcon.vue'
|
||
2 years ago
|
|
||
|
const meta = inject(MetaInj)!
|
||
2 years ago
|
|
||
2 years ago
|
const activeView = inject(ActiveViewInj)!
|
||
2 years ago
|
|
||
2 years ago
|
const reloadDataHook = inject(ReloadViewDataHookInj)!
|
||
2 years ago
|
|
||
2 years ago
|
const rootFields = inject(FieldsInj)
|
||
2 years ago
|
|
||
|
const isLocked = inject(IsLockedInj, ref(false))
|
||
|
|
||
|
const isPublic = inject(IsPublicInj, ref(false))
|
||
2 years ago
|
|
||
2 years ago
|
const { $api, $e } = useNuxtApp()
|
||
2 years ago
|
|
||
2 years ago
|
const {
|
||
|
showSystemFields,
|
||
|
sortedAndFilteredFields,
|
||
|
fields,
|
||
|
loadViewColumns,
|
||
|
filteredFieldList,
|
||
|
filterQuery,
|
||
|
showAll,
|
||
|
hideAll,
|
||
|
saveOrUpdate,
|
||
2 years ago
|
metaColumnById,
|
||
2 years ago
|
} = useViewColumns(activeView, meta, () => reloadDataHook.trigger())
|
||
2 years ago
|
|
||
|
watch(
|
||
2 years ago
|
() => (activeView.value as any)?.id,
|
||
2 years ago
|
async (newVal, oldVal) => {
|
||
2 years ago
|
if (newVal !== oldVal && meta.value) {
|
||
2 years ago
|
await loadViewColumns()
|
||
2 years ago
|
}
|
||
|
},
|
||
|
{ immediate: true },
|
||
|
)
|
||
2 years ago
|
|
||
2 years ago
|
watch(
|
||
2 years ago
|
sortedAndFilteredFields,
|
||
2 years ago
|
(v) => {
|
||
|
if (rootFields) rootFields.value = v || []
|
||
|
},
|
||
|
{ immediate: true },
|
||
|
)
|
||
2 years ago
|
|
||
2 years ago
|
const isAnyFieldHidden = computed(() => filteredFieldList.value?.some((field) => !field.show))
|
||
2 years ago
|
|
||
2 years ago
|
const onMove = (_event: { moved: { newIndex: number } }) => {
|
||
2 years ago
|
// todo : sync with server
|
||
2 years ago
|
if (!fields.value) return
|
||
2 years ago
|
|
||
|
if (fields.value.length < 2) return
|
||
|
|
||
2 years ago
|
fields.value.forEach((field, index) => {
|
||
2 years ago
|
if (field.order !== index + 1) {
|
||
|
field.order = index + 1
|
||
|
saveOrUpdate(field, index)
|
||
|
}
|
||
2 years ago
|
})
|
||
2 years ago
|
|
||
2 years ago
|
$e('a:fields:reorder')
|
||
|
}
|
||
2 years ago
|
|
||
2 years ago
|
const coverImageColumnId = computed({
|
||
|
get: () =>
|
||
|
activeView.value?.type === ViewTypes.GALLERY ? (activeView.value?.view as GalleryType).fk_cover_image_col_id : undefined,
|
||
|
set: async (val) => {
|
||
|
if (val && activeView.value.type === ViewTypes.GALLERY && activeView.value.id && activeView.value.view) {
|
||
|
await $api.dbView.galleryUpdate(activeView.value.id, {
|
||
|
...activeView.value.view,
|
||
|
fk_cover_image_col_id: val,
|
||
|
})
|
||
|
;(activeView.value?.view as GalleryType).fk_cover_image_col_id = val
|
||
|
reloadDataHook.trigger()
|
||
|
}
|
||
|
},
|
||
|
})
|
||
|
|
||
|
const coverOptions = computed<SelectProps['options']>(() => {
|
||
|
return fields.value
|
||
|
?.filter((el) => el.fk_column_id && metaColumnById.value[el.fk_column_id].uidt === UITypes.Attachment)
|
||
|
.map((field) => {
|
||
|
return {
|
||
|
value: field.fk_column_id,
|
||
|
label: field.title,
|
||
|
}
|
||
|
})
|
||
|
})
|
||
|
|
||
2 years ago
|
const getIcon = (c: ColumnType) =>
|
||
|
h(isVirtualCol(c) ? VirtualCellIcon : CellIcon, {
|
||
|
columnMeta: c,
|
||
|
})
|
||
2 years ago
|
</script>
|
||
|
|
||
|
<template>
|
||
2 years ago
|
<a-dropdown :trigger="['click']">
|
||
2 years ago
|
<div :class="{ 'nc-badge nc-active-btn': isAnyFieldHidden }">
|
||
2 years ago
|
<a-button v-t="['c:fields']" class="nc-fields-menu-btn nc-toolbar-btn" :disabled="isLocked">
|
||
2 years ago
|
<div class="flex items-center gap-1">
|
||
2 years ago
|
<MdiEyeOffOutline />
|
||
2 years ago
|
|
||
2 years ago
|
<!-- Fields -->
|
||
2 years ago
|
<span class="text-capitalize !text-sm font-weight-normal">{{ $t('objects.fields') }}</span>
|
||
2 years ago
|
|
||
|
<MdiMenuDown class="text-grey" />
|
||
2 years ago
|
</div>
|
||
|
</a-button>
|
||
|
</div>
|
||
2 years ago
|
<template #overlay>
|
||
2 years ago
|
<div
|
||
|
class="p-3 min-w-[280px] bg-gray-50 shadow-lg nc-table-toolbar-menu max-h-[max(80vh,500px)] overflow-auto !border"
|
||
|
@click.stop
|
||
|
>
|
||
2 years ago
|
<a-card v-if="activeView.type === ViewTypes.GALLERY" size="small" title="Cover image">
|
||
|
<a-select v-model:value="coverImageColumnId" class="w-full" :options="coverOptions" @click.stop></a-select>
|
||
|
</a-card>
|
||
2 years ago
|
<div class="p-1" @click.stop>
|
||
|
<a-input v-model:value="filterQuery" size="small" :placeholder="$t('placeholder.searchFields')" />
|
||
2 years ago
|
</div>
|
||
2 years ago
|
<div class="nc-fields-list py-1">
|
||
2 years ago
|
<Draggable v-model="fields" item-key="id" @change="onMove($event)">
|
||
2 years ago
|
<template #item="{ element: field, index: index }">
|
||
2 years ago
|
<div v-show="filteredFieldList.includes(field)" :key="field.id" class="px-2 py-1 flex items-center" @click.stop>
|
||
2 years ago
|
<a-checkbox v-model:checked="field.show" class="shrink" @change="saveOrUpdate(field, index)">
|
||
2 years ago
|
<div class="flex items-center">
|
||
|
<component :is="getIcon(metaColumnById[field.fk_column_id])" />
|
||
|
<span>{{ field.title }}</span>
|
||
|
</div>
|
||
2 years ago
|
</a-checkbox>
|
||
|
<div class="flex-1" />
|
||
2 years ago
|
<MdiDrag class="cursor-move" />
|
||
2 years ago
|
</div>
|
||
2 years ago
|
</template>
|
||
2 years ago
|
</Draggable>
|
||
2 years ago
|
</div>
|
||
2 years ago
|
|
||
|
<a-divider class="!my-2" />
|
||
2 years ago
|
|
||
2 years ago
|
<div v-if="!isPublic" class="p-2 py-1 flex" @click.stop>
|
||
2 years ago
|
<a-checkbox v-model:checked="showSystemFields" class="!items-center">
|
||
2 years ago
|
<span class="text-xs"> {{ $t('activity.showSystemFields') }}</span>
|
||
|
</a-checkbox>
|
||
2 years ago
|
</div>
|
||
2 years ago
|
<div class="p-2 flex gap-2" @click.stop>
|
||
2 years ago
|
<a-button size="small" class="!text-xs text-gray-500 text-capitalize" @click.stop="showAll()">
|
||
2 years ago
|
<!-- Show All -->
|
||
|
{{ $t('general.showAll') }}
|
||
|
</a-button>
|
||
2 years ago
|
<a-button size="small" class="!text-xs text-gray-500 text-capitalize" @click.stop="hideAll()">
|
||
2 years ago
|
<!-- Hide All -->
|
||
|
{{ $t('general.hideAll') }}
|
||
|
</a-button>
|
||
2 years ago
|
</div>
|
||
|
</div>
|
||
2 years ago
|
</template>
|
||
|
</a-dropdown>
|
||
2 years ago
|
</template>
|
||
|
|
||
|
<style scoped lang="scss">
|
||
2 years ago
|
:deep(.ant-checkbox-inner) {
|
||
|
@apply transform scale-60;
|
||
|
}
|
||
2 years ago
|
:deep(.ant-checkbox) {
|
||
|
@apply top-auto;
|
||
|
}
|
||
2 years ago
|
</style>
|