wip for schedule end backend ok

This commit is contained in:
jr-k 2024-05-25 14:48:16 +02:00
parent fc80d13af3
commit 0d9d47f938
7 changed files with 111 additions and 84 deletions

View File

@ -18,23 +18,26 @@ jQuery(document).ready(function ($) {
return `${d.getFullYear()}-${String(d.getMonth()).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')} ${String(d.getHours()).padStart(2, '0')}:${String(d.getMinutes()).padStart(2, '0')}:${String(d.getSeconds()).padStart(2, '0')} ` return `${d.getFullYear()}-${String(d.getMonth()).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')} ${String(d.getHours()).padStart(2, '0')}:${String(d.getMinutes()).padStart(2, '0')}:${String(d.getSeconds()).padStart(2, '0')} `
} }
const loadDateTimePicker = function($el) { const loadDateTimePicker = function($els) {
$el.val(''); $els.each(function() {
const pickr = $el.flatpickr({ var $el = $(this);
enableTime: true, $el.val('');
time_24hr: true, const pickr = $el.flatpickr({
allowInput: false, enableTime: true,
allowInvalidPreload: false, time_24hr: true,
dateFormat: 'Y-m-d H:i', allowInput: false,
onChange: function(selectedDates, dateStr, instance) { allowInvalidPreload: false,
const d = selectedDates[0]; dateFormat: 'Y-m-d H:i',
const $target = $el.parents('.widget:eq(0)').find('.target'); onChange: function(selectedDates, dateStr, instance) {
$target.val( const d = selectedDates[0];
d ? `${d.getMinutes()} ${d.getHours()} ${d.getDate()} ${(d.getMonth() + 1)} * ${d.getFullYear()}` : '' const $target = $el.parents('.widget:eq(0)').find('.target');
); $target.val(
} d ? `${d.getMinutes()} ${d.getHours()} ${d.getDate()} ${(d.getMonth() + 1)} * ${d.getFullYear()}` : ''
}); );
$el.addClass('hidden'); }
});
$el.addClass('hidden');
})
}; };
const getId = function ($el) { const getId = function ($el) {
@ -90,7 +93,51 @@ jQuery(document).ready(function ($) {
.removeClass('hidden') .removeClass('hidden')
.prop('disabled', false) .prop('disabled', false)
; ;
} };
const inputSchedulerUpdate = function() {
const $modal = $('.modal-slide:visible');
const $scheduleStartGroup = $modal.find('.slide-schedule-group');
const $scheduleEndGroup = $modal.find('.slide-schedule-end-group');
const $durationGroup = $modal.find('.slide-duration-group');
const $triggerStart = $scheduleStartGroup.find('.trigger');
const $triggerEnd = $scheduleEndGroup.find('.trigger');
const $targetCronFieldStart = $scheduleStartGroup.find('.target');
const $targetCronFieldEnd = $scheduleEndGroup.find('.target');
const $datetimepickerStart = $scheduleStartGroup.find('.datetimepicker');
const $datetimepickerEnd = $scheduleEndGroup.find('.datetimepicker');
const isCronStart = $triggerStart.val() === 'cron';
const isCronEnd = $triggerEnd.val() === 'cron';
const isDatetimeStart = $triggerStart.val() === 'datetime';
const isDatetimeEnd = $triggerEnd.val() === 'datetime';
const isLoopStart = $triggerStart.val() === 'loop';
const isDurationEnd = $triggerEnd.val() === 'duration';
const flushValueStart = isLoopStart;
const flushValueEnd = isDurationEnd;
$targetCronFieldStart.toggleClass('hidden', !isCronStart);
$targetCronFieldEnd.toggleClass('hidden', !isCronEnd);
$datetimepickerStart.toggleClass('hidden', !isDatetimeStart);
$datetimepickerEnd.toggleClass('hidden', !isDatetimeEnd);
$durationGroup.toggleClass('hidden', !isLoopStart && !isDurationEnd);
$scheduleEndGroup.toggleClass('hidden', isLoopStart);
$durationGroup.find('.widget input').prop('required', $durationGroup.is(':visible'));
if (flushValueStart) {
$targetCronFieldStart.val('');
$datetimepickerStart.val('');
}
if (flushValueEnd) {
$targetCronFieldEnd.val('');
$datetimepickerEnd.val('');
}
};
const main = function () { const main = function () {
$("table").tableDnD({ $("table").tableDnD({
@ -119,28 +166,7 @@ jQuery(document).ready(function ($) {
}); });
$(document).on('change', '.modal-slide select.trigger', function () { $(document).on('change', '.modal-slide select.trigger', function () {
const $modal = $(this).parents('.modal-slide:eq(0)'); inputSchedulerUpdate();
const $target = $(this).parents('.widget:eq(0)').find('.target');
const $datetimepicker = $(this).parents('.widget:eq(0)').find('.datetimepicker');
const $durationGroup = $modal.find('.slide-duration-group');
const $scheduleEndGroup = $modal.find('.slide-schedule-end-group');
const isDateTime = $(this).val() === 'datetime';
const isLoop = $(this).val() === 'loop';
const flushValue = isLoop;
const hideCronField = isLoop || isDateTime;
const hideDateTimeField = !isDateTime;
$target.toggleClass('hidden', hideCronField);
$datetimepicker.toggleClass('hidden', hideDateTimeField);
// $durationGroup.toggleClass('hidden', !isLoop);
// $scheduleEndGroup.toggleClass('hidden', isLoop);
if (flushValue) {
$target.val('');
$datetimepicker.val('');
}
}); });
$(document).on('change', '#slide-add-type', inputTypeUpdate); $(document).on('change', '#slide-add-type', inputTypeUpdate);
@ -153,6 +179,7 @@ jQuery(document).ready(function ($) {
showModal('modal-slide-add'); showModal('modal-slide-add');
loadDateTimePicker($('.modal-slide-add .datetimepicker')) loadDateTimePicker($('.modal-slide-add .datetimepicker'))
inputTypeUpdate(); inputTypeUpdate();
inputSchedulerUpdate();
$('.modal-slide-add input:eq(0)').focus().select(); $('.modal-slide-add input:eq(0)').focus().select();
}); });
@ -192,7 +219,7 @@ jQuery(document).ready(function ($) {
$('#slide-edit-cron-schedule-trigger').val(hasDateTime ? 'datetime' : (hasCron ? 'cron' : 'loop')); $('#slide-edit-cron-schedule-trigger').val(hasDateTime ? 'datetime' : (hasCron ? 'cron' : 'loop'));
$('#slide-edit-cron-schedule-end').val(slide.cron_schedule_end).toggleClass('hidden', !hasCronEnd || hasDateTimeEnd); $('#slide-edit-cron-schedule-end').val(slide.cron_schedule_end).toggleClass('hidden', !hasCronEnd || hasDateTimeEnd);
$('#slide-edit-cron-schedule-end-trigger').val(hasDateTimeEnd ? 'datetime' : (hasCronEnd ? 'cron' : 'loop')); $('#slide-edit-cron-schedule-end-trigger').val(hasDateTimeEnd ? 'datetime' : (hasCronEnd ? 'cron' : 'duration'));
$('#slide-edit-cron-schedule-datetimepicker').toggleClass('hidden', !hasDateTime).val( $('#slide-edit-cron-schedule-datetimepicker').toggleClass('hidden', !hasDateTime).val(
hasDateTime ? getCronDateTime(slide.cron_schedule) : '' hasDateTime ? getCronDateTime(slide.cron_schedule) : ''
@ -202,6 +229,7 @@ jQuery(document).ready(function ($) {
hasDateTimeEnd ? getCronDateTime(slide.cron_schedule_end) : '' hasDateTimeEnd ? getCronDateTime(slide.cron_schedule_end) : ''
); );
$('#slide-edit-id').val(slide.id); $('#slide-edit-id').val(slide.id);
inputSchedulerUpdate();
}); });
$(document).on('click', '.slide-delete', function () { $(document).on('click', '.slide-delete', function () {

View File

@ -32,6 +32,8 @@
"slideshow_slide_form_label_cron_scheduled": "Start", "slideshow_slide_form_label_cron_scheduled": "Start",
"slideshow_slide_form_label_cron_scheduled_end": "End", "slideshow_slide_form_label_cron_scheduled_end": "End",
"slideshow_slide_form_label_cron_scheduled_loop": "In the loop", "slideshow_slide_form_label_cron_scheduled_loop": "In the loop",
"slideshow_slide_form_label_cron_scheduled_duration": "Duration",
"slideshow_slide_form_label_cron_scheduled_duration_unit": "seconds",
"slideshow_slide_form_label_cron_scheduled_datetime": "Date & Time", "slideshow_slide_form_label_cron_scheduled_datetime": "Date & Time",
"slideshow_slide_form_label_cron_scheduled_datetime_placeholder": "Set a date and time", "slideshow_slide_form_label_cron_scheduled_datetime_placeholder": "Set a date and time",
"slideshow_slide_form_label_cron_scheduled_cron": "Cron", "slideshow_slide_form_label_cron_scheduled_cron": "Cron",

View File

@ -32,6 +32,8 @@
"slideshow_slide_form_label_cron_scheduled": "Début", "slideshow_slide_form_label_cron_scheduled": "Début",
"slideshow_slide_form_label_cron_scheduled_end": "Fin", "slideshow_slide_form_label_cron_scheduled_end": "Fin",
"slideshow_slide_form_label_cron_scheduled_loop": "Dans la boucle", "slideshow_slide_form_label_cron_scheduled_loop": "Dans la boucle",
"slideshow_slide_form_label_cron_scheduled_duration": "Durée",
"slideshow_slide_form_label_cron_scheduled_duration_unit": "secondes",
"slideshow_slide_form_label_cron_scheduled_datetime": "Date & Heure", "slideshow_slide_form_label_cron_scheduled_datetime": "Date & Heure",
"slideshow_slide_form_label_cron_scheduled_datetime_placeholder": "Choisir une date et une heure", "slideshow_slide_form_label_cron_scheduled_datetime_placeholder": "Choisir une date et une heure",
"slideshow_slide_form_label_cron_scheduled_cron": "Cron", "slideshow_slide_form_label_cron_scheduled_cron": "Cron",

View File

@ -78,6 +78,8 @@ class DatabaseManager:
except sqlite3.Error as e: except sqlite3.Error as e:
logging.error("SQL query execution error while writing '{}': {}".format(query, e)) logging.error("SQL query execution error while writing '{}': {}".format(query, e))
self._conn.rollback() self._conn.rollback()
except sqlite3.OperationalError:
pass
finally: finally:
if cur is not None: if cur is not None:
cur.close() cur.close()

View File

@ -43,7 +43,7 @@
var needHardRefresh = null; var needHardRefresh = null;
// Frontend config // Frontend config
var syncedWithTime = true; var syncedWithTime = false;
var tickRefreshResolutionMs = 100; var tickRefreshResolutionMs = 100;
// Frontend flag updates // Frontend flag updates
@ -132,7 +132,7 @@
} }
if (syncedWithTime) { if (syncedWithTime) {
return console.warn('You can\'t call seek with synced playlists'); return console.warn('You can\'t seek with synced playlists');
} }
var maxDuration = getLoopDuration(); var maxDuration = getLoopDuration();
@ -188,7 +188,7 @@
setTimeout(function() { setTimeout(function() {
introSlide.remove(); introSlide.remove();
setInterval(checkAndMoveSlide, tickRefreshResolutionMs); setInterval(checkAndMoveSlide, tickRefreshResolutionMs);
setInterval(cronTick, 1000); setInterval(checkAndMoveCron, 1000);
}, introDuration); }, introDuration);
}; };
@ -260,21 +260,22 @@
//console.log("curSlide", curSlide.attributes['id'].value, curSlide.style.zIndex, "to", "next", nextSlide.attributes['id'].value, nextSlide.style.zIndex); //console.log("curSlide", curSlide.attributes['id'].value, curSlide.style.zIndex, "to", "next", nextSlide.attributes['id'].value, nextSlide.style.zIndex);
//console.log("###"); //console.log("###");
var loadingNextSlide = function () {
if (forcePreload) {
forcePreload = false;
play();
}
if (isPaused() && !syncedWithTime) {
return setTimeout(loadingNextSlide, 500);
}
refreshSlidesOrder();
preloadSlide(nextSlide.attributes['id'].value, lookupNextItem());
};
if (animate) { if (animate) {
nextSlide.classList.add('animate__animated', animate_transitions[0], animate_speed); nextSlide.classList.add('animate__animated', animate_transitions[0], animate_speed);
var loadingNextSlide = function () {
if (forcePreload) {
forcePreload = false;
play();
}
if (isPaused() && !syncedWithTime) {
return setTimeout(loadingNextSlide, 500);
}
refreshSlidesOrder();
preloadSlide(nextSlide.attributes['id'].value, lookupNextItem());
};
nextSlide.onanimationend = function() { nextSlide.onanimationend = function() {
nextSlide.classList.remove(animate_transitions[0], animate_speed); nextSlide.classList.remove(animate_transitions[0], animate_speed);
loadingNextSlide(); loadingNextSlide();
@ -285,18 +286,6 @@
curSlide.classList.remove(animate_transitions[1], animate_speed); curSlide.classList.remove(animate_transitions[1], animate_speed);
}; };
} else { } else {
var loadingNextSlide = function () {
if (forcePreload) {
forcePreload = false;
play();
}
if (isPaused() && !syncedWithTime) {
return setTimeout(loadingNextSlide, 500);
}
refreshSlidesOrder();
preloadSlide(nextSlide.attributes['id'].value, lookupNextItem());
};
loadingNextSlide(); loadingNextSlide();
} }
} }
@ -378,7 +367,7 @@
setTimeout(autoplayLoader, delayNoisyContentJIT); setTimeout(autoplayLoader, delayNoisyContentJIT);
} }
var cronTick = function() { var checkAndMoveCron = function() {
if ((new Date()).getSeconds() != 0) { if ((new Date()).getSeconds() != 0) {
return; return;
} }
@ -387,31 +376,34 @@
var item = items.cron[i]; var item = items.cron[i];
if (cron.isActive(item.cron_schedule) && cronItemIndex !== i) { if (cron.isActive(item.cron_schedule) && cronItemIndex !== i) {
setTimeout(function() { moveToCronSlide(i);
moveToCronSlide(i); }
}, 100);
if (cron.isActive(item.cron_schedule_end) && cronItemIndex === i) {
stopCronSlide();
} }
} }
}; };
function moveToCronSlide(cronSlideIndex) { function moveToCronSlide(cronSlideIndex) {
var item = items.cron[cronSlideIndex]; var item = items.cron[cronSlideIndex];
var savedSlide = curSlide.innerHTML;
cronItemIndex = cronSlideIndex; cronItemIndex = cronSlideIndex;
pause(); pause();
var callbackReady = function() { var callbackReady = function() {
cronSlide.style.zIndex = '2000'; cronSlide.style.zIndex = '2000';
setTimeout(function() { setTimeout(function() {
cronItemIndex = null; stopCronSlide();
curSlide.innerHTML = savedSlide;
cronSlide.style.zIndex = '0';
play();
}, safe_duration(item) * 1000); }, safe_duration(item) * 1000);
}; };
loadContent(cronSlide, callbackReady, item); loadContent(cronSlide, callbackReady, item);
} }
function stopCronSlide() {
cronItemIndex = null;
cronSlide.style.zIndex = '0';
play();
}
main(); main();
</script> </script>
</body> </body>

