Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
537d6dd1
Commit
537d6dd1
authored
Feb 12, 2013
by
David Ormsbee
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1490 from MITx/bugfix/brian/pearson-timer
change timer to calculate relative duration in javascript
parents
baee9f96
b5378b04
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
20 deletions
+20
-20
common/lib/xmodule/xmodule/timelimit_module.py
+2
-2
lms/djangoapps/courseware/views.py
+9
-10
lms/templates/courseware/courseware.html
+9
-8
No files found.
common/lib/xmodule/xmodule/timelimit_module.py
View file @
537d6dd1
...
...
@@ -86,8 +86,8 @@ class TimeLimitModule(XModule):
modified_duration
=
self
.
_get_accommodated_duration
(
duration
)
self
.
ending_at
=
self
.
beginning_at
+
modified_duration
def
get_
end
_time_in_ms
(
self
):
return
int
(
self
.
ending_at
*
1000
)
def
get_
remaining
_time_in_ms
(
self
):
return
int
(
(
self
.
ending_at
-
time
())
*
1000
)
def
get_instance_state
(
self
):
state
=
{}
...
...
lms/djangoapps/courseware/views.py
View file @
537d6dd1
...
...
@@ -177,10 +177,10 @@ def check_for_active_timelimit_module(request, course_id, course):
raise
Http404
(
"No {0} metadata at this location: {1} "
.
format
(
'time_expired_redirect_url'
,
location
))
time_expired_redirect_url
=
timelimit_descriptor
.
metadata
.
get
(
'time_expired_redirect_url'
)
context
[
'time_expired_redirect_url'
]
=
time_expired_redirect_url
# Fetch the
end time (in GMT)
as stored in the module when it was started.
# This value should be
UTC time as number of milliseconds since epoch
.
end_date
=
timelimit_module
.
get_end
_time_in_ms
()
context
[
'timer_expiration_d
atetime'
]
=
end_dat
e
# Fetch the
remaining time relative to the end time
as stored in the module when it was started.
# This value should be
in milliseconds
.
remaining_time
=
timelimit_module
.
get_remaining
_time_in_ms
()
context
[
'timer_expiration_d
uration'
]
=
remaining_tim
e
if
'suppress_toplevel_navigation'
in
timelimit_descriptor
.
metadata
:
context
[
'suppress_toplevel_navigation'
]
=
timelimit_descriptor
.
metadata
[
'suppress_toplevel_navigation'
]
return_url
=
reverse
(
'jump_to'
,
kwargs
=
{
'course_id'
:
course_id
,
'location'
:
location
})
...
...
@@ -191,7 +191,7 @@ def update_timelimit_module(user, course_id, student_module_cache, timelimit_des
'''
Updates the state of the provided timing module, starting it if it hasn't begun.
Returns dict with timer-related values to enable display of time remaining.
Returns 'timer_expiration_d
atetime
' in dict if timer is still active, and not if timer has expired.
Returns 'timer_expiration_d
uration
' in dict if timer is still active, and not if timer has expired.
'''
context
=
{}
# determine where to go when the exam ends:
...
...
@@ -215,10 +215,9 @@ def update_timelimit_module(user, course_id, student_module_cache, timelimit_des
instance_module
.
save
()
# the exam has been started, either because the student is returning to the
# exam page, or because they have just visited it. Fetch the end time (in GMT) as stored
# in the module when it was started.
# This value should be UTC time as number of milliseconds since epoch.
context
[
'timer_expiration_datetime'
]
=
timelimit_module
.
get_end_time_in_ms
()
# exam page, or because they have just visited it. Fetch the remaining time relative to the
# end time as stored in the module when it was started.
context
[
'timer_expiration_duration'
]
=
timelimit_module
.
get_remaining_time_in_ms
()
# also use the timed module to determine whether top-level navigation is visible:
if
'suppress_toplevel_navigation'
in
timelimit_descriptor
.
metadata
:
context
[
'suppress_toplevel_navigation'
]
=
timelimit_descriptor
.
metadata
[
'suppress_toplevel_navigation'
]
...
...
@@ -325,7 +324,7 @@ def index(request, course_id, chapter=None, section=None,
if
section_module
.
category
==
'timelimit'
:
timer_context
=
update_timelimit_module
(
request
.
user
,
course_id
,
student_module_cache
,
section_descriptor
,
section_module
)
if
'timer_expiration_d
atetime
'
in
timer_context
:
if
'timer_expiration_d
uration
'
in
timer_context
:
context
.
update
(
timer_context
)
else
:
# if there is no expiration defined, then we know the timer has expired:
...
...
lms/templates/courseware/courseware.html
View file @
537d6dd1
...
...
@@ -60,14 +60,12 @@
});
</script>
% if timer_expiration_d
atetime
:
% if timer_expiration_d
uration
:
<script
type=
"text/javascript"
>
var
timer
=
{
timer_inst
:
null
,
get_remaining_secs
:
function
()
{
// set the end time when the template is rendered.
// This value should be UTC time as number of milliseconds since epoch.
var
endTime
=
new
Date
(
$
{
timer_expiration_datetime
});
timer_inst
:
null
,
end_time
:
null
,
get_remaining_secs
:
function
(
endTime
)
{
var
currentTime
=
new
Date
();
var
remaining_secs
=
Math
.
floor
((
endTime
-
currentTime
)
/
1000
);
return
remaining_secs
;
...
...
@@ -87,13 +85,16 @@
return
remainingTimeString
;
},
update_time
:
function
(
self
)
{
remaining_secs
=
self
.
get_remaining_secs
();
remaining_secs
=
self
.
get_remaining_secs
(
self
.
end_time
);
if
(
remaining_secs
<=
0
)
{
self
.
end
(
self
);
}
$
(
'#exam_timer'
).
text
(
self
.
get_time_string
(
remaining_secs
));
},
start
:
function
()
{
var
that
=
this
;
// set the end time when the template is rendered.
// This value should be UTC time as number of milliseconds since epoch.
this
.
end_time
=
new
Date
((
new
Date
()).
getTime
()
+
$
{
timer_expiration_duration
});
this
.
timer_inst
=
setInterval
(
function
(){
that
.
update_time
(
that
);
},
1000
);
},
end
:
function
(
self
)
{
...
...
@@ -109,7 +110,7 @@
</
%
block>
% if timer_expiration_d
atetime
:
% if timer_expiration_d
uration
:
<div
class=
"timer-main"
>
<div
id=
"timer_wrapper"
>
% if timer_navigation_return_url:
...
...
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