mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
99 lines
3.8 KiB
99 lines
3.8 KiB
2 years ago
|
import type { ColumnType } from 'nocodb-sdk'
|
||
|
import { SqlUiFactory, UITypes, isVirtualCol } from 'nocodb-sdk'
|
||
2 years ago
|
import type { ComputedRef, Ref } from 'vue'
|
||
2 years ago
|
import { useProject } from '#imports'
|
||
2 years ago
|
|
||
2 years ago
|
export function useColumn(column: Ref<ColumnType>) {
|
||
2 years ago
|
const { project } = useProject()
|
||
2 years ago
|
|
||
2 years ago
|
const uiDatatype: ComputedRef<UITypes> = computed(() => column?.value?.uidt as UITypes)
|
||
2 years ago
|
const abstractType = computed(() => {
|
||
2 years ago
|
// kludge: CY test hack; column.value is being received NULL during attach cell delete operation
|
||
2 years ago
|
return isVirtualCol(column?.value) || !column?.value
|
||
2 years ago
|
? null
|
||
2 years ago
|
: SqlUiFactory.create(
|
||
2 years ago
|
project.value?.bases?.[0]?.type ? { client: project.value.bases[0].type } : { client: 'mysql2' },
|
||
2 years ago
|
).getAbstractType(column?.value)
|
||
|
})
|
||
2 years ago
|
|
||
2 years ago
|
const dataTypeLow = computed(() => column?.value?.dt?.toLowerCase())
|
||
|
const isBoolean = computed(() => abstractType.value === 'boolean')
|
||
2 years ago
|
const isString = computed(() => uiDatatype.value === UITypes.SingleLineText || abstractType.value === 'string')
|
||
2 years ago
|
const isTextArea = computed(() => uiDatatype.value === UITypes.LongText)
|
||
|
const isInt = computed(() => abstractType.value === 'integer')
|
||
2 years ago
|
const isFloat = computed(() => abstractType.value === 'float' || abstractType.value === UITypes.Number)
|
||
2 years ago
|
const isDate = computed(() => abstractType.value === 'date' || uiDatatype.value === UITypes.Date)
|
||
|
const isYear = computed(() => abstractType.value === 'year' || uiDatatype.value === UITypes.Year)
|
||
|
const isTime = computed(() => abstractType.value === 'time' || uiDatatype.value === UITypes.Time)
|
||
|
const isDateTime = computed(() => abstractType.value === 'datetime' || uiDatatype.value === UITypes.DateTime)
|
||
|
const isJSON = computed(() => uiDatatype.value === UITypes.JSON)
|
||
|
const isEnum = computed(() => uiDatatype.value === UITypes.SingleSelect)
|
||
|
const isSingleSelect = computed(() => uiDatatype.value === UITypes.SingleSelect)
|
||
|
const isSet = computed(() => uiDatatype.value === UITypes.MultiSelect)
|
||
|
const isMultiSelect = computed(() => uiDatatype.value === UITypes.MultiSelect)
|
||
|
const isURL = computed(() => uiDatatype.value === UITypes.URL)
|
||
2 years ago
|
const isEmail = computed(() => uiDatatype.value === UITypes.Email)
|
||
2 years ago
|
const isAttachment = computed(() => uiDatatype.value === UITypes.Attachment)
|
||
2 years ago
|
const isRating = computed(() => uiDatatype.value === UITypes.Rating)
|
||
2 years ago
|
const isCurrency = computed(() => uiDatatype.value === UITypes.Currency)
|
||
2 years ago
|
const isPhoneNumber = computed(() => uiDatatype.value === UITypes.PhoneNumber)
|
||
|
const isDecimal = computed(() => uiDatatype.value === UITypes.Decimal)
|
||
|
const isDuration = computed(() => uiDatatype.value === UITypes.Duration)
|
||
|
const isPercent = computed(() => uiDatatype.value === UITypes.Percent)
|
||
2 years ago
|
const isSpecificDBType = computed(() => uiDatatype.value === UITypes.SpecificDBType)
|
||
2 years ago
|
const isAutoSaved = computed(() =>
|
||
|
[
|
||
|
UITypes.SingleLineText,
|
||
|
UITypes.LongText,
|
||
|
UITypes.PhoneNumber,
|
||
|
UITypes.Email,
|
||
|
UITypes.URL,
|
||
|
UITypes.Number,
|
||
|
UITypes.Decimal,
|
||
|
UITypes.Percent,
|
||
|
UITypes.Count,
|
||
|
UITypes.AutoNumber,
|
||
|
UITypes.SpecificDBType,
|
||
|
UITypes.Geometry,
|
||
|
].includes(uiDatatype.value),
|
||
|
)
|
||
|
const isManualSaved = computed(() =>
|
||
|
[UITypes.Currency, UITypes.Year, UITypes.Time, UITypes.Duration].includes(uiDatatype.value),
|
||
|
)
|
||
2 years ago
|
const isPrimary = computed(() => {
|
||
|
return column?.value?.pv
|
||
|
})
|
||
2 years ago
|
|
||
|
return {
|
||
|
abstractType,
|
||
|
dataTypeLow,
|
||
2 years ago
|
isPrimary,
|
||
2 years ago
|
isBoolean,
|
||
|
isString,
|
||
|
isTextArea,
|
||
|
isInt,
|
||
|
isFloat,
|
||
|
isDate,
|
||
2 years ago
|
isYear,
|
||
2 years ago
|
isTime,
|
||
|
isDateTime,
|
||
|
isJSON,
|
||
|
isEnum,
|
||
|
isSet,
|
||
|
isURL,
|
||
|
isEmail,
|
||
|
isAttachment,
|
||
|
isRating,
|
||
|
isCurrency,
|
||
2 years ago
|
isDecimal,
|
||
2 years ago
|
isDuration,
|
||
|
isAutoSaved,
|
||
2 years ago
|
isManualSaved,
|
||
2 years ago
|
isSingleSelect,
|
||
2 years ago
|
isMultiSelect,
|
||
2 years ago
|
isPercent,
|
||
2 years ago
|
isPhoneNumber,
|
||
2 years ago
|
isSpecificDBType,
|
||
2 years ago
|
}
|
||
|
}
|