Skip to content

Commit

Permalink
Make MusicNext() and MusicLast() actions cyclic with RepeatAll active
Browse files Browse the repository at this point in the history
Minor change: it also improves on the Makefile's update rule, making
it more stable.
  • Loading branch information
rafael-santiago committed Aug 30, 2024
1 parent 9c3d48d commit 4f91ca3
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 6 deletions.
11 changes: 9 additions & 2 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ define do_update
sleep 1s;\
done;\
fi
@sleep 5s
@cp eutherpe $$(which eutherpe) && \
cp -rf web/ /etc/eutherpe/web/ && \
systemctl start eutherpe && \
Expand All @@ -36,8 +37,14 @@ eutherpe:
fi

tests:
@go clean -testcache
@go test internal/... -v
@ if [ -f /etc/profile.d/goenv.sh ] ; then\
. /etc/profile.d/goenv.sh ;\
go clean -testcache ;\
go test internal/... -v ;\
else \
go clean -testcache ;\
go test internal/... -v ;\
fi

bootstrap:
@$(shell cd .. && ./bootstrap.sh)
Expand Down
4 changes: 4 additions & 0 deletions src/internal/actions/music_last.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ func MusicLast(eutherpeVars *vars.EutherpeVars, userData *url.Values) error {
}
if jumpIndex == -1 {
eutherpeVars.Player.UpNextCurrentOffset--
if eutherpeVars.Player.UpNextCurrentOffset == -1 &&
eutherpeVars.Player.RepeatAll {
eutherpeVars.Player.UpNextCurrentOffset = len(eutherpeVars.Player.UpNext) - 1
}
} else if jumpIndex < eutherpeVars.Player.UpNextCurrentOffset {
eutherpeVars.Player.UpNextCurrentOffset = jumpIndex
}
Expand Down
2 changes: 2 additions & 0 deletions src/internal/actions/music_next.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ func MusicNext(eutherpeVars *vars.EutherpeVars, userData *url.Values) error {
if jumpIndex == -1 {
if eutherpeVars.Player.UpNextCurrentOffset < len(eutherpeVars.Player.UpNext) - 1 {
eutherpeVars.Player.UpNextCurrentOffset++
} else if eutherpeVars.Player.RepeatAll {
eutherpeVars.Player.UpNextCurrentOffset = 0
}
} else if jumpIndex > eutherpeVars.Player.UpNextCurrentOffset {
eutherpeVars.Player.UpNextCurrentOffset = jumpIndex
Expand Down
6 changes: 4 additions & 2 deletions src/internal/renders/collection_render.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ func renderCollectionListing(collection mplayer.MusicCollection) string {
collectionHTML := "<ul id=\"eutherpeUL\">"
artists := mplayer.GetArtistsFromCollection(collection)
for _, artist := range artists {
artistId := fmt.Sprintf("%s-eutpid_%d", artist, idNr)
idNr++
collectionHTML += "<li>"
collectionHTML += "<input type=\"checkbox\" onclick=\"flush_child(this);\" id=\"" + artist + "\" class=\"CollectionArtist\"><span class=\"caret\">" + artist + "</span>"
collectionHTML += "<input type=\"checkbox\" onclick=\"flush_child(this);\" id=\"" + artistId + "\" class=\"CollectionArtist\"><span class=\"caret\">" + artist + "</span>"
collectionHTML += "<ul class=\"nested\">"
albums := mplayer.GetAlbumsFromArtist(artist, collection)
for _, album := range albums {
albumId := fmt.Sprintf("%s/%s-eutpid_%d", artist, album, idNr)
albumId := fmt.Sprintf("%s/%s-eutpid_%d", artistId, album, idNr)
idNr++
collectionHTML += "<li>"
collectionHTML += "<input type=\"checkbox\" onclick=\"flush_child(this);\" id=\"" + albumId + "\" class=\"CollectionAlbum\"><span class=\"caret\">" + album + "</span>"
Expand Down
2 changes: 1 addition & 1 deletion src/internal/renders/collection_render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestCollectionRender(t *testing.T) {
}
templatedInput := fmt.Sprintf("%s", vars.EutherpeTemplateNeedleCollection)
output := CollectionRender(templatedInput, eutherpeVars)
if output != "<ul id=\"eutherpeUL\"><li><input type=\"checkbox\" onclick=\"flush_child(this);\" id=\"Motorhead\" class=\"CollectionArtist\"><span class=\"caret\">Motorhead</span><ul class=\"nested\"><li><input type=\"checkbox\" onclick=\"flush_child(this);\" id=\"Motorhead/Overkill-eutpid_0\" class=\"CollectionAlbum\"><span class=\"caret\">Overkill</span><ul class=\"nested\"><li><input type=\"checkbox\" onclick=\"flush_child(this);\" id=\"Motorhead/Overkill-eutpid_0/Overkill-eutpid_1:overkill.mp3\" class=\"CollectionSong\">Overkill</li><li><input type=\"checkbox\" onclick=\"flush_child(this);\" id=\"Motorhead/Overkill-eutpid_0/Stay Clean-eutpid_2:stay-clean.mp3\" class=\"CollectionSong\">Stay Clean</li><li><input type=\"checkbox\" onclick=\"flush_child(this);\" id=\"Motorhead/Overkill-eutpid_0/(I Won't) Pay Your Price-eutpid_3:pay-your-price.mp3\" class=\"CollectionSong\">(I Won't) Pay Your Price</li></ul></li><li><input type=\"checkbox\" onclick=\"flush_child(this);\" id=\"Motorhead/Bomber-eutpid_4\" class=\"CollectionAlbum\"><span class=\"caret\">Bomber</span><ul class=\"nested\"><li><input type=\"checkbox\" onclick=\"flush_child(this);\" id=\"Motorhead/Bomber-eutpid_4/Dead Men Tell No Tales-eutpid_5:dead_men_tell_no_tales.mp3\" class=\"CollectionSong\">Dead Men Tell No Tales</li></ul></li></ul></li><li><input type=\"checkbox\" onclick=\"flush_child(this);\" id=\"Queens Of The Stone Age\" class=\"CollectionArtist\"><span class=\"caret\">Queens Of The Stone Age</span><ul class=\"nested\"><li><input type=\"checkbox\" onclick=\"flush_child(this);\" id=\"Queens Of The Stone Age/Queens Of The Stone Age-eutpid_6\" class=\"CollectionAlbum\"><span class=\"caret\">Queens Of The Stone Age</span><ul class=\"nested\"><li><input type=\"checkbox\" onclick=\"flush_child(this);\" id=\"Queens Of The Stone Age/Queens Of The Stone Age-eutpid_6/Regular John-eutpid_7:regular-john.mp3\" class=\"CollectionSong\">Regular John</li></ul></li></ul></li><li><input type=\"checkbox\" onclick=\"flush_child(this);\" id=\"The Cramps\" class=\"CollectionArtist\"><span class=\"caret\">The Cramps</span><ul class=\"nested\"><li><input type=\"checkbox\" onclick=\"flush_child(this);\" id=\"The Cramps/Songs The Lord Taught Us-eutpid_8\" class=\"CollectionAlbum\"><span class=\"caret\">Songs The Lord Taught Us</span><ul class=\"nested\"><li><input type=\"checkbox\" onclick=\"flush_child(this);\" id=\"The Cramps/Songs The Lord Taught Us-eutpid_8/Fever-eutpid_9:fever.mp3\" class=\"CollectionSong\">Fever</li></ul></li></ul></li></ul>" {
if output != `<ul id="eutherpeUL"><li><input type="checkbox" onclick="flush_child(this);" id="Motorhead-eutpid_0" class="CollectionArtist"><span class="caret">Motorhead</span><ul class="nested"><li><input type="checkbox" onclick="flush_child(this);" id="Motorhead-eutpid_0/Overkill-eutpid_1" class="CollectionAlbum"><span class="caret">Overkill</span><ul class="nested"><li><input type="checkbox" onclick="flush_child(this);" id="Motorhead-eutpid_0/Overkill-eutpid_1/Overkill-eutpid_2:overkill.mp3" class="CollectionSong">Overkill</li><li><input type="checkbox" onclick="flush_child(this);" id="Motorhead-eutpid_0/Overkill-eutpid_1/Stay Clean-eutpid_3:stay-clean.mp3" class="CollectionSong">Stay Clean</li><li><input type="checkbox" onclick="flush_child(this);" id="Motorhead-eutpid_0/Overkill-eutpid_1/(I Won't) Pay Your Price-eutpid_4:pay-your-price.mp3" class="CollectionSong">(I Won't) Pay Your Price</li></ul></li><li><input type="checkbox" onclick="flush_child(this);" id="Motorhead-eutpid_0/Bomber-eutpid_5" class="CollectionAlbum"><span class="caret">Bomber</span><ul class="nested"><li><input type="checkbox" onclick="flush_child(this);" id="Motorhead-eutpid_0/Bomber-eutpid_5/Dead Men Tell No Tales-eutpid_6:dead_men_tell_no_tales.mp3" class="CollectionSong">Dead Men Tell No Tales</li></ul></li></ul></li><li><input type="checkbox" onclick="flush_child(this);" id="Queens Of The Stone Age-eutpid_7" class="CollectionArtist"><span class="caret">Queens Of The Stone Age</span><ul class="nested"><li><input type="checkbox" onclick="flush_child(this);" id="Queens Of The Stone Age-eutpid_7/Queens Of The Stone Age-eutpid_8" class="CollectionAlbum"><span class="caret">Queens Of The Stone Age</span><ul class="nested"><li><input type="checkbox" onclick="flush_child(this);" id="Queens Of The Stone Age-eutpid_7/Queens Of The Stone Age-eutpid_8/Regular John-eutpid_9:regular-john.mp3" class="CollectionSong">Regular John</li></ul></li></ul></li><li><input type="checkbox" onclick="flush_child(this);" id="The Cramps-eutpid_10" class="CollectionArtist"><span class="caret">The Cramps</span><ul class="nested"><li><input type="checkbox" onclick="flush_child(this);" id="The Cramps-eutpid_10/Songs The Lord Taught Us-eutpid_11" class="CollectionAlbum"><span class="caret">Songs The Lord Taught Us</span><ul class="nested"><li><input type="checkbox" onclick="flush_child(this);" id="The Cramps-eutpid_10/Songs The Lord Taught Us-eutpid_11/Fever-eutpid_12:fever.mp3" class="CollectionSong">Fever</li></ul></li></ul></li></ul>` {
t.Errorf("CollectionRender() seems not to be working accordingly. : '%s'\n", output)
}
}
2 changes: 1 addition & 1 deletion src/internal/renders/test-data/expected-eutherpe.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ <h2 class="info-banner">&#x1F9A5; Wait... &#x23F3;</h2>
<h3>&#x1F3B6; Collection</h3>
<hr>
<div class="scrollbox">
<ul id="eutherpeUL"><li><input type="checkbox" onclick="flush_child(this);" id="Motorhead" class="CollectionArtist"><span class="caret">Motorhead</span><ul class="nested"><li><input type="checkbox" onclick="flush_child(this);" id="Motorhead/Overkill-eutpid_0" class="CollectionAlbum"><span class="caret">Overkill</span><ul class="nested"><li><input type="checkbox" onclick="flush_child(this);" id="Motorhead/Overkill-eutpid_0/Overkill-eutpid_1:overkill.mp3" class="CollectionSong">Overkill</li><li><input type="checkbox" onclick="flush_child(this);" id="Motorhead/Overkill-eutpid_0/Stay Clean-eutpid_2:stay-clean.mp3" class="CollectionSong">Stay Clean</li><li><input type="checkbox" onclick="flush_child(this);" id="Motorhead/Overkill-eutpid_0/(I Won't) Pay Your Price-eutpid_3:pay-your-price.mp3" class="CollectionSong">(I Won't) Pay Your Price</li></ul></li><li><input type="checkbox" onclick="flush_child(this);" id="Motorhead/Bomber-eutpid_4" class="CollectionAlbum"><span class="caret">Bomber</span><ul class="nested"><li><input type="checkbox" onclick="flush_child(this);" id="Motorhead/Bomber-eutpid_4/Dead Men Tell No Tales-eutpid_5:dead_men_tell_no_tales.mp3" class="CollectionSong">Dead Men Tell No Tales</li></ul></li></ul></li><li><input type="checkbox" onclick="flush_child(this);" id="Queens Of The Stone Age" class="CollectionArtist"><span class="caret">Queens Of The Stone Age</span><ul class="nested"><li><input type="checkbox" onclick="flush_child(this);" id="Queens Of The Stone Age/Queens Of The Stone Age-eutpid_6" class="CollectionAlbum"><span class="caret">Queens Of The Stone Age</span><ul class="nested"><li><input type="checkbox" onclick="flush_child(this);" id="Queens Of The Stone Age/Queens Of The Stone Age-eutpid_6/Regular John-eutpid_7:regular-john.mp3" class="CollectionSong">Regular John</li></ul></li></ul></li><li><input type="checkbox" onclick="flush_child(this);" id="The Cramps" class="CollectionArtist"><span class="caret">The Cramps</span><ul class="nested"><li><input type="checkbox" onclick="flush_child(this);" id="The Cramps/Songs The Lord Taught Us-eutpid_8" class="CollectionAlbum"><span class="caret">Songs The Lord Taught Us</span><ul class="nested"><li><input type="checkbox" onclick="flush_child(this);" id="The Cramps/Songs The Lord Taught Us-eutpid_8/Fever-eutpid_9:fever.mp3" class="CollectionSong">Fever</li></ul></li></ul></li></ul>
<ul id="eutherpeUL"><li><input type="checkbox" onclick="flush_child(this);" id="Motorhead-eutpid_0" class="CollectionArtist"><span class="caret">Motorhead</span><ul class="nested"><li><input type="checkbox" onclick="flush_child(this);" id="Motorhead-eutpid_0/Overkill-eutpid_1" class="CollectionAlbum"><span class="caret">Overkill</span><ul class="nested"><li><input type="checkbox" onclick="flush_child(this);" id="Motorhead-eutpid_0/Overkill-eutpid_1/Overkill-eutpid_2:overkill.mp3" class="CollectionSong">Overkill</li><li><input type="checkbox" onclick="flush_child(this);" id="Motorhead-eutpid_0/Overkill-eutpid_1/Stay Clean-eutpid_3:stay-clean.mp3" class="CollectionSong">Stay Clean</li><li><input type="checkbox" onclick="flush_child(this);" id="Motorhead-eutpid_0/Overkill-eutpid_1/(I Won't) Pay Your Price-eutpid_4:pay-your-price.mp3" class="CollectionSong">(I Won't) Pay Your Price</li></ul></li><li><input type="checkbox" onclick="flush_child(this);" id="Motorhead-eutpid_0/Bomber-eutpid_5" class="CollectionAlbum"><span class="caret">Bomber</span><ul class="nested"><li><input type="checkbox" onclick="flush_child(this);" id="Motorhead-eutpid_0/Bomber-eutpid_5/Dead Men Tell No Tales-eutpid_6:dead_men_tell_no_tales.mp3" class="CollectionSong">Dead Men Tell No Tales</li></ul></li></ul></li><li><input type="checkbox" onclick="flush_child(this);" id="Queens Of The Stone Age-eutpid_7" class="CollectionArtist"><span class="caret">Queens Of The Stone Age</span><ul class="nested"><li><input type="checkbox" onclick="flush_child(this);" id="Queens Of The Stone Age-eutpid_7/Queens Of The Stone Age-eutpid_8" class="CollectionAlbum"><span class="caret">Queens Of The Stone Age</span><ul class="nested"><li><input type="checkbox" onclick="flush_child(this);" id="Queens Of The Stone Age-eutpid_7/Queens Of The Stone Age-eutpid_8/Regular John-eutpid_9:regular-john.mp3" class="CollectionSong">Regular John</li></ul></li></ul></li><li><input type="checkbox" onclick="flush_child(this);" id="The Cramps-eutpid_10" class="CollectionArtist"><span class="caret">The Cramps</span><ul class="nested"><li><input type="checkbox" onclick="flush_child(this);" id="The Cramps-eutpid_10/Songs The Lord Taught Us-eutpid_11" class="CollectionAlbum"><span class="caret">Songs The Lord Taught Us</span><ul class="nested"><li><input type="checkbox" onclick="flush_child(this);" id="The Cramps-eutpid_10/Songs The Lord Taught Us-eutpid_11/Fever-eutpid_12:fever.mp3" class="CollectionSong">Fever</li></ul></li></ul></li></ul>
</div>
<center>
<hr>
Expand Down

0 comments on commit 4f91ca3

Please sign in to comment.