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-remove', 'json')
|
||||
->addActionContext('builder-dialog', 'json')
|
||||
->addActionContext('check-builder-feed', 'json')
|
||||
->addActionContext('builder-feed', 'json')
|
||||
->initContext();
|
||||
}
|
||||
|
@ -88,6 +89,37 @@ class ShowbuilderController extends Zend_Controller_Action
|
|||
$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() {
|
||||
|
||||
$request = $this->getRequest();
|
||||
|
@ -98,6 +130,7 @@ class ShowbuilderController extends Zend_Controller_Action
|
|||
$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"));
|
||||
|
@ -109,6 +142,7 @@ class ShowbuilderController extends Zend_Controller_Action
|
|||
$showBuilder = new Application_Model_ShowBuilder($startsDT, $endsDT, $opts);
|
||||
|
||||
$this->view->schedule = $showBuilder->GetItems();
|
||||
$this->view->timestamp = $current_time;
|
||||
}
|
||||
|
||||
public function scheduleAddAction() {
|
||||
|
|
|
@ -11,6 +11,12 @@ class Application_Form_ShowBuilder extends Zend_Form_SubForm
|
|||
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
|
||||
$startDate = new Zend_Form_Element_Text('sb_date_start');
|
||||
$startDate->class = 'input_text';
|
||||
|
|
|
@ -1448,7 +1448,8 @@ class Application_Model_Show {
|
|||
}
|
||||
|
||||
$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
|
||||
LEFT JOIN cc_show ON cc_show.id = cc_show_instances.show_id
|
||||
WHERE cc_show_instances.modified_instance = FALSE";
|
||||
|
@ -1479,6 +1480,9 @@ class Application_Model_Show {
|
|||
$sql = $sql." AND ({$exclude})";
|
||||
}
|
||||
|
||||
Logging::log("getShows");
|
||||
Logging::log($sql);
|
||||
|
||||
return $CC_DBC->GetAll($sql);
|
||||
}
|
||||
|
||||
|
|
|
@ -6,8 +6,12 @@ require_once 'formatters/TimeFilledFormatter.php';
|
|||
class Application_Model_ShowBuilder {
|
||||
|
||||
private $timezone;
|
||||
|
||||
//in UTC timezone
|
||||
private $startDT;
|
||||
//in UTC timezone
|
||||
private $endDT;
|
||||
|
||||
private $user;
|
||||
private $opts;
|
||||
|
||||
|
@ -194,6 +198,39 @@ class Application_Model_ShowBuilder {
|
|||
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() {
|
||||
|
||||
$current_id = -1;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<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_time_start') ?>
|
||||
<?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) {
|
||||
var oLibTT = TableTools.fnGetInstance('library_display');
|
||||
|
||||
|
@ -47,6 +73,8 @@ var AIRTIME = (function(AIRTIME){
|
|||
};
|
||||
|
||||
fnServerData = function ( sSource, aoData, fnCallback ) {
|
||||
|
||||
aoData.push( { name: "timestamp", value: AIRTIME.showbuilder.getTimestamp()} );
|
||||
aoData.push( { name: "format", value: "json"} );
|
||||
|
||||
if (fnServerData.hasOwnProperty("start")) {
|
||||
|
@ -65,7 +93,10 @@ var AIRTIME = (function(AIRTIME){
|
|||
"type": "GET",
|
||||
"url": sSource,
|
||||
"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");
|
||||
|
||||
setTimeout(function(){
|
||||
AIRTIME.showbuilder.resetTimestamp();
|
||||
oTable.fnDraw();
|
||||
}, aData.refresh * 1000); //need refresh in milliseconds
|
||||
}
|
||||
|
@ -311,7 +343,9 @@ var AIRTIME = (function(AIRTIME){
|
|||
},
|
||||
//remove any selected nodes before the draw.
|
||||
"fnPreDrawCallback": function( oSettings ) {
|
||||
var oTT = TableTools.fnGetInstance('show_builder_table');
|
||||
var oTT;
|
||||
|
||||
oTT = TableTools.fnGetInstance('show_builder_table');
|
||||
oTT.fnSelectNone();
|
||||
},
|
||||
|
||||
|
|
|
@ -109,6 +109,9 @@ $(document).ready(function(){
|
|||
op,
|
||||
oTable = $('#show_builder_table').dataTable();
|
||||
|
||||
//reset timestamp value since input values could have changed.
|
||||
AIRTIME.showbuilder.resetTimestamp();
|
||||
|
||||
oRange = fnGetScheduleRange();
|
||||
|
||||
fn = oTable.fnSettings().fnServerData;
|
||||
|
@ -136,6 +139,9 @@ $(document).ready(function(){
|
|||
|
||||
if ($button.hasClass("sb-edit")) {
|
||||
|
||||
//reset timestamp to redraw the cursors.
|
||||
AIRTIME.showbuilder.resetTimestamp();
|
||||
|
||||
$lib.show();
|
||||
$lib.width(Math.floor(screenWidth * 0.5));
|
||||
$builder.width(Math.floor(screenWidth * 0.5));
|
||||
|
@ -155,7 +161,6 @@ $(document).ready(function(){
|
|||
}
|
||||
|
||||
oTable.fnDraw();
|
||||
|
||||
});
|
||||
|
||||
oRange = fnGetScheduleRange();
|
||||
|
@ -165,8 +170,35 @@ $(document).ready(function(){
|
|||
AIRTIME.library.libraryInit();
|
||||
AIRTIME.showbuilder.builderDataTable();
|
||||
|
||||
//check if the timeline viewed needs updating.
|
||||
setInterval(function(){
|
||||
var oTable = $('#show_builder_table').dataTable();
|
||||
oTable.fnDraw();
|
||||
}, 20 * 1000); //need refresh in milliseconds
|
||||
var data = {},
|
||||
oTable = $('#show_builder_table').dataTable(),
|
||||
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