diff --git a/changedetectionio/blueprint/watchlist/templates/watch-overview.html b/changedetectionio/blueprint/watchlist/templates/watch-overview.html
index fcad5582..e7896505 100644
--- a/changedetectionio/blueprint/watchlist/templates/watch-overview.html
+++ b/changedetectionio/blueprint/watchlist/templates/watch-overview.html
@@ -209,15 +209,18 @@
Edit
{% if watch.history_n >= 2 %}
+ {% set open_diff_in_new_tab = datastore.data['settings']['application']['ui'].get('open_diff_in_new_tab') %}
+ {% set target_attr = ' target="' ~ watch.uuid ~ '"' if open_diff_in_new_tab else '' %}
+
{% if is_unviewed %}
-
History
+
History
{% else %}
-
History
+
History
{% endif %}
{% else %}
{% if watch.history_n == 1 or (watch.history_n ==0 and watch.error_text_ctime )%}
-
Preview
+
Preview
{% endif %}
{% endif %}
diff --git a/changedetectionio/forms.py b/changedetectionio/forms.py
index 559516da..7561d540 100644
--- a/changedetectionio/forms.py
+++ b/changedetectionio/forms.py
@@ -721,6 +721,8 @@ class globalSettingsRequestForm(Form):
self.extra_proxies.errors.append('Both a name, and a Proxy URL is required.')
return False
+class globalSettingsApplicationUIForm(Form):
+ open_diff_in_new_tab = BooleanField('Open diff page in a new tab', default=True, validators=[validators.Optional()])
# datastore.data['settings']['application']..
class globalSettingsApplicationForm(commonSettingsForm):
@@ -752,6 +754,7 @@ class globalSettingsApplicationForm(commonSettingsForm):
render_kw={"style": "width: 5em;"},
validators=[validators.NumberRange(min=0,
message="Should contain zero or more attempts")])
+ ui = FormField(globalSettingsApplicationUIForm)
class globalSettingsForm(Form):
diff --git a/changedetectionio/model/App.py b/changedetectionio/model/App.py
index 6e564630..34809017 100644
--- a/changedetectionio/model/App.py
+++ b/changedetectionio/model/App.py
@@ -60,6 +60,9 @@ class model(dict):
'webdriver_delay': None , # Extra delay in seconds before extracting text
'tags': {}, #@todo use Tag.model initialisers
'timezone': None, # Default IANA timezone name
+ 'ui': {
+ 'open_diff_in_new_tab': True,
+ },
}
}
}
diff --git a/changedetectionio/tests/test_ui.py b/changedetectionio/tests/test_ui.py
new file mode 100644
index 00000000..743b70b5
--- /dev/null
+++ b/changedetectionio/tests/test_ui.py
@@ -0,0 +1,80 @@
+#!/usr/bin/env python3
+
+from flask import url_for
+from .util import set_original_response, set_modified_response, live_server_setup, wait_for_all_checks
+
+def test_checkbox_open_diff_in_new_tab(client, live_server):
+
+ set_original_response()
+ live_server_setup(live_server)
+
+ # Add our URL to the import page
+ res = client.post(
+ url_for("imports.import_page"),
+ data={"urls": url_for('test_endpoint', _external=True)},
+ follow_redirects=True
+ )
+
+ assert b"1 Imported" in res.data
+ wait_for_all_checks(client)
+
+ # Make a change
+ set_modified_response()
+
+ # Test case 1 - checkbox is enabled in settings
+ res = client.post(
+ url_for("settings.settings_page"),
+ data={"application-ui-open_diff_in_new_tab": "1"},
+ follow_redirects=True
+ )
+ assert b'Settings updated' in res.data
+
+ # Force recheck
+ res = client.get(url_for("ui.form_watch_checknow"), follow_redirects=True)
+ assert b'Queued 1 watch for rechecking.' in res.data
+
+ wait_for_all_checks(client)
+
+ res = client.get(url_for("watchlist.index"))
+ lines = res.data.decode().split("\n")
+
+ # Find link to diff page
+ target_line = None
+ for line in lines:
+ if '/diff' in line:
+ target_line = line.strip()
+ break
+
+ assert target_line != None
+ assert 'target=' in target_line
+
+ # Test case 2 - checkbox is disabled in settings
+ res = client.post(
+ url_for("settings.settings_page"),
+ data={"application-ui-open_diff_in_new_tab": ""},
+ follow_redirects=True
+ )
+ assert b'Settings updated' in res.data
+
+ # Force recheck
+ res = client.get(url_for("ui.form_watch_checknow"), follow_redirects=True)
+ assert b'Queued 1 watch for rechecking.' in res.data
+
+ wait_for_all_checks(client)
+
+ res = client.get(url_for("watchlist.index"))
+ lines = res.data.decode().split("\n")
+
+ # Find link to diff page
+ target_line = None
+ for line in lines:
+ if '/diff' in line:
+ target_line = line.strip()
+ break
+
+ assert target_line != None
+ assert 'target=' not in target_line
+
+ # Cleanup everything
+ res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True)
+ assert b'Deleted' in res.data