Adds simple delete api

This commit is contained in:
2019-02-02 15:56:44 +01:00
parent 46532eee9e
commit a7cc92f903
6 changed files with 32 additions and 3 deletions

View File

@@ -9,10 +9,11 @@
<h1>Cook Assistant</h1>
<!-- Details View -->
<section v-if="active_view > -1">
<button @click="setActiveView(-1)">X close</button>
<button @click="closeActiveView">X close</button>
<h4>{{ items[active_view].title }}</h4>
<h6>{{ categories[items[active_view].category].name }}</h6>
<p><strong>{{ items[active_view].ingredients }}</strong></p>
<button @click="deleteRecipe(active_view + 1)">DELETE !</button>
</section>
<!-- Category List View -->
<section v-else>
@@ -57,6 +58,16 @@
setActiveView: function(id) {
this.active_view = id - 1;
},
closeActiveView: function() {
this.active_view = -1;
},
deleteRecipe: function(id) {
fetch("/api/delete/" + id)
.then((res) => res.json())
.then((data) => console.log("Deleted :" + data))
.catch((err) => console.error(err));
this.closeActiveView();
},
fetchRecipesList: function() {
fetch("/api/list")
.then((res) => res.json())