Skip to content

Commit 397d35e

Browse files
committed
Merge branch 'next' of github.com:devforth/adminforth into next
2 parents 0317650 + 0bcbabf commit 397d35e

39 files changed

+526
-105
lines changed

adminforth/commands/callTsProxy.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,28 @@ import { spawn } from "child_process";
33
import path from "path";
44
import fs from "fs";
55
import chalk from "chalk";
6+
import dotenv from "dotenv";
67

78
const currentFilePath = import.meta.url;
89
const currentFileFolder = path.dirname(currentFilePath).replace("file:", "");
910

1011
export function callTsProxy(tsCode, silent=false) {
1112

13+
const currentDirectory = process.cwd();
14+
const envPath = path.resolve(currentDirectory, ".env");
15+
const envLocalPath = path.resolve(currentDirectory, ".env.local");
16+
if (fs.existsSync(envLocalPath)) {
17+
dotenv.config({ path: envLocalPath, override: true });
18+
}
19+
if (fs.existsSync(envPath)) {
20+
dotenv.config({ path: envPath, override: true });
21+
}
22+
1223
process.env.HEAVY_DEBUG && console.log("🌐 Calling tsproxy with code:", path.join(currentFileFolder, "proxy.ts"));
1324
return new Promise((resolve, reject) => {
14-
const child = spawn("tsx", [
15-
path.join(currentFileFolder, "proxy.ts")
16-
]);
17-
25+
const child = spawn("tsx", [path.join(currentFileFolder, "proxy.ts")], {
26+
env: process.env,
27+
});
1828
let stdout = "";
1929
let stderr = "";
2030

adminforth/commands/createApp/templates/index.ts.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import AdminForth from 'adminforth';
33
import usersResource from "./resources/adminuser.js";
44
import { fileURLToPath } from 'url';
55
import path from 'path';
6-
6+
77
const ADMIN_BASE_URL = '';
88

99
export const admin = new AdminForth({

adminforth/dataConnectors/mongo.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class MongoConnector extends AdminForthBaseConnector implements IAdminForthDataS
6969
return Number.isInteger(value) ? 'integer' : 'float';
7070
}
7171
if (value instanceof Date) return 'datetime';
72+
if (value && typeof value === 'object' && ('$numberDecimal' in value || value._bsontype === 'Decimal128')) return 'decimal';
7273
if (typeof value === 'object') return 'json';
7374
return 'string';
7475
}
@@ -89,13 +90,18 @@ class MongoConnector extends AdminForthBaseConnector implements IAdminForthDataS
8990
sampleValues.set(fullKey, value);
9091
}
9192

92-
if (
93-
value instanceof Buffer ||
94-
(value && typeof value === 'object' && (value as any)._bsontype === 'Decimal128')
95-
) {
93+
if (value instanceof Buffer) {
9694
addType(fullKey, 'json');
9795
return;
9896
}
97+
if (
98+
value &&
99+
typeof value === 'object' &&
100+
('$numberDecimal' in value || (value as any)._bsontype === 'Decimal128')
101+
) {
102+
addType(fullKey, 'decimal');
103+
return;
104+
}
99105

100106
if (
101107
value &&
@@ -104,9 +110,10 @@ class MongoConnector extends AdminForthBaseConnector implements IAdminForthDataS
104110
!(value instanceof Date)
105111
) {
106112
addType(fullKey, 'json');
107-
} else {
108-
addType(fullKey, detectType(value));
113+
return
109114
}
115+
116+
addType(fullKey, detectType(value));
110117
});
111118
}
112119

