summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKjetil Orbekk <kjetil.orbekk@gmail.com>2017-07-12 21:11:33 -0400
committerKjetil Orbekk <kjetil.orbekk@gmail.com>2017-07-12 21:11:33 -0400
commite033861befa702b9110d531c4d17b40305915ffc (patch)
tree9e7d2b7c791e50828f003a071fb01574bacf3cfa
parent86245ba9e4341a096727158e06290fb8075654ce (diff)
add: Populate date in the new quote form
-rw-r--r--Cargo.lock11
-rw-r--r--Cargo.toml1
-rw-r--r--src/data/templates/add.hbs4
-rw-r--r--src/error.rs2
-rw-r--r--src/lib.rs1
-rw-r--r--src/server.rs10
6 files changed, 23 insertions, 6 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 6633ab9..b1263db 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2,6 +2,7 @@
name = "linoquotes-gamma"
version = "3.0.0"
dependencies = [
+ "chrono 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"clap 2.25.0 (registry+https://github.com/rust-lang/crates.io-index)",
"env_logger 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"handlebars 0.26.2 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -84,6 +85,15 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
+name = "chrono"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "num 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)",
+ "time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
name = "clap"
version = "2.25.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -880,6 +890,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum bodyparser 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6928e817538b74a73d1dd6e9a942a2a35c632a597b6bb14fd009480f859a6bf5"
"checksum buf_redux 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "861b9d19b9f5cb40647242d10d0cb0a13de0a96d5ff8c8a01ea324fa3956eb7d"
"checksum byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c40977b0ee6b9885c9013cd41d9feffdd22deb3bb4dc3a71d901cc7a77de18c8"
+"checksum chrono 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7c20ebe0b2b08b0aeddba49c609fe7957ba2e33449882cb186a180bc60682fa9"
"checksum clap 2.25.0 (registry+https://github.com/rust-lang/crates.io-index)" = "867a885995b4184be051b70a592d4d70e32d7a188db6e8dff626af286a962771"
"checksum conduit-mime-types 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "95ca30253581af809925ef68c2641cc140d6183f43e12e0af4992d53768bd7b8"
"checksum dtoa 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0dd841b58510c9618291ffa448da2e4e0f699d984d436122372f446dae62263d"
diff --git a/Cargo.toml b/Cargo.toml
index 679fbc8..b55533f 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -17,3 +17,4 @@ serde_json = "^1.0.0"
serde_derive = "^1.0.0"
persistent = "^0.3.0"
params = "^0.6.0"
+chrono = "^0.4.0"
diff --git a/src/data/templates/add.hbs b/src/data/templates/add.hbs
index dedc0db..1c7b853 100644
--- a/src/data/templates/add.hbs
+++ b/src/data/templates/add.hbs
@@ -6,8 +6,8 @@
<form action="add.jsp" method="post">
ditt nick:<br>
<input type=text name="nick" size=20><br>
-dato, YYYY-MM-DD (blank for dagens dato):<br>
-<input type=text name="date" size=20><br>
+dato:<br>
+<input type=text name="date" value="{{date}}" size=20><br>
quote:<br>
<textarea name="quote" rows="20" cols="80"></textarea><br>
Prøv å bruke sånn ca. samme timestamp-format (HH:MM) o.l. som eksisterende quotes :-)<br><br>
diff --git a/src/error.rs b/src/error.rs
index 3ccb73c..41b4e64 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -2,7 +2,7 @@ use std;
use std::fmt;
use std::convert::From;
use rusqlite;
-use iron::{self, Response, IronError, status};
+use iron::{IronError, status};
use iron::headers::ContentType;
use iron::modifiers::Header;
diff --git a/src/lib.rs b/src/lib.rs
index 2052a02..6b3e4fb 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -11,6 +11,7 @@ extern crate serde_derive;
extern crate rusqlite;
extern crate persistent;
extern crate params;
+extern crate chrono;
pub mod server;
pub mod data;
diff --git a/src/server.rs b/src/server.rs
index ee51ef3..bd3e8ac 100644
--- a/src/server.rs
+++ b/src/server.rs
@@ -11,6 +11,7 @@ use handlebars_iron::handlebars::to_json;
use serde_json::Map;
use params;
use error::LinoError;
+use chrono;
#[derive(Debug)]
pub struct State {
@@ -87,11 +88,14 @@ fn quotes(r: &mut Request) -> IronResult<Response> {
)))
}
-fn add_get(r: &mut Request) -> IronResult<Response> {
+fn add_get(_r: &mut Request) -> IronResult<Response> {
+ let date = chrono::offset::Local::now().format("%Y-%m-%d").to_string();
+ let mut result = Map::new();
+ result.insert("date".to_string(), to_json(&date));
Ok(Response::with((
status::Ok,
Header(ContentType::html()),
- Template::new("add", Map::new()),
+ Template::new("add", result)
)))
}
@@ -175,7 +179,7 @@ pub fn vote(r: &mut Request) -> IronResult<Response> {
let quote = {
let mu = r.get::<Write<State>>().unwrap();
let state = mu.lock().unwrap();
- data::new_vote(&state.connection, quote_id, vote);
+ data::new_vote(&state.connection, quote_id, vote)?;
data::get_quote(&state.connection, quote_id)?
};