Skip to content

Commit

Permalink
wip: view docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mle-moni committed May 3, 2024
1 parent 1cec22c commit e8cd991
Show file tree
Hide file tree
Showing 8 changed files with 254 additions and 81 deletions.
1 change: 1 addition & 0 deletions app/adomin/create_model_view_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const PASSWORD_SERIALIZED_FORM = '***'

export interface ModelConfigStaticOptions {
type: 'model'
/** Name of the page that will be shown on the frontend @default Model.name */
label: string
labelPluralized: string
/** Use this if you want to add more checks to the default adomin validation
Expand Down
10 changes: 8 additions & 2 deletions docs/content/docs/backend/configuration/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ title: 'Configuration'

{{< br >}}

Now That Adomin is installed and ready (if not go [here](/adomin/docs/backend/installation)), let's add some basic configuration:
## Basic configuration

Now That Adomin is installed and ready (if not, start [here](/adomin/docs/backend/installation)), let's add some basic configuration:

- open `app/adomin/adomin_config.ts`

Expand All @@ -24,7 +26,7 @@ const USER_CONFIG = createModelViewConfig(() => User, {

export const ADOMIN_CONFIG: AdominConfig = {
title: 'Adomin',
models: [USER_CONFIG],
views: [USER_CONFIG],
}
```

Expand All @@ -44,3 +46,7 @@ const PRIMARY_KEY_DEFAULT_CONFIG: AdominNumberFieldConfig = {
```

You can overwrite this config as you please, e.g. if the primary key is a string

## Real world configuration

In a real application, your backoffice might have many pages with complex configurations, to learn what you can do with Adomin see [models views](/adomin/docs/backend/views/models)
4 changes: 4 additions & 0 deletions docs/content/docs/backend/views/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
bookCollapseSection: true
weight: 3
---
113 changes: 113 additions & 0 deletions docs/content/docs/backend/views/models/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
---
weight: 1
title: 'Model views'
---

# Model views

{{< br >}}

Model views allows to see, filter, download extractions, create and update adonis models.

## 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.

```ts
export const ADOMIN_CONFIG: AdominConfig = {
title: 'Adomin',
views: [MY_MODEL_CONFIG],
}
```

Use the `createModelViewConfig` function to create your `ModelConfig` object:

```ts
export const MY_MODEL_CONFIG = createModelViewConfig(() => MyModel, {
columns: {
title: { type: 'string', label: 'Titre' },
description: { type: 'string', label: 'Description' },
},
})
```

You need to pass a function returning your Adonis model, and an object with the adomin configuration for this model.

You can pass the following options inside the config object:

### columns

An object listing all the model properties you want to see on the frontend

See [types of fields](#types-of-fields)

### label

Name of the page that will be shown on the frontend, default to name of the model

### labelPluralized

Lets you override the default behaviour of using Adonis `string.pluralize` helper on the label: `string.pluralize(label)`

### validation

Use this if you want to add more checks to the default adomin validation
e.g. for checking that a field should exist only if another exist or so
If you want to change what is stored, or how it is stored, you will have to use _routesOverrides_ instead

### routesOverrides

Use this to overide the adomin API route for a CRUDL action
e.g. for using a custom logic for creating a resource

### staticRights

Static rights to define if some CRUDL actions are restricted for everyone for this model

### visibilityCheck

Access check function to verify if logged in user can see this model
If you want more granularity, e.g. allows Bob to see all Posts but not edit them, use `crudlRights`

### crudlRights

Granular dynamic access checks functions for each CRUDL action
For each function, if you return `hasAccess = false`, with `errorMessage = undefined`, you will have to send the error response yourself
e.g. with `response.badRequest({ error: 'oups' })`

### isHidden

Use this if you want to hide this model on the frontend.
Frontend routes for create/update/list will still be created and available, but the navbar won't show it.

⚠️ Do not see this as a protection, but rather a cosmetic feature.

If you want to protect things, use [staticRights](#staticrights), [visibilityCheck](#visibilitycheck) and [crudlRights](#crudlrights)

## Types of fields

### String field

### Number field

### Boolean field

### Date field

### Enum field

### File field

### Array field

### ForeignKey field

### BelongsTo field

### HasMany field

### HasOne field

## See the source code

[Type definitions](https://github.com/galadrimteam/adomin/blob/main/app/adomin/fields.types.ts)
39 changes: 39 additions & 0 deletions docs/content/docs/backend/views/stats/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
weight: 2
title: 'Stat views'
---

# Stat views

{{< br >}}

With Adomin, you can also easily show graphs, pie charts and other KPI visualizations.

For this, you will need to write some backend configuration, and then the adomin frontend will render your charts with [Chartkick](https://chartkick.com/react), a js chart lib that uses chart.js under the hood.

## Config

To declare a stat view page, you will need to add a `StatViewConfig` object inside the `views` array of the `app/adomin/config/adomin_config.ts` file.

```ts
export const ADOMIN_CONFIG: AdominConfig = {
title: 'Adomin',
views: [MY_STAT_VIEW_CONFIG],
}
```

## Types of charts

### Pie chart

### Bar chart

### Column chart

### Line chart

### Area chart

## See the source code

[create_stats_view_config.ts](https://github.com/galadrimteam/adomin/blob/main/app/adomin/create_stats_view_config.ts)
Loading

0 comments on commit e8cd991

Please sign in to comment.