moved date format functions to utilities
This commit is contained in:
parent
64e54ceaec
commit
7673e794bf
@ -471,7 +471,7 @@ import CopyToClipboard from "@/components/Buttons/CopyToClipboard"
|
|||||||
import GenericMultiselect from "@/components/GenericMultiselect"
|
import GenericMultiselect from "@/components/GenericMultiselect"
|
||||||
import ShoppingModal from "@/components/Modals/ShoppingModal"
|
import ShoppingModal from "@/components/Modals/ShoppingModal"
|
||||||
|
|
||||||
import {ApiMixin, getUserPreference, StandardToasts, makeToast, ResolveUrlMixin} from "@/utils/utils"
|
import {ApiMixin, getUserPreference, StandardToasts, makeToast, ResolveUrlMixin, FormatMixin} from "@/utils/utils"
|
||||||
import {ApiApiFactory} from "@/utils/openapi/api"
|
import {ApiApiFactory} from "@/utils/openapi/api"
|
||||||
import ShoppingSettingsComponent from "@/components/Settings/ShoppingSettingsComponent";
|
import ShoppingSettingsComponent from "@/components/Settings/ShoppingSettingsComponent";
|
||||||
|
|
||||||
@ -486,7 +486,7 @@ import NumberScalerComponent from "@/components/NumberScalerComponent.vue";
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "ShoppingListView",
|
name: "ShoppingListView",
|
||||||
mixins: [ApiMixin, ResolveUrlMixin],
|
mixins: [ApiMixin, ResolveUrlMixin, FormatMixin],
|
||||||
components: {
|
components: {
|
||||||
NumberScalerComponent,
|
NumberScalerComponent,
|
||||||
|
|
||||||
@ -550,15 +550,6 @@ export default {
|
|||||||
methods: {
|
methods: {
|
||||||
useUserPreferenceStore,
|
useUserPreferenceStore,
|
||||||
useShoppingListStore,
|
useShoppingListStore,
|
||||||
// TODO move to utils
|
|
||||||
formatDate: function (datetime) {
|
|
||||||
if (!datetime) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
return Intl.DateTimeFormat(window.navigator.language, {
|
|
||||||
dateStyle: "short",
|
|
||||||
}).format(Date.parse(datetime))
|
|
||||||
},
|
|
||||||
/**
|
/**
|
||||||
* recursive function calling autosync after set amount of time has passed
|
* recursive function calling autosync after set amount of time has passed
|
||||||
*/
|
*/
|
||||||
|
@ -116,7 +116,7 @@
|
|||||||
import Vue from "vue"
|
import Vue from "vue"
|
||||||
import {BootstrapVue} from "bootstrap-vue"
|
import {BootstrapVue} from "bootstrap-vue"
|
||||||
import "bootstrap-vue/dist/bootstrap-vue.css"
|
import "bootstrap-vue/dist/bootstrap-vue.css"
|
||||||
import {ApiMixin, resolveDjangoUrl, StandardToasts} from "@/utils/utils"
|
import {ApiMixin, FormatMixin, resolveDjangoUrl, StandardToasts} from "@/utils/utils"
|
||||||
import {useMealPlanStore} from "@/stores/MealPlanStore";
|
import {useMealPlanStore} from "@/stores/MealPlanStore";
|
||||||
import {useShoppingListStore} from "@/stores/ShoppingListStore";
|
import {useShoppingListStore} from "@/stores/ShoppingListStore";
|
||||||
import {ApiApiFactory} from "@/utils/openapi/api";
|
import {ApiApiFactory} from "@/utils/openapi/api";
|
||||||
@ -129,7 +129,7 @@ Vue.use(BootstrapVue)
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "ShoppingLineItem",
|
name: "ShoppingLineItem",
|
||||||
mixins: [ApiMixin],
|
mixins: [ApiMixin, FormatMixin],
|
||||||
components: {GenericModalForm, NumberScalerComponent},
|
components: {GenericModalForm, NumberScalerComponent},
|
||||||
props: {
|
props: {
|
||||||
entries: {type: Object,},
|
entries: {type: Object,},
|
||||||
@ -247,15 +247,6 @@ export default {
|
|||||||
useUserPreferenceStore,
|
useUserPreferenceStore,
|
||||||
useShoppingListStore,
|
useShoppingListStore,
|
||||||
resolveDjangoUrl,
|
resolveDjangoUrl,
|
||||||
// TODO move to utils
|
|
||||||
formatDate: function (datetime) {
|
|
||||||
if (!datetime) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
return Intl.DateTimeFormat(window.navigator.language, {
|
|
||||||
dateStyle: "short",
|
|
||||||
}).format(Date.parse(datetime))
|
|
||||||
},
|
|
||||||
/**
|
/**
|
||||||
* update the food after the category was changed
|
* update the food after the category was changed
|
||||||
* handle changing category to category ID as a workaround
|
* handle changing category to category ID as a workaround
|
||||||
|
@ -365,6 +365,23 @@ export function energyHeading() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const FormatMixin = {
|
||||||
|
name: "FormatMixin",
|
||||||
|
methods: {
|
||||||
|
/**
|
||||||
|
* format short date from datetime
|
||||||
|
* @param datetime any string that can be parsed by Date.parse()
|
||||||
|
* @return {string}
|
||||||
|
*/
|
||||||
|
formatDate: function (datetime) {
|
||||||
|
return Intl.DateTimeFormat(window.navigator.language, {
|
||||||
|
dateStyle: "short",
|
||||||
|
}).format(Date.parse(datetime))
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
axios.defaults.xsrfCookieName = "csrftoken"
|
axios.defaults.xsrfCookieName = "csrftoken"
|
||||||
axios.defaults.xsrfHeaderName = "X-CSRFTOKEN"
|
axios.defaults.xsrfHeaderName = "X-CSRFTOKEN"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user