Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
bwinf
medal
Commits
21eab7ab
Commit
21eab7ab
authored
Mar 13, 2020
by
Robert Czechowski
Browse files
Refactor: reorder code in show_contest()
parent
a26c7fd0
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/core.rs
View file @
21eab7ab
...
...
@@ -232,15 +232,6 @@ pub fn show_contest<T: MedalConnection>(conn: &T, contest_id: i32, session_token
let
mut
data
=
json_val
::
Map
::
new
();
data
.insert
(
"contest"
.to_string
(),
to_json
(
&
ci
));
if
session
.is_logged_in
()
{
data
.insert
(
"logged_in"
.to_string
(),
to_json
(
&
true
));
data
.insert
(
"username"
.to_string
(),
to_json
(
&
session
.username
));
data
.insert
(
"firstname"
.to_string
(),
to_json
(
&
session
.firstname
));
data
.insert
(
"lastname"
.to_string
(),
to_json
(
&
session
.lastname
));
data
.insert
(
"teacher"
.to_string
(),
to_json
(
&
session
.is_teacher
));
data
.insert
(
"csrf_token"
.to_string
(),
to_json
(
&
session
.csrf_token
));
}
let
now
=
time
::
get_time
();
let
student_grade
=
session
.grade
%
100
-
if
session
.grade
/
100
==
1
{
1
}
else
{
0
};
...
...
@@ -253,37 +244,38 @@ pub fn show_contest<T: MedalConnection>(conn: &T, contest_id: i32, session_token
let
matching_grade
=
!
grade_too_low
&&
!
grade_too_high
;
let
can_start
=
session
.is_logged_in
()
&&
contest_running
&&
matching_grade
;
let
has_duration
=
contest
.duration
>
0
;
contest
.start
.map
(|
start
|
{
if
now
<
start
{
let
time_until
=
start
-
now
;
data
.insert
(
"time_until_start_d"
.to_string
(),
to_json
(
&
(
time_until
.num_days
())));
data
.insert
(
"time_until_start_h"
.to_string
(),
to_json
(
&
(
time_until
.num_hours
()
%
24
)));
data
.insert
(
"time_until_start_m"
.to_string
(),
to_json
(
&
(
time_until
.num_minutes
()
%
60
)));
}
});
contest
.end
.map
(|
end
|
{
if
now
<
end
{
let
time_until
=
end
-
now
;
data
.insert
(
"time_until_end_d"
.to_string
(),
to_json
(
&
(
time_until
.num_days
())));
data
.insert
(
"time_until_end_h"
.to_string
(),
to_json
(
&
(
time_until
.num_hours
()
%
24
)));
data
.insert
(
"time_until_end_m"
.to_string
(),
to_json
(
&
(
time_until
.num_minutes
()
%
60
)));
}
});
data
.insert
(
"has_duration"
.to_string
(),
to_json
(
&
has_duration
));
data
.insert
(
"can_start"
.to_string
(),
to_json
(
&
can_start
));
data
.insert
(
"grade_too_high"
.to_string
(),
to_json
(
&
grade_too_high
));
data
.insert
(
"grade_too_low"
.to_string
(),
to_json
(
&
grade_too_low
));
data
.insert
(
"contest_not_yet"
.to_string
(),
to_json
(
&
contest_not_yet
));
data
.insert
(
"contest_no_more"
.to_string
(),
to_json
(
&
contest_no_more
));
// This only checks if a query string is existent, so any query string will
// lead to the assumption that a bare page is requested. This is useful to
// disable caching (via random token) but should be changed if query string
// can obtain more than only this meaning in the future
if
query_string
.is_none
()
{
data
.insert
(
"not_bare"
.to_string
(),
to_json
(
&
true
));
if
let
Some
(
start
)
=
contest
.start
{
if
now
<
start
{
let
until
=
start
-
now
;
data
.insert
(
"time_until_start"
.to_string
(),
to_json
(
&
[
until
.num_days
(),
until
.num_hours
()
%
24
,
until
.num_minutes
()
%
60
]));
}
}
if
let
Some
(
end
)
=
contest
.end
{
if
now
<
end
{
let
until
=
end
-
now
;
data
.insert
(
"time_until_end"
.to_string
(),
to_json
(
&
[
until
.num_days
(),
until
.num_hours
()
%
24
,
until
.num_minutes
()
%
60
]));
}
}
if
session
.is_logged_in
()
{
data
.insert
(
"logged_in"
.to_string
(),
to_json
(
&
true
));
data
.insert
(
"username"
.to_string
(),
to_json
(
&
session
.username
));
data
.insert
(
"firstname"
.to_string
(),
to_json
(
&
session
.firstname
));
data
.insert
(
"lastname"
.to_string
(),
to_json
(
&
session
.lastname
));
data
.insert
(
"teacher"
.to_string
(),
to_json
(
&
session
.is_teacher
));
data
.insert
(
"csrf_token"
.to_string
(),
to_json
(
&
session
.csrf_token
));
}
if
let
Some
(
participation
)
=
opt_part
{
...
...
@@ -328,8 +320,12 @@ pub fn show_contest<T: MedalConnection>(conn: &T, contest_id: i32, session_token
data
.insert
(
"seconds_left"
.to_string
(),
to_json
(
&
left_secs
));
}
if
contest
.duration
>
0
{
data
.insert
(
"duration"
.to_string
(),
to_json
(
&
true
));
// This only checks if a query string is existent, so any query string will
// lead to the assumption that a bare page is requested. This is useful to
// disable caching (via random token) but should be changed if query string
// can obtain more than only this meaning in the future
if
query_string
.is_none
()
{
data
.insert
(
"not_bare"
.to_string
(),
to_json
(
&
true
));
}
Ok
((
"contest"
.to_owned
(),
data
))
...
...
templates/jwinf/contest.hbs
View file @
21eab7ab
...
...
@@ -81,7 +81,7 @@
<div
class=
"columns"
>
<div
class=
"column is-8 is-offset-2"
>
<h3
class=
"title is-4"
>
{{#if
duration
}}
Wettbewerb:
{{else}}
Trainingsaufgaben:
{{/if}}
{{
contest
.
name
}}
</h3>
<h3
class=
"title is-4"
>
{{#if
has_
duration
}}
Wettbewerb:
{{else}}
Trainingsaufgaben:
{{/if}}
{{
contest
.
name
}}
</h3>
{{#if
contest
.
duration
}}
<h4
class=
"subtitle is-5"
>
Dauer:
{{
contest
.
duration
}}
Minuten
</h4>
{{/if}}
</div>
</div>
...
...
@@ -104,12 +104,12 @@
<div
class=
"column is-6 is-offset-3"
>
<div
style=
"min-height: 400px; margin-bottom:100px;"
class=
"content"
>
<!-- <h3 class="title is-4">
{{#if
duration
}}
Wettbewerb:
{{else}}
Trainingsaufgaben:
{{/if}}
{{
contest
.
name
}}
</h3>
<!-- <h3 class="title is-4">
{{#if
has_
duration
}}
Wettbewerb:
{{else}}
Trainingsaufgaben:
{{/if}}
{{
contest
.
name
}}
</h3>
{{#if
contest
.
duration
}}
<h4 class="subtitle is-5">Dauer:
{{
contest
.
duration
}}
Minuten</h4>
{{/if}}
-->
{{#if
participation_start_date
}}
<p>
{{#if
duration
}}
{{#if
has_
duration
}}
{{#if
time_left
}}
Verbleibenden Zeit:
<span
id=
"timetime"
>
{{
time_left
}}
</span>
...
...
@@ -183,7 +183,7 @@
{{/if}}
{{#if
time_until_end_d
}}
<p>
Der Wettbewerb kann noch gestartet werden:
{{
time_until_end
_d
}}
Tage,
{{
time_until_end
_h
}}
Stunden,
{{
time_until_end
_m
}}
Minuten.
</p>
<p>
Der Wettbewerb kann noch gestartet werden:
{{
time_until_end
.
0
}}
Tage,
{{
time_until_end
.
1
}}
Stunden,
{{
time_until_end
.
2
}}
Minuten.
</p>
{{/if}}
{{else}}
<p>
Du kannst diesen Wettbewerb nicht starten.
</p>
...
...
@@ -193,7 +193,7 @@
{{#if
contest_not_yet
}}
<p>
Der Wettbewerb hat noch nicht begonnen.
</p>
{{#if
time_until_start_d
}}
<p>
Der Wettbewerb wird geöffnet in:
{{
time_until_start
_d
}}
Tagen,
{{
time_until_start
_h
}}
Stunden,
{{
time_until_start
_m
}}
Minuten.
</p>
<p>
Der Wettbewerb wird geöffnet in:
{{
time_until_start
.
0
}}
Tagen,
{{
time_until_start
.
1
}}
Stunden,
{{
time_until_start
.
2
}}
Minuten.
</p>
{{/if}}
{{else}}
{{#if
logged_in
}}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment