-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
208 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
96 changes: 96 additions & 0 deletions
96
docs/src/content/docs/reference/views/models/global-actions.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
--- | ||
title: Model Global Actions | ||
sidebar: | ||
order: 1030 | ||
description: Adomin model global actions reference | ||
--- | ||
|
||
In the user interface **globalActions** are buttons that trigger an action relative to a table globally | ||
|
||
![field image](~/assets/images/reference/models/actions/global_actions.png) | ||
|
||
Here is the code needed to add those two buttons to the user interface | ||
|
||
```ts | ||
{ | ||
globalActions: [ | ||
{ | ||
name: 'add-random-idea', | ||
tooltip: 'Ajouter une idée random', | ||
icon: 'arrows-shuffle', | ||
iconColor: 'red', | ||
action: async () => { | ||
await Idea.create({ | ||
title: faker.music.songName(), | ||
description: faker.lorem.sentence(), | ||
}) | ||
|
||
return { message: 'Création effectuée' } | ||
}, | ||
}, | ||
{ | ||
name: 'delete-ideas-not-linked-to-user', | ||
tooltip: 'Supprimer les idées non liées à un utilisateur', | ||
icon: 'trash', | ||
iconColor: 'orange', | ||
action: async () => { | ||
await Idea.query().whereNull('userId').delete() | ||
|
||
return { message: 'Suppression effectuée' } | ||
}, | ||
}, | ||
] | ||
} | ||
``` | ||
|
||
## Config | ||
|
||
**globalActions** is an array of objects, each object representing an action, here are the parameters for each action | ||
|
||
### name | ||
|
||
Name of the action, this will be used to identify the action, must be unique for the model | ||
|
||
e.g. the API endpoint generated will look like this if name = 'add-random-idea' | ||
|
||
POST /adomin/api/actions/Idea/add-random-idea | ||
|
||
### tooltip | ||
|
||
Tooltip shown on the frontend, when hovering the button | ||
|
||
### icon | ||
|
||
Icon name, by default this uses Tabler icons | ||
|
||
You can browse the list of available icons at: https://tabler.io/icons | ||
|
||
### iconColor | ||
|
||
Color of the icon, this will be passed as the css color property, so you can use any valid css color | ||
|
||
### action | ||
|
||
Function to execute when the action is triggered | ||
|
||
It will be called with the http context as a parameter | ||
|
||
You are in charge of doing authorization checks if you want to restrict which backoffice users can use this action | ||
|
||
:::note | ||
If you want the frontend to show a success toast message, you can return a 200 status code with an object like this | ||
|
||
```ts | ||
return { message: 'Success message' } | ||
``` | ||
|
||
::: | ||
|
||
:::note | ||
If you want the frontend to show an error toast message, you can return a >= 400 status code with an object like this | ||
|
||
```ts | ||
return response.badRequest({ error: 'Error message' }) | ||
``` | ||
|
||
::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
docs/src/content/docs/reference/views/models/instance-actions.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
--- | ||
title: Model Instance Actions | ||
sidebar: | ||
order: 1031 | ||
description: Adomin model instance actions reference | ||
--- | ||
|
||
In the user interface **instanceActions** are buttons that trigger an action relative to a table and a specific line | ||
|
||
![field image](~/assets/images/reference/models/actions/instance_actions.png) | ||
|
||
Here is the code needed to add this button to the user interface | ||
|
||
```ts | ||
{ | ||
instanceActions: [ | ||
{ | ||
name: 'duplicate-idea', | ||
tooltip: "Dupliquer l'idée", | ||
icon: 'copy', | ||
iconColor: 'brown', | ||
action: async (ctx) => { | ||
const idea = await Idea.findOrFail(ctx.params.id) | ||
|
||
await Idea.create({ | ||
title: idea.title, | ||
description: idea.description, | ||
userId: idea.userId, | ||
}) | ||
|
||
return { message: 'Duplication effectuée' } | ||
}, | ||
}, | ||
], | ||
} | ||
``` | ||
|
||
## Config | ||
|
||
**instanceActions** is an array of objects, each object representing an action, here are the parameters for each action | ||
|
||
### name | ||
|
||
Name of the action, this will be used to identify the action, must be unique for the model | ||
|
||
e.g. the API endpoint generated will look like this if name = 'duplicate-idea', and the id of the row is 1 | ||
|
||
POST /adomin/api/actions/Idea/duplicate-idea/1 | ||
|
||
### tooltip | ||
|
||
Tooltip shown on the frontend, when hovering the button | ||
|
||
### icon | ||
|
||
Icon name, by default this uses Tabler icons | ||
|
||
You can browse the list of available icons at: https://tabler.io/icons | ||
|
||
### iconColor | ||
|
||
Color of the icon, this will be passed as the css color property, so you can use any valid css color | ||
|
||
### action | ||
|
||
Function to execute when the action is triggered | ||
|
||
It will be called with the http context as a parameter | ||
|
||
You are in charge of doing authorization checks if you want to restrict which backoffice users can use this action | ||
|
||
Your action function will receive the model instance primary key inside the `params` object like this | ||
|
||
```ts | ||
const yourActionFunction = async (ctx) => { | ||
const primaryKeyValue = ctx.params.id | ||
// do something with the primary key value | ||
return { message: '🎉' } | ||
} | ||
``` | ||
|
||
:::note | ||
If you want the frontend to show a success toast message, you can return a 200 status code with an object like this | ||
|
||
```ts | ||
return { message: 'Success message' } | ||
``` | ||
|
||
::: | ||
|
||
:::note | ||
If you want the frontend to show an error toast message, you can return a >= 400 status code with an object like this | ||
|
||
```ts | ||
return response.badRequest({ error: 'Error message' }) | ||
``` | ||
|
||
::: |