CC-3542 : When you delete the current show it takes all songs from that show out of the playout history

This commit is contained in:
Naomi Aro 2012-04-02 15:20:13 +02:00
parent 9f0741a684
commit eeb7273909
6 changed files with 210 additions and 91 deletions

View file

@ -22,6 +22,7 @@ class ScheduleController extends Zend_Controller_Action
->addActionContext('edit-show', 'json') ->addActionContext('edit-show', 'json')
->addActionContext('add-show', 'json') ->addActionContext('add-show', 'json')
->addActionContext('cancel-show', 'json') ->addActionContext('cancel-show', 'json')
->addActionContext('cancel-current-show', 'json')
->addActionContext('get-form', 'json') ->addActionContext('get-form', 'json')
->addActionContext('upload-to-sound-cloud', 'json') ->addActionContext('upload-to-sound-cloud', 'json')
->addActionContext('content-context-menu', 'json') ->addActionContext('content-context-menu', 'json')
@ -816,21 +817,21 @@ class ScheduleController extends Zend_Controller_Action
public function cancelCurrentShowAction() public function cancelCurrentShowAction()
{ {
$userInfo = Zend_Auth::getInstance()->getStorage()->read(); $user = Application_Model_User::GetCurrentUser();
$user = new Application_Model_User($userInfo->id);
if($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER))) { if ($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER))) {
$showInstanceId = $this->_getParam('id'); $id = $this->_getParam('id');
try{
$showInstance = new Application_Model_ShowInstance($showInstanceId); try {
}catch(Exception $e){ $scheduler = new Application_Model_Scheduler();
$this->view->show_error = true; $scheduler->cancelShow($id);
return false; }
catch (Exception $e) {
$this->view->error = $e->getMessage();
Logging::log($e->getMessage());
Logging::log("{$e->getFile()}");
Logging::log("{$e->getLine()}");
} }
$showInstance->clearShow();
$showInstance->delete();
Application_Model_RabbitMq::PushSchedule();
} }
} }

View file

@ -93,10 +93,10 @@ class Application_Model_Scheduler {
throw new OutDatedScheduleException("The show {$show->getDbName()} is over and cannot be scheduled."); throw new OutDatedScheduleException("The show {$show->getDbName()} is over and cannot be scheduled.");
} }
$origTs = intval($instanceInfo[$id]); $ts = intval($instanceInfo[$id]);
$currTs = intval($instance->getDbLastScheduled("U")) ? : 0; $lastSchedTs = intval($instance->getDbLastScheduled("U")) ? : 0;
if ($origTs !== $currTs) { if ($ts < $lastSchedTs) {
Logging::log("orig {$origTs} current {$currTs}"); Logging::log("ts {$ts} last sched {$lastSchedTs}");
throw new OutDatedScheduleException("The show {$show->getDbName()} has been previously updated!"); throw new OutDatedScheduleException("The show {$show->getDbName()} has been previously updated!");
} }
} }
@ -216,6 +216,41 @@ class Application_Model_Scheduler {
return $nextDT; return $nextDT;
} }
/*
* @param int $showInstance
* @param array $exclude
* ids of sched items to remove from the calulation.
*/
private function removeGaps($showInstance, $exclude=null) {
Logging::log("removing gaps from show instance #".$showInstance);
$instance = CcShowInstancesQuery::create()->findPK($showInstance, $this->con);
if (is_null($instance)) {
throw new OutDatedScheduleException("The schedule you're viewing is out of date!");
}
$itemStartDT = $instance->getDbStarts(null);
$schedule = CcScheduleQuery::create()
->filterByDbInstanceId($showInstance)
->filterByDbId($exclude, Criteria::NOT_IN)
->orderByDbStarts()
->find($this->con);
foreach ($schedule as $item) {
$itemEndDT = $this->findEndTime($itemStartDT, $item->getDbClipLength());
$item->setDbStarts($itemStartDT)
->setDbEnds($itemEndDT)
->save($this->con);
$itemStartDT = $itemEndDT;
}
}
/* /*
* @param array $scheduledIds * @param array $scheduledIds
* @param array $fileIds * @param array $fileIds
@ -280,16 +315,16 @@ class Application_Model_Scheduler {
$sched = new CcSchedule(); $sched = new CcSchedule();
} }
$sched->setDbStarts($nextStartDT); $sched->setDbStarts($nextStartDT)
$sched->setDbEnds($endTimeDT); ->setDbEnds($endTimeDT)
$sched->setDbFileId($file['id']); ->setDbFileId($file['id'])
$sched->setDbCueIn($file['cuein']); ->setDbCueIn($file['cuein'])
$sched->setDbCueOut($file['cueout']); ->setDbCueOut($file['cueout'])
$sched->setDbFadeIn($file['fadein']); ->setDbFadeIn($file['fadein'])
$sched->setDbFadeOut($file['fadeout']); ->setDbFadeOut($file['fadeout'])
$sched->setDbClipLength($file['cliplength']); ->setDbClipLength($file['cliplength'])
$sched->setDbInstanceId($instance->getDbId()); ->setDbInstanceId($instance->getDbId())
$sched->save($this->con); ->save($this->con);
$nextStartDT = $endTimeDT; $nextStartDT = $endTimeDT;
} }
@ -506,37 +541,42 @@ class Application_Model_Scheduler {
} }
/* /*
* @param int $showInstance * Used for cancelling the current show instance.
* @param array $exclude *
* ids of sched items to remove from the calulation. * @param $p_id id of the show instance to cancel.
*/ */
private function removeGaps($showInstance, $exclude=null) { public function cancelShow($p_id) {
Logging::log("removing gaps from show instance #".$showInstance); $this->con->beginTransaction();
$instance = CcShowInstancesQuery::create()->findPK($showInstance, $this->con); try {
if (is_null($instance)) {
throw new OutDatedScheduleException("The schedule you're viewing is out of date!"); $instance = CcShowInstancesQuery::create()->findPK($p_id);
$items = CcScheduleQuery::create()
->filterByDbInstanceId($p_id)
->filterByDbEnds($this->nowDT, Criteria::GREATER_THAN)
->find($this->con);
$remove = array();
$ts = $this->nowDT->format('U');
for($i = 0; $i < count($items); $i++) {
$remove[$i]["instance"] = $p_id;
$remove[$i]["timestamp"] = $ts;
$remove[$i]["id"] = $items[$i]->getDbId();
}
$this->removeItems($remove, false);
$instance->setDbEnds($this->nowDT);
$instance->save($this->con);
$this->con->commit();
} }
catch (Exception $e) {
$itemStartDT = $instance->getDbStarts(null); $this->con->rollback();
throw $e;
$schedule = CcScheduleQuery::create()
->filterByDbInstanceId($showInstance)
->filterByDbId($exclude, Criteria::NOT_IN)
->orderByDbStarts()
->find($this->con);
foreach ($schedule as $item) {
$itemEndDT = $this->findEndTime($itemStartDT, $item->getDbClipLength());
$item->setDbStarts($itemStartDT);
$item->setDbEnds($itemEndDT);
$item->save($this->con);
$itemStartDT = $itemEndDT;
} }
} }
} }

View file

@ -18,6 +18,7 @@ class Application_Model_ShowBuilder {
private $pos; private $pos;
private $contentDT; private $contentDT;
private $epoch_now; private $epoch_now;
private $currentShow;
private $defaultRowArray = array( private $defaultRowArray = array(
"header" => false, "header" => false,
@ -54,6 +55,7 @@ class Application_Model_ShowBuilder {
$this->user = Application_Model_User::GetCurrentUser(); $this->user = Application_Model_User::GetCurrentUser();
$this->opts = $p_opts; $this->opts = $p_opts;
$this->epoch_now = floatval(microtime(true)); $this->epoch_now = floatval(microtime(true));
$this->currentShow = false;
} }
//check to see if this row should be editable by the user. //check to see if this row should be editable by the user.
@ -118,7 +120,7 @@ class Application_Model_ShowBuilder {
else if ($row["footer"] === true && $this->epoch_now < $p_epochItemEnd) { else if ($row["footer"] === true && $this->epoch_now < $p_epochItemEnd) {
$row["scheduled"] = 2; $row["scheduled"] = 2;
} }
else if ($row["header"] === true && $this->epoch_now > $p_epochItemStart) { else if ($row["header"] === true && $this->epoch_now >= $p_epochItemStart) {
$row["scheduled"] = 0; $row["scheduled"] = 0;
} }
else if ($row["header"] === true && $this->epoch_now < $p_epochItemEnd) { else if ($row["header"] === true && $this->epoch_now < $p_epochItemEnd) {
@ -157,6 +159,14 @@ class Application_Model_ShowBuilder {
$showEndDT->setTimezone(new DateTimeZone($this->timezone)); $showEndDT->setTimezone(new DateTimeZone($this->timezone));
$endsEpoch = floatval($showEndDT->format("U.u")); $endsEpoch = floatval($showEndDT->format("U.u"));
if ($startsEpoch < $this->epoch_now && $endsEpoch > $this->epoch_now) {
$row["currentShow"] = true;
$this->currentShow = true;
}
else {
$this->currentShow = false;
}
$row["header"] = true; $row["header"] = true;
$row["starts"] = $showStartDT->format("Y-m-d H:i"); $row["starts"] = $showStartDT->format("Y-m-d H:i");
$row["refresh"] = floatval($showStartDT->format("U.u")) - $this->epoch_now; $row["refresh"] = floatval($showStartDT->format("U.u")) - $this->epoch_now;
@ -225,6 +235,10 @@ class Application_Model_ShowBuilder {
$row["instance"] = intval($p_item["si_id"]); $row["instance"] = intval($p_item["si_id"]);
} }
if ($this->currentShow = true) {
$row["currentShow"] = true;
}
$this->getItemColor($p_item, $row); $this->getItemColor($p_item, $row);
$this->getRowTimestamp($p_item, $row); $this->getRowTimestamp($p_item, $row);
$this->isAllowed($p_item, $row); $this->isAllowed($p_item, $row);
@ -257,6 +271,10 @@ class Application_Model_ShowBuilder {
$row["refresh"] = floatval($showEndDT->format("U.u")) - $this->epoch_now; $row["refresh"] = floatval($showEndDT->format("U.u")) - $this->epoch_now;
if ($this->currentShow = true) {
$row["currentShow"] = true;
}
$this->getScheduledStatus($startsEpoch, $endsEpoch, $row); $this->getScheduledStatus($startsEpoch, $endsEpoch, $row);
$this->isAllowed($p_item, $row); $this->isAllowed($p_item, $row);

View file

@ -24,7 +24,7 @@
.sb-content .fg-toolbar ul { .sb-content .fg-toolbar ul {
float: left; float: left;
padding: 0; padding: 0;
margin: 0.5em 0 0 0; margin: 0.5em 10px 0 0;
cursor: pointer; cursor: pointer;
} }
@ -176,6 +176,10 @@ table.datatable tr.sb-header.odd:hover td, table.datatable tr.sb-header.even:hov
border-bottom-color:#6b6a6a !important; border-bottom-color:#6b6a6a !important;
} }
.sb-header div.ui-state-default {
float: left;
}
.sb-content table th.ui-state-default { .sb-content table th.ui-state-default {
background: -moz-linear-gradient(top, #b2b2b2 0, #a2a2a2 100%); background: -moz-linear-gradient(top, #b2b2b2 0, #a2a2a2 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0, #b2b2b2), color-stop(100%, #a2a2a2)); background: -webkit-gradient(linear, left top, left bottom, color-stop(0, #b2b2b2), color-stop(100%, #a2a2a2));

View file

@ -1,8 +1,14 @@
/** var AIRTIME = (function(AIRTIME){
* var mod;
* Schedule Dialog creation methods.
* if (AIRTIME.schedule === undefined) {
*/ AIRTIME.schedule = {};
}
mod = AIRTIME.schedule;
return AIRTIME;
}(AIRTIME || {}));
var serverTimezoneOffset = 0; var serverTimezoneOffset = 0;
@ -27,21 +33,27 @@ function checkShowLength(json) {
} }
function confirmCancelShow(show_instance_id){ function confirmCancelShow(show_instance_id){
if (confirm('Erase current show and stop playback?')){ if (confirm('Cancel Current Show?')) {
var url = "/Schedule/cancel-current-show/id/"+show_instance_id; var url = "/Schedule/cancel-current-show";
$.ajax({ $.ajax({
url: url, url: url,
success: function(data){scheduleRefetchEvents(data);} data: {format: "json", id: show_instance_id},
success: function(data){
scheduleRefetchEvents(data);
}
}); });
} }
} }
function confirmCancelRecordedShow(show_instance_id){ function confirmCancelRecordedShow(show_instance_id){
if (confirm('Erase current show and stop recording?')){ if (confirm('Erase current show and stop recording?')) {
var url = "/Schedule/cancel-current-show/id/"+show_instance_id; var url = "/Schedule/cancel-current-show";
$.ajax({ $.ajax({
url: url, url: url,
success: function(data){scheduleRefetchEvents(data);} data: {format: "json", id: show_instance_id},
success: function(data){
scheduleRefetchEvents(data);
}
}); });
} }
} }

View file

@ -364,6 +364,10 @@ var AIRTIME = (function(AIRTIME){
$(nRow).addClass("sb-over"); $(nRow).addClass("sb-over");
} }
if (aData.currentShow === true) {
$(nRow).addClass("sb-current-show");
}
//call the context menu so we can prevent the event from propagating. //call the context menu so we can prevent the event from propagating.
$(nRow).find('td:gt(1)').click(function(e){ $(nRow).find('td:gt(1)').click(function(e){
@ -372,6 +376,20 @@ var AIRTIME = (function(AIRTIME){
return false; return false;
}); });
}, },
//remove any selected nodes before the draw.
"fnPreDrawCallback": function( oSettings ) {
var oTT;
oTT = TableTools.fnGetInstance('show_builder_table');
oTT.fnSelectNone();
//disable jump to current button.
AIRTIME.button.disableButton("sb-button-current");
//disable deleting of overbooked tracks.
AIRTIME.button.disableButton("sb-button-trim");
//disable cancelling current show.
AIRTIME.button.disableButton("sb-button-cancel");
},
"fnDrawCallback": function(oSettings, json) { "fnDrawCallback": function(oSettings, json) {
var wrapperDiv, var wrapperDiv,
markerDiv, markerDiv,
@ -454,22 +472,16 @@ var AIRTIME = (function(AIRTIME){
//enable deleting of overbooked tracks. //enable deleting of overbooked tracks.
AIRTIME.button.enableButton("sb-button-trim"); AIRTIME.button.enableButton("sb-button-trim");
} }
$tr = $sbTable.find('tr.sb-future:first');
if ($tr.hasClass('sb-current-show')) {
//enable cancelling current show.
AIRTIME.button.enableButton("sb-button-cancel");
}
}, },
"fnHeaderCallback": function(nHead) { "fnHeaderCallback": function(nHead) {
$(nHead).find("input[type=checkbox]").attr("checked", false); $(nHead).find("input[type=checkbox]").attr("checked", false);
}, },
//remove any selected nodes before the draw.
"fnPreDrawCallback": function( oSettings ) {
var oTT;
oTT = TableTools.fnGetInstance('show_builder_table');
oTT.fnSelectNone();
//disable jump to current button.
AIRTIME.button.disableButton("sb-button-current");
//disable deleting of overbooked tracks.
AIRTIME.button.disableButton("sb-button-trim");
},
"oColVis": { "oColVis": {
"aiExclude": [ 0, 1 ] "aiExclude": [ 0, 1 ]
@ -707,12 +719,44 @@ var AIRTIME = (function(AIRTIME){
//start setup of the builder toolbar. //start setup of the builder toolbar.
$toolbar = $(".sb-content .fg-toolbar"); $toolbar = $(".sb-content .fg-toolbar");
$toolbar $ul = $("<ul/>");
.append("<ul />") $ul.append('<li class="ui-state-default ui-state-disabled sb-button-trim" title="delete all overbooked tracks"><span class="ui-icon ui-icon-scissors"></span></li>')
.find('ul') .append('<li class="ui-state-default ui-state-disabled sb-button-delete" title="delete selected items"><span class="ui-icon ui-icon-trash"></span></li>');
.append('<li class="ui-state-default ui-state-disabled sb-button-current" title="jump to the currently playing track"><span class="ui-icon ui-icon-arrowstop-1-s"></span></li>') $toolbar.append($ul);
.append('<li class="ui-state-default ui-state-disabled sb-button-trim" title="delete all overbooked tracks"><span class="ui-icon ui-icon-scissors"></span></li>')
.append('<li class="ui-state-default ui-state-disabled sb-button-delete" title="delete selected items"><span class="ui-icon ui-icon-trash"></span></li>'); $ul = $("<ul/>");
$ul.append('<li class="ui-state-default ui-state-disabled sb-button-current" title="jump to the currently playing track"><span class="ui-icon ui-icon-arrowstop-1-s"></span></li>')
.append('<li class="ui-state-default ui-state-disabled sb-button-cancel" title="cancel current show"><span class="ui-icon ui-icon-eject"></span></li>');
$toolbar.append($ul);
//jump to current
$toolbar.find('.sb-button-cancel')
.click(function() {
var $tr,
data;
if (AIRTIME.button.isDisabled('sb-button-cancel') === true) {
return;
}
$tr = $sbTable.find('tr.sb-future:first');
if ($tr.hasClass('sb-current-show')) {
data = $tr.data("aData");
if (confirm('Cancel Current Show?')) {
var url = "/Schedule/cancel-current-show";
$.ajax({
url: url,
data: {format: "json", id: data.instance},
success: function(data){
var oTable = $sbTable.dataTable();
oTable.fnDraw();
}
});
}
}
});
//jump to current //jump to current
$toolbar.find('.sb-button-current') $toolbar.find('.sb-button-current')