diff --git a/src/Classes/SIS/SIS_Tracklist.php b/src/Classes/SIS/SIS_Tracklist.php index 3e30054d2..ac3a75e29 100644 --- a/src/Classes/SIS/SIS_Tracklist.php +++ b/src/Classes/SIS/SIS_Tracklist.php @@ -30,25 +30,17 @@ public static function getTrackListing($timeslotid, $offset = 0) $tracks = []; foreach ($tracklist as $tracklistitem) { $track = $tracklistitem->getTrack(); - if (is_array($track)) { - $tracks[] = [ - 'playtime' => $tracklistitem->getStartTime(), - 'title' => $track['title'], - 'artist' => $track['artist'], - 'album' => $track['album'], - 'trackid' => 'custom', - 'id' => $tracklistitem->getID(), - ]; - } else { - $tracks[] = [ - 'playtime' => $tracklistitem->getStartTime(), - 'title' => $track->getTitle(), - 'artist' => $track->getArtist(), - 'album' => $track->getAlbum()->getTitle(), - 'trackid' => $track->getID(), - 'id' => $tracklistitem->getID(), - ]; - } + // Essentially, if the item is a manual tracklist outside the library, it will be an array instead of an MyRadio_Track. + $is_array = is_array($track); + $tracks[] = [ + 'playtime' => $tracklistitem->getStartTime(), + 'endtime' => $tracklistitem->getEndTime(), + 'title' => $is_array ? $track['title'] : $track->getTitle(), + 'artist' => $is_array ? $track['artist'] : $track->getArtist(), + 'album' => $is_array ? $track['album'] : $track->getAlbum()->getTitle(), + 'trackid' => $is_array ? 'custom' : $track->getID(), + 'id' => $tracklistitem->getID(), + ]; } return $tracks; diff --git a/src/Classes/ServiceAPI/MyRadio_TracklistItem.php b/src/Classes/ServiceAPI/MyRadio_TracklistItem.php index c20554538..8d0128e21 100644 --- a/src/Classes/ServiceAPI/MyRadio_TracklistItem.php +++ b/src/Classes/ServiceAPI/MyRadio_TracklistItem.php @@ -106,8 +106,10 @@ public static function create($trackid, $timeslotid = null, $starttime = null, $ 403 ); } - + + $timeslot_was_null = false; if ($timeslotid == null) { + $timeslot_was_null = true; $timeslot = MyRadio_Timeslot::getCurrentTimeslot(); $timeslotid = $timeslot != null ? $timeslot->getID() : null; // will be null if jukebox etc. } else { @@ -153,6 +155,14 @@ public static function create($trackid, $timeslotid = null, $starttime = null, $ # If we've been left to work out which state we're in (confirmed or off air), let's look this up. if ($state == null) { $state = in_array($sourceid, self::getTracklistSourcesOnAirAtTime($starttime)) ? 'c': 'o'; + + // If we didn't originally supply a timeslotid, and we're tracklisting off air + // Don't attach to the current timeslot. + // This is useful for BAPS, where it doesn't know if it's tracklisting to a show, or if it's the on air studio. + // We don't want to report a track as played off air to a timeslot if it's in a different room etc. + if ($state == 'o' && $timeslot_was_null == true) { + $timeslotid == null; + } } self::$db->query('BEGIN'); diff --git a/src/Public/js/sis.js b/src/Public/js/sis.js index e5a5ffc30..2bce53eb9 100644 --- a/src/Public/js/sis.js +++ b/src/Public/js/sis.js @@ -23,7 +23,7 @@ var SIS = function (container) { dataType: "json", //The timeout here is to prevent stack overflow complete: function () { - setTimeout(connect, 100); + setTimeout(connect, 10000); }, success: handleResponse, statusCode: { diff --git a/src/Public/js/sis.tracklist.js b/src/Public/js/sis.tracklist.js index bacf90e08..3cf085725 100644 --- a/src/Public/js/sis.tracklist.js +++ b/src/Public/js/sis.tracklist.js @@ -25,7 +25,33 @@ var Tracklist = function () { ); myradio.createDialog( "Confirm removal", - "Are you sure you want to remove " + title + " by " + artist + " from the tracklist?", + "Are you sure you want to remove '" + title + " by " + artist + "' from the tracklist?", + [confirmButton, myradio.closeButton()] + ); + }; + }, + get_end_func = function (id, title, artist) { + return function () { + var confirmButton = document.createElement("button"); + confirmButton.className = "btn btn-warning"; + confirmButton.innerHTML = "End Tracklist"; + confirmButton.setAttribute("data-dismiss", "modal"); + confirmButton.addEventListener( + "click", + function () { + myradio.callAPI("PUT", "tracklistItem", "endtime", id, "", "", + function () { + let row = document.getElementById("t" + id); + let tds = row.childNodes; + let endbtn = tds[tds.length - 1].querySelectorAll('.end-btn')[0]; + row.removeChild(endbtn); + } + ); + } + ); + myradio.createDialog( + "Confirm end of track?", + "Are you sure you want to mark '" + title + " by " + artist + "' as ended in the tracklist?", [confirmButton, myradio.closeButton()] ); }; @@ -203,24 +229,33 @@ var Tracklist = function () { table = document.createElement("table"); table.setAttribute("class", "tracklist"); header = document.createElement("tr"); - header.innerHTML = "TitleArtistAlbumTimeRemove"; + header.innerHTML = "TitleArtistAlbumStart TimeEnd TimeActions"; table.appendChild(header); this.appendChild(addButton); this.appendChild(table); }, update: function (data) { + // Empty the tracklist table so we can fill it with updated content. + var paras = document.getElementsByClassName('td-tracklistitem'); + while(paras[0]) { + paras[0].parentNode.removeChild(paras[0]); + } + for (var i in data) { - var time, + var time,endTime, newRow = document.createElement("tr"), titleTd = document.createElement("td"), artistTd = document.createElement("td"), albumTd = document.createElement("td"), timeTd = document.createElement("td"), - deleteTd = document.createElement("td"), - deleteButton = document.createElement("button"); - + endTimeTd = document.createElement("td"), + actionTd = document.createElement("td"), + deleteButton = document.createElement("button"), + endButton = document.createElement("button"); + time = moment.unix(data[i].playtime); + newRow.className = "td-tracklistitem"; newRow.setAttribute("id", "t"+data[i].id); newRow.setAttribute("trackid", data[i].trackid); @@ -228,26 +263,39 @@ var Tracklist = function () { deleteButton.className = "btn btn-danger"; deleteButton.innerHTML = ""; deleteButton.addEventListener("click", get_delete_func(data[i].id, data[i].title, data[i].artist)); + actionTd.appendChild(deleteButton); + if (data[i].endtime == false) { + endButton.className = "end-btn btn btn-warning"; + endButton.innerHTML = ""; + endButton.addEventListener("click", get_end_func(data[i].id, data[i].title, data[i].artist)); + actionTd.appendChild(endButton); + + endTimeTd.innerHTML = "Playing..." + } else { + endTime = moment.unix(data[i].endtime); + endTimeTd.innerHTML = endTime.format("HH:MM") + }; titleTd.innerHTML = data[i].title; artistTd.innerHTML = data[i].artist; albumTd.innerHTML = data[i].album; timeTd.innerHTML = time.format("HH:mm"); - deleteTd.appendChild(deleteButton); newRow.appendChild(titleTd); newRow.appendChild(artistTd); newRow.appendChild(albumTd); newRow.appendChild(timeTd); - newRow.appendChild(deleteTd); + newRow.appendChild(endTimeTd); + newRow.appendChild(actionTd); table.appendChild(newRow); //Increment the highest message id, if necessary - tracklist_highest_id = (tracklist_highest_id < data[i].id) ? data[i].id : tracklist_highest_id; + //tracklist_highest_id = (tracklist_highest_id < data[i].id) ? data[i].id : tracklist_highest_id; } //Update the server's highest id parameter - this.registerParam("tracklist_highest_id", tracklist_highest_id); + //this.registerParam("tracklist_highest_id", tracklist_highest_id); + //This would then only append new tracklists as they come in, however, we want to show updating end times, so get full tracklist every time. } }; };