cuizin/cuizin/js_src/components/Recipe.vue

166 lines
6.0 KiB
Vue
Raw Normal View History

2018-02-27 17:47:32 +01:00
<template>
<v-container grid-list-md class="panel">
<Loader v-if="isLoading"></Loader>
<v-layout row v-else>
2018-03-04 23:37:10 +01:00
<ErrorDialog :v-model="errorDelete" description="Unable to delete recipe: " />
<ErrorDialog :v-model="errorFetch" description="Unable to fetch recipe: " />
<ErrorDialog :v-model="errorRefetch" description="Unable to refetch recipe: " />
<v-dialog v-model="refetchConfirm" max-width="500px">
<v-card>
2018-03-06 18:29:37 +01:00
<v-card-title class="headline">{{ $t('recipe.refetch_recipe') }}</v-card-title>
<v-card-text>
2018-03-06 18:29:37 +01:00
{{ $t('recipe.refetch_recipe_description') }}
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
2018-03-06 18:29:37 +01:00
<v-btn color="secondary" flat @click.stop="refetchConfirm=false">{{ $t('misc.cancel') }}</v-btn>
<v-btn color="error" flat @click.stop="handleRefetch">{{ $t('recipe.refetch') }}</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
<v-dialog v-model="deleteConfirm" max-width="500px">
<v-card>
2018-03-06 18:29:37 +01:00
<v-card-title class="headline">{{ $t('recipe.delete_recipe') }}</v-card-title>
<v-card-text>{{ $t('recipe.delete_recipe_description') }}</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
2018-03-06 18:29:37 +01:00
<v-btn color="secondary" flat @click.stop="deleteConfirm=false">{{ $t('misc.cancel') }}</v-btn>
<v-btn color="error" flat @click.stop="handleDelete">{{ $t('recipe.delete') }}</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
<v-flex xs12 v-if="recipe">
<h1 class="text-xs-center mt-3 mb-3">
{{ recipe.title }}
</h1>
<p>
</p>
<p class="text-xs-center">
<img :src="recipe.picture" />
</p>
<v-layout row class="text-xs-center">
<v-flex xs6>
<p>{{ recipe.nb_person }}</p>
</v-flex>
<v-flex xs6>
2018-03-10 11:43:14 +01:00
<p><v-icon>timelapse</v-icon> {{ $t('recipe.preparation') }} {{ $tc('misc.Nmins', recipe.preparation_time, { count: recipe.preparation_time ? recipe.preparation_time : '?' }) }}</p>
<p><v-icon>whatshot</v-icon> {{ $t('recipe.cooking') }} {{ $tc('misc.Nmins', recipe.cooking_time, { count: recipe.cooking_time ? recipe.cooking_time : '?' }) }}</p>
</v-flex>
</v-layout>
<p>{{ recipe.short_description }}</p>
2018-03-10 11:43:14 +01:00
2018-03-06 18:29:37 +01:00
<h2>{{ $t('recipe.ingredients') }}</h2>
2018-03-10 11:43:14 +01:00
<ul class="ml-5" v-if="recipe.ingredients && recipe.ingredients.length">
<li v-for="ingredient in recipe.ingredients">
{{ ingredient }}
</li>
</ul>
2018-03-10 11:43:14 +01:00
<p class="ml-5 my-3" v-else>{{ $t('new.none') }}</p>
2018-03-06 18:29:37 +01:00
<h2 class="mt-3">{{ $t('recipe.instructions') }}</h2>
<p v-for="item in recipe.instructions">
{{ item }}
</p>
2018-03-10 11:43:14 +01:00
<p class="text-xs-center">
<v-btn :href="recipe.url" :title="$t('recipe.website')" v-if="recipe.url">
<v-icon class="fa-icon">fa-external-link</v-icon>
</v-btn>
2018-03-06 18:29:37 +01:00
<v-btn @click.stop="deleteConfirm = true" :title="$t('recipe.delete')">
<v-icon>delete</v-icon>
</v-btn>
2018-03-06 18:29:37 +01:00
<v-btn @click.stop="refetchConfirm = true" :title="$t('recipe.refetch')">
<v-icon>autorenew</v-icon>
</v-btn>
</p>
2018-02-28 22:06:21 +01:00
</v-flex>
</v-layout>
</v-container>
2018-02-27 17:47:32 +01:00
</template>
<script>
2018-03-04 23:37:10 +01:00
import * as api from '@/api';
import ErrorDialog from '@/components/ErrorDialog';
import Loader from '@/components/Loader';
2018-02-27 17:47:32 +01:00
export default {
components: {
2018-03-04 23:37:10 +01:00
ErrorDialog,
Loader,
},
data() {
return {
isLoading: false,
recipe: null,
2018-03-04 23:37:10 +01:00
errorFetch: null,
errorDelete: null,
errorRefetch: null,
deleteConfirm: false,
refetchConfirm: false,
};
2018-02-27 17:47:32 +01:00
},
created() {
2018-03-04 23:37:10 +01:00
this.loadRecipe();
},
watch: {
// call again the method if the route changes
2018-03-04 23:37:10 +01:00
$route: 'loadRecipe',
},
methods: {
handleRecipesResponse(response) {
2018-03-04 23:37:10 +01:00
if (response.recipes.length < 1) {
this.$router.replace({
name: 'Home',
});
}
this.recipe = response.recipes[0];
this.isLoading = false;
},
2018-03-04 23:37:10 +01:00
loadRecipe() {
this.isLoading = true;
2018-03-04 23:37:10 +01:00
api.loadRecipe(this.$route.params.recipeId)
.then(this.handleRecipesResponse)
.catch((error) => {
this.isLoading = false;
this.errorFetch = error;
});
},
handleDelete() {
this.isLoading = true;
this.deleteConfirm = false;
2018-03-04 23:37:10 +01:00
api.deleteRecipe(this.$route.params.recipeId)
.then(() => this.$router.replace('/'))
.catch((error) => {
this.isLoading = false;
this.errorDelete = error;
});
},
handleRefetch() {
this.isLoading = true;
this.refetchConfirm = false;
2018-03-04 23:37:10 +01:00
api.refetchRecipe(this.$route.params.recipeId)
.then(this.handleRecipesResponse)
.catch((error) => {
this.isLoading = false;
this.errorRefetch = error;
});
},
2018-02-28 22:06:21 +01:00
},
2018-02-27 17:47:32 +01:00
};
</script>
2018-02-28 22:06:21 +01:00
<style scoped>
img {
2018-03-03 11:41:23 +01:00
width: 100%;
}
.fa-icon {
font-size: 20px;
2018-02-28 22:06:21 +01:00
}
</style>