Skip to content

Commit

Permalink
Change insert to add track below insertion point.
Browse files Browse the repository at this point in the history
  • Loading branch information
jcass77 committed Jan 7, 2017
1 parent 200559e commit f777933
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion mopidy_musicbox_webclient/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ <h2>Artists</h2>
<a href="#" onclick="return controls.playQueueTrack();">Play <span class="popupTrackName"></span></a>
</li>
<li data-icon="insert">
<a href="#" onclick="return controls.showAddTrackPopup();">Insert a Track Here</a>
<a href="#" onclick="return controls.showAddTrackPopup();">Insert Below this Track</a>
</li>
<li data-icon="remove">
<a href="#" onclick="return controls.removeTrack('', mopidy);">Remove from Queue</a>
Expand Down
8 changes: 3 additions & 5 deletions mopidy_musicbox_webclient/static/js/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,8 @@
var pos = index
if (pos === null) {
pos = 0
}

if (action === PLAY_NEXT) {
pos = pos + 1
} else if (action !== INSERT_AT_INDEX) {
pos += 1
}

mopidy.tracklist.add({at_position: pos, uris: trackUris}).then(function (tlTracks) {
Expand Down Expand Up @@ -242,7 +240,7 @@
$(this).removeData('tlid')
})
var trackName = popupData[$('#popupQueue').data('track')].name
$('#select-add').append('<option value="6" selected="selected">Insert track before \'' + trackName + '\'</option>')
$('#select-add').append('<option value="6" selected="selected">Insert track below \'' + trackName + '\'</option>')
}
if (typeof songdata.track.uri !== 'undefined' && songdata.track.uri !== '') {
$('#getPlayingBtn').button('enable')
Expand Down
6 changes: 5 additions & 1 deletion mopidy_musicbox_webclient/static/js/gui.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ function setSongTitle (title, refresh_ui) {
}

function setSongInfo (data) {
// console.log(data, songdata);
if (!data) { return }
if (data.tlid === songdata.tlid) { return }
if (!data.track.name || data.track.name === '') {
Expand Down Expand Up @@ -255,6 +254,11 @@ function initSocketevents () {
controls.setPlayState(true)
})

mopidy.on('event:trackPlaybackResumed', function (data) {
setSongInfo(data.tl_track)
controls.setPlayState(true)
})

mopidy.on('event:playlistsLoaded', function (data) {
showLoading(true)
library.getPlaylists()
Expand Down
6 changes: 3 additions & 3 deletions tests/js/test_controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ describe('controls', function () {

it('PLAY_NOW, PLAY_NEXT, and ADD_THIS_BOTTOM should only add one track to the tracklist', function () {
controls.playTracks(PLAY_NOW, mopidy, NEW_TRACKS[0].uri, CURRENT_PLAYLIST_TABLE)
assert(addSpy.calledWithMatch({at_position: 0, uris: [NEW_TRACKS[0].uri]}), 'PLAY_NOW did not add correct track')
assert(addSpy.calledWithMatch({at_position: 1, uris: [NEW_TRACKS[0].uri]}), 'PLAY_NOW did not add correct track')

mopidy.tracklist.clear()
mopidy.tracklist.add({uris: getUris(QUEUE_TRACKS)})
Expand Down Expand Up @@ -132,7 +132,7 @@ describe('controls', function () {

it('PLAY_NEXT should insert track after currently playing track by default', function () {
controls.playTracks(PLAY_NOW, mopidy, NEW_TRACKS[0].uri)
assert(addSpy.calledWithMatch({at_position: 0, uris: [NEW_TRACKS[0].uri]}), 'PLAY_NEXT did not insert track at correct position')
assert(addSpy.calledWithMatch({at_position: 1, uris: [NEW_TRACKS[0].uri]}), 'PLAY_NEXT did not insert track at correct position')
})

it('PLAY_NEXT should insert track after reference track index, if provided', function () {
Expand All @@ -148,7 +148,7 @@ describe('controls', function () {

it('PLAY_NOW should always insert track at current index', function () {
controls.playTracks(PLAY_NOW, mopidy, NEW_TRACKS[0].uri)
assert(addSpy.calledWithMatch({at_position: 0, uris: [NEW_TRACKS[0].uri]}), 'PLAY_NOW did not insert track at correct position')
assert(addSpy.calledWithMatch({at_position: 1, uris: [NEW_TRACKS[0].uri]}), 'PLAY_NOW did not insert track at correct position')
addSpy.reset()

mopidy.tracklist.clear()
Expand Down

0 comments on commit f777933

Please sign in to comment.