From bbfab376ed5744a27ab18515f1d7c9d10af152b5 Mon Sep 17 00:00:00 2001
From: Christian Wolf
Date: Sun, 24 Jul 2022 21:17:55 +0200
Subject: [PATCH 1/2] Make recipeYield optional
Signed-off-by: Christian Wolf
---
.../Filter/JSON/FixRecipeYieldFilter.php | 4 ++
src/components/EditInputField.vue | 30 +++++++----
src/components/RecipeEdit.vue | 52 +++++++++++++++++--
src/components/RecipeView.vue | 2 +-
.../Filter/JSON/FixRecipeYieldFilterTest.php | 1 +
5 files changed, 76 insertions(+), 13 deletions(-)
diff --git a/lib/Helper/Filter/JSON/FixRecipeYieldFilter.php b/lib/Helper/Filter/JSON/FixRecipeYieldFilter.php
index bd031f30b..0f6afc77f 100644
--- a/lib/Helper/Filter/JSON/FixRecipeYieldFilter.php
+++ b/lib/Helper/Filter/JSON/FixRecipeYieldFilter.php
@@ -56,6 +56,10 @@ public function apply(array &$json): bool {
return true;
}
+ if ($json[self::YIELD] === null) {
+ return $changed;
+ }
+
if (is_array($json[self::YIELD])) {
assert(count($json[self::YIELD]) !== 1);
diff --git a/src/components/EditInputField.vue b/src/components/EditInputField.vue
index 9635057c6..fb81163c9 100644
--- a/src/components/EditInputField.vue
+++ b/src/components/EditInputField.vue
@@ -9,13 +9,16 @@
v-model="content"
@input="handleInput"
/>
-
+
+
+
+
@@ -41,6 +44,11 @@ export default {
default: "",
required: true,
},
+ hide: {
+ type: Boolean,
+ default: false,
+ required: false,
+ },
},
data() {
return {
@@ -196,13 +204,17 @@ fieldset > label {
vertical-align: top;
}
-fieldset > input,
+fieldset > div,
fieldset > textarea {
width: revert;
flex: 1;
}
-fieldset > input[type="number"] {
+fieldset > div > input {
+ width: 100%;
+}
+
+fieldset input[type="number"] {
width: 5em;
flex-grow: 0;
}
diff --git a/src/components/RecipeEdit.vue b/src/components/RecipeEdit.vue
index acef56f01..91ff24432 100644
--- a/src/components/RecipeEdit.vue
+++ b/src/components/RecipeEdit.vue
@@ -58,7 +58,20 @@
v-model="recipe['recipeYield']"
:field-type="'number'"
:field-label="t('cookbook', 'Servings')"
- />
+ :hide="!showRecipeYield"
+ >
+
+
+
+
+
+
{
if (this.recipe_id) {
return this.$store.dispatch("updateRecipe", {
- recipe: this.recipe,
+ recipe: this.recipeWithCorrectedYield,
})
}
return this.$store.dispatch("createRecipe", {
- recipe: this.recipe,
+ recipe: this.recipeWithCorrectedYield,
})
})()
@@ -690,6 +718,15 @@ export default {
this.allCategories.push(this.recipe.recipeCategory)
}
+ if (this.recipe.recipeYield === null) {
+ this.showRecipeYield = false
+ } else if (!this.recipe.recipeYield) {
+ this.showRecipeYield = false
+ this.recipe.recipeYield = null
+ } else {
+ this.showRecipeYield = true
+ }
+
// Always set the active page last!
this.$store.dispatch("setPage", { page: "edit" })
} else {
@@ -724,6 +761,11 @@ export default {
nutrition: {},
}
this.formDirty = false
+ this.showRecipeYield = true
+ },
+ toggleShowRecipeYield() {
+ this.showRecipeYield = !this.showRecipeYield
+ this.formDirty = true
},
},
}
@@ -771,4 +813,8 @@ form fieldset ul label input[type="checkbox"] {
margin-top: 3.5em;
text-align: end;
}
+
+.btn-enable-recipe-yield {
+ vertical-align: bottom;
+}
diff --git a/src/components/RecipeView.vue b/src/components/RecipeView.vue
index 7a8cd463e..53d39a6a5 100644
--- a/src/components/RecipeView.vue
+++ b/src/components/RecipeView.vue
@@ -63,7 +63,7 @@
>{{ $store.state.recipe.url }}
-
+
{{ t("cookbook", "Servings") }}: {{ $store.state.recipe.recipeYield }}
diff --git a/tests/Unit/Helper/Filter/JSON/FixRecipeYieldFilterTest.php b/tests/Unit/Helper/Filter/JSON/FixRecipeYieldFilterTest.php
index 9af15e9f8..0aeeec9ad 100644
--- a/tests/Unit/Helper/Filter/JSON/FixRecipeYieldFilterTest.php
+++ b/tests/Unit/Helper/Filter/JSON/FixRecipeYieldFilterTest.php
@@ -52,6 +52,7 @@ public function dp() {
[[4,5], 5, true],
['', 1, true],
['one two three', 1, true],
+ [null, null, false]
];
}
From 10de3f19bfe14400948f355f4a405e516655983d Mon Sep 17 00:00:00 2001
From: Christian Wolf
Date: Sun, 24 Jul 2022 21:27:04 +0200
Subject: [PATCH 2/2] Update changelog
Signed-off-by: Christian Wolf
---
CHANGELOG.md | 2 ++
1 file changed, 2 insertions(+)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index bb2916c2d..4a88bcb5c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,6 +13,8 @@
[#1103](https://github.com/nextcloud/cookbook/pull/1103) @MarcelRobitaille
- Replace print icon with something better recognizable
[#1106](https://github.com/nextcloud/cookbook/pull/1106) @christianlupus
+- Make recipeYield optional
+ [#1108](https://github.com/nextcloud/cookbook/pull/1108) @christianlupus
### Maintenance
- Add composer.json to version control to have unique installed dependency versions