2020-06-15 17:41:31 +02:00
|
|
|
export const FIELDS = {
|
2020-08-07 17:13:57 +02:00
|
|
|
STRING: {
|
2020-09-29 19:27:35 +02:00
|
|
|
name: "Text",
|
2020-06-15 17:41:31 +02:00
|
|
|
icon: "ri-text",
|
2020-06-16 21:29:18 +02:00
|
|
|
type: "string",
|
|
|
|
constraints: {
|
2020-06-15 17:41:31 +02:00
|
|
|
type: "string",
|
2020-06-16 21:29:18 +02:00
|
|
|
length: {},
|
2020-10-05 18:28:23 +02:00
|
|
|
presence: false,
|
2020-06-15 17:41:31 +02:00
|
|
|
},
|
|
|
|
},
|
2020-12-03 15:03:17 +01:00
|
|
|
LONGFORM: {
|
|
|
|
name: "Long Form Text",
|
|
|
|
icon: "ri-file-text-line",
|
|
|
|
type: "longform",
|
|
|
|
constraints: {
|
|
|
|
type: "string",
|
|
|
|
length: {},
|
|
|
|
presence: false,
|
|
|
|
},
|
|
|
|
},
|
2020-09-29 19:27:35 +02:00
|
|
|
OPTIONS: {
|
|
|
|
name: "Options",
|
|
|
|
icon: "ri-list-check-2",
|
|
|
|
type: "options",
|
|
|
|
constraints: {
|
|
|
|
type: "string",
|
2020-10-11 21:42:30 +02:00
|
|
|
presence: false,
|
2020-09-29 19:27:35 +02:00
|
|
|
inclusion: [],
|
|
|
|
},
|
|
|
|
},
|
2020-06-15 17:41:31 +02:00
|
|
|
NUMBER: {
|
|
|
|
name: "Number",
|
|
|
|
icon: "ri-number-1",
|
2020-06-16 21:29:18 +02:00
|
|
|
type: "number",
|
|
|
|
constraints: {
|
2020-06-15 17:41:31 +02:00
|
|
|
type: "number",
|
2020-10-05 18:28:23 +02:00
|
|
|
presence: false,
|
2020-08-20 12:19:13 +02:00
|
|
|
numericality: { greaterThanOrEqualTo: "", lessThanOrEqualTo: "" },
|
2020-06-15 17:41:31 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
BOOLEAN: {
|
|
|
|
name: "True/False",
|
|
|
|
icon: "ri-toggle-line",
|
2020-06-16 21:29:18 +02:00
|
|
|
type: "boolean",
|
|
|
|
constraints: {
|
2020-06-15 17:41:31 +02:00
|
|
|
type: "boolean",
|
2020-10-05 18:28:23 +02:00
|
|
|
presence: false,
|
2020-06-15 17:41:31 +02:00
|
|
|
},
|
|
|
|
},
|
2020-09-08 19:03:41 +02:00
|
|
|
DATETIME: {
|
|
|
|
name: "Date/Time",
|
|
|
|
icon: "ri-calendar-event-fill",
|
|
|
|
type: "datetime",
|
|
|
|
constraints: {
|
|
|
|
type: "string",
|
|
|
|
length: {},
|
2020-10-05 18:28:23 +02:00
|
|
|
presence: false,
|
2020-09-08 19:03:41 +02:00
|
|
|
datetime: {
|
|
|
|
latest: "",
|
|
|
|
earliest: "",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-09-11 16:09:56 +02:00
|
|
|
ATTACHMENT: {
|
|
|
|
name: "Attachment",
|
|
|
|
icon: "ri-file-line",
|
|
|
|
type: "attachment",
|
|
|
|
constraints: {
|
|
|
|
type: "array",
|
2020-10-05 18:28:23 +02:00
|
|
|
presence: false,
|
2020-09-11 16:09:56 +02:00
|
|
|
},
|
|
|
|
},
|
2020-09-29 19:27:35 +02:00
|
|
|
LINK: {
|
|
|
|
name: "Relationship",
|
|
|
|
icon: "ri-link",
|
|
|
|
type: "link",
|
|
|
|
constraints: {
|
|
|
|
type: "array",
|
2020-10-11 21:42:30 +02:00
|
|
|
presence: false,
|
2020-09-29 19:27:35 +02:00
|
|
|
},
|
2021-02-15 20:59:30 +01:00
|
|
|
}
|
2021-02-15 18:47:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export const AUTO_COLUMN_SUB_TYPES = {
|
2021-02-15 20:59:30 +01:00
|
|
|
AUTO_ID: "autoID",
|
2021-02-15 18:47:14 +01:00
|
|
|
CREATED_BY: "createdBy",
|
|
|
|
CREATED_AT: "createdAt",
|
|
|
|
UPDATED_BY: "updatedBy",
|
|
|
|
UPDATED_AT: "updatedAt",
|
2021-02-15 20:59:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export const AUTO_COLUMN_DISPLAY_NAMES = {
|
|
|
|
AUTO_ID: "Auto ID",
|
|
|
|
CREATED_BY: "Created By",
|
|
|
|
CREATED_AT: "Created At",
|
|
|
|
UPDATED_BY: "Updated By",
|
|
|
|
UPDATED_AT: "Updated At",
|
2020-06-15 17:41:31 +02:00
|
|
|
}
|
2020-09-17 13:45:28 +02:00
|
|
|
|
|
|
|
export const FILE_TYPES = {
|
|
|
|
IMAGE: ["png", "tiff", "gif", "raw", "jpg", "jpeg"],
|
|
|
|
CODE: ["js", "rs", "py", "java", "rb", "hs", "yml"],
|
2020-09-17 17:36:39 +02:00
|
|
|
DOCUMENT: ["odf", "docx", "doc", "pdf", "csv"],
|
|
|
|
}
|
2021-01-26 12:07:30 +01:00
|
|
|
|
|
|
|
export const HostingTypes = {
|
|
|
|
CLOUD: "cloud",
|
|
|
|
SELF: "self",
|
|
|
|
}
|
2021-02-10 23:23:27 +01:00
|
|
|
|
|
|
|
export const Roles = {
|
|
|
|
ADMIN: "ADMIN",
|
|
|
|
POWER: "POWER",
|
|
|
|
BASIC: "BASIC",
|
|
|
|
PUBLIC: "PUBLIC",
|
|
|
|
BUILDER: "BUILDER",
|
|
|
|
}
|
2021-02-15 18:47:14 +01:00
|
|
|
|
|
|
|
export const USER_TABLE_ID = "ta_users"
|
|
|
|
|
|
|
|
export function isAutoColumnUserRelationship(subtype) {
|
|
|
|
return subtype === AUTO_COLUMN_SUB_TYPES.CREATED_BY ||
|
|
|
|
subtype === AUTO_COLUMN_SUB_TYPES.UPDATED_BY
|
|
|
|
}
|
|
|
|
|
2021-02-15 20:59:30 +01:00
|
|
|
export function getAutoColumnInformation(enabled = true) {
|
|
|
|
let info = {}
|
|
|
|
for (let [key, subtype] of Object.entries(AUTO_COLUMN_SUB_TYPES)) {
|
|
|
|
info[subtype] = {enabled, name: AUTO_COLUMN_DISPLAY_NAMES[key]}
|
|
|
|
}
|
|
|
|
return info
|
|
|
|
}
|
|
|
|
|
2021-02-15 18:47:14 +01:00
|
|
|
export function buildAutoColumn(tableName, name, subtype) {
|
2021-02-15 20:59:30 +01:00
|
|
|
let type, constraints
|
2021-02-15 18:47:14 +01:00
|
|
|
switch (subtype) {
|
|
|
|
case AUTO_COLUMN_SUB_TYPES.UPDATED_BY:
|
|
|
|
case AUTO_COLUMN_SUB_TYPES.CREATED_BY:
|
|
|
|
type = FIELDS.LINK.type
|
2021-02-15 20:59:30 +01:00
|
|
|
constraints = FIELDS.LINK.constraints
|
2021-02-15 18:47:14 +01:00
|
|
|
break
|
|
|
|
case AUTO_COLUMN_SUB_TYPES.AUTO_ID:
|
|
|
|
type = FIELDS.NUMBER.type
|
2021-02-15 20:59:30 +01:00
|
|
|
constraints = FIELDS.NUMBER.constraints
|
2021-02-15 18:47:14 +01:00
|
|
|
break
|
|
|
|
default:
|
|
|
|
type = FIELDS.STRING.type
|
2021-02-15 20:59:30 +01:00
|
|
|
constraints = FIELDS.STRING.constraints
|
2021-02-15 18:47:14 +01:00
|
|
|
break
|
|
|
|
}
|
|
|
|
if (Object.values(AUTO_COLUMN_SUB_TYPES).indexOf(subtype) === -1) {
|
|
|
|
throw "Cannot build auto column with supplied subtype"
|
|
|
|
}
|
|
|
|
const base = {
|
|
|
|
name,
|
|
|
|
type,
|
|
|
|
subtype,
|
|
|
|
icon: "ri-magic-line",
|
|
|
|
autocolumn: true,
|
2021-02-15 20:59:30 +01:00
|
|
|
constraints,
|
2021-02-15 18:47:14 +01:00
|
|
|
}
|
|
|
|
if (isAutoColumnUserRelationship(subtype)) {
|
|
|
|
base.tableId = USER_TABLE_ID
|
|
|
|
base.fieldName = `${tableName}-${name}`
|
|
|
|
}
|
|
|
|
return base
|
|
|
|
}
|