Merge branch 'feature/export-progress' into develop

This commit is contained in:
vabene1111
2022-01-28 15:41:49 +01:00
committed by GitHub
141 changed files with 14841 additions and 8379 deletions

View File

@@ -59,7 +59,7 @@ export class Models {
// MODELS - inherits and takes precedence over MODEL_TYPES and ACTIONS
static FOOD = {
name: i18n.t("Food"), // *OPTIONAL* : parameters will be built model -> model_type -> default
name: "Food", // *OPTIONAL* : parameters will be built model -> model_type -> default
apiName: "Food", // *REQUIRED* : the name that is used in api.ts for this model
model_type: this.TREE, // *OPTIONAL* : model specific params for api, if not present will attempt modeltype_create then default_create
paginated: true,
@@ -76,15 +76,17 @@ 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"]],
params: [["name", "description", "recipe", "food_onhand", "supermarket_category", "inherit", "inherit_fields", "ignore_shopping"]],
form: {
show_help: true,
name: {
form_field: true,
type: "text",
field: "name",
label: i18n.t("Name"),
placeholder: "",
subtitle_field: "full_name",
},
description: {
form_field: true,
@@ -99,12 +101,21 @@ export class Models {
field: "recipe",
list: "RECIPE",
label: i18n.t("Recipe"),
help_text: i18n.t("food_recipe_help"),
},
shopping: {
onhand: {
form_field: true,
type: "checkbox",
field: "food_onhand",
label: i18n.t("OnHand"),
help_text: i18n.t("OnHand_help"),
},
ignore_shopping: {
form_field: true,
type: "checkbox",
field: "ignore_shopping",
label: i18n.t("Ignore_Shopping"),
help_text: i18n.t("ignore_shopping_help"),
},
shopping_category: {
form_field: true,
@@ -113,6 +124,7 @@ export class Models {
list: "SHOPPING_CATEGORY",
label: i18n.t("Shopping_Category"),
allow_create: true,
help_text: i18n.t("shopping_category_help"),
},
inherit_fields: {
form_field: true,
@@ -121,12 +133,7 @@ export class Models {
field: "inherit_fields",
list: "FOOD_INHERIT_FIELDS",
label: i18n.t("InheritFields"),
condition: { field: "parent", value: true, condition: "exists" },
},
full_name: {
form_field: true,
type: "smalltext",
field: "full_name",
condition: { field: "food_children_exist", value: true, condition: "preference_equals" },
},
form_function: "FoodCreateDefault",
},
@@ -136,12 +143,12 @@ export class Models {
},
}
static FOOD_INHERIT_FIELDS = {
name: i18n.t("FoodInherit"),
name: "FoodInherit",
apiName: "FoodInheritField",
}
static KEYWORD = {
name: i18n.t("Keyword"), // *OPTIONAL: parameters will be built model -> model_type -> default
name: "Keyword", // *OPTIONAL: parameters will be built model -> model_type -> default
apiName: "Keyword",
model_type: this.TREE,
paginated: true,
@@ -184,7 +191,7 @@ export class Models {
}
static UNIT = {
name: i18n.t("Unit"),
name: "Unit",
apiName: "Unit",
paginated: true,
create: {
@@ -210,7 +217,7 @@ export class Models {
}
static SHOPPING_LIST = {
name: i18n.t("Shopping_list"),
name: "Shopping_list",
apiName: "ShoppingListEntry",
list: {
params: ["id", "checked", "supermarket", "options"],
@@ -239,7 +246,7 @@ export class Models {
}
static RECIPE_BOOK = {
name: i18n.t("Recipe_Book"),
name: "Recipe_Book",
apiName: "RecipeBook",
create: {
params: [["name", "description", "icon"]],
@@ -269,7 +276,7 @@ export class Models {
}
static SHOPPING_CATEGORY = {
name: i18n.t("Shopping_Category"),
name: "Shopping_Category",
apiName: "SupermarketCategory",
create: {
params: [["name", "description"]],
@@ -293,7 +300,7 @@ export class Models {
}
static SHOPPING_CATEGORY_RELATION = {
name: i18n.t("Shopping_Category_Relation"),
name: "Shopping_Category_Relation",
apiName: "SupermarketCategoryRelation",
create: {
params: [["category", "supermarket", "order"]],
@@ -317,7 +324,7 @@ export class Models {
}
static SUPERMARKET = {
name: i18n.t("Supermarket"),
name: "Supermarket",
apiName: "Supermarket",
ordered_tags: [{ field: "category_to_supermarket", label: "category::name", color: "info" }],
create: {
@@ -360,7 +367,7 @@ export class Models {
}
static AUTOMATION = {
name: i18n.t("Automation"),
name: "Automation",
apiName: "Automation",
paginated: true,
list: {
@@ -423,7 +430,7 @@ export class Models {
}
static RECIPE = {
name: i18n.t("Recipe"),
name: "Recipe",
apiName: "Recipe",
list: {
params: ["query", "keywords", "foods", "units", "rating", "books", "keywordsOr", "foodsOr", "booksOr", "internal", "random", "_new", "page", "pageSize", "options"],
@@ -439,7 +446,7 @@ export class Models {
}
static USER_NAME = {
name: i18n.t("User"),
name: "User",
apiName: "User",
list: {
params: ["filter_list"],
@@ -447,7 +454,7 @@ export class Models {
}
static MEAL_TYPE = {
name: i18n.t("Meal_Type"),
name: "Meal_Type",
apiName: "MealType",
list: {
params: ["filter_list"],
@@ -455,7 +462,7 @@ export class Models {
}
static MEAL_PLAN = {
name: i18n.t("Meal_Plan"),
name: "Meal_Plan",
apiName: "MealPlan",
list: {
params: ["options"],
@@ -463,7 +470,7 @@ export class Models {
}
static USERFILE = {
name: i18n.t("File"),
name: "File",
apiName: "UserFile",
paginated: false,
list: {
@@ -492,13 +499,13 @@ export class Models {
},
}
static USER = {
name: i18n.t("User"),
name: "User",
apiName: "User",
paginated: false,
}
static STEP = {
name: i18n.t("Step"),
name: "Step",
apiName: "Step",
list: {
params: ["recipe", "query", "page", "pageSize", "options"],

View File

@@ -312,6 +312,12 @@ export interface Food {
* @memberof Food
*/
full_name?: string;
/**
*
* @type {boolean}
* @memberof Food
*/
ignore_shopping?: boolean;
}
/**
*
@@ -708,6 +714,12 @@ export interface IngredientFood {
* @memberof IngredientFood
*/
full_name?: string;
/**
*
* @type {boolean}
* @memberof IngredientFood
*/
ignore_shopping?: boolean;
}
/**
*
@@ -1353,6 +1365,12 @@ export interface MealPlanRecipe {
* @memberof MealPlanRecipe
*/
_new?: string;
/**
*
* @type {string}
* @memberof MealPlanRecipe
*/
recent?: string;
}
/**
*
@@ -1813,25 +1831,25 @@ export interface RecipeNutrition {
* @type {string}
* @memberof RecipeNutrition
*/
carbohydrates?: string;
carbohydrates: string;
/**
*
* @type {string}
* @memberof RecipeNutrition
*/
fats?: string;
fats: string;
/**
*
* @type {string}
* @memberof RecipeNutrition
*/
proteins?: string;
proteins: string;
/**
*
* @type {string}
* @memberof RecipeNutrition
*/
calories?: string;
calories: string;
/**
*
* @type {string}
@@ -1941,6 +1959,12 @@ export interface RecipeOverview {
* @memberof RecipeOverview
*/
_new?: string;
/**
*
* @type {string}
* @memberof RecipeOverview
*/
recent?: string;
}
/**
*
@@ -2016,12 +2040,6 @@ export interface RecipeSteps {
* @memberof RecipeSteps
*/
name?: string;
/**
*
* @type {string}
* @memberof RecipeSteps
*/
type?: RecipeStepsTypeEnum;
/**
*
* @type {string}
@@ -2089,18 +2107,6 @@ export interface RecipeSteps {
*/
numrecipe?: string;
}
/**
* @export
* @enum {string}
*/
export enum RecipeStepsTypeEnum {
Text = 'TEXT',
Time = 'TIME',
File = 'FILE',
Recipe = 'RECIPE'
}
/**
*
* @export
@@ -2621,12 +2627,6 @@ export interface Step {
* @memberof Step
*/
name?: string;
/**
*
* @type {string}
* @memberof Step
*/
type?: StepTypeEnum;
/**
*
* @type {string}
@@ -2694,18 +2694,6 @@ export interface Step {
*/
numrecipe?: string;
}
/**
* @export
* @enum {string}
*/
export enum StepTypeEnum {
Text = 'TEXT',
Time = 'TIME',
File = 'FILE',
Recipe = 'RECIPE'
}
/**
*
* @export
@@ -3050,6 +3038,12 @@ export interface UserPreference {
* @memberof UserPreference
*/
default_page?: UserPreferenceDefaultPageEnum;
/**
*
* @type {boolean}
* @memberof UserPreference
*/
use_fractions?: boolean;
/**
*
* @type {boolean}
@@ -3124,10 +3118,10 @@ export interface UserPreference {
mealplan_autoexclude_onhand?: boolean;
/**
*
* @type {Array<number>}
* @type {Array<MealPlanShared>}
* @memberof UserPreference
*/
shopping_share?: Array<number>;
shopping_share?: Array<MealPlanShared> | null;
/**
*
* @type {number}
@@ -3158,6 +3152,13 @@ export interface UserPreference {
* @memberof UserPreference
*/
shopping_add_onhand?: boolean;
/**
*
* @type {boolean}
* @memberof UserPreference
*/
left_handed?: boolean;
}
/**

View File

@@ -156,7 +156,7 @@ export function getUserPreference(pref = undefined) {
return undefined
}
if (pref) {
return user_preference[pref]
return user_preference?.[pref]
}
return user_preference
}
@@ -389,6 +389,8 @@ export function getForm(model, action, item1, item2) {
}
if (value?.form_field) {
value["value"] = item1?.[value?.field] ?? undefined
value["help"] = item1?.[value?.help_text_field] ?? value?.help_text ?? undefined
value["subtitle"] = item1?.[value?.subtitle_field] ?? value?.subtitle ?? undefined
form.fields.push({
...value,
...{
@@ -508,32 +510,48 @@ const specialCases = {
// delete, update or change all of the category/relations
let id = result.id
let existing_categories = result.category_to_supermarket
let updated_categories = options.category_to_supermarket
let updated_categories = options.category_to_supermarket.map((x) => {
return {
...x,
category: {
id: x?.category?.id ?? x.id,
name: x?.category?.name ?? x.name,
},
id: x?.category_to_supermarket__id,
order: x?.order ?? x?.category_to_supermarket__order,
}
})
let promises = []
// if the 'category.name' key does not exist on the updated_categories, the categories were not updated
if (updated_categories?.[0]?.category?.name) {
// list of category relationship ids that are not part of the updated supermarket
let removed_categories = existing_categories.filter((x) => !updated_categories.map((x) => x.category.id).includes(x.category.id))
let added_categories = updated_categories.filter((x) => !existing_categories.map((x) => x.category.id).includes(x.category.id))
let changed_categories = updated_categories.filter((x) => existing_categories.map((x) => x.category.id).includes(x.category.id))
removed_categories.forEach((x) => {
promises.push(GenericAPI(Models.SHOPPING_CATEGORY_RELATION, Actions.DELETE, { id: x.id }))
})
let item = { supermarket: id }
added_categories.forEach((x) => {
item.order = x.order
item.category = { id: x.category.id, name: x.category.name }
promises.push(GenericAPI(Models.SHOPPING_CATEGORY_RELATION, Actions.CREATE, item))
})
changed_categories.forEach((x) => {
item.id = x?.id ?? existing_categories.find((y) => y.category.id === x.category.id).id
item.order = x.order
item.category = { id: x.category.id, name: x.category.name }
promises.push(GenericAPI(Models.SHOPPING_CATEGORY_RELATION, Actions.UPDATE, item))
})
}
// list of category relationship ids that are not part of the updated supermarket
let removed_categories = existing_categories.filter((x) => !updated_categories.map((x) => x.category.id).includes(x.category.id))
let added_categories = updated_categories.filter((x) => !existing_categories.map((x) => x.category.id).includes(x.category.id))
let changed_categories = updated_categories.filter((x) => existing_categories.map((x) => x.category.id).includes(x.category.id))
let order = Math.max(...existing_categories.map((x) => x?.order ?? 0), ...updated_categories.map((x) => x?.order ?? 0), 0) + 1
removed_categories.forEach((x) => {
promises.push(GenericAPI(Models.SHOPPING_CATEGORY_RELATION, Actions.DELETE, { id: x.id }))
})
let item = { supermarket: id }
added_categories.forEach((x) => {
item.order = x?.order ?? order
if (!x?.order) {
order = order + 1
}
item.category = { id: x.category.id, name: x.category.name }
promises.push(GenericAPI(Models.SHOPPING_CATEGORY_RELATION, Actions.CREATE, item))
})
changed_categories.forEach((x) => {
item.id = x?.id ?? existing_categories.find((y) => y.category.id === x.category.id).id
item.order = x?.order ?? order
if (!x?.order) {
order = order + 1
}
item.category = { id: x.category.id, name: x.category.name }
promises.push(GenericAPI(Models.SHOPPING_CATEGORY_RELATION, Actions.UPDATE, item))
})
return Promise.all(promises).then(() => {
// finally get and return the Supermarket which everything downstream is expecting