@hostlink/nuxt-light 1.42.2 → 1.43.0

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/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "light",
3
3
  "configKey": "light",
4
- "version": "1.42.2",
4
+ "version": "1.43.0",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.1",
7
7
  "unbuild": "3.5.0"
@@ -3,10 +3,9 @@ import { useQuasar, QTable, Dialog } from "quasar";
3
3
  import { defu } from "defu";
4
4
  import { ref, computed, onMounted, useSlots, watch, reactive } from "vue";
5
5
  import useLight from "../composables/useLight";
6
- import GQLFieldBuilder from "../composables/GQLFieldBuilder";
7
6
  import model from "../composables/model";
8
7
  import { toQuery } from "@hostlink/light";
9
- import { collect } from "#imports";
8
+ import { list } from "#imports";
10
9
  import { useI18n } from "vue-i18n";
11
10
  const $q = useQuasar();
12
11
  const { t } = useI18n();
@@ -180,37 +179,39 @@ const validateData = () => {
180
179
  };
181
180
  const onLocalRequest = async (p) => {
182
181
  if (!isServerSide) return;
182
+ let localFields = {};
183
183
  let sort = "";
184
184
  if (p.pagination.sortBy) {
185
185
  sort = p.pagination.sortBy + ":" + (p.pagination.descending ? "desc" : "asc");
186
186
  }
187
- const builder = GQLFieldBuilder();
188
187
  if (props.rowKey) {
189
- builder.add(props.rowKey);
188
+ localFields = defu(localFields, {
189
+ [props.rowKey]: true
190
+ });
190
191
  }
191
192
  props.columns?.forEach((col) => {
192
193
  if (col.gqlField) {
193
- builder.add(col.gqlField);
194
+ localFields = defu(localFields, col.gqlField);
194
195
  return;
195
196
  }
196
197
  if (!col.name) return;
197
198
  if (col.name.startsWith("_")) {
198
199
  return;
199
200
  }
200
- builder.add(col.name);
201
+ localFields = defu(localFields, { [col.name]: true });
201
202
  });
202
203
  if (actionView) {
203
- builder.add("canView");
204
+ localFields = defu(localFields, { canView: true });
204
205
  }
205
206
  if (actionDelete) {
206
- builder.add("canDelete");
207
+ localFields = defu(localFields, { canDelete: true });
207
208
  }
208
209
  if (activeEdit) {
209
- builder.add("canUpdate");
210
+ localFields = defu(localFields, { canUpdate: true });
210
211
  }
211
212
  const callback = {
212
213
  sort,
213
- fields: builder.get(),
214
+ fields: localFields,
214
215
  offset: (p.pagination.page - 1) * p.pagination.rowsPerPage,
215
216
  limit: p.pagination.rowsPerPage,
216
217
  gql: {
@@ -223,7 +224,7 @@ const onLocalRequest = async (p) => {
223
224
  limit: p.pagination.rowsPerPage,
224
225
  offset: (p.pagination.page - 1) * p.pagination.rowsPerPage
225
226
  },
226
- ...toQuery(builder.get())
227
+ ...toQuery(localFields)
227
228
  },
228
229
  meta: {
229
230
  total: true,
@@ -259,52 +260,28 @@ const onLocalRequest = async (p) => {
259
260
  }
260
261
  if (Array.isArray(fields)) {
261
262
  fields.forEach((f) => {
262
- builder.add(f);
263
+ localFields = defu(localFields, { [f]: true });
263
264
  });
264
265
  } else {
265
- builder.add(fields);
266
+ localFields = defu(localFields, fields);
266
267
  }
267
268
  let localFilters = getFilterValue();
268
269
  if (filters2) {
269
- localFilters = {
270
- ...localFilters,
271
- ...filters2
272
- };
270
+ localFilters = defu(localFilters, filters2);
273
271
  }
274
272
  loading.value = true;
275
273
  try {
276
- let c = collect(model2, builder.get());
277
- if (localFilters) {
278
- for (let [key, value] of Object.entries(localFilters)) {
279
- if (typeof value == "object" && value !== null) {
280
- const filterValue = value;
281
- if (filterValue.contains) {
282
- c = c.whereContains(key, filterValue.contains);
283
- }
284
- if (filterValue.between) {
285
- c = c.whereBetween(key, filterValue.between);
286
- }
287
- } else {
288
- c = c.where(key, value);
289
- }
290
- }
291
- }
274
+ let l = list(model2, localFields);
275
+ l = l.filters(localFilters);
292
276
  if (sort) {
293
- if (sort.split(":")[1] == "asc") {
294
- c = c.sortBy(sort.split(":")[0]);
295
- } else {
296
- c = c.sortByDesc(sort.split(":")[0]);
297
- }
277
+ l = l.sort(sort);
298
278
  }
299
279
  if (p.pagination.rowsPerPage != 0) {
300
- c = c.forPage(p.pagination.page, p.pagination.rowsPerPage);
280
+ l = l.limit(p.pagination.rowsPerPage);
281
+ l = l.offset((p.pagination.page - 1) * p.pagination.rowsPerPage);
301
282
  }
302
- const data = await c.all();
303
- const allData = {
304
- data,
305
- meta: c.meta
306
- };
307
- this.setData(allData);
283
+ const data = await l.fetchWithMeta();
284
+ this.setData(data);
308
285
  } catch (e) {
309
286
  quasar.dialog({
310
287
  message: e,
@@ -24,7 +24,7 @@ export type LTableProps = QTableProps & {
24
24
  };
25
25
  export interface LTableRequest {
26
26
  sort: string;
27
- fields: Array<string>;
27
+ fields: Array<any> | Object;
28
28
  gql: {
29
29
  __args: {
30
30
  filters: any;
@@ -1,7 +1,3 @@
1
- import { type Fields } from "@hostlink/light";
2
- export default function list(name: string, props?: {
3
- sort?: string;
4
- filters?: object;
5
- offset?: number;
6
- limit?: number;
7
- } | null, fields?: Fields): Promise<any>;
1
+ import { default as api } from "./api.js";
2
+ declare const _default: (name: string, fields: Object) => ReturnType<typeof api.list>;
3
+ export default _default;
@@ -1,39 +1,4 @@
1
- import { toQuery } from "@hostlink/light";
2
1
  import { default as api } from "./api.js";
3
- export default async function list(name, props = null, fields = []) {
4
- let q = {};
5
- if (props) {
6
- if (props.sort) {
7
- q.__args = q.__args || {};
8
- q.__args.sort = props.sort;
9
- }
10
- if (props.filters) {
11
- q.__args = q.__args || {};
12
- q.__args.filters = props.filters;
13
- }
14
- }
15
- q.data = {};
16
- if (props) {
17
- if (props.offset) {
18
- q.data.__args = q.data.__args || {};
19
- q.data.__args.offset = props.offset;
20
- }
21
- if (props.limit) {
22
- q.data.__args = q.data.__args || {};
23
- q.data.__args.limit = props.limit;
24
- }
25
- }
26
- q.data = {
27
- ...q.data,
28
- ...toQuery(fields)
29
- };
30
- q.meta = {
31
- total: true,
32
- key: true,
33
- name: true
34
- };
35
- const resp = await api.query({
36
- [`list${name}`]: q
37
- });
38
- return resp[`list${name}`];
39
- }
2
+ export default (name, fields) => {
3
+ return api.list(name, fields);
4
+ };
@@ -61,36 +61,40 @@ const cursor = ref("cursor-grab");
61
61
  </style>
62
62
 
63
63
  <template>
64
- <FormKit type="list" v-model="localValue" dynamic #default="{ items, node }" :name="node.name">
65
- <q-list bordered separator ref="parent">
66
- <FormKit type="group" v-for="(item, index) in items" :index="index" :key="item" #default="{ node }">
67
- <q-item class="q-pa-xs">
68
- <q-item-section avatar class="">
69
- <div class="l-repeater-handle" v-if="sortable" :class="cursor" @mousedown="cursor = 'cursor-grabbing'"
70
- @mouseup="cursor = 'cursor-grab'" @mouseleave="cursor = 'cursor-grab'">
71
- <q-icon name="sym_o_drag_indicator" :color="$light.color" size="sm" />
72
- </div>
73
- </q-item-section>
64
+ <div class="col col-12 ">
65
+ <FormKit type="list" v-model="localValue" dynamic #default="{ items, node }" :name="node.name">
66
+ <q-list bordered separator ref="parent">
67
+ <FormKit type="group" v-for="(item, index) in items" :index="index" :key="item" #default="{ node }">
68
+ <q-item class="q-pa-xs">
69
+ <q-item-section avatar class="">
70
+ <div class="l-repeater-handle" v-if="sortable" :class="cursor"
71
+ @mousedown="cursor = 'cursor-grabbing'" @mouseup="cursor = 'cursor-grab'"
72
+ @mouseleave="cursor = 'cursor-grab'">
73
+ <q-icon name="sym_o_drag_indicator" :color="$light.color" size="sm" />
74
+ </div>
75
+ </q-item-section>
74
76
 
75
- <q-item-section>
76
- <slot v-bind="{ value: localValue[index], index: index, node: node }"></slot>
77
- </q-item-section>
77
+ <q-item-section>
78
+ <slot v-bind="{ value: localValue[index], index: index, node: node }"></slot>
79
+ </q-item-section>
78
80
 
79
- <q-item-section side>
80
- <!-- up -->
81
- <q-btn type="button" @click="onMoveUp(index)" icon="sym_o_arrow_upward" :color="$light.color"
82
- dense flat :disable="!isAllowMoveUp(index)" />
81
+ <q-item-section side>
82
+ <!-- up -->
83
+ <q-btn type="button" @click="onMoveUp(index)" icon="sym_o_arrow_upward"
84
+ :color="$light.color" dense flat :disable="!isAllowMoveUp(index)" />
83
85
 
84
- <q-btn type="button" @click="onRemove(index)" icon="sym_o_delete" :color="$light.color" dense
85
- :disable="!isAllowRemove" flat />
86
- <!-- down -->
87
- <q-btn type="button" @click="onMoveDown(index)" icon="sym_o_arrow_downward"
88
- :color="$light.color" dense flat :disable="!isAllowMoveDown(index)" />
86
+ <q-btn type="button" @click="onRemove(index)" icon="sym_o_delete" :color="$light.color"
87
+ dense :disable="!isAllowRemove" flat />
88
+ <!-- down -->
89
+ <q-btn type="button" @click="onMoveDown(index)" icon="sym_o_arrow_downward"
90
+ :color="$light.color" dense flat :disable="!isAllowMoveDown(index)" />
89
91
 
90
- </q-item-section>
91
- </q-item>
92
- </FormKit>
93
- </q-list>
94
- <q-btn @click="onAdd" :label="addLabel" icon="sym_o_add" :color="$light.color" outline />
95
- </FormKit>
92
+ </q-item-section>
93
+ </q-item>
94
+ </FormKit>
95
+ </q-list>
96
+ <q-btn @click="onAdd" :label="addLabel" icon="sym_o_add" :color="$light.color" outline class="q-mt-sm"
97
+ :disable="localValue.length >= max" />
98
+ </FormKit>
99
+ </div>
96
100
  </template>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hostlink/nuxt-light",
3
- "version": "1.42.2",
3
+ "version": "1.43.0",
4
4
  "description": "HostLink Nuxt Light Framework",
5
5
  "repository": {
6
6
  "type": "git",
@@ -32,7 +32,7 @@
32
32
  "dependencies": {
33
33
  "@azure/msal-browser": "^3.26.1",
34
34
  "@formkit/drag-and-drop": "^0.5.3",
35
- "@hostlink/light": "^2.9.0",
35
+ "@hostlink/light": "^2.11.0",
36
36
  "@nuxt/module-builder": "^1.0.1",
37
37
  "@quasar/extras": "^1.17.0",
38
38
  "@quasar/quasar-ui-qmarkdown": "^2.0.5",
@@ -1 +0,0 @@
1
- export default function (): any;
@@ -1,28 +0,0 @@
1
- import { toQuery } from "@hostlink/light";
2
- import { defu } from "defu";
3
- export default function() {
4
- let fields = {};
5
- return {
6
- //deep merge
7
- merge: defu,
8
- add: (f) => {
9
- if (typeof f === "string") {
10
- fields = defu(fields, { [f]: true });
11
- return;
12
- }
13
- if (Array.isArray(f)) {
14
- f.forEach((item) => {
15
- fields = defu(fields, { [item]: true });
16
- });
17
- return;
18
- }
19
- if (typeof f === "object") {
20
- fields = defu(fields, toQuery(f));
21
- return;
22
- }
23
- },
24
- get() {
25
- return fields;
26
- }
27
- };
28
- }