Commit 5c597df7 authored by Robert Czechowski's avatar Robert Czechowski
Browse files

Show contestresults (stub template)

parent 83337571
......@@ -169,6 +169,35 @@ pub fn show_contest<T: MedalConnection>(conn: &T, contest_id: u32, session_token
}
}
pub fn show_contest_results<T: MedalConnection>(conn: &T, contest_id: u32, session_token: String) -> MedalValueResult {
let session = conn.get_session(session_token).ok_or(MedalError::AccessDenied)?.ensure_alive().ok_or(MedalError::AccessDenied)?; // TODO SessionTimeout?
let (tasknames, resultdata) = conn.get_contest_groups_grades(session.id, contest_id);
let mut results: Vec<(String, Vec<(String, Vec<String>)>)> = Vec::new();
for (group, groupdata) in resultdata {
let mut groupresults: Vec<(String, Vec<String>)> = Vec::new();
for (user, userdata) in groupdata {
let mut userresults: Vec<String> = Vec::new();
for grade in userdata {
userresults.push(format!("Grade"))
}
groupresults.push((format!("Name"), userresults))
}
results.push((format!("{}",group.name), groupresults));
}
let mut data = json_val::Map::new();
data.insert("taskname".to_string(), to_json(&tasknames));
data.insert("result".to_string(), to_json(&results));
Ok(("contestresults".to_owned(), data))
}
pub fn start_contest<T: MedalConnection>(conn: &T, contest_id: u32, session_token: String, csrf_token:String) -> MedalResult<()> {
let data = json_val::Map::new();
......
......@@ -270,6 +270,24 @@ fn contest(req: &mut Request) -> IronResult<Response> {
Ok(resp)
}
fn contestresults(req: &mut Request) -> IronResult<Response> {
let contest_id = req.expect_int::<u32>("contestid")?;
let session_token = req.require_session_token()?;
let (template, data) = {
// hier ggf. Daten aus dem Request holen
let mutex = req.get::<Write<SharedDatabaseConnection>>().unwrap();
let conn = mutex.lock().unwrap_or_else(|e| e.into_inner());
// Antwort erstellen und zurücksenden
functions::show_contest_results(&*conn, contest_id, session_token).aug(req)?
};
let mut resp = Response::new();
resp.set_mut(Template::new(&template, data)).set_mut(status::Ok);
Ok(resp)
}
fn contest_post(req: &mut Request) -> IronResult<Response> {
let contest_id = req.expect_int::<u32>("contestid")?;
let session_token = req.expect_session_token()?;
......@@ -803,7 +821,7 @@ pub fn start_server(conn: Connection, config: ::Config) -> iron::error::HttpResu
greet: get "/" => greet_personal,
contests: get "/contest/" => contests,
contest: get "/contest/:contestid" => contest,
contestresults: get "/contest/:contestid/results" => contest,
contestresults: get "/contest/:contestid/result/" => contestresults,
contest_post: post "/contest/:contestid" => contest_post,
login: get "/login" => login,
login_post: post "/login" => login_post,
......@@ -820,12 +838,8 @@ pub fn start_server(conn: Connection, config: ::Config) -> iron::error::HttpResu
profile: get "/profile" => profile,
profile_post: post "/profile" => profile_post,
user: get "/user/:userid" => user,
user_post: post "/user/:userid" => user_post,
/*contest_load_par: get "/load" => task_par,
contest_save_par: post "/save" => task_post_par,*/
user_post: post "/user/:userid" => user_post,
task: get "/task/:taskid" => task,
/*load: get "/load" => load_task,
save: post "/save" => save_task,*/
oauth: get "/oauth" => oauth,
check_cookie: get "/cookie" => cookie_warning,
);
......
......@@ -41,5 +41,5 @@ Der Wettbewerb kann nach dem starten nicht mehr pausiert werden.
{{#if teacher}}
<a href="/contest/{{ contest.id }}/results">Ergebnisse meiner Gruppen anzeigen.</a>
<a href="/contest/{{ contest.id }}/result/">Ergebnisse meiner Gruppen anzeigen.</a>
{{/if}}
\ No newline at end of file
{{#each taskname}}
{{this}}
{{/each}}
{{#each result}}
{{this.1}}
{{1}}
{{#each this.2}}
{{this.1}}
{{/each}}
{{/each}}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment