Skip to content

Commit

Permalink
added meal type settings to meal plan settings component
Browse files Browse the repository at this point in the history
  • Loading branch information
vabene1111 committed Sep 6, 2023
1 parent 1a20c4b commit d33b0d2
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 4 deletions.
4 changes: 3 additions & 1 deletion vue/src/components/Modals/GenericModalForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import SmallText from "@/components/Modals/SmallText"
import HelpBadge from "@/components/Badges/Help"
import NumberInput from "@/components/Modals/NumberInput.vue";
import TextAreaInput from "@/components/Modals/TextAreaInput.vue";
import ColorInput from "@/components/Modals/ColorInput.vue";
export default {
name: "GenericModalForm",
Expand All @@ -71,7 +72,8 @@ export default {
HelpBadge,
DateInput,
NumberInput,
TextAreaInput
TextAreaInput,
ColorInput
},
mixins: [ApiMixin, ToastMixin],
props: {
Expand Down
75 changes: 72 additions & 3 deletions vue/src/components/Settings/MealPlanSettingsComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
></generic-multiselect>
</b-form-group>

<hr/>

<b-form v-if="meal_plan_store">
<b-form-group id="UomInput" :label="$t('Period')" :description="$t('Plan_Period_To_Show')"
label-for="UomInput">
Expand All @@ -34,6 +36,38 @@
</b-form-checkbox>
</b-form-group>
</b-form>

<hr/>

<h5>{{ $t("Meal_Types") }}
<button type="button" class="btn btn-success shadow-none float-right" @click="generic_action = Actions.CREATE;"><i class="fas fa-plus"></i></button>
</h5>

<draggable :list="meal_types" group="meal_types" :empty-insert-threshold="10" class="mt-4"
@sort="sortMealTypes()" ghost-class="ghost" handle=".handle">
<b-list-group-item v-for="mt in meal_types" v-bind:key="mt.id">

<button type="button" class="btn handle shadow-none"><i class="fas fa-arrows-alt-v"></i></button>

<b-badge :style="{'background-color': mt.color}"><i class="fas fa-palette"></i> </b-badge>
<span> {{ mt.name }} </span>

<b-badge v-if="mt.default">{{ $t('Default') }}</b-badge>
<div class="btn-group float-right">
<button type="button" class="btn btn-primary shadow-none" @click="generic_action = Actions.UPDATE; editing_meal_type=mt;"><i class="fas fa-edit"></i></button>
<button type="button" class="btn btn-danger shadow-none" @click="generic_action = Actions.DELETE; editing_meal_type=mt;"><i class="fas fa-trash-alt"></i></button>
</div>

</b-list-group-item>
</draggable>
<b-list-group>


</b-list-group>

<generic-modal-form :model="Models.MEAL_TYPE" :action="generic_action" :show="generic_action !== null"
:item1="editing_meal_type"
@finish-action="finishGenericAction"/>
</div>
</template>

Expand All @@ -45,16 +79,16 @@ import axios from "axios";
import GenericMultiselect from "@/components/GenericMultiselect";
import {useMealPlanStore} from "@/stores/MealPlanStore";
import {CalendarMathMixin} from "vue-simple-calendar/src/components/bundle";
import draggable from "vuedraggable"
import GenericModalForm from "@/components/Modals/GenericModalForm.vue";
axios.defaults.xsrfCookieName = 'csrftoken'
axios.defaults.xsrfHeaderName = "X-CSRFTOKEN"
let SETTINGS_COOKIE_NAME = "mealplan_settings"
export default {
name: "MealPlanSettingsComponent",
mixins: [ApiMixin, CalendarMathMixin],
components: {GenericMultiselect},
components: {GenericModalForm, draggable, GenericMultiselect},
props: {
user_id: Number,
},
Expand All @@ -71,6 +105,9 @@ export default {
],
displayPeriodCount: [1, 2, 3, 4],
},
meal_types: [],
generic_action: null,
editing_meal_type: null,
}
},
mounted() {
Expand All @@ -79,6 +116,8 @@ export default {
this.loadSettings()
this.meal_plan_store = useMealPlanStore()
this.loadMealTypes()
},
methods: {
loadSettings: function () {
Expand Down Expand Up @@ -107,6 +146,36 @@ export default {
})
return options
},
loadMealTypes: function () {
let apiClient = new ApiApiFactory()
apiClient.listMealTypes().then(result => {
this.meal_types = result.data
}).catch(err => {
StandardToasts.makeStandardToast(this, StandardToasts.FAIL_FETCH, err)
})
},
sortMealTypes() {
this.meal_types.forEach(function (element, index) {
element.order = index
})
this.meal_types.forEach((meal_type) => {
let apiClient = new ApiApiFactory()
apiClient.updateMealType(meal_type.id, meal_type).then((e) => {
}).catch((err) => {
StandardToasts.makeStandardToast(this, StandardToasts.FAIL_UPDATE, err)
})
})
},
finishGenericAction: function (e) {
if (e !== 'cancel') {
this.loadMealTypes()
}
this.editing_meal_type = null;
this.generic_action = null;
}
}
}
</script>
Expand Down

0 comments on commit d33b0d2

Please sign in to comment.