From 909275727ae51cbaef38d490a60c9fe773330112 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Thu, 1 Apr 2021 11:15:21 +0200 Subject: [PATCH] [pricelist][chore] minor cleanup --- .../pricelist/components/CalculationTable.vue | 11 +++------- .../pricelist/components/Pricelist.vue | 10 +++------- .../pricelist/components/SearchInput.vue | 11 ++++------ src/plugins/pricelist/pages/Receipts.vue | 10 +++------- src/plugins/pricelist/utils/filter.ts | 20 +++++++++++++++---- src/plugins/pricelist/utils/sort.ts | 7 +++++++ 6 files changed, 36 insertions(+), 33 deletions(-) create mode 100644 src/plugins/pricelist/utils/sort.ts diff --git a/src/plugins/pricelist/components/CalculationTable.vue b/src/plugins/pricelist/components/CalculationTable.vue index 0f83aa7..b172e3a 100644 --- a/src/plugins/pricelist/components/CalculationTable.vue +++ b/src/plugins/pricelist/components/CalculationTable.vue @@ -335,14 +335,9 @@ import MinPriceSetting from 'src/plugins/pricelist/components/MinPriceSetting.vu import NewDrink from 'src/plugins/pricelist/components/CalculationTable/NewDrink.vue'; import BuildManual from 'src/plugins/pricelist/components/CalculationTable/BuildManual.vue'; import SearchInput from './SearchInput.vue'; -import { filter } from '../utils/filter'; +import { filter, Search } from '../utils/filter'; import { Notify } from 'quasar'; - -function sort(a: string | number, b: string | number) { - if (a > b) return 1; - if (b > a) return -1; - return 0; -} +import { sort } from '../utils/sort'; export default defineComponent({ name: 'CalculationTable', @@ -528,7 +523,7 @@ export default defineComponent({ updateDrink(drink); } - const search = ref({ + const search = ref({ value: '', key: '', label: '', diff --git a/src/plugins/pricelist/components/Pricelist.vue b/src/plugins/pricelist/components/Pricelist.vue index 91cfa7b..2c539cc 100644 --- a/src/plugins/pricelist/components/Pricelist.vue +++ b/src/plugins/pricelist/components/Pricelist.vue @@ -91,12 +91,8 @@ import { defineComponent, onBeforeMount, computed, ref } from 'vue'; import { usePricelistStore } from '../store'; import { useMainStore } from 'src/stores'; import SearchInput from './SearchInput.vue'; -import { filter } from '../utils/filter'; -function sort(a: string | number, b: string | number) { - if (a > b) return 1; - if (b > a) return -1; - return 0; -} +import { filter, Search } from '../utils/filter'; +import { sort } from '../utils/sort'; export default defineComponent({ name: 'Pricelist', components: { SearchInput }, @@ -223,7 +219,7 @@ export default defineComponent({ }); return retVal; } - const search = ref({ label: '', value: '', key: '' }); + const search = ref({ label: '', value: '', key: '' }); return { columns_drinks, diff --git a/src/plugins/pricelist/components/SearchInput.vue b/src/plugins/pricelist/components/SearchInput.vue index 44b9da3..6edb3da 100644 --- a/src/plugins/pricelist/components/SearchInput.vue +++ b/src/plugins/pricelist/components/SearchInput.vue @@ -7,19 +7,16 @@ +a diff --git a/src/plugins/pricelist/pages/Receipts.vue b/src/plugins/pricelist/pages/Receipts.vue index 48aac72..6f9c2ba 100644 --- a/src/plugins/pricelist/pages/Receipts.vue +++ b/src/plugins/pricelist/pages/Receipts.vue @@ -44,12 +44,8 @@ import { usePricelistStore } from 'src/plugins/pricelist/store'; import BuildManual from 'src/plugins/pricelist/components/CalculationTable/BuildManual.vue'; import BuildManualVolume from '../components/BuildManual/BuildManualVolume.vue'; import SearchInput from '../components/SearchInput.vue'; -import { filter } from '../utils/filter'; -function sort(a: string | number, b: string | number) { - if (a > b) return 1; - if (b > a) return -1; - return 0; -} +import { filter, Search } from '../utils/filter'; +import { sort } from '../utils/sort'; export default defineComponent({ name: 'Reciepts', components: { BuildManual, BuildManualVolume, SearchInput }, @@ -123,7 +119,7 @@ export default defineComponent({ }, ]; - const search = ref({ value: '', key: '', label: '' }); + const search = ref({ value: '', key: '', label: '' }); return { drinks, diff --git a/src/plugins/pricelist/utils/filter.ts b/src/plugins/pricelist/utils/filter.ts index af4329e..cb8c5ba 100644 --- a/src/plugins/pricelist/utils/filter.ts +++ b/src/plugins/pricelist/utils/filter.ts @@ -2,9 +2,9 @@ import { Drink } from '../store'; function filter( rows: Array, - terms: { value: string; key: string }, - cols: Array<{ name: string; label: string; field: string }>, - cellValue: { (col: { name: string; label: string; field: string }, row: Drink): string } + terms: Search, + cols: Array, + cellValue: { (col: Col, row: Drink): string } ) { if (terms.value) { return rows.filter((row) => { @@ -24,4 +24,16 @@ function filter( return rows; } -export { filter }; +interface Search { + value: string; + label: string | undefined; + key: string | undefined; +} + +interface Col { + name: string; + label: string; + field: string; +} + +export { filter, Search, Col }; diff --git a/src/plugins/pricelist/utils/sort.ts b/src/plugins/pricelist/utils/sort.ts new file mode 100644 index 0000000..cfd6f2a --- /dev/null +++ b/src/plugins/pricelist/utils/sort.ts @@ -0,0 +1,7 @@ +function sort(a: string | number, b: string | number) { + if (a > b) return 1; + if (b > a) return -1; + return 0; +} + +export { sort };