quasar-ui-danx 0.4.21 → 0.4.23

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.4.21",
3
+ "version": "0.4.23",
4
4
  "author": "Dan <dan@flytedesk.com>",
5
5
  "description": "DanX Vue / Quasar component library",
6
6
  "license": "MIT",
@@ -1,6 +1,6 @@
1
1
  <template>
2
2
  <QToggle
3
- :data-testid="'boolean-field-' + field.id"
3
+ :data-testid="'boolean-field-' + (name || label)"
4
4
  :model-value="modelValue || (toggleIndeterminate ? modelValue : false)"
5
5
  :disable="disable || readonly"
6
6
  :toggle-indeterminate="toggleIndeterminate"
@@ -8,37 +8,39 @@
8
8
  @update:model-value="$emit('update:model-value', $event)"
9
9
  >
10
10
  <FieldLabel
11
- :field="{...field, label: label || field.label}"
11
+ :label="label || name"
12
+ :name="name"
12
13
  :show-name="showName"
13
14
  :class="labelClass"
14
15
  />
15
16
  </QToggle>
16
17
  </template>
17
18
 
18
- <script setup>
19
+ <script setup lang="ts">
19
20
  import FieldLabel from "./FieldLabel";
20
21
 
21
22
  defineEmits(["update:model-value"]);
22
23
  defineProps({
23
- label: {
24
- type: String,
25
- default: null
26
- },
27
- modelValue: {
28
- type: [Boolean],
29
- default: undefined
30
- },
31
- field: {
32
- type: Object,
33
- required: true
34
- },
35
- labelClass: {
36
- type: String,
37
- default: "text-sm"
38
- },
39
- showName: Boolean,
40
- toggleIndeterminate: Boolean,
41
- disable: Boolean,
42
- readonly: Boolean
24
+ label: {
25
+ type: String,
26
+ default: null
27
+ },
28
+ name: {
29
+ type: String,
30
+ default: null
31
+ },
32
+ required: Boolean,
33
+ modelValue: {
34
+ type: Boolean,
35
+ default: undefined
36
+ },
37
+ labelClass: {
38
+ type: String,
39
+ default: "text-sm"
40
+ },
41
+ showName: Boolean,
42
+ toggleIndeterminate: Boolean,
43
+ disable: Boolean,
44
+ readonly: Boolean
43
45
  });
44
46
  </script>
@@ -1,26 +1,22 @@
1
1
  <template>
2
2
  <NumberField
3
- :field="field"
3
+ v-bind="$props"
4
4
  :precision="0"
5
5
  :model-value="modelValue"
6
- :show-name="showName"
7
6
  @update:model-value="$emit('update:model-value', $event)"
8
7
  />
9
8
  </template>
10
9
 
11
- <script setup>
10
+ <script setup lang="ts">
11
+ import { NumberFieldProps } from "../../../../types";
12
12
  import NumberField from "./NumberField";
13
13
 
14
14
  defineEmits(["update:model-value"]);
