Skip to content

Commit 10264b1

Browse files
committed
Merge branch 'next' of github.com:devforth/adminforth into next
2 parents 82ba4d4 + 03d3e0c commit 10264b1

File tree

10 files changed

+36
-41
lines changed

10 files changed

+36
-41
lines changed

adminforth/dataConnectors/baseConnector.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,13 +253,13 @@ export default class AdminForthBaseConnector implements IAdminForthDataSourceCon
253253
resource: AdminForthResource; record: any; adminUser: any;
254254
}): Promise<{ error?: string; ok: boolean; createdRecord?: any; }> {
255255
// transform value using setFieldValue and call createRecordOriginalValues
256-
256+
257257
const filledRecord = {...record};
258258
const recordWithOriginalValues = {...record};
259259

260260
for (const col of resource.dataSourceColumns) {
261261
if (col.fillOnCreate) {
262-
if (filledRecord[col.name] === undefined) {
262+
if (filledRecord[col.name] === undefined || (Array.isArray(filledRecord[col.name]) && filledRecord[col.name].length === 0)) {
263263
filledRecord[col.name] = col.fillOnCreate({
264264
initialRecord: record,
265265
adminUser

adminforth/modules/restApi.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ async function isShown(
6464
return true;
6565
}
6666

67+
async function isFilledOnCreate( col: AdminForthResource['columns'][number] ): Promise<boolean> {
68+
const fillOnCreate = !!col.fillOnCreate;
69+
return fillOnCreate;
70+
}
71+
6772
export async function interpretResource(
6873
adminUser: AdminUser,
6974
resource: AdminForthResource,
@@ -1190,9 +1195,10 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
11901195
for (const column of resource.columns) {
11911196
const fieldName = column.name;
11921197
if (fieldName in record) {
1193-
const shown = await isShown(column, 'create', ctxCreate);
1198+
const shown = await isShown(column, 'create', ctxCreate); //
11941199
const bo = await isBackendOnly(column, ctxCreate);
1195-
if (!shown || bo) {
1200+
const filledOnCreate = await isFilledOnCreate(column);
1201+
if ((!shown && !filledOnCreate) || bo) {
11961202
return { error: `Field "${fieldName}" cannot be modified as it is restricted from creation (backendOnly or showIn.create is false, please set it to true)`, ok: false };
11971203
}
11981204
}

adminforth/spa/src/App.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ const expandedWidth = computed(() => coreStore.config?.iconOnlySidebar?.expanded
201201
const theme = ref('light');
202202
203203
const userMenuComponents = computed(() => {
204+
console.log('🪲🆕 userMenuComponents recomputed', coreStore?.config?.globalInjections?.userMenu);
204205
return coreStore?.config?.globalInjections?.userMenu || [];
205206
})
206207

adminforth/spa/src/afcl/Table.vue

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,15 @@
110110
<!-- <IconChevronDoubleLeftOutline class="w-4 h-4" /> -->
111111
1
112112
</button>
113-
<div
114-
:contenteditable="!isLoading && !props.isLoading"
113+
<input
114+
type="text"
115+
v-model="pageInput"
116+
:style="{ width: `${Math.max(1, pageInput.length+4)}ch` }"
115117
class="min-w-10 outline-none inline-block w-auto py-1.5 px-3 text-sm text-center text-lightTablePaginationInputText border border-lightTablePaginationInputBorder bg-lightTablePaginationInputBackground dark:border-darkTablePaginationInputBorder dark:text-darkTablePaginationInputText dark:bg-darkTablePaginationInputBackground z-10"
116118
@keydown="onPageKeydown($event)"
117-
@input="onPageInput($event)"
118119
@blur="validatePageInput()"
119120
>
120-
{{ pageInput }}
121-
</div>
121+
</input>
122122

123123
<button
124124
class="flex items-center py-1 px-3 text-sm font-medium text-lightUnactivePaginationButtonText focus:outline-none bg-lightUnactivePaginationButtonBackground border-l-0 border border-lightUnactivePaginationButtonBorder hover:bg-lightUnactivePaginationButtonHoverBackground hover:text-lightUnactivePaginationButtonHoverText dark:bg-darkUnactivePaginationButtonBackground dark:text-darkUnactivePaginationButtonText dark:border-darkUnactivePaginationButtonBorder dark:hover:text-darkUnactivePaginationButtonHoverText dark:hover:bg-darkUnactivePaginationButtonHoverBackground disabled:opacity-50"
@@ -245,10 +245,6 @@
245245
'sort-change',
246246
'clickTableRow'
247247
]);
248-
249-
function onPageInput(event: any) {
250-
pageInput.value = event.target.innerText;
251-
}
252248
253249
function validatePageInput() {
254250
const newPage = parseInt(pageInput.value) || 1;

adminforth/spa/src/components/ResourceListTable.vue

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -241,15 +241,14 @@
241241
<!-- <IconChevronDoubleLeftOutline class="w-4 h-4" /> -->
242242
1
243243
</button>
244-
<div
245-
contenteditable="true"
246-
class="af-pagination-input min-w-10 outline-none inline-block w-auto py-1.5 px-3 text-sm text-center text-lightListTablePaginationCurrentPageText border border-lightListTablePaginationBorder dark:border-darkListTablePaginationBorder dark:text-darkListTablePaginationCurrentPageText dark:bg-darkListTablePaginationBackgoround z-10"
244+
<input
245+
type="text"
246+
v-model="pageInput"
247+
:style="{ width: `${Math.max(1, pageInput.length+4)}ch` }"
248+
class="af-pagination-input min-w-10 outline-none inline-block py-1.5 px-3 text-sm text-center text-lightListTablePaginationCurrentPageText border border-lightListTablePaginationBorder dark:border-darkListTablePaginationBorder dark:text-darkListTablePaginationCurrentPageText dark:bg-darkListTablePaginationBackgoround z-10"
247249
@keydown="onPageKeydown($event)"
248-
@input="onPageInput($event)"
249250
@blur="validatePageInput()"
250-
>
251-
{{ pageInput }}
252-
</div>
251+
/>
253252

254253
<button
255254
class="af-pagination-last-page-button flex items-center py-1 px-3 text-sm font-medium text-lightListTablePaginationText focus:outline-none bg-lightListTablePaginationBackgoround border-l-0 border border-lightListTablePaginationBorder hover:bg-lightListTablePaginationBackgoroundHover hover:text-lightListTablePaginationTextHover focus:z-10 focus:ring-4 focus:ring-lightListTablePaginationFocusRing dark:focus:ring-darkListTablePaginationFocusRing dark:bg-darkListTablePaginationBackgoround dark:text-darkListTablePaginationText dark:border-darkListTablePaginationBorder dark:hover:text-white dark:hover:bg-darkListTablePaginationBackgoroundHover disabled:opacity-50"
@@ -599,10 +598,6 @@ async function startCustomAction(actionId: string, row: any) {
599598
}
600599
}
601600
602-
function onPageInput(event: any) {
603-
pageInput.value = event.target.innerText;
604-
}
605-
606601
function validatePageInput() {
607602
const newPage = parseInt(pageInput.value) || 1;
608603
const validPage = Math.max(1, Math.min(newPage, totalPages.value));

adminforth/spa/src/components/ResourceListTableVirtual.vue

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -262,15 +262,15 @@
262262
<!-- <IconChevronDoubleLeftOutline class="w-4 h-4" /> -->
263263
1
264264
</button>
265-
<div
266-
contenteditable="true"
265+
<input
266+
type="text"
267+
v-model="pageInput"
268+
:style="{ width: `${Math.max(1, pageInput.length+4)}ch` }"
267269
class="af-pagination-input min-w-10 outline-none inline-block w-auto py-1.5 px-3 text-sm text-center text-lightListTablePaginationCurrentPageText border border-lightListTablePaginationBorder dark:border-darkListTablePaginationBorder dark:text-darkListTablePaginationCurrentPageText dark:bg-darkListTablePaginationBackgoround z-10"
268270
@keydown="onPageKeydown($event)"
269-
@input="onPageInput($event)"
270271
@blur="validatePageInput()"
271272
>
272-
{{ pageInput }}
273-
</div>
273+
</input>
274274

275275
<button
276276
class="af-pagination-last-page-button flex items-center py-1 px-3 text-sm font-medium text-lightListTablePaginationText focus:outline-none bg-lightListTablePaginationBackgoround border-l-0 border border-lightListTablePaginationBorder hover:bg-lightListTablePaginationBackgoroundHover hover:text-lightListTablePaginationTextHover focus:z-10 focus:ring-4 focus:ring-lightListTablePaginationFocusRing dark:focus:ring-darkListTablePaginationFocusRing dark:bg-darkListTablePaginationBackgoround dark:text-darkListTablePaginationText dark:border-darkListTablePaginationBorder dark:hover:text-white dark:hover:bg-darkListTablePaginationBackgoroundHover disabled:opacity-50"
@@ -623,9 +623,6 @@ async function startCustomAction(actionId: string, row: any) {
623623
}
624624
}
625625
626-
function onPageInput(event: any) {
627-
pageInput.value = event.target.innerText;
628-
}
629626
630627
function validatePageInput() {
631628
const newPage = parseInt(pageInput.value) || 1;

adminforth/types/adapters/StorageAdapter.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,17 @@ export interface StorageAdapter {
3939
* This method should work even if the file does not exist yet (e.g. only presigned URL was generated).
4040
* @param key - The key of the file to be uploaded e.g. "uploads/file.txt"
4141
*/
42-
markKeyForDeletation(key: string): Promise<void>;
42+
markKeyForDeletation(key: string): Promise<void>; //TODO delete after one year
43+
markKeyForDeletion(key: string): Promise<void>;
4344

4445

4546
/**
4647
* This method should mark the file to not be deleted.
4748
* This method should be used to cancel the deletion of the file if it was marked for deletion.
4849
* @param key - The key of the file to be uploaded e.g. "uploads/file.txt"
4950
*/
50-
markKeyForNotDeletation(key: string): Promise<void>;
51+
markKeyForNotDeletation(key: string): Promise<void>; //TODO delete after one year
52+
markKeyForNotDeletion(key: string): Promise<void>;
5153

5254

5355
/**

dev-demo/resources/apartments.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,6 @@ export default {
522522
meta: any;
523523
source: ActionCheckSource;
524524
}): Promise<boolean | string> => {
525-
console.log("edit aa check 🔒", meta, source, adminUser);
526525
return adminUser.dbUser.role === "superadmin";
527526
// return true;
528527
// if (source === ActionCheckSource.DisplayButtons) {
@@ -542,7 +541,6 @@ export default {
542541
return true;
543542
},
544543
show: async ({ adminUser, meta, source, adminforth }: any) => {
545-
console.log("show aa check 🔒", meta);
546544
// if (source === 'showRequest' || source === 'editLoadRequest') {
547545
// const record = await adminforth.resource('aparts').get(Filters.EQ('id', meta.pk));
548546
// return record.user_id === adminUser.dbUser.id;

live-demo/app/package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

live-demo/app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"@adminforth/two-factors-auth": "^1.1.2",
3333
"@adminforth/upload": "^2.3.6",
3434
"@prisma/client": "^6.6.0",
35-
"adminforth": "^2.4.0-next.298",
35+
"adminforth": "^2.4.0-next.313",
3636
"better-sqlite3": "^10.0.0",
3737
"express": "^4.19.2"
3838
},

0 commit comments

Comments
 (0)