Proof of concept for #160, 'Allow recheck time in seconds'. Currently retains 'minutes_between_check' key:value, so I'm requesting a review before globally renaming it 'to duration_between_check' or similar.

pull/317/head
ntmmfts 3 years ago
parent a37a5038d8
commit a7763ae9a3

@ -456,6 +456,7 @@ def changedetection_app(config=None, datastore_o=None):
update_obj = {'url': form.url.data.strip(), update_obj = {'url': form.url.data.strip(),
'minutes_between_check': form.minutes_between_check.data, 'minutes_between_check': form.minutes_between_check.data,
'use_seconds': form.use_seconds.data,
'tag': form.tag.data.strip(), 'tag': form.tag.data.strip(),
'title': form.title.data.strip(), 'title': form.title.data.strip(),
'headers': form.headers.data, 'headers': form.headers.data,
@ -972,8 +973,8 @@ def ticker_thread_check_time_launch_checks():
for uuid, watch in copied_datastore.data['watching'].items(): for uuid, watch in copied_datastore.data['watching'].items():
# If they supplied an individual entry minutes to threshold. # If they supplied an individual entry minutes to threshold.
if 'minutes_between_check' in watch and watch['minutes_between_check'] is not None: if 'minutes_between_check' in watch and watch['minutes_between_check'] is not None:
# Cast to int just incase # Cast to int just incase #160, kluge for checks in seconds
max_time = int(watch['minutes_between_check']) * 60 max_time = int(watch['minutes_between_check']) * (1 if watch['use_seconds'] else 60)
else: else:
# Default system wide. # Default system wide.
max_time = int(copied_datastore.data['settings']['requests']['minutes_between_check']) * 60 max_time = int(copied_datastore.data['settings']['requests']['minutes_between_check']) * 60

@ -229,6 +229,7 @@ class watchForm(commonSettingsForm):
minutes_between_check = html5.IntegerField('Maximum time in minutes until recheck', minutes_between_check = html5.IntegerField('Maximum time in minutes until recheck',
[validators.Optional(), validators.NumberRange(min=1)]) [validators.Optional(), validators.NumberRange(min=1)])
use_seconds = BooleanField('Use seconds')
css_filter = StringField('CSS/JSON Filter', [ValidateCSSJSONInput()]) css_filter = StringField('CSS/JSON Filter', [ValidateCSSJSONInput()])
title = StringField('Title') title = StringField('Title')

@ -1,10 +1,13 @@
// Rewrite this is a plugin.. is all this JS really 'worth it?' // Rewrite this is a plugin.. is all this JS really 'worth it?'
// display correct label and messages for minutes or seconds
document.addEventListener("DOMContentLoaded", function(event) {
use_seconds_change();
});
window.addEventListener('hashchange', function() { window.addEventListener('hashchange', function() {
var tabs = document.getElementsByClassName('active'); var tabs = document.getElementsByClassName('active');
while (tabs[0]) { while (tabs[0]) {
tabs[0].classList.remove('active') tabs[0].classList.remove('active');
} }
set_active_tab(); set_active_tab();
}, false); }, false);
@ -37,7 +40,7 @@ function focus_error_tab() {
var tabs = document.querySelectorAll('.tabs li a'),i; var tabs = document.querySelectorAll('.tabs li a'),i;
for (i = 0; i < tabs.length; ++i) { for (i = 0; i < tabs.length; ++i) {
var tab_name=tabs[i].hash.replace('#',''); var tab_name=tabs[i].hash.replace('#','');
var pane_errors=document.querySelectorAll('#'+tab_name+' .error') var pane_errors=document.querySelectorAll('#'+tab_name+' .error');
if (pane_errors.length) { if (pane_errors.length) {
document.location.hash = '#'+tab_name; document.location.hash = '#'+tab_name;
return true; return true;
@ -46,6 +49,38 @@ function focus_error_tab() {
return false; return false;
} }
function use_seconds_change() {
var isChecked = document.querySelectorAll('input[id="use_seconds"]:checked').length
var labelIntegerField = document.querySelector("label[for=minutes_between_check]");
var msgDefault = document.getElementById("minutes-message-default");
var msgNonDefault = document.getElementById("minutes-message-non-default");
var msgWarning = document.getElementById("seconds-warning");
if (isChecked) {
labelIntegerField.innerHTML = "Maximum time in seconds until recheck";
try {
msgDefault.style.display = "none";
} catch(error) {
// continue, won't be present if not default interval
}
try {
msgNonDefault.style.display = "none";
} catch(error) {
// continue, won't be present if not default interval
}
msgWarning.style.display = "";
}
else {
labelIntegerField.innerHTML = "Maximum time in minutes until recheck";
try {
msgDefault.style.display = "";
} catch(error) {
// continue, won't be present if not default interval
}
try {
msgNonDefault.style.display = "";
} catch(error) {
// continue, won't be present if not default interval
}
msgWarning.style.display = "none";
}
}

File diff suppressed because one or more lines are too long

@ -67,6 +67,8 @@ class ChangeDetectionStore:
# Re #110, so then if this is set to None, we know to use the default value instead # Re #110, so then if this is set to None, we know to use the default value instead
# Requires setting to None on submit if it's the same as the default # Requires setting to None on submit if it's the same as the default
'minutes_between_check': None, 'minutes_between_check': None,
# #160
'use_seconds': False,
'previous_md5': "", 'previous_md5': "",
'uuid': str(uuid_builder.uuid4()), 'uuid': str(uuid_builder.uuid4()),
'headers': {}, # Extra headers to send 'headers': {}, # Extra headers to send

@ -34,15 +34,18 @@
<div class="pure-control-group"> <div class="pure-control-group">
{{ render_field(form.minutes_between_check) }} {{ render_field(form.minutes_between_check) }}
{% if using_default_minutes %} {% if using_default_minutes %}
<span class="pure-form-message-inline">Currently using the <a <span id="minutes-message-default" class="pure-form-message-inline">Currently using the <a
href="{{ url_for('settings_page', uuid=uuid) }}">default global settings</a>, change to another value if you want to be specific.</span> href="{{ url_for('settings_page', uuid=uuid) }}">default global settings</a>, change to another value if you want to be specific.</span>
{% else %} {% else %}
<span class="pure-form-message-inline">Set to blank to use the <a <span id="minutes-message-non-default" class="pure-form-message-inline">Set to blank to use the <a
href="{{ url_for('settings_page', uuid=uuid) }}">default global settings</a>.</span> href="{{ url_for('settings_page', uuid=uuid) }}">default global settings</a>.</span>
{% endif %} {% endif %}
</div> </div>
<div class="pure-control-group"> <div class="pure-control-group">
{{ render_field(form.extract_title_as_title) }} {{ render_field(form.use_seconds, onchange="use_seconds_change()") }}
<span id="seconds-warning" class="pure-form-message-inline" style="display:{{'' if watch.use_seconds == True else 'none'}};">Warning: Setting the recheck duration too short can overload the queue and lead to
unstable performance and application crashes. Test and adjust the duration to ensure
it allows sufficent time to check the target website before queing the watch again.</span>
</div> </div>
</fieldset> </fieldset>
</div> </div>

Loading…
Cancel
Save