From 36716cf5a971811019280614f8d6ea68c91cdba8 Mon Sep 17 00:00:00 2001 From: Benedict Börger Date: Sat, 27 Apr 2019 22:03:20 +0200 Subject: [web_frontend] adapt URLs to be ablte to address spefic accounts --- src/web_frontend/chart.rs | 13 +++++++------ src/web_frontend/transactions.rs | 9 +++++---- templates/asset.html.tera | 2 +- templates/chart.html.tera | 8 ++++---- templates/transaction.html.tera | 9 ++++----- 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/web_frontend/chart.rs b/src/web_frontend/chart.rs index ed593dd..43ec3eb 100644 --- a/src/web_frontend/chart.rs +++ b/src/web_frontend/chart.rs @@ -23,8 +23,9 @@ struct ChartContext { } -#[get("/chart?&")] -pub fn chart_handler(start : Option<&RawStr>, end : Option<&RawStr>) -> rocket_contrib::templates::Template { +#[get("/chart/?&")] +pub fn chart_handler(account : &RawStr, start : Option<&RawStr>, end : Option<&RawStr>) -> rocket_contrib::templates::Template { + let account_name = account.to_string(); let date_start = match start { Some(s) => { let mut tmp = s.to_string(); tmp.push_str("-01"); @@ -40,7 +41,7 @@ pub fn chart_handler(start : Option<&RawStr>, end : Option<&RawStr>) -> rocket_c let date_range = crate::web_frontend::util::DateRange::new(date_start, date_end); let asset_ini = "data/asset.ini"; let asset = crate::banking::asset::Asset::from_ini_file(asset_ini); - let account = asset.get_account_by_name("Girokonto"); + let account = asset.get_account_by_name(&account_name); let acc; match account { Some(trans) => acc = trans, @@ -55,12 +56,12 @@ pub fn chart_handler(start : Option<&RawStr>, end : Option<&RawStr>) -> rocket_c } let mut groups = HashMap::new(); - let t = acc.transactions; + let t = acc.transactions; // filter transaction to match only the specified timeframe println!("unfiltered number: {}", t.len()); let mut t_filtered = Vec::new(); for date in date_range { - let mut tmp : Vec<_> = t.iter().filter(|x| x.date.month() == date.month()).collect(); + let mut tmp : Vec<_> = t.iter().filter(|x| x.date.month() == date.month() && x.date.year() == date.year()).collect(); t_filtered.append(& mut tmp); } @@ -88,7 +89,7 @@ pub fn chart_handler(start : Option<&RawStr>, end : Option<&RawStr>) -> rocket_c total_chart = total_chart + complete; // ALSO INSERT OTHER, AKA THE REST } - let context = ChartContext { account_name : String::from("Girokonto"), + let context = ChartContext { account_name : account_name, groups : groups, total_sum : total_sum, total_chart : total_chart, date_start : date_start.to_string()[0..7].to_string(), date_end : date_end.to_string()[0..7].to_string() }; diff --git a/src/web_frontend/transactions.rs b/src/web_frontend/transactions.rs index d17f50d..54aacf9 100644 --- a/src/web_frontend/transactions.rs +++ b/src/web_frontend/transactions.rs @@ -37,9 +37,10 @@ fn apply_transaction_filter(filter : String, transactions : Vec&&")] -pub fn transaction_handler(start : Option<&RawStr>, end : Option<&RawStr>, +#[get("/transactions/?&&")] +pub fn transaction_handler(account : &RawStr, start : Option<&RawStr>, end : Option<&RawStr>, filter : Option<&RawStr>) -> rocket_contrib::templates::Template { + let account_name = account.to_string(); let date_start = match start { Some(s) => { let mut tmp = s.to_string(); tmp.push_str("-01"); @@ -58,7 +59,7 @@ pub fn transaction_handler(start : Option<&RawStr>, end : Option<&RawStr>, }; let asset_ini = "data/asset.ini"; let asset : Asset = crate::banking::asset::Asset::from_ini_file(asset_ini); - let transactions = asset.get_account_by_name("Girokonto"); + let transactions = asset.get_account_by_name(&account_name); let acc; match transactions { Some(trans) => acc = trans, @@ -78,7 +79,7 @@ pub fn transaction_handler(start : Option<&RawStr>, end : Option<&RawStr>, // apply filter let ft = apply_transaction_filter(transaction_filter.clone(), t_filtered); - let context = TransactionContext { transactions: ft, account_name : String::from("Girokonto"), + let context = TransactionContext { transactions: ft, account_name : account_name, filter : transaction_filter, date_start : date_start.to_string()[0..7].to_string(), date_end : date_end.to_string()[0..7].to_string()}; Template::render("transaction", context) diff --git a/templates/asset.html.tera b/templates/asset.html.tera index bd0e5b9..9e768d7 100644 --- a/templates/asset.html.tera +++ b/templates/asset.html.tera @@ -57,7 +57,7 @@ {% set amount_sum = 0 %} {% for account in accounts %} - {{ account.name }} + {{ account.name }} {{ account.category }} {% if account.balance >= 0 %} {{ account.balance | round(method="common", precision=2)}} diff --git a/templates/chart.html.tera b/templates/chart.html.tera index 64cb9b3..50adbef 100644 --- a/templates/chart.html.tera +++ b/templates/chart.html.tera @@ -44,9 +44,9 @@ {{ account_name }}