Skip to content

Commit d59121d

Browse files
committed
initial version
1 parent b4bc9fe commit d59121d

File tree

8 files changed

+629
-0
lines changed

8 files changed

+629
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
custom/node_modules
3+
dist

Changelog.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [1.0.27]
9+
10+
### Fixed
11+
12+
- Modify InlineList add loading state for bulk actions
13+
14+
## [1.0.26]
15+
16+
### Fixed
17+
18+
- Modify Resource Config did not support allowedActions, now it does
19+
- Modify Resource Config did not support bulkActions, now it does

custom/InlineList.vue

Lines changed: 292 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,292 @@
1+
<template>
2+
<Teleport to="body">
3+
<!-- todo exclude foreign column-->
4+
<Filters
5+
v-if="listResource"
6+
:columns="listResource.columns.filter((c) => c.name !== listResourceRefColumn.name)"
7+
v-model:filters="filters"
8+
:columnsMinMax="columnsMinMax"
9+
:show="filtersShow"
10+
@hide="filtersShow = false"
11+
/>
12+
</Teleport>
13+
14+
<td colspan="2" class="pb-3">
15+
<div class="flex items-center gap-1">
16+
<h4 v-if="listResource"
17+
class="px-6 py-4"
18+
>{{ listResource.label }} {{$t('inline records')}}</h4>
19+
20+
<button
21+
@click="()=>{checkboxes = []}"
22+
v-if="checkboxes.length"
23+
data-tooltip-target="tooltip-remove-all"
24+
data-tooltip-placement="bottom"
25+
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-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"
26+
>
27+
<IconBanOutline class="w-5 h-5 "/>
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+
{{$t('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 listResource?.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="{
42+
'bg-red-100 text-red-800 border-red-400 dark:bg-red-700 dark:text-red-400 dark:border-red-400': action.state==='danger',
43+
'bg-green-100 text-green-800 border-green-400 dark:bg-green-700 dark:text-green-400 dark:border-green-400':action.state==='success',
44+
'bg-lightPrimaryOpacity text-lightPrimary border-blue-400 dark:bg-blue-700 dark:text-blue-400 dark:border-blue-400':action.state==='active',
45+
}"
46+
>
47+
<component
48+
v-if="action.icon && !bulkActionLoadingStates[action.id]"
49+
:is="getIcon(action.icon)"
50+
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">
51+
</component>
52+
<div v-if="bulkActionLoadingStates[action.id]">
53+
<svg
54+
aria-hidden="true"
55+
class="w-5 h-5 animate-spin"
56+
:class="{
57+
'text-gray-200 dark:text-gray-500 fill-gray-500 dark:fill-gray-300': action.state !== 'danger',
58+
'text-red-200 dark:text-red-800 fill-red-600 dark:fill-red-500': action.state === 'danger'
59+
}"
60+
viewBox="0 0 100 101"
61+
fill="none"
62+
xmlns="http://www.w3.org/2000/svg"
63+
>
64+
<path d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z" fill="currentColor"/>
65+
<path d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z" fill="currentFill"/>
66+
</svg>
67+
<span class="sr-only">Loading...</span>
68+
</div>
69+
70+
{{ `${action.label} (${checkboxes.length})` }}
71+
</button>
72+
73+
<RouterLink v-if="listResource?.options?.allowedActions?.create"
74+
:to="{
75+
name: 'resource-create',
76+
params: { resourceId: listResource.resourceId },
77+
query: {
78+
values: encodeURIComponent(JSON.stringify({[listResourceRefColumn.name]: props.record[selfPrimaryKeyColumn.name]})),
79+
returnTo: $route.fullPath,
80+
},
81+
}"
82+
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"
83+
>
84+
<IconPlusOutline class="w-4 h-4 me-2"/>
85+
{{$t('Create')}}
86+
</RouterLink>
87+
88+
<button
89+
v-if="listResource?.options?.allowedActions?.filter"
90+
class="flex gap-1 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"
91+
@click="()=>{filtersShow = !filtersShow}"
92+
>
93+
<IconFilterOutline class="w-4 h-4 me-2"/>
94+
{{$t('Filter')}}
95+
<span
96+
class="bg-red-100 text-red-800 text-xs font-medium px-2.5 py-0.5 rounded dark:bg-gray-700 dark:text-red-400 border border-red-400"
97+
v-if="filters.length">
98+
{{ filters.length }}
99+
</span>
100+
</button>
101+
102+
</div>
103+
104+
<ResourceListTable
105+
:noRoundings="true"
106+
:resource="listResource"
107+
:rows="rows"
108+
@update:page="page = $event"
109+
@update:sort="sort = $event"
110+
@update:checkboxes="checkboxes = $event"
111+
@update:records="getList"
112+
113+
:pageSize="pageSize"
114+
:totalRows="totalRows"
115+
:checkboxes="checkboxes"
116+
:customActionsInjection="listResource?.options?.pageInjections?.list?.customActionIcons"
117+
/>
118+
119+
</td>
120+
</template>
121+
122+
<script setup>
123+
import { callAdminForthApi } from '@/utils';
124+
import { ref, onMounted, watch, computed, nextTick } from 'vue';
125+
import ResourceListTable from '@/components/ResourceListTable.vue';
126+
import Filters from '@/components/Filters.vue';
127+
import {
128+
IconBanOutline,
129+
IconFilterOutline,
130+
IconPlusOutline,
131+
} from '@iconify-prerendered/vue-flowbite';
132+
import { showErrorTost } from '@/composables/useFrontendApi';
133+
import { getIcon } from '@/utils';
134+
135+
const props = defineProps(['column', 'record', 'meta', 'resource', 'adminUser']);
136+
137+
const listResource = ref(null);
138+
const loading = ref(true);
139+
140+
const page = ref(1);
141+
const sort = ref([]);
142+
const checkboxes = ref([]);
143+
const pageSize = computed(() => listResource.value?.options?.listPageSize || 10);
144+
145+
const rows = ref(null);
146+
const totalRows = ref(0);
147+
148+
const filters = ref([]);
149+
const filtersShow = ref(false);
150+
const columnsMinMax = ref(null);
151+
152+
const listResourceRefColumn = computed(() => {
153+
if (!listResource.value) {
154+
return null;
155+
}
156+
return listResource.value.columns.find(c => c.foreignResource?.resourceId === props.resource.resourceId);
157+
});
158+
159+
const selfPrimaryKeyColumn = computed(() => {
160+
return props.resource.columns.find(c => c.primaryKey);
161+
});
162+
163+
const endFilters = computed(() => {
164+
if (!listResource.value) {
165+
return [];
166+
}
167+
// get name of the column that is foreign key
168+
const refColumn = listResourceRefColumn.value;
169+
170+
const primaryKeyColumn = selfPrimaryKeyColumn.value;
171+
172+
if (!refColumn) {
173+
showErrorTost(`Column with foreignResource.resourceId which is equal to '${props.resource.resourceId}' not found in resource which is specified as foreighResourceId '${listResource.value.resourceId}'`,10000);
174+
return [];
175+
}
176+
return [
177+
...filters.value,
178+
{
179+
field: refColumn.name,
180+
operator: 'eq',
181+
value: props.record[primaryKeyColumn.name],
182+
},
183+
];
184+
});
185+
186+
watch([page], async () => {
187+
await getList();
188+
});
189+
190+
watch([sort], async () => {
191+
await getList();
192+
}, {deep: true});
193+
194+
watch([filters], async () => {
195+
page.value = 1;
196+
checkboxes.value = [];
197+
await getList();
198+
}, {deep: true});
199+
200+
const bulkActionLoadingStates = ref({});
201+
202+
async function startBulkAction(actionId) {
203+
const action = listResource.value.options.bulkActions.find(a => a.id === actionId);
204+
if (action.confirm) {
205+
const confirmed = await adminforth.confirm({
206+
message: action.confirm,
207+
});
208+
if (!confirmed) {
209+
return;
210+
}
211+
}
212+
bulkActionLoadingStates.value[actionId] = true;
213+
214+
const data = await callAdminForthApi({
215+
path: `/plugin/${props.meta.pluginInstanceId}/start_bulk_action`,
216+
method: 'POST',
217+
body: {
218+
resourceId: listResource.value.resourceId,
219+
actionId: actionId,
220+
recordIds: checkboxes.value
221+
}
222+
});
223+
bulkActionLoadingStates.value[actionId] = false;
224+
225+
if (data?.ok) {
226+
checkboxes.value = [];
227+
await getList();
228+
229+
if (data.successMessage) {
230+
adminforth.alert({
231+
message: data.successMessage,
232+
variant: 'success'
233+
});
234+
}
235+
}
236+
if (data?.error) {
237+
showErrorTost(data.error);
238+
}
239+
}
240+
241+
async function getList() {
242+
rows.value = null;
243+
const data = await callAdminForthApi({
244+
path: '/get_resource_data',
245+
method: 'POST',
246+
body: {
247+
source: 'list',
248+
resourceId: listResource.value.resourceId,
249+
limit: pageSize.value,
250+
offset: (page.value - 1) * pageSize.value,
251+
filters: endFilters.value,
252+
sort: sort.value,
253+
}
254+
});
255+
256+
if (data.error) {
257+
showErrorTost(data.error);
258+
rows.value = [];
259+
totalRows.value = 0;
260+
return;
261+
}
262+
263+
rows.value = data.data?.map(row => {
264+
row._primaryKeyValue = row[listResource.value.columns.find(c => c.primaryKey).name];
265+
return row;
266+
});
267+
totalRows.value = data.total;
268+
269+
await nextTick();
270+
}
271+
272+
onMounted( async () => {
273+
loading.value = true;
274+
const foreighResourceId = props.meta.foreignResourceId;
275+
listResource.value = (await callAdminForthApi({
276+
path: `/plugin/${props.meta.pluginInstanceId}/get_resource`,
277+
method: 'POST',
278+
body: {},
279+
})).resource;
280+
columnsMinMax.value = await callAdminForthApi({
281+
path: '/get_min_max_for_columns',
282+
method: 'POST',
283+
body: {
284+
resourceId: foreighResourceId,
285+
}
286+
});
287+
loading.value = false;
288+
await getList();
289+
290+
});
291+
292+
</script>

0 commit comments

Comments
 (0)