@hostlink/nuxt-light 1.20.3 → 1.20.6

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.
@@ -4,6 +4,7 @@ import { useQuasar, QTable, type QTableColumn, type QTableProps, Dialog, QTab }
4
4
  import { ref, computed, onMounted, useSlots, useAttrs, watch, defineComponent, h } from "vue";
5
5
  import { t, q, useLight, GQLFieldBuilder, model } from '../';
6
6
  import { toQuery } from '@hostlink/light';
7
+ import { collect } from "#imports"
7
8
 
8
9
  const $q = useQuasar();
9
10
 
@@ -206,57 +207,6 @@ const validateData = () => {
206
207
 
207
208
  }
208
209
 
209
- const getData = async (
210
- operation: string,
211
- filters = {},
212
- sort: String,
213
- offset: number,
214
- limit: number,
215
- fields: Array<string> = []) => {
216
-
217
- const query: any = {};
218
- query[operation] = {
219
- meta: {
220
- total: true,
221
- key: true,
222
- name: true
223
- }
224
- }
225
-
226
- let offset_limit: any = {}
227
- if (offset) {
228
- offset_limit.offset = offset;
229
- }
230
-
231
- if (limit) {
232
- offset_limit.limit = limit;
233
- }
234
-
235
- if (offset_limit) {
236
- query[operation].data = {
237
- __args: offset_limit
238
- };
239
- }
240
-
241
- let params: any = {}
242
- if (sort) {
243
- params.sort = sort;
244
- }
245
-
246
- if (filters) {
247
- params.filters = filters
248
- }
249
-
250
- query[operation].__args = params;
251
-
252
- query[operation].data = query[operation].data || {};
253
- Object.assign(query[operation].data, fields);
254
-
255
- const resp = await q(query);
256
- return resp[operation];
257
-
258
- }
259
-
260
210
  const onLocalRequest = async (p: any) => {
261
211
  if (!isServerSide) return;
262
212
 
@@ -338,9 +288,9 @@ const onLocalRequest = async (p: any) => {
338
288
  validateData();
339
289
  },
340
290
  loadObjects(model: string, filters: any = null, fields: Array<any> = []) {
341
- return this.loadData("list" + model, filters, fields);
291
+ return this.loadData(model, filters, fields);
342
292
  },
343
- async loadData(operation: string, filters: any = null, fields: Array<any> = []) {
293
+ async loadData(model: string, filters: any = null, fields: Array<any> = []) {
344
294
  fields.forEach((f) => {
345
295
  builder.add(f);
346
296
  })
@@ -353,8 +303,41 @@ const onLocalRequest = async (p: any) => {
353
303
  }
354
304
  }
355
305
  loading.value = true;
306
+
356
307
  try {
357
- const allData = await getData(operation, localFilters, sort, this.offset, this.limit, builder.get());
308
+ let c = collect(model, builder.get())
309
+
310
+ if (localFilters) {
311
+ for (let [key, value] of Object.entries(localFilters)) {
312
+ if (typeof value == "object") {
313
+ if (value.contains) {
314
+ c = c.whereContains(key, value.contains);
315
+ }
316
+ if (value.between) {
317
+ c = c.whereBetween(key, value.between);
318
+ }
319
+ } else {
320
+ c = c.where(key, value);
321
+ }
322
+ }
323
+ }
324
+
325
+ if (sort) {
326
+ if (sort.split(":")[1] == "asc") {
327
+ c = c.sortBy(sort.split(":")[0]);
328
+ } else {
329
+ c = c.sortByDesc(sort.split(":")[0]);
330
+ }
331
+ }
332
+
333
+ c = c.forPage(p.pagination.page, p.pagination.rowsPerPage);
334
+
335
+ const data = await c.all();
336
+ const allData = {
337
+ data,
338
+ meta: c.meta
339
+ }
340
+
358
341
  this.setData(allData);
359
342
  } catch (e: any) {
360
343
  quasar.dialog({
@@ -363,9 +346,6 @@ const onLocalRequest = async (p: any) => {
363
346
  })
364
347
  this.setData({ data: [], meta: { total: 0, key: "", name: "" } });
365
348
  }
366
-
367
-
368
-
369
349
  }
370
350
  }
371
351