From 55966a9d643d4bef0699590d9e1a2e37c636ea2e Mon Sep 17 00:00:00 2001 From: Kjetil Orbekk Date: Fri, 14 Jul 2017 06:42:31 -0400 Subject: add: Limit to quotes displayed --- src/data/templates/quotes.hbs | 4 +++- src/server.rs | 6 +++++- 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:

{{/each}} +{{#if display_more}} +Alle quotes +{{/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 { |id| id.parse::().ok(), ); let ordering = get_param(r, "order").unwrap_or("".to_string()); + let limit = get_param(r, "limit").ok().and_then( + |limit| limit.parse::().ok(), + ).unwrap_or(200); let quotes = { let mu = r.get::>().unwrap(); @@ -120,9 +123,10 @@ fn quotes(r: &mut Request) -> IronResult { None => data::get_quotes(&state.connection, user_id.0, &ordering)?, } }; - let quotes = quotes.into_iter().collect::>(); + let quotes = quotes.into_iter().take(limit).collect::>(); result.insert("quotes".to_string(), to_json("es)); result.insert("scores".to_string(), to_json(&(1..6).collect::>())); + result.insert("display_more".to_string(), to_json(&(quotes.len() == limit))); Ok(Response::with(( status::Ok, Header(ContentType::html()), -- cgit v1.2.3