From e1d9113a4f027261915e81458b834a3c1e47a6df Mon Sep 17 00:00:00 2001 From: Vitalii Kulyk Date: Fri, 13 Jun 2025 11:40:40 +0300 Subject: [PATCH 01/56] fix: Support both single function and array for beforeLoginConfirmation --- adminforth/modules/restApi.ts | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/adminforth/modules/restApi.ts b/adminforth/modules/restApi.ts index 499ee606..7c19a194 100644 --- a/adminforth/modules/restApi.ts +++ b/adminforth/modules/restApi.ts @@ -84,22 +84,21 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI { async processLoginCallbacks(adminUser: AdminUser, toReturn: { redirectTo?: string, allowedLogin:boolean, error?: string }, response: any, extra: HttpExtra) { const beforeLoginConfirmation = this.adminforth.config.auth.beforeLoginConfirmation as (BeforeLoginConfirmationFunction[] | undefined); - if (beforeLoginConfirmation?.length){ - for (const hook of beforeLoginConfirmation) { - const resp = await hook({ - adminUser, - response, - adminforth: this.adminforth, - extra, - }); - - if (resp?.body?.redirectTo || resp?.error) { - // delete all items from toReturn and add these: - toReturn.redirectTo = resp?.body?.redirectTo; - toReturn.allowedLogin = resp?.body?.allowedLogin; - toReturn.error = resp?.error; - break; - } + + for (const hook of listify(Array.isArray(beforeLoginConfirmation) ? beforeLoginConfirmation : [beforeLoginConfirmation])) { + const resp = await hook({ + adminUser, + response, + adminforth: this.adminforth, + extra, + }); + + if (resp?.body?.redirectTo || resp?.error) { + // delete all items from toReturn and add these: + toReturn.redirectTo = resp?.body?.redirectTo; + toReturn.allowedLogin = resp?.body?.allowedLogin; + toReturn.error = resp?.error; + break; } } } From 12b12179b23354eacd12a6ff151e6458fb4b6ed3 Mon Sep 17 00:00:00 2001 From: Maksym Pipkun Date: Mon, 16 Jun 2025 14:03:40 +0300 Subject: [PATCH 02/56] feat: add custom filter component for square meters and integrate into resource selection --- .../commands/createCustomComponent/main.js | 1 + .../templates/customFields/filter.vue.hbs | 34 +++++ .../02-customFieldRendering.md | 119 +++++++++++++++++- adminforth/spa/src/components/Filters.vue | 19 ++- adminforth/types/Common.ts | 6 + dev-demo/custom/CustomSqueareMetersFilter.vue | 100 +++++++++++++++ dev-demo/resources/apartments.ts | 1 + 7 files changed, 278 insertions(+), 2 deletions(-) create mode 100644 adminforth/commands/createCustomComponent/templates/customFields/filter.vue.hbs create mode 100644 dev-demo/custom/CustomSqueareMetersFilter.vue diff --git a/adminforth/commands/createCustomComponent/main.js b/adminforth/commands/createCustomComponent/main.js index e9236bf2..33954693 100644 --- a/adminforth/commands/createCustomComponent/main.js +++ b/adminforth/commands/createCustomComponent/main.js @@ -50,6 +50,7 @@ async function handleFieldComponentCreation(config, resources) { { name: 'πŸ“ƒ show', value: 'show' }, { name: '✏️ edit', value: 'edit' }, { name: 'βž• create', value: 'create' }, + { name: 'πŸ” filter', value: 'filter'}, new Separator(), { name: 'πŸ”™ BACK', value: '__BACK__' }, ] diff --git a/adminforth/commands/createCustomComponent/templates/customFields/filter.vue.hbs b/adminforth/commands/createCustomComponent/templates/customFields/filter.vue.hbs new file mode 100644 index 00000000..9a2876be --- /dev/null +++ b/adminforth/commands/createCustomComponent/templates/customFields/filter.vue.hbs @@ -0,0 +1,34 @@ + + + \ No newline at end of file diff --git a/adminforth/documentation/docs/tutorial/03-Customization/02-customFieldRendering.md b/adminforth/documentation/docs/tutorial/03-Customization/02-customFieldRendering.md index 96d04a6b..8d6e88ad 100644 --- a/adminforth/documentation/docs/tutorial/03-Customization/02-customFieldRendering.md +++ b/adminforth/documentation/docs/tutorial/03-Customization/02-customFieldRendering.md @@ -481,4 +481,121 @@ list: '@/renderers/ZeroStylesRichText.vue', //diff-add ``` -`ZeroStyleRichText` fits well for tasks like email templates preview fields. \ No newline at end of file +`ZeroStyleRichText` fits well for tasks like email templates preview fields. + + +### Custom filter component for square meters + + +Sometimes standard filters are not enough, and you want to make a convenient UI for selecting a range of apartment areas. For example, buttons with options for β€œSmall (<25 mΒ²)”, β€œMedium (25–90 mΒ²)” and β€œLarge (>90 mΒ²)”. + +```ts title='./custom/SquareMetersFilter.vue' + + + +``` + +```ts title='./resources/apartments.ts' + columns: [ + ... + { + name: 'square_meter', + label: 'Square', + //diff-add + components: { + //diff-add + filter: '@@/SquareMetersFilter.vue' + //diff-add + } + }, + ... +] \ No newline at end of file diff --git a/adminforth/spa/src/components/Filters.vue b/adminforth/spa/src/components/Filters.vue index e6442f1a..7eb43541 100644 --- a/adminforth/spa/src/components/Filters.vue +++ b/adminforth/spa/src/components/Filters.vue @@ -21,9 +21,25 @@