quasar-ui-danx 0.0.32 → 0.0.34

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quasar-ui-danx",
3
- "version": "0.0.32",
3
+ "version": "0.0.34",
4
4
  "author": "Dan <dan@flytedesk.com>",
5
5
  "description": "DanX Vue / Quasar component library",
6
6
  "license": "MIT",
@@ -70,12 +70,13 @@
70
70
  {{ rowProps.value }}
71
71
  </slot>
72
72
  </div>
73
- <ActionMenu
74
- v-if="rowProps.col.actions" class="ml-2"
75
- :items="rowProps.col.actions"
76
- :targets="[rowProps.row]"
77
- @action="(action) => $emit('action', {action: action, row: rowProps.row})"
78
- />
73
+ <div v-if="rowProps.col.actions" class="flex-grow flex justify-end pl-2">
74
+ <ActionMenu
75
+ :items="rowProps.col.actions"
76
+ :targets="[rowProps.row]"
77
+ @action="(action) => $emit('action', {action: action, row: rowProps.row})"
78
+ />
79
+ </div>
79
80
  </component>
80
81
  </q-td>
81
82
  </template>
@@ -87,16 +87,21 @@ function toQDateValue(val) {
87
87
  }
88
88
 
89
89
  const dateRangeValue = computed(() => {
90
- let range = dateRange.value;
90
+ let range;
91
91
 
92
- if (typeof range === 'string') {
92
+ if (typeof dateRange.value === 'string') {
93
93
  range = {
94
- from: range,
95
- to: range
94
+ from: dateRange.value,
95
+ to: dateRange.value
96
+ };
97
+ } else if (dateRange.value) {
98
+ range = {
99
+ from: dateRange.value.from,
100
+ to: dateRange.value.to
96
101
  };
97
102
  }
98
103
 
99
- if (range?.from && range?.to && props.withTime) {
104
+ if (range?.from && range?.to && props.withTime && !range.from.includes('00:00:00')) {
100
105
  range.from += ' 00:00:00';
101
106
  range.to += ' 23:59:59';
102
107
  }
@@ -6,7 +6,6 @@ export * from "./listHelpers";
6
6
  export * from "./tableColumns";
7
7
  export { default as ActionMenu } from "./ActionMenu.vue";
8
8
  export { default as ActionTable } from "./ActionTable.vue";
9
- export { default as BatchActionMenu } from "./BatchActionMenu.vue";
10
9
  export { default as EmptyTableState } from "./EmptyTableState.vue";
11
10
  export { default as RenderComponent } from "./RenderComponent.vue";
12
11
  export { default as TableSummaryRow } from "./TableSummaryRow.vue";
@@ -2,18 +2,30 @@ import { computed, ref, watch } from "vue";
2
2
  import { getItem, setItem, waitForRef } from "../../helpers";
3
3
  import { getFilterFromUrl } from "./listHelpers";
4
4
 
5
- export function useListActions(name, {
5
+ interface ListActionsOptions {
6
+ listRoute: Function;
7
+ summaryRoute?: Function;
8
+ filterFieldOptionsRoute?: Function;
9
+ moreRoute?: Function;
10
+ applyActionRoute?: Function;
11
+ itemDetailsRoute?: Function;
12
+ urlPattern?: RegExp;
13
+ filterDefaults?: Record<string, any>;
14
+ refreshFilters?: boolean;
15
+ }
16
+
17
+
18
+ export function useListActions(name: string, {
6
19
  listRoute,
7
- filterFieldOptionsRoute,
8
20
  summaryRoute = null,
21
+ filterFieldOptionsRoute = null,
9
22
  moreRoute = null,
10
23
  applyActionRoute = null,
11
- applyBatchActionRoute = null,
12
24
  itemDetailsRoute = null,
13
25
  refreshFilters = false,
14
26
  urlPattern = null,
15
27
  filterDefaults = {}
16
- }) {
28
+ }: ListActionsOptions) {
17
29
  let isInitialized = false;
18
30
  const PAGE_SETTINGS_KEY = `${name}-pagination-settings`;
19
31
  const pagedItems = ref(null);
@@ -60,23 +72,22 @@ export function useListActions(name, {
60
72
  }
61
73
 
62
74
  async function loadList() {
63
- if (isInitialized) {
64
- isLoadingList.value = true;
65
- setPagedItems(await listRoute(pager.value));
66
- isLoadingList.value = false;
67
- }
75
+ if (!isInitialized) return;
76
+ isLoadingList.value = true;
77
+ setPagedItems(await listRoute(pager.value));
78
+ isLoadingList.value = false;
68
79
  }
69
80
 
70
81
  async function loadSummary() {
71
- if (summaryRoute && isInitialized) {
72
- isLoadingSummary.value = true;
73
- const summaryFilter = { id: null, ...filter.value, ...globalFilter.value };
74
- if (selectedRows.value.length) {
75
- summaryFilter.id = selectedRows.value.map((row) => row.id);
76
- }
77
- summary.value = await summaryRoute(summaryFilter);
78
- isLoadingSummary.value = false;
82
+ if (!summaryRoute || !isInitialized) return;
83
+
84
+ isLoadingSummary.value = true;
85
+ const summaryFilter = { id: null, ...filter.value, ...globalFilter.value };
86
+ if (selectedRows.value.length) {
87
+ summaryFilter.id = selectedRows.value.map((row) => row.id);
79
88
  }
89
+ summary.value = await summaryRoute(summaryFilter);
90
+ isLoadingSummary.value = false;
80
91
  }
81
92
 
82
93
  // Filter fields are the field values available for the currently applied filter on Creative Groups
@@ -89,6 +100,7 @@ export function useListActions(name, {
89
100
  });
90
101
 
91
102
  async function loadFilterFieldOptions() {
103
+ if (!filterFieldOptionsRoute || !isInitialized) return;
92
104
  isLoadingFilters.value = true;
93
105
  filterFieldOptions.value = await filterFieldOptionsRoute(filter.value);
94
106
  isLoadingFilters.value = false;
@@ -240,21 +252,6 @@ export function useListActions(name, {
240
252
  return result;
241
253
  }
242
254
 
243
- /**
244
- * Applies an action to all selected items.
245
- */
246
- const isApplyingBatchAction = ref(false);
247
-
248
- async function applyBatchAction(input) {
249
- isApplyingBatchAction.value = true;
250
- const batchFilter = { id: selectedRows.value.map(r => r.id) };
251
- const result = await applyBatchActionRoute(batchFilter, input);
252
- isApplyingBatchAction.value = false;
253
- await refreshAll();
254
-
255
- return result;
256
- }
257
-
258
255
  // The active ad for viewing / editing in the Ad Form
259
256
  const activeItem = ref(null);
260
257
  // Controls the tab on the Ad Form
@@ -267,7 +264,7 @@ export function useListActions(name, {
267
264
  */
268
265
  async function getActiveItemDetails() {
269
266
  if (!activeItem.value) return;
270
-
267
+
271
268
  const result = await itemDetailsRoute(activeItem.value);
272
269
 
273
270
  // Only set the ad details if we are the response for the currently loaded item
@@ -337,11 +334,11 @@ export function useListActions(name, {
337
334
  activeItem.value = pagedItems.value.data[nextIndex];
338
335
  }
339
336
 
340
- // Async load the settings for this Action List
341
- setTimeout(() => {
337
+ // Initialize the list actions and load settings, lists, summaries, filter fields, etc.
338
+ function initialize() {
342
339
  isInitialized = true;
343
340
  loadSettings();
344
- }, 1);
341
+ }
345
342
 
346
343
  return {
347
344
  // State
@@ -359,18 +356,17 @@ export function useListActions(name, {
359
356
  pager,
360
357
  quasarPagination,
361
358
  isApplyingActionToItem,
362
- isApplyingBatchAction,
363
359
  activeItem,
364
360
  formTab,
365
361
 
366
362
  // Actions
363
+ initialize,
367
364
  loadSummary,
368
365
  resetPaging,
369
366
  loadList,
370
367
  loadMore,
371
368
  refreshAll,
372
369
  applyAction,
373
- applyBatchAction,
374
370
  getNextItem,
375
371
  openItemForm,
376
372
  applyFilterFromUrl
@@ -1,60 +0,0 @@
1
- <template>
2
- <div>
3
- <PopoverMenu
4
- class="bg-neutral-plus-6 px-4 h-full flex"
5
- :items="items"
6
- :disabled="selectedRows.length === 0"
7
- @action="onAction"
8
- />
9
- <q-tooltip v-if="selectedRows.length === 0">
10
- Batch actions require a selection
11
- </q-tooltip>
12
- <slot>
13
- <Component
14
- :is="activeComponent.is"
15
- v-if="activeComponent"
16
- v-bind="activeComponent.props"
17
- :is-saving="isSaving"
18
- @close="activeAction = false"
19
- @confirm="onConfirmAction"
20
- />
21
- </slot>
22
- </div>
23
- </template>
24
- <script setup>
25
- import { computed, ref } from 'vue';
26
- import { PopoverMenu } from '../Utility';
27
-
28
- const emit = defineEmits(['action']);
29
- const props = defineProps({
30
- items: {
31
- type: Array,
32
- required: true
33
- },
34
- selectedRows: {
35
- type: Array,
36
- required: true
37
- },
38
- applyBatchAction: {
39
- type: Function,
40
- required: true
41
- },
42
- isSaving: Boolean
43
- });
44
-
45
-
46
- const activeAction = ref(null);
47
- const activeComponent = computed(() => (props.items.find(i => i.action === activeAction.value)?.component || (() => null))(props.selectedRows));
48
-
49
- function onAction(action) {
50
- activeAction.value = action;
51
- emit('action', action);
52
- }
53
- async function onConfirmAction(input) {
54
- const result = await props.applyBatchAction(input || activeComponent.value.input());
55
-
56
- if (result?.success) {
57
- activeAction.value = null;
58
- }
59
- }
60
- </script>