Skip to content

Commit 83318b2

Browse files
authored
Merge branch 'next' into add-command-to-import-resource
2 parents 871e826 + 969eb52 commit 83318b2

File tree

9 files changed

+57
-17
lines changed

9 files changed

+57
-17
lines changed

adminforth/commands/createApp/templates/Dockerfile.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ WORKDIR /code/
33
ADD package.json package-lock.json /code/
44
RUN npm ci
55
ADD . /code/
6-
RUN --mount=type=cache,target=/tmp npx adminforth bundle
6+
RUN npx adminforth bundle
77
CMD ["sh", "-c", "npm run migrate:prod && npm run prod"]

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,9 +519,19 @@ Default behavior of the Dialog component will allow user to close it by just cli
519519
</div>
520520
</div>
521521

522-
### Dialog open and close
522+
### Programatically open or close dialog
523523

524-
You can open and close dialog by calling `open` and `close` methods.
524+
If you want to control dialog programmatically, you can use `ref` to get a reference to the dialog component.
525+
526+
```html
527+
<Dialog ref="confirmDialog" class="w-96">
528+
<div class="space-y-4">
529+
The dialog content goes here.
530+
</div>
531+
</Dialog>
532+
```
533+
534+
Now you can open and close dialog by calling `open` and `close` methods.
525535

526536
```ts
527537

adminforth/documentation/docs/tutorial/05-Plugins/05-upload.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,17 @@ This plugin allows you to upload files to Amazon S3 bucket.
66

77
```
88
npm i @adminforth/upload --save
9-
npm i @adminforth/storage-adapter-amazon-s3 --save
109
```
1110

12-
## S3
11+
Plugin needs some storage adapter to store files and serve them for preview.
12+
13+
### Using Amazon S3 storage adapter
14+
15+
Amazon S3 is probably the most popular storage service.
16+
17+
```
18+
npm i @adminforth/storage-adapter-amazon-s3 --save
19+
```
1320

1421
1. Go to https://aws.amazon.com and login.
1522
2. Go to Services -> S3 and create a bucket. Put in bucket name e.g. `my-reality-bucket`.
@@ -204,7 +211,7 @@ export async function getPresignedUrl(s3Path: string): Promise<string> {
204211
205212
Alternatively, if you don't want to generate presigned URLs, you might want to make all objects public. Then you will be able concatenate backet base domain and path stored in db, and use it as source of image. Let's consider how to do it.
206213
207-
### S3 upload with public access
214+
#### S3 upload with public access
208215
209216
1. First of all go to your bucket settings, Permissions, scroll down to Block public access (bucket settings for this bucket) and uncheck all checkboxes.
210217
2. Go to bucket settings, Permissions, Object ownership and select "ACLs Enabled" and "Bucket owner preferred" radio buttons.
@@ -268,6 +275,8 @@ If for example your domain is `my-domain.com` and you bucket has name `static.my
268275
269276
Also you will have to enable static website hosting in your bucket settings and set index.html and error.html to empty strings.
270277
278+
### S
279+
271280
272281
## Image generation
273282

adminforth/index.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,15 @@ class AdminForth implements IAdminForth {
236236
});
237237
}
238238

