adminforth 1.3.54-next.24 → 1.3.54-next.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -2
- package/spa/.eslintrc.cjs +14 -0
- package/spa/README.md +39 -0
- package/spa/env.d.ts +1 -0
- package/spa/index.html +23 -0
- package/spa/package-lock.json +4659 -0
- package/spa/package.json +52 -0
- package/spa/postcss.config.js +6 -0
- package/spa/public/assets/favicon.png +0 -0
- package/spa/src/App.vue +418 -0
- package/spa/src/assets/base.css +2 -0
- package/spa/src/assets/logo.svg +19 -0
- package/spa/src/components/AcceptModal.vue +45 -0
- package/spa/src/components/Breadcrumbs.vue +41 -0
- package/spa/src/components/BreadcrumbsWithButtons.vue +26 -0
- package/spa/src/components/CustomDatePicker.vue +176 -0
- package/spa/src/components/CustomDateRangePicker.vue +218 -0
- package/spa/src/components/CustomRangePicker.vue +156 -0
- package/spa/src/components/Dropdown.vue +168 -0
- package/spa/src/components/Filters.vue +222 -0
- package/spa/src/components/HelloWorld.vue +17 -0
- package/spa/src/components/MenuLink.vue +27 -0
- package/spa/src/components/ResourceForm.vue +325 -0
- package/spa/src/components/ResourceListTable.vue +466 -0
- package/spa/src/components/SingleSkeletLoader.vue +13 -0
- package/spa/src/components/SkeleteLoader.vue +23 -0
- package/spa/src/components/ThreeDotsMenu.vue +43 -0
- package/spa/src/components/Toast.vue +78 -0
- package/spa/src/components/ValueRenderer.vue +141 -0
- package/spa/src/components/icons/IconCalendar.vue +5 -0
- package/spa/src/components/icons/IconCommunity.vue +7 -0
- package/spa/src/components/icons/IconDocumentation.vue +7 -0
- package/spa/src/components/icons/IconEcosystem.vue +7 -0
- package/spa/src/components/icons/IconSupport.vue +7 -0
- package/spa/src/components/icons/IconTime.vue +5 -0
- package/spa/src/components/icons/IconTooling.vue +19 -0
- package/spa/src/composables/useFrontendApi.ts +26 -0
- package/spa/src/composables/useStores.ts +131 -0
- package/spa/src/index.scss +31 -0
- package/spa/src/main.ts +18 -0
- package/spa/src/renderers/CompactUUID.vue +48 -0
- package/spa/src/renderers/CountryFlag.vue +69 -0
- package/spa/src/router/index.ts +59 -0
- package/spa/src/spa_types/core.ts +53 -0
- package/spa/src/stores/core.ts +148 -0
- package/spa/src/stores/filters.ts +27 -0
- package/spa/src/stores/modal.ts +48 -0
- package/spa/src/stores/toast.ts +31 -0
- package/spa/src/stores/user.ts +72 -0
- package/spa/src/utils.ts +160 -0
- package/spa/src/views/CreateView.vue +167 -0
- package/spa/src/views/EditView.vue +170 -0
- package/spa/src/views/ListView.vue +352 -0
- package/spa/src/views/LoginView.vue +192 -0
- package/spa/src/views/ResourceParent.vue +17 -0
- package/spa/src/views/ShowView.vue +194 -0
- package/spa/tailwind.config.js +17 -0
- package/spa/tsconfig.app.json +14 -0
- package/spa/tsconfig.json +11 -0
- package/spa/tsconfig.node.json +19 -0
- package/spa/vite.config.ts +56 -0
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="relative">
|
|
3
|
+
<component
|
|
4
|
+
v-for="c in coreStore?.resourceOptions?.pageInjections?.edit?.beforeBreadcrumbs || []"
|
|
5
|
+
:is="getCustomComponent(c)"
|
|
6
|
+
:meta="c.meta"
|
|
7
|
+
:record="editableRecord"
|
|
8
|
+
:resource="coreStore.resource"
|
|
9
|
+
:adminUser="coreStore.adminUser"
|
|
10
|
+
/>
|
|
11
|
+
|
|
12
|
+
<BreadcrumbsWithButtons>
|
|
13
|
+
<!-- save and cancle -->
|
|
14
|
+
<button @click="$router.back()"
|
|
15
|
+
class="flex items-center py-1 px-3 me-2 text-sm font-medium text-gray-900 rounded-default focus:outline-none bg-white rounded border border-gray-300 hover:bg-gray-100 hover:text-lightPrimary focus:z-10 focus:ring-4 focus:ring-gray-100 dark:focus:ring-gray-700 dark:bg-gray-800 dark:text-gray-400 dark:border-gray-600 dark:hover:text-white dark:hover:bg-gray-700"
|
|
16
|
+
>
|
|
17
|
+
Cancel
|
|
18
|
+
</button>
|
|
19
|
+
|
|
20
|
+
<button
|
|
21
|
+
@click="saveRecord"
|
|
22
|
+
class="flex items-center py-1 px-3 text-sm font-medium rounded-default text-red-600 focus:outline-none bg-white rounded border border-gray-300 hover:bg-gray-100 hover:text-red-700 focus:z-10 focus:ring-4 focus:ring-gray-100 dark:focus:ring-gray-700 dark:bg-gray-800 dark:text-red-500 dark:border-gray-600 dark:hover:text-white dark:hover:bg-gray-700 disabled:opacity-50"
|
|
23
|
+
:disabled="saving || (validating && !isValid)"
|
|
24
|
+
>
|
|
25
|
+
<IconFloppyDiskSolid class="w-4 h-4" />
|
|
26
|
+
Save
|
|
27
|
+
</button>
|
|
28
|
+
|
|
29
|
+
<ThreeDotsMenu
|
|
30
|
+
:threeDotsDropdownItems="coreStore.resourceOptions?.pageInjections?.edit?.threeDotsDropdownItems"
|
|
31
|
+
></ThreeDotsMenu>
|
|
32
|
+
|
|
33
|
+
</BreadcrumbsWithButtons>
|
|
34
|
+
|
|
35
|
+
<component
|
|
36
|
+
v-for="c in coreStore?.resourceOptions?.pageInjections?.edit?.afterBreadcrumbs || []"
|
|
37
|
+
:is="getCustomComponent(c)"
|
|
38
|
+
:meta="c.meta"
|
|
39
|
+
:record="coreStore.record"
|
|
40
|
+
:resource="coreStore.resource"
|
|
41
|
+
:adminUser="coreStore.adminUser"
|
|
42
|
+
/>
|
|
43
|
+
|
|
44
|
+
<SingleSkeletLoader v-if="loading"></SingleSkeletLoader>
|
|
45
|
+
|
|
46
|
+
<ResourceForm
|
|
47
|
+
v-else
|
|
48
|
+
:record="editableRecord"
|
|
49
|
+
:resource="coreStore.resource"
|
|
50
|
+
:adminUser="coreStore.adminUser"
|
|
51
|
+
@update:record="onUpdateRecord"
|
|
52
|
+
@update:isValid="isValid = $event"
|
|
53
|
+
:validating="validating"
|
|
54
|
+
:source="'edit'"
|
|
55
|
+
>
|
|
56
|
+
</ResourceForm>
|
|
57
|
+
|
|
58
|
+
<component
|
|
59
|
+
v-for="c in coreStore?.resourceOptions?.pageInjections?.edit?.bottom || []"
|
|
60
|
+
:is="getCustomComponent(c)"
|
|
61
|
+
:meta="c.meta"
|
|
62
|
+
:record="coreStore.record"
|
|
63
|
+
:resource="coreStore.resource"
|
|
64
|
+
:adminUser="coreStore.adminUser"
|
|
65
|
+
/>
|
|
66
|
+
|
|
67
|
+
</div>
|
|
68
|
+
</template>
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
<script setup>
|
|
72
|
+
|
|
73
|
+
import BreadcrumbsWithButtons from '@/components/BreadcrumbsWithButtons.vue';
|
|
74
|
+
import ResourceForm from '@/components/ResourceForm.vue';
|
|
75
|
+
import SingleSkeletLoader from '@/components/SingleSkeletLoader.vue';
|
|
76
|
+
import { useCoreStore } from '@/stores/core';
|
|
77
|
+
import { callAdminForthApi, getCustomComponent,checkAcessByAllowedActions, initThreeDotsDropdown } from '@/utils';
|
|
78
|
+
import { IconFloppyDiskSolid } from '@iconify-prerendered/vue-flowbite';
|
|
79
|
+
import { computed, onMounted, ref } from 'vue';
|
|
80
|
+
import { useRoute, useRouter } from 'vue-router';
|
|
81
|
+
import { showErrorTost } from '@/composables/useFrontendApi';
|
|
82
|
+
import ThreeDotsMenu from '@/components/ThreeDotsMenu.vue';
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
const coreStore = useCoreStore();
|
|
86
|
+
|
|
87
|
+
const isValid = ref(false);
|
|
88
|
+
const validating = ref(false);
|
|
89
|
+
|
|
90
|
+
const route = useRoute();
|
|
91
|
+
const router = useRouter();
|
|
92
|
+
|
|
93
|
+
const loading = ref(true);
|
|
94
|
+
|
|
95
|
+
const saving = ref(false);
|
|
96
|
+
|
|
97
|
+
const record = ref({});
|
|
98
|
+
|
|
99
|
+
async function onUpdateRecord(newRecord) {
|
|
100
|
+
record.value = newRecord;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const editableRecord = computed(() => {
|
|
104
|
+
const newRecord = { ...coreStore.record };
|
|
105
|
+
if (!coreStore.resource) {
|
|
106
|
+
return {};
|
|
107
|
+
}
|
|
108
|
+
coreStore.resource.columns.forEach(column => {
|
|
109
|
+
if (column.foreignResource) {
|
|
110
|
+
newRecord[column.name] = newRecord[column.name]?.pk
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
return newRecord;
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
onMounted(async () => {
|
|
117
|
+
loading.value = true;
|
|
118
|
+
|
|
119
|
+
await coreStore.fetchResourceFull({
|
|
120
|
+
resourceId: route.params.resourceId
|
|
121
|
+
});
|
|
122
|
+
initThreeDotsDropdown();
|
|
123
|
+
|
|
124
|
+
await coreStore.fetchRecord({
|
|
125
|
+
resourceId: route.params.resourceId,
|
|
126
|
+
primaryKey: route.params.primaryKey,
|
|
127
|
+
});
|
|
128
|
+
checkAcessByAllowedActions(coreStore.resourceOptions.allowedActions,'edit');
|
|
129
|
+
loading.value = false;
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
async function saveRecord() {
|
|
133
|
+
if (!isValid.value) {
|
|
134
|
+
validating.value = true;
|
|
135
|
+
return;
|
|
136
|
+
} else {
|
|
137
|
+
validating.value = false;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
saving.value = true;
|
|
141
|
+
const updates = {};
|
|
142
|
+
for (const key in record.value) {
|
|
143
|
+
if (record.value[key] !== coreStore.record[key]) {
|
|
144
|
+
updates[key] = record.value[key];
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const resp = await callAdminForthApi({
|
|
149
|
+
method: 'POST',
|
|
150
|
+
path: `/update_record`,
|
|
151
|
+
body: {
|
|
152
|
+
resourceId: route.params.resourceId,
|
|
153
|
+
recordId: route.params.primaryKey,
|
|
154
|
+
record: updates,
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
if (resp.error) {
|
|
158
|
+
showErrorTost(resp.error);
|
|
159
|
+
} else {
|
|
160
|
+
window.adminforth.alert({
|
|
161
|
+
message: 'Record updated successfully',
|
|
162
|
+
variant: 'success',
|
|
163
|
+
timeout: 400000
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
saving.value = false;
|
|
167
|
+
router.push({ name: 'resource-show', params: { resourceId: route.params.resourceId, primaryKey: coreStore.record[coreStore.primaryKey] } });
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
</script>
|
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="relative">
|
|
3
|
+
<Teleport to="body">
|
|
4
|
+
<Filters
|
|
5
|
+
:columns="coreStore.resource?.columns"
|
|
6
|
+
:columnsMinMax="columnsMinMax" :show="filtersShow"
|
|
7
|
+
@hide="filtersShow = false"
|
|
8
|
+
/>
|
|
9
|
+
</Teleport>
|
|
10
|
+
|
|
11
|
+
<component
|
|
12
|
+
v-for="c in coreStore?.resourceOptions?.pageInjections?.list?.beforeBreadcrumbs || []"
|
|
13
|
+
:is="getCustomComponent(c)"
|
|
14
|
+
:meta="c.meta"
|
|
15
|
+
:resource="coreStore.resource"
|
|
16
|
+
:adminUser="coreStore.adminUser"
|
|
17
|
+
/>
|
|
18
|
+
|
|
19
|
+
<BreadcrumbsWithButtons>
|
|
20
|
+
<button
|
|
21
|
+
@click="()=>{checkboxes = []}"
|
|
22
|
+
v-if="checkboxes.length"
|
|
23
|
+
data-tooltip-target="tooltip-remove-all"
|
|
24
|
+
class="flex gap-1 items-center py-1 px-3 me-2 text-sm font-medium text-gray-900 focus:outline-none bg-white rounded border border-gray-300 hover:bg-gray-100 hover:text-lightPrimary focus:z-10 focus:ring-4 focus:ring-gray-100 dark:focus:ring-gray-700 dark:bg-darkListTable dark:text-gray-400 dark:border-gray-600 dark:hover:text-white dark:hover:bg-gray-700 rounded-default"
|
|
25
|
+
>
|
|
26
|
+
<IconBanOutline class="w-5 h-5 "/>
|
|
27
|
+
|
|
28
|
+
<div id="tooltip-remove-all" role="tooltip"
|
|
29
|
+
class="absolute z-10 invisible inline-block px-3 py-2 text-sm font-medium text-white transition-opacity duration-300 bg-gray-900 rounded-lg shadow-sm opacity-0 tooltip dark:bg-gray-700">
|
|
30
|
+
Remove selection
|
|
31
|
+
<div class="tooltip-arrow" data-popper-arrow></div>
|
|
32
|
+
</div>
|
|
33
|
+
</button>
|
|
34
|
+
|
|
35
|
+
<button
|
|
36
|
+
v-if="checkboxes.length"
|
|
37
|
+
v-for="(action,i) in coreStore.resource?.options?.bulkActions"
|
|
38
|
+
:key="action.id"
|
|
39
|
+
@click="startBulkAction(action.id)"
|
|
40
|
+
class="flex gap-1 items-center py-1 px-3 text-sm font-medium text-gray-900 focus:outline-none bg-white rounded-default border border-gray-300 hover:bg-gray-100 hover:text-lightPrimary focus:z-10 focus:ring-4 focus:ring-gray-100 dark:focus:ring-gray-700 dark:bg-gray-800 dark:text-gray-400 dark:border-gray-600 dark:hover:text-white dark:hover:bg-gray-700"
|
|
41
|
+
:class="{'bg-red-100 text-red-800 border-red-400 dark:bg-red-700 dark:text-red-400 dark:border-red-400':action.state==='danger', 'bg-green-100 text-green-800 border-green-400 dark:bg-green-700 dark:text-green-400 dark:border-green-400':action.state==='success',
|
|
42
|
+
'bg-lightPrimaryOpacity text-lightPrimary border-blue-400 dark:bg-blue-700 dark:text-blue-400 dark:border-blue-400':action.state==='active',
|
|
43
|
+
}"
|
|
44
|
+
>
|
|
45
|
+
<component
|
|
46
|
+
v-if="action.icon"
|
|
47
|
+
:is="getIcon(action.icon)"
|
|
48
|
+
class="w-5 h-5 text-gray-500 transition duration-75 dark:text-gray-400 group-hover:text-gray-900 dark:group-hover:text-white"></component>
|
|
49
|
+
|
|
50
|
+
{{ `${action.label} (${checkboxes.length})` }}
|
|
51
|
+
</button>
|
|
52
|
+
|
|
53
|
+
<RouterLink v-if="coreStore.resource?.options?.allowedActions?.create"
|
|
54
|
+
:to="{ name: 'resource-create', params: { resourceId: $route.params.resourceId } }"
|
|
55
|
+
class="flex items-center py-1 px-3 text-sm font-medium text-gray-900 focus:outline-none bg-white rounded border border-gray-300 hover:bg-gray-100 hover:text-lightPrimary focus:z-10 focus:ring-4 focus:ring-gray-100 dark:focus:ring-gray-700 dark:bg-gray-800 dark:text-gray-400 dark:border-gray-600 dark:hover:text-white dark:hover:bg-gray-700 rounded-default"
|
|
56
|
+
>
|
|
57
|
+
<IconPlusOutline class="w-4 h-4 me-2"/>
|
|
58
|
+
Create
|
|
59
|
+
</RouterLink>
|
|
60
|
+
|
|
61
|
+
<button
|
|
62
|
+
class="flex gap-1 items-center py-1 px-3 me-2 text-sm font-medium text-gray-900 focus:outline-none bg-white rounded border border-gray-300 hover:bg-gray-100 hover:text-lightPrimary focus:z-10 focus:ring-4 focus:ring-gray-100 dark:focus:ring-gray-700 dark:bg-gray-800 dark:text-gray-400 dark:border-gray-600 dark:hover:text-white dark:hover:bg-gray-700 rounded-default"
|
|
63
|
+
@click="()=>{filtersShow = !filtersShow}"
|
|
64
|
+
v-if="coreStore.resource?.options?.allowedActions?.filter"
|
|
65
|
+
>
|
|
66
|
+
<IconFilterOutline class="w-4 h-4 me-2"/>
|
|
67
|
+
Filter
|
|
68
|
+
<span
|
|
69
|
+
class="bg-red-100 text-red-800 text-xs font-medium me-2 px-2.5 py-0.5 rounded dark:bg-gray-700 dark:text-red-400 border border-red-400"
|
|
70
|
+
v-if="filtersStore.filters.length">
|
|
71
|
+
{{ filtersStore.filters.length }}
|
|
72
|
+
</span>
|
|
73
|
+
</button>
|
|
74
|
+
|
|
75
|
+
<ThreeDotsMenu
|
|
76
|
+
:threeDotsDropdownItems="coreStore.resourceOptions?.pageInjections?.list?.threeDotsDropdownItems"
|
|
77
|
+
></ThreeDotsMenu>
|
|
78
|
+
</BreadcrumbsWithButtons>
|
|
79
|
+
|
|
80
|
+
<component
|
|
81
|
+
v-for="c in coreStore?.resourceOptions?.pageInjections?.list?.afterBreadcrumbs || []"
|
|
82
|
+
:is="getCustomComponent(c)"
|
|
83
|
+
:meta="c.meta"
|
|
84
|
+
:resource="coreStore.resource"
|
|
85
|
+
:adminUser="coreStore.adminUser"
|
|
86
|
+
/>
|
|
87
|
+
|
|
88
|
+
<ResourceListTable
|
|
89
|
+
:resource="coreStore.resource"
|
|
90
|
+
:rows="rows"
|
|
91
|
+
:page="page"
|
|
92
|
+
@update:page="page = $event"
|
|
93
|
+
@update:sort="sort = $event"
|
|
94
|
+
@update:checkboxes="checkboxes = $event"
|
|
95
|
+
@update:records="getList"
|
|
96
|
+
:sort="sort"
|
|
97
|
+
:pageSize="pageSize"
|
|
98
|
+
:totalRows="totalRows"
|
|
99
|
+
:checkboxes="checkboxes"
|
|
100
|
+
/>
|
|
101
|
+
|
|
102
|
+
<component
|
|
103
|
+
v-for="c in coreStore?.resourceOptions?.pageInjections?.list?.bottom || []"
|
|
104
|
+
:is="getCustomComponent(c)"
|
|
105
|
+
:meta="c.meta"
|
|
106
|
+
:resource="coreStore.resource"
|
|
107
|
+
:adminUser="coreStore.adminUser"
|
|
108
|
+
/>
|
|
109
|
+
|
|
110
|
+
</div>
|
|
111
|
+
</template>
|
|
112
|
+
|
|
113
|
+
<script setup>
|
|
114
|
+
import BreadcrumbsWithButtons from '@/components/BreadcrumbsWithButtons.vue';
|
|
115
|
+
import ResourceListTable from '@/components/ResourceListTable.vue';
|
|
116
|
+
import { useCoreStore } from '@/stores/core';
|
|
117
|
+
import { useFiltersStore } from '@/stores/filters';
|
|
118
|
+
import { callAdminForthApi, currentQuery, getIcon, setQuery } from '@/utils';
|
|
119
|
+
import { computed, onMounted, ref, watch } from 'vue';
|
|
120
|
+
import { useRoute } from 'vue-router';
|
|
121
|
+
import { showErrorTost } from '@/composables/useFrontendApi'
|
|
122
|
+
import { getCustomComponent, initThreeDotsDropdown } from '@/utils';
|
|
123
|
+
import { initFlowbite } from 'flowbite';
|
|
124
|
+
import ThreeDotsMenu from '@/components/ThreeDotsMenu.vue';
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
import {
|
|
128
|
+
IconBanOutline,
|
|
129
|
+
IconFilterOutline,
|
|
130
|
+
IconPlusOutline
|
|
131
|
+
} from '@iconify-prerendered/vue-flowbite';
|
|
132
|
+
|
|
133
|
+
import Filters from '@/components/Filters.vue';
|
|
134
|
+
|
|
135
|
+
const filtersShow = ref(false);
|
|
136
|
+
|
|
137
|
+
const coreStore = useCoreStore();
|
|
138
|
+
const filtersStore = useFiltersStore();
|
|
139
|
+
|
|
140
|
+
const route = useRoute();
|
|
141
|
+
|
|
142
|
+
const page = ref(1);
|
|
143
|
+
const columnsMinMax = ref({});
|
|
144
|
+
const sort = ref([]);
|
|
145
|
+
|
|
146
|
+
watch(() => sort, async (to, from) => {
|
|
147
|
+
// in store sort might be needed for plugins
|
|
148
|
+
filtersStore.setSort(sort.value);
|
|
149
|
+
}, {deep: true});
|
|
150
|
+
|
|
151
|
+
const rows = ref(null);
|
|
152
|
+
const totalRows = ref(0);
|
|
153
|
+
const checkboxes = ref([]);
|
|
154
|
+
|
|
155
|
+
const DEFAULT_PAGE_SIZE = 10;
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
const pageSize = computed(() => coreStore.resource?.options?.listPageSize || DEFAULT_PAGE_SIZE);
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
async function getList() {
|
|
162
|
+
rows.value = null;
|
|
163
|
+
const data = await callAdminForthApi({
|
|
164
|
+
path: '/get_resource_data',
|
|
165
|
+
method: 'POST',
|
|
166
|
+
body: {
|
|
167
|
+
source: 'list',
|
|
168
|
+
resourceId: route.params.resourceId,
|
|
169
|
+
limit: pageSize.value,
|
|
170
|
+
offset: ((page.value || 1) - 1) * pageSize.value,
|
|
171
|
+
filters: filtersStore.filters,
|
|
172
|
+
sort: sort.value,
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
if (data.error) {
|
|
176
|
+
showErrorTost(data.error);
|
|
177
|
+
rows.value = [];
|
|
178
|
+
totalRows.value = 0;
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
rows.value = data.data?.map(row => {
|
|
182
|
+
row._primaryKeyValue = row[coreStore.resource.columns.find(c => c.primaryKey).name];
|
|
183
|
+
return row;
|
|
184
|
+
});
|
|
185
|
+
totalRows.value = data.total;
|
|
186
|
+
await new Promise(resolve => setTimeout(resolve, 0));
|
|
187
|
+
initFlowbite(); // for tooltips in table
|
|
188
|
+
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
async function startBulkAction(actionId) {
|
|
192
|
+
const action = coreStore.resource.options.bulkActions.find(a => a.id === actionId);
|
|
193
|
+
if (action.confirm) {
|
|
194
|
+
const confirmed = await window.adminforth.confirm({
|
|
195
|
+
message: action.confirm,
|
|
196
|
+
});
|
|
197
|
+
if (!confirmed) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const data = await callAdminForthApi({
|
|
203
|
+
path: '/start_bulk_action',
|
|
204
|
+
method: 'POST',
|
|
205
|
+
body: {
|
|
206
|
+
resourceId: route.params.resourceId,
|
|
207
|
+
actionId: actionId,
|
|
208
|
+
recordIds: checkboxes.value
|
|
209
|
+
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
if (data?.ok) {
|
|
213
|
+
checkboxes.value = [];
|
|
214
|
+
await getList();
|
|
215
|
+
|
|
216
|
+
if (data.successMessage) {
|
|
217
|
+
window.adminforth.alert({
|
|
218
|
+
message: data.successMessage,
|
|
219
|
+
variant: 'success'
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
}
|
|
224
|
+
if (data?.error) {
|
|
225
|
+
showErrorTost(data.error);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
class SortQuerySerializer {
|
|
231
|
+
static serialize(sort) {
|
|
232
|
+
return sort.map(s => `${s.field}__${s.direction}`).join(',');
|
|
233
|
+
}
|
|
234
|
+
static deserialize(str) {
|
|
235
|
+
return str.split(',').map(s => {
|
|
236
|
+
const [field, direction] = s.split('__');
|
|
237
|
+
return { field, direction };
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
async function init() {
|
|
244
|
+
|
|
245
|
+
await coreStore.fetchResourceFull({
|
|
246
|
+
resourceId: route.params.resourceId
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
initFlowbite();
|
|
250
|
+
|
|
251
|
+
// !!! clear filters should be in same tick with sort assignment so that watch can catch it as one change
|
|
252
|
+
|
|
253
|
+
// try to init filters from query params
|
|
254
|
+
const filters = Object.keys(route.query).filter(k => k.startsWith('filter__')).map(k => {
|
|
255
|
+
const [_, field, operator] = k.split('__');
|
|
256
|
+
return {
|
|
257
|
+
field,
|
|
258
|
+
operator,
|
|
259
|
+
value: JSON.parse(decodeURIComponent(route.query[k]))
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
if (filters.length) {
|
|
263
|
+
filtersStore.setFilters(filters);
|
|
264
|
+
} else {
|
|
265
|
+
filtersStore.clearFilters();
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
if (route.query.sort) {
|
|
269
|
+
sort.value = SortQuerySerializer.deserialize(route.query.sort);
|
|
270
|
+
} else if (coreStore.resource.options?.defaultSort) {
|
|
271
|
+
sort.value = [{
|
|
272
|
+
field: coreStore.resource.options.defaultSort.columnName,
|
|
273
|
+
direction: coreStore.resource.options.defaultSort.direction
|
|
274
|
+
}];
|
|
275
|
+
} else {
|
|
276
|
+
sort.value = [];
|
|
277
|
+
}
|
|
278
|
+
// page init should be also in same tick
|
|
279
|
+
if (route.query.page) {
|
|
280
|
+
page.value = parseInt(route.query.page);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// await getList(); - Not needed here, watch will trigger it
|
|
284
|
+
columnsMinMax.value = await callAdminForthApi({
|
|
285
|
+
path: '/get_min_max_for_columns',
|
|
286
|
+
method: 'POST',
|
|
287
|
+
body: {
|
|
288
|
+
resourceId: route.params.resourceId
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
watch([page, sort, () => filtersStore.filters], async () => {
|
|
294
|
+
console.log('🔄️ page/sort/filter change fired, page:', page.value);
|
|
295
|
+
|
|
296
|
+
await getList();
|
|
297
|
+
}, { deep: true });
|
|
298
|
+
|
|
299
|
+
window.adminforth.list.refresh = async () => {
|
|
300
|
+
await getList();
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
let initInProcess = false;
|
|
304
|
+
|
|
305
|
+
watch(() => filtersStore.filters, async (to, from) => {
|
|
306
|
+
if (initInProcess) {
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
console.log('🔄️ filters changed', JSON.stringify(to))
|
|
310
|
+
page.value = 1;
|
|
311
|
+
checkboxes.value = [];
|
|
312
|
+
// update query param for each filter as filter_<column_name>=value
|
|
313
|
+
const query = {};
|
|
314
|
+
const currentQ = currentQuery();
|
|
315
|
+
filtersStore.filters.forEach(f => {
|
|
316
|
+
if (f.value) {
|
|
317
|
+
query[`filter__${f.field}__${f.operator}`] = encodeURIComponent(JSON.stringify(f.value));
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
// set every key in currentQ which starts with filter_ to undefined if it is not in query
|
|
321
|
+
Object.keys(currentQ).forEach(k => {
|
|
322
|
+
if (k.startsWith('filter_') && !query[k]) {
|
|
323
|
+
query[k] = undefined;
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
setQuery(query);
|
|
327
|
+
}, {deep: true});
|
|
328
|
+
|
|
329
|
+
onMounted(async () => {
|
|
330
|
+
initInProcess = true;
|
|
331
|
+
await init();
|
|
332
|
+
initThreeDotsDropdown();
|
|
333
|
+
initInProcess = false;
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
watch([page], async () => {
|
|
337
|
+
setQuery({ page: page.value });
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
watch([sort], async () => {
|
|
344
|
+
if (!sort.value.length) {
|
|
345
|
+
setQuery({ sort: undefined });
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
setQuery({ sort: SortQuerySerializer.serialize(sort.value) });
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
</script>
|