From 5bd9eaf99d2b92d5357ca6f7ae48fb3234fc3ae3 Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Thu, 28 Jul 2022 12:13:26 +0200 Subject: [PATCH] UI Feature - Add watch in "paused" state, saving then unpauses (#779) --- changedetectionio/.gitignore | 1 + changedetectionio/__init__.py | 24 ++++++++++++++----- changedetectionio/forms.py | 3 +++ changedetectionio/static/styles/styles.css | 13 ++++++---- changedetectionio/static/styles/styles.scss | 17 +++++++++---- changedetectionio/templates/edit.html | 2 +- .../templates/watch-overview.html | 17 +++++++++---- .../tests/test_filter_failure_notification.py | 2 +- changedetectionio/tests/test_notification.py | 4 ++-- .../tests/test_notification_errors.py | 2 +- 10 files changed, 60 insertions(+), 25 deletions(-) diff --git a/changedetectionio/.gitignore b/changedetectionio/.gitignore index 1d463784..0d3c1d4e 100644 --- a/changedetectionio/.gitignore +++ b/changedetectionio/.gitignore @@ -1 +1,2 @@ test-datastore +package-lock.json diff --git a/changedetectionio/__init__.py b/changedetectionio/__init__.py index 2b10ace3..da08d12e 100644 --- a/changedetectionio/__init__.py +++ b/changedetectionio/__init__.py @@ -580,6 +580,9 @@ def changedetection_app(config=None, datastore_o=None): if request.method == 'POST' and form.validate(): extra_update_obj = {} + if request.args.get('unpause_on_save'): + extra_update_obj['paused'] = False + # Re #110, if they submit the same as the default value, set it to None, so we continue to follow the default # Assume we use the default value, unless something relevant is different, then use the form value # values could be None, 0 etc. @@ -619,7 +622,10 @@ def changedetection_app(config=None, datastore_o=None): datastore.data['watching'][uuid].update(form.data) datastore.data['watching'][uuid].update(extra_update_obj) - flash("Updated watch.") + if request.args.get('unpause_on_save'): + flash("Updated watch - unpaused!.") + else: + flash("Updated watch.") # Re #286 - We wait for syncing new data to disk in another thread every 60 seconds # But in the case something is added we should save straight away @@ -1063,9 +1069,9 @@ def changedetection_app(config=None, datastore_o=None): except FileNotFoundError: abort(404) - @app.route("/api/add", methods=['POST']) + @app.route("/form/add/quickwatch", methods=['POST']) @login_required - def form_watch_add(): + def form_quick_watch_add(): from changedetectionio import forms form = forms.quickWatchForm(request.form) @@ -1078,13 +1084,19 @@ def changedetection_app(config=None, datastore_o=None): flash('The URL {} already exists'.format(url), "error") return redirect(url_for('index')) - # @todo add_watch should throw a custom Exception for validation etc - new_uuid = datastore.add_watch(url=url, tag=request.form.get('tag').strip()) - if new_uuid: + add_paused = request.form.get('edit_and_watch_submit_button') != None + new_uuid = datastore.add_watch(url=url, tag=request.form.get('tag').strip(), extras={'paused': add_paused}) + + + if not add_paused and new_uuid: # Straight into the queue. update_q.put(new_uuid) flash("Watch added.") + if add_paused: + flash('Watch added in Paused state, saving will unpause.') + return redirect(url_for('edit_page', uuid=new_uuid, unpause_on_save=1)) + return redirect(url_for('index')) diff --git a/changedetectionio/forms.py b/changedetectionio/forms.py index 9d29c5c1..7a307a5b 100644 --- a/changedetectionio/forms.py +++ b/changedetectionio/forms.py @@ -308,6 +308,9 @@ class ValidateCSSJSONXPATHInput(object): class quickWatchForm(Form): url = fields.URLField('URL', validators=[validateURL()]) tag = StringField('Group tag', [validators.Optional()]) + watch_submit_button = SubmitField('Watch', render_kw={"class": "pure-button pure-button-primary"}) + edit_and_watch_submit_button = SubmitField('Edit > Watch', render_kw={"class": "pure-button pure-button-primary"}) + # Common to a single watch and the global settings class commonSettingsForm(Form): diff --git a/changedetectionio/static/styles/styles.css b/changedetectionio/static/styles/styles.css index 0acbbd9c..f3878fb6 100644 --- a/changedetectionio/static/styles/styles.css +++ b/changedetectionio/static/styles/styles.css @@ -1,9 +1,7 @@ /* * -- BASE STYLES -- * Most of these are inherited from Base, but I want to change a few. - * nvm use v14.18.1 - * npm install - * npm run build + * nvm use v14.18.1 && npm install && npm run build * or npm run watch */ body { @@ -203,13 +201,18 @@ body:after, body:before { border-radius: 10px; margin-bottom: 1em; } #new-watch-form input { - width: auto !important; - display: inline-block; } + display: inline-block; + margin-bottom: 5px; } #new-watch-form .label { display: none; } #new-watch-form legend { color: #fff; font-weight: bold; } + #new-watch-form #watch-add-wrapper-zone > div { + display: inline-block; } + @media only screen and (max-width: 760px) { + #new-watch-form #watch-add-wrapper-zone #url { + width: 100%; } } #diff-col { padding-left: 40px; } diff --git a/changedetectionio/static/styles/styles.scss b/changedetectionio/static/styles/styles.scss index 76e33b22..761235fe 100644 --- a/changedetectionio/static/styles/styles.scss +++ b/changedetectionio/static/styles/styles.scss @@ -1,9 +1,7 @@ /* * -- BASE STYLES -- * Most of these are inherited from Base, but I want to change a few. - * nvm use v14.18.1 - * npm install - * npm run build + * nvm use v14.18.1 && npm install && npm run build * or npm run watch */ body { @@ -269,8 +267,8 @@ body:after, body:before { border-radius: 10px; margin-bottom: 1em; input { - width: auto !important; display: inline-block; + margin-bottom: 5px; } .label { display: none; @@ -279,6 +277,17 @@ body:after, body:before { color: #fff; font-weight: bold; } + + #watch-add-wrapper-zone { + > div { + display: inline-block; + } + @media only screen and (max-width: 760px) { + #url { + width: 100%; + } + } + } } diff --git a/changedetectionio/templates/edit.html b/changedetectionio/templates/edit.html index 8541d957..c26ed475 100644 --- a/changedetectionio/templates/edit.html +++ b/changedetectionio/templates/edit.html @@ -33,7 +33,7 @@
+ action="{{ url_for('edit_page', uuid=uuid, next = request.args.get('next'), unpause_on_save = request.args.get('unpause_on_save')) }}" method="POST">
diff --git a/changedetectionio/templates/watch-overview.html b/changedetectionio/templates/watch-overview.html index 5ac0eef8..0b20f3c3 100644 --- a/changedetectionio/templates/watch-overview.html +++ b/changedetectionio/templates/watch-overview.html @@ -1,18 +1,25 @@ {% extends 'base.html' %} {% block content %} -{% from '_helpers.jinja' import render_simple_field %} +{% from '_helpers.jinja' import render_simple_field, render_field %}
- +
Add a new change detection watch - {{ render_simple_field(form.url, placeholder="https://...", required=true) }} - {{ render_simple_field(form.tag, value=active_tag if active_tag else '', placeholder="watch group") }} - +
+
+ {{ render_simple_field(form.url, placeholder="https://...", required=true) }} + {{ render_simple_field(form.tag, value=active_tag if active_tag else '', placeholder="watch group") }} +
+
+ {{ render_simple_field(form.watch_submit_button, title="Watch this URL!" ) }} + {{ render_simple_field(form.edit_and_watch_submit_button, title="Edit first then Watch") }} +
+
Tip: You can also add 'shared' watches. More info diff --git a/changedetectionio/tests/test_filter_failure_notification.py b/changedetectionio/tests/test_filter_failure_notification.py index c2bbe296..da4c9720 100644 --- a/changedetectionio/tests/test_filter_failure_notification.py +++ b/changedetectionio/tests/test_filter_failure_notification.py @@ -30,7 +30,7 @@ def run_filter_test(client, content_filter): # Add our URL to the import page test_url = url_for('test_endpoint', _external=True) res = client.post( - url_for("form_watch_add"), + url_for("form_quick_watch_add"), data={"url": test_url, "tag": ''}, follow_redirects=True ) diff --git a/changedetectionio/tests/test_notification.py b/changedetectionio/tests/test_notification.py index 88c5e319..29b7e00d 100644 --- a/changedetectionio/tests/test_notification.py +++ b/changedetectionio/tests/test_notification.py @@ -36,7 +36,7 @@ def test_check_notification(client, live_server): # Add our URL to the import page test_url = url_for('test_endpoint', _external=True) res = client.post( - url_for("form_watch_add"), + url_for("form_quick_watch_add"), data={"url": test_url, "tag": ''}, follow_redirects=True ) @@ -172,7 +172,7 @@ def test_notification_validation(client, live_server): # Add our URL to the import page test_url = url_for('test_endpoint', _external=True) res = client.post( - url_for("form_watch_add"), + url_for("form_quick_watch_add"), data={"url": test_url, "tag": 'nice one'}, follow_redirects=True ) diff --git a/changedetectionio/tests/test_notification_errors.py b/changedetectionio/tests/test_notification_errors.py index 6c57340e..1d51309a 100644 --- a/changedetectionio/tests/test_notification_errors.py +++ b/changedetectionio/tests/test_notification_errors.py @@ -16,7 +16,7 @@ def test_check_notification_error_handling(client, live_server): # use a different URL so that it doesnt interfere with the actual check until we are ready test_url = url_for('test_endpoint', _external=True) res = client.post( - url_for("form_watch_add"), + url_for("form_quick_watch_add"), data={"url": "https://changedetection.io/CHANGELOG.txt", "tag": ''}, follow_redirects=True )