Data: roles & rules: fixed id and pydantic handling ui+gateway Table generic: Fixed column width changing with persistent user width not overwritten by default in the session Table generic: fixed active item in navbar working with subpaths Table generic: fixed sort and pagination with modified routes Table generic: enhanced logic to select page directly and bar on top of the table Table generic: Always load data with pagination, fixed page counter (not updated), enhanced pagination to access pages directly Table generic: Filter function enhanced directly as dropdown in column headers, sorting enhanced to have cascading sorting Table generic: Added multilingual to AttributeType and handle it in the form renderer, removed explicit field definitions from team-members.ts and prompts.ts to use dynamic generation from backend attributes strictly Table generic: Inline editting of checkboxes and boolean values Table generig: Only generic logic, no explicit logic (e.g. id's) Table generic: Removed all specific parts like action icons. To e a parameter by calling instance.
193 lines
4.4 KiB
TypeScript
193 lines
4.4 KiB
TypeScript
/**
|
|
* Utility functions for mapping attribute types to HTML input types and component types
|
|
*/
|
|
|
|
export type AttributeType =
|
|
| 'text'
|
|
| 'textarea'
|
|
| 'select'
|
|
| 'multiselect'
|
|
| 'multilingual'
|
|
| 'integer'
|
|
| 'float'
|
|
| 'number'
|
|
| 'timestamp'
|
|
| 'date'
|
|
| 'time'
|
|
| 'checkbox'
|
|
| 'boolean'
|
|
| 'email'
|
|
| 'url'
|
|
| 'password'
|
|
| 'file'
|
|
| 'string'
|
|
| 'enum'
|
|
| 'readonly';
|
|
|
|
export type InputComponentType =
|
|
| 'text'
|
|
| 'textarea'
|
|
| 'select'
|
|
| 'multiselect'
|
|
| 'multilingual'
|
|
| 'checkbox'
|
|
| 'file'
|
|
| 'email'
|
|
| 'url'
|
|
| 'password'
|
|
| 'date'
|
|
| 'time'
|
|
| 'datetime-local'
|
|
| 'number';
|
|
|
|
/**
|
|
* Maps attribute type to HTML input type
|
|
*
|
|
* @param attributeType - The attribute type from the backend
|
|
* @returns The corresponding HTML input type
|
|
*
|
|
* Mapping rules:
|
|
* - text → text (single line)
|
|
* - textarea → textarea (multi-line)
|
|
* - select → select (dropdown with options)
|
|
* - multiselect → multiselect (multiple selection)
|
|
* - integer → number (integer only)
|
|
* - float or number → number (decimal allowed)
|
|
* - timestamp → datetime-local (date/time picker)
|
|
* - date → date (date picker, date only)
|
|
* - time → time (time picker, time only)
|
|
* - checkbox or boolean → checkbox (boolean)
|
|
* - email → email (with email validation)
|
|
* - url → url (with URL validation)
|
|
* - password → password (masked)
|
|
* - file → file (file upload)
|
|
*/
|
|
export function attributeTypeToInputType(attributeType: AttributeType): InputComponentType {
|
|
switch (attributeType) {
|
|
case 'text':
|
|
case 'string':
|
|
return 'text';
|
|
|
|
case 'textarea':
|
|
return 'textarea';
|
|
|
|
case 'select':
|
|
case 'enum':
|
|
return 'select';
|
|
|
|
case 'multiselect':
|
|
return 'multiselect';
|
|
|
|
case 'integer':
|
|
case 'number':
|
|
case 'float':
|
|
return 'number';
|
|
|
|
case 'timestamp':
|
|
return 'datetime-local';
|
|
|
|
case 'date':
|
|
return 'date';
|
|
|
|
case 'time':
|
|
return 'time';
|
|
|
|
case 'checkbox':
|
|
case 'boolean':
|
|
return 'checkbox';
|
|
|
|
case 'email':
|
|
return 'email';
|
|
|
|
case 'url':
|
|
return 'url';
|
|
|
|
case 'password':
|
|
return 'password';
|
|
|
|
case 'file':
|
|
return 'file';
|
|
|
|
case 'readonly':
|
|
return 'text'; // Default to text for readonly, but should be rendered as readonly
|
|
|
|
default:
|
|
// Default fallback to text input
|
|
return 'text';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Determines if an attribute type should render as a textarea
|
|
*/
|
|
export function isTextareaType(attributeType: AttributeType): boolean {
|
|
return attributeType === 'textarea';
|
|
}
|
|
|
|
/**
|
|
* Determines if an attribute type should render as a select dropdown
|
|
*/
|
|
export function isSelectType(attributeType: AttributeType): boolean {
|
|
return attributeType === 'select' || attributeType === 'enum';
|
|
}
|
|
|
|
/**
|
|
* Determines if an attribute type should render as a multiselect
|
|
*/
|
|
export function isMultiselectType(attributeType: AttributeType): boolean {
|
|
return attributeType === 'multiselect';
|
|
}
|
|
|
|
/**
|
|
* Determines if an attribute type should render as a multilingual field
|
|
*/
|
|
export function isMultilingualType(attributeType: AttributeType): boolean {
|
|
return attributeType === 'multilingual';
|
|
}
|
|
|
|
/**
|
|
* Determines if an attribute type should render as a checkbox
|
|
*/
|
|
export function isCheckboxType(attributeType: AttributeType): boolean {
|
|
return attributeType === 'checkbox' || attributeType === 'boolean';
|
|
}
|
|
|
|
/**
|
|
* Determines if an attribute type should render as a file input
|
|
*/
|
|
export function isFileType(attributeType: AttributeType): boolean {
|
|
return attributeType === 'file';
|
|
}
|
|
|
|
/**
|
|
* Determines if an attribute type should render as a number input
|
|
*/
|
|
export function isNumberType(attributeType: AttributeType): boolean {
|
|
return attributeType === 'integer' || attributeType === 'number' || attributeType === 'float';
|
|
}
|
|
|
|
/**
|
|
* Determines if an attribute type should render as a date/time input
|
|
*/
|
|
export function isDateTimeType(attributeType: AttributeType): boolean {
|
|
return attributeType === 'timestamp' || attributeType === 'date' || attributeType === 'time';
|
|
}
|
|
|
|
/**
|
|
* Gets the default value for an attribute type
|
|
*/
|
|
export function getDefaultValueForType(attributeType: AttributeType): any {
|
|
if (isCheckboxType(attributeType)) {
|
|
return false;
|
|
}
|
|
if (isMultiselectType(attributeType)) {
|
|
return [];
|
|
}
|
|
if (isMultilingualType(attributeType)) {
|
|
return { en: '' };
|
|
}
|
|
if (isNumberType(attributeType)) {
|
|
return 0;
|
|
}
|
|
return '';
|
|
}
|