Skip to content

Commit 3dd0c15

Browse files
committed
Adding some UI feedback for times that extend into the next day
1 parent c393b71 commit 3dd0c15

File tree

3 files changed

+47
-7
lines changed

3 files changed

+47
-7
lines changed

changedetectionio/flask_app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1811,7 +1811,7 @@ def ticker_thread_check_time_launch_checks():
18111811
if time_schedule_limit and time_schedule_limit.get('enabled'):
18121812
result = watch.watch_recheck_is_within_schedule(default_tz=datastore.data['settings']['application'].get('timezone', 'UTC'))
18131813
if not result:
1814-
logger.debug(f"{uuid} time scheduler - not within schedule skipping.")
1814+
logger.trace(f"{uuid} Time scheduler - not within schedule skipping.")
18151815
continue
18161816

18171817
# If they supplied an individual entry minutes to threshold.

changedetectionio/static/js/watch-settings.js

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
function toggleOpacity(checkboxSelector, fieldSelector, inverted) {
22
const checkbox = document.querySelector(checkboxSelector);
33
const fields = document.querySelectorAll(fieldSelector);
4+
45
function updateOpacity() {
56
const opacityValue = !checkbox.checked ? (inverted ? 0.6 : 1) : (inverted ? 1 : 0.6);
67
fields.forEach(field => {
78
field.style.opacity = opacityValue;
89
});
910
}
11+
1012
// Initial setup
1113
updateOpacity();
1214
checkbox.addEventListener('change', updateOpacity);
@@ -15,12 +17,14 @@ function toggleOpacity(checkboxSelector, fieldSelector, inverted) {
1517
function toggleVisibility(checkboxSelector, fieldSelector, inverted) {
1618
const checkbox = document.querySelector(checkboxSelector);
1719
const fields = document.querySelectorAll(fieldSelector);
20+
1821
function updateOpacity() {
1922
const opacityValue = !checkbox.checked ? (inverted ? 'none' : 'block') : (inverted ? 'block' : 'none');
2023
fields.forEach(field => {
2124
field.style.display = opacityValue;
2225
});
2326
}
27+
2428
// Initial setup
2529
updateOpacity();
2630
checkbox.addEventListener('change', updateOpacity);
@@ -45,7 +49,6 @@ function getTimeInTimezone(timezone) {
4549
}
4650

4751

48-
4952
function request_textpreview_update() {
5053
if (!$('body').hasClass('preview-text-enabled')) {
5154
console.error("Preview text was requested but body tag was not setup")
@@ -92,6 +95,8 @@ function request_textpreview_update() {
9295

9396

9497
$(document).ready(function () {
98+
let exceedsLimit = false;
99+
const warning_text = $("#timespan-warning")
95100

96101
window.setInterval(function () {
97102
if ($("#time_schedule_limit-timezone").val().length) {
@@ -102,12 +107,39 @@ $(document).ready(function () {
102107
document.getElementById('local-time-in-tz').textContent =
103108
getTimeInTimezone($("#time_schedule_limit-timezone").attr('placeholder'));
104109
}
110+
let allOk = true;
111+
112+
$("li.day-schedule").each(function () {
113+
const $schedule = $(this);
114+
const $checkbox = $schedule.find("input[type='checkbox']");
115+
116+
if ($checkbox.is(":checked")) {
117+
const timeValue = $schedule.find("input[type='time']").val();
118+
const durationHours = parseInt($schedule.find("select[name*='-duration-hours']").val(), 10) || 0;
119+
const durationMinutes = parseInt($schedule.find("select[name*='-duration-minutes']").val(), 10) || 0;
120+
121+
if (timeValue) {
122+
const [startHours, startMinutes] = timeValue.split(":").map(Number);
123+
const totalMinutes = (startHours * 60 + startMinutes) + (durationHours * 60 + durationMinutes);
124+
125+
exceedsLimit = totalMinutes > 1440
126+
if (exceedsLimit) {
127+
allOk = false
128+
}
129+
$schedule.toggleClass("warning", exceedsLimit);
130+
}
131+
} else {
132+
$schedule.toggleClass("warning", false);
133+
}
134+
});
135+
136+
warning_text.toggle(!allOk)
105137
}, 500);
106138

107139
$('#time_schedule_limit-saturday, #time_schedule_limit-sunday').addClass("weekend-day")
108140

109-
$(document).on('click', '[data-template].set-schedule', function() {
110-
// Get the value of the 'data-template' attribute
141+
$(document).on('click', '[data-template].set-schedule', function () {
142+
// Get the value of the 'data-template' attribute
111143

112144
switch ($(this).attr('data-template')) {
113145
case 'business-hours':
@@ -138,7 +170,7 @@ $(document).ready(function () {
138170
break;
139171
}
140172
});
141-
173+
142174
$('#notification-setting-reset-to-default').click(function (e) {
143175
$('#notification_title').val('');
144176
$('#notification_body').val('');
@@ -155,8 +187,8 @@ $(document).ready(function () {
155187
toggleVisibility('#time_schedule_limit-enabled', '#schedule-day-limits-wrapper', true)
156188

157189
const vh = Math.max(document.documentElement.clientHeight || 0, window.innerHeight || 0);
158-
$("#text-preview-inner").css('max-height', (vh-300)+"px");
159-
$("#text-preview-before-inner").css('max-height', (vh-300)+"px");
190+
$("#text-preview-inner").css('max-height', (vh - 300) + "px");
191+
$("#text-preview-before-inner").css('max-height', (vh - 300) + "px");
160192

161193
$("#activate-text-preview").click(function (e) {
162194
$('body').toggleClass('preview-text-enabled')

changedetectionio/templates/_helpers.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@
7878
padding-left: 0.5rem;
7979
padding-right: 0.5rem;
8080
}
81+
#timespan-warning {
82+
color: #ff0000;
83+
}
84+
.day-schedule.warning table {
85+
background-color: #ffbbc2;
86+
}
8187
ul#day-wrapper {
8288
list-style: none;
8389
}
@@ -121,6 +127,8 @@
121127
{{ render_nolabel_field(form.time_schedule_limit[day]) }}
122128
</li>
123129
{% endfor %}
130+
<li id="timespan-warning">Warning, one or more of your 'days' has a duration that would extend into the next day.<br>
131+
This could have unintended consequences.</li>
124132
<li id="timezone-info">
125133
{{ render_field(form.time_schedule_limit.timezone) }} <span id="local-time-in-tz"></span>
126134
<datalist id="timezones" style="display: none;">

0 commit comments

Comments
 (0)