Compare commits
2 Commits
46532eee9e
...
28afe8ece0
| Author | SHA1 | Date | |
|---|---|---|---|
| 28afe8ece0 | |||
| a7cc92f903 |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -12,3 +12,7 @@
|
||||
**/target
|
||||
**/*.rs.bk
|
||||
**/Cargo.lock
|
||||
|
||||
# Node.js
|
||||
**/node_modules
|
||||
**/package-lock.json
|
||||
|
||||
Binary file not shown.
@@ -76,7 +76,7 @@ fn main() {
|
||||
}
|
||||
let mut category_id = String::new();
|
||||
stdin().read_line(&mut category_id).unwrap();
|
||||
let category_id = category_id.trim().parse::<i16>().expect("Could not parse id");
|
||||
let category_id = category_id.trim().parse::<i16>().unwrap_or(0);
|
||||
builder.set_category(category_id);
|
||||
|
||||
println!("Ingredients (empty line to finish): ");
|
||||
|
||||
@@ -30,6 +30,14 @@ pub mod recipes {
|
||||
recipes.load::<Recipe>(conn)
|
||||
.expect("Error loading recipe's list")
|
||||
}
|
||||
|
||||
pub fn delete(conn: &SqliteConnection, recipe_id: i32) -> bool {
|
||||
use self::schema::recipes::dsl::*;
|
||||
|
||||
diesel::delete(recipes.filter(id.eq(recipe_id)))
|
||||
.execute(conn)
|
||||
.is_ok()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ extern crate planner;
|
||||
|
||||
use self::cookbook::*;
|
||||
use self::cookbook::models::Recipe;
|
||||
use self::planner::solver::{Variables, Domain, Problem, Constraint};
|
||||
use self::planner::solver::{Variables, Domain, Problem};
|
||||
|
||||
/// We want a mapping of the week meals (matin, midi, soir)
|
||||
/// Breakfast => RecipeCategory::Breakfast
|
||||
@@ -29,11 +29,7 @@ impl Into<String> for Meals {
|
||||
}
|
||||
}
|
||||
}
|
||||
/// associated with filters for Domain, depending on recipes RecipeCategory
|
||||
enum RecipeCategory {
|
||||
Breakfast,
|
||||
MainCourse
|
||||
}
|
||||
|
||||
/// It may also contains an initial value for each variable
|
||||
fn generate_variables<V>(domain: &Domain<V>) -> Vec<(String, &Domain<V>, Option<&V>)> {
|
||||
let mut vars = Vec::new();
|
||||
|
||||
@@ -2,39 +2,51 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Hello Bulma!</title>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.2/css/bulma.min.css">
|
||||
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.22/dist/vue.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app">
|
||||
<h1>Cook Assistant</h1>
|
||||
<div class="hero hero-body">
|
||||
<h1 class="title">Cook Assistant</h1>
|
||||
<h2 class="subtitle">Recettes</h2>
|
||||
</div>
|
||||
<!-- Details View -->
|
||||
<section v-if="active_view > -1">
|
||||
<button @click="setActiveView(-1)">X close</button>
|
||||
<h4>{{ items[active_view].title }}</h4>
|
||||
<h6>{{ categories[items[active_view].category].name }}</h6>
|
||||
<section v-if="active_view > -1" class="section has-background-grey-lighter">
|
||||
<div class="box">
|
||||
<button @click="closeActiveView" class="button is-pulled-right">X close</button>
|
||||
<h4 class="title">{{ items[active_view].title }}</h4>
|
||||
<h6 class="subtitle">{{ categories[items[active_view].category].name }}</h6>
|
||||
<p><strong>{{ items[active_view].ingredients }}</strong></p>
|
||||
<button @click="deleteRecipe(active_view + 1)" class="button is-danger is-pulled-right">DELETE !</button>
|
||||
</div>
|
||||
</section>
|
||||
<!-- Category List View -->
|
||||
<section v-else>
|
||||
<div v-if="active_category == -1">
|
||||
<div v-for="c in categories" :key="c.id">
|
||||
<button @click="setActiveCategory(c.id)">{{ c.name }}</button>
|
||||
<section v-else class="section has-background-grey-lighter">
|
||||
<div class="container">
|
||||
<div v-if="active_category == -1" class="columns">
|
||||
<div v-for="c in categories" :key="c.id" class="column">
|
||||
<button @click="setActiveCategory(c.id)" class="button is-large is-primary has-text-dark">{{ c.name }}</button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else>
|
||||
<button @click="setActiveCategory(-1)"><< back</button>
|
||||
<p>{{ categories[active_category].name }}</p>
|
||||
<div v-else class="box">
|
||||
<button @click="setActiveCategory(-1)" class="button is-pulled-left"><< back</button>
|
||||
<h2 class="subtitle">{{ categories[active_category].name }}</h2>
|
||||
<ul>
|
||||
<li v-for="item in displayed" :key="item.id">
|
||||
<a href="" @click.prevent="setActiveView(item.id)">{{ item.title }}</a>
|
||||
<a href="" @click.prevent="setActiveView(items.findIndex((i) => i.id ==item.id))">{{ item.title }}</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</body>
|
||||
<script type="text/javascript">
|
||||
|
||||
// TODO: Must find a viable use of Recipe.id instead of active_view !
|
||||
var app = new Vue({
|
||||
el: '#app',
|
||||
data () {
|
||||
@@ -54,8 +66,18 @@
|
||||
setActiveCategory: function(id) {
|
||||
this.active_category = id;
|
||||
},
|
||||
setActiveView: function(id) {
|
||||
this.active_view = id - 1;
|
||||
setActiveView: function(idx) {
|
||||
this.active_view = idx;
|
||||
},
|
||||
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")
|
||||
|
||||
@@ -55,11 +55,18 @@ mod api {
|
||||
.collect()
|
||||
)
|
||||
}
|
||||
|
||||
#[get("/delete/<id>")]
|
||||
pub fn delete_recipe(conn: CookbookDbConn, id: i32) -> Json<bool> {
|
||||
Json(
|
||||
recipes::delete(&conn, id)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
rocket::ignite()
|
||||
.attach(api::CookbookDbConn::fairing())
|
||||
.mount("/", routes![index])
|
||||
.mount("/api", routes![api::recipes_list]).launch();
|
||||
.mount("/api", routes![api::recipes_list, api::delete_recipe]).launch();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user