|
|
@ -3,13 +3,10 @@ import type { ColumnType, TableType, ViewType } from 'nocodb-sdk' |
|
|
|
import { watch } from 'vue' |
|
|
|
import { watch } from 'vue' |
|
|
|
import type { ComputedRef, Ref } from 'vue' |
|
|
|
import type { ComputedRef, Ref } from 'vue' |
|
|
|
import { useNuxtApp } from '#app' |
|
|
|
import { useNuxtApp } from '#app' |
|
|
|
|
|
|
|
import { IsPublicInj } from '~/context' |
|
|
|
|
|
|
|
|
|
|
|
export function useViewColumns( |
|
|
|
export function useViewColumns(view: Ref<ViewType> | undefined, meta: ComputedRef<TableType>, reloadData?: () => void) { |
|
|
|
view: Ref<ViewType> | undefined, |
|
|
|
const isPublic = inject(IsPublicInj, ref(false)) |
|
|
|
meta: ComputedRef<TableType>, |
|
|
|
|
|
|
|
isPublic = false, |
|
|
|
|
|
|
|
reloadData?: () => void, |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
const fields = ref< |
|
|
|
const fields = ref< |
|
|
|
{ |
|
|
|
{ |
|
|
|
order: number |
|
|
|
order: number |
|
|
@ -31,7 +28,7 @@ export function useViewColumns( |
|
|
|
|
|
|
|
|
|
|
|
let order = 1 |
|
|
|
let order = 1 |
|
|
|
if (view.value?.id) { |
|
|
|
if (view.value?.id) { |
|
|
|
const data = (await $api.dbViewColumn.list(view.value.id)) as any[] |
|
|
|
const data = (isPublic.value ? meta.value?.columns : await $api.dbViewColumn.list(view.value.id)) as any[] |
|
|
|
|
|
|
|
|
|
|
|
const fieldById = data.reduce<Record<string, any>>((acc, curr) => { |
|
|
|
const fieldById = data.reduce<Record<string, any>>((acc, curr) => { |
|
|
|
curr.show = !!curr.show |
|
|
|
curr.show = !!curr.show |
|
|
@ -54,8 +51,6 @@ export function useViewColumns( |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
.sort((a, b) => a.order - b.order) |
|
|
|
.sort((a, b) => a.order - b.order) |
|
|
|
} else if (isPublic) { |
|
|
|
|
|
|
|
fields.value = meta.value.columns as any |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -89,6 +84,22 @@ export function useViewColumns( |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const saveOrUpdate = async (field: any, index: number) => { |
|
|
|
const saveOrUpdate = async (field: any, index: number) => { |
|
|
|
|
|
|
|
if (isPublic && fields.value) { |
|
|
|
|
|
|
|
fields.value[index] = field |
|
|
|
|
|
|
|
meta.value.columns = meta.value?.columns?.map((column) => { |
|
|
|
|
|
|
|
if (column.id === field.fk_column_id) { |
|
|
|
|
|
|
|
return { |
|
|
|
|
|
|
|
...column, |
|
|
|
|
|
|
|
...field, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return column |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reloadData?.() |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (isUIAllowed('fieldsSync')) { |
|
|
|
if (isUIAllowed('fieldsSync')) { |
|
|
|
if (field.id && view?.value?.id) { |
|
|
|
if (field.id && view?.value?.id) { |
|
|
|
await $api.dbViewColumn.update(view.value.id, field.id, field) |
|
|
|
await $api.dbViewColumn.update(view.value.id, field.id, field) |
|
|
@ -118,11 +129,13 @@ export function useViewColumns( |
|
|
|
}, |
|
|
|
}, |
|
|
|
set(v: boolean) { |
|
|
|
set(v: boolean) { |
|
|
|
if (view?.value?.id) { |
|
|
|
if (view?.value?.id) { |
|
|
|
$api.dbView |
|
|
|
if (!isPublic.value) { |
|
|
|
.update(view.value.id, { |
|
|
|
$api.dbView |
|
|
|
show_system_fields: v, |
|
|
|
.update(view.value.id, { |
|
|
|
}) |
|
|
|
show_system_fields: v, |
|
|
|
.finally(() => reloadData?.()) |
|
|
|
}) |
|
|
|
|
|
|
|
.finally(() => reloadData?.()) |
|
|
|
|
|
|
|
} |
|
|
|
;(view.value as any).show_system_fields = v |
|
|
|
;(view.value as any).show_system_fields = v |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|