quasar-ui-danx 0.0.31 → 0.0.32
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +1 -1
- package/src/components/ActionTable/ActionMenu.vue +10 -3
- package/src/components/Utility/Popovers/PopoverMenu.vue +1 -0
- package/src/components/Utility/Tools/ActionPerformerTool.vue +9 -9
- package/src/helpers/http.ts +34 -34
- package/src/helpers/performAction.ts +13 -1
- package/src/styles/actions.scss +10 -0
package/package.json
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
<template>
|
2
2
|
<PopoverMenu
|
3
|
-
class="px-
|
3
|
+
class="px-2 flex action-button"
|
4
4
|
:items="activeItems"
|
5
|
+
:disabled="targets.length === 0"
|
5
6
|
@action-item="onAction"
|
6
|
-
|
7
|
+
>
|
8
|
+
<q-tooltip v-if="targets.length === 0">{{ tooltip }}</q-tooltip>
|
9
|
+
</PopoverMenu>
|
7
10
|
</template>
|
8
11
|
<script setup>
|
9
12
|
import { computed } from 'vue';
|
@@ -19,12 +22,16 @@ const props = defineProps({
|
|
19
22
|
targets: {
|
20
23
|
type: Array,
|
21
24
|
required: true
|
25
|
+
},
|
26
|
+
tooltip: {
|
27
|
+
type: String,
|
28
|
+
default: 'First select records to perform a batch action'
|
22
29
|
}
|
23
30
|
});
|
24
31
|
|
25
32
|
const activeItems = computed(() => props.items.filter(item => {
|
26
33
|
if (item.enabled === undefined) return true;
|
27
|
-
return typeof item.enabled === 'function' ? !!item.enabled(props.targets) : !!item.enabled;
|
34
|
+
return typeof item.enabled === 'function' ? !!item.enabled(props.targets?.[0] ?? null, props.targets) : !!item.enabled;
|
28
35
|
}));
|
29
36
|
|
30
37
|
function onAction(item) {
|
@@ -45,7 +45,15 @@ async function onConfirmAction(input) {
|
|
45
45
|
const result = await props.action.onAction(props.targets, input);
|
46
46
|
isSaving.value = false;
|
47
47
|
|
48
|
-
if (
|
48
|
+
if (result.success) {
|
49
|
+
FlashMessages.success(`The update was successful`);
|
50
|
+
|
51
|
+
if (props.action.onSuccess) {
|
52
|
+
await props.action.onSuccess(result, props.targets, input);
|
53
|
+
}
|
54
|
+
|
55
|
+
emit('done');
|
56
|
+
} else {
|
49
57
|
const errors = [];
|
50
58
|
if (result.errors) {
|
51
59
|
errors.push(...result.errors);
|
@@ -62,16 +70,8 @@ async function onConfirmAction(input) {
|
|
62
70
|
}
|
63
71
|
}
|
64
72
|
|
65
|
-
FlashMessages.success(`The update was successful`);
|
66
|
-
|
67
|
-
if (props.action.onSuccess) {
|
68
|
-
await props.action.onSuccess(result, props.targets, input);
|
69
|
-
}
|
70
|
-
|
71
73
|
if (props.action.onFinish) {
|
72
74
|
await props.action.onFinish(result, props.targets, input);
|
73
75
|
}
|
74
|
-
|
75
|
-
emit('done');
|
76
76
|
}
|
77
77
|
</script>
|
package/src/helpers/http.ts
CHANGED
@@ -1,26 +1,26 @@
|
|
1
1
|
export const request = {
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
2
|
+
async get(url, options = {}) {
|
3
|
+
return fetch(url, {
|
4
|
+
method: "get",
|
5
|
+
headers: {
|
6
|
+
Accept: "application/json",
|
7
|
+
"Content-Type": "application/json"
|
8
|
+
},
|
9
|
+
...options
|
10
|
+
}).then((r) => r.json());
|
11
|
+
},
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
13
|
+
async post(url, data = {}, options = {}) {
|
14
|
+
return fetch(url, {
|
15
|
+
method: "post",
|
16
|
+
body: JSON.stringify(data),
|
17
|
+
headers: {
|
18
|
+
Accept: "application/json",
|
19
|
+
"Content-Type": "application/json"
|
20
|
+
},
|
21
|
+
...options
|
22
|
+
}).then((r) => r.json());
|
23
|
+
}
|
24
24
|
};
|
25
25
|
|
26
26
|
/**
|
@@ -36,19 +36,19 @@ export const request = {
|
|
36
36
|
* @returns {Promise<void>}
|
37
37
|
*/
|
38
38
|
export async function fetchResourceListWithSelected(fetchFn, list, id, filter) {
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
39
|
+
// First make sure we have the selected record, so we can always add it to the list
|
40
|
+
let selectedResource;
|
41
|
+
if (id) {
|
42
|
+
selectedResource = list.value.find((c) => c.id === id) || (await fetchFn({ id }))[0];
|
43
|
+
}
|
44
44
|
|
45
|
-
|
46
|
-
|
45
|
+
// Get the filtered campaign list
|
46
|
+
list.value = await fetchFn(filter);
|
47
47
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
48
|
+
// If our selected campaign is not in the filtered list, add it
|
49
|
+
if (selectedResource && !list.value.find((c) => c.id === id)) {
|
50
|
+
list.value.push(selectedResource);
|
51
|
+
}
|
52
52
|
}
|
53
53
|
|
54
54
|
/**
|
@@ -57,6 +57,6 @@ export async function fetchResourceListWithSelected(fetchFn, list, id, filter) {
|
|
57
57
|
* @param url
|
58
58
|
*/
|
59
59
|
export function getUrlParam(key, url = undefined) {
|
60
|
-
|
61
|
-
|
60
|
+
const params = new URLSearchParams(url?.replace(/.*\?/, "") || window.location.search);
|
61
|
+
return params.get(key);
|
62
62
|
}
|
@@ -12,6 +12,17 @@ export const actionTargets = ref([]);
|
|
12
12
|
* @returns {{performAction(name, targets): Promise<void>}}
|
13
13
|
*/
|
14
14
|
export function usePerformAction(actions: any[]) {
|
15
|
+
|
16
|
+
function filterActions(filters) {
|
17
|
+
let filteredActions = [...actions];
|
18
|
+
|
19
|
+
for (const filter of Object.keys(filters)) {
|
20
|
+
const filterValue = filters[filter];
|
21
|
+
filteredActions = filteredActions.filter(a => a[filter] === filterValue || (Array.isArray(filterValue) && filterValue.includes(a[filter])));
|
22
|
+
}
|
23
|
+
return filteredActions;
|
24
|
+
}
|
25
|
+
|
15
26
|
return {
|
16
27
|
/**
|
17
28
|
* Perform an action on a set of targets
|
@@ -31,7 +42,8 @@ export function usePerformAction(actions: any[]) {
|
|
31
42
|
await performAction({ ...action, ...options }, targets);
|
32
43
|
},
|
33
44
|
|
34
|
-
|
45
|
+
actions,
|
46
|
+
filterActions,
|
35
47
|
};
|
36
48
|
}
|
37
49
|
|