|
|
@ -1,18 +1,41 @@ |
|
|
|
import type { GalleryType, GridType, KanbanType, SortType } from 'nocodb-sdk' |
|
|
|
import type { GalleryType, GridType, KanbanType, SortType } from 'nocodb-sdk' |
|
|
|
import type { Ref } from 'vue' |
|
|
|
import type { Ref } from 'vue' |
|
|
|
import { useNuxtApp } from '#imports' |
|
|
|
import { useNuxtApp } from '#imports' |
|
|
|
|
|
|
|
import { IsPublicInj, ReloadViewDataHookInj } from '~/context' |
|
|
|
|
|
|
|
|
|
|
|
export function useViewSorts( |
|
|
|
export function useViewSorts( |
|
|
|
view: Ref<(GridType | KanbanType | GalleryType) & { id?: string }> | undefined, |
|
|
|
view: Ref<(GridType | KanbanType | GalleryType) & { id?: string }> | undefined, |
|
|
|
reloadData?: () => void, |
|
|
|
reloadData?: () => void, |
|
|
|
) { |
|
|
|
) { |
|
|
|
const sorts = ref<SortType[]>([]) |
|
|
|
const _sorts = ref<SortType[]>([]) |
|
|
|
|
|
|
|
const { sorts: sharedViewSorts, sharedView } = useSharedView() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const reloadHook = inject(ReloadViewDataHookInj) |
|
|
|
|
|
|
|
const isPublic = inject(IsPublicInj, ref(false)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const sorts = computed<SortType[]>({ |
|
|
|
|
|
|
|
get: () => (isPublic.value ? sharedViewSorts.value : _sorts.value), |
|
|
|
|
|
|
|
set: (value) => { |
|
|
|
|
|
|
|
if (isPublic.value) { |
|
|
|
|
|
|
|
sharedViewSorts.value = value |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
_sorts.value = value |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
reloadHook?.trigger() |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
const { $api } = useNuxtApp() |
|
|
|
const { $api } = useNuxtApp() |
|
|
|
|
|
|
|
|
|
|
|
const { isUIAllowed } = useUIPermission() |
|
|
|
const { isUIAllowed } = useUIPermission() |
|
|
|
|
|
|
|
|
|
|
|
const loadSorts = async () => { |
|
|
|
const loadSorts = async () => { |
|
|
|
|
|
|
|
if (isPublic.value) { |
|
|
|
|
|
|
|
console.log('load sorts public', sharedView.value?.sorts) |
|
|
|
|
|
|
|
const sharedSorts = sharedView.value?.sorts || [] |
|
|
|
|
|
|
|
sorts.value = [...sharedSorts] |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
if (!view?.value) return |
|
|
|
if (!view?.value) return |
|
|
|
sorts.value = ((await $api.dbTableSort.list(view?.value?.id as string)) as any)?.sorts?.list |
|
|
|
sorts.value = ((await $api.dbTableSort.list(view?.value?.id as string)) as any)?.sorts?.list |
|
|
|
} |
|
|
|
} |
|
|
@ -20,6 +43,12 @@ export function useViewSorts( |
|
|
|
const saveOrUpdate = async (sort: SortType, i: number) => { |
|
|
|
const saveOrUpdate = async (sort: SortType, i: number) => { |
|
|
|
// TODO:
|
|
|
|
// TODO:
|
|
|
|
// if (!this.shared && this._isUIAllowed('sortSync')) {
|
|
|
|
// if (!this.shared && this._isUIAllowed('sortSync')) {
|
|
|
|
|
|
|
|
if (isPublic.value) { |
|
|
|
|
|
|
|
sorts.value[i] = sort |
|
|
|
|
|
|
|
sorts.value = [...sorts.value] |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (isUIAllowed('sortSync')) { |
|
|
|
if (isUIAllowed('sortSync')) { |
|
|
|
if (sort.id) { |
|
|
|
if (sort.id) { |
|
|
|
await $api.dbTableSort.update(sort.id, sort) |
|
|
|
await $api.dbTableSort.update(sort.id, sort) |
|
|
@ -30,14 +59,23 @@ export function useViewSorts( |
|
|
|
reloadData?.() |
|
|
|
reloadData?.() |
|
|
|
} |
|
|
|
} |
|
|
|
const addSort = () => { |
|
|
|
const addSort = () => { |
|
|
|
sorts.value.push({ |
|
|
|
sorts.value = [ |
|
|
|
direction: 'asc', |
|
|
|
...sorts.value, |
|
|
|
}) |
|
|
|
{ |
|
|
|
|
|
|
|
direction: 'asc', |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
] |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const deleteSort = async (sort: SortType, i: number) => { |
|
|
|
const deleteSort = async (sort: SortType, i: number) => { |
|
|
|
// TOOD:
|
|
|
|
// TOOD:
|
|
|
|
// if (!this.shared && sort.id && this._isUIAllowed('sortSync')) {
|
|
|
|
// if (!this.shared && sort.id && this._isUIAllowed('sortSync')) {
|
|
|
|
|
|
|
|
if (isPublic.value) { |
|
|
|
|
|
|
|
sorts.value.splice(i, 1) |
|
|
|
|
|
|
|
sorts.value = [...sorts.value] |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (isUIAllowed('sortSync') && sort.id) { |
|
|
|
if (isUIAllowed('sortSync') && sort.id) { |
|
|
|
await $api.dbTableSort.delete(sort.id) |
|
|
|
await $api.dbTableSort.delete(sort.id) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|