Commit 216d1ce8 authored by Robert Czechowski's avatar Robert Czechowski

No longer show hidden contest in list of all contest but instead hide contests...

No longer show hidden contest in list of all contest but instead hide contests that are over in all other lists
parent 27ac8c89
Pipeline #566 passed with stages
in 17 minutes and 52 seconds
......@@ -28,7 +28,6 @@ pub struct ContestInfo {
pub name: String,
pub duration: i32,
pub public: bool,
pub login_required: bool,
}
#[derive(Clone)]
......@@ -181,19 +180,19 @@ pub fn show_contests<T: MedalConnection>(conn: &T, session_token: &str,
data.insert("self_url".to_string(), to_json(&self_url));
data.insert("oauth_links".to_string(), to_json(&oauth_links));
let v: Vec<ContestInfo> = conn.get_contest_list()
.iter()
.map(|c| ContestInfo { id: c.id.unwrap(),
name: c.name.clone(),
duration: c.duration,
public: c.public,
login_required: c.requires_login.unwrap_or(false) })
.filter(|ci| ci.public || visibility == ContestVisibility::All)
.filter(|ci| ci.duration == 0 || visibility != ContestVisibility::Open)
.filter(|ci| ci.duration != 0 || visibility != ContestVisibility::Current)
.filter(|ci| ci.login_required || visibility != ContestVisibility::LoginRequired)
.filter(|ci| !ci.login_required || visibility == ContestVisibility::LoginRequired)
.collect();
let now = time::get_time();
let v: Vec<ContestInfo> =
conn.get_contest_list()
.iter()
.filter(|c| c.public)
.filter(|c| c.end.map(|end| now <= end).unwrap_or(true) || visibility == ContestVisibility::All)
.filter(|c| c.duration == 0 || visibility != ContestVisibility::Open)
.filter(|c| c.duration != 0 || visibility != ContestVisibility::Current)
.filter(|c| c.requires_login.unwrap_or(false) || visibility != ContestVisibility::LoginRequired)
.filter(|c| !c.requires_login.unwrap_or(false) || visibility == ContestVisibility::LoginRequired)
.map(|c| ContestInfo { id: c.id.unwrap(), name: c.name.clone(), duration: c.duration, public: c.public })
.collect();
data.insert("contest".to_string(), to_json(&v));
data.insert("contestlist_header".to_string(),
to_json(&match visibility {
......@@ -282,8 +281,7 @@ pub fn show_contest<T: MedalConnection>(conn: &T, contest_id: i32, session_token
let ci = ContestInfo { id: contest.id.unwrap(),
name: contest.name.clone(),
duration: contest.duration,
public: contest.public,
login_required: contest.requires_login.unwrap_or(false) };
public: contest.public };
let mut data = json_val::Map::new();
data.insert("contest".to_string(), to_json(&ci));
......@@ -422,11 +420,8 @@ pub fn show_contest_results<T: MedalConnection>(conn: &T, contest_id: i32, sessi
data.insert("result".to_string(), to_json(&results));
let c = conn.get_contest_by_id(contest_id);
let ci = ContestInfo { id: c.id.unwrap(),
name: c.name.clone(),
duration: c.duration,
public: c.public,
login_required: c.requires_login.unwrap_or(false) };
let ci = ContestInfo { id: c.id.unwrap(), name: c.name.clone(), duration: c.duration, public: c.public };
data.insert("contest".to_string(), to_json(&ci));
data.insert("contestname".to_string(), to_json(&c.name));
......
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