quasar-factory-lib 0.0.49 → 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.
package/package.json CHANGED
@@ -97,6 +97,6 @@
97
97
  "release": "standard-version"
98
98
  },
99
99
  "type": "module",
100
- "version": "0.0.49",
100
+ "version": "0.0.50",
101
101
  "author": ""
102
102
  }
@@ -3,7 +3,6 @@
3
3
  <!-- eslint-disable vue/no-v-model-argument -->
4
4
  <!-- eslint-disable vue/no-use-v-if-with-v-for -->
5
5
  <div>
6
- {{filteredRows.length}}
7
6
  <q-table
8
7
  v-if="!showSkeleton"
9
8
  ref="myTable"
@@ -12,7 +11,7 @@
12
11
  :grid="smallDevice"
13
12
  :style="tableStyle"
14
13
  flat
15
- :filter-method="customFilter"
14
+ :filter-method="customFilter"
16
15
  bordered
17
16
  :rows="rowsData"
18
17
  :columns="columns"
@@ -182,11 +181,17 @@ export default defineComponent({
182
181
  getCellClass: {
183
182
  type: Function,
184
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 () {}
185
193
  }
186
- // filteredRows: {
187
- // type: Array,
188
- // required: true
189
- // }
194
+ //
190
195
  },
191
196
  emits: [
192
197
  'onSelectVisibleColumns',
@@ -212,8 +217,8 @@ export default defineComponent({
212
217
  loading: false,
213
218
  forceRender: false,
214
219
  totalPage: 0,
215
- pageSize: 5,
216
- filteredRows: [] as object | []
220
+ pageSize: 20,
221
+ filteredRows: [] as object [] | []
217
222
  }
218
223
  },
219
224
  computed: {
@@ -307,18 +312,23 @@ export default defineComponent({
307
312
  toogleLoading () {
308
313
  this.loading = !this.loading
309
314
  },
310
- customSortMethod(
311
- rows,
312
- sortBy: string,
313
- descending: boolean
314
- ) {
315
+ customSortMethod(rows: object[] | [], sortBy: string, descending: boolean) {
315
316
  let data = []
316
- if (this.store.filterValue === '') {
317
- data = [...this.rows];
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);
318
325
  } else {
319
- data = [...this.filteredRows];
326
+ console.log('else sort')
320
327
  }
321
-
328
+ this.getSortedData(sortBy, data, descending)
329
+ return data.slice(0, this.pageLength);
330
+ },
331
+ getSortedData (sortBy: string, data: object[] | [], descending: boolean) {
322
332
  if (sortBy) {
323
333
  data.sort((a, b) => {
324
334
  const x = descending ? b : a;
@@ -329,12 +339,12 @@ export default defineComponent({
329
339
 
330
340
  const parseDate = (dateString: string): Date => {
331
341
  const [day, month, year] = dateString.split('/');
332
- return new Date(`${year}-${month}-${day}`); // Converte para 'yyyy-mm-dd'
342
+ return new Date(`${year}-${month}-${day}`);
333
343
  };
334
344
 
335
345
  const parseTime = (timeString: string): number => {
336
346
  const [hours, minutes, seconds] = timeString.split(':').map(Number);
337
- return (hours * 3600) + (minutes * 60) + seconds; // Converte para o total de segundos
347
+ return (hours * 3600) + (minutes * 60) + seconds;
338
348
  };
339
349
 
340
350
  if (typeof xValue === 'string' && typeof yValue === 'string') {
@@ -365,25 +375,37 @@ export default defineComponent({
365
375
  }
366
376
  });
367
377
  }
368
- return data.slice(0, this.pageLength);
369
378
  },
370
- customFilter(rows: string | [], terms: { search: string }) {
371
- console.log('terms', terms)
372
- if (this.store.filterValue === '') return this.rows.slice(0, this.pageLength);
373
-
374
- const filteredRows = this.rows.filter((row) => {
375
- const rowValues = Object.values(row).join(" ").toLowerCase();
376
-
377
- if (terms.search && terms.search.trim() !== '') {
378
- if (rowValues.includes(terms.search.toLowerCase())) {
379
- return true;
380
- }
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
381
386
  }
382
- return false
383
- });
384
-
385
- this.filteredRows = filteredRows
386
- return filteredRows.slice(0, this.pageLength);
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)
387
409
  }
388
410
  }
389
411
  })
@@ -7,6 +7,8 @@
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
- :filtered-rows="filteredRows"
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
  }