cc-2167-top-panel-doesn't-list-recording-shows
This commit is contained in:
parent
b9c1f7356f
commit
bc640d38f2
9 changed files with 302 additions and 139 deletions
185
airtime_mvc/public/js/airtime/dashboard/helperfunctions.js
Normal file
185
airtime_mvc/public/js/airtime/dashboard/helperfunctions.js
Normal file
|
@ -0,0 +1,185 @@
|
|||
/* function to create popup window */
|
||||
function popup(mylink){
|
||||
if (!window.focus)
|
||||
return true;
|
||||
var href;
|
||||
if (typeof(mylink) == 'string')
|
||||
href=mylink;
|
||||
else
|
||||
href=mylink.href;
|
||||
window.open(href, "player", 'width=300,height=100,scrollbars=yes');
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/* Takes an input parameter of milliseconds and converts these into
|
||||
* the format HH:MM:SS */
|
||||
function convertToHHMMSS(timeInMS){
|
||||
var time = parseInt(timeInMS);
|
||||
|
||||
var hours = parseInt(time / 3600000);
|
||||
time -= 3600000*hours;
|
||||
|
||||
var minutes = parseInt(time / 60000);
|
||||
time -= 60000*minutes;
|
||||
|
||||
var seconds = parseInt(time / 1000);
|
||||
|
||||
hours = hours.toString();
|
||||
minutes = minutes.toString();
|
||||
seconds = seconds.toString();
|
||||
|
||||
if (hours.length == 1)
|
||||
hours = "0" + hours;
|
||||
if (minutes.length == 1)
|
||||
minutes = "0" + minutes;
|
||||
if (seconds.length == 1)
|
||||
seconds = "0" + seconds;
|
||||
if (hours == "00")
|
||||
return minutes + ":" + seconds;
|
||||
else
|
||||
return hours + ":" + minutes + ":" + seconds;
|
||||
}
|
||||
|
||||
function convertToHHMMSSmm(timeInMS){
|
||||
var time = parseInt(timeInMS);
|
||||
|
||||
var hours = parseInt(time / 3600000);
|
||||
time -= 3600000*hours;
|
||||
|
||||
var minutes = parseInt(time / 60000);
|
||||
time -= 60000*minutes;
|
||||
|
||||
var seconds = parseInt(time / 1000);
|
||||
time -= 1000*seconds;
|
||||
|
||||
var ms = parseInt(time);
|
||||
|
||||
hours = hours.toString();
|
||||
minutes = minutes.toString();
|
||||
seconds = seconds.toString();
|
||||
ms = ms.toString();
|
||||
|
||||
if (hours.length == 1)
|
||||
hours = "0" + hours;
|
||||
if (minutes.length == 1)
|
||||
minutes = "0" + minutes;
|
||||
if (seconds.length == 1)
|
||||
seconds = "0" + seconds;
|
||||
|
||||
if (ms.length == 3)
|
||||
ms = ms.substring(0, 2);
|
||||
else if (ms.length == 2)
|
||||
ms = "0" + ms.substring(0,1);
|
||||
else if (ms.length == 1)
|
||||
ms = "00";
|
||||
|
||||
if (hours == "00")
|
||||
return minutes + ":" + seconds + "." + ms;
|
||||
else
|
||||
return hours + ":" + minutes + ":" + seconds+ "." + ms;
|
||||
}
|
||||
|
||||
function convertDateToHHMM(epochTime){
|
||||
var d = new Date(epochTime);
|
||||
|
||||
var hours = d.getUTCHours().toString();
|
||||
var minutes = d.getUTCMinutes().toString();
|
||||
|
||||
if (hours.length == 1)
|
||||
hours = "0" + hours;
|
||||
if (minutes.length == 1)
|
||||
minutes = "0" + minutes;
|
||||
|
||||
return hours + ":" + minutes;
|
||||
}
|
||||
|
||||
function convertDateToHHMMSS(epochTime){
|
||||
var d = new Date(epochTime);
|
||||
|
||||
var hours = d.getUTCHours().toString();
|
||||
var minutes = d.getUTCMinutes().toString();
|
||||
var seconds = d.getUTCSeconds().toString();
|
||||
|
||||
if (hours.length == 1)
|
||||
hours = "0" + hours;
|
||||
if (minutes.length == 1)
|
||||
minutes = "0" + minutes;
|
||||
if (seconds.length == 1)
|
||||
seconds = "0" + seconds;
|
||||
return hours + ":" + minutes + ":" + seconds;
|
||||
}
|
||||
|
||||
/* Takes in a string of format similar to 2011-02-07 02:59:57,
|
||||
* and converts this to epoch/posix time. */
|
||||
function convertDateToPosixTime(s){
|
||||
|
||||
var datetime = s.split(" ");
|
||||
|
||||
var date = datetime[0].split("-");
|
||||
var time = datetime[1].split(":");
|
||||
|
||||
var year = date[0];
|
||||
var month = date[1];
|
||||
var day = date[2];
|
||||
var hour = time[0];
|
||||
var minute = time[1];
|
||||
var sec = 0;
|
||||
var msec = 0;
|
||||
|
||||
if (time[2].indexOf(".") != -1){
|
||||
var temp = time[2].split(".");
|
||||
sec = temp[0];
|
||||
msec = temp[1];
|
||||
} else
|
||||
sec = time[2];
|
||||
|
||||
return Date.UTC(year, month-1, day, hour, minute, sec, msec);
|
||||
}
|
||||
|
||||
function getFileExt(filename){
|
||||
return filename.split('.').pop();
|
||||
}
|
||||
|
||||
var currentAudioPreviewID = "";
|
||||
|
||||
function audioPreview(filename, elemID){
|
||||
|
||||
var elems = $('.ui-icon.ui-icon-pause');
|
||||
elems.attr("class", "ui-icon ui-icon-play");
|
||||
|
||||
if (currentAudioPreviewID == elemID){
|
||||
$('#jquery_jplayer_1').jPlayer('stop');
|
||||
currentAudioPreviewID = "";
|
||||
return;
|
||||
} else {
|
||||
currentAudioPreviewID = elemID;
|
||||
}
|
||||
|
||||
var ext = getFileExt(filename);
|
||||
var uri = "/api/get-media/api_key/" + apiKey + "/file/" + filename;
|
||||
|
||||
var media;
|
||||
var supplied;
|
||||
if (ext == "ogg"){
|
||||
media = {oga:uri};
|
||||
supplied = "oga";
|
||||
} else {
|
||||
media = {mp3:uri};
|
||||
supplied = "mp3";
|
||||
}
|
||||
|
||||
//$('#jquery_jplayer_1').jPlayer('stop');
|
||||
$("#jquery_jplayer_1").jPlayer("destroy");
|
||||
$("#jquery_jplayer_1").jPlayer({
|
||||
ready: function () {
|
||||
//alert(media);
|
||||
$(this).jPlayer("setMedia", media).jPlayer("play");
|
||||
},
|
||||
swfPath: "/js/jplayer",
|
||||
supplied: supplied
|
||||
});
|
||||
|
||||
//$('#jquery_jplayer_1').jPlayer('setMedia', media).jPlayer('play');
|
||||
$('#'+elemID+' div.list-item-container a span').attr("class", "ui-icon ui-icon-pause");
|
||||
}
|
272
airtime_mvc/public/js/airtime/dashboard/playlist.js
Normal file
272
airtime_mvc/public/js/airtime/dashboard/playlist.js
Normal file
|
@ -0,0 +1,272 @@
|
|||
var estimatedSchedulePosixTime = null;
|
||||
var localRemoteTimeOffset = null;
|
||||
|
||||
var previousSong = null;
|
||||
var currentSong = null;
|
||||
var nextSong = null;
|
||||
|
||||
var currentShow = new Array();
|
||||
var nextShow = new Array();
|
||||
|
||||
var currentElem;
|
||||
|
||||
var serverUpdateInterval = 5000;
|
||||
var uiUpdateInterval = 200;
|
||||
|
||||
//set to "development" if we are developing :). Useful to disable alerts
|
||||
//when entering production mode.
|
||||
var APPLICATION_ENV = "";
|
||||
|
||||
/* boolean flag to let us know if we should prepare to execute a function
|
||||
* that flips the playlist to the next song. This flags purpose is to
|
||||
* make sure the function is only executed once*/
|
||||
var nextSongPrepare = true;
|
||||
var nextShowPrepare = true;
|
||||
|
||||
var apiKey = "";
|
||||
|
||||
function secondsTimer(){
|
||||
if (localRemoteTimeOffset !== null){
|
||||
var date = new Date();
|
||||
estimatedSchedulePosixTime = date.getTime() - localRemoteTimeOffset;
|
||||
updateProgressBarValue();
|
||||
updatePlaybar();
|
||||
}
|
||||
setTimeout(secondsTimer, uiUpdateInterval);
|
||||
}
|
||||
|
||||
function newSongStart(){
|
||||
nextSongPrepare = true;
|
||||
currentSong = nextSong;
|
||||
nextSong = null;
|
||||
|
||||
if (typeof notifySongStart == "function")
|
||||
notifySongStart();
|
||||
|
||||
}
|
||||
|
||||
function nextShowStart(){
|
||||
nextShowPrepare = true;
|
||||
currentShow[0] = nextShow.shift();
|
||||
|
||||
//call function in nowplayingdatagrid.js
|
||||
if (typeof notifyShowStart == "function")
|
||||
notifyShowStart(currentShow[0]);
|
||||
}
|
||||
|
||||
/* Called every "uiUpdateInterval" mseconds. */
|
||||
function updateProgressBarValue(){
|
||||
var showPercentDone = 0;
|
||||
if (currentShow.length > 0){
|
||||
showPercentDone = (estimatedSchedulePosixTime - currentShow[0].showStartPosixTime)/currentShow[0].showLengthMs*100;
|
||||
if (showPercentDone < 0 || showPercentDone > 100){
|
||||
showPercentDone = 0;
|
||||
currentShow = new Array();
|
||||
currentSong = new Array();
|
||||
}
|
||||
}
|
||||
$('#progress-show').attr("style", "width:"+showPercentDone+"%");
|
||||
|
||||
var songPercentDone = 0;
|
||||
if (currentSong !== null){
|
||||
songPercentDone = (estimatedSchedulePosixTime - currentSong.songStartPosixTime)/currentSong.songLengthMs*100;
|
||||
if (songPercentDone < 0 || songPercentDone > 100){
|
||||
songPercentDone = 0;
|
||||
currentSong = null;
|
||||
} else {
|
||||
if (currentSong.media_item_played == "t" && currentShow.length > 0)
|
||||
$('#on-air-info').attr("class", "on-air-info on");
|
||||
else
|
||||
$('#on-air-info').attr("class", "on-air-info off");
|
||||
$('#progress-show').attr("class", "progress-show");
|
||||
}
|
||||
} else {
|
||||
$('#on-air-info').attr("class", "on-air-info off");
|
||||
$('#progress-show').attr("class", "progress-show-error");
|
||||
}
|
||||
$('#progress-bar').attr("style", "width:"+songPercentDone+"%");
|
||||
|
||||
//calculate how much time left to next song if there is any
|
||||
if (nextSong !== null && nextSongPrepare){
|
||||
var diff = nextSong.songStartPosixTime - estimatedSchedulePosixTime;
|
||||
if (diff < serverUpdateInterval){
|
||||
|
||||
//sometimes the diff is negative (-100ms for example). Still looking
|
||||
//into why this could sometimes happen.
|
||||
if (diff < 0)
|
||||
diff=0;
|
||||
|
||||
nextSongPrepare = false;
|
||||
setTimeout(newSongStart, diff);
|
||||
}
|
||||
}
|
||||
|
||||
//calculate how much time left to next show if there is any
|
||||
if (nextShow.length > 0 && nextShowPrepare){
|
||||
var diff = nextShow[0].showStartPosixTime - estimatedSchedulePosixTime;
|
||||
if (diff < serverUpdateInterval){
|
||||
if (diff < 0)
|
||||
diff=0;
|
||||
|
||||
nextShowPrepare = false;
|
||||
setTimeout(nextShowStart, diff);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function updatePlaybar(){
|
||||
/* Column 0 update */
|
||||
$('#previous').empty();
|
||||
$('#prev-length').empty();
|
||||
$('#current').html("Current: <span style='color:red; font-weight:bold'>Nothing Scheduled</span>");
|
||||
$('#next').empty();
|
||||
$('#next-length').empty();
|
||||
if (previousSong !== null){
|
||||
$('#previous').text(previousSong.name+",");
|
||||
$('#prev-length').text(convertToHHMMSSmm(previousSong.songLengthMs));
|
||||
}
|
||||
if (currentSong !== null){
|
||||
if (currentSong.record == "1")
|
||||
$('#current').html("<span style='color:red; font-weight:bold'>Recording: </span>"+currentSong.name+",");
|
||||
else
|
||||
$('#current').text(currentSong.name+",");
|
||||
}
|
||||
/*
|
||||
else if (currentShow.length > 0){
|
||||
if (currentShow[0].record == "1"){
|
||||
$('#current').html("Current: <span style='color:red; font-weight:bold'>Recording</span>");
|
||||
}
|
||||
}
|
||||
* */
|
||||
if (nextSong !== null){
|
||||
$('#next').text(nextSong.name+",");
|
||||
$('#next-length').text(convertToHHMMSSmm(nextSong.songLengthMs));
|
||||
}
|
||||
|
||||
$('#start').empty();
|
||||
$('#end').empty();
|
||||
$('#time-elapsed').empty();
|
||||
$('#time-remaining').empty();
|
||||
$('#song-length').empty();
|
||||
if (currentSong !== null){
|
||||
$('#start').text(currentSong.starts.substring(currentSong.starts.indexOf(" ")+1));
|
||||
$('#end').text(currentSong.ends.substring(currentSong.starts.indexOf(" ")+1));
|
||||
|
||||
/* Get rid of the millisecond accuracy so that the second counters for both
|
||||
* show and song change at the same time. */
|
||||
var songStartRoughly = parseInt(Math.round(currentSong.songStartPosixTime/1000))*1000;
|
||||
var songEndRoughly = parseInt(Math.round(currentSong.songEndPosixTime/1000))*1000;
|
||||
|
||||
$('#time-elapsed').text(convertToHHMMSS(estimatedSchedulePosixTime - songStartRoughly));
|
||||
$('#time-remaining').text(convertToHHMMSS(songEndRoughly - estimatedSchedulePosixTime));
|
||||
$('#song-length').text(convertToHHMMSSmm(currentSong.songLengthMs));
|
||||
}
|
||||
/* Column 1 update */
|
||||
$('#playlist').text("Current Show:");
|
||||
var recElem = $('.recording-show');
|
||||
if (currentShow.length > 0){
|
||||
$('#playlist').text(currentShow[0].name);
|
||||
(currentShow[0].record == "1") ? recElem.show(): recElem.hide();
|
||||
} else {
|
||||
recElem.hide();
|
||||
}
|
||||
|
||||
$('#show-length').empty();
|
||||
if (currentShow.length > 0){
|
||||
$('#show-length').text(convertDateToHHMM(currentShow[0].showStartPosixTime) + " - " + convertDateToHHMM(currentShow[0].showEndPosixTime));
|
||||
}
|
||||
|
||||
/* Column 2 update */
|
||||
$('#time').text(convertDateToHHMMSS(estimatedSchedulePosixTime));
|
||||
}
|
||||
|
||||
function calcAdditionalData(currentItem){
|
||||
currentItem.songStartPosixTime = convertDateToPosixTime(currentItem.starts);
|
||||
currentItem.songEndPosixTime = convertDateToPosixTime(currentItem.ends);
|
||||
currentItem.songLengthMs = currentItem.songEndPosixTime - currentItem.songStartPosixTime;
|
||||
}
|
||||
|
||||
function calcAdditionalShowData(show){
|
||||
if (show.length > 0){
|
||||
show[0].showStartPosixTime = convertDateToPosixTime(show[0].start_timestamp);
|
||||
show[0].showEndPosixTime = convertDateToPosixTime(show[0].end_timestamp);
|
||||
show[0].showLengthMs = show[0].showEndPosixTime - show[0].showStartPosixTime;
|
||||
}
|
||||
}
|
||||
|
||||
function parseItems(obj){
|
||||
APPLICATION_ENV = obj.env;
|
||||
apiKey = obj.apiKey;
|
||||
|
||||
$('#time-zone').text(obj.timezone);
|
||||
|
||||
previousSong = obj.previous;
|
||||
currentSong = obj.current;
|
||||
nextSong = obj.next;
|
||||
|
||||
if (previousSong !== null)
|
||||
calcAdditionalData(previousSong);
|
||||
if (currentSong !== null)
|
||||
calcAdditionalData(currentSong);
|
||||
if (nextSong !== null)
|
||||
calcAdditionalData(nextSong);
|
||||
|
||||
currentShow = obj.currentShow;
|
||||
nextShow = obj.nextShow;
|
||||
|
||||
calcAdditionalShowData(obj.currentShow);
|
||||
calcAdditionalShowData(obj.nextShow);
|
||||
|
||||
var schedulePosixTime = convertDateToPosixTime(obj.schedulerTime);
|
||||
schedulePosixTime += parseInt(obj.timezoneOffset)*1000;
|
||||
var date = new Date();
|
||||
localRemoteTimeOffset = date.getTime() - schedulePosixTime;
|
||||
}
|
||||
|
||||
|
||||
function getScheduleFromServer(){
|
||||
$.ajax({ url: "/Schedule/get-current-playlist/format/json", dataType:"json", success:function(data){
|
||||
parseItems(data.entries);
|
||||
}, error:function(jqXHR, textStatus, errorThrown){}});
|
||||
setTimeout(getScheduleFromServer, serverUpdateInterval);
|
||||
}
|
||||
|
||||
function setupQtip(){
|
||||
var qtipElem = $('#about-link');
|
||||
|
||||
if (qtipElem.length > 0){
|
||||
qtipElem.qtip({
|
||||
content: $('#about-txt').html(),
|
||||
show: 'mouseover',
|
||||
hide: { when: 'mouseout', fixed: true },
|
||||
position: {
|
||||
corner: {
|
||||
target: 'center',
|
||||
tooltip: 'topRight'
|
||||
}
|
||||
},
|
||||
style: {
|
||||
border: {
|
||||
width: 0,
|
||||
radius: 4
|
||||
},
|
||||
name: 'light' // Use the default light style
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function init() {
|
||||
//begin producer "thread"
|
||||
getScheduleFromServer();
|
||||
|
||||
//begin consumer "thread"
|
||||
secondsTimer();
|
||||
|
||||
setupQtip();
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
if ($('#master-panel').length > 0)
|
||||
init();
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue