meal plan hotkeys and sharing

This commit is contained in:
Kaibu 2021-11-25 01:28:07 +01:00
parent 19f5684d26
commit d76fdd090a
4 changed files with 52 additions and 6 deletions

View File

@ -620,6 +620,7 @@ class MealPlanSerializer(SpacedModelSerializer, WritableNestedModelSerializer):
meal_type_name = serializers.ReadOnlyField(source='meal_type.name') # TODO deprecate once old meal plan was removed meal_type_name = serializers.ReadOnlyField(source='meal_type.name') # TODO deprecate once old meal plan was removed
note_markdown = serializers.SerializerMethodField('get_note_markdown') note_markdown = serializers.SerializerMethodField('get_note_markdown')
servings = CustomDecimalField() servings = CustomDecimalField()
shared = UserNameSerializer(many=True)
def get_note_markdown(self, obj): def get_note_markdown(self, obj):
return markdown(obj.note) return markdown(obj.note)

View File

@ -513,12 +513,18 @@ export default {
return entry.id === id return entry.id === id
})[0] })[0]
}, },
moveEntry(null_object, target_date) { moveEntry(null_object, target_date, drag_event) {
this.plan_entries.forEach((entry) => { this.plan_entries.forEach((entry) => {
if (entry.id === this.dragged_item.id) { if (entry.id === this.dragged_item.id) {
if (drag_event.ctrlKey) {
let new_entry = Object.assign({}, entry)
new_entry.date = target_date
this.createEntry(new_entry)
} else {
entry.date = target_date entry.date = target_date
this.saveEntry(entry) this.saveEntry(entry)
} }
}
}) })
}, },
moveEntryLeft(data) { moveEntryLeft(data) {

View File

@ -116,6 +116,8 @@ export default {
} }
</script> </script>
<style src="vue-multiselect/dist/vue-multiselect.min.css"></style>
<style scoped> <style scoped>
</style> </style>

View File

@ -1,5 +1,5 @@
<template> <template>
<b-modal :id="modal_id" size="lg" :title="modal_title" hide-footer aria-label=""> <b-modal :id="modal_id" size="lg" :title="modal_title" hide-footer aria-label="" @show="showModal">
<div class="row"> <div class="row">
<div class="col col-md-12"> <div class="col col-md-12">
<div class="row"> <div class="row">
@ -60,6 +60,18 @@
:placeholder="$t('Servings')"></b-form-input> :placeholder="$t('Servings')"></b-form-input>
</b-input-group> </b-input-group>
<small tabindex="-1" class="form-text text-muted">{{ $t("Servings") }}</small> <small tabindex="-1" class="form-text text-muted">{{ $t("Servings") }}</small>
<b-form-group class="mt-3">
<generic-multiselect required
@change="entryEditing.shared = $event.val" parent_variable="entryEditing.shared"
:label="'username'"
:model="Models.USER_NAME"
style="flex-grow: 1; flex-shrink: 1; flex-basis: 0"
v-bind:placeholder="$t('Share')" :limit="10"
:multiple="true"
:initial_selection="entryEditing.shared"
></generic-multiselect>
<small tabindex="-1" class="form-text text-muted">{{ $t("Share") }}</small>
</b-form-group>
</div> </div>
<div class="col-lg-6 d-none d-lg-block d-xl-block"> <div class="col-lg-6 d-none d-lg-block d-xl-block">
<recipe-card :recipe="entryEditing.recipe" v-if="entryEditing.recipe != null"></recipe-card> <recipe-card :recipe="entryEditing.recipe" v-if="entryEditing.recipe != null"></recipe-card>
@ -103,7 +115,7 @@ export default {
allow_delete: { allow_delete: {
type: Boolean, type: Boolean,
default: true default: true
}, }
}, },
mixins: [ApiMixin], mixins: [ApiMixin],
components: { components: {
@ -114,7 +126,8 @@ export default {
return { return {
entryEditing: {}, entryEditing: {},
missing_recipe: false, missing_recipe: false,
missing_meal_type: false missing_meal_type: false,
default_plan_share: []
} }
}, },
watch: { watch: {
@ -126,6 +139,23 @@ export default {
} }
}, },
methods: { methods: {
showModal() {
let apiClient = new ApiApiFactory()
apiClient.listUserPreferences().then(result => {
let default_share = result.data[0].plan_share;
if (default_share !== []) {
let apiClient = new ApiApiFactory()
apiClient.listUsers(default_share).then(result => {
if (this.entry.id === -1) {
this.entryEditing.shared = result.data
}
})
}
})
},
editEntry() { editEntry() {
this.missing_meal_type = false this.missing_meal_type = false
this.missing_recipe = false this.missing_recipe = false
@ -155,6 +185,13 @@ export default {
this.entryEditing.meal_type = null; this.entryEditing.meal_type = null;
} }
}, },
selectShared(event) {
if (event.val != null) {
this.entryEditing.shared = event.val;
} else {
this.entryEditing.meal_type = null;
}
},
createMealType(event) { createMealType(event) {
if (event != "") { if (event != "") {
let apiClient = new ApiApiFactory() let apiClient = new ApiApiFactory()