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
2dbc5a41
Commit
2dbc5a41
authored
Feb 16, 2014
by
Valera Rozuvan
Committed by
Valera Rozuvan
Feb 21, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Converting Time module to JS.
parent
1bf5d712
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
113 additions
and
54 deletions
+113
-54
common/lib/xmodule/xmodule/discussion_module.py
+8
-4
common/lib/xmodule/xmodule/js/spec/.gitignore
+3
-0
common/lib/xmodule/xmodule/js/spec/time_spec.coffee
+0
-18
common/lib/xmodule/xmodule/js/spec/time_spec.js
+50
-0
common/lib/xmodule/xmodule/js/src/.gitignore
+5
-2
common/lib/xmodule/xmodule/js/src/time.coffee
+0
-30
common/lib/xmodule/xmodule/js/src/time.js
+47
-0
No files found.
common/lib/xmodule/xmodule/discussion_module.py
View file @
2dbc5a41
...
...
@@ -36,10 +36,14 @@ class DiscussionFields(object):
class
DiscussionModule
(
DiscussionFields
,
XModule
):
js
=
{
'coffee'
:
[
resource_string
(
__name__
,
'js/src/time.coffee'
),
resource_string
(
__name__
,
'js/src/discussion/display.coffee'
)]
}
js
=
{
'coffee'
:
[
resource_string
(
__name__
,
'js/src/discussion/display.coffee'
)
],
'js'
:
[
resource_string
(
__name__
,
'js/src/time.js'
)
]
}
js_module_name
=
"InlineDiscussion"
def
get_html
(
self
):
...
...
common/lib/xmodule/xmodule/js/spec/.gitignore
View file @
2dbc5a41
...
...
@@ -2,3 +2,6 @@
# Tests for video are written in pure JavaScript.
!video/*.js
# Tests for Time are written in pure JavaScript.
!time_spec.js
common/lib/xmodule/xmodule/js/spec/time_spec.coffee
deleted
100644 → 0
View file @
1bf5d712
describe
'Time'
,
->
describe
'format'
,
->
describe
'with duration more than or equal to 1 hour'
,
->
it
'return a correct time format'
,
->
expect
(
Time
.
format
(
3600
)).
toEqual
'1:00:00'
expect
(
Time
.
format
(
7272
)).
toEqual
'2:01:12'
describe
'with duration less than 1 hour'
,
->
it
'return a correct time format'
,
->
expect
(
Time
.
format
(
1
)).
toEqual
'0:01'
expect
(
Time
.
format
(
61
)).
toEqual
'1:01'
expect
(
Time
.
format
(
3599
)).
toEqual
'59:59'
describe
'convert'
,
->
it
'return a correct time based on speed modifier'
,
->
expect
(
Time
.
convert
(
0
,
1
,
1.5
)).
toEqual
'0.000'
expect
(
Time
.
convert
(
100
,
1
,
1.5
)).
toEqual
'66.667'
expect
(
Time
.
convert
(
100
,
1.5
,
1
)).
toEqual
'150.000'
common/lib/xmodule/xmodule/js/spec/time_spec.js
0 → 100644
View file @
2dbc5a41
(
function
(
undefined
)
{
'use strict'
;
describe
(
'Time'
,
function
()
{
describe
(
'format'
,
function
()
{
describe
(
'with duration more than or equal to 1 hour'
,
function
()
{
it
(
'return a correct time format'
,
function
()
{
expect
(
Time
.
format
(
3600
)).
toEqual
(
'1:00:00'
);
expect
(
Time
.
format
(
7272
)).
toEqual
(
'2:01:12'
);
});
});
describe
(
'with duration less than 1 hour'
,
function
()
{
it
(
'return a correct time format'
,
function
()
{
expect
(
Time
.
format
(
1
)).
toEqual
(
'0:01'
);
expect
(
Time
.
format
(
61
)).
toEqual
(
'1:01'
);
expect
(
Time
.
format
(
3599
)).
toEqual
(
'59:59'
);
});
});
});
describe
(
'formatFull'
,
function
()
{
it
(
'gives correct string for times'
,
function
()
{
var
testTimes
=
[
[
0
,
'00:00:00'
],
[
60
,
'00:01:00'
],
[
488
,
'00:08:08'
],
[
2452
,
'00:40:52'
],
[
3600
,
'01:00:00'
],
[
28800
,
'08:00:00'
],
[
144532
,
'40:08:52'
],
[
190360
,
'52:52:40'
],
[
294008
,
'81:40:08'
]
];
$
.
each
(
testTimes
,
function
(
index
,
times
)
{
var
timeInt
=
times
[
0
],
timeStr
=
times
[
1
];
expect
(
Time
.
formatFull
(
timeInt
)).
toBe
(
timeStr
);
});
});
});
describe
(
'convert'
,
function
()
{
it
(
'return a correct time based on speed modifier'
,
function
()
{
expect
(
Time
.
convert
(
0
,
1
,
1.5
)).
toEqual
(
'0.000'
);
expect
(
Time
.
convert
(
100
,
1
,
1.5
)).
toEqual
(
'66.667'
);
expect
(
Time
.
convert
(
100
,
1.5
,
1
)).
toEqual
(
'150.000'
);
});
});
});
}).
call
(
this
);
common/lib/xmodule/xmodule/js/src/.gitignore
View file @
2dbc5a41
...
...
@@ -6,4 +6,8 @@
# Video are written in pure JavaScript.
!video/*.js
!video/transcripts/*.js
\ No newline at end of file
!video/transcripts/*.js
# Converted to JS from CoffeeScript.
!time.js
common/lib/xmodule/xmodule/js/src/time.coffee
deleted
100644 → 0
View file @
1bf5d712
class
@
Time
@
format
:
(
time
)
->
pad
=
(
number
)
->
if
number
<
10
then
"0
#{
number
}
"
else
number
seconds
=
Math
.
floor
time
minutes
=
Math
.
floor
seconds
/
60
hours
=
Math
.
floor
minutes
/
60
seconds
=
seconds
%
60
minutes
=
minutes
%
60
if
hours
"
#{
hours
}
:
#{
pad
(
minutes
)
}
:
#{
pad
(
seconds
%
60
)
}
"
else
"
#{
minutes
}
:
#{
pad
(
seconds
%
60
)
}
"
@
formatFull
:
(
time
)
->
pad
=
(
number
)
->
if
number
<
10
then
"0
#{
number
}
"
else
number
seconds
=
Math
.
floor
time
minutes
=
Math
.
floor
seconds
/
60
hours
=
Math
.
floor
minutes
/
60
seconds
=
seconds
%
60
minutes
=
minutes
%
60
# The returned value will not be user-facing. So no need for
# internationalization.
"
#{
pad
(
hours
)
}
:
#{
pad
(
minutes
)
}
:
#{
pad
(
seconds
%
60
)
}
"
@
convert
:
(
time
,
oldSpeed
,
newSpeed
)
->
(
time
*
oldSpeed
/
newSpeed
).
toFixed
(
3
)
common/lib/xmodule/xmodule/js/src/time.js
0 → 100644
View file @
2dbc5a41
(
function
(
undefined
)
{
'use strict'
;
this
.
Time
=
{
format
:
format
,
formatFull
:
formatFull
,
convert
:
convert
};
return
;
function
format
(
time
,
formatFull
)
{
var
hours
,
minutes
,
seconds
;
seconds
=
Math
.
floor
(
time
);
minutes
=
Math
.
floor
(
seconds
/
60
);
hours
=
Math
.
floor
(
minutes
/
60
);
seconds
=
seconds
%
60
;
minutes
=
minutes
%
60
;
if
(
formatFull
)
{
return
''
+
_pad
(
hours
)
+
':'
+
_pad
(
minutes
)
+
':'
+
_pad
(
seconds
%
60
);
}
else
if
(
hours
)
{
return
''
+
hours
+
':'
+
_pad
(
minutes
)
+
':'
+
_pad
(
seconds
%
60
);
}
else
{
return
''
+
minutes
+
':'
+
_pad
(
seconds
%
60
);
}
}
function
formatFull
(
time
)
{
// The returned value will not be user-facing. So no need for
// internationalization.
return
format
(
time
,
true
);
}
function
convert
(
time
,
oldSpeed
,
newSpeed
)
{
return
(
time
*
oldSpeed
/
newSpeed
).
toFixed
(
3
);
}
function
_pad
(
number
)
{
if
(
number
<
10
)
{
return
'0'
+
number
;
}
else
{
return
''
+
number
;
}
}
}).
call
(
this
);
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