Skip to content

Commit

Permalink
UI - Live preview - misc improvements (Adding test, fixes to filters) (
Browse files Browse the repository at this point in the history
  • Loading branch information
dgtlmoon authored Sep 30, 2024
1 parent 1b625dc commit 5b34aec
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 10 deletions.
1 change: 1 addition & 0 deletions changedetectionio/flask_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1432,6 +1432,7 @@ def watch_get_preview_rendered(uuid):
)
# Use the last loaded HTML as the input
update_handler.fetcher.content = decompressed_data
update_handler.fetcher.headers['content-type'] = tmp_watch.get('content-type')
try:
changed_detected, update_obj, contents, text_after_filter = update_handler.run_changedetection(
watch=tmp_watch,
Expand Down
1 change: 1 addition & 0 deletions changedetectionio/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def __init__(self, *arg, **kw):
'check_count': 0,
'check_unique_lines': False, # On change-detected, compare against all history if its something new
'consecutive_filter_failures': 0, # Every time the CSS/xPath filter cannot be located, reset when all is fine.
'content-type': None,
'date_created': None,
'extract_text': [], # Extract text by regex after filters
'extract_title_as_title': False,
Expand Down
2 changes: 1 addition & 1 deletion changedetectionio/processors/text_json_diff/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def run_changedetection(self, watch, skip_when_checksum_same=True):
stripped_text_from_html = '\n'.join(line.strip() for line in stripped_text_from_html.replace("\n\n", "\n").splitlines())

if watch.get('remove_duplicate_lines'):
stripped_text_from_html = '\n'.join(dict.fromkeys(line.strip() for line in stripped_text_from_html.replace("\n\n", "\n").splitlines()))
stripped_text_from_html = '\n'.join(dict.fromkeys(line for line in stripped_text_from_html.replace("\n\n", "\n").splitlines()))

if watch.get('sort_text_alphabetically'):
# Note: Because a <p>something</p> will add an extra line feed to signify the paragraph gap
Expand Down
16 changes: 8 additions & 8 deletions changedetectionio/static/js/watch-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ function toggleOpacity(checkboxSelector, fieldSelector, inverted) {

function request_textpreview_update() {
if (!$('body').hasClass('preview-text-enabled')) {
console.error("Preview text was requested but body tag was not setup")
return
}

Expand Down Expand Up @@ -77,20 +78,19 @@ $(document).ready(function () {

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

// Realtime preview of 'Filters & Text' setup
var debounced_request_textpreview_update = request_textpreview_update.debounce(100);

$("#activate-text-preview").click(function (e) {
$(this).fadeOut();
$('body').toggleClass('preview-text-enabled')

request_textpreview_update();

$("#text-preview-refresh").click(function (e) {
request_textpreview_update();
});
$('textarea:visible').on('keyup blur', debounced_request_textpreview_update);
$('input:visible').on('keyup blur change', debounced_request_textpreview_update);
$("#filters-and-triggers-tab").on('click', debounced_request_textpreview_update);
const method = $('body').hasClass('preview-text-enabled') ? 'on' : 'off';
$("#text-preview-refresh")[method]('click', debounced_request_textpreview_update);
$('textarea:visible')[method]('keyup blur', debounced_request_textpreview_update);
$('input:visible')[method]('keyup blur change', debounced_request_textpreview_update);
$("#filters-and-triggers-tab")[method]('click', debounced_request_textpreview_update);
});

});
Expand Down
7 changes: 6 additions & 1 deletion changedetectionio/tests/test_encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import time
from flask import url_for
from .util import live_server_setup, wait_for_all_checks
from .util import live_server_setup, wait_for_all_checks, extract_UUID_from_client
import pytest


Expand Down Expand Up @@ -38,6 +38,11 @@ def test_check_encoding_detection(client, live_server, measure_memory_usage):
# Give the thread time to pick it up
wait_for_all_checks(client)


# Content type recording worked
uuid = extract_UUID_from_client(client)
assert live_server.app.config['DATASTORE'].data['watching'][uuid]['content-type'] == "text/html"

res = client.get(
url_for("preview_page", uuid="first"),
follow_redirects=True
Expand Down
2 changes: 2 additions & 0 deletions changedetectionio/update_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,8 @@ def run(self):
if not self.datastore.data['watching'].get(uuid):
continue

update_obj['content-type'] = update_handler.fetcher.get_all_headers().get('content-type', '').lower()

# Mark that we never had any failures
if not watch.get('ignore_status_codes'):
update_obj['consecutive_filter_failures'] = 0
Expand Down

0 comments on commit 5b34aec

Please sign in to comment.