[chore] add serverside sorting for pricelist. fix public viewing
This commit is contained in:
		
							parent
							
								
									2cb72426a1
								
							
						
					
					
						commit
						7f33a44d94
					
				|  | @ -23,7 +23,7 @@ declare namespace FG { | ||||||
|   interface DrinkPrice { |   interface DrinkPrice { | ||||||
|     id: number; |     id: number; | ||||||
|     price: number; |     price: number; | ||||||
|     volume: Array<DrinkPriceVolume> |     volume: Array<DrinkPriceVolume>; | ||||||
|     public: boolean; |     public: boolean; | ||||||
|     description?: string; |     description?: string; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  | @ -414,7 +414,7 @@ export default defineComponent({ | ||||||
|         console.log('result', result.count); |         console.log('result', result.count); | ||||||
|         if (result.count) pagination.value.rowsNumber = result.count; |         if (result.count) pagination.value.rowsNumber = result.count; | ||||||
|       } catch (error) { |       } catch (error) { | ||||||
|         console.warn(error) |         console.warn(error); | ||||||
|       } |       } | ||||||
|       loading.value = false; |       loading.value = false; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | @ -43,7 +43,7 @@ | ||||||
|       </div> |       </div> | ||||||
|       <div class="q-pa-sm"> |       <div class="q-pa-sm"> | ||||||
|         <div v-for="(price, index) in volume.prices" :key="price.id"> |         <div v-for="(price, index) in volume.prices" :key="price.id"> | ||||||
|           <div class="fit row justify-around q-py-sm"> |           <div v-if="isPublic(price, volume)" class="fit row justify-around q-py-sm"> | ||||||
|             <div |             <div | ||||||
|               v-if="!editable || !hasPermission(PERMISSIONS.EDIT_PRICE)" |               v-if="!editable || !hasPermission(PERMISSIONS.EDIT_PRICE)" | ||||||
|               class="text-body1 col-3" |               class="text-body1 col-3" | ||||||
|  | @ -294,6 +294,15 @@ export default defineComponent({ | ||||||
|       emit('update:modelValue', volumes.value); |       emit('update:modelValue', volumes.value); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     function isPublic(price: FG.DrinkPrice, drink) { | ||||||
|  |       console.log('drink', drink); | ||||||
|  |       if (props.public) { | ||||||
|  |         console.log(price); | ||||||
|  |         return price.public; | ||||||
|  |       } | ||||||
|  |       return true; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     const isUnderMinPrice = computed(() => { |     const isUnderMinPrice = computed(() => { | ||||||
|       if (volumes.value) { |       if (volumes.value) { | ||||||
|         const this_volume = volumes.value.find((a) => a.id === volume.value); |         const this_volume = volumes.value.find((a) => a.id === volume.value); | ||||||
|  | @ -328,6 +337,7 @@ export default defineComponent({ | ||||||
|       isUnderMinPrice, |       isUnderMinPrice, | ||||||
|       hasPermission, |       hasPermission, | ||||||
|       PERMISSIONS, |       PERMISSIONS, | ||||||
|  |       isPublic, | ||||||
|     }; |     }; | ||||||
|   }, |   }, | ||||||
| }); | }); | ||||||
|  |  | ||||||
|  | @ -111,11 +111,11 @@ export default defineComponent({ | ||||||
|       if (!props.public) { |       if (!props.public) { | ||||||
|         user.value = useMainStore().currentUser.userid; |         user.value = useMainStore().currentUser.userid; | ||||||
|         void store.getPriceListColumnOrder(user.value); |         void store.getPriceListColumnOrder(user.value); | ||||||
|         onRequest({pagination: pagination.value, filter: {limit: 10}}) |  | ||||||
|         void store.getPriceCalcColumn(user.value); |         void store.getPriceCalcColumn(user.value); | ||||||
|       } else { |       } else { | ||||||
|         user.value = ''; |         user.value = ''; | ||||||
|       } |       } | ||||||
|  |       onRequest({ pagination: pagination.value, filter: { limit: 10 } }); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     const _order = ref<Array<Order>>([ |     const _order = ref<Array<Order>>([ | ||||||
|  | @ -175,7 +175,7 @@ export default defineComponent({ | ||||||
|         //field: 'name', |         //field: 'name', | ||||||
|         field: 'volume', |         field: 'volume', | ||||||
|         format: (val: FG.DrinkPriceVolume) => val.drink.name, |         format: (val: FG.DrinkPriceVolume) => val.drink.name, | ||||||
|         sortable: false, |         sortable: true, | ||||||
|         filterable: true, |         filterable: true, | ||||||
|         align: 'left', |         align: 'left', | ||||||
|       }, |       }, | ||||||
|  | @ -184,7 +184,7 @@ export default defineComponent({ | ||||||
|         label: 'Kategorie', |         label: 'Kategorie', | ||||||
|         //field: 'type', |         //field: 'type', | ||||||
|         field: 'volume', |         field: 'volume', | ||||||
|         sortable: false, |         sortable: true, | ||||||
|         filterable: true, |         filterable: true, | ||||||
|         format: (val: FG.DrinkPriceVolume) => val.drink.type.name, |         format: (val: FG.DrinkPriceVolume) => val.drink.type.name, | ||||||
|       }, |       }, | ||||||
|  | @ -212,14 +212,14 @@ export default defineComponent({ | ||||||
|         //field: 'volume', |         //field: 'volume', | ||||||
|         field: 'volume', |         field: 'volume', | ||||||
|         filterable: true, |         filterable: true, | ||||||
|         sortable: false, |         sortable: true, | ||||||
|         format: (val: FG.DrinkPriceVolume) => `${val.volume.toFixed(3)}L`, |         format: (val: FG.DrinkPriceVolume) => `${val.volume.toFixed(3)}L`, | ||||||
|       }, |       }, | ||||||
|       { |       { | ||||||
|         name: 'price', |         name: 'price', | ||||||
|         label: 'Preis', |         label: 'Preis', | ||||||
|         field: 'price', |         field: 'price', | ||||||
|         sortable: false, |         sortable: true, | ||||||
|         filterable: true, |         filterable: true, | ||||||
|         format: (val: number) => `${val.toFixed(2)}€`, |         format: (val: number) => `${val.toFixed(2)}€`, | ||||||
|       }, |       }, | ||||||
|  | @ -317,13 +317,15 @@ export default defineComponent({ | ||||||
|       //console.log('search_keys', search_keys); |       //console.log('search_keys', search_keys); | ||||||
|       const fetchCount = rowsPerPage === 0 ? pagination.value.rowsNumber : rowsPerPage; |       const fetchCount = rowsPerPage === 0 ? pagination.value.rowsNumber : rowsPerPage; | ||||||
|       const startRow = (page - 1) * rowsPerPage; |       const startRow = (page - 1) * rowsPerPage; | ||||||
|  |       console.log('descending', descending); | ||||||
|       try { |       try { | ||||||
|         const result = await store.getPricelist({ |         const result = await store.getPricelist({ | ||||||
|           offset: startRow, |           offset: startRow, | ||||||
|           limit: fetchCount, |           limit: fetchCount, | ||||||
|           descending, |           descending: descending ? true : undefined, | ||||||
|           search_name: props.filter?.value, |           search_name: props.filter?.value, | ||||||
|           search_key: props.filter?.key, |           search_key: props.filter?.key, | ||||||
|  |           sortBy: sortBy, | ||||||
|         }); |         }); | ||||||
|         pagination.value.page = page; |         pagination.value.page = page; | ||||||
|         pagination.value.rowsPerPage = rowsPerPage; |         pagination.value.rowsPerPage = rowsPerPage; | ||||||
|  | @ -332,7 +334,7 @@ export default defineComponent({ | ||||||
|         console.log('result', result); |         console.log('result', result); | ||||||
|         if (result) pagination.value.rowsNumber = result; |         if (result) pagination.value.rowsNumber = result; | ||||||
|       } catch (error) { |       } catch (error) { | ||||||
|         console.warn(error) |         console.warn(error); | ||||||
|       } |       } | ||||||
|       loading.value = false; |       loading.value = false; | ||||||
|     } |     } | ||||||
|  | @ -343,7 +345,7 @@ export default defineComponent({ | ||||||
|       rowsPerPage: 10, |       rowsPerPage: 10, | ||||||
|       rowsNumber: 10, |       rowsNumber: 10, | ||||||
|       descending: false, |       descending: false, | ||||||
|       page: 1 |       page: 1, | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     const fullscreen = ref(false); |     const fullscreen = ref(false); | ||||||
|  |  | ||||||
							
								
								
									
										25
									
								
								src/store.ts
								
								
								
								
							
							
						
						
									
										25
									
								
								src/store.ts
								
								
								
								
							|  | @ -181,9 +181,12 @@ export const usePricelistStore = defineStore({ | ||||||
|     }) { |     }) { | ||||||
|       if (!filter) filter = { limit: 10 }; |       if (!filter) filter = { limit: 10 }; | ||||||
|       console.log('filter_api', filter); |       console.log('filter_api', filter); | ||||||
|       const { data } = await api.get<{drinks: Array<FG.Drink>; count: number}>('pricelist/drinks', { |       const { data } = await api.get<{ drinks: Array<FG.Drink>; count: number }>( | ||||||
|  |         'pricelist/drinks', | ||||||
|  |         { | ||||||
|           params: filter, |           params: filter, | ||||||
|       }); |         } | ||||||
|  |       ); | ||||||
|       const drinks = []; |       const drinks = []; | ||||||
|       data.drinks.forEach((drink) => { |       data.drinks.forEach((drink) => { | ||||||
|         const _drink = new Drink(drink); |         const _drink = new Drink(drink); | ||||||
|  | @ -202,15 +205,19 @@ export const usePricelistStore = defineStore({ | ||||||
|       descending?: boolean; |       descending?: boolean; | ||||||
|       search_name?: string; |       search_name?: string; | ||||||
|       search_key?: string; |       search_key?: string; | ||||||
|  |       sortBy?: string; | ||||||
|     }) { |     }) { | ||||||
|         const { data } = await api.get<{pricelist: Array<FG.DrinkPrice>; count: number}>('pricelist/list', { |       const { data } = await api.get<{ pricelist: Array<FG.DrinkPrice>; count: number }>( | ||||||
|  |         'pricelist/list', | ||||||
|  |         { | ||||||
|           params: filter, |           params: filter, | ||||||
|         }); |         } | ||||||
|  |       ); | ||||||
|       this.pricelist = []; |       this.pricelist = []; | ||||||
|         console.log(data) |       console.log(data); | ||||||
|       this.pricelist = data.pricelist; |       this.pricelist = data.pricelist; | ||||||
|       console.log(this.pricelist); |       console.log(this.pricelist); | ||||||
|         return data.count |       return data.count; | ||||||
|     }, |     }, | ||||||
|     async deletePrice(price: FG.DrinkPrice) { |     async deletePrice(price: FG.DrinkPrice) { | ||||||
|       await api.delete(`pricelist/prices/${price.id}`); |       await api.delete(`pricelist/prices/${price.id}`); | ||||||
|  | @ -384,9 +391,9 @@ export const usePricelistStore = defineStore({ | ||||||
|           public: price.public, |           public: price.public, | ||||||
|           price: price.price, |           price: price.price, | ||||||
|           description: <string>price.description, |           description: <string>price.description, | ||||||
|               }) |         }); | ||||||
|           }) |       }); | ||||||
|       } |     }, | ||||||
|   }, |   }, | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue