From 8404fa41457a3e98e50a2bedd9b1684513d1fc27 Mon Sep 17 00:00:00 2001 From: mkonecny Date: Wed, 29 Dec 2010 17:01:28 -0500 Subject: [PATCH 1/4] -synchronize - broken --- .../controllers/ScheduleController.php | 2 +- .../scripts/schedule/get-scheduler-time.phtml | 106 +------------ public/js/playlist/playlist.js | 142 ++++++++++++++++++ 3 files changed, 146 insertions(+), 104 deletions(-) create mode 100644 public/js/playlist/playlist.js diff --git a/application/controllers/ScheduleController.php b/application/controllers/ScheduleController.php index a1ee638b4..6cc2b0e49 100644 --- a/application/controllers/ScheduleController.php +++ b/application/controllers/ScheduleController.php @@ -177,7 +177,7 @@ class ScheduleController extends Zend_Controller_Action public function getSchedulerTimeAction() { - $this->view->headScript()->appendFile('/js/progressbar/jquery.progressbar.min.js','text/javascript'); + $this->view->headScript()->appendFile('/js/playlist/playlist.js','text/javascript'); } public function getCurrentPlaylistAction() diff --git a/application/views/scripts/schedule/get-scheduler-time.phtml b/application/views/scripts/schedule/get-scheduler-time.phtml index 03e1d2a0f..48f23dee4 100644 --- a/application/views/scripts/schedule/get-scheduler-time.phtml +++ b/application/views/scripts/schedule/get-scheduler-time.phtml @@ -1,110 +1,10 @@
+ - -
-0% - +
diff --git a/public/js/playlist/playlist.js b/public/js/playlist/playlist.js new file mode 100644 index 000000000..b4ea360e4 --- /dev/null +++ b/public/js/playlist/playlist.js @@ -0,0 +1,142 @@ +(function($) { + // jQuery plugin definition + $.fn.playlistViewer = function(params) { + // merge default and user parameters + params = $.extend( {minlength: 0, maxlength: 99999}, params); + + + var $t; + + // traverse all nodes + return this.each(function() { + // express a single node as a jQuery object + $t = $(this); + + 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 = 0; + var msec = 0; + if (s.length >= 20){ + sec = s.substring(17, 19); + msec = s.substring(20); + } else { + sec = s.substring(17); + } + + return Date.UTC(year, month, day, hour, minute, sec, msec); + } + + var estimatedSchedulePosixTime = -1; + var schedulePosixTime; + + var previousSongs; + var currentSong; + var nextSongs; + + function secondsTimer(){ + estimatedSchedulePosixTime += 1000; + updateProgressBarValue(); + } + + function updateProgressBarValue(){ + alert(estimatedSchedulePosixTime); + if (estimatedSchedulePosixTime != -1){ + if (currentSong.length > 0){ + var percentDone = (estimatedSchedulePosixTime - currentSong[0].songStartPosixTime)/currentSong[0].songLengthMs*100; + if (percentDone <= 100){ + //$('#spaceused1').progressBar(percentDone); + } else { + if (nextSongs.length > 0){ + currentSong[0] = nextSongs.shift(); + } else { + currentSong = new Array(); + } + //$('#spaceused1').progressBar(0); + estimatedSchedulePosixTime = schedulePosixTime; + } + } + 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){ + schedulePosixTime = convertDateToPosixTime(obj.schedulerTime); + + if (estimatedSchedulePosixTime == -1) + estimatedSchedulePosixTime = schedulePosixTime; + + previousSongs = obj.previous; + currentSong = obj.current; + nextSongs = obj.next; + + calcAdditionalData(previousSongs); + calcAdditionalData(currentSong); + calcAdditionalData(nextSongs); + + //updatePlaylist(); + //updateProgressBarValue(); + } + + function getScheduleFromServer(){ + $.ajax({ url: "http://localhost/Schedule/get-current-playlist/format/json", dataType:"json", success:function(data){ + parseItems(data.entries); + }}); + setTimeout(getScheduleFromServer, 5000); + } + + }; +})(jQuery); From ffa508de34cd9f682fb7bafceb5daf74da54bf97 Mon Sep 17 00:00:00 2001 From: martin Date: Thu, 30 Dec 2010 09:41:52 -0500 Subject: [PATCH 2/4] -synchronize --- .../controllers/ScheduleController.php | 1 + .../scripts/schedule/get-scheduler-time.phtml | 2 +- public/js/playlist/playlist.js | 285 +++++++++--------- 3 files changed, 148 insertions(+), 140 deletions(-) diff --git a/application/controllers/ScheduleController.php b/application/controllers/ScheduleController.php index 6cc2b0e49..0121038cb 100644 --- a/application/controllers/ScheduleController.php +++ b/application/controllers/ScheduleController.php @@ -178,6 +178,7 @@ class ScheduleController extends Zend_Controller_Action public function getSchedulerTimeAction() { $this->view->headScript()->appendFile('/js/playlist/playlist.js','text/javascript'); + $this->view->headScript()->appendFile('/js/progressbar/jquery.progressbar.min.js','text/javascript'); } public function getCurrentPlaylistAction() diff --git a/application/views/scripts/schedule/get-scheduler-time.phtml b/application/views/scripts/schedule/get-scheduler-time.phtml index 48f23dee4..4152f4c54 100644 --- a/application/views/scripts/schedule/get-scheduler-time.phtml +++ b/application/views/scripts/schedule/get-scheduler-time.phtml @@ -6,5 +6,5 @@ });
- +
diff --git a/public/js/playlist/playlist.js b/public/js/playlist/playlist.js index b4ea360e4..4983117e5 100644 --- a/public/js/playlist/playlist.js +++ b/public/js/playlist/playlist.js @@ -1,142 +1,149 @@ -(function($) { - // jQuery plugin definition - $.fn.playlistViewer = function(params) { - // merge default and user parameters - params = $.extend( {minlength: 0, maxlength: 99999}, params); +(function($) { + // jQuery plugin definition + $.fn.playlistViewer = function(params) { + var cc = this; + cc.estimatedSchedulePosixTime = -1; + cc.schedulePosixTime; - - var $t; - - // traverse all nodes - return this.each(function() { - // express a single node as a jQuery object - $t = $(this); - - 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 = 0; - var msec = 0; - if (s.length >= 20){ - sec = s.substring(17, 19); - msec = s.substring(20); - } else { - sec = s.substring(17); - } - - return Date.UTC(year, month, day, hour, minute, sec, msec); - } - - var estimatedSchedulePosixTime = -1; - var schedulePosixTime; - - var previousSongs; - var currentSong; - var nextSongs; - - function secondsTimer(){ - estimatedSchedulePosixTime += 1000; - updateProgressBarValue(); - } - - function updateProgressBarValue(){ - alert(estimatedSchedulePosixTime); - if (estimatedSchedulePosixTime != -1){ - if (currentSong.length > 0){ - var percentDone = (estimatedSchedulePosixTime - currentSong[0].songStartPosixTime)/currentSong[0].songLengthMs*100; - if (percentDone <= 100){ - //$('#spaceused1').progressBar(percentDone); - } else { - if (nextSongs.length > 0){ - currentSong[0] = nextSongs.shift(); - } else { - currentSong = new Array(); - } - //$('#spaceused1').progressBar(0); - estimatedSchedulePosixTime = schedulePosixTime; - } - } - 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){ - schedulePosixTime = convertDateToPosixTime(obj.schedulerTime); + cc.previousSongs; + cc.currentSong; + cc.nextSongs; - if (estimatedSchedulePosixTime == -1) - estimatedSchedulePosixTime = schedulePosixTime; - - previousSongs = obj.previous; - currentSong = obj.current; - nextSongs = obj.next; - - calcAdditionalData(previousSongs); - calcAdditionalData(currentSong); - calcAdditionalData(nextSongs); - - //updatePlaylist(); - //updateProgressBarValue(); - } + cc.currentElem; - function getScheduleFromServer(){ - $.ajax({ url: "http://localhost/Schedule/get-current-playlist/format/json", dataType:"json", success:function(data){ - parseItems(data.entries); - }}); - setTimeout(getScheduleFromServer, 5000); - } - - }; -})(jQuery); + // 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 currDiv = document.createElement('div'); + currDiv.setAttribute("id", "current"); + $(cc.currentElem).append(currDiv); + + var nextDiv = document.createElement('div'); + nextDiv.setAttribute("id", "next"); + $(cc.currentElem).append(nextDiv); + + $('#spaceused1').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 = 0; + var msec = 0; + if (s.length >= 20){ + sec = s.substring(17, 19); + msec = s.substring(20); + } else { + sec = s.substring(17); + } + + 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){ + $('#spaceused1').progressBar(percentDone); + } else { + if (nextSongs.length > 0){ + cc.currentSong[0] = cc.nextSongs.shift(); + } else { + cc.currentSong = new Array(); + } + $('#spaceused1').progressBar(0); + cc.estimatedSchedulePosixTime = cc.schedulePosixTime; + } + } + 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); From 4ac347cb65e11090e7d9cdce889b4e1cce1e8591 Mon Sep 17 00:00:00 2001 From: mkonecny Date: Thu, 30 Dec 2010 11:42:31 -0500 Subject: [PATCH 3/4] -currently playing + playlist now available (as a Jquery plugin!). Next step is to improve UI. --- application/models/Schedule.php | 4 +-- .../scripts/schedule/get-scheduler-time.phtml | 1 - public/js/playlist/playlist.js | 32 +++++++++++-------- 3 files changed, 21 insertions(+), 16 deletions(-) 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 index 4152f4c54..49ba61b1c 100644 --- a/application/views/scripts/schedule/get-scheduler-time.phtml +++ b/application/views/scripts/schedule/get-scheduler-time.phtml @@ -6,5 +6,4 @@ });
-
diff --git a/public/js/playlist/playlist.js b/public/js/playlist/playlist.js index 4983117e5..064864205 100644 --- a/public/js/playlist/playlist.js +++ b/public/js/playlist/playlist.js @@ -20,15 +20,23 @@ 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"); - $(cc.currentElem).append(currDiv); + $(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); - $('#spaceused1').progressBar(0); + $('#progressbar').progressBar(0); getScheduleFromServer(); updateProgressBarValue(); @@ -40,13 +48,10 @@ var day = s.substring(8, 10); var hour = s.substring(11, 13); var minute = s.substring(14, 16); - var sec = 0; + var sec = s.substring(17, 19); var msec = 0; if (s.length >= 20){ - sec = s.substring(17, 19); msec = s.substring(20); - } else { - sec = s.substring(17); } return Date.UTC(year, month, day, hour, minute, sec, msec); @@ -62,17 +67,21 @@ if (cc.currentSong.length > 0){ var percentDone = (cc.estimatedSchedulePosixTime - cc.currentSong[0].songStartPosixTime)/cc.currentSong[0].songLengthMs*100; if (percentDone <= 100){ - $('#spaceused1').progressBar(percentDone); + $('#progressbar').progressBar(percentDone); } else { - if (nextSongs.length > 0){ + if (cc.nextSongs.length > 0){ cc.currentSong[0] = cc.nextSongs.shift(); } else { cc.currentSong = new Array(); } - $('#spaceused1').progressBar(0); + $('#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); @@ -93,19 +102,16 @@ var divElem = document.createElement('div'); divElem.innerHTML = createPlaylistElementString(cc.previousSongs[i]); $('#previous').append(divElem); - //cc.currentElem.html(createPlaylistElementString(previousSongs[i])); } for (var i=0; i Date: Thu, 30 Dec 2010 12:02:02 -0500 Subject: [PATCH 4/4] -renamed some files to better represent their function --- application/configs/navigation.php | 2 +- application/controllers/ScheduleController.php | 2 +- .../schedule/{get-scheduler-time.phtml => view-playlist.phtml} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename application/views/scripts/schedule/{get-scheduler-time.phtml => view-playlist.phtml} (100%) 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 0121038cb..651efb191 100644 --- a/application/controllers/ScheduleController.php +++ b/application/controllers/ScheduleController.php @@ -175,7 +175,7 @@ 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/views/scripts/schedule/get-scheduler-time.phtml b/application/views/scripts/schedule/view-playlist.phtml similarity index 100% rename from application/views/scripts/schedule/get-scheduler-time.phtml rename to application/views/scripts/schedule/view-playlist.phtml