add notifications and error messages to settings page

This commit is contained in:
simon 2021-12-17 15:09:21 +07:00
parent 8e976922e9
commit a500f9ec63
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
5 changed files with 32 additions and 6 deletions

View File

@ -175,11 +175,30 @@ class ScheduleBuilder:
for key, value in form_post.items(): for key, value in form_post.items():
to_check = value[0] to_check = value[0]
if key in self.SCHEDULES and to_check: if key in self.SCHEDULES and to_check:
try:
to_write = self.value_builder(key, to_check) to_write = self.value_builder(key, to_check)
except ValueError:
print(f"failed: {key} {to_check}")
mess_dict = {
"status": "message:setting",
"level": "error",
"title": "Scheduler update failed.",
"message": "Invalid schedule input",
}
RedisArchivist().set_message("message:setting", mess_dict)
return
redis_config["scheduler"][key] = to_write redis_config["scheduler"][key] = to_write
if key in self.CONFIG and to_check: if key in self.CONFIG and to_check:
redis_config["scheduler"][key] = int(to_check) redis_config["scheduler"][key] = int(to_check)
RedisArchivist().set_message("config", redis_config, expire=False) RedisArchivist().set_message("config", redis_config, expire=False)
mess_dict = {
"status": "message:setting",
"level": "info",
"title": "Scheduler changed.",
"message": "Please restart container for changes to take effect",
}
RedisArchivist().set_message("message:setting", mess_dict)
def value_builder(self, key, to_check): def value_builder(self, key, to_check):
"""validate single cron form entry and return cron dict""" """validate single cron form entry and return cron dict"""
@ -196,7 +215,8 @@ class ScheduleBuilder:
values = to_check.split() values = to_check.split()
if len(keys) != len(values): if len(keys) != len(values):
raise ValueError(f"failed to parse {to_check} for {key}") print(f"failed to parse {to_check} for {key}")
raise ValueError("invalid input")
to_write = dict(zip(keys, values)) to_write = dict(zip(keys, values))
if "*" in to_write["minute"]: if "*" in to_write["minute"]:

View File

@ -162,6 +162,7 @@ class RedisArchivist:
"subchannel", "subchannel",
"subplaylist", "subplaylist",
"playlistscan", "playlistscan",
"setting",
] ]
def __init__(self): def __init__(self):

View File

@ -1,6 +1,8 @@
{% extends "home/base.html" %} {% extends "home/base.html" %}
{% load static %}
{% block content %} {% block content %}
<div class="boxed-content"> <div class="boxed-content">
<div id="notifications" data="setting"></div>
<div class="title-bar"> <div class="title-bar">
<h1>User Configurations</h1> <h1>User Configurations</h1>
</div> </div>
@ -163,8 +165,8 @@
{{ scheduler_form.check_reindex }} {{ scheduler_form.check_reindex }}
</div> </div>
<div class="settings-item"> <div class="settings-item">
<p>Current refresh for metadata older than, in days: <span class="settings-current">{{ config.scheduler.check_reindex_days }}</span></p> <p>Current refresh for metadata older than x days: <span class="settings-current">{{ config.scheduler.check_reindex_days }}</span></p>
<p>Refresh videos older than, in days:</p> <p>Refresh older than x days, recommended 90:</p>
{{ scheduler_form.check_reindex_days }} {{ scheduler_form.check_reindex_days }}
</div> </div>
</div> </div>
@ -273,4 +275,5 @@
</div> </div>
{% endif %} {% endif %}
</div> </div>
<script type="text/javascript" src="{% static 'progress.js' %}"></script>
{% endblock content %} {% endblock content %}

View File

@ -948,6 +948,7 @@ class SettingsView(View):
print(form_post) print(form_post)
ScheduleBuilder().update_schedule_conf(form_post) ScheduleBuilder().update_schedule_conf(form_post)
sleep(1)
return redirect("settings", permanent=True) return redirect("settings", permanent=True)

View File

@ -1,5 +1,5 @@
/** /**
* Handle progress bar on /download * Handle multi channel notifications
* *
*/ */
@ -10,7 +10,8 @@ const messageTypes = {
"download": ["message:download", "message:add", "message:rescan"], "download": ["message:download", "message:add", "message:rescan"],
"channel": ["message:subchannel"], "channel": ["message:subchannel"],
"channel_id": ["message:playlistscan"], "channel_id": ["message:playlistscan"],
"playlist": ["message:subplaylist"] "playlist": ["message:subplaylist"],
"setting": ["message:setting"]
} }
// start to look for messages // start to look for messages