diff --git a/app/models/test.ts b/app/models/test.ts index 425a462..b3e7659 100644 --- a/app/models/test.ts +++ b/app/models/test.ts @@ -7,8 +7,8 @@ export default class Test extends BaseModel { @column({ isPrimary: true }) declare id: number - // @column() - // declare stringArrayTest: string[] + @column() + declare stringArrayTest: string[] @column() declare freeText: string diff --git a/app/test_adomin_config.ts b/app/test_adomin_config.ts index 796b043..922a563 100644 --- a/app/test_adomin_config.ts +++ b/app/test_adomin_config.ts @@ -57,18 +57,18 @@ export const PROFILE_CONFIG = createModelViewConfig(() => Profile, { export const TEST_CONFIG = createModelViewConfig(() => Test, { label: 'Test', columns: { - // stringArrayTest: { type: 'array' }, - // freeText: { type: 'string', label: 'Texte libre' }, - // stringTest: { - // nullable: true, - // type: 'enum', - // label: 'Test select', - // options: [ - // { label: '(Non renseigné)', value: null }, - // { label: 'Salut', value: 'hello' }, - // { label: 'Au revoir', value: 'bye' }, - // ], - // }, + stringArrayTest: { type: 'array' }, + freeText: { type: 'string', label: 'Texte libre' }, + stringTest: { + nullable: true, + type: 'enum', + label: 'Test enum', + options: [ + { label: '(Non renseigné)', value: null }, + { label: 'Salut', value: 'hello' }, + { label: 'Au revoir', value: 'bye' }, + ], + }, dateTest: { type: 'date', subType: 'date', defaultValue: { mode: 'now', plusDays: 2 } }, datetimeTest: { type: 'date', subType: 'datetime', defaultValue: { mode: 'now', plusDays: 2 } }, numberTest: { type: 'number' }, diff --git a/database/migrations/1697188415177_tests.ts b/database/migrations/1697188415177_tests.ts index 40f179d..9de84f5 100644 --- a/database/migrations/1697188415177_tests.ts +++ b/database/migrations/1697188415177_tests.ts @@ -18,7 +18,7 @@ export default class extends BaseSchema { table.string('file_url') // specific to postgresql - // table.specificType('string_array_test', 'text[]').defaultTo('{}') + table.specificType('string_array_test', 'text[]').defaultTo('{}') table.integer('user_id').unsigned().references('users.id').onDelete('CASCADE') diff --git a/docs/content/docs/backend/views/models/_index.md b/docs/content/docs/backend/views/models/_index.md index 61c0a4b..d3a9763 100644 --- a/docs/content/docs/backend/views/models/_index.md +++ b/docs/content/docs/backend/views/models/_index.md @@ -148,7 +148,7 @@ queryBuilderCallback: (q) => { ### [Date field](/adomin/docs/backend/views/models/date/) -### Enum field +### [Enum field](/adomin/docs/backend/views/models/enum/) ### File field diff --git a/docs/content/docs/backend/views/models/enum/_index.md b/docs/content/docs/backend/views/models/enum/_index.md new file mode 100644 index 0000000..498afdb --- /dev/null +++ b/docs/content/docs/backend/views/models/enum/_index.md @@ -0,0 +1,40 @@ +--- +weight: 5 +title: 'Enum field' +--- + +# Enum field + +{{< br >}} + +In the table page, an enum field will look like this + +![field image](/adomin/images/models/enum/table_enum.png) + +In the create / edit page + +![edit field image](/adomin/images/models/enum/enum.png) + +## Config + +### options + +Options for the select component + +example: + +```ts +{ + type: 'enum', + label: 'Test enum', + options: [ + { label: '(Non renseigné)', value: null }, + { label: 'Salut', value: 'ref_1' }, + { label: 'Au revoir', value: 'ref_2' }, + ], +} +``` + +### defaultValue + +Optionnal, a static default value to show on the creation form diff --git a/docs/content/docs/frontend/deployment/_index.md b/docs/content/docs/frontend/deployment/_index.md new file mode 100644 index 0000000..26ad68a --- /dev/null +++ b/docs/content/docs/frontend/deployment/_index.md @@ -0,0 +1,132 @@ +weight: 3 +title: 'Deployment' + +--- + +# Frontend deployment + +{{< br >}} + +To deploy the Adomin frontend, you will need to: + +- run `yarn build` with correct VITE_API_URL env variable set +- copy dist folder to your static files service +- serve those files with a rule for SPAs (e.g. serving the index.html on 404) + +## S3 / Cloudfront + +```fish +# copy dist files into your s3 bucket +aws s3 sync ./dist s3://your-s3-bucket-name/ + +# invalidate cloudfront distribution to serve the new files +aws cloudfront create-invalidation --distribution-id YOUR_DISTRIB_ID --paths "/*" +``` + +### Github action for S3 / Cloudfront + +```yml +name: Deploy staging ⚙️ +on: + push: + branches: + - does-not-exist # replace by e.g: staging + +jobs: + back-office: + runs-on: ubuntu-latest + env: + VITE_API_URL: https://api.staging.your-own-domain.fr/ # replace by your API url + steps: + - uses: actions/checkout@v4 + - name: Install dependencies + run: yarn + - name: Build + run: yarn build + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v2 + with: + # you will have to create AWS_ACCESS_KEY and AWS_SECRET_KEY secrets in your repository settings + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }} + aws-region: eu-west-3 + - name: Deploy + run: aws s3 sync ./dist s3://your-s3-bucket-name/ # replace by your s3 bucket name + - name: Invalidate dashboard cloudfront + run: aws cloudfront create-invalidation --distribution-id YOUR_DISTRIB_ID --paths "/*" # replace by your cloudfront distribution id +``` + +## Caddy + +Example of Caddy config to serve a SPA + +``` +example.com { + root * /usr/share/caddy/frontend + file_server + try_files {path} {path}/ /index.html +} +``` + +### Github action for Caddy + +This github action is taken from a project that uses [Galacrypt](https://github.com/galadrimteam/galacrypt) to encrypt/decrypt the + +```yml +name: Deploy staging ⚙️ +on: + push: + branches: + - does-not-exist # replace by e.g: staging + +jobs: + frontend: + runs-on: ubuntu-latest + env: + VITE_API_URL: https://api.staging.your-own-domain.fr/ # replace by your API url + SERVER_IP: 1.2.3.4 # replace by your server IP + KEY_PATH: ./ssh_keys/staging/id_ed25519 # do not commit/push this file directly + SSH_USER: YOUR_SSH_USER # replace by your ssh user + SSH_PARAMS: -i ./ssh_keys/staging/id_ed25519 YOUR_SSH_USER@1.2.3.4 # replace dummy user / ip + + steps: + - name: Checkout source code + uses: actions/checkout@v4 + + - name: Use Node.js + uses: actions/setup-node@v4 + with: + node-version: '20.x' + cache: 'yarn' + + - name: Dependencies installation + run: yarn + + - name: Galacrypt decrypt # used to decrypt ssh key, you will have to create GALACRYPT_KEY in your repository secrets + run: yarn galacrypt use ${{ secrets.GALACRYPT_KEY }} && yarn galacrypt decrypt + + - name: Generate build + run: yarn build + + - name: Generate frontend zip + run: cd dist && zip -r ../frontend.zip . + + - name: Setup SSH + run: | + mkdir -p ~/.ssh + ssh-keyscan $SERVER_IP 2>/dev/null > ~/.ssh/known_hosts + chmod 600 $KEY_PATH + + - name: Copy files + run: scp -i $KEY_PATH ./frontend.zip $SSH_USER@$SERVER_IP:/home/$SSH_USER/frontend.zip + + - name: Unzip + run: ssh $SSH_PARAMS "cd /home/$SSH_USER/ && rm -rf front-build && mkdir front-build && mv frontend.zip front-build/ && cd front-build && unzip frontend.zip && rm frontend.zip" + + - name: Move website files + run: ssh $SSH_PARAMS "cd /home/$SSH_USER/ && (sudo mv /usr/share/caddy/frontend old_frontend || echo 'skipping mv old_frontend') && sudo mv front-build /usr/share/caddy/frontend && sudo rm -rf old_frontend" +``` + +## Nginx + +I don't want to deal with nginx anymore, but if you want to, you can find inspiration [here](https://sdickinson.com/nginx-config-for-single-page-applications/) diff --git a/docs/content/docs/frontend/routing/_index.md b/docs/content/docs/frontend/routing/_index.md index 9fe29b3..b6dc6e2 100644 --- a/docs/content/docs/frontend/routing/_index.md +++ b/docs/content/docs/frontend/routing/_index.md @@ -102,5 +102,5 @@ export const adominRoutes = createBrowserRouter([ , -}; +} ``` diff --git a/docs/content/docs/frontend/setup/_index.md b/docs/content/docs/frontend/setup/_index.md index f88a718..d7a323f 100644 --- a/docs/content/docs/frontend/setup/_index.md +++ b/docs/content/docs/frontend/setup/_index.md @@ -21,10 +21,20 @@ git clone https://github.com/galadrimteam/adomin-frontend.git cd adomin-frontend && yarn ``` -- verify that the `VITE_API_URL` variable in the .env points to your backend (by default it's `http://localhost:3333`) +- check that the `VITE_API_URL` is set to your backend URL - start the `vite` server ```fish yarn dev ``` + +## Configuration + +The real configurations are on the backend side (to set which tables to show, permissions, etc, etc), for more infos [check this](/adomin/docs/backend/configuration/) + +## Missing features + +If some features that you would like to have in your backoffice are not implemented, fear not, you can just edit the code, it's yours 🤭 + +If afterwards you would like to make a contribution to the official Adomin code base, you can create a pull request on [this repo](https://github.com/galadrimteam/adomin-frontend) diff --git a/docs/static/images/models/enum/enum.png b/docs/static/images/models/enum/enum.png new file mode 100644 index 0000000..5ad8d16 Binary files /dev/null and b/docs/static/images/models/enum/enum.png differ diff --git a/docs/static/images/models/enum/table_enum.png b/docs/static/images/models/enum/table_enum.png new file mode 100644 index 0000000..1c66f39 Binary files /dev/null and b/docs/static/images/models/enum/table_enum.png differ