|
|
@ -2,7 +2,7 @@ import type { FilterType, ViewType } from 'nocodb-sdk' |
|
|
|
import type { ComputedRef, Ref } from 'vue' |
|
|
|
import type { ComputedRef, Ref } from 'vue' |
|
|
|
import { useNuxtApp, useUIPermission } from '#imports' |
|
|
|
import { useNuxtApp, useUIPermission } from '#imports' |
|
|
|
import { useMetas } from '~/composables/useMetas' |
|
|
|
import { useMetas } from '~/composables/useMetas' |
|
|
|
import { IsPublicInj, MetaInj } from '~/context' |
|
|
|
import { IsPublicInj, ReloadViewDataHookInj } from '~/context' |
|
|
|
|
|
|
|
|
|
|
|
export function useViewFilters( |
|
|
|
export function useViewFilters( |
|
|
|
view: Ref<ViewType> | undefined, |
|
|
|
view: Ref<ViewType> | undefined, |
|
|
@ -11,16 +11,28 @@ export function useViewFilters( |
|
|
|
reloadData?: () => void, |
|
|
|
reloadData?: () => void, |
|
|
|
) { |
|
|
|
) { |
|
|
|
const { filters: sharedViewFilter } = useSharedView() |
|
|
|
const { filters: sharedViewFilter } = useSharedView() |
|
|
|
const meta = inject(MetaInj) |
|
|
|
|
|
|
|
const { loadData } = useViewData(meta, view) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const filters = ref<(FilterType & { status?: 'update' | 'delete' | 'create'; parentId?: string })[]>([]) |
|
|
|
const reloadHook = inject(ReloadViewDataHookInj) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const _filters = ref<(FilterType & { status?: 'update' | 'delete' | 'create'; parentId?: string })[]>([]) |
|
|
|
|
|
|
|
|
|
|
|
const isPublic = inject(IsPublicInj, ref(false)) |
|
|
|
const isPublic = inject(IsPublicInj, ref(false)) |
|
|
|
const { $api } = useNuxtApp() |
|
|
|
const { $api } = useNuxtApp() |
|
|
|
const { isUIAllowed } = useUIPermission() |
|
|
|
const { isUIAllowed } = useUIPermission() |
|
|
|
const { metas } = useMetas() |
|
|
|
const { metas } = useMetas() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const filters = computed({ |
|
|
|
|
|
|
|
get: () => (isPublic.value ? sharedViewFilter.value : _filters.value), |
|
|
|
|
|
|
|
set: (value) => { |
|
|
|
|
|
|
|
if (isPublic.value) { |
|
|
|
|
|
|
|
sharedViewFilter.value = value |
|
|
|
|
|
|
|
reloadHook?.trigger() |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
_filters.value = value |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
const loadFilters = async (hookId?: string) => { |
|
|
|
const loadFilters = async (hookId?: string) => { |
|
|
|
if (isPublic.value) return |
|
|
|
if (isPublic.value) return |
|
|
|
|
|
|
|
|
|
|
@ -111,27 +123,21 @@ export function useViewFilters( |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const addFilter = () => { |
|
|
|
const addFilter = () => { |
|
|
|
filters.value = [ |
|
|
|
filters.value.push({ |
|
|
|
...filters.value, |
|
|
|
comparison_op: 'eq', |
|
|
|
{ |
|
|
|
value: '', |
|
|
|
comparison_op: 'eq', |
|
|
|
status: 'create', |
|
|
|
value: '', |
|
|
|
logical_op: 'and', |
|
|
|
status: 'create', |
|
|
|
}) |
|
|
|
logical_op: 'and', |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const addFilterGroup = async () => { |
|
|
|
const addFilterGroup = async () => { |
|
|
|
filters.value = [ |
|
|
|
filters.value.push({ |
|
|
|
...filters.value, |
|
|
|
parentId, |
|
|
|
{ |
|
|
|
is_group: true, |
|
|
|
parentId, |
|
|
|
status: 'create', |
|
|
|
is_group: true, |
|
|
|
logical_op: 'and', |
|
|
|
status: 'create', |
|
|
|
}) |
|
|
|
logical_op: 'and', |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
const index = filters.value.length - 1 |
|
|
|
const index = filters.value.length - 1 |
|
|
|
await saveOrUpdate(filters.value[index], index, true) |
|
|
|
await saveOrUpdate(filters.value[index], index, true) |
|
|
|
} |
|
|
|
} |
|
|
@ -152,15 +158,5 @@ export function useViewFilters( |
|
|
|
}, |
|
|
|
}, |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
watch( |
|
|
|
|
|
|
|
() => filters.value, |
|
|
|
|
|
|
|
() => { |
|
|
|
|
|
|
|
if (!isPublic.value) return |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sharedViewFilter.value = filters.value |
|
|
|
|
|
|
|
loadData() |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { filters, loadFilters, sync, deleteFilter, saveOrUpdate, addFilter, addFilterGroup } |
|
|
|
return { filters, loadFilters, sync, deleteFilter, saveOrUpdate, addFilter, addFilterGroup } |
|
|
|
} |
|
|
|
} |
|
|
|