View File

@ -45,7 +45,7 @@
{{ l.slideshow_slide_form_section_scheduling }} {{ l.slideshow_slide_form_section_scheduling }}
</h3> </h3>
<div class="form-group"> <div class="form-group slide-schedule-group">
<label for="slide-add-cron-schedule">{{ l.slideshow_slide_form_label_cron_scheduled }}</label> <label for="slide-add-cron-schedule">{{ l.slideshow_slide_form_label_cron_scheduled }}</label>
<div class="widget"> <div class="widget">
<select id="slide-add-cron-schedule-trigger" class="trigger"> <select id="slide-add-cron-schedule-trigger" class="trigger">
@ -58,10 +58,11 @@
</div> </div>
</div> </div>
<div class="form-group slide-schedule-end-group hidden"> <div class="form-group slide-schedule-end-group">
<label for="slide-add-cron-schedule-end">{{ l.slideshow_slide_form_label_cron_scheduled_end }}</label> <label for="slide-add-cron-schedule-end">{{ l.slideshow_slide_form_label_cron_scheduled_end }}</label>
<div class="widget"> <div class="widget">
<select id="slide-add-cron-schedule-end-trigger" class="trigger"> <select id="slide-add-cron-schedule-end-trigger" class="trigger">
<option value="duration">{{ l.slideshow_slide_form_label_cron_scheduled_duration }}</option>
<option value="datetime">{{ l.slideshow_slide_form_label_cron_scheduled_datetime }}</option> <option value="datetime">{{ l.slideshow_slide_form_label_cron_scheduled_datetime }}</option>
<option value="cron">{{ l.slideshow_slide_form_label_cron_scheduled_cron }}</option> <option value="cron">{{ l.slideshow_slide_form_label_cron_scheduled_cron }}</option>
</select> </select>

