Commit 42a269ae authored by Robert Czechowski's avatar Robert Czechowski

Admin page: Contest overview page that makes contest export possible. Fixes #82

parent e49a08ba
......@@ -1277,6 +1277,25 @@ pub fn admin_delete_participation<T: MedalConnection>(conn: &T, user_id: i32, co
Ok(("profile".to_string(), data))
}
pub fn admin_show_contests<T: MedalConnection>(conn: &T, session_token: &str) -> MedalValueResult {
let session = conn.get_session(&session_token)
.ensure_logged_in()
.ok_or(MedalError::NotLoggedIn)?
.ensure_admin()
.ok_or(MedalError::AccessDenied)?;
let mut data = json_val::Map::new();
// TODO: This returns the contests ordered by 'positionalnumber'
// Should this ordering be changed?
let contests: Vec<_> = conn.get_contest_list().into_iter().map(|contest| (contest.id, contest.name)).collect();
data.insert("contests".to_string(), to_json(&contests));
Ok(("admin_contests".to_string(), data))
}
pub fn admin_contest_export<T: MedalConnection>(conn: &T, contest_id: i32, session_token: &str) -> MedalResult<String> {
conn.get_session(&session_token)
.ensure_logged_in()
......
......@@ -1004,6 +1004,17 @@ fn admin_participation<C>(req: &mut Request) -> IronResult<Response>
Ok(resp)
}
fn admin_contests<C>(req: &mut Request) -> IronResult<Response>
where C: MedalConnection + std::marker::Send + 'static {
let session_token = req.expect_session_token()?;
let (template, data) = with_conn![core::admin_show_contests, C, req, &session_token].aug(req)?;
let mut resp = Response::new();
resp.set_mut(Template::new(&template, data)).set_mut(status::Ok);
Ok(resp)
}
fn admin_export_contest<C>(req: &mut Request) -> IronResult<Response>
where C: MedalConnection + std::marker::Send + 'static {
let contest_id = req.expect_int::<i32>("contestid")?;
......@@ -1249,6 +1260,7 @@ pub fn start_server<C>(conn: C, config: Config) -> iron::error::HttpResult<iron:
admin_group_post: post "/admin/group/:groupid" => admin_group::<C>,
admin_participation: get "/admin/user/:userid/:contestid" => admin_participation::<C>,
admin_participation_post: post "/admin/user/:userid/:contestid" => admin_participation::<C>,
admin_contests: get "/admin/contest/" => admin_contests::<C>,
admin_export_contest: get "/admin/contest/:contestid/export" => admin_export_contest::<C>,
oauth: get "/oauth/:oauthid" => oauth::<C>,
check_cookie: get "/cookie" => cookie_warning,
......
<h1>Admin-Suche</h1>
<h1>Administration</h1>
<h2>Admin-Suche</h2>
<p>Suche beachtet Groß-/Kleinschreibung. Das Prozentzeichen % ist ein Wildcart in der Namenssuche. Die Suche gibt nur bis zu 30 Ergebnisse aus, auch wenn es mehr gibt!</p>
<p>
......@@ -48,3 +49,5 @@
<input type="submit" value="search">
</form>
</p>
<h2>Wettbewerbs-Export</h2>
<a href="/admin/contest/">Wettbewerbsübersicht</a>
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