UI - config.json refactoring

This commit is contained in:
bunkerity 2020-12-23 11:31:37 +01:00
parent bd7b6af668
commit 569ad75c42
No known key found for this signature in database
GPG Key ID: 654FFF51CEF7CC47
4 changed files with 612 additions and 527 deletions

File diff suppressed because it is too large Load Diff

View File

@ -11,15 +11,7 @@ if "ABSOLUTE_URI" in os.environ :
ABSOLUTE_URI = os.environ["ABSOLUTE_URI"]
app.config["ABSOLUTE_URI"] = ABSOLUTE_URI
with open("/opt/entrypoint/config.json", "r") as f :
config = json.loads(f.read())
app.config["CONFIG"] = {}
for k in config :
if not config[k]["category"] in app.config["CONFIG"] :
app.config["CONFIG"][config[k]["category"]] = []
tmp = config[k].copy()
tmp["id"] = k
app.config["CONFIG"][config[k]["category"]].append(tmp)
app.config["CONFIG"] = json.loads(f.read())
app.jinja_env.globals.update(env_to_summary_class=utils.env_to_summary_class)
app.jinja_env.globals.update(form_service_gen=utils.form_service_gen)

View File

@ -10,10 +10,9 @@
<div class="modal-body">
<ul class="nav nav-pills mb-3" id="pills-tab" role="tablist">
{% set check = {"active": "active", "selected": "true"} %}
{% for category in config["CONFIG"] %}
{% set id_category = category.replace(" ", "") %}
{% for k, v in config["CONFIG"].items() %}
<li class="nav-item" role="presentation">
<a class="nav-link {{ check.active }}" id="edit-{{ id_category }}-{{ id_server_name }}-tab" data-bs-toggle="pill" href="#edit-{{ id_category }}-{{ id_server_name }}" role="tab" aria-controls="edit-{{ id_category }}-{{ id_server_name }}" aria-selected="{{ check.selected }}">{{ category }}</a>
<a class="nav-link {{ check.active }}" id="edit-{{ v["id"] }}-{{ id_server_name }}-tab" data-bs-toggle="pill" href="#edit-{{ v["id"] }}-{{ id_server_name }}" role="tab" aria-controls="edit-{{ v["id"] }}-{{ id_server_name }}" aria-selected="{{ check.selected }}">{{ k }}</a>
</li>
{% if check.update({"active": "", "selected": "false"}) %}
{% endif %}
@ -21,11 +20,10 @@
</ul>
<div class="tab-content" id="edit-content-{{ id_server_name }}">
{% set check = {"class": "show active"} %}
{% for category in config["CONFIG"] %}
{% set id_category = category.replace(" ", "") %}
<div class="tab-pane fade {{ check.class }}" id="edit-{{ id_category }}-{{ id_server_name }}" role="tabpanel" aria-labelledby="edit-{{ id_category }}-{{ id_server_name }}-tab">
{% for config in config["CONFIG"][category] %}
{{ form_service_gen("edit", service["SERVER_NAME"], config["id"], config["label"], config["type"], service[config["env"]])|safe }}
{% for k, v in config["CONFIG"].items() %}
<div class="tab-pane fade {{ check.class }}" id="edit-{{ v["id"] }}-{{ id_server_name }}" role="tabpanel" aria-labelledby="edit-{{ v["id"] }}-{{ id_server_name }}-tab">
{% for param in v["params"] %}
{{ form_service_gen("edit", id_server_name, param["id"], param["label"], param["type"], service[param["env"]])|safe }}
{% endfor %}
</div>
{% if check.update({"class": ""}) %}

View File

@ -26,7 +26,7 @@ def env_to_summary_class(var, value) :
def form_service_gen(form, server, id, label, type, value) :
if form == "edit" :
new_id = "form-edit-" + server.replace(".", "-") + "-" + id
new_id = "form-edit-" + server + "-" + id
elif form == "new" :
new_id = "form-new-" + id
if type == "text" :