Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -430,4 +430,48 @@ function openCustomPage() {
Also there are:

* `config.customization.globalInjections.header`
* `config.customization.globalInjections.sidebar`
* `config.customization.globalInjections.sidebar`
* `config.customization.globalInjections.everyPageBottom`

Unlike `userMenu`, `header` and `sidebar` injections, `everyPageBottom` will be added to the bottom of every page even when user is not logged in.
You can use it to execute some piece of code when any page is loaded. For example, you can add welcoming pop up when user visits a page.

```ts title="/index.ts"
{
...
customization: {
globalInjections: {
userMenu: [
'@@/CustomUserMenuItem.vue',
//diff-remove
]
//diff-add
],
//diff-add
everyPageBottom: [
//diff-add
'@@/AnyPageWelcome.vue',
//diff-add
]
}
}
...
}
```

Now create file `AnyPageWelcome.vue` in the `custom` folder of your project:

```html title="./custom/AnyPageWelcome.vue"
<template></template>

<script setup>
import { onMounted } from 'vue';
import adminforth from '@/adminforth';
onMounted(() => {
adminforth.alert({
message: 'Welcome!',
variant: 'success',
});
});
</script>
```
3 changes: 2 additions & 1 deletion adminforth/modules/configValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,11 @@ export default class ConfigValidator implements IConfigValidator {
userMenu: [],
header: [],
sidebar: [],
everyPageBottom: [],
};

if (this.inputConfig.customization?.globalInjections) {
const ALLOWED_GLOBAL_INJECTIONS = ['userMenu', 'header', 'sidebar']
const ALLOWED_GLOBAL_INJECTIONS = ['userMenu', 'header', 'sidebar', 'everyPageBottom'];
Object.keys(this.inputConfig.customization.globalInjections).forEach((injection) => {
if (ALLOWED_GLOBAL_INJECTIONS.includes(injection)) {
globalInjections[injection] = this.validateAndListifyInjectionNew(this.inputConfig.customization.globalInjections, injection, errors);
Expand Down
3 changes: 3 additions & 0 deletions adminforth/modules/restApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
demoCredentials: this.adminforth.config.auth.demoCredentials,
loginPromptHTML: await tr(this.adminforth.config.auth.loginPromptHTML, 'system.loginPromptHTML'),
loginPageInjections: this.adminforth.config.customization.loginPageInjections,
globalInjections: {
everyPageBottom: this.adminforth.config.customization.globalInjections.everyPageBottom,
},
rememberMeDays: this.adminforth.config.auth.rememberMeDays,
};
},
Expand Down
7 changes: 5 additions & 2 deletions adminforth/spa/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,12 @@
drawer-backdrop="" class="bg-gray-900/50 dark:bg-gray-900/80 fixed inset-0 z-20">
</div>


<component
v-for="c in coreStore?.config?.globalInjections?.everyPageBottom || []"
:is="getCustomComponent(c)"
:meta="c.meta"
/>
</div>

</template>

<style lang="scss" scoped>
Expand Down
2 changes: 2 additions & 0 deletions adminforth/types/Back.ts
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,7 @@ interface AdminForthInputConfigCustomization {
userMenu?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>,
header?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>,
sidebar?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>,
everyPageBottom?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>,
}
}

Expand Down Expand Up @@ -984,6 +985,7 @@ export interface AdminForthConfigCustomization extends Omit<AdminForthInputConfi
userMenu: Array<AdminForthComponentDeclarationFull>,
header: Array<AdminForthComponentDeclarationFull>,
sidebar: Array<AdminForthComponentDeclarationFull>,
everyPageBottom: Array<AdminForthComponentDeclarationFull>,
},
}

Expand Down
1 change: 1 addition & 0 deletions adminforth/types/Common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,7 @@ export interface AdminForthConfigForFrontend {
userMenu: Array<AdminForthComponentDeclarationFull>,
header: Array<AdminForthComponentDeclarationFull>,
sidebar: Array<AdminForthComponentDeclarationFull>,
everyPageBottom: Array<AdminForthComponentDeclarationFull>,
}
}

Expand Down