239-
validateRecordValues(resource: AdminForthResource, record: any): any {
239+
validateRecordValues(resource: AdminForthResource, record: any, mode: 'create' | 'edit'): any {
240240
// check if record with validation is valid
241241
for (const column of resource.columns.filter((col) => col.name in record && col.validation)) {
242+
const required = typeof column.required === 'object'
243+
? column.required[mode]
244+
: true;
245+
246+
if (!required && !record[column.name]) continue;
247+
242248
let error = null;
243249
if (column.isArray?.enabled) {
244250
error = record[column.name].reduce((err, item) => {
@@ -333,6 +339,9 @@ class AdminForth implements IAdminForth {
333339
}
334340
if (fieldTypes === null) {
335341
console.error(`⛔ DataSource ${res.dataSource} was not able to perform field discovery. It will not work properly`);
342+
if (process.env.NODE_ENV === 'production') {
343+
process.exit(1);
344+
}
336345
return;
337346
}
338347
if (!res.columns) {
@@ -465,7 +474,7 @@ class AdminForth implements IAdminForth {
465474
{ resource: AdminForthResource, record: any, adminUser: AdminUser, extra?: HttpExtra }
466475
): Promise<{ error?: string, createdRecord?: any }> {
467476

468-
const err = this.validateRecordValues(resource, record);
477+
const err = this.validateRecordValues(resource, record, 'create');
469478
if (err) {
470479
return { error: err };
471480
}
@@ -534,7 +543,7 @@ class AdminForth implements IAdminForth {
534543
{ resource, recordId, record, oldRecord, adminUser, extra }:
535544
{ resource: AdminForthResource, recordId: any, record: any, oldRecord: any, adminUser: AdminUser, extra?: HttpExtra }
536545
): Promise<{ error?: string }> {
537-
const err = this.validateRecordValues(resource, record);
546+
const err = this.validateRecordValues(resource, record, 'edit');
538547
if (err) {
539548
return { error: err };
540549
}

adminforth/modules/codeInjector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ class CodeInjector implements ICodeInjector {
596596
}
597597
} catch (e) {
598598
// ignore
599-
process.env.HEAVY_DEBUG && console.log('🪲Hash file does not exist, proceeding with npm ci/install');
599+
process.env.HEAVY_DEBUG && console.log('🪲Hash file does not exist, proceeding with npm ci/install', e);
600600
}
601601

602602
await this.runNpmShell({command: 'ci', cwd: this.spaTmpPath(), envOverrides: {

adminforth/spa/src/components/MenuLink.vue

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,20 @@
1212
>
1313
<component v-if="item.icon" :is="getIcon(item.icon)" class="w-5 h-5 text-lightSidebarIcons dark:text-darkSidebarIcons transition duration-75 group-hover:text-lightSidebarIconsHover dark:group-hover:text-darkSidebarIconsHover" ></component>
1414
<span class="text-ellipsis overflow-hidden ms-3">{{ item.label }}</span>
15-
<span v-if="item.badge" class="inline-flex items-center justify-center h-3 py-3 px-1 ms-3 text-sm font-medium rounded-full bg-lightAnnouncementBG dark:bg-darkAnnouncementBG
16-
fill-lightAnnouncementText dark:fill-darkAccent text-lightAnnouncementText dark:text-darkAccent min-w-[1.5rem] max-w-[3rem]"
15+
<span v-if="item.badge"
1716
>
1817

1918
<Tooltip v-if="item.badgeTooltip">
20-
{{ item.badge }}
19+
<div class="inline-flex items-center justify-center h-3 py-3 px-1 ms-3 text-sm font-medium rounded-full bg-lightAnnouncementBG dark:bg-darkAnnouncementBG
20+
fill-lightAnnouncementText dark:fill-darkAccent text-lightAnnouncementText dark:text-darkAccent min-w-[1.5rem] max-w-[3rem]">{{ item.badge }}</div>
2121

2222
<template #tooltip>
2323
{{ item.badgeTooltip }}
2424
</template>
2525
</Tooltip>
2626
<template v-else>
27-
{{ item.badge }}
27+
<div class="inline-flex items-center justify-center h-3 py-3 px-1 ms-3 text-sm font-medium rounded-full bg-lightAnnouncementBG dark:bg-darkAnnouncementBG
28+
fill-lightAnnouncementText dark:fill-darkAccent text-lightAnnouncementText dark:text-darkAccent min-w-[1.5rem] max-w-[3rem]">{{ item.badge }}</div>
2829
</template>
2930

3031
</span>

adminforth/spa/src/stores/core.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ export const useCoreStore = defineStore('core', () => {
8686
}
8787
async function subscribeToMenuBadges() {
8888
const processItem = (mi: AdminForthConfigMenuItem) => {
89-
if (mi.badge) {
89+
90+
// console.log('🔔 subscribeToMenuBadges', mi.badge, JSON.stringify(mi));
91+
if (mi.badge !== undefined) {
9092
websocket.subscribe(`/opentopic/update-menu-badge/${mi.itemId}`, ({ badge }) => {
9193
mi.badge = badge;
9294
});

adminforth/spa/src/views/EditView.vue

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,18 @@ async function saveRecord() {
147147
saving.value = true;
148148
const updates = {};
149149
for (const key in record.value) {
150-
let columnIsUpdated = record.value[key] !== coreStore.record[key];
150+
let columnIsUpdated = false;
151+
152+
if (typeof record.value[key] !== typeof coreStore.record[key]) {
153+
columnIsUpdated = true;
154+
} else if (typeof record.value[key] === 'object') {
155+
columnIsUpdated = JSON.stringify(record.value[key]) !== JSON.stringify(coreStore.record[key]);
156+
} else {
157+
columnIsUpdated = record.value[key] !== coreStore.record[key];
158+
}
151159
152160
const column = coreStore.resource.columns.find((c) => c.name === key);
161+
153162
if (column?.foreignResource) {
154163
columnIsUpdated = record.value[key] !== coreStore.record[key]?.pk;
155164
}

live-demo/app/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ WORKDIR /code/
33
ADD package.json package-lock.json /code/
44
RUN npm ci
55
ADD . /code/
6-
RUN --mount=type=cache,target=/tmp npm run bundleNow
6+
RUN npm run bundleNow
77

88

99
CMD ["npm", "run", "startLive"]

0 commit comments

Comments
 (0)