food edit modal - reset children inheritance

This commit is contained in:
Chris Scoggins
2022-02-02 09:53:37 -06:00
parent a0508684d9
commit dcad389010
6 changed files with 40 additions and 20 deletions

View File

@ -1029,6 +1029,7 @@ export default {
if (!this.searchFiltered()) {
params.options.query.last_viewed = this.ui.recently_viewed
}
console.log(params)
return params
},
searchFiltered: function (ignore_string = false) {

View File

@ -271,29 +271,27 @@ export default {
if (type_match && field?.condition) {
const value = this.item1[field?.condition?.field]
const preference = getUserPreference(field?.condition?.field)
console.log("condition", field?.condition?.condition)
checks = false
switch (field?.condition?.condition) {
case "field_exists":
if ((value != undefined) === field.condition.value) {
checks = true
} else {
checks = false
}
break
case "preference__array_exists":
if (preference?.length > 0 === field.condition.value) {
checks = true
} else {
checks = false
}
break
case "preference_equals":
if (preference === field.condition.value) {
checks = true
} else {
checks = false
}
break
case "gt":
if (value > field.condition.value) {
checks = true
}
}
}
return type_match && checks

View File

@ -326,5 +326,6 @@
"make_now": "Make Now",
"recipe_filter": "Recipe Filter",
"book_filter_help": "Include recipes from recipe filter instead of assigning each recipe",
"filter": "Filter"
"reset_children": "Reset Child Inheritance",
"reset_children_help": "Overwrite all children with values from inherited fields."
}

View File

@ -76,7 +76,7 @@ export class Models {
// REQUIRED: unordered array of fields that can be set during create
create: {
// if not defined partialUpdate will use the same parameters, prepending 'id'
params: [["name", "description", "recipe", "food_onhand", "supermarket_category", "inherit", "inherit_fields", "ignore_shopping"]],
params: [["name", "description", "recipe", "food_onhand", "supermarket_category", "inherit", "inherit_fields", "ignore_shopping", "reset_inherit"]],
form: {
show_help: true,
@ -135,6 +135,14 @@ export class Models {
label: i18n.t("InheritFields"),
condition: { field: "food_children_exist", value: true, condition: "preference_equals" },
},
reset_inherit: {
form_field: true,
type: "checkbox",
field: "reset_inherit",
label: i18n.t("reset_children"),
help_text: i18n.t("reset_children_help"),
condition: { field: "numchild", value: 0, condition: "gt" },
},
form_function: "FoodCreateDefault",
},
},