Skip to content

Commit

Permalink
update SLR servings UI
Browse files Browse the repository at this point in the history
  • Loading branch information
vabene1111 committed Dec 30, 2023
1 parent 57d87c8 commit c695f0d
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 65 deletions.
42 changes: 0 additions & 42 deletions cookbook/static/themes/tandoor_dark.min.css
Original file line number Diff line number Diff line change
Expand Up @@ -2850,78 +2850,36 @@ input[type=button].btn-block, input[type=reset].btn-block, input[type=submit].bt
color: #fff
}

.btn-primary:hover {
background: transparent;
color: #b98766;
border: 1px solid #b98766
}

.btn-secondary {
transition: all .5s ease-in-out;
color: #fff
}

.btn-secondary:hover {
background: transparent;
color: #b55e4f;
border: 1px solid #b55e4f
}

.btn-success {
transition: all .5s ease-in-out;
color: #fff
}

.btn-success:hover {
background: transparent;
color: #82aa8b;
border: 1px solid #82aa8b
}

.btn-info {
transition: all .5s ease-in-out;
color: #fff
}

.btn-info:hover {
background: transparent;
color: #385f84;
border: 1px solid #385f84
}

.btn-warning {
transition: all .5s ease-in-out;
color: #fff
}

.btn-warning:hover {
background: transparent;
color: #eaaa21;
border: 1px solid #eaaa21
}

.btn-danger {
transition: all .5s ease-in-out;
color: #fff
}

.btn-danger:hover {
background: transparent;
color: #a7240e;
border: 1px solid #a7240e
}

.btn-light {
transition: all .5s ease-in-out;
color: #fff
}

.btn-light:hover {
background-color: hsla(0, 0%, 18%, .5);
color: #cfd5cd;
border: 1px solid hsla(0, 0%, 18%, .5)
}

