0.1.136 • Published 2 days ago

@galadrim/galadmin v0.1.136

Weekly downloads
-
License
ISC
Repository
github
Last release
2 days ago

Galadmin

Galadmin is a tool that let you setup a pretty back-office in minutes. It works with any MySQL database.

Quick start

npm install @galadrim/galadmin

Integration in a NestJS app

Put this piece of code in your src/main.ts file:

import galadmin from '@galadrim/galadmin';
import { Config } from '@galadrim/galadmin/dist/types/config';

const adminConfig: Config = { ... }

app.getHttpAdapter().use('/admin', galadmin(adminConfig));

If you are using Prisma ORM, add the following code to your schema.prisma. Galadmin will create a table in your database, and Prisma won't be able to perform migrations correctly if we don't specify it.

With PostgreSQL

model galadmin_sessions {
  sid    String   @id @db.VarChar(128)
  sess   Json
  expire DateTime
}

With MySQL

model galadmin_sessions {
  session_id String  @id @db.VarChar(128)
  expires    Int     @db.UnsignedInt
  data       String? @db.MediumText
}

Integration in an Express app

const galadmin = require("@galadrim/galadmin").default;

app.use("/admin", galadmin(adminConfig));

What is adminConfig?

adminConfig is the object that contains all the configuration information about your back-office. Its properties are listed below.

Minimal example

const adminConfig = {
  name: "Mon projet",
  sessionSecret: "chapeaumelon",
  auth: {
    username: "user",
    password: "password",
  },
  postgresql: {
    host: "abc.example.com",
    user: "root",
    password: "password",
    database: "monprojet",
  },
  // mysql: {
  //   host: "abc.example.com",
  //   user: "root",
  //   password: "password",
  //   database: "monprojet",
  // },
  views: [
    {
      type: "table",
      label: "Fruits",
      tableName: "fruits",
      columns: [
        {
          label: "Nom",
          name: "fruitName",
        },
        {
          label: "Acidité",
          name: "acidity",
        },
      ],
    },
  ],
};

Configuration

const adminConfig = {
  /** Nom du projet (OBLIGATOIRE) */
  name: "Mon projet",

  /** Chaîne de caractères aléatoires qui permet de chiffrer les cookies de session (OBLIGATOIRE) */
  sessionSecret: "chapeaumelon",

  /** Identifiants permettant d'accéder au back-office (OBLIGATOIRE) */
  auth: {
    /** Nom d'utilisateur */
    username: "user",

    /** Password */
    password: "password",
  },

  /** Identifiants de connexion à la base de données (OBLIGATOIRE) */
  postgresql: {
    host: "abc.example.com",
    user: "root",
    password: "password",
    database: "monprojet",
  },
  // mysql: {
  //   host: "abc.example.com",
  //   user: "root",
  //   password: "password",
  //   database: "monprojet",
  // },

  /** Clé API Google Maps pour les champs adresses et l'affichage de cartes */
  googleMapsKey: "______",

  /** Désactiver la sélection multiple dans les vues de type table */
  hideMultiselect: true,

  /** Cache l'inscription Made with love by Galadrim */
  hideBranding: true,

  views: [
    {
      /** Vue de type "table" */
      type: "table",

      /** Nom affiché de la vue */
      label: string,

      /** Icône FontAwesome de la vue dans le menu. user affiche l'icône fa-user. */
      icon: "user",

      /** Nom de la table MySQL */
      tableName: "users",

      /** Nombre de résultats par page */
      limit: 100,

      /**
       * Ces champs permettent de personnaliser la requête MySQL qui gère l'affichage de la table.
       * Ils sont tous optionnels.
       *
       * SELECT {selectExpression} FROM {tableName} {join} WHERE {filters} GROUP BY {groupBy} ORDER BY {orderBy} {desc ? "DESC" : ""}
       */
      selectExpression: "*, MAX(age) AS maxAge",
      join: "JOIN activities ON users.activity_id = activities.id",
      groupBy: "activity_id",
      orderBy: "maxAge",
      isDesc: true,
      filters: "age < 50",

      /** Lorsque notClickable est à true, les résultats ne sont pas cliquables. (default: false) */
      notClickable: true,

      /** Rendre possible de créer des enregistrements (default: false) */
      canCreate: true,

      /** Groupe nominal "un nouvel élément" */
      aNewSingular: "un nouvel utilisateur",

      /** Rendre possible de supprimer des enregistrements (default: true) */
      canDelete: true,

      /** Rendre possible de modifier des enregistrements (default: true) */
      canEdit: true,

      /** URL appelée en POST lors de la création d'un nouvel élément, avec l'ID de l'élément créé */
      createCallback: "https://myapi.com/createCallback",

      editCallback: "https://myapi.com/editCallback",
      deleteCallback: "https://myapi.com/deleteCallback",

      columns: [
        {
          /** Nom affiché de la colonne (OBLIGATOIRE) */
          label: "Poids",

          /** Nom de la colonne dans la table MySQL */
          name: "weight",

          /** Formatter la valeur avant de l'afficher */
          formatValue: (user) => `${user.weight} kg`,

          /** Masquer la colonne dans la liste des résultats et ne l'afficher que dans le détail (default: false) */
          hideInTable: true,
        },
      ],
      subviews: [],
      recordViewPanels: [],
    },
  ],
};

