Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
vabene1111 committed Jan 17, 2022
1 parent e0b8d6f commit 8b1e80e
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 33 deletions.
40 changes: 30 additions & 10 deletions vue/src/components/Buttons/RecipeSwitcher.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<b-nav-item variant="link" @click="
navRecipe(r)
hide()
">{{ r.name }}
">{{ r.name }} <a href="javascript:void(0);">x</a>
</b-nav-item>
</div>
<hr/>
Expand All @@ -38,6 +38,16 @@
">{{ r.name }}
</b-nav-item>
</div>

<h5><i class="fas fa-link fa-fw"></i> TEST</h5>

<div v-for="r in test" :key="`test${r.id}`">
<b-nav-item variant="link" @click="
navRecipe(r)
hide()
">{{ r.name }}
</b-nav-item>
</div>
</b-nav>
</nav>
</template>
Expand All @@ -60,7 +70,8 @@ export default {
related_recipes: [],
planned_recipes: [],
pinned_recipes: [],
recipes: {}
recipes: {},
test : []
}
},
computed: {
Expand All @@ -84,7 +95,7 @@ export default {
navRecipe: function (recipe) {
if (this.is_recipe_view) {
this.$emit("switch", this.recipes[recipe.id])
this.$emit("switch", recipe)
} else {
window.location.href = this.resolveDjangoUrl("view_recipe", recipe.id)
}
Expand All @@ -93,16 +104,23 @@ export default {
let apiClient = new ApiApiFactory()
let recipe_list = [...this.related_recipes, ...this.planned_recipes, ...this.pinned_recipes]
let recipe_ids = []
recipe_list.forEach((recipe) => {
if (!recipe_ids.includes(recipe.id)) {
recipe_ids.push(recipe.id)
let id = recipe.id
if (id === undefined){
id = recipe
}
})
if (!recipe_ids.includes(id)) {
recipe_ids.push(id)
}
})
console.log(recipe_list, recipe_ids)
recipe_ids.forEach((id) => {
apiClient.retrieveRecipe(id).then((result) => {
this.recipes[id] = result.data
this.test.push(result.data)
})
})
Expand All @@ -111,12 +129,14 @@ export default {
let apiClient = new ApiApiFactory()
// get related recipes and save them for later
return apiClient.relatedRecipe(this.recipe, {query: {levels: 2}}).then((result) => {
this.related_recipes = result.data
})
if (this.recipe){
return apiClient.relatedRecipe(this.recipe, {query: {levels: 2}}).then((result) => {
this.related_recipes = result.data
})
}
},
loadPinnedRecipes: function () {
let pinned_recipe_ids = localStorage.getItem('pinned_recipes') || []
let pinned_recipe_ids = JSON.parse(localStorage.getItem('pinned_recipes')) || []
this.pinned_recipes = pinned_recipe_ids
},
loadMealPlans: function () {
Expand Down
70 changes: 52 additions & 18 deletions vue/src/components/RecipeContextMenu.vue
Original file line number Diff line number Diff line change
@@ -1,38 +1,60 @@
<template>
<div>
<div class="dropdown d-print-none">
<a class="btn shadow-none" href="javascript:void(0);" role="button" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<a class="btn shadow-none" href="javascript:void(0);" role="button" id="dropdownMenuLink"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="fas fa-ellipsis-v fa-lg"></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> {{ $t("Edit") }}</a>
<a class="dropdown-item" :href="resolveDjangoUrl('edit_recipe', recipe.id)"><i
class="fas fa-pencil-alt fa-fw"></i> {{ $t("Edit") }}</a>

<a class="dropdown-item" :href="resolveDjangoUrl('edit_convert_recipe', recipe.id)" v-if="!recipe.internal"><i class="fas fa-exchange-alt fa-fw"></i> {{ $t("convert_internal") }}</a>
<a class="dropdown-item" :href="resolveDjangoUrl('edit_convert_recipe', recipe.id)"
v-if="!recipe.internal"><i class="fas fa-exchange-alt fa-fw"></i> {{ $t("convert_internal") }}</a>

<a href="javascript:void(0);">
<button class="dropdown-item" @click="$bvModal.show(`id_modal_add_book_${modal_id}`)"><i class="fas fa-bookmark fa-fw"></i> {{ $t("Manage_Books") }}</button>
<button class="dropdown-item" @click="$bvModal.show(`id_modal_add_book_${modal_id}`)"><i
class="fas fa-bookmark fa-fw"></i> {{ $t("Manage_Books") }}
</button>
</a>

<a class="dropdown-item" :href="`${resolveDjangoUrl('view_shopping')}?r=[${recipe.id},${servings_value}]`" v-if="recipe.internal" target="_blank" rel="noopener noreferrer">
<a class="dropdown-item"
:href="`${resolveDjangoUrl('view_shopping')}?r=[${recipe.id},${servings_value}]`"
v-if="recipe.internal" target="_blank" rel="noopener noreferrer">
<i class="fas fa-shopping-cart fa-fw"></i> {{ $t("Add_to_Shopping") }}
</a>
<a class="dropdown-item" v-if="recipe.internal" @click="addToShopping" href="#"> <i class="fas fa-shopping-cart fa-fw"></i> {{ $t("create_shopping_new") }} </a>
<a class="dropdown-item" v-if="recipe.internal" @click="addToShopping" href="#"> <i
class="fas fa-shopping-cart fa-fw"></i> {{ $t("create_shopping_new") }} </a>

<a class="dropdown-item" @click="createMealPlan" href="javascript:void(0);"><i class="fas fa-calendar fa-fw"></i> {{ $t("Add_to_Plan") }} </a>
<a class="dropdown-item" @click="createMealPlan" href="javascript:void(0);"><i
class="fas fa-calendar fa-fw"></i> {{ $t("Add_to_Plan") }} </a>

<a href="javascript:void(0);">
<button class="dropdown-item" @click="$bvModal.show(`id_modal_cook_log_${modal_id}`)"><i class="fas fa-clipboard-list fa-fw"></i> {{ $t("Log_Cooking") }}</button>
<button class="dropdown-item" @click="$bvModal.show(`id_modal_cook_log_${modal_id}`)"><i
class="fas fa-clipboard-list fa-fw"></i> {{ $t("Log_Cooking") }}
</button>
</a>

<a href="javascript:void(0);">
<button class="dropdown-item" onclick="window.print()"><i class="fas fa-print fa-fw"></i> {{ $t("Print") }}</button>
<button class="dropdown-item" onclick="window.print()"><i class="fas fa-print fa-fw"></i>
{{ $t("Print") }}
</button>
</a>

<a class="dropdown-item" :href="resolveDjangoUrl('view_export') + '?r=' + recipe.id" target="_blank" rel="noopener noreferrer"><i class="fas fa-file-export fa-fw"></i> {{ $t("Export") }}</a>
<a class="dropdown-item" :href="resolveDjangoUrl('view_export') + '?r=' + recipe.id" target="_blank"
rel="noopener noreferrer"><i class="fas fa-file-export fa-fw"></i> {{ $t("Export") }}</a>

<a href="javascript:void(0);">
<button class="dropdown-item" @click="createShareLink()" v-if="recipe.internal"><i class="fas fa-share-alt fa-fw"></i> {{ $t("Share") }}</button>
<button class="dropdown-item" @click="pinRecipe()"><i class="fas fa-thumbtack fa-fw"></i>
{{ $t("Pin") }}
</button>
</a>

<a href="javascript:void(0);">
<button class="dropdown-item" @click="createShareLink()" v-if="recipe.internal"><i
class="fas fa-share-alt fa-fw"></i> {{ $t("Share") }}
</button>
</a>
</div>
</div>
Expand All @@ -44,10 +66,17 @@
<div class="row">
<div class="col col-md-12">
<label v-if="recipe_share_link !== undefined">{{ $t("Public share link") }}</label>
<input ref="share_link_ref" class="form-control" v-model="recipe_share_link" />
<b-button class="mt-2 mb-3 d-none d-md-inline" variant="secondary" @click="$bvModal.hide(`modal-share-link_${modal_id}`)">{{ $t("Close") }} </b-button>
<b-button class="mt-2 mb-3 ml-md-2" variant="primary" @click="copyShareLink()">{{ $t("Copy") }}</b-button>
<b-button class="mt-2 mb-3 ml-2 float-right" variant="success" @click="shareIntend()">{{ $t("Share") }} <i class="fa fa-share-alt"></i></b-button>
<input ref="share_link_ref" class="form-control" v-model="recipe_share_link"/>
<b-button class="mt-2 mb-3 d-none d-md-inline" variant="secondary"
@click="$bvModal.hide(`modal-share-link_${modal_id}`)">{{ $t("Close") }}
</b-button>
<b-button class="mt-2 mb-3 ml-md-2" variant="primary" @click="copyShareLink()">{{
$t("Copy")
}}
</b-button>
<b-button class="mt-2 mb-3 ml-2 float-right" variant="success" @click="shareIntend()">{{
$t("Share")
}} <i class="fa fa-share-alt"></i></b-button>
</div>
</div>
</b-modal>
Expand All @@ -62,20 +91,20 @@
:allow_delete="false"
:modal_title="$t('Create_Meal_Plan_Entry')"
></meal-plan-edit-modal>
<shopping-modal :recipe="recipe" :servings="servings_value" :modal_id="modal_id" />
<shopping-modal :recipe="recipe" :servings="servings_value" :modal_id="modal_id"/>
</div>
</template>

<script>
import { makeToast, resolveDjangoUrl, ResolveUrlMixin, StandardToasts } from "@/utils/utils"
import {makeToast, resolveDjangoUrl, ResolveUrlMixin, StandardToasts} from "@/utils/utils"
import CookLog from "@/components/CookLog"
import axios from "axios"
import AddRecipeToBook from "@/components/Modals/AddRecipeToBook"
import MealPlanEditModal from "@/components/MealPlanEditModal"
import ShoppingModal from "@/components/Modals/ShoppingModal"
import moment from "moment"
import Vue from "vue"
import { ApiApiFactory } from "@/utils/openapi/api"
import {ApiApiFactory} from "@/utils/openapi/api"
Vue.prototype.moment = moment
Expand Down Expand Up @@ -121,6 +150,11 @@ export default {
this.servings_value = this.servings === -1 ? this.recipe.servings : this.servings
},
methods: {
pinRecipe: function () {
let pinnedRecipes = JSON.parse(localStorage.getItem('pinned_recipes') )|| []
pinnedRecipes.push(this.recipe.id)
localStorage.setItem('pinned_recipes', JSON.stringify(pinnedRecipes))
},
saveMealPlan: function (entry) {
entry.date = moment(entry.date).format("YYYY-MM-DD")
Expand Down
7 changes: 2 additions & 5 deletions vue/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,11 @@
"copy_markdown_table": "Copy as Markdown Table",
"in_shopping": "In Shopping List",
"DelayUntil": "Delay Until",
"Pin": "Pin",
"mark_complete": "Mark Complete",
"QuickEntry": "Quick Entry",
"shopping_add_onhand_desc": "Mark food 'On Hand' when checked off shopping list.",
"shopping_add_onhand": "Auto On Hand",
"related_recipes": "Related Recipes",
"today_recipes": "Today's Recipes",
"mark_complete": "Mark Complete",
"QuickEntry": "Quick Entry",
"shopping_add_onhand_desc": "Mark food 'On Hand' when checked off shopping list.",
"shopping_add_onhand": "Auto On Hand"
"today_recipes": "Today's Recipes"
}

0 comments on commit 8b1e80e

Please sign in to comment.