Merge pull request #605 from Robbt/feature-smartblock-remaining-time

Add Fill Remaining Time Smartblock Limit
This commit is contained in:
frecuencialibre 2018-12-12 15:43:49 -06:00 committed by GitHub
commit 4752c728b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 59 additions and 10 deletions

View File

@ -159,7 +159,8 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm
$this->limitOptions = array(
"hours" => _("hours"),
"minutes" => _("minutes"),
"items" => _("items")
"items" => _("items"),
"remaining" => _("time remaining in show")
);
}
return $this->limitOptions;

View File

@ -1321,9 +1321,13 @@ SQL;
}
}
public function getListOfFilesUnderLimit()
/*
*
*/
public function getListOfFilesUnderLimit($show = null)
{
$info = $this->getListofFilesMeetCriteria();
$info = $this->getListofFilesMeetCriteria($show);
$files = $info['files'];
$limit = $info['limit'];
$repeat = $info['repeat_tracks'];
@ -1507,7 +1511,7 @@ SQL;
}
// this function return list of propel object
public function getListofFilesMeetCriteria()
public function getListofFilesMeetCriteria($show = null)
{
$storedCrit = $this->getCriteria();
@ -1645,6 +1649,17 @@ SQL;
if ($storedCrit['limit']['modifier'] == "items") {
$limits['time'] = 1440 * 60;
$limits['items'] = $storedCrit['limit']['value'];
} elseif (($storedCrit['limit']['modifier'] == "remaining") ){
// show will be null unless being called inside a show instance
if (!(is_null($show))) {
$showInstance = new Application_Model_ShowInstance($show);
$limits['time'] = $showInstance->getSecondsRemaining();
$limits['items'] = null;
}
else {
$limits['time'] = 60 * 60;
$limits['items'] = null;
}
} else {
$limits['time'] = $storedCrit['limit']['modifier'] == "hours" ?
intval(floatval($storedCrit['limit']['value']) * 60 * 60) :

View File

@ -207,10 +207,11 @@ final class Application_Model_Scheduler
/*
* @param $id
* @param $type
* @param $show
*
* @return $files
*/
private function retrieveMediaFiles($id, $type)
private function retrieveMediaFiles($id, $type, $show)
{
$files = array();
@ -337,7 +338,7 @@ final class Application_Model_Scheduler
} else {
$defaultFadeIn = Application_Model_Preference::GetDefaultFadeIn();
$defaultFadeOut = Application_Model_Preference::GetDefaultFadeOut();
$dynamicFiles = $bl->getListOfFilesUnderLimit();
$dynamicFiles = $bl->getListOfFilesUnderLimit($show);
foreach ($dynamicFiles as $f) {
$fileId = $f['id'];
$file = CcFilesQuery::create()->findPk($fileId);
@ -788,11 +789,14 @@ final class Application_Model_Scheduler
Logging::debug(floatval($pend) - floatval($pstart));
}
// passing $schedule["instance"] so that the instance being scheduled
// can be used to determine the remaining time
// in the case of a fill remaining time smart block
if (is_null($filesToInsert)) {
$filesToInsert = array();
foreach ($mediaItems as $media) {
$filesToInsert = array_merge($filesToInsert,
$this->retrieveMediaFiles($media["id"], $media["type"]));
$this->retrieveMediaFiles($media["id"], $media["type"], $schedule["instance"]));
}
}

View File

@ -476,6 +476,12 @@ SQL;
return intval($ends->format('U')) - intval($starts->format('U'));
}
// should return the amount of seconds remaining to be scheduled in a show instance
public function getSecondsRemaining()
{
return ($this->getDurationSecs() - $this->getTimeScheduledSecs());
}
public function getPercentScheduled()
{
$durationSeconds = $this->getDurationSecs();

View File

@ -711,7 +711,7 @@ table.library-get-file-md.table-small{
}
.sp_input_select{
width: 130px;
width: 140px;
}
.sp_input_text_limit{

View File

@ -291,8 +291,20 @@ function setSmartBlockEvents() {
setupUI();
AIRTIME.library.checkAddButton();
});
/********** CRITERIA CHANGE **********/
/********** LIMIT CHANGE *************/
form.find('select[id="sp_limit_options"]').live("change", function() {
var limVal = form.find('input[id="sp_limit_value"]');
if ($(this).val() === 'remaining') {
disableAndHideLimitValue();
}
else {
enableAndShowLimitValue();
}
});
/********** CRITERIA CHANGE **********/
form.find('select[id^="sp_criteria"]:not([id^="sp_criteria_modifier"])').live("change", function(){
var index = getRowIndex($(this).parent());
//need to change the criteria value for any modifier rows
@ -461,6 +473,9 @@ function setupUI() {
shuffleButton = activeTab.find('button[name="shuffle_button"]'),
generateButton = activeTab.find('button[name="generate_button"]'),
fadesButton = activeTab.find('#spl_crossfade, #pl-bl-clear-content');
if (activeTab.find('#sp_limit_options').val() == 'remaining') {
disableAndHideLimitValue();
}
if (!plContents.hasClass('spl_empty')) {
if (shuffleButton.hasClass('ui-state-disabled')) {
@ -633,6 +648,14 @@ function disableAndHideExtraField(valEle, index) {
var criteria_value = $('#sp_criteria_value_'+index);
sizeTextBoxes(criteria_value, 'sp_extra_input_text', 'sp_input_text');
}
function disableAndHideLimitValue() {
console.log('we hide it');
$('#sp_limit_value').hide();
}
function enableAndShowLimitValue() {
console.log('we show it');
$('#sp_limit_value').show();
}
function sizeTextBoxes(ele, classToRemove, classToAdd) {
if (ele.hasClass(classToRemove)) {