Skip to content

Commit 31d273e

Browse files
committed
get rid of window.adminforth and replace it with @/adminforth import
1 parent e17433f commit 31d273e

File tree

33 files changed

+245
-74
lines changed

33 files changed

+245
-74
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ import { ref, onMounted } from 'vue';
9898
import ApexCharts from 'apexcharts';
9999
import dayjs from 'dayjs';
100100
import { callApi } from '@/utils';
101+
import adminforth from '@adminforth';
101102
102103
const data = ref({});
103104
@@ -343,7 +344,7 @@ onMounted(async () => {
343344
try {
344345
data.value = await callApi({path: '/api/dashboard/', method: 'GET'});
345346
} catch (error) {
346-
window.adminforth.alert({
347+
adminforth.alert({
347348
message: `Error fetching data: ${error.message}`,
348349
variant: 'danger',
349350
timeout: 'unlimited'

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ Create a Vue component in the custom directory of your project, e.g. Alerts.vue:
1919
</div>
2020
</template>
2121
<script setup>
22-
22+
import adminforth from '@/adminforth';
2323
import { useI18n } from 'vue-i18n';
2424
const { t } = useI18n();
2525
2626
function callAlert(message,variant='success'){
27-
window.adminforth.alert({message: message, variant: variant})
27+
adminforth.alert({message: message, variant: variant})
2828
};
2929
async function callConfirmation(){
30-
const isConfirmed = await window.adminforth.confirm({message: t('Are you sure?'), yes: t('Yes'), no: t('No')})
30+
const isConfirmed = await adminforth.confirm({message: t('Are you sure?'), yes: t('Yes'), no: t('No')})
3131
}
3232
</script>
3333
```

adminforth/documentation/docs/tutorial/03-Customization/08-pageInjections.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Now create file `ApartsPie.vue` in the `custom` folder of your project:
3939
import { onMounted, ref, Ref } from 'vue';
4040
import ApexCharts from 'apexcharts';
4141
import { callApi } from '@/utils';
42+
import adminforth from '@/adminforth';
4243
4344
4445
const data: Ref<any[]> = ref([]);
@@ -56,10 +57,10 @@ const chatOptions = {
5657
dataPointSelection: function (event, chartContext, config) {
5758
if (config.selectedDataPoints[0].length) {
5859
const selectedRoomsCount = data.value[config.dataPointIndex].rooms;
59-
window.adminforth.list.updateFilter({field: 'number_of_rooms', operator: 'eq', value: selectedRoomsCount});
60+
adminforth.list.updateFilter({field: 'number_of_rooms', operator: 'eq', value: selectedRoomsCount});
6061
} else {
6162
// clear filter
62-
window.adminforth.list.updateFilter({field: 'number_of_rooms', value: undefined});
63+
adminforth.list.updateFilter({field: 'number_of_rooms', value: undefined});
6364
}
6465
}
6566
},
@@ -117,7 +118,7 @@ onMounted(async () => {
117118
try {
118119
data.value = await callApi({path: '/api/aparts-by-room-percentages', method: 'GET'});
119120
} catch (error) {
120-
window.adminforth.alert({
121+
adminforth.alert({
121122
message: `Error fetching data: ${error.message}`,
122123
variant: 'danger',
123124
timeout: 'unlimited'
@@ -177,7 +178,7 @@ Also we have to add an Api to get percentages:
177178
admin.express.serve(app)
178179
```
179180

180-
> ☝️ Please note that we are using [Frontend API](/docs/api/types/FrontendAPI/interfaces/FrontendAPIInterface/) `window.adminforth.list.updateFilter({field: 'number_of_rooms', operator: 'eq', value: selectedRoomsCount});` to set filter when we are located on apartments list page
181+
> ☝️ Please note that we are using [Frontend API](/docs/api/types/FrontendAPI/interfaces/FrontendAPIInterface/) `adminforth.list.updateFilter({field: 'number_of_rooms', operator: 'eq', value: selectedRoomsCount});` to set filter when we are located on apartments list page
181182
182183
Here is how it looks:
183184
![alt text](<Page Injections.png>)
@@ -294,17 +295,18 @@ Now create file `CheckReadingTime.vue` in the `custom` folder of your project:
294295

295296
<script setup>
296297
import { getReadingTime} from "text-analyzer";
298+
import adminforth from '@/adminforth';
297299
298300
function checkReadingTime() {
299301
const text = document.querySelector('[data-af-column="description"]')?.innerText;
300302
if (text) {
301303
const readingTime = getReadingTime(text);
302-
window.adminforth.alert({
304+
adminforth.alert({
303305
message: `Reading time: ${readingTime.minutes} minutes`,
304306
variant: 'success',
305307
});
306308
}
307-
window.adminforth.list.closeThreeDotsDropdown();
309+
adminforth.list.closeThreeDotsDropdown();
308310
}
309311
</script>
310312
```
@@ -319,7 +321,7 @@ npm install text-analyzer --save
319321
```
320322
321323
322-
> ☝️ Please note that we are using AdminForth [Frontend API](/docs/api/types/FrontendAPI/interfaces/FrontendAPIInterface/) `window.adminforth.list.closeThreeDotsDropdown();` to close the dropdown after the item is clicked.
324+
> ☝️ Please note that we are using AdminForth [Frontend API](/docs/api/types/FrontendAPI/interfaces/FrontendAPIInterface/) `adminforth.list.closeThreeDotsDropdown();` to close the dropdown after the item is clicked.
323325
324326
325327
## List table custom action icons
@@ -392,7 +394,7 @@ You have opportunity to inject custom components to the global layout. For examp
392394
393395
![alt text](<Group 6.png>)
394396
395-
use `window.adminforth.closeUserMenuDropdown();` to close the dropdown after the item is clicked.
397+
use `adminforth.closeUserMenuDropdown();` to close the dropdown after the item is clicked.
396398
397399
```ts title="/index.ts"
398400
{
@@ -418,12 +420,14 @@ Now create file `CustomUserMenuItem.vue` in the `custom` folder of your project:
418420
</template>
419421
420422
<script setup>
423+
import adminforth from '@/adminforth';
424+
421425
function openCustomPage() {
422-
window.adminforth.alert({
426+
adminforth.alert({
423427
message: 'Custom page is opened',
424428
variant: 'success',
425429
});
426-
window.adminforth.closeUserMenuDropdown();
430+
adminforth.closeUserMenuDropdown();
427431
}
428432
</script>
429433
```

adminforth/documentation/docs/tutorial/03-Customization/10-menuConfiguration.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ Most times you need to refresh the badge from some backend API or hook. To do th
222222
More rare case when you need to refresh menu item from the frontend component. You can achieve this by calling the next method:
223223

224224
```typescript
225-
window.adminforth.menu.refreshMenuBadges()
225+
import adminforth from '@/adminforth';
226+
227+
adminforth.menu.refreshMenuBadges()
226228
```
227229

adminforth/documentation/docs/tutorial/05-Plugins/10-i18n.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ For simple example let's move previous example to format string on the backend s
329329
import type { AdminForthResourceColumnCommon, AdminForthResourceCommon, AdminUser } from '@/types/Common';
330330
import { callApi } from '@/utils';
331331
import { ref, onMounted } from 'vue';
332+
import adminforth from '@/adminforth';
332333

333334
const greeting: Ref<string> = ref('');
334335

@@ -337,7 +338,7 @@ onMounted(async () => {
337338
const data = await callApi({path: '/api/greeting', method: 'GET'});
338339
greeting.value = data.text;
339340
} catch (error) {
340-
window.adminforth.alert({
341+
adminforth.alert({
341342
message: `Error fetching data: ${error.message}`,
342343
variant: 'danger',
343344
timeout: 'unlimited'

adminforth/documentation/docs/tutorial/06-Advanced/01-plugin-development.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,31 @@ Now we have to create custom Vue component which will be used in plugin. To do i
210210
mkdir -p af-plugin-chatgpt/custom
211211
```
212212

213+
Also create `tsconfig.ts` file so your IDE will be able to resolve adminforth spa imports:
214+
215+
```json title='./af-plugin-chatgpt/custom/tsconfig.json'
216+
{
217+
"compilerOptions": {
218+
"baseUrl": ".", // This should point to your project root
219+
"paths": {
220+
"@/*": [
221+
// "node_modules/adminforth/dist/spa/src/*"
222+
"../../../spa/src/*"
223+
],
224+
"*": [
225+
// "node_modules/adminforth/dist/spa/node_modules/*"
226+
"../../../spa/node_modules/*"
227+
],
228+
"@@/*": [
229+
// "node_modules/adminforth/dist/spa/src/*"
230+
"."
231+
]
232+
}
233+
}
234+
}
235+
```
236+
237+
213238
We will use `vue-suggestion-input` package in our frontend component.
214239
To install package into frontend component, first of all we have to initialize npm package in custom folder:
215240

adminforth/plugins/email-password-reset/custom/ResetPassword.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ import { useRoute, useRouter } from 'vue-router';
159159
import { IconEyeSolid, IconEyeSlashSolid } from '@iconify-prerendered/vue-flowbite';
160160
import Button from '@/afcl/Button.vue';
161161
import Link from '@/afcl/Link.vue';
162+
import adminforth from '@/adminforth';
162163
163164
const inProgress = ref(false);
164165
@@ -279,7 +280,7 @@ async function setNewPassword() {
279280
} else {
280281
error.value = null;
281282
router.push('/login');
282-
window.adminforth.alert({
283+
adminforth.alert({
283284
message: 'Password reset successfully. Please login with your new password',
284285
variant: 'success',
285286
timeout: 15,
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"compilerOptions": {
3+
"baseUrl": ".", // This should point to your project root
4+
"paths": {
5+
"@/*": [
6+
// "node_modules/adminforth/dist/spa/src/*"
7+
"../../../spa/src/*"
8+
],
9+
"*": [
10+
// "node_modules/adminforth/dist/spa/node_modules/*"
11+
"../../../spa/node_modules/*"
12+
],
13+
"@@/*": [
14+
// "node_modules/adminforth/dist/spa/src/*"
15+
"."
16+
]
17+
}
18+
}
19+
}

adminforth/plugins/import-export/custom/ExportCsv.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { onMounted, ref } from 'vue';
1515
import { useCoreStore } from '@/stores/core';
1616
import { callAdminForthApi, loadFile } from '@/utils';
1717
import { useFiltersStore } from '@/stores/filters';
18+
import adminforth from '@/adminforth';
1819
1920
2021
const filtersStore = useFiltersStore();
@@ -55,16 +56,16 @@ async function exportCsv() {
5556
});
5657
inProgress.value = false;
5758
if (resp.error) {
58-
window.adminforth.alert({
59+
adminforth.alert({
5960
message: resp.error,
6061
})
6162
} else {
6263
loadFile(resp.data, `export-${coreStore.resource.resourceId}-${new Date().toISOString()}.csv`);
63-
window.adminforth.alert({
64+
adminforth.alert({
6465
message: `Exported ${resp.exportedCount} item${resp.exportedCount > 1 ? 's' : ''} successfully. Check your downloads folder`,
6566
})
6667
}
67-
window.adminforth.list.closeThreeDotsDropdown();
68+
adminforth.list.closeThreeDotsDropdown();
6869
}
6970
7071

adminforth/plugins/import-export/custom/ImportCsv.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<script setup lang="ts">
1212
import { ref, Ref } from 'vue';
1313
import { callAdminForthApi } from '@/utils';
14+
import adminforth from '@/adminforth';
1415
1516
const inProgress: Ref<boolean> = ref(false);
1617
@@ -33,16 +34,16 @@ async function postData(data: Record<string, string[]>) {
3334
inProgress.value = false;
3435
3536
if (resp.importedCount > 0) {
36-
window.adminforth.list.refresh();
37+
adminforth.list.refresh();
3738
}
38-
window.adminforth.alert({
39+
adminforth.alert({
3940
message: `Imported count ${resp.importedCount || 0} records. ${resp.errors?.length ? `Errors: ${resp.errors.join(', ')}` : ''}`,
4041
variant: resp.errors?.length ? (
4142
resp.importedCount ? 'warning' : 'danger'
4243
) : 'success'
4344
});
4445
45-
window.adminforth.list.closeThreeDotsDropdown();
46+
adminforth.list.closeThreeDotsDropdown();
4647
}
4748
4849
async function importCsv() {

0 commit comments

Comments
 (0)