cleanup redundant code

This commit is contained in:
hay-kot 2021-05-30 13:13:41 -08:00
commit 45a34ceb35
3 changed files with 21 additions and 27 deletions

View file

@ -67,12 +67,13 @@
</v-card-text> </v-card-text>
<v-row align="center" justify="end"> <v-row align="center" justify="end">
<v-card-actions class="mr-5"> <v-card-actions class="mr-5">
<v-btn color="success" @click="random" v-if="planDays.length > 0" text> <TheButton edit @click="random" v-if="planDays.length > 0" text>
<template v-slot:icon>
mdi-dice-multiple
</template>
{{ $t("general.random") }} {{ $t("general.random") }}
</v-btn> </TheButton>
<v-btn color="success" @click="save" text :disabled="planDays.length == 0"> <TheButton create @click="save" :disabled="planDays.length == 0" />
{{ $t("general.save") }}
</v-btn>
</v-card-actions> </v-card-actions>
</v-row> </v-row>
</v-card> </v-card>
@ -105,6 +106,9 @@ export default {
}, },
watch: { watch: {
startDate(val) {
console.log(val);
},
dateDif() { dateDif() {
this.planDays = []; this.planDays = [];
for (let i = 0; i < this.dateDif; i++) { for (let i = 0; i < this.dateDif; i++) {
@ -138,16 +142,10 @@ export default {
return Date.parse(this.endDate); return Date.parse(this.endDate);
}, },
dateDif() { dateDif() {
let startDate = new Date(this.startDate); let dateDif = (this.actualEndDate - this.actualStartDate) / (1000 * 3600 * 24) + 1;
let endDate = new Date(this.endDate);
console.log(startDate, endDate);
let dateDif = (endDate - startDate) / (1000 * 3600 * 24) + 1;
if (dateDif < 1) { if (dateDif < 1) {
return null; return null;
} }
return dateDif; return dateDif;
}, },
startComputedDateFormatted() { startComputedDateFormatted() {
@ -179,22 +177,17 @@ export default {
}, },
random() { random() {
this.usedRecipes = [1]; this.usedRecipes = [1];
this.planDays.forEach((element, index) => { this.planDays.forEach((_, index) => {
let recipe = this.getRandom(this.filteredRecipes); let recipe = this.getRandom(this.filteredRecipes);
this.planDays[index]["meals"][0]["slug"] = recipe.slug; this.planDays[index]["meals"][0]["slug"] = recipe.slug;
this.planDays[index]["meals"][0]["name"] = recipe.name; this.planDays[index]["meals"][0]["name"] = recipe.name;
this.usedRecipes.push(recipe); this.usedRecipes.push(recipe);
}); });
}, },
processTime(index) {
let dateText = new Date(this.actualStartDate.valueOf() + 1000 * 3600 * 24 * index);
return dateText;
},
getDate(index) { getDate(index) {
const dateObj = this.processTime(index); const dateObj = new Date(this.actualStartDate.valueOf() + 1000 * 3600 * 24 * index);
return utils.getDateAsPythonDate(dateObj); return utils.getDateAsPythonDate(dateObj);
}, },
async save() { async save() {
const mealBody = { const mealBody = {
group: this.groupSettings.name, group: this.groupSettings.name,
@ -209,7 +202,6 @@ export default {
this.endDate = null; this.endDate = null;
} }
}, },
formatDate(date) { formatDate(date) {
if (!date) return null; if (!date) return null;
@ -227,12 +219,9 @@ export default {
const nextEndDate = new Date(nextMonday); const nextEndDate = new Date(nextMonday);
nextEndDate.setDate(nextEndDate.getDate() + 4); nextEndDate.setDate(nextEndDate.getDate() + 4);
this.startDate = nextMonday.toISOString().substr(0, 10); this.startDate = utils.getDateAsPythonDate(nextMonday);
this.endDate = utils.getDateAsPythonDate(nextEndDate);
this.endDate = nextEndDate.toISOString().substr(0, 10);
}, },
}, },
}; };
</script> </script>
<style></style>

View file

@ -4,6 +4,7 @@
:small="small" :small="small"
:x-small="xSmall" :x-small="xSmall"
:loading="loading" :loading="loading"
:disabled="disabled"
@click="$emit('click')" @click="$emit('click')"
:outlined="btnStyle.outlined" :outlined="btnStyle.outlined"
:text="btnStyle.text" :text="btnStyle.text"
@ -49,6 +50,10 @@ export default {
type: Boolean, type: Boolean,
default: false, default: false,
}, },
disabled: {
type: Boolean,
default: false,
},
// Styles // Styles
small: { small: {
type: Boolean, type: Boolean,

View file

@ -6,10 +6,10 @@ import { store } from "@/store";
export const utils = { export const utils = {
recipe: recipe, recipe: recipe,
generateUniqueKey(item, index) { generateUniqueKey(item, index) {
const uniqueKey = `${item}-${index}`; return `${item}-${index}`;
return uniqueKey;
}, },
getDateAsPythonDate(dateObject) { getDateAsPythonDate(dateObject) {
if (!dateObject) return null;
const month = dateObject.getMonth() + 1; const month = dateObject.getMonth() + 1;
const day = dateObject.getDate(); const day = dateObject.getDate();
const year = dateObject.getFullYear(); const year = dateObject.getFullYear();