Skip to content

Commit

Permalink
delete excess tracks on show time change
Browse files Browse the repository at this point in the history
fixes #425
  • Loading branch information
RocketMan committed Nov 7, 2023
1 parent 0ec7222 commit 939bbbe
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion api/Playlists.php
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ public function patchResource(RequestInterface $request): ResponseInterface {
}

$success = $attrs->isEmpty() ? true :
$api->updatePlaylist($key, $date, $time, $name, $aid);
$api->updatePlaylist($key, $date, $time, $name, $aid, true);

if($success) {
PushServer::sendAsyncNotification();
Expand Down
26 changes: 26 additions & 0 deletions js/playlists.pick.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,24 @@ $().ready(function(){
return roundedDate.toISOString().split('T');
}

/**
* return duration in minutes between two specified times
*
* if end is less than start, it is assumed to be the next day
*
* @param start string formatted 'hhmm'
* @param end string formatted 'hhmm'
* @returns duration in minutes
*/
function duration(start, end) {
var startTime = new Date('2020-01-01T' + localTimeIntl(start) + ':00Z');
var endTime = new Date('2020-01-01T' + localTimeIntl(end) + ':00Z');
if(endTime < startTime)
endTime.setDate(endTime.getDate() + 1);

return (endTime.getTime() - startTime.getTime()) / 60000;
}

function isEditing(cancel = false) {
if(editing && cancel)
editing.find('#cancel').trigger('click');
Expand Down Expand Up @@ -575,6 +593,14 @@ $().ready(function(){
return;

var list = getEditRow(row);

var newTime = list.attributes.time.split('-');
var oldTime = row.data('orig').attributes.time.split('-');

if(duration(newTime[0], newTime[1]) < duration(oldTime[0], oldTime[1])
&& !confirm("Show has been shortened. Tracks past the end will be deleted.\n\nAre you sure you want to do this?"))
return;

var postData = {
data: {
type: 'show',
Expand Down

0 comments on commit 939bbbe

Please sign in to comment.