Compare commits
2 Commits
46532eee9e
...
28afe8ece0
| Author | SHA1 | Date | |
|---|---|---|---|
| 28afe8ece0 | |||
| a7cc92f903 |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -12,3 +12,7 @@
|
|||||||
**/target
|
**/target
|
||||||
**/*.rs.bk
|
**/*.rs.bk
|
||||||
**/Cargo.lock
|
**/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();
|
let mut category_id = String::new();
|
||||||
stdin().read_line(&mut category_id).unwrap();
|
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);
|
builder.set_category(category_id);
|
||||||
|
|
||||||
println!("Ingredients (empty line to finish): ");
|
println!("Ingredients (empty line to finish): ");
|
||||||
|
|||||||
@@ -30,6 +30,14 @@ pub mod recipes {
|
|||||||
recipes.load::<Recipe>(conn)
|
recipes.load::<Recipe>(conn)
|
||||||
.expect("Error loading recipe's list")
|
.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::*;
|
||||||
use self::cookbook::models::Recipe;
|
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)
|
/// We want a mapping of the week meals (matin, midi, soir)
|
||||||
/// Breakfast => RecipeCategory::Breakfast
|
/// 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
|
/// It may also contains an initial value for each variable
|
||||||
fn generate_variables<V>(domain: &Domain<V>) -> Vec<(String, &Domain<V>, Option<&V>)> {
|
fn generate_variables<V>(domain: &Domain<V>) -> Vec<(String, &Domain<V>, Option<&V>)> {
|
||||||
let mut vars = Vec::new();
|
let mut vars = Vec::new();
|
||||||
|
|||||||
@@ -2,39 +2,51 @@
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.22/dist/vue.js"></script>
|
<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>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="app">
|
<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 -->
|
<!-- Details View -->
|
||||||
<section v-if="active_view > -1">
|
<section v-if="active_view > -1" class="section has-background-grey-lighter">
|
||||||
<button @click="setActiveView(-1)">X close</button>
|
<div class="box">
|
||||||
<h4>{{ items[active_view].title }}</h4>
|
<button @click="closeActiveView" class="button is-pulled-right">X close</button>
|
||||||
<h6>{{ categories[items[active_view].category].name }}</h6>
|
<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>
|
<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>
|
</section>
|
||||||
<!-- Category List View -->
|
<!-- Category List View -->
|
||||||
<section v-else>
|
<section v-else class="section has-background-grey-lighter">
|
||||||
<div v-if="active_category == -1">
|
<div class="container">
|
||||||
<div v-for="c in categories" :key="c.id">
|
<div v-if="active_category == -1" class="columns">
|
||||||
<button @click="setActiveCategory(c.id)">{{ c.name }}</button>
|
<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 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(items.findIndex((i) => i.id ==item.id))">{{ item.title }}</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
<div v-else>
|
|
||||||
<button @click="setActiveCategory(-1)"><< back</button>
|
|
||||||
<p>{{ categories[active_category].name }}</p>
|
|
||||||
<ul>
|
|
||||||
<li v-for="item in displayed" :key="item.id">
|
|
||||||
<a href="" @click.prevent="setActiveView(item.id)">{{ item.title }}</a>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
// TODO: Must find a viable use of Recipe.id instead of active_view !
|
||||||
var app = new Vue({
|
var app = new Vue({
|
||||||
el: '#app',
|
el: '#app',
|
||||||
data () {
|
data () {
|
||||||
@@ -54,8 +66,18 @@
|
|||||||
setActiveCategory: function(id) {
|
setActiveCategory: function(id) {
|
||||||
this.active_category = id;
|
this.active_category = id;
|
||||||
},
|
},
|
||||||
setActiveView: function(id) {
|
setActiveView: function(idx) {
|
||||||
this.active_view = id - 1;
|
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() {
|
fetchRecipesList: function() {
|
||||||
fetch("/api/list")
|
fetch("/api/list")
|
||||||
|
|||||||
@@ -55,11 +55,18 @@ mod api {
|
|||||||
.collect()
|
.collect()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[get("/delete/<id>")]
|
||||||
|
pub fn delete_recipe(conn: CookbookDbConn, id: i32) -> Json<bool> {
|
||||||
|
Json(
|
||||||
|
recipes::delete(&conn, id)
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
rocket::ignite()
|
rocket::ignite()
|
||||||
.attach(api::CookbookDbConn::fairing())
|
.attach(api::CookbookDbConn::fairing())
|
||||||
.mount("/", routes![index])
|
.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