58
58
v-model =" recipe['recipeYield']"
59
59
:field-type =" 'number'"
60
60
: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 >
62
75
<EditMultiselectInputGroup
63
76
v-model =" recipe['nutrition']"
64
77
:field-label =" t('cookbook', 'Nutrition Information')"
@@ -120,6 +133,10 @@ import Vue from "vue"
120
133
121
134
import api from " cookbook/js/api-interface"
122
135
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"
123
140
124
141
import EditImageField from " ./EditImageField.vue"
125
142
import EditInputField from " ./EditInputField.vue"
@@ -139,6 +156,9 @@ export default {
139
156
EditTimeField,
140
157
EditMultiselectInputGroup,
141
158
EditMultiselectPopup,
159
+ Actions,
160
+ ActionButton,
161
+ NumericIcon,
142
162
},
143
163
// We can check if the user has browsed from the same recipe's view to this
144
164
// edit and save some time by not reloading the recipe data, leading to a
@@ -308,6 +328,7 @@ export default {
308
328
referencesPopupFocused: false ,
309
329
popupContext: undefined ,
310
330
loadingRecipeReferences: true ,
331
+ showRecipeYield: true ,
311
332
}
312
333
},
313
334
computed: {
@@ -329,6 +350,13 @@ export default {
329
350
this .recipe .recipeCategory )
330
351
)
331
352
},
353
+ recipeWithCorrectedYield () {
354
+ const r = this .recipe
355
+ if (! this .showRecipeYield ) {
356
+ r .recipeYield = null
357
+ }
358
+ return r
359
+ },
332
360
},
333
361
watch: {
334
362
prepTime: {
@@ -578,11 +606,11 @@ export default {
578
606
const request = (() => {
579
607
if (this .recipe_id ) {
580
608
return this .$store .dispatch (" updateRecipe" , {
581
- recipe: this .recipe ,
609
+ recipe: this .recipeWithCorrectedYield ,
582
610
})
583
611
}
584
612
return this .$store .dispatch (" createRecipe" , {
585
- recipe: this .recipe ,
613
+ recipe: this .recipeWithCorrectedYield ,
586
614
})
587
615
})()
588
616
@@ -690,6 +718,15 @@ export default {
690
718
this .allCategories .push (this .recipe .recipeCategory )
691
719
}
692
720
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
+
693
730
// Always set the active page last!
694
731
this .$store .dispatch (" setPage" , { page: " edit" })
695
732
} else {
@@ -724,6 +761,11 @@ export default {
724
761
nutrition: {},
725
762
}
726
763
this .formDirty = false
764
+ this .showRecipeYield = true
765
+ },
766
+ toggleShowRecipeYield () {
767
+ this .showRecipeYield = ! this .showRecipeYield
768
+ this .formDirty = true
727
769
},
728
770
},
729
771
}
@@ -771,4 +813,8 @@ form fieldset ul label input[type="checkbox"] {
771
813
margin-top : 3.5em ;
772
814
text-align : end ;
773
815
}
816
+
817
+ .btn-enable-recipe-yield {
818
+ vertical-align : bottom ;
819
+ }
774
820
</style >
0 commit comments