@@ -117,7 +124,7 @@ class MongoConnector extends AdminForthBaseConnector implements IAdminForthDataS
117124
return Array.from(fieldTypes.entries()).map(([name, types]) => {
118125
const primaryKey = name === '_id';
119126

120-
const priority = ['datetime', 'date', 'integer', 'float', 'boolean', 'json', 'string'];
127+
const priority = ['datetime', 'date', 'integer', 'float', 'boolean', 'json', 'decimal', 'string'];
121128

122129
const matched = priority.find(t => types.has(t)) || 'string';
123130

@@ -129,8 +136,8 @@ class MongoConnector extends AdminForthBaseConnector implements IAdminForthDataS
129136
datetime: 'DATETIME',
130137
date: 'DATE',
131138
json: 'JSON',
139+
decimal: 'DECIMAL',
132140
};
133-
134141
return {
135142
name,
136143
type: typeMap[matched] ?? 'STRING',

adminforth/documentation/blog/2024-10-01-ai-blog/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ model ContentImage {
199199
Create a migration:
200200

201201
```bash
202-
npm run makemigration -- --name add-posts && npm run migrate:local
202+
npm run makemigration -- --name add-posts ; npm run migrate:local
203203
```
204204

205205

adminforth/documentation/docs/tutorial/001-gettingStarted.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ This will create a migration file in `migrations` and apply it to the database.
8989
In future, when you need to add new resources, you need to modify `schema.prisma` (add models, change fields, etc.). After doing any modification you need to create a new migration using next command:
9090

9191
```bash
92-
npm run makemigration -- --name init && npm run migrate:local
92+
npm run makemigration -- --name init ; npm run migrate:local
9393
```
9494

9595
Other developers need to pull migration and run `npm run migrateLocal` to apply any unapplied migrations.
@@ -173,7 +173,7 @@ model apartments {
173173
Run the following command to create a new migration:
174174

175175
```bash
176-
npm run makemigration -- --name add-apartments && npm run migrate:local
176+
npm run makemigration -- --name add-apartments ; npm run migrate:local
177177
```
178178

179179
### Step3. Create the `apartments` resource

adminforth/documentation/docs/tutorial/01-helloWorld.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ model Post {
122122
Create database using `prisma migrate`:
123123

124124
```bash
125-
npm run makemigration --name init && npm run migrate:local
125+
npm run makemigration --name init ; npm run migrate:local
126126
```
127127

128128
## Setting up AdminForth

adminforth/documentation/docs/tutorial/03-Customization/01-branding.md

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,26 @@ const admin = new AdminForth({
9494
Here is how it looks:
9595
![AdminForth Themes](image-10.png)
9696

97+
## Single theme
98+
99+
If you want to enforce a consistent theme and disable the theme switcher, you can configure AdminForth to use only one theme variant.
100+
101+
```ts title='./index.ts'
102+
103+
const admin = new AdminForth({
104+
...
105+
customization: {
106+
//diff-add
107+
singleTheme: "light",
108+
styles: {
109+
...
110+
}
111+
}
112+
},
113+
...
114+
});
115+
```
116+
97117

98118
## Square vs rounded buttons?
99119

@@ -149,4 +169,52 @@ auth: {
149169
`loginBackgroundPosition` accepts values:
150170

151171
- `over` - image will be over the whole login page with cover mode
152-
- `1/2`(default), `3/4`, `2/5`, `3/5` etc. - image will be in the left side of the login page with cover mode
172+
- `1/2`(default), `3/4`, `2/5`, `3/5` etc. - image will be in the left side of the login page with cover mode
173+
174+
### Disabling background blend mode
175+
176+
When using `loginBackgroundPosition: 'over'`, AdminForth applies a background blend mode by default to ensure text readability over the background image. If you want to disable this blend mode and display the background image without any overlay effects, you can add:
177+
178+
```ts title='./index.ts'
179+
auth: {
180+
...
181+
loginBackgroundImage: '@@/photo-1516501312919-d0cb0b7b60b8.jpeg',
182+
loginBackgroundPosition: 'over',
183+
//diff-add
184+
removeBackgroundBlendMode: true,
185+
}
186+
187+
```
188+
189+
## Custom items in html head
190+
191+
If you want to add custom elements to the HTML head, you can define them in the configuration:
192+
193+
```ts title='./index.ts'
194+
customization: {
195+
customHeadItems: [
196+
{
197+
tagName: 'link',
198+
attributes: {
199+
rel: 'stylesheet',
200+
href: 'https://example.com/custom.css'
201+
}
202+
},
203+
{
204+
tagName: 'script',
205+
attributes: {
206+
src: 'https://example.com/custom.js',
207+
defer: true
208+
}
209+
},
210+
{
211+
tagName: 'meta',
212+
attributes: {
213+
name: 'theme-color',
214+
content: ' #000000'
215+
}
216+
}
217+
]
218+
}
219+
220+
```

adminforth/documentation/docs/tutorial/03-Customization/13-standardPagesTuning.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ To open a custom page, return URL to the custom page (can start with https://, o
194194
//diff-add
195195
listTableClickUrl: async (record, adminUser) => {
196196
//diff-add
197-
return `https://google.com/search?q=${record.name}`;
197+
return `https://google.com/search?q=${record.title}`;
198198
//diff-add
199199
}
200200
}

adminforth/documentation/docs/tutorial/03-Customization/15-afcl.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,3 +1726,40 @@ import { MixedChart } from '@/afcl'
17261726
</div>
17271727
</div>
17281728

1729+
## Json Viever
1730+
1731+
```ts
1732+
import { JsonViever } from '@/afcl'
1733+
```
1734+
1735+
### Basic
1736+
1737+
<div class="split-screen" >
1738+
1739+
<div>
1740+
```html
1741+
<JsonViewer
1742+
:value="[
1743+
{
1744+
id: 1,
1745+
name: 'Alice',
1746+
meta: {
1747+
age: 30,
1748+
hobbies: ['reading', 'biking'],
1749+
}
1750+
},
1751+
{
1752+
id: 2,
1753+
name: 'Bob',
1754+
}
1755+
]"
1756+
:expandDepth="2"
1757+
/>
1758+
```
1759+
</div>
1760+
<div>
1761+
![Mixed Chart](image-93.png)
1762+
</div>
1763+
</div>
1764+
1765+
763 KB
Loading

0 commit comments

Comments
 (0)