15
- defineProps({
16
- modelValue: {
17
- type: [String, Number],
18
- default: null
19
- },
20
- field: {
21
- type: Object,
22
- required: true
23
- },
24
- showName: Boolean
15
+ withDefaults(defineProps<NumberFieldProps>(), {
16
+ modelValue: "",
17
+ label: undefined,
18
+ delay: 1000,
19
+ min: undefined,
20
+ max: undefined
25
21
  });
26
22
  </script>
@@ -1,17 +1,30 @@
1
1
  <template>
2
2
  <div>
3
3
  <div class="text-xs font-bold">
4
- {{ label }}
4
+ <slot name="label">
5
+ {{ label }}
6
+ </slot>
5
7
  </div>
6
8
  <div :class="valueClass">
7
- <a
8
- v-if="url"
9
- target="_blank"
10
- :href="url"
11
- :class="valueClass"
12
- >
13
- <slot>{{ formattedValue }}</slot>
14
- </a>
9
+ <template v-if="url">
10
+ <a
11
+ v-if="!isLargeContent"
12
+ target="_blank"
13
+ :href="url"
14
+ >
15
+ <slot>{{ formattedValue }}</slot>
16
+ </a>
17
+ <template v-else>
18
+ <slot>{{ formattedValue }}</slot>
19
+ <a
20
+ target="_blank"
21
+ :href="url"
22
+ class="inline-block ml-2"
23
+ >
24
+ <LinkIcon class="w-4" />
25
+ </a>
26
+ </template>
27
+ </template>
15
28
  <template v-else>
16
29
  <slot>{{ formattedValue }}</slot>
17
30
  </template>
@@ -19,12 +32,13 @@
19
32
  </div>
20
33
  </template>
21
34
  <script setup lang="ts">
35
+ import { FaSolidLink as LinkIcon } from "danx-icon";
22
36
  import { computed } from "vue";
23
37
  import { fBoolean, fNumber } from "../../../../helpers";
24
38
 
25
39
  export interface LabelValueBlockProps {
26
40
  label: string;
27
- value: string | number | boolean;
41
+ value?: string | number | boolean;
28
42
  url?: string;
29
43
  dense?: boolean;
30
44
  nowrap?: boolean;
@@ -36,6 +50,7 @@ const props = withDefaults(defineProps<LabelValueBlockProps>(), {
36
50
  });
37
51
 
38
52
  const valueClass = computed(() => ({ "mt-2": !props.dense, "mt-1": props.dense, "text-no-wrap": props.nowrap }));
53
+ const isLargeContent = computed(() => typeof props.value === "string" && props.value.length > 30);
39
54
  const formattedValue = computed(() => {
40
55
  switch (typeof props.value) {
41
56
  case "boolean":
@@ -11,18 +11,11 @@
11
11
  import { useDebounceFn } from "@vueuse/core";
12
12
  import { nextTick, ref, watch } from "vue";
13
13
  import { fNumber } from "../../../../helpers";
14
- import { AnyObject, TextFieldProps } from "../../../../types";
14
+ import { AnyObject, NumberFieldProps } from "../../../../types";
15
15
  import TextField from "./TextField";
16
16
 
17
17
  const emit = defineEmits(["update:model-value", "update"]);
18
18
 
19
- export interface NumberFieldProps extends TextFieldProps {
20
- precision?: number;
21
- delay?: number;
22
- currency?: boolean;
23
- min?: number;
24
- max?: number;
25
- }
26
19
 
27
20
  const props = withDefaults(defineProps<NumberFieldProps>(), {
28
21
  modelValue: "",
@@ -364,7 +364,7 @@ export function useListControls(name: string, options: ListControlsOptions): Act
364
364
 
365
365
  const latestNextIndex = latestCallOnly("getNextItem", async () => {
366
366
  if (!pagedItems.value?.data) return -1;
367
-
367
+
368
368
  // Load the previous page if the offset is before index 0
369
369
  if (nextIndex < 0) {
370
370
  if (pagination.value.page > 1) {
@@ -439,11 +439,21 @@ export function useListControls(name: string, options: ListControlsOptions): Act
439
439
  */
440
440
  function updateRouteParams(params: AnyObject) {
441
441
  const vueRouter = getVueRouter();
442
- const { name: routeName } = vueRouter.currentRoute.value;
443
- vueRouter.push({
444
- name: (Array.isArray(routeName) ? routeName[0] : routeName) || "home",
445
- params
446
- });
442
+ let { name: routeName } = vueRouter.currentRoute.value;
443
+ routeName = Array.isArray(routeName) ? routeName[0] : routeName;
444
+
445
+ if (!routeName) {
446
+ console.error("No route name found for list controls", name);
447
+ return;
448
+ }
449
+
450
+ const newRoutePath = vueRouter.resolve({ name: routeName, params }).href;
451
+ const currentRoutePath = vueRouter.currentRoute.value.fullPath;
452
+
453
+ // Only update the route if the route is different (or the currentRoutePath is a child of the newRoutePath)
454
+ if (currentRoutePath !== newRoutePath && !currentRoutePath.startsWith(newRoutePath)) {
455
+ vueRouter.push({ name: routeName, params });
456
+ }
447
457
  }
448
458
 
449
459
  function setPanelFromRoute(params: RouteParams, meta: AnyObject) {
@@ -234,7 +234,13 @@ export function fShortSize(value: string | number) {
234
234
  return Math.round(n / div) + " " + power.unit;
235
235
  }
236
236
 
237
- export function fBoolean(value?: boolean) {
237
+ export function fBoolean(value?: boolean | string | any) {
238
+ switch (value) {
239
+ case "Yes":
240
+ case "No":
241
+ return value;
242
+ }
243
+
238
244
  return (value === undefined || value === null) ? "-" : (value ? "Yes" : "No");
239
245
  }
240
246
 
@@ -73,7 +73,6 @@ export async function autoRefreshObject<T extends TypedObject>(object: T, condit
73
73
  }
74
74
 
75
75
  if (condition(object)) {
76
- console.log("condition true", object);
77
76
  const refreshedObject = await callback(object);
78
77
 
79
78
  if (!refreshedObject.id) {
@@ -3,7 +3,7 @@ import { ListControlsRoutes } from "../types";
3
3
  import { downloadFile } from "./downloadPdf";
4
4
  import { request } from "./request";
5
5
 
6
- export function useActionRoutes(baseUrl: string): ListControlsRoutes {
6
+ export function useActionRoutes(baseUrl: string, extend?: object): ListControlsRoutes {
7
7
  return {
8
8
  list(pager?) {
9
9
  return request.post(`${baseUrl}/list`, pager);
@@ -33,6 +33,7 @@ export function useActionRoutes(baseUrl: string): ListControlsRoutes {
33
33
  },
34
34
  export(filter, name) {
35
35
  return downloadFile(`${baseUrl}/export`, name || "export.csv", { filter });
36
- }
36
+ },
37
+ ...extend
37
38
  };
38
39
  }
@@ -19,3 +19,11 @@ export interface TextFieldProps {
19
19
  readonly?: boolean;
20
20
  debounce?: string | number;
21
21
  }
22
+
23
+ export interface NumberFieldProps extends TextFieldProps {
24
+ precision?: number;
25
+ delay?: number;
26
+ currency?: boolean;
27
+ min?: number;
28
+ max?: number;
29
+ }