quasar-factory-lib 0.0.48 → 0.0.50

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.
@@ -3,6 +3,7 @@ export const tableStore: import("pinia").StoreDefinition<"tableStore", {
3
3
  filterValue: import("@vueuse/shared").RemovableRef<string>;
4
4
  lastFilterValue: import("@vueuse/shared").RemovableRef<string>;
5
5
  visiblecolumns: import("@vueuse/shared").RemovableRef<never[]>;
6
+ prepared: import("@vueuse/shared").RemovableRef<boolean>;
6
7
  }, {}, {
7
8
  setFilterValue(val: any): void;
8
9
  cleanTableFilter(): void;
package/package.json CHANGED
@@ -97,6 +97,6 @@
97
97
  "release": "standard-version"
98
98
  },
99
99
  "type": "module",
100
- "version": "0.0.48",
100
+ "version": "0.0.50",
101
101
  "author": ""
102
102
  }
@@ -11,6 +11,7 @@
11
11
  :grid="smallDevice"
12
12
  :style="tableStyle"
13
13
  flat
14
+ :filter-method="customFilter"
14
15
  bordered
15
16
  :rows="rowsData"
16
17
  :columns="columns"
@@ -21,7 +22,6 @@
21
22
  table-class="text-grey-9"
22
23
  table-header-class="main-color"
23
24
  :filter="filterComputed"
24
- :filter-method="filterMethod"
25
25
  :sort-method="customSortMethod"
26
26
  separator="horizontal"
27
27
  binary-state-sort
