adminforth 1.1.1 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/dist/index.js +23 -7
  2. package/dist/modules/codeInjector.js +9 -9
  3. package/dist/plugins/ForeignInlineListPlugin/index.js +2 -1
  4. package/dist/spa/spa/src/App.vue +1 -1
  5. package/dist/spa/spa/src/components/ResourceListTable.vue +363 -0
  6. package/dist/spa/spa/src/stores/core.ts +7 -9
  7. package/dist/spa/spa/src/utils.ts +2 -2
  8. package/dist/spa/spa/src/views/CreateView.vue +3 -0
  9. package/dist/spa/spa/src/views/EditView.vue +3 -0
  10. package/dist/spa/spa/src/views/ListView.vue +24 -317
  11. package/dist/spa/spa/src/views/ShowView.vue +8 -11
  12. package/index.ts +29 -11
  13. package/modules/codeInjector.ts +12 -12
  14. package/modules/styles.ts +52 -0
  15. package/package.json +1 -1
  16. package/plugins/ForeignInlineListPlugin/custom/InlineList.vue +110 -2
  17. package/plugins/ForeignInlineListPlugin/index.ts +2 -2
  18. package/spa/src/App.vue +1 -1
  19. package/spa/src/components/ResourceListTable.vue +363 -0
  20. package/spa/src/stores/core.ts +7 -9
  21. package/spa/src/utils.ts +2 -2
  22. package/spa/src/views/CreateView.vue +3 -0
  23. package/spa/src/views/EditView.vue +3 -0
  24. package/spa/src/views/ListView.vue +24 -317
  25. package/spa/src/views/ShowView.vue +8 -11
  26. package/types/AdminForthConfig.ts +79 -23
  27. package/documentation/README.md +0 -41
  28. package/documentation/babel.config.js +0 -3
  29. package/documentation/blog/2019-05-28-first-blog-post.md +0 -12
  30. package/documentation/blog/2019-05-29-long-blog-post.md +0 -44
  31. package/documentation/blog/2021-08-01-mdx-blog-post.mdx +0 -20
  32. package/documentation/blog/2021-08-26-welcome/docusaurus-plushie-banner.jpeg +0 -0
  33. package/documentation/blog/2021-08-26-welcome/index.md +0 -25
  34. package/documentation/blog/authors.yml +0 -17
  35. package/documentation/blog/tags.yml +0 -16
  36. package/documentation/docs/Getting Started.md +0 -374
  37. package/documentation/docs/Glossary.md +0 -37
  38. package/documentation/docs/image.png +0 -0
  39. package/documentation/docusaurus.config.ts +0 -171
  40. package/documentation/package-lock.json +0 -14655
  41. package/documentation/package.json +0 -51
  42. package/documentation/sidebars.ts +0 -51
  43. package/documentation/src/components/HomepageFeatures/index.tsx +0 -68
  44. package/documentation/src/components/HomepageFeatures/styles.module.css +0 -11
  45. package/documentation/src/css/custom.css +0 -30
  46. package/documentation/src/pages/index.module.css +0 -24
  47. package/documentation/src/pages/index.tsx +0 -43
  48. package/documentation/src/pages/markdown-page.md +0 -7
  49. package/documentation/static/.nojekyll +0 -0
  50. package/documentation/static/CNAME +0 -1
  51. package/documentation/static/img/css.png +0 -0
  52. package/documentation/static/img/db.png +0 -0
  53. package/documentation/static/img/db2.png +0 -0
  54. package/documentation/static/img/favicon.png +0 -0
  55. package/documentation/static/img/gen.sh +0 -24
  56. package/documentation/static/img/logo.svg +0 -19
  57. package/documentation/static/img/tail.png +0 -0
  58. package/documentation/static/img/vue.png +0 -0
  59. package/documentation/typedoc-plugin.mjs +0 -11
  60. /package/{styles.js → dist/modules/styles.js} +0 -0
