This commit is contained in:
dgtlmoon
2025-05-16 17:53:25 +02:00
parent 24afe0ed3d
commit 2660bb3bb3
6 changed files with 54 additions and 42 deletions

View File

@@ -105,8 +105,7 @@
<tr id="{{ watch.uuid }}" data-watch-uuid="{{ watch.uuid }}"
class="{{ loop.cycle('pure-table-odd', 'pure-table-even') }} processor-{{ watch['processor'] }}
{# socket.js also sets these vars on the row for update #}
{% if watch.render_errors_as_text %}has-error{% endif %}
{% if watch.last_notification_error is defined and watch.last_notification_error != False %}error{% endif %}
{% if watch.compile_error_texts()|length >2 %}has-error{% endif %}
{% if watch.paused is defined and watch.paused != False %}paused{% endif %}
{% if watch.has_unviewed %}unviewed{% endif %}
{% if watch.has_restock_info %} has-restock-info {% if watch['restock']['in_stock'] %}in-stock{% else %}not-in-stock{% endif %} {% else %}no-restock-info{% endif %}
@@ -133,10 +132,10 @@
<img class="status-icon" src="{{url_for('static_content', group='images', filename='google-chrome-icon.png')}}" alt="Using a Chrome browser" title="Using a Chrome browser" >
{% endif %}
{%if watch.is_pdf %}<img class="status-icon" src="{{url_for('static_content', group='images', filename='pdf-icon.svg')}}" alt="Converting PDF to text" >{% endif %}
{% if watch.is_pdf %}<img class="status-icon" src="{{url_for('static_content', group='images', filename='pdf-icon.svg')}}" alt="Converting PDF to text" >{% endif %}
{% if watch.has_browser_steps %}<img class="status-icon status-browsersteps" src="{{url_for('static_content', group='images', filename='steps.svg')}}" alt="Browser Steps is enabled" >{% endif %}
<div class="error-text">{{ watch.compile_error_texts(has_proxies=datastore.proxy_list)|safe }}</div>
<div class="error-text" style="display:none;">{{ watch.compile_error_texts(has_proxies=datastore.proxy_list)|safe }}</div>
{% if watch['processor'] == 'text_json_diff' %}
{% if watch['has_ldjson_price_data'] and not watch['track_ldjson_price_data'] %}

View File

@@ -669,15 +669,28 @@ class model(watch_base):
output = [] # Initialize as list since we're using append
last_error = self.get('last_error','')
from flask import has_app_context, current_app
if last_error and '403' in last_error:
if has_proxies:
output.append(str(Markup(f"{last_error} - <a href=\"{url_for('settings.settings_page', uuid=self.get('uuid'))}\">Try other proxies/location</a>&nbsp;'")))
else:
output.append(str(Markup(f"{last_error} - <a href=\"{url_for('settings.settings_page', uuid=self.get('uuid'))}\">Try adding external proxies/locations</a>&nbsp;'")))
# has app+request context, we can use url_for()
if has_app_context:
if last_error:
if '403' in last_error:
if has_proxies:
output.append(str(Markup(f"{last_error} - <a href=\"{url_for('settings.settings_page', uuid=self.get('uuid'))}\">Try other proxies/location</a>&nbsp;'")))
else:
output.append(str(Markup(f"{last_error} - <a href=\"{url_for('settings.settings_page', uuid=self.get('uuid'))}\">Try adding external proxies/locations</a>&nbsp;'")))
else:
output.append(str(Markup(last_error)))
if self.get('last_notification_error'):
output.append(str(Markup(f"<div class=\"notification-error\"><a href=\"{url_for('settings.notification_logs')}\">{ self.get('last_notification_error') }</a></div>")))
if self.get('last_notification_error'):
output.append(str(Markup(f"<div class=\"notification-error\"><a href=\"{url_for('settings.notification_logs')}\">{ self.get('last_notification_error') }</a></div>")))
else:
# Lo_Fi version
if last_error:
output.append(str(Markup(last_error)))
if self.get('last_notification_error'):
output.append(str(Markup(self.get('last_notification_error'))))
res = "\n".join(output)
return res

View File

@@ -1,6 +1,5 @@
import timeago
from flask_socketio import SocketIO
from flask import has_app_context, current_app
import time
import os
@@ -88,12 +87,11 @@ def handle_watch_update(socketio, **kwargs):
queue_list.append(q_item.item['uuid'])
error_texts = ""
if has_app_context():
# So anything with 'url_for' etc needs to be triggered with app_context of the current app when sending the signal
# with app.app_context():
# watch_check_update.send(app_context=app, watch_uuid=uuid)
error_texts = watch.compile_error_texts()
error_texts = watch.compile_error_texts()
# Create a simplified watch data object to send to clients
watch_data = {
@@ -114,7 +112,7 @@ def handle_watch_update(socketio, **kwargs):
}
socketio.emit("watch_update", watch_data)
logger.debug(f"Socket.IO: Emitted update for watch {watch.get('uuid')}, Checking now: {watch_data['checking_now']}")
logger.trace(f"Socket.IO: Emitted update for watch {watch.get('uuid')}, Checking now: {watch_data['checking_now']}")
except Exception as e:
logger.error(f"Socket.IO error in handle_watch_update: {str(e)}")

View File

@@ -2,21 +2,24 @@
// @todo only bind ajax if the socket server attached success.
$(document).ready(function () {
$('.ajax-op').click(function (e) {
e.preventDefault();
$.ajax({
type: "POST",
url: ajax_toggle_url,
data: {'op': $(this).data('op'), 'uuid': $(this).closest('tr').data('watch-uuid')},
statusCode: {
400: function () {
// More than likely the CSRF token was lost when the server restarted
alert("There was a problem processing the request, please reload the page.");
function bindAjaxHandlerButtonsEvents() {
$('.ajax-op').on('click.ajaxHandlerNamespace', function (e) {
e.preventDefault();
$.ajax({
type: "POST",
url: ajax_toggle_url,
data: {'op': $(this).data('op'), 'uuid': $(this).closest('tr').data('watch-uuid')},
statusCode: {
400: function () {
// More than likely the CSRF token was lost when the server restarted
alert("There was a problem processing the request, please reload the page.");
}
}
}
});
return false;
});
return false;
});
}
// Only try to connect if authentication isn't required or user is authenticated
@@ -35,10 +38,12 @@ $(document).ready(function () {
// Connection status logging
socket.on('connect', function () {
console.log('Socket.IO connected');
bindAjaxHandlerButtonsEvents();
});
socket.on('disconnect', function () {
console.log('Socket.IO disconnected');
$('.ajax-op').off('.ajaxHandlerNamespace')
});
socket.on('queue_size', function (data) {
@@ -56,11 +61,11 @@ $(document).ready(function () {
$($watchRow).toggleClass('checking-now', watch.checking_now);
$($watchRow).toggleClass('queued', watch.queued);
$($watchRow).toggleClass('unviewed', watch.unviewed);
$($watchRow).toggleClass('error', watch.has_error);
$($watchRow).toggleClass('has-error', watch.has_error);
$($watchRow).toggleClass('notification_muted', watch.notification_muted);
$($watchRow).toggleClass('paused', watch.paused);
$('td.error-text', $watchRow).text(watch.error_text)
$('td.title-col .error-text', $watchRow).html(watch.error_text)
$('td.last-changed', $watchRow).text(watch.last_checked_text)

View File

@@ -7,11 +7,6 @@
&.unviewed {
font-weight: bold;
}
&.error {
color: var(--color-watch-table-error);
}
color: var(--color-watch-table-row-text);
}
@@ -112,9 +107,11 @@
}
}
tr.error {
.fetch-error {
display: inline-block !important;
tr.has-error {
color: var(--color-watch-table-error);
.error-text {
display: block !important;
}
}
}

View File

@@ -532,8 +532,6 @@ body.preview-text-enabled {
color: var(--color-watch-table-row-text); }
.watch-table tr.unviewed {
font-weight: bold; }
.watch-table tr.error {
color: var(--color-watch-table-error); }
.watch-table td {
white-space: nowrap; }
.watch-table td.title-col {
@@ -577,8 +575,10 @@ body.preview-text-enabled {
display: inline !important; }
.watch-table tr.notification_muted a.mute-toggle.state-off {
display: none !important; }
.watch-table tr.error .fetch-error {
display: inline-block !important; }
.watch-table tr.has-error {
color: var(--color-watch-table-error); }
.watch-table tr.has-error .error-text {
display: block !important; }
ul#conditions_match_logic {
list-style: none; }