Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add End Time manual handling for SIS. #1005

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 11 additions & 19 deletions src/Classes/SIS/SIS_Tracklist.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 11 additions & 1 deletion src/Classes/ServiceAPI/MyRadio_TracklistItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion src/Public/js/sis.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
68 changes: 58 additions & 10 deletions src/Public/js/sis.tracklist.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()]
);
};
Expand Down Expand Up @@ -203,51 +229,73 @@ var Tracklist = function () {
table = document.createElement("table");
table.setAttribute("class", "tracklist");
header = document.createElement("tr");
header.innerHTML = "<th>Title</th><th>Artist</th><th>Album</th><th>Time</th><th>Remove</th>";
header.innerHTML = "<th>Title</th><th>Artist</th><th>Album</th><th>Start Time</th><th>End Time</th><th>Actions</th>";
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);

deleteButton.className = "btn btn-danger";
deleteButton.innerHTML = "<span class='glyphicon glyphicon-trash'></span>";
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 = "<span class='glyphicon glyphicon-stop'></span>";
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.
}
};
};
Expand Down