|
|
@ -8,30 +8,26 @@ import { |
|
|
|
computed, |
|
|
|
computed, |
|
|
|
getSortDirectionOptions, |
|
|
|
getSortDirectionOptions, |
|
|
|
inject, |
|
|
|
inject, |
|
|
|
onMounted, |
|
|
|
|
|
|
|
ref, |
|
|
|
ref, |
|
|
|
useMenuCloseOnEsc, |
|
|
|
useMenuCloseOnEsc, |
|
|
|
useMetas, |
|
|
|
|
|
|
|
useNuxtApp, |
|
|
|
useNuxtApp, |
|
|
|
useSmartsheetStoreOrThrow, |
|
|
|
useSmartsheetStoreOrThrow, |
|
|
|
useViewColumnsOrThrow, |
|
|
|
useViewColumnsOrThrow, |
|
|
|
watch, |
|
|
|
watch, |
|
|
|
} from '#imports' |
|
|
|
} from '#imports' |
|
|
|
|
|
|
|
|
|
|
|
const excludedGroupingUidt = [UITypes.Attachment] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const meta = inject(MetaInj, ref()) |
|
|
|
const meta = inject(MetaInj, ref()) |
|
|
|
const view = inject(ActiveViewInj, ref()) |
|
|
|
const view = inject(ActiveViewInj, ref()) |
|
|
|
const isLocked = inject(IsLockedInj, ref(false)) |
|
|
|
const isLocked = inject(IsLockedInj, ref(false)) |
|
|
|
|
|
|
|
|
|
|
|
const { gridViewCols, updateGridViewColumn, metaColumnById, showSystemFields } = useViewColumnsOrThrow() |
|
|
|
const { gridViewCols, updateGridViewColumn, metaColumnById, showSystemFields } = useViewColumnsOrThrow() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const { fieldsToGroupBy } = useViewGroupBy(view) |
|
|
|
|
|
|
|
|
|
|
|
const { $e } = useNuxtApp() |
|
|
|
const { $e } = useNuxtApp() |
|
|
|
|
|
|
|
|
|
|
|
const _groupBy = ref<{ fk_column_id?: string; sort: string; order: number }[]>([]) |
|
|
|
const _groupBy = ref<{ fk_column_id?: string; sort: string; order: number }[]>([]) |
|
|
|
|
|
|
|
|
|
|
|
const { getMeta } = useMetas() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const groupBy = computed<{ fk_column_id?: string; sort: string; order: number }[]>(() => { |
|
|
|
const groupBy = computed<{ fk_column_id?: string; sort: string; order: number }[]>(() => { |
|
|
|
const tempGroupBy: { fk_column_id?: string; sort: string; order: number }[] = [] |
|
|
|
const tempGroupBy: { fk_column_id?: string; sort: string; order: number }[] = [] |
|
|
|
Object.values(gridViewCols.value).forEach((col) => { |
|
|
|
Object.values(gridViewCols.value).forEach((col) => { |
|
|
@ -53,24 +49,8 @@ const { eventBus } = useSmartsheetStoreOrThrow() |
|
|
|
|
|
|
|
|
|
|
|
const { isMobileMode } = useGlobal() |
|
|
|
const { isMobileMode } = useGlobal() |
|
|
|
|
|
|
|
|
|
|
|
const supportedLookups = ref<string[]>([]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const showCreateGroupBy = ref(false) |
|
|
|
const showCreateGroupBy = ref(false) |
|
|
|
|
|
|
|
|
|
|
|
const fieldsToGroupBy = computed(() => { |
|
|
|
|
|
|
|
const fields = meta.value?.columns || [] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return fields.filter((field) => { |
|
|
|
|
|
|
|
if (excludedGroupingUidt.includes(field.uidt as UITypes)) return false |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (field.uidt === UITypes.Lookup) { |
|
|
|
|
|
|
|
return field.id && supportedLookups.value.includes(field.id) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const columns = computed(() => meta.value?.columns || []) |
|
|
|
const columns = computed(() => meta.value?.columns || []) |
|
|
|
|
|
|
|
|
|
|
|
const columnByID = computed(() => |
|
|
|
const columnByID = computed(() => |
|
|
@ -152,6 +132,7 @@ const saveGroupBy = async () => { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const addFieldToGroupBy = (column: ColumnType) => { |
|
|
|
const addFieldToGroupBy = (column: ColumnType) => { |
|
|
|
|
|
|
|
console.log('groupByField', column) |
|
|
|
_groupBy.value.push({ fk_column_id: column.id, sort: 'asc', order: _groupBy.value.length + 1 }) |
|
|
|
_groupBy.value.push({ fk_column_id: column.id, sort: 'asc', order: _groupBy.value.length + 1 }) |
|
|
|
saveGroupBy() |
|
|
|
saveGroupBy() |
|
|
|
showCreateGroupBy.value = false |
|
|
|
showCreateGroupBy.value = false |
|
|
@ -174,54 +155,19 @@ watch(open, () => { |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
const loadAllowedLookups = async () => { |
|
|
|
eventBus.on(async (event, column) => { |
|
|
|
const filteredLookupCols = [] |
|
|
|
if (!column?.id) return |
|
|
|
try { |
|
|
|
|
|
|
|
for (const col of meta.value?.columns || []) { |
|
|
|
|
|
|
|
if (col.uidt !== UITypes.Lookup) continue |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let nextCol: ColumnType = col |
|
|
|
|
|
|
|
// check the lookup column is supported type or not |
|
|
|
|
|
|
|
while (nextCol && nextCol.uidt === UITypes.Lookup) { |
|
|
|
|
|
|
|
const lookupRelation = (await getMeta(nextCol.fk_model_id as string))?.columns?.find( |
|
|
|
|
|
|
|
(c) => c.id === (nextCol?.colOptions as LookupType).fk_relation_column_id, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const relatedTableMeta = await getMeta( |
|
|
|
|
|
|
|
(lookupRelation?.colOptions as LinkToAnotherRecordType).fk_related_model_id as string, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nextCol = relatedTableMeta?.columns?.find( |
|
|
|
|
|
|
|
(c) => c.id === ((nextCol?.colOptions as LookupType).fk_lookup_column_id as string), |
|
|
|
|
|
|
|
) as ColumnType |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if next column is same as root lookup column then break the loop |
|
|
|
|
|
|
|
// since it's going to be a circular loop, and ignore the column |
|
|
|
|
|
|
|
if (nextCol?.id === col.id) { |
|
|
|
|
|
|
|
break |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (nextCol?.uidt !== UITypes.Attachment && col.id) filteredLookupCols.push(col.id) |
|
|
|
console.log('_groupBy', column, _groupBy.value) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
supportedLookups.value = filteredLookupCols |
|
|
|
if (event === SmartsheetStoreEvents.GROUP_BY_ADD) { |
|
|
|
} catch (e) { |
|
|
|
addFieldToGroupBy(column) |
|
|
|
console.error(e) |
|
|
|
} else if (event === SmartsheetStoreEvents.GROUP_BY_REMOVE) { |
|
|
|
} |
|
|
|
if (groupedByColumnIds.value.length === 0) return |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
onMounted(async () => { |
|
|
|
_groupBy.value = _groupBy.value.filter((g) => g.fk_column_id !== column.id) |
|
|
|
await loadAllowedLookups() |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
watch(meta, async () => { |
|
|
|
await saveGroupBy() |
|
|
|
await loadAllowedLookups() |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
eventBus.on(async (event, payload) => { |
|
|
|
|
|
|
|
if (event === SmartsheetStoreEvents.GROUP_BY_ADD) { |
|
|
|
|
|
|
|
open.value = true |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
</script> |
|
|
|
</script> |
|
|
|