CC-3174 : showbuilder
only updating the timeline view if it is needed.
This commit is contained in:
parent
a4d07b3060
commit
e9627bca07
7 changed files with 160 additions and 12 deletions
|
@ -10,6 +10,7 @@ class ShowbuilderController extends Zend_Controller_Action
|
||||||
->addActionContext('schedule-add', 'json')
|
->addActionContext('schedule-add', 'json')
|
||||||
->addActionContext('schedule-remove', 'json')
|
->addActionContext('schedule-remove', 'json')
|
||||||
->addActionContext('builder-dialog', 'json')
|
->addActionContext('builder-dialog', 'json')
|
||||||
|
->addActionContext('check-builder-feed', 'json')
|
||||||
->addActionContext('builder-feed', 'json')
|
->addActionContext('builder-feed', 'json')
|
||||||
->initContext();
|
->initContext();
|
||||||
}
|
}
|
||||||
|
@ -19,7 +20,7 @@ class ShowbuilderController extends Zend_Controller_Action
|
||||||
$this->_helper->layout->setLayout('builder');
|
$this->_helper->layout->setLayout('builder');
|
||||||
|
|
||||||
$this->view->headScript()->appendFile($this->view->baseUrl('/js/airtime/library/events/library_showbuilder.js'),'text/javascript');
|
$this->view->headScript()->appendFile($this->view->baseUrl('/js/airtime/library/events/library_showbuilder.js'),'text/javascript');
|
||||||
|
|
||||||
$this->_helper->actionStack('library', 'library');
|
$this->_helper->actionStack('library', 'library');
|
||||||
$this->_helper->actionStack('builder', 'showbuilder');
|
$this->_helper->actionStack('builder', 'showbuilder');
|
||||||
}
|
}
|
||||||
|
@ -88,6 +89,37 @@ class ShowbuilderController extends Zend_Controller_Action
|
||||||
$this->view->dialog = $this->view->render('showbuilder/builderDialog.phtml');
|
$this->view->dialog = $this->view->render('showbuilder/builderDialog.phtml');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function checkBuilderFeedAction() {
|
||||||
|
|
||||||
|
$request = $this->getRequest();
|
||||||
|
$current_time = time();
|
||||||
|
|
||||||
|
$starts_epoch = $request->getParam("start", $current_time);
|
||||||
|
//default ends is 24 hours after starts.
|
||||||
|
$ends_epoch = $request->getParam("end", $current_time + (60*60*24));
|
||||||
|
$show_filter = intval($request->getParam("showFilter", 0));
|
||||||
|
$my_shows = intval($request->getParam("myShows", 0));
|
||||||
|
$timestamp = intval($request->getParam("timestamp", -1));
|
||||||
|
|
||||||
|
$startsDT = DateTime::createFromFormat("U", $starts_epoch, new DateTimeZone("UTC"));
|
||||||
|
$endsDT = DateTime::createFromFormat("U", $ends_epoch, new DateTimeZone("UTC"));
|
||||||
|
|
||||||
|
Logging::log("showbuilder starts {$startsDT->format("Y-m-d H:i:s")}");
|
||||||
|
Logging::log("showbuilder ends {$endsDT->format("Y-m-d H:i:s")}");
|
||||||
|
|
||||||
|
$opts = array("myShows" => $my_shows, "showFilter" => $show_filter);
|
||||||
|
$showBuilder = new Application_Model_ShowBuilder($startsDT, $endsDT, $opts);
|
||||||
|
|
||||||
|
//only send the schedule back if updates have been made.
|
||||||
|
// -1 default will always call the schedule to be sent back if no timestamp is defined.
|
||||||
|
if ($showBuilder->hasBeenUpdatedSince($timestamp)) {
|
||||||
|
$this->view->update = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$this->view->update = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function builderFeedAction() {
|
public function builderFeedAction() {
|
||||||
|
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
|
@ -98,6 +130,7 @@ class ShowbuilderController extends Zend_Controller_Action
|
||||||
$ends_epoch = $request->getParam("end", $current_time + (60*60*24));
|
$ends_epoch = $request->getParam("end", $current_time + (60*60*24));
|
||||||
$show_filter = intval($request->getParam("showFilter", 0));
|
$show_filter = intval($request->getParam("showFilter", 0));
|
||||||
$my_shows = intval($request->getParam("myShows", 0));
|
$my_shows = intval($request->getParam("myShows", 0));
|
||||||
|
$timestamp = intval($request->getParam("timestamp", -1));
|
||||||
|
|
||||||
$startsDT = DateTime::createFromFormat("U", $starts_epoch, new DateTimeZone("UTC"));
|
$startsDT = DateTime::createFromFormat("U", $starts_epoch, new DateTimeZone("UTC"));
|
||||||
$endsDT = DateTime::createFromFormat("U", $ends_epoch, new DateTimeZone("UTC"));
|
$endsDT = DateTime::createFromFormat("U", $ends_epoch, new DateTimeZone("UTC"));
|
||||||
|
@ -109,6 +142,7 @@ class ShowbuilderController extends Zend_Controller_Action
|
||||||
$showBuilder = new Application_Model_ShowBuilder($startsDT, $endsDT, $opts);
|
$showBuilder = new Application_Model_ShowBuilder($startsDT, $endsDT, $opts);
|
||||||
|
|
||||||
$this->view->schedule = $showBuilder->GetItems();
|
$this->view->schedule = $showBuilder->GetItems();
|
||||||
|
$this->view->timestamp = $current_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function scheduleAddAction() {
|
public function scheduleAddAction() {
|
||||||
|
|
|
@ -11,6 +11,12 @@ class Application_Form_ShowBuilder extends Zend_Form_SubForm
|
||||||
array('ViewScript', array('viewScript' => 'form/showbuilder.phtml'))
|
array('ViewScript', array('viewScript' => 'form/showbuilder.phtml'))
|
||||||
));
|
));
|
||||||
|
|
||||||
|
//set value to -1 originally to ensure we grab the schedule on first call.
|
||||||
|
$timestamp = new Zend_Form_Element_Hidden('sb_timestamp');
|
||||||
|
$timestamp->setValue(-1)
|
||||||
|
->setDecorators(array('ViewHelper'));
|
||||||
|
$this->addElement($timestamp);
|
||||||
|
|
||||||
// Add start date element
|
// Add start date element
|
||||||
$startDate = new Zend_Form_Element_Text('sb_date_start');
|
$startDate = new Zend_Form_Element_Text('sb_date_start');
|
||||||
$startDate->class = 'input_text';
|
$startDate->class = 'input_text';
|
||||||
|
|
|
@ -1448,7 +1448,8 @@ class Application_Model_Show {
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = "SELECT starts, ends, record, rebroadcast, instance_id, show_id, name,
|
$sql = "SELECT starts, ends, record, rebroadcast, instance_id, show_id, name,
|
||||||
color, background_color, file_id, cc_show_instances.id AS instance_id
|
color, background_color, file_id, cc_show_instances.id AS instance_id,
|
||||||
|
last_scheduled
|
||||||
FROM cc_show_instances
|
FROM cc_show_instances
|
||||||
LEFT JOIN cc_show ON cc_show.id = cc_show_instances.show_id
|
LEFT JOIN cc_show ON cc_show.id = cc_show_instances.show_id
|
||||||
WHERE cc_show_instances.modified_instance = FALSE";
|
WHERE cc_show_instances.modified_instance = FALSE";
|
||||||
|
@ -1479,6 +1480,9 @@ class Application_Model_Show {
|
||||||
$sql = $sql." AND ({$exclude})";
|
$sql = $sql." AND ({$exclude})";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Logging::log("getShows");
|
||||||
|
Logging::log($sql);
|
||||||
|
|
||||||
return $CC_DBC->GetAll($sql);
|
return $CC_DBC->GetAll($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,12 @@ require_once 'formatters/TimeFilledFormatter.php';
|
||||||
class Application_Model_ShowBuilder {
|
class Application_Model_ShowBuilder {
|
||||||
|
|
||||||
private $timezone;
|
private $timezone;
|
||||||
|
|
||||||
|
//in UTC timezone
|
||||||
private $startDT;
|
private $startDT;
|
||||||
|
//in UTC timezone
|
||||||
private $endDT;
|
private $endDT;
|
||||||
|
|
||||||
private $user;
|
private $user;
|
||||||
private $opts;
|
private $opts;
|
||||||
|
|
||||||
|
@ -59,12 +63,12 @@ class Application_Model_ShowBuilder {
|
||||||
|
|
||||||
$showStartDT = new DateTime($p_item["si_starts"], new DateTimeZone("UTC"));
|
$showStartDT = new DateTime($p_item["si_starts"], new DateTimeZone("UTC"));
|
||||||
$schedStartDT = new DateTime($p_item["sched_starts"], new DateTimeZone("UTC"));
|
$schedStartDT = new DateTime($p_item["sched_starts"], new DateTimeZone("UTC"));
|
||||||
|
|
||||||
$showStartEpoch = intval($showStartDT->format('U'));
|
$showStartEpoch = intval($showStartDT->format('U'));
|
||||||
$schedStartEpoch = intval($schedStartDT->format('U'));
|
$schedStartEpoch = intval($schedStartDT->format('U'));
|
||||||
|
|
||||||
//can only schedule the show if item hasn't started and you are allowed.
|
//can only schedule the show if item hasn't started and you are allowed.
|
||||||
if ($this->epoch_now < max($showStartEpoch, $schedStartEpoch)
|
if ($this->epoch_now < max($showStartEpoch, $schedStartEpoch)
|
||||||
&& $this->user->canSchedule($p_item["show_id"]) == true) {
|
&& $this->user->canSchedule($p_item["show_id"]) == true) {
|
||||||
$row["allowed"] = true;
|
$row["allowed"] = true;
|
||||||
}
|
}
|
||||||
|
@ -89,7 +93,7 @@ class Application_Model_ShowBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
private function isCurrent($p_epochItemStart, $p_epochItemEnd, &$row) {
|
private function isCurrent($p_epochItemStart, $p_epochItemEnd, &$row) {
|
||||||
|
|
||||||
if ($this->epoch_now >= $p_epochItemStart && $this->epoch_now < $p_epochItemEnd) {
|
if ($this->epoch_now >= $p_epochItemStart && $this->epoch_now < $p_epochItemEnd) {
|
||||||
$row["current"] = true;
|
$row["current"] = true;
|
||||||
//how many seconds the view should wait to redraw itself.
|
//how many seconds the view should wait to redraw itself.
|
||||||
|
@ -194,6 +198,39 @@ class Application_Model_ShowBuilder {
|
||||||
return $row;
|
return $row;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @param int $timestamp Unix timestamp in seconds.
|
||||||
|
*
|
||||||
|
* @return boolean whether the schedule in the show builder's range has been updated.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function hasBeenUpdatedSince($timestamp) {
|
||||||
|
$outdated = false;
|
||||||
|
|
||||||
|
Logging::log("checking if show builder has been updated since {$timestamp}");
|
||||||
|
|
||||||
|
$shows = Application_Model_Show::getShows($this->startDT, $this->endDT);
|
||||||
|
|
||||||
|
foreach ($shows as $show) {
|
||||||
|
|
||||||
|
if (isset($show["last_scheduled"])) {
|
||||||
|
$dt = new DateTime($show["last_scheduled"], new DateTimeZone("UTC"));
|
||||||
|
|
||||||
|
//check if any of the shows have a more recent timestamp.
|
||||||
|
if ($timestamp < intval($dt->format("U"))) {
|
||||||
|
$outdated = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count($shows) == 0) {
|
||||||
|
$outdated = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $outdated;
|
||||||
|
}
|
||||||
|
|
||||||
public function GetItems() {
|
public function GetItems() {
|
||||||
|
|
||||||
$current_id = -1;
|
$current_id = -1;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<div class="sb-timerange">
|
<div class="sb-timerange">
|
||||||
|
<?php echo $this->element->getElement('sb_timestamp') ?>
|
||||||
<?php echo $this->element->getElement('sb_date_start') ?>
|
<?php echo $this->element->getElement('sb_date_start') ?>
|
||||||
<?php echo $this->element->getElement('sb_time_start') ?>
|
<?php echo $this->element->getElement('sb_time_start') ?>
|
||||||
<?php echo $this->element->getElement('sb_date_end') ?>
|
<?php echo $this->element->getElement('sb_date_end') ?>
|
||||||
|
|
|
@ -14,6 +14,32 @@ var AIRTIME = (function(AIRTIME){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mod.resetTimestamp = function() {
|
||||||
|
var timestamp = $("#sb_timestamp");
|
||||||
|
//reset timestamp value since input values could have changed.
|
||||||
|
timestamp.val(-1);
|
||||||
|
};
|
||||||
|
|
||||||
|
mod.setTimestamp = function(timestamp) {
|
||||||
|
$("#sb_timestamp").val(timestamp);
|
||||||
|
};
|
||||||
|
|
||||||
|
mod.getTimestamp = function() {
|
||||||
|
var timestamp = $("#sb_timestamp"),
|
||||||
|
val;
|
||||||
|
|
||||||
|
//if the timestamp field is on the page return it, or give the default of -1
|
||||||
|
//to ensure a page refresh.
|
||||||
|
if (timestamp.length === 1) {
|
||||||
|
val = timestamp.val();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
val = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return val;
|
||||||
|
};
|
||||||
|
|
||||||
mod.fnAdd = function(aMediaIds, aSchedIds) {
|
mod.fnAdd = function(aMediaIds, aSchedIds) {
|
||||||
var oLibTT = TableTools.fnGetInstance('library_display');
|
var oLibTT = TableTools.fnGetInstance('library_display');
|
||||||
|
|
||||||
|
@ -47,6 +73,8 @@ var AIRTIME = (function(AIRTIME){
|
||||||
};
|
};
|
||||||
|
|
||||||
fnServerData = function ( sSource, aoData, fnCallback ) {
|
fnServerData = function ( sSource, aoData, fnCallback ) {
|
||||||
|
|
||||||
|
aoData.push( { name: "timestamp", value: AIRTIME.showbuilder.getTimestamp()} );
|
||||||
aoData.push( { name: "format", value: "json"} );
|
aoData.push( { name: "format", value: "json"} );
|
||||||
|
|
||||||
if (fnServerData.hasOwnProperty("start")) {
|
if (fnServerData.hasOwnProperty("start")) {
|
||||||
|
@ -65,7 +93,10 @@ var AIRTIME = (function(AIRTIME){
|
||||||
"type": "GET",
|
"type": "GET",
|
||||||
"url": sSource,
|
"url": sSource,
|
||||||
"data": aoData,
|
"data": aoData,
|
||||||
"success": fnCallback
|
"success": function(json) {
|
||||||
|
AIRTIME.showbuilder.setTimestamp(json.timestamp);
|
||||||
|
fnCallback(json);
|
||||||
|
}
|
||||||
} );
|
} );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -302,6 +333,7 @@ var AIRTIME = (function(AIRTIME){
|
||||||
aData = tr.data("aData");
|
aData = tr.data("aData");
|
||||||
|
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
|
AIRTIME.showbuilder.resetTimestamp();
|
||||||
oTable.fnDraw();
|
oTable.fnDraw();
|
||||||
}, aData.refresh * 1000); //need refresh in milliseconds
|
}, aData.refresh * 1000); //need refresh in milliseconds
|
||||||
}
|
}
|
||||||
|
@ -311,7 +343,9 @@ var AIRTIME = (function(AIRTIME){
|
||||||
},
|
},
|
||||||
//remove any selected nodes before the draw.
|
//remove any selected nodes before the draw.
|
||||||
"fnPreDrawCallback": function( oSettings ) {
|
"fnPreDrawCallback": function( oSettings ) {
|
||||||
var oTT = TableTools.fnGetInstance('show_builder_table');
|
var oTT;
|
||||||
|
|
||||||
|
oTT = TableTools.fnGetInstance('show_builder_table');
|
||||||
oTT.fnSelectNone();
|
oTT.fnSelectNone();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -109,6 +109,9 @@ $(document).ready(function(){
|
||||||
op,
|
op,
|
||||||
oTable = $('#show_builder_table').dataTable();
|
oTable = $('#show_builder_table').dataTable();
|
||||||
|
|
||||||
|
//reset timestamp value since input values could have changed.
|
||||||
|
AIRTIME.showbuilder.resetTimestamp();
|
||||||
|
|
||||||
oRange = fnGetScheduleRange();
|
oRange = fnGetScheduleRange();
|
||||||
|
|
||||||
fn = oTable.fnSettings().fnServerData;
|
fn = oTable.fnSettings().fnServerData;
|
||||||
|
@ -136,6 +139,9 @@ $(document).ready(function(){
|
||||||
|
|
||||||
if ($button.hasClass("sb-edit")) {
|
if ($button.hasClass("sb-edit")) {
|
||||||
|
|
||||||
|
//reset timestamp to redraw the cursors.
|
||||||
|
AIRTIME.showbuilder.resetTimestamp();
|
||||||
|
|
||||||
$lib.show();
|
$lib.show();
|
||||||
$lib.width(Math.floor(screenWidth * 0.5));
|
$lib.width(Math.floor(screenWidth * 0.5));
|
||||||
$builder.width(Math.floor(screenWidth * 0.5));
|
$builder.width(Math.floor(screenWidth * 0.5));
|
||||||
|
@ -154,8 +160,7 @@ $(document).ready(function(){
|
||||||
$button.val("Add Files");
|
$button.val("Add Files");
|
||||||
}
|
}
|
||||||
|
|
||||||
oTable.fnDraw();
|
oTable.fnDraw();
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
oRange = fnGetScheduleRange();
|
oRange = fnGetScheduleRange();
|
||||||
|
@ -165,8 +170,35 @@ $(document).ready(function(){
|
||||||
AIRTIME.library.libraryInit();
|
AIRTIME.library.libraryInit();
|
||||||
AIRTIME.showbuilder.builderDataTable();
|
AIRTIME.showbuilder.builderDataTable();
|
||||||
|
|
||||||
|
//check if the timeline viewed needs updating.
|
||||||
setInterval(function(){
|
setInterval(function(){
|
||||||
var oTable = $('#show_builder_table').dataTable();
|
var data = {},
|
||||||
oTable.fnDraw();
|
oTable = $('#show_builder_table').dataTable(),
|
||||||
}, 20 * 1000); //need refresh in milliseconds
|
fn = oTable.fnSettings().fnServerData,
|
||||||
|
start = fn.start,
|
||||||
|
end = fn.end;
|
||||||
|
|
||||||
|
data["format"] = "json";
|
||||||
|
data["start"] = start;
|
||||||
|
data["end"] = end;
|
||||||
|
data["timestamp"] = AIRTIME.showbuilder.getTimestamp();
|
||||||
|
|
||||||
|
if (fn.hasOwnProperty("ops")) {
|
||||||
|
data["myShows"] = fn.ops.myShows;
|
||||||
|
data["showFilter"] = fn.ops.showFilter;
|
||||||
|
}
|
||||||
|
|
||||||
|
$.ajax( {
|
||||||
|
"dataType": "json",
|
||||||
|
"type": "GET",
|
||||||
|
"url": "/showbuilder/check-builder-feed",
|
||||||
|
"data": data,
|
||||||
|
"success": function(json) {
|
||||||
|
if (json.update === true) {
|
||||||
|
oTable.fnDraw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
|
||||||
|
}, 5 * 1000); //need refresh in milliseconds
|
||||||
});
|
});
|
Loading…
Add table
Add a link
Reference in a new issue