|
|
@ -1,17 +1,21 @@ |
|
|
|
import type { FilterType, GalleryType, GridType, KanbanType } from 'nocodb-sdk' |
|
|
|
import type {FilterType, GalleryType, GridType, KanbanType} from 'nocodb-sdk' |
|
|
|
import type { ComputedRef, Ref } from 'vue' |
|
|
|
import type {ComputedRef, Ref} from 'vue' |
|
|
|
import { useNuxtApp } from '#imports' |
|
|
|
import {useNuxtApp} from '#imports' |
|
|
|
|
|
|
|
import useUIPermission from '~/composables/useUIPermission' |
|
|
|
|
|
|
|
|
|
|
|
export function useViewFilters( |
|
|
|
export function useViewFilters( |
|
|
|
view: Ref<(GridType | KanbanType | GalleryType) & { id?: string }> | undefined, |
|
|
|
view: Ref<(GridType | KanbanType | GalleryType) & { id?: string }> | undefined, |
|
|
|
parentId?: string, |
|
|
|
parentId?: string, |
|
|
|
autoApply?: ComputedRef<boolean>, |
|
|
|
autoApply?: ComputedRef<boolean>, |
|
|
|
reloadData?: () => void, |
|
|
|
reloadData?: () => void, |
|
|
|
|
|
|
|
shared = false |
|
|
|
) { |
|
|
|
) { |
|
|
|
|
|
|
|
|
|
|
|
// todo: update swagger
|
|
|
|
// todo: update swagger
|
|
|
|
const filters = ref<(FilterType & { status?: 'update' | 'delete'; parentId?: string })[]>([]) |
|
|
|
const filters = ref<(FilterType & { status?: 'update' | 'delete' | 'create'; parentId?: string })[]>([]) |
|
|
|
|
|
|
|
|
|
|
|
const { $api } = useNuxtApp() |
|
|
|
const {$api} = useNuxtApp() |
|
|
|
|
|
|
|
const {isUIAllowed} = useUIPermission() |
|
|
|
|
|
|
|
|
|
|
|
const loadFilters = async () => { |
|
|
|
const loadFilters = async () => { |
|
|
|
if (parentId) { |
|
|
|
if (parentId) { |
|
|
@ -30,7 +34,7 @@ export function useViewFilters( |
|
|
|
...filter, |
|
|
|
...filter, |
|
|
|
fk_parent_id: parentId, |
|
|
|
fk_parent_id: parentId, |
|
|
|
}) |
|
|
|
}) |
|
|
|
} else { |
|
|
|
} else if (filter.status === 'create') { |
|
|
|
filters.value[+i] = (await $api.dbTableFilter.create(view?.value?.id as string, { |
|
|
|
filters.value[+i] = (await $api.dbTableFilter.create(view?.value?.id as string, { |
|
|
|
...filter, |
|
|
|
...filter, |
|
|
|
fk_parent_id: parentId, |
|
|
|
fk_parent_id: parentId, |
|
|
@ -41,54 +45,41 @@ export function useViewFilters( |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const deleteFilter = async (filter: FilterType & { status: string }, i: number) => { |
|
|
|
const deleteFilter = async (filter: FilterType & { status: string }, i: number) => { |
|
|
|
// if (this.shared || !this._isUIAllowed('filterSync')) {
|
|
|
|
|
|
|
|
// this.filters.splice(i, 1)
|
|
|
|
|
|
|
|
// this.$emit('updated')
|
|
|
|
|
|
|
|
// } else
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (filter.id) { |
|
|
|
if (shared || !isUIAllowed('filterSync')) { |
|
|
|
|
|
|
|
const _filters = unref(filters.value) |
|
|
|
|
|
|
|
_filters.splice(i, 1) |
|
|
|
|
|
|
|
filters.value = _filters |
|
|
|
|
|
|
|
} else if (filter.id) { |
|
|
|
if (!autoApply?.value) { |
|
|
|
if (!autoApply?.value) { |
|
|
|
filter.status = 'delete' |
|
|
|
filter.status = 'delete' |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
await $api.dbTableFilter.delete(filter.id) /**/ |
|
|
|
await $api.dbTableFilter.delete(filter.id) |
|
|
|
// await this.loadFilter()
|
|
|
|
const _filters = unref(filters.value) |
|
|
|
// this.$emit('updated')
|
|
|
|
_filters.splice(i, 1) |
|
|
|
|
|
|
|
filters.value = _filters |
|
|
|
|
|
|
|
reloadData?.() |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
|
|
|
|
// this.$emit('updated')
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
const _filters = unref(filters.value) |
|
|
|
|
|
|
|
_filters.splice(i, 1) |
|
|
|
|
|
|
|
filters.value = _filters |
|
|
|
|
|
|
|
// this.$e('a:filter:delete')
|
|
|
|
|
|
|
|
// // },
|
|
|
|
|
|
|
|
reloadData?.() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const saveOrUpdate = async (filter: FilterType & { status?: string }, i: number) => { |
|
|
|
const saveOrUpdate = async (filter: FilterType & { status?: string }, i: number, force = false) => { |
|
|
|
if (!view?.value) return |
|
|
|
if (!view?.value) return |
|
|
|
|
|
|
|
if (shared || !isUIAllowed('filterSync')) { |
|
|
|
// if (this.shared || !this._isUIAllowed('filterSync')) {
|
|
|
|
// skip
|
|
|
|
// this.$emit('input', this.filters.filter(f => f.fk_column_id && f.comparison_op))
|
|
|
|
} else if (!autoApply?.value && !force) { |
|
|
|
// this.$emit('updated')
|
|
|
|
filter.status = filter.id ? 'update' : 'create' |
|
|
|
// } else
|
|
|
|
|
|
|
|
if (!autoApply?.value) { |
|
|
|
|
|
|
|
filter.status = 'update' |
|
|
|
|
|
|
|
} else if (filter.id) { |
|
|
|
} else if (filter.id) { |
|
|
|
await $api.dbTableFilter.update(filter.id, { |
|
|
|
await $api.dbTableFilter.update(filter.id, { |
|
|
|
...filter, |
|
|
|
...filter, |
|
|
|
fk_parent_id: parentId, |
|
|
|
fk_parent_id: parentId, |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
// this.$emit('updated')
|
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
// todo: return type correction
|
|
|
|
// todo: return type correction
|
|
|
|
filters.value[i] = (await $api.dbTableFilter.create(view?.value?.id as string, { |
|
|
|
filters.value[i] = (await $api.dbTableFilter.create(view?.value?.id as string, { |
|
|
|
...filter, |
|
|
|
...filter, |
|
|
|
fk_parent_id: parentId, |
|
|
|
fk_parent_id: parentId, |
|
|
|
})) as any |
|
|
|
})) as any |
|
|
|
|
|
|
|
|
|
|
|
// this.$emit('updated')
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
reloadData?.() |
|
|
|
reloadData?.() |
|
|
|
} |
|
|
|
} |
|
|
@ -97,7 +88,7 @@ export function useViewFilters( |
|
|
|
filters.value.push({ |
|
|
|
filters.value.push({ |
|
|
|
comparison_op: 'eq', |
|
|
|
comparison_op: 'eq', |
|
|
|
value: '', |
|
|
|
value: '', |
|
|
|
status: 'update', |
|
|
|
status: 'create', |
|
|
|
logical_op: 'and', |
|
|
|
logical_op: 'and', |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
@ -106,12 +97,12 @@ export function useViewFilters( |
|
|
|
filters.value.push({ |
|
|
|
filters.value.push({ |
|
|
|
parentId, |
|
|
|
parentId, |
|
|
|
is_group: true, |
|
|
|
is_group: true, |
|
|
|
status: 'update', |
|
|
|
status: 'create', |
|
|
|
logical_op: 'and', |
|
|
|
logical_op: 'and', |
|
|
|
}) |
|
|
|
}) |
|
|
|
const index = filters.value.length - 1 |
|
|
|
const index = filters.value.length - 1 |
|
|
|
await saveOrUpdate(filters.value[index], index) |
|
|
|
await saveOrUpdate(filters.value[index], index, true) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return { filters, loadFilters, sync, deleteFilter, saveOrUpdate, addFilter, addFilterGroup } |
|
|
|
return {filters, loadFilters, sync, deleteFilter, saveOrUpdate, addFilter, addFilterGroup} |
|
|
|
} |
|
|
|
} |
|
|
|