-datagrid now highlights current song playing
This commit is contained in:
parent
51f77dba50
commit
e8d7b59127
4 changed files with 64 additions and 19 deletions
|
@ -9,7 +9,8 @@ class Application_Model_Nowplaying
|
|||
$current = Schedule::GetCurrentlyPlaying($timeNow);
|
||||
$next = Schedule::GetNextItems($timeNow, 10);
|
||||
|
||||
$columnHeaders = array(array("sTitle"=>"Date"),
|
||||
$columnHeaders = array(array("sTitle"=>"type", "bVisible"=>false),
|
||||
array("sTitle"=>"Date"),
|
||||
array("sTitle"=>"Start"),
|
||||
array("sTitle"=>"End"),
|
||||
array("sTitle"=>"Duration"),
|
||||
|
@ -21,19 +22,19 @@ class Application_Model_Nowplaying
|
|||
$rows = array();
|
||||
|
||||
foreach ($previous as $item){
|
||||
array_push($rows, array($item["starts"], $item["starts"], $item["ends"], $item["clip_length"], $item["track_title"], $item["artist_name"],
|
||||
$item["album_title"], "x" , "y"));
|
||||
array_push($rows, array("p", $item["starts"], $item["starts"], $item["ends"], $item["clip_length"], $item["track_title"], $item["artist_name"],
|
||||
$item["album_title"], "x" , $item["playlistname"]));
|
||||
}
|
||||
|
||||
|
||||
foreach ($current as $item){
|
||||
array_push($rows, array($item["starts"], $item["starts"], $item["ends"], $item["clip_length"], $item["track_title"], $item["artist_name"],
|
||||
$item["album_title"], "x" , "y"));
|
||||
array_push($rows, array("c", $item["starts"], $item["starts"], $item["ends"], $item["clip_length"], $item["track_title"], $item["artist_name"],
|
||||
$item["album_title"], "x" , $item["playlistname"]));
|
||||
}
|
||||
|
||||
foreach ($next as $item){
|
||||
array_push($rows, array($item["starts"], $item["starts"], $item["ends"], $item["clip_length"], $item["track_title"], $item["artist_name"],
|
||||
$item["album_title"], "x" , "y"));
|
||||
array_push($rows, array("n", $item["starts"], $item["starts"], $item["ends"], $item["clip_length"], $item["track_title"], $item["artist_name"],
|
||||
$item["album_title"], "x" , $item["playlistname"]));
|
||||
}
|
||||
|
||||
return array("columnHeaders"=>$columnHeaders, "rows"=>$rows);
|
||||
|
|
|
@ -479,9 +479,10 @@ class Schedule {
|
|||
|
||||
public static function GetPreviousItems($timeNow, $prevCount = 1){
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
$sql = "SELECT * FROM $CC_CONFIG[scheduleTable] st, $CC_CONFIG[filesTable] ft"
|
||||
$sql = "SELECT *, pt.name as playlistname FROM $CC_CONFIG[scheduleTable] st, $CC_CONFIG[filesTable] ft, $CC_CONFIG[playListTable] pt"
|
||||
." WHERE (st.ends < TIMESTAMP '$timeNow')"
|
||||
." AND (st.file_id = ft.id)"
|
||||
." AND (st.playlist_id = pt.id)"
|
||||
." ORDER BY st.starts DESC"
|
||||
." LIMIT $prevCount";
|
||||
$rows = $CC_DBC->GetAll($sql);
|
||||
|
@ -491,7 +492,7 @@ class Schedule {
|
|||
public static function GetCurrentlyPlaying($timeNow){
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
|
||||
$sql = "SELECT *, pt.name as playlistName FROM $CC_CONFIG[scheduleTable] st, $CC_CONFIG[filesTable] ft, $CC_CONFIG[playListTable] pt"
|
||||
$sql = "SELECT *, pt.name as playlistname FROM $CC_CONFIG[scheduleTable] st, $CC_CONFIG[filesTable] ft, $CC_CONFIG[playListTable] pt"
|
||||
." WHERE (st.starts < TIMESTAMP '$timeNow')"
|
||||
." AND (st.ends > TIMESTAMP '$timeNow')"
|
||||
." AND (st.playlist_id = pt.id)"
|
||||
|
@ -502,7 +503,7 @@ class Schedule {
|
|||
|
||||
public static function GetNextItems($timeNow, $nextCount = 1) {
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
$sql = "SELECT *, pt.name as playlistName FROM $CC_CONFIG[scheduleTable] st, $CC_CONFIG[filesTable] ft, $CC_CONFIG[playListTable] pt"
|
||||
$sql = "SELECT *, pt.name as playlistname FROM $CC_CONFIG[scheduleTable] st, $CC_CONFIG[filesTable] ft, $CC_CONFIG[playListTable] pt"
|
||||
." WHERE (st.starts > TIMESTAMP '$timeNow')"
|
||||
." AND (st.file_id = ft.id)"
|
||||
." AND (st.playlist_id = pt.id)"
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
<div id='demo'></div>
|
||||
<script>
|
||||
function getDateText(obj){
|
||||
//var str = "";
|
||||
//for (s in obj.oSettings)
|
||||
// str += s + ", ";
|
||||
//alert(str);
|
||||
var str = obj.aData[ obj.iDataColumn ];
|
||||
if (str.indexOf(" ") != -1){
|
||||
return changeTimePrecision(str.substring(0, str.indexOf(" ")));
|
||||
|
@ -30,13 +34,26 @@ function changeTimePrecision(str){
|
|||
return str;
|
||||
}
|
||||
|
||||
function createDataGrid(obj){
|
||||
function notifySongEnd(){
|
||||
for (row in datagridData.rows){
|
||||
if (row[0] == "c")
|
||||
row[0] = "p";
|
||||
if (row[0] == "n"){
|
||||
row[0] = "c";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
obj.columnHeaders[0]["fnRender"] = getDateText;
|
||||
obj.columnHeaders[1]["fnRender"] = getTimeText;
|
||||
obj.columnHeaders[2]["fnRender"] = getTimeText;
|
||||
obj.columnHeaders[3]["fnRender"] = changeTimePrecisionInit;
|
||||
createDataGrid();
|
||||
}
|
||||
|
||||
function createDataGrid(){
|
||||
|
||||
datagridData.columnHeaders[0]["fnRender"] = getDateText;
|
||||
datagridData.columnHeaders[1]["fnRender"] = getTimeText;
|
||||
datagridData.columnHeaders[2]["fnRender"] = getTimeText;
|
||||
datagridData.columnHeaders[3]["fnRender"] = changeTimePrecisionInit;
|
||||
|
||||
$('#demo').html( '<table cellpadding="0" cellspacing="0" border="0" class="display" id="example"></table>' );
|
||||
$('#example').dataTable( {
|
||||
"bSort" : false,
|
||||
|
@ -44,16 +61,34 @@ function createDataGrid(obj){
|
|||
"bFilter": true,
|
||||
"bInfo": false,
|
||||
"bLengthChange": false,
|
||||
"aaData": obj.rows,
|
||||
"aoColumns": obj.columnHeaders
|
||||
"aaData": datagridData.rows,
|
||||
"aoColumns": datagridData.columnHeaders,
|
||||
"fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
|
||||
if (aData[0] == "p"){
|
||||
//$(nRow).attr("style", "background-color:blue;");
|
||||
} else if (aData[0] == "c"){
|
||||
$(nRow).attr("style", "background-color:#61B329;");
|
||||
} else if (aData[0] == "n"){
|
||||
}
|
||||
return nRow;
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
var registered = false
|
||||
|
||||
function init2(){
|
||||
$.ajax({ url: "/Nowplaying/get-data-grid-data/format/json", dataType:"json", success:function(data){
|
||||
createDataGrid(data.entries);
|
||||
datagridData = data.entries;
|
||||
createDataGrid();
|
||||
}});
|
||||
//setTimeout(init2, 5000);
|
||||
|
||||
if (typeof registerSongEndListener == 'function' && !registered){
|
||||
registered = true;
|
||||
registerSongEndListener(notifySongEnd);
|
||||
}
|
||||
|
||||
setTimeout(init2, 5000);
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
|
|
|
@ -11,6 +11,12 @@ var currentElem;
|
|||
|
||||
var updateInterval = 5000;
|
||||
|
||||
var songEndFunc;
|
||||
|
||||
function registerSongEndListener(func){
|
||||
songEndFunc = func;
|
||||
}
|
||||
|
||||
|
||||
function convertToHHMMSS(timeInMS){
|
||||
var time = parseInt(timeInMS);
|
||||
|
@ -103,6 +109,8 @@ function updateProgressBarValue(){
|
|||
function temp(){
|
||||
currentSong[0] = nextSongs[0];
|
||||
updatePlaylist();
|
||||
|
||||
songEndFunc();
|
||||
}
|
||||
|
||||
function updatePlaylist(){
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue