Skip to content

Commit

Permalink
Fix few frontend bugs slipped in after code restructuring (#184)
Browse files Browse the repository at this point in the history
* Fix Editor tabs switch by passing event to toggleEditorTab() in studio-edit.js.
* Fix playback state save by correctly reading prev state from localStorage.
* Add `token` field to UI for Brightcove and Wistia.
  • Loading branch information
z4y4ts authored Mar 30, 2017
1 parent 42cabe0 commit 9379edd
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 38 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## [0.6.3] - 2017-03-29
## [0.6.3] - 2017-03-30

### Changed

Expand Down
6 changes: 3 additions & 3 deletions video_xblock/backends/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def basic_fields(self):
Subclasses can extend or redefine list if needed. Defaults to a tuple defined by VideoXBlock.
"""
return ('display_name', 'href')
return ['display_name', 'href']

@property
def advanced_fields(self):
Expand All @@ -130,11 +130,11 @@ def advanced_fields(self):
Subclasses can extend or redefine list if needed. Defaults to a tuple defined by VideoXBlock.
"""
return (
return [
'start_time', 'end_time', 'handout', 'transcripts',
'threeplaymedia_file_id', 'threeplaymedia_apikey', 'download_transcript_allowed',
'default_transcripts', 'download_video_allowed', 'download_video_url'
)
]

@property
def fields_help(self):
Expand Down
7 changes: 5 additions & 2 deletions video_xblock/backends/brightcove.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def basic_fields(self):
Brightcove videos require Brightcove Account id.
"""
return super(BrightcovePlayer, self).basic_fields + ('account_id',)
return super(BrightcovePlayer, self).basic_fields + ['account_id']

@property
def advanced_fields(self):
Expand All @@ -343,7 +343,10 @@ def advanced_fields(self):
Brightcove videos require Brightcove Account id.
"""
return ('player_id',) + super(BrightcovePlayer, self).advanced_fields
fields_list = ['player_id'] + super(BrightcovePlayer, self).advanced_fields
# Add `token` field before `threeplaymedia_file_id`
fields_list.insert(fields_list.index('threeplaymedia_file_id'), 'token')
return fields_list

fields_help = {
'token': 'You can generate a BC token following the guide of '
Expand Down
4 changes: 2 additions & 2 deletions video_xblock/backends/html5.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ def advanced_fields(self):
Hide `download_video_url` field for Html5Player.
"""
return tuple(
return [
field for field in super(Html5Player, self).advanced_fields
if field not in self.exclude_advanced_fields
)
]

exclude_advanced_fields = ('default_transcripts', 'download_video_url')

Expand Down
16 changes: 12 additions & 4 deletions video_xblock/backends/wistia.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ class WistiaPlayer(BaseVideoPlayer):
'Please ensure appropriate operations scope has been set on the video platform.'
}

@property
def advanced_fields(self):
"""
Tuple of VideoXBlock fields to display in Basic tab of edit modal window.
Brightcove videos require Brightcove Account id.
"""
fields_list = super(WistiaPlayer, self).advanced_fields
# Add `token` field before `threeplaymedia_file_id`
fields_list.insert(fields_list.index('threeplaymedia_file_id'), 'token')
return fields_list

def media_id(self, href):
"""
Extract Platform's media id from the video url.
Expand All @@ -78,10 +90,6 @@ def get_frag(self, **context):
self.render_resource('static/html/wistiavideo.html', **context)
)

frag.add_javascript(
self.render_resource('static/js/context.js', **context)
)

js_files = [
'static/vendor/js/vjs.wistia.js',
'static/vendor/js/videojs-offset.min.js',
Expand Down
6 changes: 1 addition & 5 deletions video_xblock/static/js/student-view/player-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,7 @@ var PlayerState = function(player, playerState) {
var saveProgressToLocalStore = function() {
var playerObj = this;
var playbackProgress;
try {
playbackProgress = JSON.parse(localStorage.getItem('playbackProgress'));
} catch (err) {
playbackProgress = {};
}
playbackProgress = JSON.parse(localStorage.getItem('playbackProgress') || '{}');
playbackProgress[window.videoPlayerId] = playerObj.ended() ? 0 : playerObj.currentTime();
localStorage.setItem('playbackProgress', JSON.stringify(playbackProgress));
};
Expand Down
4 changes: 2 additions & 2 deletions video_xblock/static/js/studio-edit/studio-edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function StudioEditableXBlock(runtime, element) {

/** Toggle studio editor's current tab.
*/
function toggleEditorTab(tabName) {
function toggleEditorTab(event, tabName) {
var $tabDisable;
var $tabEnable;
var $otherTabName;
Expand Down Expand Up @@ -77,7 +77,7 @@ function StudioEditableXBlock(runtime, element) {
// Bind listeners to the toggle buttons
$('.edit-menu-tab').click(function(event) {
currentTabName = $(event.currentTarget).attr('data-tab-name');
toggleEditorTab(currentTabName);
toggleEditorTab(event, currentTabName);
});
}
}());
Expand Down
38 changes: 19 additions & 19 deletions video_xblock/tests/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,39 +89,39 @@ def test_get_player_html(self):
self.assertIn('window.videojs', res.body)

expected_basic_fields = [
('display_name', 'href'),
('display_name', 'href', 'account_id'),
('display_name', 'href'),
('display_name', 'href'),
('display_name', 'href'),
['display_name', 'href'],
['display_name', 'href', 'account_id'],
['display_name', 'href'],
['display_name', 'href'],
['display_name', 'href'],
]

expected_advanced_fields = [
(
[ # Youtube
'start_time', 'end_time', 'handout', 'transcripts',
'threeplaymedia_file_id', 'threeplaymedia_apikey', 'download_transcript_allowed',
'default_transcripts', 'download_video_allowed', 'download_video_url'
),
(
'player_id', 'start_time', 'end_time', 'handout', 'transcripts',
],
[ # Brightcove
'player_id', 'start_time', 'end_time', 'handout', 'transcripts', 'token',
'threeplaymedia_file_id', 'threeplaymedia_apikey', 'download_transcript_allowed',
'default_transcripts', 'download_video_allowed', 'download_video_url'
),
(
'start_time', 'end_time', 'handout', 'transcripts',
],
[ # Wistia
'start_time', 'end_time', 'handout', 'transcripts', 'token',
'threeplaymedia_file_id', 'threeplaymedia_apikey', 'download_transcript_allowed',
'default_transcripts', 'download_video_allowed', 'download_video_url'
),
(
],
[ # Vimeo
'start_time', 'end_time', 'handout', 'transcripts',
'threeplaymedia_file_id', 'threeplaymedia_apikey', 'download_transcript_allowed',
'default_transcripts', 'download_video_allowed', 'download_video_url'
),
(
],
[ # Html5
'start_time', 'end_time', 'handout', 'transcripts',
'threeplaymedia_file_id', 'threeplaymedia_apikey', 'download_transcript_allowed',
'download_video_allowed',
),
],
]

@data(*zip(backends, expected_basic_fields, expected_advanced_fields))
Expand All @@ -131,8 +131,8 @@ def test_basic_advanced_fields(self, backend, expected_basic_fields, expected_ad
Test basic_fields & advanced_fields for {0} backend
"""
player = self.player[backend](self.xblock)
self.assertTupleEqual(player.basic_fields, expected_basic_fields)
self.assertTupleEqual(player.advanced_fields, expected_advanced_fields)
self.assertListEqual(player.basic_fields, expected_basic_fields)
self.assertListEqual(player.advanced_fields, expected_advanced_fields)

@data(
([{'lang': 'ru'}], [{'lang': 'en'}, {'lang': 'uk'}]),
Expand Down

0 comments on commit 9379edd

Please sign in to comment.