Skip to content

Commit

Permalink
docs: number field
Browse files Browse the repository at this point in the history
  • Loading branch information
mle-moni committed May 7, 2024
1 parent 43f8ee7 commit 9f86660
Show file tree
Hide file tree
Showing 9 changed files with 178 additions and 4 deletions.
12 changes: 9 additions & 3 deletions app/adomin/fields.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
/**
Expand Down Expand Up @@ -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
/**
Expand Down
6 changes: 5 additions & 1 deletion docs/content/docs/backend/views/models/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand Down
52 changes: 52 additions & 0 deletions docs/content/docs/backend/views/models/number/_index.md
Original file line number Diff line number Diff line change
@@ -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
72 changes: 72 additions & 0 deletions docs/content/docs/backend/views/models/number/bitset/_index.md
Original file line number Diff line number Diff line change
@@ -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' }
```
40 changes: 40 additions & 0 deletions docs/content/docs/backend/views/models/string/_index.md
Original file line number Diff line number Diff line change
@@ -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}} €"`
Binary file added docs/static/images/models/bitset.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/static/images/models/number.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/static/images/models/table_bitset.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/static/images/models/table_number.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 9f86660

Please sign in to comment.