mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2026-01-02 04:39:54 -05:00
refactor list_from_recipe as class RecipeShoppingEditor
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
v-model="selected_objects"
|
||||
:options="objects"
|
||||
:close-on-select="true"
|
||||
:clear-on-select="true"
|
||||
:clear-on-select="multiple"
|
||||
:hide-selected="multiple"
|
||||
:preserve-search="true"
|
||||
:internal-search="false"
|
||||
@@ -48,7 +48,7 @@ export default {
|
||||
},
|
||||
label: { type: String, default: "name" },
|
||||
parent_variable: { type: String, default: undefined },
|
||||
limit: { type: Number, default: 10 },
|
||||
limit: { type: Number, default: 25 },
|
||||
sticky_options: {
|
||||
type: Array,
|
||||
default() {
|
||||
@@ -61,6 +61,10 @@ export default {
|
||||
return []
|
||||
},
|
||||
},
|
||||
initial_single_selection: {
|
||||
type: Object,
|
||||
default: undefined,
|
||||
},
|
||||
multiple: { type: Boolean, default: true },
|
||||
allow_create: { type: Boolean, default: false },
|
||||
create_placeholder: { type: String, default: "You Forgot to Add a Tag Placeholder" },
|
||||
@@ -71,18 +75,37 @@ export default {
|
||||
// watch it
|
||||
this.selected_objects = newVal
|
||||
},
|
||||
initial_single_selection: function (newVal, oldVal) {
|
||||
// watch it
|
||||
this.selected_objects = newVal
|
||||
},
|
||||
clear: function (newVal, oldVal) {
|
||||
this.selected_objects = []
|
||||
if (this.multiple) {
|
||||
this.selected_objects = []
|
||||
} else {
|
||||
this.selected_objects = undefined
|
||||
}
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
this.search("")
|
||||
this.selected_objects = this.initial_selection
|
||||
if (this.multiple || !this.initial_single_selection) {
|
||||
this.selected_objects = this.initial_selection
|
||||
} else {
|
||||
this.selected_objects = this.initial_single_selection
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
lookupPlaceholder() {
|
||||
return this.placeholder || this.model.name || this.$t("Search")
|
||||
},
|
||||
nothingSelected() {
|
||||
if (this.multiple) {
|
||||
return this.selected_objects.length === 0 && this.initial_selection.length === 0
|
||||
} else {
|
||||
return !this.selected_objects && !this.initial_selection
|
||||
}
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
// this.genericAPI inherited from ApiMixin
|
||||
@@ -95,8 +118,9 @@ export default {
|
||||
}
|
||||
this.genericAPI(this.model, this.Actions.LIST, options).then((result) => {
|
||||
this.objects = this.sticky_options.concat(result.data?.results ?? result.data)
|
||||
if (this.selected_objects.length === 0 && this.initial_selection.length === 0 && this.objects.length > 0) {
|
||||
if (this.nothingSelected && this.objects.length > 0) {
|
||||
this.objects.forEach((item) => {
|
||||
// select default items when present in object
|
||||
if ("default" in item) {
|
||||
if (item.default) {
|
||||
if (this.multiple) {
|
||||
@@ -109,6 +133,7 @@ export default {
|
||||
}
|
||||
})
|
||||
}
|
||||
// this.removeMissingItems() # This removes items that are on another page of results
|
||||
})
|
||||
},
|
||||
selectionChanged: function () {
|
||||
@@ -121,6 +146,13 @@ export default {
|
||||
this.search("")
|
||||
}, 750)
|
||||
},
|
||||
// removeMissingItems: function () {
|
||||
// if (this.multiple) {
|
||||
// this.selected_objects = this.selected_objects.filter((x) => !this.objects.map((y) => y.id).includes(x))
|
||||
// } else {
|
||||
// this.selected_objects = this.objects.filter((x) => x.id === this.selected_objects.id)[0]
|
||||
// }
|
||||
// },
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -146,7 +146,7 @@ export default {
|
||||
saveShopping: function (del_shopping = false) {
|
||||
let servings = this.servings
|
||||
if (del_shopping) {
|
||||
servings = 0
|
||||
servings = -1
|
||||
}
|
||||
let params = {
|
||||
id: this.recipe,
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
<b-form-group>
|
||||
<generic-multiselect
|
||||
@change="selectRecipe"
|
||||
:initial_selection="entryEditing_initial_recipe"
|
||||
:initial_single_selection="entryEditing.recipe"
|
||||
:label="'name'"
|
||||
:model="Models.RECIPE"
|
||||
style="flex-grow: 1; flex-shrink: 1; flex-basis: 0"
|
||||
@@ -45,7 +45,7 @@
|
||||
v-bind:placeholder="$t('Meal_Type')"
|
||||
:limit="10"
|
||||
:multiple="false"
|
||||
:initial_selection="entryEditing_initial_meal_type"
|
||||
:initial_single_selection="entryEditing.meal_type"
|
||||
:allow_create="true"
|
||||
:create_placeholder="$t('Create_New_Meal_Type')"
|
||||
@new="createMealType"
|
||||
@@ -81,8 +81,7 @@
|
||||
</b-input-group>
|
||||
</div>
|
||||
<div class="col-lg-6 d-none d-lg-block d-xl-block">
|
||||
<recipe-card v-if="entryEditing.recipe && !entryEditing.addshopping" :recipe="entryEditing.recipe" :detailed="false"></recipe-card>
|
||||
<ingredients-card v-if="entryEditing.recipe && entryEditing.addshopping" :recipe="entryEditing.recipe" :detailed="false"></ingredients-card>
|
||||
<recipe-card v-if="entryEditing.recipe" :recipe="entryEditing.recipe" :detailed="false"></recipe-card>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mt-3 mb-3">
|
||||
@@ -113,8 +112,6 @@ export default {
|
||||
name: "MealPlanEditModal",
|
||||
props: {
|
||||
entry: Object,
|
||||
entryEditing_initial_recipe: Array,
|
||||
entryEditing_initial_meal_type: Array,
|
||||
entryEditing_inital_servings: Number,
|
||||
modal_title: String,
|
||||
modal_id: {
|
||||
@@ -130,7 +127,6 @@ export default {
|
||||
components: {
|
||||
GenericMultiselect,
|
||||
RecipeCard: () => import("@/components/RecipeCard.vue"),
|
||||
IngredientsCard: () => import("@/components/IngredientsCard.vue"),
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
@@ -144,12 +140,20 @@ export default {
|
||||
entry: {
|
||||
handler() {
|
||||
this.entryEditing = Object.assign({}, this.entry)
|
||||
console.log("entryEditing", this.entryEditing)
|
||||
if (this.entryEditing_inital_servings) {
|
||||
this.entryEditing.servings = this.entryEditing_inital_servings
|
||||
}
|
||||
},
|
||||
deep: true,
|
||||
},
|
||||
entryEditing: {
|
||||
handler(newVal) {},
|
||||
deep: true,
|
||||
},
|
||||
entryEditing_inital_servings: function (newVal) {
|
||||
this.entryEditing.servings = newVal
|
||||
},
|
||||
},
|
||||
mounted: function () {},
|
||||
computed: {
|
||||
|
||||
@@ -106,7 +106,6 @@ export default {
|
||||
deep: true,
|
||||
},
|
||||
servings: function (newVal) {
|
||||
console.log(newVal)
|
||||
this.recipe_servings = parseInt(newVal)
|
||||
},
|
||||
},
|
||||
|
||||
@@ -64,8 +64,8 @@
|
||||
</b-modal>
|
||||
|
||||
<meal-plan-edit-modal
|
||||
v-if="entryEditing"
|
||||
:entry="entryEditing"
|
||||
:entryEditing_initial_recipe="[recipe]"
|
||||
:entryEditing_inital_servings="servings_value"
|
||||
:entry-editing_initial_meal_type="[]"
|
||||
@save-entry="saveMealPlan"
|
||||
|
||||
Reference in New Issue
Block a user