Commit 25a16348 authored by Robert Czechowski's avatar Robert Czechowski

Admin page: Add participation details page

parent 5e8a02e2
Pipeline #686 failed with stage
in 8 minutes and 38 seconds
......@@ -1226,8 +1226,47 @@ pub fn admin_delete_group<T: MedalConnection>(conn: &T, group_id: i32, session_t
#[allow(unused_variables)]
pub fn admin_show_participation<T: MedalConnection>(conn: &T, user_id: i32, contest_id: i32, session_token: &str)
-> MedalValueResult {
let data = json_val::Map::new();
Ok(("profile".to_string(), data))
conn.get_session(&session_token)
.ensure_logged_in()
.ok_or(MedalError::NotLoggedIn)?
.ensure_admin()
.ok_or(MedalError::AccessDenied)?;
let contest = conn.get_contest_by_id_complete(contest_id);
let subms: Vec<(String, Vec<(i32, Vec<(String, i32)>)>)> =
contest.taskgroups
.into_iter()
.map(|tg| {
(tg.name,
tg.tasks
.into_iter()
.map(|t| {
(t.stars,
conn.get_all_submissions(user_id, t.id.unwrap(), None)
.into_iter()
.map(|s| (self::time::strftime("%FT%T%z", &self::time::at(s.date)).unwrap(), s.grade))
.collect())
})
.collect())
})
.collect();
let mut data = json_val::Map::new();
data.insert("submissions".to_string(), to_json(&subms));
data.insert("contestid".to_string(), to_json(&contest.id));
data.insert("contestname".to_string(), to_json(&contest.name));
let user = conn.get_user_by_id(user_id).ok_or(MedalError::AccessDenied)?;
fill_user_data(&user, &mut data);
data.insert("userid".to_string(), to_json(&user.id));
let participation =
conn.get_participation(&user.session_token.unwrap(), contest_id).ok_or(MedalError::AccessDenied)?;
data.insert("start_date".to_string(),
to_json(&self::time::strftime("%FT%T%z", &self::time::at(participation.start)).unwrap()));
Ok(("admin_participation".to_string(), data))
}
#[allow(unused_variables)]
......
......@@ -599,6 +599,28 @@ impl MedalConnection for Connection {
}
}
}
fn get_all_submissions(&self, session_id: i32, task: i32, subtask: Option<&str>) -> Vec<Submission> {
match subtask {
None => {
let query = "SELECT id, grade, validated, nonvalidated_grade, value, date, needs_validation
FROM submission
WHERE task = $1
AND session = $2";
self.query_map_many(query, &[&task, &session_id], |row| Submission { id: Some(row.get(0)),
task: task,
session_user: session_id,
grade: row.get(1),
validated: row.get(2),
nonvalidated_grade: row.get(3),
subtask_identifier: None,
value: row.get(4),
date: row.get(5),
needs_validation: row.get(6) })
.unwrap()
}
_ => unimplemented!()
}
}
fn submit_submission(&self, mut submission: Submission) {
submission.save(self);
......
......@@ -40,6 +40,7 @@ pub trait MedalConnection {
fn logout(&self, session: &str);
fn load_submission(&self, session: &SessionUser, task: i32, subtask: Option<&str>) -> Option<Submission>;
fn get_all_submissions(&self, session_id: i32, task: i32, subtask: Option<&str>) -> Vec<Submission>;
fn submit_submission(&self, submission: Submission);
fn get_grade_by_submission(&self, submission_id: i32) -> Grade;
fn get_contest_groups_grades(&self, session_id: i32, contest_id: i32)
......
......@@ -719,6 +719,28 @@ impl MedalConnection for Connection {
}
}
}
fn get_all_submissions(&self, session_id: i32, task: i32, subtask: Option<&str>) -> Vec<Submission> {
match subtask {
None => {
let query = "SELECT id, grade, validated, nonvalidated_grade, value, date, needs_validation
FROM submission
WHERE task = $1
AND session = $2";
self.query_map_many(query, &[&task, &session_id], |row| Submission { id: Some(row.get(0)),
task: task,
session_user: session_id,
grade: row.get(1),
validated: row.get(2),
nonvalidated_grade: row.get(3),
subtask_identifier: None,
value: row.get(4),
date: row.get(5),
needs_validation: row.get(6) })
.unwrap()
}
_ => unimplemented!(),
}
}
fn submit_submission(&self, mut submission: Submission) {
submission.save(self);
......
......@@ -719,6 +719,28 @@ impl MedalConnection for Connection {
}
}
}
fn get_all_submissions(&self, session_id: i32, task: i32, subtask: Option<&str>) -> Vec<Submission> {
match subtask {
None => {
let query = "SELECT id, grade, validated, nonvalidated_grade, value, date, needs_validation
FROM submission
WHERE task = ?1
AND session = ?2";
self.query_map_many(query, &[&task, &session_id], |row| Submission { id: Some(row.get(0)),
task: task,
session_user: session_id,
grade: row.get(1),
validated: row.get(2),
nonvalidated_grade: row.get(3),
subtask_identifier: None,
value: row.get(4),
date: row.get(5),
needs_validation: row.get(6) })
.unwrap()
}
_ => unimplemented!(),
}
}
fn submit_submission(&self, mut submission: Submission) {
submission.save(self);
......
<h1>Teilnahme</h1>
<h2>Teilnahmedaten</h2>
<h3>Benutzer</h3>
<a href=".">{{firstname}} {{lastname}} ({{userid}})</a>
<h3>Wettbewerb</h3>
{{contestname}} ({{contestid}})
<h3>Start</h3>
{{ start_date }}
<h2>Einsendungen</h2>
<ul>
{{#each submissions}}
{{#each this.1}}
<li>{{ ../0 }} ({{this.0}}☆):
<ul>
{{#each this.1}}
<li>{{this.0}}: {{this.1}}</li>
{{/each}}
</ul>
</li>
{{/each}}
{{/each}}
</ul>
../default/admin_participation.hbs
\ 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