File upload on S3

Different column types exists, one of them is the FileColumn, allowing the upload of a file onto AWS S3. A basic configuration would be as follow:

...
  columns: [{
    label: 'Image',
    name: 'imageUrl',
    dataType: 'file',
    s3Config: {
      host: process.env.AWS_S3_HOST,
      accessKeyId: process.env.AWS_ACCESS_KEY_ID,
      secretAccessKey: process.env.AWS_SECRET_KEY,
      bucket: process.env.AWS_S3_PODCAST_BUCKET_NAME,
      /** Optional, only needed when your bucket isn't public and you need to generate a signed URL */
      signedUrlNeeded: true,
      /** Optional, only needed when your bucket isn't public and you need to generate a signed URL */
      region: 'eu-west-3',
    },
  }]

File upload on a remote server (via SFTP)

It is possible to use a FileColumn to allow upload to a remote server via SFTP. A basic configuration would be as follow:

...
  columns: [{
    label: 'Image',
    name: 'imageUrl',
    dataType: 'file',
    publicPath: '/home/ubuntu/project/public',
    subdirectory: 'img',
    sftpConfig: {
      host: process.env.SFTP_HOST,
      user: process.env.SFTP_USER,
      password: process.env.SFTP_PASSWORD,
    },
  }]
0.1.136

2 days ago

0.1.135

4 days ago

0.1.134

5 days ago

0.1.133

5 days ago

0.1.132

6 days ago

0.1.129

7 days ago

0.1.128

7 days ago

0.1.127

7 days ago

0.1.131

7 days ago

0.1.130

7 days ago

0.1.125

17 days ago

0.1.126

17 days ago

0.1.124

18 days ago

0.1.121

1 month ago

0.1.122

1 month ago

0.1.120

1 month ago

0.1.119

1 month ago

0.1.118

1 month ago

0.1.117

1 month ago

0.1.116

1 month ago

0.1.115

2 months ago

0.1.114

2 months ago

0.1.113

2 months ago

0.1.112

2 months ago

0.1.111

2 months ago

0.1.110

2 months ago

0.1.109

2 months ago

0.1.108

2 months ago

0.1.106

2 months ago

0.1.105

2 months ago

0.1.104

2 months ago

0.1.103

2 months ago

0.1.102

2 months ago

0.1.101

2 months ago

0.1.100

2 months ago

0.1.97

2 months ago

0.1.98

2 months ago

0.1.99

2 months ago

0.1.94

2 months ago

0.1.90

3 months ago

0.1.91

3 months ago

0.1.92

2 months ago

0.1.93

2 months ago

0.1.87

3 months ago

0.1.88

3 months ago

0.1.89

3 months ago

0.1.86

3 months ago

0.1.85

3 months ago

0.1.83

3 months ago

0.1.84

3 months ago

0.1.81

3 months ago

0.1.82

3 months ago

0.1.80

3 months ago

0.1.79

3 months ago

0.1.75

4 months ago

0.1.76

4 months ago

0.1.77

4 months ago

0.1.78

4 months ago

0.1.74

4 months ago

0.1.71

4 months ago

0.1.72

4 months ago

0.1.73

4 months ago

0.1.68

4 months ago

0.1.69

4 months ago

0.1.65

4 months ago

0.1.64

4 months ago

0.1.63

4 months ago

0.1.61

4 months ago

0.1.62

4 months ago

0.1.53

