|
|
|
@ -20,7 +20,8 @@ const useForm = Form.useForm
|
|
|
|
|
|
|
|
|
|
const columnToValidate = [UITypes.Email, UITypes.URL, UITypes.PhoneNumber] |
|
|
|
|
|
|
|
|
|
const [useProvideColumnCreateStore, useColumnCreateStore] = createInjectionState((meta: Ref<TableType>, column?: ColumnType) => { |
|
|
|
|
const [useProvideColumnCreateStore, useColumnCreateStore] = createInjectionState( |
|
|
|
|
(meta: Ref<TableType>, column?: Ref<ColumnType>) => { |
|
|
|
|
const { sqlUi } = useProject() |
|
|
|
|
const { $api } = useNuxtApp() |
|
|
|
|
|
|
|
|
@ -33,9 +34,9 @@ const [useProvideColumnCreateStore, useColumnCreateStore] = createInjectionState
|
|
|
|
|
const formState = ref<Partial<Record<string, any>>>({ |
|
|
|
|
title: 'title', |
|
|
|
|
uidt: UITypes.SingleLineText, |
|
|
|
|
...(column || {}), |
|
|
|
|
...(column?.value || {}), |
|
|
|
|
// todo: swagger json update - include meta
|
|
|
|
|
meta: (column as any)?.meta || {}, |
|
|
|
|
meta: (column?.value as any)?.meta || {}, |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
const additionalValidations = ref<Record<string, any>>({}) |
|
|
|
@ -109,8 +110,8 @@ const [useProvideColumnCreateStore, useColumnCreateStore] = createInjectionState
|
|
|
|
|
formState.value.dtxs = sqlUi.value.getDefaultScaleForDatatype(formState.value.dt) |
|
|
|
|
|
|
|
|
|
const selectTypes = [UITypes.MultiSelect, UITypes.SingleSelect] |
|
|
|
|
if (column && selectTypes.includes(formState.value.uidt) && selectTypes.includes(column.uidt as UITypes)) { |
|
|
|
|
formState.value.dtxp = column.dtxp |
|
|
|
|
if (column && selectTypes.includes(formState.value.uidt) && selectTypes.includes(column?.value?.uidt as UITypes)) { |
|
|
|
|
formState.value.dtxp = column?.value?.dtxp |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (columnToValidate.includes(formState.value.uidt)) { |
|
|
|
@ -120,9 +121,9 @@ const [useProvideColumnCreateStore, useColumnCreateStore] = createInjectionState
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (isCurrency) { |
|
|
|
|
if (column?.uidt === UITypes.Currency) { |
|
|
|
|
formState.value.dtxp = column.dtxp |
|
|
|
|
formState.value.dtxs = column.dtxs |
|
|
|
|
if (column?.value?.uidt === UITypes.Currency) { |
|
|
|
|
formState.value.dtxp = column.value.dtxp |
|
|
|
|
formState.value.dtxs = column.value.dtxs |
|
|
|
|
} else { |
|
|
|
|
formState.value.dtxp = 19 |
|
|
|
|
formState.value.dtxs = 2 |
|
|
|
@ -148,14 +149,14 @@ const [useProvideColumnCreateStore, useColumnCreateStore] = createInjectionState
|
|
|
|
|
formState.value.dtx = 'specificType' |
|
|
|
|
|
|
|
|
|
const selectTypes = [UITypes.MultiSelect, UITypes.SingleSelect] |
|
|
|
|
if (column && selectTypes.includes(formState.value.uidt) && selectTypes.includes(column.uidt as UITypes)) { |
|
|
|
|
formState.value.dtxp = column.dtxp |
|
|
|
|
if (column?.value && selectTypes.includes(formState.value.uidt) && selectTypes.includes(column?.value.uidt as UITypes)) { |
|
|
|
|
formState.value.dtxp = column?.value.dtxp |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (isCurrency) { |
|
|
|
|
if (column?.uidt === UITypes.Currency) { |
|
|
|
|
formState.value.dtxp = column.dtxp |
|
|
|
|
formState.value.dtxs = column.dtxs |
|
|
|
|
if (column?.value?.uidt === UITypes.Currency) { |
|
|
|
|
formState.value.dtxp = column.value.dtxp |
|
|
|
|
formState.value.dtxs = column.value.dtxs |
|
|
|
|
} else { |
|
|
|
|
formState.value.dtxp = 19 |
|
|
|
|
formState.value.dtxs = 2 |
|
|
|
@ -179,8 +180,8 @@ const [useProvideColumnCreateStore, useColumnCreateStore] = createInjectionState
|
|
|
|
|
|
|
|
|
|
formState.value.table_name = meta.value.table_name |
|
|
|
|
formState.value.title = formState.value.column_name |
|
|
|
|
if (column) { |
|
|
|
|
await $api.dbTableColumn.update(column.id as string, formState.value) |
|
|
|
|
if (column?.value) { |
|
|
|
|
await $api.dbTableColumn.update(column?.value?.id as string, formState.value) |
|
|
|
|
toast.success('Column updated') |
|
|
|
|
} else { |
|
|
|
|
// todo : set additional meta for auto generated string id
|
|
|
|
@ -215,10 +216,11 @@ const [useProvideColumnCreateStore, useColumnCreateStore] = createInjectionState
|
|
|
|
|
onAlter, |
|
|
|
|
addOrUpdate, |
|
|
|
|
generateNewColumnMeta, |
|
|
|
|
isEdit: !!column?.id, |
|
|
|
|
isEdit: computed(() => !!column?.value?.id), |
|
|
|
|
column, |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
export { useProvideColumnCreateStore } |
|
|
|
|
|
|
|
|
|