Skip to content

Commit a21d9b2

Browse files
authored
Merge pull request #544 from devforth/next
Next
2 parents 941e56d + 61af5eb commit a21d9b2

8 files changed

Lines changed: 65 additions & 6 deletions

File tree

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,22 @@ import { Express, Request, Response } from "express";
22
import { IAdminForth } from "adminforth";
33
export function initApi(app: Express, admin: IAdminForth) {
44
app.get(`${admin.config.baseUrl}/api/hello/`,
5+
6+
// you can use data API to work with your database https://adminforth.dev/docs/tutorial/Customization/dataApi/
57
async (req: Request, res: Response) => {
8+
// req.adminUser to get info about the admin users
69
const allUsers = await admin.resource("adminuser").list([]);
710
res.json({
8-
message: "Hello from AdminForth API!",
11+
message: "List of admin users from AdminForth API",
912
users: allUsers,
1013
});
1114
}
15+
16+
// you can use admin.express.authorize to get info about the current user
17+
admin.express.authorize(
18+
async (req: Request, res: Response) => {
19+
res.json({ message: "Current adminuser from AdminForth API", adminUser: req.adminUser });
20+
}
21+
)
1222
);
1323
}

adminforth/documentation/docs/tutorial/08-Plugins/14-markdown.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,32 @@ plugins: [
205205

206206
>👆 Full list of buttons you can enable or disable via topPanelSettings:
207207
bold, italic, underline, strike, h1, h2, h3, ul, ol, link, codeBlock
208+
209+
210+
## Change size of show view markdown text
211+
By default in markdown plugin turned cumpact preview mode, but you can turn it off:
212+
213+
214+
```ts
215+
new MarkdownPlugin({
216+
fieldName: 'description',
217+
//diff-add
218+
compactShowPreview: false,
219+
...
220+
})
221+
222+
```
223+
224+
## Limiting height of the markdown renderer on show view
225+
If you have really long markdown text and you don't wan't it to take the whole space on show view page, you can use `maxShowViewContainerHeightPx`, that will add max-height to the markdown renderer and button `show more`, so you can expand it.
226+
227+
```ts
228+
new MarkdownPlugin({
229+
fieldName: 'description',
230+
compactShowPreview: false,
231+
//diff-add
232+
maxShowViewContainerHeightPx: 400,
233+
...
234+
})
235+
236+
```

adminforth/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
}
6565
},
6666
"author": "devforth.io",
67-
"license": "ISC",
67+
"license": "MIT",
6868
"type": "module",
6969
"dependencies": {
7070
"@babel/parser": "^7.27.5",

adminforth/servers/express.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,11 @@ class ExpressServer implements IExpressHttpServer {
136136
'Pragma': 'public',
137137
}
138138
}
139-
)
139+
, (err) => {
140+
if (err && err.message.includes('ENOENT')) {
141+
res.status(404).send('Not found');
142+
}
143+
});
140144
})
141145

142146
this.expressApp.get(`${prefix}*`, async (req, res) => {

adminforth/spa/src/components/ResourceForm.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ const columnError = (column: AdminForthResourceColumnCommon) => {
162162
return currentValues.value[column.name] && currentValues.value[column.name].reduce((error: any, item: any) => {
163163
if (column.isArray) {
164164
return error || validateValue(column.isArray.itemType, item, column) ||
165-
(item === null || !item.toString() ? t('Array cannot contain empty items') : null);
165+
(item === null || (!item || item.toString() === '') ? t('Array cannot contain empty items') : null);
166166
} else {
167167
return error;
168168
}

adminforth/spa/src/components/ValueRenderer.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
class="rounded-md m-0.5 bg-lightAnnouncementBG dark:bg-darkAnnouncementBG text-lightAnnouncementText dark:text-darkAnnouncementText py-0.5 px-2.5 text-sm"
1212
>
1313
<RouterLink
14+
v-if="foreignResource && foreignResource?.pk"
1415
class="font-medium text-lightSidebarText dark:text-darkSidebarText hover:brightness-110 whitespace-nowrap"
1516
:to="{
1617
name: 'resource-show',

adminforth/spa/src/views/EditView.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ const editableRecord = computed(() => {
147147
coreStore.resource.columns.forEach(column => {
148148
if (column.foreignResource) {
149149
if (column.isArray?.enabled) {
150-
newRecord[column.name] = newRecord[column.name]?.map((fr: { pk: any }) => fr.pk);
150+
newRecord[column.name] = newRecord[column.name]?.map((fr: { pk: any }) => fr?.pk);
151151
} else {
152152
newRecord[column.name] = newRecord[column.name]?.pk;
153153
}

dev-demo/resources/cars_resources/carsResourseTemplate.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ export default function carsResourseTemplate(resourceId: string, dataSource: str
219219
}),
220220
new MarkdownPlugin({
221221
fieldName: 'description',
222+
maxShowViewContainerHeightPx: 400,
222223
attachments: {
223224
attachmentResource: "cars_description_images",
224225
attachmentFieldName: "image_path",
@@ -332,6 +333,11 @@ export default function carsResourseTemplate(resourceId: string, dataSource: str
332333
fillPlainFields: {
333334
description: "Create a desription for the car with name {{model}} and engine type {{engine_type}}. Desription should be HTML formatted.",
334335
price: "Based on the car model {{model}} and engine type {{engine_type}}, suggest a competitive market price in USD. Return only the numeric value.",
336+
},
337+
rateLimits: { // bulk generation limits
338+
fillFieldsFromImages: "1/1m", // 1 request per minute
339+
fillPlainFields: "1/1m", // 1 request per minute
340+
generateImages: "1/1m", // 1 request per minute
335341
}
336342
}),
337343
new BulkAiFlowPlugin({
@@ -352,6 +358,11 @@ export default function carsResourseTemplate(resourceId: string, dataSource: str
352358
}
353359
return [`https://tmpbucket-adminforth.s3.eu-central-1.amazonaws.com/${record.promo_picture}`];
354360
},
361+
rateLimits: { // bulk generation limits
362+
fillFieldsFromImages: "1/1m", // 1 request per minute
363+
fillPlainFields: "1/1m", // 1 request per minute
364+
generateImages: "1/1m", // 1 request per two minutes
365+
}
355366
}),
356367
new BulkAiFlowPlugin({
357368
actionName: 'Generate promo image',
@@ -367,7 +378,11 @@ export default function carsResourseTemplate(resourceId: string, dataSource: str
367378
prompt: "Create a high-quality promotional image for a {{color}} car shown on attached image. Generated image should be in anime style",
368379
}
369380
},
370-
381+
rateLimits: { // bulk generation limits
382+
fillFieldsFromImages: "1/1m", // 1 request per minute
383+
fillPlainFields: "1/1m", // 1 request per minute
384+
generateImages: "1/1m", // 1 request per minute
385+
},
371386
attachFiles: async ({ record }) => {
372387
if (!record.promo_picture) {
373388
return [];

0 commit comments

Comments
 (0)