Skip to content

Commit 9ee4154

Browse files
Merge pull request #1108 from nextcloud/fix/1042-recipeyield-optional
Make recipeYield optional
2 parents 3999339 + 10de3f1 commit 9ee4154

File tree

6 files changed

+78
-13
lines changed

6 files changed

+78
-13
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
[#1103](https://github.com./nextcloud/cookbook/pull/1103) @MarcelRobitaille
1414
- Replace print icon with something better recognizable
1515
[#1106](https://github.com./nextcloud/cookbook/pull/1106) @christianlupus
16+
- Make recipeYield optional
17+
[#1108](https://github.com./nextcloud/cookbook/pull/1108) @christianlupus
1618

1719
### Maintenance
1820
- Add composer.json to version control to have unique installed dependency versions

lib/Helper/Filter/JSON/FixRecipeYieldFilter.php

+4
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ public function apply(array &$json): bool {
5656
return true;
5757
}
5858

59+
if ($json[self::YIELD] === null) {
60+
return $changed;
61+
}
62+
5963
if (is_array($json[self::YIELD])) {
6064
assert(count($json[self::YIELD]) !== 1);
6165

src/components/EditInputField.vue

+21-9
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@
99
v-model="content"
1010
@input="handleInput"
1111
/>
12-
<input
13-
v-else
14-
ref="inputField"
15-
v-model="content"
16-
:type="fieldType"
17-
@input="handleInput"
18-
/>
12+
<div v-else>
13+
<slot />
14+
<input
15+
v-if="!hide"
16+
ref="inputField"
17+
v-model="content"
18+
:type="fieldType"
19+
@input="handleInput"
20+
/>
21+
</div>
1922
</fieldset>
2023
</template>
2124

@@ -41,6 +44,11 @@ export default {
4144
default: "",
4245
required: true,
4346
},
47+
hide: {
48+
type: Boolean,
49+
default: false,
50+
required: false,
51+
},
4452
},
4553
data() {
4654
return {
@@ -196,13 +204,17 @@ fieldset > label {
196204
vertical-align: top;
197205
}
198206
199-
fieldset > input,
207+
fieldset > div,
200208
fieldset > textarea {
201209
width: revert;
202210
flex: 1;
203211
}
204212
205-
fieldset > input[type="number"] {
213+
fieldset > div > input {
214+
width: 100%;
215+
}
216+
217+
fieldset input[type="number"] {
206218
width: 5em;
207219
flex-grow: 0;
208220
}

src/components/RecipeEdit.vue

+49-3
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,20 @@
5858
v-model="recipe['recipeYield']"
5959
:field-type="'number'"
6060
:field-label="t('cookbook', 'Servings')"
61-
/>
61+
:hide="!showRecipeYield"
62+
>
63+
<actions>
64+
<action-button
65+
class="btn-enable-recipe-yield"
66+
:aria-label="
67+
t('cookbook', 'Toggle if recipe yield field is present')
68+
"
69+
@click="toggleShowRecipeYield"
70+
>
71+
<template #icon><numeric-icon :size="20" /></template>
72+
</action-button>
73+
</actions>
74+
</EditInputField>
6275
<EditMultiselectInputGroup
6376
v-model="recipe['nutrition']"
6477
:field-label="t('cookbook', 'Nutrition Information')"
@@ -120,6 +133,10 @@ import Vue from "vue"
120133
121134
import api from "cookbook/js/api-interface"
122135
import helpers from "cookbook/js/helper"
136+
import NumericIcon from "icons/Numeric.vue"
137+
138+
import Actions from "@nextcloud/vue/dist/Components/Actions"
139+
import ActionButton from "@nextcloud/vue/dist/Components/ActionButton"
123140
124141
import EditImageField from "./EditImageField.vue"
125142
import EditInputField from "./EditInputField.vue"
@@ -139,6 +156,9 @@ export default {
139156
EditTimeField,
140157
EditMultiselectInputGroup,
141158
EditMultiselectPopup,
159+
Actions,
160+
ActionButton,
161+
NumericIcon,
142162
},
143163
// We can check if the user has browsed from the same recipe's view to this
144164
// edit and save some time by not reloading the recipe data, leading to a
@@ -308,6 +328,7 @@ export default {
308328
referencesPopupFocused: false,
309329
popupContext: undefined,
310330
loadingRecipeReferences: true,
331+
showRecipeYield: true,
311332
}
312333
},
313334
computed: {
@@ -329,6 +350,13 @@ export default {
329350
this.recipe.recipeCategory)
330351
)
331352
},
353+
recipeWithCorrectedYield() {
354+
const r = this.recipe
355+
if (!this.showRecipeYield) {
356+
r.recipeYield = null
357+
}
358+
return r
359+
},
332360
},
333361
watch: {
334362
prepTime: {
@@ -578,11 +606,11 @@ export default {
578606
const request = (() => {
579607
if (this.recipe_id) {
580608
return this.$store.dispatch("updateRecipe", {
581-
recipe: this.recipe,
609+
recipe: this.recipeWithCorrectedYield,
582610
})
583611
}
584612
return this.$store.dispatch("createRecipe", {
585-
recipe: this.recipe,
613+
recipe: this.recipeWithCorrectedYield,
586614
})
587615
})()
588616
@@ -690,6 +718,15 @@ export default {
690718
this.allCategories.push(this.recipe.recipeCategory)
691719
}
692720
721+
if (this.recipe.recipeYield === null) {
722+
this.showRecipeYield = false
723+
} else if (!this.recipe.recipeYield) {
724+
this.showRecipeYield = false
725+
this.recipe.recipeYield = null
726+
} else {
727+
this.showRecipeYield = true
728+
}
729+
693730
// Always set the active page last!
694731
this.$store.dispatch("setPage", { page: "edit" })
695732
} else {
@@ -724,6 +761,11 @@ export default {
724761
nutrition: {},
725762
}
726763
this.formDirty = false
764+
this.showRecipeYield = true
765+
},
766+
toggleShowRecipeYield() {
767+
this.showRecipeYield = !this.showRecipeYield
768+
this.formDirty = true
727769
},
728770
},
729771
}
@@ -771,4 +813,8 @@ form fieldset ul label input[type="checkbox"] {
771813
margin-top: 3.5em;
772814
text-align: end;
773815
}
816+
817+
.btn-enable-recipe-yield {
818+
vertical-align: bottom;
819+
}
774820
</style>

src/components/RecipeView.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
>{{ $store.state.recipe.url }}</a
6464
>
6565
</p>
66-
<p>
66+
<p v-if="$store.state.recipe.recipeYield != null">
6767
<strong>{{ t("cookbook", "Servings") }}: </strong
6868
>{{ $store.state.recipe.recipeYield }}
6969
</p>

tests/Unit/Helper/Filter/JSON/FixRecipeYieldFilterTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public function dp() {
5252
[[4,5], 5, true],
5353
['', 1, true],
5454
['one two three', 1, true],
55+
[null, null, false]
5556
];
5657
}
5758

0 commit comments

Comments
 (0)