From a5e343ca372918ad3e66d14c0d3a8474e839eae5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Tue, 16 Nov 2021 09:52:09 +0100 Subject: [PATCH] [fix] fix minor linting problems --- .eslintrc.js | 1 + .gitignore | 1 + src/api.d.ts | 4 +- .../CalculationTable/Ingredients.vue | 14 ++--- src/components/Pricelist.vue | 14 ++--- src/index.ts | 5 +- src/pages/CocktailBuilder.vue | 2 +- src/pages/InnerPricelist.vue | 2 +- src/pages/Receipts.vue | 8 +-- src/pages/Settings.vue | 2 +- src/store.ts | 61 ++++--------------- 11 files changed, 34 insertions(+), 80 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index b1c98ba..abb7497 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -68,6 +68,7 @@ module.exports = { quotes: ['warn', 'single', { avoidEscape: true }], '@typescript-eslint/explicit-function-return-type': 'off', '@typescript-eslint/explicit-module-boundary-types': 'off', + 'vue/multi-word-component-names': 'off', // allow debugger during development only 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off', diff --git a/.gitignore b/.gitignore index a724e6a..b932595 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ node_modules yarn-error.log # No need for sharing this yarn.lock +.idea diff --git a/src/api.d.ts b/src/api.d.ts index 7a8559f..a9ddd31 100644 --- a/src/api.d.ts +++ b/src/api.d.ts @@ -23,13 +23,13 @@ declare namespace FG { interface DrinkPrice { id: number; price: number; - volume: Array; + volume?: DrinkPriceVolume; public: boolean; description?: string; } interface DrinkPriceVolume { id: number; - drink: Array; + drink?: Drink; volume: number; min_prices: Array; prices: Array; diff --git a/src/components/CalculationTable/Ingredients.vue b/src/components/CalculationTable/Ingredients.vue index 4e5ba4b..adae378 100644 --- a/src/components/CalculationTable/Ingredients.vue +++ b/src/components/CalculationTable/Ingredients.vue @@ -203,7 +203,7 @@ export default defineComponent({ id: -1, ingredient_id: newIngredient.value.id, volume: newIngredientVolume.value, - cost_per_volume: newIngredient.value.cost_per_volume, + cost_per_volume: (newIngredient.value).cost_per_volume, name: newIngredient.value.name, }, extra_ingredient: undefined, @@ -243,17 +243,11 @@ export default defineComponent({ emit('update:modelValue', unref(edit_ingredients)); update(); } - //const drinks = computed(() => - // store.drinks.filter((drink) => { - // console.log('computed drinks', drink.name, drink.cost_per_volume); - // return drink.cost_per_volume; - // }) - //); const drinks = ref>([]); const _extra_ingredients = computed(() => store.extraIngredients); const extra_ingredients = ref(_extra_ingredients.value); - async function filter_drinks(val, update) { + async function filter_drinks(val: string, update: (a: () => void) => void) { let result = >[]; if (val === '') { result = await store.getDrinks_no_store({ limit: 5, ingredient: true }); @@ -269,7 +263,7 @@ export default defineComponent({ drinks.value = result; }); } - function filter_extra_ingredients(val, update) { + function filter_extra_ingredients(val: string, update: (a: () => void) => void) { if (val === '') { update(() => { extra_ingredients.value = _extra_ingredients.value; @@ -283,7 +277,7 @@ export default defineComponent({ } } - async function filter(val, update) { + async function filter(val: string, update: () => void) { await filter_drinks(val, update); filter_extra_ingredients(val, update); } diff --git a/src/components/Pricelist.vue b/src/components/Pricelist.vue index dfd80f4..d8fbd6f 100644 --- a/src/components/Pricelist.vue +++ b/src/components/Pricelist.vue @@ -82,7 +82,7 @@ import SearchInput from '../components/SearchInput.vue'; import { usePricelistStore, Order } from '../store'; import { useMainStore } from '@flaschengeist/api'; import { Search, filter } from '../utils/filter'; -import drag from 'vuedraggable'; +import draggableComponent from 'vuedraggable'; interface Row { name: string; @@ -96,7 +96,7 @@ interface Row { export default defineComponent({ name: 'Pricelist', - components: { SearchInput, drag: drag }, + components: { SearchInput, drag: draggableComponent }, props: { public: { type: Boolean, @@ -115,7 +115,7 @@ export default defineComponent({ } else { user.value = ''; } - onRequest({ pagination: pagination.value, filter: { limit: 10 } }); + void onRequest({ pagination: pagination.value }); }); const _order = ref>([ @@ -174,7 +174,7 @@ export default defineComponent({ label: 'Name', //field: 'name', field: 'volume', - format: (val: FG.DrinkPriceVolume) => val.drink.name, + format: (val: FG.DrinkPriceVolume) => val.drink?.name, sortable: true, filterable: true, align: 'left', @@ -186,7 +186,7 @@ export default defineComponent({ field: 'volume', sortable: true, filterable: true, - format: (val: FG.DrinkPriceVolume) => val.drink.type.name, + format: (val: FG.DrinkPriceVolume) => val.drink?.type?.name, }, { name: 'tags', @@ -197,8 +197,8 @@ export default defineComponent({ format: (val: FG.DrinkPriceVolume) => { let retVal = ''; - val.drink.tags.forEach((tag, index) => { - if (index >= val.length - 1 && index > 0) { + val.drink?.tags?.forEach((tag, index) => { + if (index >= (>val.drink?.tags).length - 1 && index > 0) { retVal += ', '; } retVal += tag.name; diff --git a/src/index.ts b/src/index.ts index 1a65597..d90da12 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,13 +1,12 @@ import { innerRoutes, outerRoutes } from './routes'; -import { FG_Plugin } from '@flaschengeist/typings'; +import { FG_Plugin } from '@flaschengeist/types'; const plugin: FG_Plugin.Plugin = { id: 'pricelist', name: 'Pricelist', innerRoutes, outerRoutes, - requiredModules: [], - requiredBackendModules: ['pricelist'], + requiredModules: [['pricelist']], version: '0.0.1', widgets: [], }; diff --git a/src/pages/CocktailBuilder.vue b/src/pages/CocktailBuilder.vue index 1b02dd0..9a91ea4 100644 --- a/src/pages/CocktailBuilder.vue +++ b/src/pages/CocktailBuilder.vue @@ -39,7 +39,7 @@ export default defineComponent({ void store.get_min_prices().finally(() => { volume.value.min_prices = calc_min_prices(volume.value, undefined, store.min_prices); }); - void store.getDrinks(); + void store.getDrinks({ limit: 10 }); void store.getDrinkTypes(); void store.getExtraIngredients(); }); diff --git a/src/pages/InnerPricelist.vue b/src/pages/InnerPricelist.vue index 9e23e80..84e0cb2 100644 --- a/src/pages/InnerPricelist.vue +++ b/src/pages/InnerPricelist.vue @@ -25,7 +25,7 @@ export default defineComponent({ const mainStore = useMainStore(); onBeforeMount(() => { - void store.getDrinks(); + void store.getDrinks({ limit: 10 }); void store.getPriceListView(mainStore.currentUser.userid); }); diff --git a/src/pages/Receipts.vue b/src/pages/Receipts.vue index 94797fe..97d0127 100644 --- a/src/pages/Receipts.vue +++ b/src/pages/Receipts.vue @@ -71,10 +71,8 @@ export default defineComponent({ setup() { const store = usePricelistStore(); onBeforeMount(() => { - //void store.getDrinks(); - onRequest({ + void onRequest({ pagination: pagination.value, - filter: { limit: 10, receipt: true }, }); }); const drinks = computed( @@ -192,8 +190,8 @@ export default defineComponent({ offset: startRow, limit: fetchCount, descending, - search_name: props.filter.value, - search_key: props.filter.key, + search_name: props.filter?.value, + search_key: props.filter?.key, receipt: true, }); pagination.value.page = page; diff --git a/src/pages/Settings.vue b/src/pages/Settings.vue index 6f51be7..99f9d2f 100644 --- a/src/pages/Settings.vue +++ b/src/pages/Settings.vue @@ -77,7 +77,7 @@ export default defineComponent({ .catch((err) => console.log(err)); void store.getTags(); void store.getDrinkTypes(); - void store.getDrinks(); + void store.getDrinks({ limit: 10 }); void store.get_min_prices(); }); diff --git a/src/store.ts b/src/store.ts index 6483039..fd316ab 100644 --- a/src/store.ts +++ b/src/store.ts @@ -14,16 +14,6 @@ interface Drink extends Omit, 'volumes'> { _cost_per_volume?: number; } -interface Pricelist { - name: string; - type: FG.DrinkType; - tags: Array; - volume: number; - price: number; - public: boolean; - description: string; -} - class DrinkPriceVolume implements DrinkPriceVolume { constructor({ id, volume, prices, ingredients }: FG.DrinkPriceVolume) { this.id = id; @@ -149,9 +139,12 @@ export const usePricelistStore = defineStore({ }) { if (!filter) filter = { limit: 10 }; console.log('filter_api', filter); - const { data } = await api.get>('pricelist/drinks', { - params: filter, - }); + const { data } = await api.get<{ drinks: Array; count: number }>( + 'pricelist/drinks', + { + params: filter, + } + ); this.drinks = []; data.drinks.forEach((drink) => { const _drink = new Drink(drink); @@ -187,7 +180,7 @@ export const usePricelistStore = defineStore({ params: filter, } ); - const drinks = []; + const drinks: Array = []; data.drinks.forEach((drink) => { const _drink = new Drink(drink); drink.volumes.forEach((volume) => { @@ -266,7 +259,9 @@ export const usePricelistStore = defineStore({ _ingredient.drink_ingredient && _ingredient.drink_ingredient.ingredient_id === drink.id ) { - _ingredient.drink_ingredient.cost_per_volume = drink.cost_per_volume; + if (drink.cost_per_volume != null) { + _ingredient.drink_ingredient.cost_per_volume = drink.cost_per_volume; + } _ingredient.drink_ingredient.name = drink.name; } }); @@ -360,41 +355,7 @@ export const usePricelistStore = defineStore({ this.pricelist_columns_order = data; }, }, - getters: { - /*pricelist() { - const retVal: Array = []; - this.drinks.forEach((drink) => { - drink.volumes.forEach((volume) => { - volume.prices.forEach((price) => { - retVal.push({ - name: drink.name, - type: drink.type, - tags: >drink.tags, - volume: volume.volume, - price: price.price, - public: price.public, - description: price.description, - }); - }); - }); - }); - return retVal; - },*/ - computed_pricelist() { - const retVal: Array = []; - this.pricelist.forEach((price) => { - retVal.push({ - name: price.volume.drink.name, - type: price.volume.drink.type, - tags: >price.volume.drink.tags, - volume: price.volume.volume, - public: price.public, - price: price.price, - description: price.description, - }); - }); - }, - }, + getters: {}, }); export { DrinkPriceVolume, Drink, Order };