Skip to content

Commit f35d1c6

Browse files
committed
Merge branch 'next' of github.com:devforth/adminforth into feature/AdminForth/1137/lets-remove-heavy_debug-and-in
2 parents 383c5f4 + 16502b0 commit f35d1c6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+554
-485
lines changed

adminforth/basePlugin.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ export default class AdminForthPlugin implements IAdminForthPlugin {
3838
return 'non-uniquely-identified';
3939
}
4040

41+
shouldHaveSingleInstancePerWholeApp(): boolean {
42+
return true;
43+
}
44+
4145
modifyResourceConfig(adminforth: IAdminForth, resourceConfig: AdminForthResource, allPluginInstances?: {pi: AdminForthPlugin, resource: AdminForthResource}[]) {
4246
this.resourceConfig = resourceConfig;
4347
const uniqueness = this.instanceUniqueRepresentation(this.pluginOptions);

adminforth/commands/createCustomComponent/templates/customCrud/afterBreadcrumbs.vue.hbs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@
1313
<script setup lang="ts">
1414
import { onMounted } from 'vue';
1515
import { useI18n } from 'vue-i18n';
16-
import adminforth from '@/adminforth';
16+
import { useAdminforth } from '@/adminforth';
1717
import { AdminForthResourceCommon, AdminUser } from "@/types/Common";
1818
1919
const { t } = useI18n();
2020
21+
const { alert } = useAdminforth();
22+
2123
const props = defineProps<{
2224
record: any
2325
resource: AdminForthResourceCommon
@@ -30,7 +32,7 @@ onMounted(() => {
3032
});
3133
3234
function handleClick() {
33-
adminforth.alert({
35+
alert({
3436
message: t('Confirmed'),
3537
variant: 'success',
3638
});

adminforth/commands/createCustomComponent/templates/customCrud/beforeActionButtons.vue.hbs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
<script setup lang="ts">
1414
import { onMounted } from 'vue';
1515
import { useI18n } from 'vue-i18n';
16-
import adminforth from '@/adminforth';
16+
import { useAdminforth } from '@/adminforth';
1717
import { AdminForthResourceCommon, AdminUser } from "@/types/Common";
1818

19+
const { alert } = useAdminforth();
1920
const { t } = useI18n();
2021

2122
const props = defineProps<{
@@ -30,7 +31,7 @@ onMounted(() => {
3031
});
3132

3233
function handleClick() {
33-
adminforth.alert({
34+
alert({
3435
message: t('Confirmed'),
3536
variant: 'success',
3637
});

adminforth/commands/createCustomComponent/templates/customCrud/beforeBreadcrumbs.vue.hbs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@
1313
<script setup lang="ts">
1414
import { onMounted } from 'vue';
1515
import { useI18n } from 'vue-i18n';
16-
import adminforth from '@/adminforth';
16+
import { useAdminforth } from '@/adminforth';
1717
import { AdminForthResourceCommon, AdminUser } from "@/types/Common";
1818
1919
const { t } = useI18n();
2020
21+
const { alert } = useAdminforth();
22+
2123
const props = defineProps<{
2224
record: any
2325
resource: AdminForthResourceCommon
@@ -30,7 +32,7 @@ onMounted(() => {
3032
});
3133
3234
function handleClick() {
33-
adminforth.alert({
35+
alert({
3436
message: t('Confirmed'),
3537
variant: 'success',
3638
});

adminforth/commands/createCustomComponent/templates/customCrud/bottom.vue.hbs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@
1313
<script setup lang="ts">
1414
import { onMounted } from 'vue';
1515
import { useI18n } from 'vue-i18n';
16-
import adminforth from '@/adminforth';
16+
import { useAdminforth } from '@/adminforth';
1717
import { AdminForthResourceCommon, AdminUser } from "@/types/Common";
1818
1919
const { t } = useI18n();
2020
21+
const { alert } = useAdminforth();
22+
2123
const props = defineProps<{
2224
record: any
2325
resource: AdminForthResourceCommon
@@ -30,7 +32,7 @@ onMounted(() => {
3032
});
3133
3234
function handleClick() {
33-
adminforth.alert({
35+
alert({
3436
message: t('Confirmed'),
3537
variant: 'success',
3638
});

adminforth/commands/createCustomComponent/templates/customCrud/threeDotsDropdownItems.vue.hbs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212

1313
<script setup lang="ts">
1414
import { useI18n } from 'vue-i18n';
15-
import adminforth from '@/adminforth';
15+
import { useAdminforth} from '@/adminforth';
1616
import { onMounted } from 'vue';
1717
import { AdminForthResourceCommon, AdminUser } from "@/types/Common";
1818
1919
const { t } = useI18n();
2020
21+
const { alert } = useAdminforth();
22+
2123
const props = defineProps<{
2224
record: any
2325
resource: AdminForthResourceCommon
@@ -29,7 +31,7 @@ const menuItems = [
2931
{
3032
label: 'Show Success Alert',
3133
action: () => {
32-
adminforth.alert({
34+
alert({
3335
message: t('Success Alert'),
3436
variant: 'success',
3537
});

adminforth/commands/createPlugin/templates/index.ts.hbs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ export default class {{pluginName}} extends AdminForthPlugin {
2727
return `single`;
2828
}
2929

30+
shouldHaveSingleInstancePerWholeApp(): boolean {
31+
return false;
32+
}
33+
3034
setupEndpoints(server: IHttpServer) {
3135
server.endpoint({
3236
method: 'POST',

adminforth/documentation/docs/tutorial/03-Customization/06-customPages.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,16 @@ import { ref, type Ref, onMounted, computed } from 'vue';
182182
import dayjs from 'dayjs';
183183
import { callApi } from '@/utils';
184184
import { useI18n } from 'vue-i18n';
185-
import adminforth from '@/adminforth';
185+
import { useAdminforth } from '@/adminforth';
186186
import { AreaChart, BarChart, PieChart } from '@/afcl';
187187
188188
const data: Ref<{listedVsUnlistedPriceByDays: any, listedVsUnlistedByDays: any,
189189
apartsByDays: any, apartsCountsByRooms: any, topCountries: any, totalAparts: any} | null> = ref(null);
190190
191191
const { t } = useI18n();
192192
193+
const { alert } = useAdminforth();
194+
193195
const COLORS = ["#4E79A7", "#F28E2B", "#E15759", "#76B7B2", "#59A14F"]
194196
195197
const apartsCountsByDaysChart = computed(() => {
@@ -246,7 +248,7 @@ onMounted(async () => {
246248
try {
247249
data.value = await callApi({path: '/api/dashboard/', method: 'GET'});
248250
} catch (error) {
249-
adminforth.alert({
251+
alert({
250252
message: t(`Error fetching data: {message}`, { message: error.message }),
251253
variant: 'danger',
252254
});

adminforth/documentation/docs/tutorial/03-Customization/07-alert.md

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ AdminForth has very simple [frontend API](/docs/api/FrontendAPI/interfaces/Front
1212
To show an alert use `adminforth.alert` method:
1313

1414
```ts
15-
import adminforth from '@/adminforth';
15+
import { useAdminforth } from '@/adminforth';
1616

17-
adminforth.alert({message: 'Hello world', variant: 'success'})
17+
const { alert } = useAdminforth();
18+
19+
alert({message: 'Hello world', variant: 'success'})
1820
```
1921

2022
Next variants are supported:
@@ -62,9 +64,11 @@ Here's how the alert looks now:
6264
To show a confirmation dialog use `adminforth.confirm` method:
6365

6466
```ts
65-
import adminforth from '@/adminforth';
67+
import { useAdminforth } from '@/adminforth';
68+
69+
const { confirm } = useAdminforth();
6670

67-
const isConfirmed = await adminforth.confirm({message: 'Are you sure?', yes: 'Yes', no: 'No'})
71+
const isConfirmed = await confirm({message: 'Are you sure?', yes: 'Yes', no: 'No'})
6872
```
6973

7074
## Usage example
@@ -88,26 +92,28 @@ Create a Vue component in the custom directory of your project, e.g. `Alerts.vue
8892
</div>
8993
</template>
9094
<script setup>
91-
import adminforth from '@/adminforth';
95+
import { useAdminforth } from '@/adminforth';
9296
import { Button } from '@/afcl'
9397
import { useI18n } from 'vue-i18n';
9498
9599
const { t } = useI18n();
96100
101+
const { alert, confirm } = useAdminforth();
102+
97103
function successAlert(message) {
98-
adminforth.alert({message, variant: 'success'})
104+
alert({message, variant: 'success'})
99105
};
100106
101107
function warningAlert(message) {
102-
adminforth.alert({message, variant: 'warning'})
108+
alert({message, variant: 'warning'})
103109
};
104110
105111
async function doConfirm() {
106-
const isConfirmed = await adminforth.confirm({message: t('Are you sure?'), yes: t('Yes'), no: t('No')})
112+
const isConfirmed = await confirm({message: t('Are you sure?'), yes: t('Yes'), no: t('No')})
107113
if (isConfirmed){
108-
adminforth.alert({message: t('Confirmed'), variant: 'success'})
114+
alert({message: t('Confirmed'), variant: 'success'})
109115
} else {
110-
adminforth.alert({message: t('Not confirmed'), variant: 'warning'})
116+
alert({message: t('Not confirmed'), variant: 'warning'})
111117
}
112118
}
113119
</script>

0 commit comments

Comments
 (0)