diff --git a/app/adomin/fields.types.ts b/app/adomin/fields.types.ts index 33af0d7..8e52ab5 100644 --- a/app/adomin/fields.types.ts +++ b/app/adomin/fields.types.ts @@ -39,15 +39,17 @@ export interface AdominNumberFieldConfig extends AdominBaseFieldConfig { type: 'number' /** - * passed in number input component in the frontend + * Minimum value for the number */ min?: number /** - * passed in number input component in the frontend + * Maximum value for the number */ max?: number /** * passed in number input component in the frontend + * e.g. 0.01 if you want to allow 2 decimals + * @default 1 */ step?: number /** @@ -86,11 +88,15 @@ export interface AdominStringFieldConfig extends AdominBaseFieldConfig { type: 'string' /** - * If true, returns *** to the frontend, on create/update hash the password, etc... + * If true, in order to not leak the password hash, returns '***' to the frontend + * on create/update, will work as expected (run beforeSave hooks) + * e.g. will hash the password if your model uses the `withAuthFinder` mixin + * @default false */ isPassword?: boolean /** * If true, add basic email validation on the backend + * @default false */ isEmail?: boolean /** diff --git a/docs/content/docs/backend/views/models/_index.md b/docs/content/docs/backend/views/models/_index.md index ebd3e33..59f1dc7 100644 --- a/docs/content/docs/backend/views/models/_index.md +++ b/docs/content/docs/backend/views/models/_index.md @@ -9,6 +9,8 @@ title: 'Model views' Model views allows to see, filter, download extractions, create and update adonis models. +![Model view](/adomin/images/models/model_view.png) + ## Config To declare a model view page, you will need to add a `ModelConfig` object inside the `views` array of the `app/adomin/config/adomin_config.ts` file. @@ -138,7 +140,9 @@ queryBuilderCallback: (q) => { ### [String field](/adomin/docs/backend/views/models/string/) -### Number field +### [Number field](/adomin/docs/backend/views/models/number/) + +### [Bitset field](/adomin/docs/backend/views/models/number/bitset/) ### Boolean field diff --git a/docs/content/docs/backend/views/models/number/_index.md b/docs/content/docs/backend/views/models/number/_index.md new file mode 100644 index 0000000..fb02edc --- /dev/null +++ b/docs/content/docs/backend/views/models/number/_index.md @@ -0,0 +1,52 @@ +--- +weight: 2 +title: 'Number field' +--- + +# Number field + +{{< br >}} + +In the table page, a number field will look like this + +![field image](/adomin/images/models/table_number.png) + +In the create / edit page + +![edit field image](/adomin/images/models/number.png) + +## Config + +### min + +Optionnal, minimum value for the number + +### max + +Optionnal, maximum value for the number + +### step + +Optionnal, step to use in the HTML number input type field + +e.g. `0.01` if you want to allow 2 decimals + +By default only allows integers: `step = 1` + +### defaultValue + +Optionnal, a static number default value to show on the creation form + +### valueDisplayTemplate + +Optionnal, a string that work as a template to customize the value displayed in the table + +You can put whatever you want in the string as long as you put `{{value}}` somewhere + +e.g. `"{{value}} €"` + +### variant + +Optionnal, use a number component variant: + +- for now only [bitset](/adomin/docs/backend/views/models/number/bitset/) exists diff --git a/docs/content/docs/backend/views/models/number/bitset/_index.md b/docs/content/docs/backend/views/models/number/bitset/_index.md new file mode 100644 index 0000000..dc4c83e --- /dev/null +++ b/docs/content/docs/backend/views/models/number/bitset/_index.md @@ -0,0 +1,72 @@ +--- +weight: 1 +title: 'Bitset field' +--- + +# Bitset field + +{{< br >}} + +In the table page, a bitset number field will look like this + +![field image](/adomin/images/models/table_bitset.png) + +In the create / edit page + +![edit field image](/adomin/images/models/bitset.png) + +## Config + +Inside the number field config, you must pass the bitset config like this + +```ts +{ + type: 'number', + // ... + variant: { + type: 'bitset', + bitsetValues: {}, + bitsetLabels: {}, + } +} +``` + +### bitsetValues + +Values for the bitset + +```ts +{ [K in string]: number } +``` + +e.g. + +```ts +{ 'DEFAULT': 0b0, 'ROLE1': 0b1, 'ROLE2': 0b10, 'ROLE3': 0b100 } +``` + +With each number value representing a specific bit. + +With the example config: + +- ROLE1 represents the first bit of the number (the least significant bit 0b1) +- ROLE2 the 2nd bit (the 2nd least significant bit 0b01) +- ROLE3 the 3rd bit (the 3rd least significant bit 0b001) + +So if the model column value is the integer 3 (0b011) + +the model instance will have ROLE1 and ROLE2, but not ROLE3 + +### bitsetLabels + +Optionnal, labels for the bitset + +```ts +{ [K in string]: string } +``` + +e.g. + +```ts +{ 'DEFAULT': 'Utilisateur', 'ROLE1': 'Role 1', 'ROLE2': 'Role 2', 'ROLE3': 'Role 3' } +``` diff --git a/docs/content/docs/backend/views/models/string/_index.md b/docs/content/docs/backend/views/models/string/_index.md new file mode 100644 index 0000000..711073d --- /dev/null +++ b/docs/content/docs/backend/views/models/string/_index.md @@ -0,0 +1,40 @@ +--- +weight: 1 +title: 'String field' +--- + +# String field + +{{< br >}} + +In the table page, a string field will look like this + +![field image](/adomin/images/models/table_email.png) + +In the create / edit page + +![edit field image](/adomin/images/models/email.png) + +## Config + +### isPassword + +Optionnal, if true, in order to not leak the password hash, returns '\*\*\*' to the frontend. +On create/update, will work as expected (run beforeSave hooks) +e.g. will hash the password if your model uses the `withAuthFinder` mixin + +### isEmail + +Optionnal, if true, add basic email validation on the backend + +### defaultValue + +Optionnal, a static string default value to show on the creation form + +### valueDisplayTemplate + +Optionnal, a string that work as a template to customize the value displayed in the table + +You can put whatever you want in the string as long as you put `{{value}}` somewhere + +e.g. `"{{value}} €"` diff --git a/docs/static/images/models/bitset.png b/docs/static/images/models/bitset.png new file mode 100644 index 0000000..90ccecf Binary files /dev/null and b/docs/static/images/models/bitset.png differ diff --git a/docs/static/images/models/number.png b/docs/static/images/models/number.png new file mode 100644 index 0000000..8fdfbaf Binary files /dev/null and b/docs/static/images/models/number.png differ diff --git a/docs/static/images/models/table_bitset.png b/docs/static/images/models/table_bitset.png new file mode 100644 index 0000000..4d5dc95 Binary files /dev/null and b/docs/static/images/models/table_bitset.png differ diff --git a/docs/static/images/models/table_number.png b/docs/static/images/models/table_number.png new file mode 100644 index 0000000..18fd614 Binary files /dev/null and b/docs/static/images/models/table_number.png differ