7 months ago

0.1.54

7 months ago

0.1.55

6 months ago

0.1.56

6 months ago

0.1.57

6 months ago

0.1.58

6 months ago

0.1.59

6 months ago

0.1.41

8 months ago

0.1.43

8 months ago

0.1.44

8 months ago

0.1.45

8 months ago

0.1.46

7 months ago

0.1.47

7 months ago

0.1.48

7 months ago

0.1.40

8 months ago

0.1.38

9 months ago

0.1.33

10 months ago

0.1.34

9 months ago

0.1.35

9 months ago

0.1.36

9 months ago

0.1.37

9 months ago

0.1.60

6 months ago

0.1.30

11 months ago

0.1.31

11 months ago

0.1.32

10 months ago

0.1.28

11 months ago

0.1.29

11 months ago

0.2.1

11 months ago

0.2.0

11 months ago

0.2.3

11 months ago

0.2.2

11 months ago

0.2.5

11 months ago

0.2.4

11 months ago

0.1.27

11 months ago

0.1.23

1 year ago

0.1.24

12 months ago

0.1.25

12 months ago

0.1.26

12 months ago

0.1.20

1 year ago

0.1.21

1 year ago

0.1.22

1 year ago

0.1.18

1 year ago

0.1.19

1 year ago

0.1.12

1 year ago

0.1.13

1 year ago

0.1.14

1 year ago

0.1.9

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.3

2 years ago

0.1.6

2 years ago

0.0.106

2 years ago

0.0.108

2 years ago

0.0.107

2 years ago

0.1.0

2 years ago

0.1.2

2 years ago

0.0.105

2 years ago

0.0.104

2 years ago

0.0.103

2 years ago

0.0.102

2 years ago

0.0.101

2 years ago

0.0.100

2 years ago

0.0.97

2 years ago

0.0.98

2 years ago

0.0.99

2 years ago

0.0.84

2 years ago

0.0.85

2 years ago

0.0.86

2 years ago

0.0.87

2 years ago

0.0.88

2 years ago

0.0.89

2 years ago

0.0.80

2 years ago

0.0.81

2 years ago

0.0.82

2 years ago

0.0.83

2 years ago

0.0.73

2 years ago

0.0.74

2 years ago

0.0.75

2 years ago

0.0.76

2 years ago

0.0.77

2 years ago

0.0.78

2 years ago

0.0.79

2 years ago

0.0.70

2 years ago

0.0.71

2 years ago

0.0.72

2 years ago

0.0.62

2 years ago

0.0.63

2 years ago

0.0.64

2 years ago

0.0.65

2 years ago

0.0.66

2 years ago

0.0.67

2 years ago

0.0.60

2 years ago

0.0.61

2 years ago

0.0.59

2 years ago

0.0.95

2 years ago

0.0.96

2 years ago

0.0.57

2 years ago

0.0.58

2 years ago

0.0.90

2 years ago

0.0.91

2 years ago

0.0.92

2 years ago

0.0.93

2 years ago

0.0.94

2 years ago

0.0.47

2 years ago

0.0.53

2 years ago

0.0.54

2 years ago

0.0.55

2 years ago

0.0.56

2 years ago

0.0.48

2 years ago

0.0.49

2 years ago

0.0.46

3 years ago

0.0.41

3 years ago

0.0.42

3 years ago

0.0.43

3 years ago

0.0.44

3 years ago

0.0.45

3 years ago

0.0.40

3 years ago

0.0.39

3 years ago

0.0.37

3 years ago

0.0.38

3 years ago

0.0.32

3 years ago

0.0.33

3 years ago

0.0.34

3 years ago

0.0.35

3 years ago

0.0.36

3 years ago

0.0.31

3 years ago

0.0.30

3 years ago

0.0.26

3 years ago

0.0.27

3 years ago

0.0.28

3 years ago

0.0.29

3 years ago

0.0.20

3 years ago

0.0.21

3 years ago

0.0.22

3 years ago

0.0.23

3 years ago

0.0.24

3 years ago

0.0.25

3 years ago

0.0.19

3 years ago

0.0.18

3 years ago

0.0.17

3 years ago

0.0.10

3 years ago

0.0.11

3 years ago

0.0.12

3 years ago

0.0.13

3 years ago

0.0.14

3 years ago

0.0.15

3 years ago

0.0.9

3 years ago

0.0.16

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago