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
8badb477
Commit
8badb477
authored
Feb 19, 2019
by
Robert Czechowski
Browse files
Countdown in task display
parent
80080987
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/functions.rs
View file @
8badb477
...
...
@@ -342,14 +342,13 @@ pub fn show_task<T: MedalConnection>(conn: &T, task_id: u32, session_token: Stri
// TODO: Nicer message!
}
else
{
let
left_min
=
left_secs
/
60
;
let
left_sec
=
left_secs
%
60
;
if
left_sec
<
10
{
data
.insert
(
"time_left"
.to_string
(),
to_json
(
&
format!
(
"{}:0{}"
,
left_min
,
left_sec
)));
}
else
{
data
.insert
(
"time_left"
.to_string
(),
to_json
(
&
format!
(
"{}:{}"
,
left_min
,
left_sec
)));
}
let
(
hour
,
min
,
sec
)
=
(
left_secs
/
3600
,
left_secs
/
60
%
60
,
left_secs
%
60
);
data
.insert
(
"time_left"
.to_string
(),
to_json
(
&
format!
(
"{}:{:02}"
,
hour
,
min
)));
data
.insert
(
"time_left_sec"
.to_string
(),
to_json
(
&
format!
(
":{:02}"
,
sec
)));
let
taskpath
=
format!
(
"{}{}"
,
c
.location
,
t
.location
);
...
...
@@ -358,6 +357,7 @@ pub fn show_task<T: MedalConnection>(conn: &T, task_id: u32, session_token: Stri
data
.insert
(
"csrftoken"
.to_string
(),
to_json
(
&
session
.csrf_token
));
data
.insert
(
"taskpath"
.to_string
(),
to_json
(
&
taskpath
));
data
.insert
(
"contestid"
.to_string
(),
to_json
(
&
c
.id
));
data
.insert
(
"seconds_left"
.to_string
(),
to_json
(
&
left_secs
));
Ok
((
"task"
.to_owned
(),
data
))
}
...
...
templates/task.hbs
View file @
8badb477
...
...
@@ -87,10 +87,33 @@ width: 100vw;border: 0px;height: calc(100vh - 45px);
Verbleibende Zeit
</div>
<div
id=
"timetime"
>
{{
time_left
}}
<
!--
span id="ttsec">
:00
</span
--
>
{{
time_left
}}
<span
id=
"ttsec"
>
{{
time_left_sec
}}
</span>
</div>
<script>
// todo: update timer
var
seconds_left_at_start
=
{{
seconds_left
}}
;
var
timerStart
=
Date
.
now
();
function
lz
(
a
)
{
var
b
=
a
.
toString
();
if
(
b
.
length
<
2
)
{
return
"
0
"
+
b
;
}
return
b
;
}
function
updateTimer
()
{
var
seconds_passed
=
(
Date
.
now
()
-
timerStart
)
/
1000
;
var
seconds_left
=
seconds_left_at_start
-
seconds_passed
;
var
hour
=
seconds_left
/
3600
|
0
;
var
min
=
seconds_left
/
60
|
0
%
60
|
0
;
var
sec
=
seconds_left
%
60
|
0
;
text
=
hour
.
toString
()
+
"
:
"
+
lz
(
min
)
+
"
<span id=
\"
ttsec
\"
>:
"
+
lz
(
sec
)
+
"
</span>
"
;
document
.
getElementById
(
"
timetime
"
).
innerHTML
=
text
;
}
setInterval
(
updateTimer
,
300
);
</script>
</div>
...
...
Robert Czechowski
@zgtm
mentioned in issue
#8 (closed)
·
Jun 08, 2019
mentioned in issue
#8 (closed)
mentioned in issue #8
Toggle commit list
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