Commit 7fa525d8 authored by Robert Czechowski's avatar Robert Czechowski
Browse files

Change page content reloading for contest page to show newly achieved stars...

Change page content reloading for contest page to show newly achieved stars without flooding the browser history
parent a497b7bb
......@@ -161,7 +161,7 @@ fn generate_subtaskstars(tg: &Taskgroup, grade: &Grade, ast: Option<i32>) -> Vec
subtaskinfos
}
pub fn show_contest<T: MedalConnection>(conn: &T, contest_id: i32, session_token: &str) -> MedalValueResult {
pub fn show_contest<T: MedalConnection>(conn: &T, contest_id: i32, session_token: &str, query_string: Option<String>) -> MedalValueResult {
let c = conn.get_contest_by_id_complete(contest_id);
let grades = conn.get_contest_user_grades(&session_token, contest_id);
......@@ -206,6 +206,10 @@ pub fn show_contest<T: MedalConnection>(conn: &T, contest_id: i32, session_token
data.insert("can_start".to_string(), to_json(&true));
}
if query_string.is_none() {
data.insert("not_bare".to_string(), to_json(&true));
}
match conn.get_participation(&session_token, contest_id) {
None => Ok(("contest".to_owned(), data)),
Some(participation) => {
......
......@@ -341,8 +341,9 @@ fn contest<C>(req: &mut Request) -> IronResult<Response>
where C: MedalConnection + std::marker::Send + 'static {
let contest_id = req.expect_int::<i32>("contestid")?;
let session_token = req.require_session_token()?;
let query_string = req.url.query().map(|s| s.to_string());
let (template, data) = with_conn![core::show_contest, C, req, contest_id, &session_token].aug(req)?;
let (template, data) = with_conn![core::show_contest, C, req, contest_id, &session_token, query_string].aug(req)?;
let mut resp = Response::new();
resp.set_mut(Template::new(&template, data)).set_mut(status::Ok);
......
{{#if not_bare}}
<!DOCTYPE html>
<html lang="en" style="background-color: #fafafa;">
<head>
......@@ -62,7 +63,8 @@
</div>
{{/if}}
<div class="columns">
<div class="columns" id="bare_content">
{{/if}}
<div class="column is-8 is-offset-2">
<div style="min-height: 400px; margin-bottom:100px;">
<h3 class="title is-4">{{ contest.name }}</h3>
......@@ -107,6 +109,7 @@
{{/if}}
</div>
</div>
{{#if not_bare}}
</div>
</div>
&nbsp;
......@@ -119,17 +122,20 @@
</footer>
<script>
// Reload page as soon as you come back from another task via the back button in order to show the newly achieved stars
// Reload page content as soon as you come back from another task via the back button in order to show the newly achieved stars
window.onpageshow = function(event) {
if (window.history.state == 1) {
window.history.pushState(0, "title");
location.reload();
var request = new XMLHttpRequest();
request.open("GET","?bare");
request.addEventListener('load', function(event) {
if (request.status >= 200 && request.status < 300) {
document.getElementById("bare_content").innerHTML = request.responseText;
} else {
window.history.pushState(1, "title");
console.warn(request.statusText, request.responseText);
}
});
request.send();
}
</script>
</body>
</html>
{{/if}}
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