@@ -1,374 +0,0 @@
1
-
2
- # Installation
3
-
4
- ## Prerequisites
5
-
6
- We recommend using Node v18 and higher
7
-
8
- ## Installation
9
-
10
- ```bash
11
- mkdir myadmin
12
- cd myadmin
13
- npm install adminforth
14
- ```
15
-
16
- AdminForth does not provide own HTTP server, but can add own listeners over exisitng [Express](https://expressjs.com/) server (Fastify support is planned in future). This allows to create custom APIs for backoffice in a way you know.
17
-
18
- Let's install express:
19
-
20
- ```bash
21
- npm install express@4.19.2
22
- ```
23
-
24
- For demo purposes we will use SQLite data source. You can use postgress, Mongo or Clickhouse as well.
25
-
26
-
27
- ```bash
28
- npm install better-sqlite3@10.0.0
29
- ```
30
-
31
- You can use adminforth in pure Node, but we recommend using TypeScript for better development experience.
32
-
33
- ```bash
34
- npm install typescript@5.4.5 --save-dev
35
- npm install tsx@4.11.2 --save-dev
36
- ```
37
-
38
- # Philosophy
39
-
40
- AdminForth connects to existing databases and provide a backoffice for managing data including CRUD operations, filtering, sorting, and more.
41
-
42
- Database should be already created by using any database management tool, ORM or migrator. AdminForth does not provide a way to create tables or columns in the database.
43
-
44
- Once you have a database, you pass a connection string to AdminForth and define resources(tables) and columns you would like to see in backoffice. For most DB AdminForth can guess column types and constraints (e.g. max-lenght) by connecting to DB. However you can redefine them in AdminForth configuration. Type and constraints definition are take precedence over DB metadata.
45
-
46
- Also in AdminForth you can define in "Vue" way how each field will be rendered, and create own pages e.g. Dashboards.
47
-
48
- In the demo we will create a simple database with 2 tables: `apartments` and `users`. We will just use plain SQL to create tables and insert some fake data.
49
-
50
- Users table will be used to store a credentials for login into backoffice itself.
51
-
52
- ## Possible configuration options
53
-
54
- We will use schema with different column types for apartments to show many of AdminForth features.
55
-
56
- Check [AdminForthConfig](/docs/api/type-aliases/AdminForthConfig.md) for all possible AdminForth Configs.
57
-
58
-
59
- # Setting up a demo
60
-
61
- Open `package.json`, set `type` to `module` and add `start` script:
62
-
63
- ```json
64
- {
65
- ...
66
- "type": "module",
67
- "scripts": {
68
- ...
69
- "start": "ADMINFORTH_SECRET=CHANGE_ME_IN_PRODUCTION NODE_ENV=development tsx watch index.ts"
70
- },
71
- }
72
- ```
73
-
74
-
75
- Create `index.ts` file with following content:
76
-
77
- ```typescript
78
-
79
- import betterSqlite3 from 'better-sqlite3';
80
- import express from 'express';
81
- import AdminForth from 'adminforth';
82
-
83
- const dbFile = 'test.sqlite';
84
- const db = betterSqlite3(dbFile)
85
-
86
- const tableExists = db.prepare(`SELECT name FROM sqlite_master WHERE type='table' AND name='apartments';`).get();
87
- if (!tableExists) {
88
- await db.prepare(`
89
- CREATE TABLE apartments (
90
- id VARCHAR(20) PRIMARY KEY NOT NULL,
91
- title VARCHAR(255) NOT NULL,
92
- square_meter REAL,
93
- price DECIMAL(10, 2) NOT NULL,
94
- number_of_rooms INT,
95
- description TEXT,
96
- property_type VARCHAR(255) DEFAULT 'apartment',
97
- listed BOOLEAN DEFAULT FALSE,
98
- created_at TIMESTAMP,
99
- user_id VARCHAR(255)
100
- );`).run();
101
-
102
- await db.prepare(`
103
- CREATE TABLE users (
104
- id VARCHAR(255) PRIMARY KEY NOT NULL,
105
- email VARCHAR(255) NOT NULL,
106
- password_hash VARCHAR(255) NOT NULL,
107
- created_at VARCHAR(255) NOT NULL,
108
- role VARCHAR(255) NOT NULL
109
- );`).run();
110
-
111
- for (let i = 0; i < 50; i++) {
112
- await db.prepare(`
113
- INSERT INTO apartments (
114
- id, title, square_meter, price, number_of_rooms, description, created_at, listed, property_type
115
- ) VALUES ('${i}', 'Apartment ${i}', ${Math.random() * 100}, ${Math.random() * 10000}, ${Math
116
- .floor(Math.random() * 5) }, 'Next gen appartments', ${Date.now() / 1000 - i * 60 * 60 * 24}, ${i % 2 == 0}, ${i % 2 == 0 ? "'house'" : "'apartment'"});
117
- `).run();
118
- }
119
- }
120
-
121
- const ADMIN_BASE_URL = '';
122
-
123
- const admin = new AdminForth({
124
- baseUrl : ADMIN_BASE_URL,
125
- rootUser: {
126
- username: 'adminforth', // use these as credentials to login
127
- password: 'adminforth',
128
- },
129
- auth: {
130
- resourceId: 'users', // resource for getting user
131
- usernameField: 'email',
132
- passwordHashField: 'password_hash',
133
- },
134
- customization: {
135
- brandName: 'My Admin',
136
- datesFormat: 'D MMM YY HH:mm:ss',
137
- emptyFieldPlaceholder: '-',
138
- },
139
-
140
- dataSources: [
141
- {
142
- id: 'maindb',
143
- url: `sqlite://${dbFile}`
144
- },
145
- ],
146
- resources: [
147
- {
148
- dataSource: 'maindb',
149
- table: 'apartments',
150
- resourceId: 'apparts', // resourceId is defaulted to table name but you can change it e.g.
151
- // in case of same table names from different data sources
152
- label: 'Apartments', // label is defaulted to table name but you can change it
153
- recordLabel: (r) => `🏡 ${r.title}`,
154
- columns: [
155
- {
156
- name: 'id',
157
- label: 'Identifier', // if you wish you can redefine label
158
- showIn: ['filter', 'show'], // show in filter and in show page
159
- primaryKey: true,
160
- fillOnCreate: ({initialRecord, adminUser}) => Math.random().toString(36).substring(7), // initialRecord is values user entered, adminUser object of user who creates record
161
- },
162
- {
163
- name: 'title',
164
- required: true,
165
- showIn: ['list', 'create', 'edit', 'filter', 'show'], // the default is full set
166
- maxLength: 255, // you can set max length for string fields
167
- minLength: 3, // you can set min length for string fields
168
- },
169
- {
170
- name: 'created_at',
171
- type: AdminForth.Types.DATETIME ,
172
- allowMinMaxQuery: true,
173
- showIn: ['list', 'filter', 'show', 'edit'],
174
- fillOnCreate: ({initialRecord, adminUser}) => (new Date()).toISOString(),
175
- },
176
- {
177
- name: 'price',
178
- min: 10,
179
- max: 10000.12,
180
- allowMinMaxQuery: true, // use better experience for filtering e.g. date range, set it only if you have index on this column or if there will be low number of rows
181
- editingNote: 'Price is in USD', // you can appear note on editing or creating page
182
- },
183
- {
184
- name: 'square_meter',
185
- label: 'Square',
186
- allowMinMaxQuery: true,
187
- minValue: 1, // you can set min /max value for number fields
188
- maxValue: 1000,
189
- },
190
- {
191
- name: 'number_of_rooms',
192
- allowMinMaxQuery: true,
193
- enum: [
194
- { value: 1, label: '1 room' },
195
- { value: 2, label: '2 rooms' },
196
- { value: 3, label: '3 rooms' },
197
- { value: 4, label: '4 rooms' },
198
- { value: 5, label: '5 rooms' },
199
- ],
200
- allowCustomValue: true,
201
- },
202
- {
203
- name: 'description',
204
- sortable: false,
205
- },
206
- {
207
- name: 'property_type',
208
- enum: [{
209
- value: 'house',
210
- label: 'House'
211
- }, {
212
- value: 'apartment',
213
- label: 'Apartment'
214
- }, {
215
- value: null,
216
- label: 'Not defined'
217
- }],
218
- },
219
- {
220
- name: 'listed',
221
- required: true, // will be required on create/edit
222
- },
223
- {
224
- name: 'user_id',
225
- foreignResource: {
226
- resourceId: 'users',
227
- }
228
- }
229
- ],
230
- options: {
231
- listPageSize: 12,
232
- allowedActions:{
233
- edit: false,
234
- delete: true,
235
- show: true,
236
- filter: true,
237
- },
238
- },
239
- },
240
- {
241
- dataSource: 'maindb',
242
- table: 'users',
243
- resourceId: 'users',
244
- label: 'Users',
245
- recordLabel: (r) => `👤 ${r.email}`,
246
- columns: [
247
- {
248
- name: 'id',
249
- primaryKey: true,
250
- fillOnCreate: ({initialRecord, adminUser}) => Math.random().toString(36).substring(7),
251
- showIn: ['list', 'filter', 'show'],
252
- },
253
- {
254
- name: 'email',
255
- required: true,
256
- isUnique: true,
257
- validation: [
258
- {
259
- regExp: '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$',
260
- message: 'Email is not valid, must be in format example@test.com'
261
- },
262
- ]
263
- },
264
- {
265
- name: 'created_at',
266
- type: AdminForth.Types.DATETIME,
267
- showIn: ['list', 'filter', 'show'],
268
- fillOnCreate: ({initialRecord, adminUser}) => (new Date()).toISOString(),
269
- },
270
- {
271
- name: 'role',
272
- enum: [
273
- { value: 'superadmin', label: 'Super Admin' },
274
- { value: 'user', label: 'User' },
275
- ]
276
- },
277
- {
278
- name: 'password',
279
- virtual: true, // field will not be persisted into db
280
- required: { create: true }, // make required only on create page
281
- editingNote: { edit: 'Leave empty to keep password unchanged' },
282
- minLength: 8,
283
- type: AdminForth.Types.STRING,
284
- showIn: ['create', 'edit'], // to show field only on create and edit pages
285
- masked: true, // to show stars in input field
286
- }
287
- ],
288
- hooks: {
289
- create: {
290
- beforeSave: async ({ record, adminUser, resource }) => {
291
- record.password_hash = await AdminForth.Utils.generatePasswordHash(record.password);
292
- return { ok:true, error: false };
293
- }
294
- },
295
- edit: {
296
- beforeSave: async ({ record, adminUser, resource}) => {
297
- if (record.password) {
298
- record.password_hash = await AdminForth.Utils.generatePasswordHash(record.password);
299
- }
300
- return { ok: true, error: false }
301
- },
302
- },
303
- }
304
- },
305
- ],
306
- menu: [
307
- {
308
- label: 'Core',
309
- icon: 'flowbite:brain-solid', // any icon from iconify supported in format <setname>:<icon>, e.g. from here https://icon-sets.iconify.design/flowbite/
310
- open: true,
311
- children: [
312
- {
313
- homepage: true,
314
- label: 'Appartments',
315
- icon: 'flowbite:home-solid',
316
- resourceId: 'apparts',
317
- },
318
- ]
319
- },
320
- {
321
- type: 'gap'
322
- },
323
- {
324
- type: 'divider'
325
- },
326
- {
327
- type: 'heading',
328
- label: 'SYSTEM',
329
- },
330
- {
331
- label: 'Users',
332
- icon: 'flowbite:user-solid',
333
- resourceId: 'users',
334
- }
335
- ],
336
- })
337
-
338
-
339
- const app = express()
340
- app.use(express.json());
341
- const port = 3500;
342
-
343
- (async () => {
344
- // needed to compile SPA. Call it here or from a build script e.g. in Docker build time to reduce downtime
345
- await admin.bundleNow({ hotReload: process.env.NODE_ENV === 'development'});
346
- console.log('Bundling AdminForth done. For faster serving consider calling bundleNow() from a build script.');
347
- })();
348
-
349
-
350
- // serve after you added all api
351
- admin.express.serve(app, express)
352
- admin.discoverDatabases();
353
-
354
-
355
- app.listen(port, () => {
356
- console.log(`Example app listening at http://localhost:${port}`)
357
- console.log(`\n⚡ AdminForth is available at http://localhost:${port}${ADMIN_BASE_URL}\n`)
358
- });
359
- ```
360
-
361
-
362
- Now you can run your app:
363
-
364
- ```bash
365
- npm start
366
- ```
367
-
368
- Open http://localhost:3500 in your browser and login with credentials `adminforth` / `adminforth`.
369
-
370
- ![alt text](image.png)
371
-
372
-
373
- After Login you should see:
374
-
@@ -1,37 +0,0 @@
1
-
2
- # dataSource
3
-
4
- A DataSource is a connection to one database. Datasources has id for references from resources and URL which follows the standard URI format. For example `mysql://user:password@localhost:3306/database`.
5
- It used to:
6
-
7
- * Discover the columns in the database
8
- * Make queries to get the list and show records
9
- * Make queries to modify data
10
-
11
- There might be several datasources in the system for vairous databases e.g. One 2 Mongo DBs and 1 Postgres DB.
12
-
13
- # resource
14
-
15
- A Resource is a representation of a table or collection in AdminForth. One resource is one table in the database.
16
- It has a `name` which should match name in database, a datasource id, and a list of columns.
17
- Also it has various customization options.
18
-
19
- # column
20
-
21
- A Column is a representation of a column in a table. It has a `name` which should be equal to name in database and various configuration options.
22
-
23
- # record
24
-
25
- A record is a row in a relational database table. Or Document in document database table.
26
-
27
- # adminUser
28
-
29
- Object which represents a user who logged in to the AdminForth
30
-
31
- # hook
32
-
33
- Hook is a optional async function which allows to inject in backend logic before exuting the datasource query or after it
34
-
35
- # component
36
-
37
- Component is a Vue component which is used to add or modify UI elements in AdminForth.
Binary file
@@ -1,171 +0,0 @@
1
- import {themes as prismThemes} from 'prism-react-renderer';
2
- import type {Config} from '@docusaurus/types';
3
- import type * as Preset from '@docusaurus/preset-classic';
4
-
5
- const config: Config = {
6
- title: 'AdminForth',
7
- tagline: 'OpenSource Dashboard on Tailwind UI extendable with Vue3 ',
8
- favicon: 'img/favicon.png',
9
-
10
- // Set the production url of your site here
11
- url: 'https://adminforth.dev',
12
- // Set the /<baseUrl>/ pathname under which your site is served
13
- // For GitHub pages deployment, it is often '/<projectName>/'
14
- baseUrl: '/',
15
-
16
- // GitHub pages deployment config.
17
- // If you aren't using GitHub pages, you don't need these.
18
- organizationName: 'devforth', // Usually your GitHub org/user name.
19
- projectName: 'devforth.github.io', // Usually your repo name.
20
-
21
- onBrokenLinks: 'throw',
22
- onBrokenMarkdownLinks: 'warn',
23
-
24
- // Even if you don't use internationalization, you can use this field to set
25
- // useful metadata like html lang. For example, if your site is Chinese, you
26
- // may want to replace "en" with "zh-Hans".
27
- i18n: {
28
- defaultLocale: 'en',
29
- locales: ['en'],
30
- },
31
-
32
- presets: [
33
- [
34
- 'classic',
35
- {
36
- docs: {
37
- sidebarPath: './sidebars.ts',
38
- // Please change this to your repo.
39
- // Remove this to remove the "edit this page" links.
40
- // editUrl:
41
- // 'https://github.com/facebook/docusaurus/tree/main/packages/create-docusaurus/templates/shared/',
42
- },
43
- // blog: {
44
- // showReadingTime: true,
45
- // // Please change this to your repo.
46
- // // Remove this to remove the "edit this page" links.
47
- // // editUrl:
48
- // // 'https://github.com/facebook/docusaurus/tree/main/packages/create-docusaurus/templates/shared/',
49
- // },
50
- theme: {
51
- customCss: './src/css/custom.css',
52
- },
53
- } satisfies Preset.Options,
54
- ],
55
- ],
56
-
57
- plugins: [
58
- [
59
- "docusaurus-plugin-typedoc",
60
- {
61
- entryPoints: ["../types/AdminForthConfig.ts", "../types/FrontendAPI.ts"],
62
- plugin: ["./typedoc-plugin.mjs"],
63
- readme: "none",
64
- indexFormat: "table",
65
- disableSources: true,
66
- sidebar: { pretty: true },
67
- textContentMappings: {
68
- "title.indexPage": "TypeDoc API",
69
- "title.memberPage": "{name}",
70
- },
71
- parametersFormat: "table",
72
- enumMembersFormat: "table",
73
- },
74
- ],
75
- ],
76
-
77
- themeConfig: {
78
- // Replace with your project's social card
79
- // image: 'img/docusaurus-social-card.jpg',
80
- navbar: {
81
- title: 'AdminForth',
82
- logo: {
83
- alt: 'AdminForth Logo',
84
- src: 'img/logo.svg',
85
- },
86
- items: [
87
- {
88
- type: 'docSidebar',
89
- sidebarId: 'tutorialSidebar',
90
- position: 'left',
91
- label: 'Tutorial',
92
- },
93
- {
94
- type: 'docSidebar',
95
- sidebarId: 'apiSidebar',
96
- position: 'left',
97
- label: 'API',
98
- },
99
- // {to: '/blog', label: 'Blog', position: 'left'},
100
- {
101
- href: 'https://github.com/devforth/adminforth',
102
- label: 'GitHub',
103
- position: 'right',
104
- },
105
- ],
106
- },
107
- footer: {
108
- style: 'dark',
109
- links: [
110
- {
111
- title: 'Docs',
112
- items: [
113
- {
114
- label: 'Tutorial',
115
- to: '/docs/Getting%20Started',
116
- },
117
- {
118
- label: 'API',
119
- to: '/docs/api',
120
- },
121
- ],
122
- },
123
- // {
124
- // title: 'Community',
125
- // items: [
126
- // {
127
- // label: 'Stack Overflow',
128
- // href: 'https://stackoverflow.com/questions/tagged/docusaurus',
129
- // },
130
- // {
131
- // label: 'Discord',
132
- // href: 'https://discordapp.com/invite/docusaurus',
133
- // },
134
- // {
135
- // label: 'Twitter',
136
- // href: 'https://twitter.com/docusaurus',
137
- // },
138
- // ],
139
- // },
140
- {
141
- title: 'More',
142
- items: [
143
- // {
144
- // label: 'Blog',
145
- // to: '/blog',
146
- // },
147
- {
148
- label: 'DevForth.io',
149
- href: 'https://devforth.io',
150
- },
151
- {
152
- label: 'We can develop dashboard for you',
153
- href: 'https://devforth.io/contact',
154
- },
155
- {
156
- label: 'GitHub',
157
- href: 'https://github.com/devforth/adminforth',
158
- },
159
- ],
160
- },
161
- ],
162
- copyright: `Copyright © ${new Date().getFullYear()} Devforth sp. z o.o.`,
163
- },
164
- prism: {
165
- theme: prismThemes.okaidia,
166
- darkTheme: prismThemes.dracula,
167
- },
168
- } satisfies Preset.ThemeConfig,
169
- };
170
-
171
- export default config;