recipe editor UI improvements

This commit is contained in:
vabene1111
2021-09-14 11:47:00 +02:00
parent 658ef23b42
commit b151356bce
2 changed files with 22 additions and 14 deletions

View File

@ -31,6 +31,7 @@
window.CUSTOM_LOCALE = '{{ request.LANGUAGE_CODE }}' window.CUSTOM_LOCALE = '{{ request.LANGUAGE_CODE }}'
window.RECIPE_ID = {{ recipe.pk }} window.RECIPE_ID = {{ recipe.pk }}
window.DEFAULT_UNIT = '{{request.user.userpreference.default_unit}}'
</script> </script>

View File

@ -22,10 +22,8 @@
</div> </div>
</div> </div>
<br/>
<div class="row">
<div class="row pt-2">
<div class="col-md-6" style="max-height: 50vh"> <div class="col-md-6" style="max-height: 50vh">
<input id="id_file_upload" ref="file_upload" type="file" hidden @change="uploadImage($event.target.files[0])"> <input id="id_file_upload" ref="file_upload" type="file" hidden @change="uploadImage($event.target.files[0])">
@ -587,14 +585,13 @@ export default {
this.recipe = response.data; this.recipe = response.data;
this.loading = false this.loading = false
//TODO workaround function until view is properly refactored, loads name of selected sub recipe so the input can find its label //TODO workaround function until view is properly refactored, loads name of selected sub recipe so the input can find its label
this.recipe.steps.forEach(s => { this.recipe.steps.forEach(s => {
if (s.step_recipe != null) { if (s.step_recipe != null) {
this.recipes.push(s.step_recipe_data) this.recipes.push(s.step_recipe_data)
} }
}) })
console.log('after step loop')
}).catch((err) => { }).catch((err) => {
this.loading = false this.loading = false
console.log(err) console.log(err)
@ -627,6 +624,7 @@ export default {
if (file !== undefined) { if (file !== undefined) {
apiClient.imageRecipe(this.recipe.id, file).then(request => { apiClient.imageRecipe(this.recipe.id, file).then(request => {
this.recipe.image = request.data.image this.recipe.image = request.data.image
this.recipe_changed = false
StandardToasts.makeStandardToast(StandardToasts.SUCCESS_UPDATE) StandardToasts.makeStandardToast(StandardToasts.SUCCESS_UPDATE)
}).catch(err => { }).catch(err => {
StandardToasts.makeStandardToast(StandardToasts.FAIL_UPDATE) StandardToasts.makeStandardToast(StandardToasts.FAIL_UPDATE)
@ -635,14 +633,17 @@ export default {
} }
}, },
deleteImage: function () { deleteImage: function () {
let apiClient = new ApiApiFactory() if (confirm(this.$t('delete_confirmation', {}))) {
apiClient.imageRecipe(this.recipe.id, undefined).then(request => { let apiClient = new ApiApiFactory()
this.recipe.image = null apiClient.imageRecipe(this.recipe.id, undefined).then(request => {
StandardToasts.makeStandardToast(StandardToasts.SUCCESS_DELETE) this.recipe.image = null
}).catch(err => { this.recipe_changed = false
StandardToasts.makeStandardToast(StandardToasts.FAIL_DELETE) StandardToasts.makeStandardToast(StandardToasts.SUCCESS_DELETE)
console.log(err.request, err.response) }).catch(err => {
}) StandardToasts.makeStandardToast(StandardToasts.FAIL_DELETE)
console.log(err.request, err.response)
})
}
}, },
addStep: function () { //TODO see if default can be generated from options request addStep: function () { //TODO see if default can be generated from options request
this.recipe.steps.push( this.recipe.steps.push(
@ -663,7 +664,7 @@ export default {
step.ingredients.push({ step.ingredients.push({
'food': null, 'food': null,
'unit': { 'unit': {
'name': '{{request.user.userpreference.default_unit}}' 'name': window.DEFAULT_UNIT
}, },
'amount': 0, 'amount': 0,
'note': '', 'note': '',
@ -818,9 +819,15 @@ export default {
<style src="vue-multiselect/dist/vue-multiselect.min.css"></style> <style src="vue-multiselect/dist/vue-multiselect.min.css"></style>
<style> <style>
.small-padding { .small-padding {
padding-left: 2px; padding-left: 2px;
padding-right: 2px; padding-right: 2px;
margin-top: 2px; margin-top: 2px;
} }
textarea {
border: 0 !important;
}
</style> </style>