summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKjetil Orbekk <kjetil.orbekk@gmail.com>2017-07-14 06:42:31 -0400
committerKjetil Orbekk <kjetil.orbekk@gmail.com>2017-07-14 06:42:31 -0400
commit55966a9d643d4bef0699590d9e1a2e37c636ea2e (patch)
tree2fc7b0885655e6cc3f9988d9ed1855f5b0216364
parent93cb735370c48c3102fdb10e744f7c95d6c0f7c9 (diff)
add: Limit to quotes displayed
-rw-r--r--src/data/templates/quotes.hbs4
-rw-r--r--src/server.rs6
2 files changed, 8 insertions, 2 deletions
diff --git a/src/data/templates/quotes.hbs b/src/data/templates/quotes.hbs
index 92cf114..ff66d8e 100644
--- a/src/data/templates/quotes.hbs
+++ b/src/data/templates/quotes.hbs
@@ -15,6 +15,8 @@ Dato: {{date}}, Score:
<br>
<hr>
{{/each}}
+{{#if display_more}}
+<a href="quotes.jsp?limit=999999">Alle quotes</a>
+{{/if}}
{{/inline}}
-
{{~> base~}}
diff --git a/src/server.rs b/src/server.rs
index 8a45e37..84bebb4 100644
--- a/src/server.rs
+++ b/src/server.rs
@@ -111,6 +111,9 @@ fn quotes(r: &mut Request) -> IronResult<Response> {
|id| id.parse::<i64>().ok(),
);
let ordering = get_param(r, "order").unwrap_or("".to_string());
+ let limit = get_param(r, "limit").ok().and_then(
+ |limit| limit.parse::<usize>().ok(),
+ ).unwrap_or(200);
let quotes = {
let mu = r.get::<Write<State>>().unwrap();
@@ -120,9 +123,10 @@ fn quotes(r: &mut Request) -> IronResult<Response> {
None => data::get_quotes(&state.connection, user_id.0, &ordering)?,
}
};
- let quotes = quotes.into_iter().collect::<Vec<_>>();
+ let quotes = quotes.into_iter().take(limit).collect::<Vec<_>>();
result.insert("quotes".to_string(), to_json(&quotes));
result.insert("scores".to_string(), to_json(&(1..6).collect::<Vec<_>>()));
+ result.insert("display_more".to_string(), to_json(&(quotes.len() == limit)));
Ok(Response::with((
status::Ok,
Header(ContentType::html()),