mirror of
https://github.com/bunkerity/bunkerweb
synced 2026-05-24 09:28:37 +00:00
start formatting raw mode with template values
This commit is contained in:
parent
f99a6de4ea
commit
7614079b11
14 changed files with 956 additions and 10674 deletions
|
|
@ -23,7 +23,7 @@ def advanced_mode_builder(templates: list[dict], plugins: list, global_config: d
|
|||
},
|
||||
{
|
||||
"type": "Subtitle",
|
||||
"data": {"subtitle": "services_manage_subtitle", "type": "container", "subtitleClass": "mb-4"},
|
||||
"data": {"subtitle": "services_manage_subtitle", "type": "container"},
|
||||
},
|
||||
{
|
||||
"type": "Templates",
|
||||
|
|
|
|||
|
|
@ -1,21 +1,13 @@
|
|||
from .utils.form import get_forms, get_service_settings
|
||||
|
||||
|
||||
def easy_mode_builder(
|
||||
templates: list[dict],
|
||||
plugins: list,
|
||||
global_config: dict,
|
||||
total_config: dict,
|
||||
service_name: str,
|
||||
is_new: bool = False,
|
||||
) -> str:
|
||||
def easy_mode_builder(templates: list[dict], plugins: list, global_config: dict, total_config: dict, service_name: str, is_new: bool = False) -> str:
|
||||
"""Render forms with global config data.
|
||||
ATM we don't need templates but we need to pass at least one to the function (it will simply not override anything).
|
||||
"""
|
||||
|
||||
# We need
|
||||
settings = get_service_settings(service_name, global_config, total_config)
|
||||
|
||||
builder = [
|
||||
{
|
||||
"type": "card",
|
||||
|
|
@ -31,7 +23,7 @@ def easy_mode_builder(
|
|||
},
|
||||
{
|
||||
"type": "Subtitle",
|
||||
"data": {"subtitle": "services_manage_subtitle", "type": "container", "subtitleClass": "mb-4"},
|
||||
"data": {"subtitle": "services_manage_subtitle", "type": "container"},
|
||||
},
|
||||
{
|
||||
"type": "Templates",
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ def raw_mode_builder(templates: list[dict], plugins: list, global_config: dict,
|
|||
},
|
||||
{
|
||||
"type": "Subtitle",
|
||||
"data": {"subtitle": "services_manage_subtitle", "type": "container", "subtitleClass": "mb-4"},
|
||||
"data": {"subtitle": "services_manage_subtitle", "type": "container"},
|
||||
},
|
||||
{
|
||||
"type": "Templates",
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ def get_plugins_multisite(plugins: list) -> list:
|
|||
|
||||
|
||||
def get_forms(
|
||||
templates: list = [],
|
||||
templates_ui: list = [],
|
||||
plugins: list = [],
|
||||
settings: dict = {},
|
||||
render_forms: tuple = ("advanced", "easy", "raw"),
|
||||
|
|
@ -64,7 +64,7 @@ def get_forms(
|
|||
plugins_base = get_plugins_multisite(plugins) if only_multisite else plugins
|
||||
|
||||
# This template will be used to show default value or value if exists
|
||||
TEMPLATE_DEFAULT = [
|
||||
templates = [
|
||||
{
|
||||
"name": "default",
|
||||
"steps": [],
|
||||
|
|
@ -73,7 +73,10 @@ def get_forms(
|
|||
}
|
||||
]
|
||||
|
||||
templates = TEMPLATE_DEFAULT + templates
|
||||
for key, value in templates_ui.items():
|
||||
value["label"] = value["name"]
|
||||
value["name"] = key
|
||||
templates.append(value)
|
||||
|
||||
# Update SERVER_NAME to be empty if new
|
||||
if is_new and "SERVER_NAME" in settings:
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ const comboboxTemplate = {
|
|||
label: "dashboard_templates",
|
||||
columns: { pc: 3, tablet: 12, mobile: 12 },
|
||||
containerClass: "setting",
|
||||
onlyDown: true,
|
||||
popovers: [
|
||||
{
|
||||
text: "inp_templates_desc",
|
||||
|
|
@ -118,7 +119,9 @@ onBeforeMount(() => {
|
|||
<template>
|
||||
<Container
|
||||
v-if="data.currModeName && data.currTemplateName"
|
||||
:containerClass="`col-span-12 w-full`"
|
||||
:containerClass="`col-span-12 w-full ${
|
||||
data.templates.length > 1 ? '' : 'mb-3'
|
||||
}`"
|
||||
:columns="props.columns"
|
||||
>
|
||||
<Grid
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -23,7 +23,7 @@ def advanced_mode_builder(templates: list[dict], plugins: list, global_config: d
|
|||
},
|
||||
{
|
||||
"type": "Subtitle",
|
||||
"data": {"subtitle": "services_manage_subtitle", "type": "container", "subtitleClass": "mb-4"},
|
||||
"data": {"subtitle": "services_manage_subtitle", "type": "container"},
|
||||
},
|
||||
{
|
||||
"type": "Templates",
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ def easy_mode_builder(templates: list[dict], plugins: list, global_config: dict,
|
|||
},
|
||||
{
|
||||
"type": "Subtitle",
|
||||
"data": {"subtitle": "services_manage_subtitle", "type": "container", "subtitleClass": "mb-4"},
|
||||
"data": {"subtitle": "services_manage_subtitle", "type": "container"},
|
||||
},
|
||||
{
|
||||
"type": "Templates",
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ def raw_mode_builder(templates: list[dict], plugins: list, global_config: dict,
|
|||
},
|
||||
{
|
||||
"type": "Subtitle",
|
||||
"data": {"subtitle": "services_manage_subtitle", "type": "container", "subtitleClass": "mb-4"},
|
||||
"data": {"subtitle": "services_manage_subtitle", "type": "container"},
|
||||
},
|
||||
{
|
||||
"type": "Templates",
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ def get_plugins_multisite(plugins: list) -> list:
|
|||
|
||||
|
||||
def get_forms(
|
||||
templates: list = [],
|
||||
templates_ui: list = [],
|
||||
plugins: list = [],
|
||||
settings: dict = {},
|
||||
render_forms: tuple = ("advanced", "easy", "raw"),
|
||||
|
|
@ -64,7 +64,7 @@ def get_forms(
|
|||
plugins_base = get_plugins_multisite(plugins) if only_multisite else plugins
|
||||
|
||||
# This template will be used to show default value or value if exists
|
||||
TEMPLATE_DEFAULT = [
|
||||
templates = [
|
||||
{
|
||||
"name": "default",
|
||||
"steps": [],
|
||||
|
|
@ -73,7 +73,10 @@ def get_forms(
|
|||
}
|
||||
]
|
||||
|
||||
templates = TEMPLATE_DEFAULT + templates
|
||||
for key, value in templates_ui.items():
|
||||
value["label"] = value["name"]
|
||||
value["name"] = key
|
||||
templates.append(value)
|
||||
|
||||
# Update SERVER_NAME to be empty if new
|
||||
if is_new and "SERVER_NAME" in settings:
|
||||
|
|
@ -151,31 +154,42 @@ def set_raw(template: list, plugins_base: list, settings: dict, is_new: bool) ->
|
|||
for plugin in plugins:
|
||||
for setting, value in plugin.get("settings").items():
|
||||
|
||||
# we want to show none default value even if this is a disabled method
|
||||
# we want to show disabled method on raw mode
|
||||
|
||||
# if setting in settings and settings[setting].get("method", "ui") not in ("ui", "default", "manual") and :
|
||||
# continue
|
||||
|
||||
raw_value = None
|
||||
template_value = template_settings.get(setting, None)
|
||||
current_value = settings[setting].get("value", None)
|
||||
default_value = value.get("default")
|
||||
is_disabled_method = settings.get(setting, {}).get("method", "ui") not in ("ui", "default", "manual")
|
||||
is_current_from_template = settings[setting].get("template", None) and template_value is not None
|
||||
is_current_default = current_value is not None and current_value == default_value
|
||||
# setting value is the current (custom one) if exists or fallback to default
|
||||
setting_value = current_value if current_value is not None else default_value
|
||||
|
||||
# Start by setting template value if exists
|
||||
if setting in template_settings:
|
||||
# Update value or set default as value
|
||||
raw_value = template_settings.get(setting, None)
|
||||
# Cases we set the setting value
|
||||
# 1 - the value is from a disabled method
|
||||
# 2 - no template value
|
||||
if is_disabled_method or not is_disabled_method and template_value is None:
|
||||
raw_settings[setting] = setting_value
|
||||
continue
|
||||
|
||||
# Then override by service settings
|
||||
if setting in settings:
|
||||
# Cases we can override by template value
|
||||
# 1 - the current value is default and from template
|
||||
# 2 - the current value is default and not from template
|
||||
# 3 - the current value is not default but from template
|
||||
if (
|
||||
(template_value is not None and is_current_default and is_current_from_template)
|
||||
or (template_value is not None and not is_current_from_template and is_current_default)
|
||||
or (template_value is not None and is_current_from_template and not is_current_default)
|
||||
):
|
||||
raw_settings[setting] = template_value
|
||||
continue
|
||||
|
||||
# Check if the service setting is not default value to add it
|
||||
default_val = value.get("default")
|
||||
val = settings[setting].get("value", value.get("value", value.get("default")))
|
||||
|
||||
if val != default_val:
|
||||
raw_value = val
|
||||
|
||||
# Add value only if exists
|
||||
if raw_value:
|
||||
raw_settings[setting] = raw_value
|
||||
# Case the current value is not default and not from template, we can't override
|
||||
# Or any others cases, we set this fallback
|
||||
raw_settings[setting] = setting_value
|
||||
|
||||
return raw_settings
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because one or more lines are too long
|
|
@ -1336,15 +1336,16 @@ def services_modes():
|
|||
plugins = app.bw_config.get_plugins()
|
||||
|
||||
data_server_builder = None
|
||||
templates = []
|
||||
templates_db = app.db.get_templates()
|
||||
|
||||
if mode == "raw":
|
||||
data_server_builder = raw_mode_builder(templates, plugins, global_config, total_config, service_name or "new", False if service_name else True)
|
||||
data_server_builder = raw_mode_builder(templates_db, plugins, global_config, total_config, service_name or "new", False if service_name else True)
|
||||
|
||||
if mode == "advanced":
|
||||
data_server_builder = advanced_mode_builder(templates, plugins, global_config, total_config, service_name or "new", False if service_name else True)
|
||||
data_server_builder = advanced_mode_builder(templates_db, plugins, global_config, total_config, service_name or "new", False if service_name else True)
|
||||
|
||||
if mode == "easy":
|
||||
data_server_builder = easy_mode_builder(templates, plugins, global_config, total_config, service_name or "new", False if service_name else True)
|
||||
data_server_builder = easy_mode_builder(templates_db, plugins, global_config, total_config, service_name or "new", False if service_name else True)
|
||||
|
||||
data_server_builder = base64.b64encode(bytes(json.dumps(data_server_builder), "utf-8")).decode("ascii")
|
||||
|
||||
|
|
@ -1471,8 +1472,7 @@ def global_config():
|
|||
|
||||
global_config = app.bw_config.get_config(global_only=True, methods=True)
|
||||
plugins = app.bw_config.get_plugins()
|
||||
templates = []
|
||||
data_server_builder = global_config_builder(templates, plugins, global_config)
|
||||
data_server_builder = global_config_builder({}, plugins, global_config)
|
||||
data_server_builder = base64.b64encode(bytes(json.dumps(data_server_builder), "utf-8")).decode("ascii")
|
||||
|
||||
return render_template("global-config.html", data_server_builder=data_server_builder)
|
||||
|
|
|
|||
Loading…
Reference in a new issue