Complete rework the index view
* Manage the vector of loads lists in the state * Use a struct as the context for the index template * Rework the _layout and index templates; remove hardcoded examples
This commit is contained in:
parent
c67ff0a78a
commit
23af7ab2be
29
src/main.rs
29
src/main.rs
|
@ -6,24 +6,39 @@ extern crate glob;
|
|||
extern crate inflector;
|
||||
extern crate rocket;
|
||||
extern crate rocket_contrib;
|
||||
|
||||
use rocket::Rocket;
|
||||
use rocket_contrib::Template;
|
||||
|
||||
use std::collections::HashMap;
|
||||
#[macro_use] extern crate serde_derive;
|
||||
extern crate serde_json;
|
||||
|
||||
mod list;
|
||||
mod static_files;
|
||||
|
||||
use list::List;
|
||||
use rocket::{Rocket, State};
|
||||
use rocket_contrib::Template;
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct IndexTemplateContext<'a> {
|
||||
lists: Vec<HashMap<&'a str, &'a str>>
|
||||
}
|
||||
|
||||
#[get("/")]
|
||||
fn index() -> Template {
|
||||
let context: HashMap<String, String> = HashMap::new();
|
||||
fn index(lists: State<Vec<List>>) -> Template {
|
||||
let mut list_kvs = vec![];
|
||||
for list in lists.iter() {
|
||||
let mut list_kv = HashMap::new();
|
||||
list_kv.insert("id", list.id.as_ref());
|
||||
list_kv.insert("name", list.name.as_ref());
|
||||
list_kvs.push(list_kv);
|
||||
}
|
||||
let context = IndexTemplateContext { lists: list_kvs };
|
||||
Template::render("index", &context)
|
||||
}
|
||||
|
||||
fn rocket() -> Rocket {
|
||||
let lists = list::List::load_all();
|
||||
rocket::ignite()
|
||||
.manage(lists)
|
||||
.mount("/", routes![index, static_files::all])
|
||||
.attach(Template::fairing())
|
||||
}
|
||||
|
|
|
@ -26,18 +26,20 @@
|
|||
|
||||
<body>
|
||||
{% block body %}
|
||||
<nav class="navbar fixed-top navbar-dark bg-dark">
|
||||
<div class="container">
|
||||
<div class="navbar-header">
|
||||
<a class="navbar-brand" href="#">Online Prikbord</a>
|
||||
<nav class="navbar navbar-expand-md fixed-top navbar-dark bg-dark" role="navigation">
|
||||
<div class="container">
|
||||
<a class="navbar-brand" href="/">Online Prikbord</a>
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
{% block navbar %}
|
||||
{% endblock navbar %}
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
</nav>
|
||||
<div class="container" id="content">
|
||||
{% block content %}
|
||||
{% endblock content %}
|
||||
{% block content %}{% endblock content %}
|
||||
</div> <!-- /.container -->
|
||||
{% block script %}{% endblock script %}
|
||||
{% endblock body %}
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1,98 +1,46 @@
|
|||
{% extends "_layout" %}
|
||||
{% block content %}
|
||||
<div class="row button-row">
|
||||
<div class="col-md-4">
|
||||
<form class="form-horizontal">
|
||||
<div>
|
||||
<select class="form-control col-md-4">
|
||||
<option id="danielle">Danielle</id>
|
||||
<option id="martin">Martin</id>
|
||||
<option id="paul" selected>Paul</id>
|
||||
<option id="ria">Ria</id>
|
||||
<option id="tom">Tom</id>
|
||||
</select>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<button class="btn btn-default pull-right">
|
||||
<span class="glyphicon glyphicon-edit"></span>
|
||||
Bewerk
|
||||
|
||||
{% block navbar %}
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<ul class="navbar-nav mr-auto">
|
||||
{% for list in lists %}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link listSelect" data-list-id="{{ list.id }}" href="#{{ list.id }}">{{ list.name }}</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
<button class="btn float-right btn-primary" id="editButton">
|
||||
<span class="glyphicon glyphicon-edit"></span>
|
||||
Bewerk
|
||||
</button>
|
||||
<div class="btn-group" role="group" aria-label="Edit buttons">
|
||||
<button class="btn float-right btn-default" id="cancelButton">
|
||||
<span class="glyphicon glyphicon-save"></span>
|
||||
Annuleren
|
||||
</button>
|
||||
</div>
|
||||
<div class="col-md-6" id="save-button">
|
||||
<button class="btn pull-right btn-primary">
|
||||
<button class="btn float-right btn-primary" id="saveButton">
|
||||
<span class="glyphicon glyphicon-save"></span>
|
||||
Opslaan
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock navbar %}
|
||||
|
||||
{% block content %}
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h1 class="panel-title">Lijst van Paul</h1>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<ul>
|
||||
<li>Amazon wish list:
|
||||
<ul>
|
||||
<li>http://is.gd/anacek<br>
|
||||
(let op boekversie en commentaar)</li>
|
||||
<li>Tegoed voor Kindle-boeken</li>
|
||||
</ul>
|
||||
</i>
|
||||
<li>Martijn B. Katan - Voedselmythes</li>
|
||||
<li>Theebewaarbussen (zwarte, paarse, oranje; Simon Levelt)</li>
|
||||
<li>Meerjarige planten voor plantenbakken schutting</li>
|
||||
<li>2 lijsten voor slaapkamer (voor foto/etc.)</li>
|
||||
<li>Schoonmaakspullen fiets:
|
||||
<ul>
|
||||
<li>Borstel:<br>
|
||||
grote voor chassis (zonder te krassen),
|
||||
kleintje voor ketting/tandwielen</li>
|
||||
<li>Ontvetter</li>
|
||||
<li>Kettingreinigerapparaat</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<h4>Zelf uitzoeken (of in overleg)</h4>
|
||||
<ul>
|
||||
<li>Tuintafel</li>
|
||||
<li>Horloge</li>
|
||||
<li>Leuke (LivingWhites-compatibele) (lees)lamp ipv het zeer oude spotje</li>
|
||||
</ul>
|
||||
<h1 class="panel-title" id="listName"></h1>
|
||||
</div>
|
||||
<div class="panel-body" id="listHtml"></div>
|
||||
<div class="panel-footer">
|
||||
<small><i>Laatst aangepast: eergisteren</i></small>
|
||||
<small><i id="listUpdatedAt"></i></small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6" id="editor">
|
||||
<textarea class="form-control" rows="25">
|
||||
* Amazon wish list:
|
||||
- http://is.gd/anacek
|
||||
(let op boekversie en commentaar)
|
||||
- Tegoed voor Kindle-boeken
|
||||
* Martijn B. Katan - Voedselmythes
|
||||
* Theebewaarbussen (zwarte, paarse, oranje; Simon Levelt)
|
||||
* Meerjarige planten voor plantenbakken schutting
|
||||
* 2 lijsten voor slaapkamer (voor foto's/etc.)
|
||||
* Schoonmaakspullen fiets:
|
||||
- Borstel:
|
||||
grote voor chassis (zonder te krassen),
|
||||
kleintje voor ketting/tandwielen
|
||||
- Ontvetter
|
||||
- Kettingreinigerapparaat
|
||||
|
||||
Zelf uitzoeken (of in overleg)
|
||||
------------------------------
|
||||
|
||||
* Tuintafel
|
||||
* Horloge
|
||||
* Leuke (LivingWhites-compatibele) (lees)lamp ipv het zeer oude spotje
|
||||
</textarea>
|
||||
<div class="col-md-6">
|
||||
<textarea class="form-control" id="listData" rows="25"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock content %}
|
||||
|
|
Loading…
Reference in New Issue