diff --git a/application/configs/navigation.php b/application/configs/navigation.php
index 42ef8aab9..a451b8340 100644
--- a/application/configs/navigation.php
+++ b/application/configs/navigation.php
@@ -74,7 +74,7 @@ $pages = array(
'label' => 'Now Playing',
'module' => 'default',
'controller' => 'Schedule',
- 'action' => 'get-scheduler-time'
+ 'action' => 'view-playlist'
),
array(
'label' => 'Schedule',
diff --git a/application/controllers/ScheduleController.php b/application/controllers/ScheduleController.php
index a1ee638b4..651efb191 100644
--- a/application/controllers/ScheduleController.php
+++ b/application/controllers/ScheduleController.php
@@ -175,8 +175,9 @@ class ScheduleController extends Zend_Controller_Action
}
}
- public function getSchedulerTimeAction()
+ public function viewPlaylistAction()
{
+ $this->view->headScript()->appendFile('/js/playlist/playlist.js','text/javascript');
$this->view->headScript()->appendFile('/js/progressbar/jquery.progressbar.min.js','text/javascript');
}
diff --git a/application/models/Schedule.php b/application/models/Schedule.php
index 5daa2c513..0ccefd7f6 100644
--- a/application/models/Schedule.php
+++ b/application/models/Schedule.php
@@ -452,7 +452,7 @@ class Schedule {
$sql = "SELECT * FROM $CC_CONFIG[scheduleTable], $CC_CONFIG[filesTable]"
." WHERE ($CC_CONFIG[scheduleTable].ends < TIMESTAMP '$timeNow')"
." AND ($CC_CONFIG[scheduleTable].file_id = $CC_CONFIG[filesTable].id)"
- ." ORDER BY $CC_CONFIG[scheduleTable].id"
+ ." ORDER BY $CC_CONFIG[scheduleTable].starts DESC"
." LIMIT $prevCount";
$rows = $CC_DBC->GetAll($sql);
return $rows;
@@ -474,7 +474,7 @@ class Schedule {
$sql = "SELECT * FROM $CC_CONFIG[scheduleTable], $CC_CONFIG[filesTable]"
." WHERE ($CC_CONFIG[scheduleTable].starts > TIMESTAMP '$timeNow')"
." AND ($CC_CONFIG[scheduleTable].file_id = $CC_CONFIG[filesTable].id)"
- ." ORDER BY $CC_CONFIG[scheduleTable].id"
+ ." ORDER BY $CC_CONFIG[scheduleTable].starts"
." LIMIT $nextCount";
$rows = $CC_DBC->GetAll($sql);
return $rows;
diff --git a/application/views/scripts/schedule/get-scheduler-time.phtml b/application/views/scripts/schedule/get-scheduler-time.phtml
deleted file mode 100644
index 03e1d2a0f..000000000
--- a/application/views/scripts/schedule/get-scheduler-time.phtml
+++ /dev/null
@@ -1,110 +0,0 @@
-
diff --git a/application/views/scripts/schedule/view-playlist.phtml b/application/views/scripts/schedule/view-playlist.phtml
new file mode 100644
index 000000000..49ba61b1c
--- /dev/null
+++ b/application/views/scripts/schedule/view-playlist.phtml
@@ -0,0 +1,9 @@
+
diff --git a/public/js/playlist/playlist.js b/public/js/playlist/playlist.js
new file mode 100644
index 000000000..064864205
--- /dev/null
+++ b/public/js/playlist/playlist.js
@@ -0,0 +1,155 @@
+(function($) {
+ // jQuery plugin definition
+ $.fn.playlistViewer = function(params) {
+ var cc = this;
+ cc.estimatedSchedulePosixTime = -1;
+ cc.schedulePosixTime;
+
+ cc.previousSongs;
+ cc.currentSong;
+ cc.nextSongs;
+
+ cc.currentElem;
+
+ // traverse all nodes
+ return this.each(function() {
+ // express a single node as a jQuery object
+ cc.currentElem = $(this);
+
+ var prevDiv = document.createElement('div');
+ prevDiv.setAttribute("id", "previous");
+ $(cc.currentElem).append(prevDiv);
+
+ var currParentDiv = document.createElement('div');
+ currParentDiv.setAttribute("style", "background-color:#bbbbbb;");
+ $(cc.currentElem).append(currParentDiv);
+
+ var currDiv = document.createElement('div');
+ currDiv.setAttribute("id", "current");
+ $(currParentDiv).append(currDiv);
+
+ var nextDiv = document.createElement('div');
+ nextDiv.setAttribute("id", "progressbar");
+ $(currParentDiv).append(nextDiv);
+
+ var nextDiv = document.createElement('div');
+ nextDiv.setAttribute("id", "next");
+ $(cc.currentElem).append(nextDiv);
+
+ $('#progressbar').progressBar(0);
+
+ getScheduleFromServer();
+ updateProgressBarValue();
+ });
+
+ function convertDateToPosixTime(s){
+ var year = s.substring(0, 4);
+ var month = s.substring(5, 7);
+ var day = s.substring(8, 10);
+ var hour = s.substring(11, 13);
+ var minute = s.substring(14, 16);
+ var sec = s.substring(17, 19);
+ var msec = 0;
+ if (s.length >= 20){
+ msec = s.substring(20);
+ }
+
+ return Date.UTC(year, month, day, hour, minute, sec, msec);
+ }
+
+ function secondsTimer(){
+ cc.estimatedSchedulePosixTime += 1000;
+ updateProgressBarValue();
+ }
+
+ function updateProgressBarValue(){
+ if (cc.estimatedSchedulePosixTime != -1){
+ if (cc.currentSong.length > 0){
+ var percentDone = (cc.estimatedSchedulePosixTime - cc.currentSong[0].songStartPosixTime)/cc.currentSong[0].songLengthMs*100;
+ if (percentDone <= 100){
+ $('#progressbar').progressBar(percentDone);
+ } else {
+ if (cc.nextSongs.length > 0){
+ cc.currentSong[0] = cc.nextSongs.shift();
+ } else {
+ cc.currentSong = new Array();
+ }
+ $('#progressbar').progressBar(0);
+ //at the end of each song we are updating the
+ //server time we have been estimating client-side
+ //with the real server time.
+ cc.estimatedSchedulePosixTime = cc.schedulePosixTime;
+ }
+ } else
+ $('#progressbar').progressBar(0);
+ updatePlaylist();
+ }
+ setTimeout(secondsTimer, 1000);
+ }
+
+ function createPlaylistElementString(song){
+ return "Start time: " + song.starts + "
" +
+ "End time: " + song.ends + "
" +
+ "Clip length: " + song.clip_length + "
" +
+ "Name: " + song.name + "
";
+ }
+
+ function updatePlaylist(){
+ $('#previous').empty();
+ $('#current').empty();
+ $('#next').empty();
+ for (var i=0; i 0){
+ var nextItem = obj.next[0];
+ }
+ }
+
+ function parseItems(obj){
+ cc.schedulePosixTime = convertDateToPosixTime(obj.schedulerTime);
+
+ if (cc.estimatedSchedulePosixTime == -1)
+ cc.estimatedSchedulePosixTime = cc.schedulePosixTime;
+
+ cc.previousSongs = obj.previous;
+ cc.currentSong = obj.current;
+ cc.nextSongs = obj.next;
+
+ calcAdditionalData(cc.previousSongs);
+ calcAdditionalData(cc.currentSong);
+ calcAdditionalData(cc.nextSongs);
+ }
+
+ function getScheduleFromServer(){
+ $.ajax({ url: "http://localhost/Schedule/get-current-playlist/format/json", dataType:"json", success:function(data){
+ parseItems(data.entries);
+ }});
+ setTimeout(getScheduleFromServer, 5000);
+ }
+
+ };
+})(jQuery);