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

@ -1,27 +1,40 @@
{ {
"http_port": 8000, "http_port": 8000,
"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,
"delete_default_json": false, "delete_default_json": false,
"show_contribute_link": true, "show_contribute_link": true,
"virtual_terminal_lines": 70, "virtual_terminal_lines": 70,
"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",
"stream_size_GB": 1, "fi_FI",
"keywords": [ "fy_NL",
"help", "he_IL",
"chunk" "hr_HR",
], "id_ID",
"allow_nsfw_profile_pictures": false, "it_IT",
"enable_user_self_delete": false "lv_LV",
} "nl_BE",
"nl_NL",
"pl_PL",
"pt_BR",
"zh_CN"
],
"stream_size_GB": 1,
"keywords": [
"help",
"chunk"
],
"allow_nsfw_profile_pictures": false,
"enable_user_self_delete": false
}

View File

@ -39,41 +39,60 @@
<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() %}
<br />
<br />
<label for="{{item[0]}}">{{item[0]}}
<small class="text-muted ml-1">
</small> </label>
{% if isinstance(item[1], list) %}
<br>
<textarea value="{{','.join(item[1])}}" type="text" name="{{item[0]}}"
class="list">{{','.join(item[1])}}</textarea>
</ul>
{% elif isinstance(item[1], bool) %}
{% if item[1] == True %} {% for item in data['config-json'].items() %}
<div style="margin-left: 30px;"> <div class="form-group">
<input type="radio" class="form-check-input" name="{{item[0]}}" id="True" value="True" checked> <label class="form" for="{{item[0]}}">{{item[0]}}
 <label for="True">True</label><br> <small class="text-muted ml-1">
<input type="radio" class="form-check-input" name="{{item[0]}}" id="False" value="False"> </small> </label>
 <label for="False">False</label> {% if item[0] == 'language' %}
<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]}}"
class="form-control list">{{','.join(item[1])}}</textarea>
{% elif isinstance(item[1], bool) %}
{% if item[1] == True %}
<div style="margin-left: 30px;">
<input type="radio" class="form-check-input" name="{{item[0]}}" id="True" value="True" checked>
 <label for="True">True</label><br>
<input type="radio" class="form-check-input" name="{{item[0]}}" id="False" value="False">
 <label for="False">False</label>
</div>
{% else %}
<div style="margin-left: 30px;">
<input type="radio" class="form-check-input" name="{{item[0]}}" id="True" value="True">
 <label for="True">True</label><br>
<input type="radio" class="form-check-input" name="{{item[0]}}" id="False" value="False" checked>
 <label for="False">False</label>
</div>
{% end %}
{% elif isinstance(item[1], int) %}
<input type="number" class="form-control" name="{{item[0]}}" id="{{item[0]}}" value="{{ item[1] }}"
step="1" min="0" required>
{% else %}
<input type="text" class="form-control" name="{{item[0]}}" id="{{item[0]}}" value="{{ item[1] }}" step="2"
min="0" required>
{% end %}
</div> </div>
{% else %}
<div style="margin-left: 30px;">
<input type="radio" class="form-check-input" name="{{item[0]}}" id="True" value="True">
 <label for="True">True</label><br>
<input type="radio" class="form-check-input" name="{{item[0]}}" id="False" value="False" checked>
 <label for="False">False</label>
</div>
{% end %}
{% elif isinstance(item[1], int) %}
<input type="number" class="form-control" name="{{item[0]}}" id="{{item[0]}}" value="{{ item[1] }}"
step="1" min="0" required>
{% else %}
<input type="text" class="form-control" name="{{item[0]}}" id="{{item[0]}}" value="{{ item[1] }}" step="2"
min="0" required>
{% end %}
{% 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++) {