mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2026-01-02 04:39:54 -05:00
recipe stuff
This commit is contained in:
@@ -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')
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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')
|
||||
})
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
Reference in New Issue
Block a user