View File

@ -43,7 +43,7 @@
{{ l.slideshow_slide_form_section_scheduling }} {{ l.slideshow_slide_form_section_scheduling }}
</h3> </h3>
<div class="form-group"> <div class="form-group slide-schedule-group">
<label for="slide-edit-cron-schedule">{{ l.slideshow_slide_form_label_cron_scheduled }}</label> <label for="slide-edit-cron-schedule">{{ l.slideshow_slide_form_label_cron_scheduled }}</label>
<div class="widget"> <div class="widget">
<select id="slide-edit-cron-schedule-trigger" class="trigger"> <select id="slide-edit-cron-schedule-trigger" class="trigger">
@ -56,11 +56,11 @@
</div> </div>
</div> </div>
<div class="form-group slide-schedule-end-group hidden"> <div class="form-group slide-schedule-end-group">
<label for="slide-edit-cron-schedule-end">{{ l.slideshow_slide_form_label_cron_scheduled_end }}</label> <label for="slide-edit-cron-schedule-end">{{ l.slideshow_slide_form_label_cron_scheduled_end }}</label>
<div class="widget"> <div class="widget">
<select id="slide-edit-cron-schedule-end-trigger" class="trigger"> <select id="slide-edit-cron-schedule-end-trigger" class="trigger">
<option value="loop">{{ l.slideshow_slide_form_label_cron_scheduled_loop }}</option> <option value="duration">{{ l.slideshow_slide_form_label_cron_scheduled_duration }}</option>
<option value="datetime">{{ l.slideshow_slide_form_label_cron_scheduled_datetime }}</option> <option value="datetime">{{ l.slideshow_slide_form_label_cron_scheduled_datetime }}</option>
<option value="cron">{{ l.slideshow_slide_form_label_cron_scheduled_cron }}</option> <option value="cron">{{ l.slideshow_slide_form_label_cron_scheduled_cron }}</option>
</select> </select>