recipe stuff

This commit is contained in:
vabene1111
2021-01-12 20:51:28 +01:00
parent 816ced83b5
commit 24ed6a1cd2
12 changed files with 175 additions and 31 deletions

View File

@@ -0,0 +1,12 @@
import axios from "axios";
import {makeToast} from "@/utils/utils";
import {resolveDjangoUrl} from "@/utils/utils";
export function apiLoadRecipe(recipe_id) {
return axios.get(resolveDjangoUrl('api:recipe-detail', recipe_id)).then((response) => {
return response.data
}).catch((err) => {
console.log(err)
makeToast('Error', 'There was an error loading a resource!', 'danger')
})
}

View File

@@ -1,12 +0,0 @@
import axios from "axios";
import {makeToast} from "@/utils/utils";
export function apiLoadRecipe(recipe_id) {
return axios.get(`/api/recipe/${recipe_id}`).then((response) => {
return response.data
}).catch((err) => {
console.log(err)
makeToast('Error', 'There was an error loading a resource!', 'danger')
})
}

View File

@@ -1,4 +1,15 @@
import { BToast } from 'bootstrap-vue'
/*
* Utility functions to call bootstrap toasts
* */
import {BToast} from 'bootstrap-vue'
export const ToastMixin = {
methods: {
makeToast: function (title, message, variant = null) {
return makeToast(title, message, variant)
}
}
}
export function makeToast(title, message, variant = null) {
let toaster = new BToast()
@@ -8,4 +19,46 @@ export function makeToast(title, message, variant = null) {
toaster: 'b-toaster-top-center',
solid: true
})
}
/*
* Utility functions to use djangos gettext
* */
export const GettextMixin = {
methods: {
/**
* uses djangos javascript gettext implementation to localize text
* @param {string} param string to translate
*/
_: function (param) {
return djangoGettext(param)
}
}
}
export function djangoGettext(param) {
return window.gettext(param)
}
/*
* Utility function to use djangos named urls
* */
// uses https://github.com/ierror/django-js-reverse#use-the-urls-in-javascript
export const ResolveUrlMixin = {
methods: {
/**
* Returns path of a django named URL
* @param {string} url name of url
* @param {*} params tuple of params to pass to django named url
*/
resolveDjangoUrl: function (url, params) {
return resolveDjangoUrl(url, params)
}
}
}
export function resolveDjangoUrl(url, params) {
return window.Urls[url](params)
}