mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2026-01-04 21:58:54 -05:00
recipe stuff
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<template>
|
||||
<div id="app" v-if="!loading">
|
||||
<h1>{{ recipe.name }}</h1>
|
||||
<recipe-context-menu v-bind:recipe="recipe"></recipe-context-menu>
|
||||
|
||||
<img v-bind:src="recipe.image">
|
||||
|
||||
@@ -17,31 +18,23 @@ import {BootstrapVue} from 'bootstrap-vue'
|
||||
|
||||
import 'bootstrap-vue/dist/bootstrap-vue.css'
|
||||
|
||||
import {makeToast} from "@/utils/utils.js";
|
||||
|
||||
const _ = window.gettext
|
||||
import {apiLoadRecipe} from "@/utils/api";
|
||||
|
||||
import Step from "@/components/Step";
|
||||
import RecipeContextMenu from "@/components/RecipeContextMenu";
|
||||
import {GettextMixin, ToastMixin} from "@/utils/utils";
|
||||
|
||||
Vue.use(BootstrapVue)
|
||||
|
||||
import Vuex from 'vuex'
|
||||
|
||||
Vue.use(Vuex)
|
||||
|
||||
const store = new Vuex.Store({
|
||||
state: {
|
||||
servings: 1
|
||||
}
|
||||
})
|
||||
|
||||
import {apiLoadRecipe} from "@/utils/django";
|
||||
|
||||
export default {
|
||||
name: 'RecipeView',
|
||||
store: store,
|
||||
mixins: [
|
||||
GettextMixin,
|
||||
ToastMixin,
|
||||
],
|
||||
components: {
|
||||
Step
|
||||
Step,
|
||||
RecipeContextMenu,
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
|
||||
64
vue/src/components/RecipeContextMenu.vue
Normal file
64
vue/src/components/RecipeContextMenu.vue
Normal file
@@ -0,0 +1,64 @@
|
||||
<template>
|
||||
<div>
|
||||
{{ resolveDjangoUrl('api:recipe-detail', 5) }}
|
||||
|
||||
<div class="col col-md-4 d-print-none" style="text-align: right">
|
||||
<div class="dropdown">
|
||||
<a class="btn shadow-none" href="#" role="button" id="dropdownMenuLink"
|
||||
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
<i class="fas fa-ellipsis-v"></i>
|
||||
</a>
|
||||
|
||||
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuLink">
|
||||
<a class="dropdown-item" :href="resolveDjangoUrl('edit_recipe', recipe.id)"><i
|
||||
class="fas fa-pencil-alt fa-fw"></i> {{ _('Edit') }}</a>
|
||||
<button class="dropdown-item" onclick="$('#bookmarkModal').modal({'show':true})">
|
||||
<i class="fas fa-bookmark fa-fw"></i> {{ _('Add to Book') }}
|
||||
</button>
|
||||
|
||||
<a class="dropdown-item" :href="recipe.name" v-if="true"> <!--TODO implement -->
|
||||
<i class="fas fa-shopping-cart fa-fw"></i> {{ _('Add to Shopping') }} </a>
|
||||
|
||||
<a class="dropdown-item" :href="resolveDjangoUrl('new_meal_plan', recipe.id)"><i
|
||||
class="fas fa-calendar fa-fw"></i> {{ _('Add to Plan') }}</a>
|
||||
|
||||
<!--
|
||||
<button class="dropdown-item" :onclick="openCookLogModal(recipe.id)"><i
|
||||
class="fas fa-clipboard-list fa-fw"></i> {{ _('Log Cooking') }}
|
||||
</button>
|
||||
-->
|
||||
<button class="dropdown-item" onclick="window.print()"><i
|
||||
class="fas fa-print fa-fw"></i> {{ _('Print') }}
|
||||
</button>
|
||||
|
||||
<a class="dropdown-item" :href="resolveDjangoUrl('view_export', recipe.id)" target="_blank"
|
||||
rel="noopener noreferrer"><i class="fas fa-file-export fa-fw"></i> {{ _('Export') }}</a>
|
||||
|
||||
<a class="dropdown-item" :href="resolveDjangoUrl('new_share_link', recipe.id)" target="_blank"
|
||||
rel="noopener noreferrer" v-if="recipe.internal"><i class="fas fa-share-alt fa-fw"></i> {{
|
||||
_('Share')
|
||||
}}</a>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
||||
import {GettextMixin, ResolveUrlMixin} from "@/utils/utils";
|
||||
|
||||
export default {
|
||||
name: 'RecipeContextMenu',
|
||||
mixins: [
|
||||
ResolveUrlMixin,
|
||||
GettextMixin
|
||||
],
|
||||
props: {
|
||||
recipe: Object,
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -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