Improving config_json form and Fixing disabled languages

This commit is contained in:
Silversthorn 2023-01-18 22:01:23 +01:00
parent dc7b682ce6
commit 35d33ef51c
3 changed files with 116 additions and 61 deletions

View File

@ -902,6 +902,20 @@ class PanelHandler(BaseHandler):
with open(self.helper.settings_file, "r", encoding="utf-8") as f: with open(self.helper.settings_file, "r", encoding="utf-8") as f:
data = json.load(f) data = json.load(f)
page_data["config-json"] = data page_data["config-json"] = data
page_data["availables_languages"] = []
page_data["all_languages"] = []
for file in sorted(
os.listdir(
os.path.join(self.helper.root_dir, "app", "translations")
)
):
if file.endswith(".json"):
if file.split(".")[0] not in self.helper.get_setting(
"disabled_language_files"
):
page_data["availables_languages"].append(file.split(".")[0])
page_data["all_languages"].append(file.split(".")[0])
template = "panel/config_json.html" template = "panel/config_json.html"
@ -961,7 +975,9 @@ class PanelHandler(BaseHandler):
os.listdir(os.path.join(self.helper.root_dir, "app", "translations")) os.listdir(os.path.join(self.helper.root_dir, "app", "translations"))
): ):
if file.endswith(".json"): if file.endswith(".json"):
if file not in self.helper.get_setting("disabled_language_files"): if file.split(".")[0] not in self.helper.get_setting(
"disabled_language_files"
):
if file != str(page_data["languages"][0] + ".json"): if file != str(page_data["languages"][0] + ".json"):
page_data["languages"].append(file.split(".")[0]) page_data["languages"].append(file.split(".")[0])
@ -1172,7 +1188,9 @@ class PanelHandler(BaseHandler):
os.listdir(os.path.join(self.helper.root_dir, "app", "translations")) os.listdir(os.path.join(self.helper.root_dir, "app", "translations"))
): ):
if file.endswith(".json"): if file.endswith(".json"):
if file not in self.helper.get_setting("disabled_language_files"): if file.split(".")[0] not in self.helper.get_setting(
"disabled_language_files"
):
if file != str(page_data["languages"][0] + ".json"): if file != str(page_data["languages"][0] + ".json"):
page_data["languages"].append(file.split(".")[0]) page_data["languages"].append(file.split(".")[0])

View File

@ -3,8 +3,8 @@
"https_port": 8443, "https_port": 8443,
"language": "en_EN", "language": "en_EN",
"cookie_expire": 30, "cookie_expire": 30,
"cookie_secret": "random", "cookie_secret": "\"random\"",
"apikey_secret": "random", "apikey_secret": "\"random\"",
"show_errors": true, "show_errors": true,
"history_max_age": 7, "history_max_age": 7,
"stats_update_frequency": 30, "stats_update_frequency": 30,
@ -14,8 +14,21 @@
"max_log_lines": 700, "max_log_lines": 700,
"max_audit_entries": 300, "max_audit_entries": 300,
"disabled_language_files": [ "disabled_language_files": [
"lol_EN.json", "cs_CS",
"" "de_DE",
"es_ES",
"fi_FI",
"fy_NL",
"he_IL",
"hr_HR",
"id_ID",
"it_IT",
"lv_LV",
"nl_BE",
"nl_NL",
"pl_PL",
"pt_BR",
"zh_CN"
], ],
"stream_size_GB": 1, "stream_size_GB": 1,
"keywords": [ "keywords": [

View File

@ -39,19 +39,37 @@
<div class="card-body"> <div class="card-body">
<form id="config-form" class="forms-sample" method="post" action="/panel/config_json"> <form id="config-form" class="forms-sample" method="post" action="/panel/config_json">
{% raw xsrf_form_html() %} {% raw xsrf_form_html() %}
{% for item in data['config-json'].items() %} {% for item in data['config-json'].items() %}
<br /> <div class="form-group">
<br /> <label class="form" for="{{item[0]}}">{{item[0]}}
<label for="{{item[0]}}">{{item[0]}}
<small class="text-muted ml-1"> <small class="text-muted ml-1">
</small> </label> </small> </label>
{% if isinstance(item[1], list) %} {% if item[0] == 'language' %}
<br> <select name="{{item[0]}}" class="custom-select">
{% for lang in data['availables_languages'] %}
{% if lang == item[1] %}
<option selected>{{lang}}</option>
{% else %}
<option>{{lang}}</option>
{% end %}
{% end %}
</select>
{% elif item[0] == 'disabled_language_files' %}
<select id="lang_select" class="custom-select" size="{{ len(data['all_languages']) }}" multiple>
{% for lang in data['all_languages'] %}
{% if lang in item[1] %}
<option selected>{{lang}}</option>
{% else %}
<option>{{lang}}</option>
{% end %}
{% end %}
</select>
<textarea id="disabled_lang" name="{{item[0]}}" class="form-control list hidden" rows="{{ len(data['all_languages']) }}" value="{{','.join(item[1])}}" hidden>{{','.join(item[1])}}</textarea>
{% elif isinstance(item[1], list) %}
<textarea value="{{','.join(item[1])}}" type="text" name="{{item[0]}}" <textarea value="{{','.join(item[1])}}" type="text" name="{{item[0]}}"
class="list">{{','.join(item[1])}}</textarea> class="form-control list">{{','.join(item[1])}}</textarea>
</ul>
{% elif isinstance(item[1], bool) %} {% elif isinstance(item[1], bool) %}
{% if item[1] == True %} {% if item[1] == True %}
<div style="margin-left: 30px;"> <div style="margin-left: 30px;">
<input type="radio" class="form-check-input" name="{{item[0]}}" id="True" value="True" checked> <input type="radio" class="form-check-input" name="{{item[0]}}" id="True" value="True" checked>
@ -74,6 +92,7 @@
<input type="text" class="form-control" name="{{item[0]}}" id="{{item[0]}}" value="{{ item[1] }}" step="2" <input type="text" class="form-control" name="{{item[0]}}" id="{{item[0]}}" value="{{ item[1] }}" step="2"
min="0" required> min="0" required>
{% end %} {% end %}
</div>
{% end %} {% end %}
<button class="btn btn-success" type="submit">Submit</button> <button class="btn btn-success" type="submit">Submit</button>
</form> </form>
@ -109,6 +128,11 @@
let uuid = uuidv4(); let uuid = uuidv4();
var token = getCookie("_xsrf") var token = getCookie("_xsrf")
e.preventDefault(); e.preventDefault();
/* Convert multiple select to text list */
let selected_Lang = $('#lang_select').val();
$('#disabled_lang').val(selected_Lang);
let class_list = document.getElementsByClassName("list"); let class_list = document.getElementsByClassName("list");
let form_json = convertFormToJSON($("#config-form")); let form_json = convertFormToJSON($("#config-form"));
for (let i = 0; i < class_list.length; i++) { for (let i = 0; i < class_list.length; i++) {