Fix small issue in highlight trigger/ignore preview page with setting the background colours, add test

pull/435/head
dgtlmoon 3 years ago
parent b401998030
commit a51c555964

@ -764,6 +764,8 @@ def changedetection_app(config=None, datastore_o=None):
@login_required @login_required
def preview_page(uuid): def preview_page(uuid):
content = [] content = []
ignored_line_numbers = []
trigger_line_numbers = []
# More for testing, possible to return the first/only # More for testing, possible to return the first/only
if uuid == 'first': if uuid == 'first':
@ -782,25 +784,38 @@ def changedetection_app(config=None, datastore_o=None):
filename = watch['history'][timestamps[-1]] filename = watch['history'][timestamps[-1]]
try: try:
with open(filename, 'r') as f: with open(filename, 'r') as f:
content = f.readlines() tmp = f.readlines()
except:
content.append("File doesnt exist or unable to read file {}".format(filename))
else:
content.append("No history found")
# Get what needs to be highlighted # Get what needs to be highlighted
ignore_rules = watch.get('ignore_text', []) + datastore.data['settings']['application']['global_ignore_text'] ignore_rules = watch.get('ignore_text', []) + datastore.data['settings']['application']['global_ignore_text']
# .readlines will keep the \n, but we will parse it here again, in the future tidy this up # .readlines will keep the \n, but we will parse it here again, in the future tidy this up
ignored_line_numbers = html_tools.strip_ignore_text(content="".join(content), ignored_line_numbers = html_tools.strip_ignore_text(content="".join(tmp),
wordlist=ignore_rules, wordlist=ignore_rules,
mode='line numbers' mode='line numbers'
) )
trigger_line_numbers = html_tools.strip_ignore_text(content="".join(content), trigger_line_numbers = html_tools.strip_ignore_text(content="".join(tmp),
wordlist=watch['trigger_text'], wordlist=watch['trigger_text'],
mode='line numbers' mode='line numbers'
) )
# Prepare the classes and lines used in the template
i=0
for l in tmp:
classes=[]
i+=1
if i in ignored_line_numbers:
classes.append('ignored')
if i in trigger_line_numbers:
classes.append('triggered')
content.append({'line': l, 'classes': ' '.join(classes)})
except Exception as e:
content.append({'line': "File doesnt exist or unable to read file {}".format(filename), 'classes': ''})
else:
content.append({'line': "No history found", 'classes': ''})
output = render_template("preview.html", output = render_template("preview.html",
content=content, content=content,

@ -13,10 +13,7 @@
<tr> <tr>
<td id="diff-col"> <td id="diff-col">
{% for row in content %} {% for row in content %}
{% set classes = [] %} <div class="{{row.classes}}">{{row.line}}</div>
{% if (loop.index in ignored_line_numbers) %}{{ classes.append("ignored") }}{% endif %}
{% if (loop.index in triggered_line_numbers) %}{{ classes.append("triggered") }}{% endif %}
<div class="{{ classes|join(' ') }}">{{row}}</div>
{% endfor %} {% endfor %}
</td> </td>
</tr> </tr>

Loading…
Cancel
Save