@@ -127,10 +127,10 @@ export default defineComponent({
127
127
  type: Array as () => string[],
128
128
  required: true
129
129
  },
130
- filterMethod: {
131
- type: Function,
132
- default: function () {}
133
- },
130
+ // filterMethod: {
131
+ // type: Function,
132
+ // default: function () {}
133
+ // },
134
134
  // sortMethod: {
135
135
  // type: Function,
136
136
  // default: function () {}
@@ -181,7 +181,17 @@ export default defineComponent({
181
181
  getCellClass: {
182
182
  type: Function,
183
183
  default: function () {}
184
+ },
185
+ // Needs to be used together
186
+ additionalFilterConditions: {
187
+ type: Function,
188
+ default: function () {}
189
+ },
190
+ additionalSortConditions: {
191
+ type: Function,
192
+ default: function () {}
184
193
  }
194
+ //
185
195
  },
186
196
  emits: [
187
197
  'onSelectVisibleColumns',
@@ -207,7 +217,8 @@ export default defineComponent({
207
217
  loading: false,
208
218
  forceRender: false,
209
219
  totalPage: 0,
210
- pageSize: 20
220
+ pageSize: 20,
221
+ filteredRows: [] as object [] | []
211
222
  }
212
223
  },
213
224
  computed: {
@@ -236,6 +247,7 @@ export default defineComponent({
236
247
  pageLength (): number {
237
248
  return (this.totalPage + 1) * this.pageSize
238
249
  }
250
+
239
251
  },
240
252
  watch: {
241
253
  rows (val) {
@@ -244,6 +256,7 @@ export default defineComponent({
244
256
  visibleColumns (val: string [] | []) {
245
257
  this.visibleColumnsData = val
246
258
  }
259
+
247
260
  },
248
261
  mounted () {
249
262
  },
@@ -299,13 +312,23 @@ export default defineComponent({
299
312
  toogleLoading () {
300
313
  this.loading = !this.loading
301
314
  },
302
- customSortMethod(
303
- rows,
304
- sortBy: string,
305
- descending: boolean
306
- ) {
307
- const data = [...rows];
308
-
315
+ customSortMethod(rows: object[] | [], sortBy: string, descending: boolean) {
316
+ let data = []
317
+ if (this.store.filterValue !== '') {
318
+ data = [...this.filteredRows];
319
+ }
320
+ else {
321
+ data = [...this.rows];
322
+ }
323
+ if (this.additionalSortConditions && this.additionalSortConditions.toString().replace(/\s+/g, '') !== 'function(){}') {
324
+ data = this.additionalSortConditions(this.store, this.filteredRows, rows);
325
+ } else {
326
+ console.log('else sort')
327
+ }
328
+ this.getSortedData(sortBy, data, descending)
329
+ return data.slice(0, this.pageLength);
330
+ },
331
+ getSortedData (sortBy: string, data: object[] | [], descending: boolean) {
309
332
  if (sortBy) {
310
333
  data.sort((a, b) => {
311
334
  const x = descending ? b : a;
@@ -316,12 +339,12 @@ export default defineComponent({
316
339
 
317
340
  const parseDate = (dateString: string): Date => {
318
341
  const [day, month, year] = dateString.split('/');
319
- return new Date(`${year}-${month}-${day}`); // Converte para 'yyyy-mm-dd'
342
+ return new Date(`${year}-${month}-${day}`);
320
343
  };
321
344
 
322
345
  const parseTime = (timeString: string): number => {
323
346
  const [hours, minutes, seconds] = timeString.split(':').map(Number);
324
- return (hours * 3600) + (minutes * 60) + seconds; // Converte para o total de segundos
347
+ return (hours * 3600) + (minutes * 60) + seconds;
325
348
  };
326
349
 
327
350
  if (typeof xValue === 'string' && typeof yValue === 'string') {
@@ -352,9 +375,38 @@ export default defineComponent({
352
375
  }
353
376
  });
354
377
  }
355
- return data;
378
+ },
379
+ containsSearchTermInRow (row: object, lowerSearch: string): boolean {
380
+ if (lowerSearch !== '') {
381
+ const values = Object.values(row)
382
+ const valuesLowerCase = values.map((x) => (x + '').toLowerCase())
383
+ for (let val = 0; val < valuesLowerCase.length; val++) {
384
+ if (valuesLowerCase[val].includes(lowerSearch)) {
385
+ return true
386
+ }
387
+ }
388
+ }
389
+ return false
390
+ },
391
+ customFilter(rows: object[] | [], terms: { search: string, prepared: boolean }) {
392
+ let filteredRows_ = []
393
+ if (terms.search !== '') {
394
+ const lowerSearch = terms.search ? terms.search.toLowerCase() : ''
395
+ for (let i = 0; i < this.rows.length; i++) {
396
+ if (this.containsSearchTermInRow(this.rows[i], lowerSearch)) {
397
+ filteredRows_.push(this.rows[i])
398
+ }
399
+ }
400
+ }
401
+ else {
402
+ filteredRows_ = rows
403
+ }
404
+ if (this.additionalFilterConditions && this.additionalFilterConditions.toString().replace(/\s+/g, '') !== 'function(){}') {
405
+ filteredRows_ = this.additionalFilterConditions(this.store, this.rows, filteredRows_)
406
+ }
407
+ this.filteredRows = filteredRows_
408
+ return filteredRows_.slice(0, this.pageLength)
356
409
  }
357
-
358
410
  }
359
411
  })
360
412
  </script>
@@ -2,7 +2,8 @@
2
2
 
3
3
  import infiniteScroll from './infiniteScroll'
4
4
  const filterMethod = {
5
- filter (self: { filteredRows: object [] | [] }, rows: string | [], terms: { search: string }): object[] | [] {
5
+ filter (self: { filteredRows: object [] | [] }, rows: string | [], terms: { search: string }) {
6
+ console.log(rows)
6
7
  if (terms.search !== '') {
7
8
  const filteredRows = []
8
9
  const lowerSearch = terms.search ? terms.search.toLowerCase() : ''
@@ -14,6 +15,7 @@ const filterMethod = {
14
15
  self.filteredRows = filteredRows
15
16
  return infiniteScroll.paginationNewTable(self, filteredRows)
16
17
  } else {
18
+ self.filteredRows = rows
17
19
  return infiniteScroll.paginationNewTable(self, rows)
18
20
  }
19
21
  },
@@ -2,11 +2,13 @@
2
2
  <q-page-container class=" full-width column justify-center">
3
3
  <q-page
4
4
  class="full-width column justify-center align-center items-center"
5
- style="height: 70vh;"
5
+ style=""
6
6
  >
7
7
  <div
8
8
  class="full-width"
9
9
  >
10
+ {{ store.prepared }}
11
+ <q-btn @click="store.prepared = !store.prepared">Click</q-btn>
10
12
  <Table
11
13
  ref="table"
12
14
  :rows="rows"
@@ -18,7 +20,9 @@
18
20
  :show-skeleton="false"
19
21
  :selection-type="'multiple'"
20
22
  :getCellClass="getCellClass"
21
- :filter-method="filterMethod"
23
+ :filterComputedOptions="{ preparedQuantity: store.prepared}"
24
+ :additionalSortConditions="additionalSortConditions"
25
+ :additional-filter-conditions="additionalFilterConditions"
22
26
  @on-select-visible-columns="saveSelectedColumns"
23
27
  @on-update-basic-checkbox-value="onUpdateBasicCheckboxValue"
24
28
  @on-update-customized-checkbox-value="onUpdateCustomizedCheckboxValue"
@@ -151,7 +155,8 @@ export default {
151
155
  name: 'sodium',
152
156
  label: 'Sodium (mg)',
153
157
  align: 'left',
154
- field: 'sodium'
158
+ field: 'sodium',
159
+ sortable: true
155
160
  },
156
161
  {
157
162
  name: 'calcium',
@@ -321,9 +326,7 @@ export default {
321
326
  iron: '6%'
322
327
  }
323
328
  ],
324
- visibleColumns: [],
325
- sortDateValues: ['dateCreation'],
326
- filteredRows: []
329
+ visibleColumns: []
327
330
  }
328
331
  },
329
332
  mounted () {
@@ -387,6 +390,37 @@ export default {
387
390
  return 'text-color-negative-bold';
388
391
  }
389
392
  return '';
393
+ },
394
+ additionalFilterConditions (store_: { prepared: boolean }, rows_: object[] | [], filteredRowsParam_: object[] | []) {
395
+ console.log('additional filter conditions')
396
+ filteredRowsParam_ = []
397
+ if (store_.prepared) {
398
+ for (let i = 0; i < rows_.length; i++) {
399
+ if (rows_[i].sodium >= 300) {
400
+ filteredRowsParam_.push(rows_[i])
401
+ }
402
+ }
403
+ return filteredRowsParam_
404
+ } else {
405
+ return rows_
406
+ }
407
+ },
408
+ additionalSortConditions (store_, filteredRowsData, rows) {
409
+ console.log('conditions sort function')
410
+ if (store_.prepared) {
411
+
412
+ const filteredRows_ = []
413
+ for (let i = 0; i < rows.length; i++) {
414
+ if (rows[i].sodium >= 300) {
415
+ filteredRows_.push(rows[i])
416
+ }
417
+ }
418
+ filteredRowsData = filteredRows_
419
+ return [...filteredRowsData]
420
+ }
421
+ else if (!store_.prepared) {
422
+ return [...rows]
423
+ }
390
424
  }
391
425
  }
392
426
  }
@@ -5,7 +5,8 @@ export const tableStore = defineStore('tableStore', {
5
5
  disableScannerButtons: useStorage('disableScannerButtons', false),
6
6
  filterValue: useStorage('filterValue', ''),
7
7
  lastFilterValue: useStorage('lastFilterValue', ''),
8
- visiblecolumns: useStorage('visiblecolumns', [])
8
+ visiblecolumns: useStorage('visiblecolumns', []),
9
+ prepared: useStorage('prepared', false),
9
10
  }),
10
11
  getters: {
11
12
  },