.btn-dark {
transition: all .5s ease-in-out;
color: #fff
Expand Down
82 changes: 60 additions & 22 deletions vue/src/apps/ShoppingListView/ShoppingListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
<span class="d-none d-md-block">{{ $t('Recipes') + ` (${Object.keys(shopping_list_store.getAssociatedRecipes()).length})` }}</span>
</template>


<b-row class="d-lg-block d-print-none d-none pr-1 pl-1 mb-3 mt-3">
<b-col cols="12">
<generic-multiselect
Expand All @@ -85,17 +86,25 @@
</b-col>
</b-row>


<b-row v-for="r in shopping_list_store.getAssociatedRecipes()" :key="r.shopping_list_recipe_id" class="pr-1 pl-1">
<b-col cols="12">
<b-button-group class="w-100 mt-1">
<b-button-group class="w-100 mt-2">
<b-button variant="dark" block class="btn btn-block text-left">
<span>{{ r.recipe_name }}</span> <br/>
<span><small class="text-muted">{{ r.recipe_name }}</small></span> <!-- TODO show meal plan date/type -->
</b-button>
<b-form-input min="1" type="number" :debounce="300" v-model="r.servings" @update="updateServings(r.shopping_list_recipe_id, r.servings)"></b-form-input>
<!-- <b-form-input min="1" type="number" :debounce="300" v-model="r.servings" @update="updateServings(r.shopping_list_recipe_id, r.servings)"></b-form-input>-->
<b-button variant="danger" @click="deleteRecipe(r.shopping_list_recipe_id)"><i class="fas fa-trash fa-fw"></i></b-button>
</b-button-group>

<b-button-group class="w-100 mt-1">
<b-button @click="r.servings = updateServings(r, 'half')" :disabled="shopping_list_store.currently_updating"><i class="fas fa-divide"></i> 2</b-button>
<b-button variant="info" @click="r.servings = updateServings(r, 'sub')" :disabled="shopping_list_store.currently_updating"><i class="fas fa-minus"></i></b-button>
<b-button variant="info" @click="r.servings = updateServings(r, 'prompt')">{{ r.servings }}</b-button>
<b-button variant="info" @click="r.servings = updateServings(r, 'add')" :disabled="shopping_list_store.currently_updating"><i class="fas fa-plus"></i></b-button>
<b-button @click="r.servings = updateServings(r, 'multiply')" :disabled="shopping_list_store.currently_updating"><i class="fas fa-times"></i> 2</b-button>
</b-button-group>

</b-col>
</b-row>
Expand Down Expand Up @@ -361,17 +370,28 @@
<shopping-modal v-if="new_recipe.id" :recipe="new_recipe" :modal_id="new_recipe.id" :servings="new_recipe.servings" :mealplan="undefined" @finish="finishShopping"/>

<bottom-navigation-bar active-view="view_shopping">
<template #custom_nav_content>
<template #custom_nav_content v-if="current_tab <= 1">
<div class="d-flex flex-row justify-content-around mb-3">

<b-input-group>
<b-form-input v-model="new_item.ingredient" :placeholder="$t('Food')" @keyup.enter="addItem"></b-form-input>
<b-input-group-append>
<b-button @click="addItem" variant="success">
<i class="fas fa-cart-plus "/>
</b-button>
</b-input-group-append>
</b-input-group>

<template v-if="current_tab===0">
<b-input-group>
<b-form-input v-model="new_item.ingredient" :placeholder="$t('Food')" @keyup.enter="addItem"></b-form-input>
<b-input-group-append>
<b-button @click="addItem" variant="success">
<i class="fas fa-cart-plus "/>
</b-button>
</b-input-group-append>
</b-input-group>
</template>
<template v-if="current_tab===1">
<generic-multiselect
:model="Models.RECIPE"
:multiple="false"
@change="addRecipeToShopping($event.val)"
></generic-multiselect>
</template>


</div>
</template>
Expand Down Expand Up @@ -691,9 +711,8 @@ export default {
*/
deleteRecipe: function (shopping_list_recipe_id) {
let api = new ApiApiFactory()
//TODO properly integrate into store logic
api.destroyShoppingListRecipe(shopping_list_recipe_id).then((x) => {
useShoppingListStore().refreshFromAPI()
useShoppingListStore().refreshFromAPI() //TODO only do partial refresh
}).catch((err) => {
StandardToasts.makeStandardToast(this, StandardToasts.FAIL_DELETE, err)
})
Expand Down Expand Up @@ -841,16 +860,37 @@ export default {
/**
* change number of servings of a shopping list recipe
* backend handles scaling of associated entries
* @param shopping_list_recipe_id shopping list recipe to update
* @param servings number of servings to set shopping list recipe to
* @param recipe recipe to update
* @param mode mode to change servings
*/
updateServings(shopping_list_recipe_id, servings) {
if (servings !== 0 && servings !== "") {
console.log('NEW SERVINGS', servings)
updateServings(recipe, mode) {
if (mode === 'half') {
recipe.servings = recipe.servings / 2
}
if (mode === 'multiply') {
recipe.servings = recipe.servings * 2
}
if (mode === 'add') {
recipe.servings++
}
if (mode === 'sub') {
recipe.servings--
}
if (mode === 'prompt') {
let servings = prompt(this.$t('Servings'), recipe.servings);
if (servings !== null && servings !== "" && !isNaN(servings) && !isNaN(parseFloat(servings))) {
recipe.servings = parseFloat(servings)
} else {
console.log('Invalid input in servings prompt', servings)
}
}
if (recipe.servings > 0 && recipe.servings !== "") {
let api = new ApiApiFactory()
api.partialUpdateShoppingListRecipe(shopping_list_recipe_id, {id: shopping_list_recipe_id, servings: servings}).then(() => {
api.partialUpdateShoppingListRecipe(recipe.shopping_list_recipe_id, {id: recipe.shopping_list_recipe_id, servings: recipe.servings}).then(() => {
useShoppingListStore().refreshFromAPI()
})
return recipe.servings
}
},
deleteSupermarket(index) {
Expand Down Expand Up @@ -1100,10 +1140,8 @@ export default {
})
},
finishShopping() {
this.add_recipe_servings = 1
this.new_recipe = {id: undefined}
this.edit_recipe_list = undefined
this.getShoppingList()
useShoppingListStore().refreshFromAPI() //TODO only do partial fetch
},
editRecipeList(e, r) {
this.new_recipe = {
Expand Down
3 changes: 2 additions & 1 deletion vue/src/stores/ShoppingListStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ export const useShoppingListStore = defineStore(_STORE_ID, {
},
},
actions: {
// TODO implement shopping list recipes
/**
* Retrieves all shopping related data (shopping list entries, supermarkets, supermarket categories and shopping list recipes) from API
*/
Expand All @@ -133,6 +132,8 @@ export const useShoppingListStore = defineStore(_STORE_ID, {
this.currently_updating = true
let apiClient = new ApiApiFactory()
apiClient.listShoppingListEntrys().then((r) => {
this.entries = {}

r.data.forEach((e) => {
Vue.set(this.entries, e.id, e)
})
Expand Down

0 comments on commit c695f0d

Please sign in to comment.