Skip to content

Commit

Permalink
start handling multiple on raw mode
Browse files Browse the repository at this point in the history
  • Loading branch information
syrk4web committed Aug 8, 2024
1 parent 22f8477 commit 711e3b8
Show file tree
Hide file tree
Showing 10 changed files with 406 additions and 47 deletions.
1 change: 0 additions & 1 deletion src/ui/builder/utils/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ def get_forms(
# Copy of the plugins, and get the plugins by context if needed
# In services page, we want only multisite settings, but in global config we want both
plugins_base = get_plugins_multisite(plugins) if only_multisite else plugins

# This template will be used to show default value or value if exists
templates = [
{
Expand Down
2 changes: 1 addition & 1 deletion src/ui/client/dashboard/pages/modes/index.html

Large diffs are not rendered by default.

78 changes: 74 additions & 4 deletions src/ui/client/tests/advanced.json
Original file line number Diff line number Diff line change
Expand Up @@ -3427,9 +3427,44 @@
"mobile": 12
},
"disabled": false,
"value": "test",
"value": "",
"name": "Custom header (HeaderName: HeaderValue)",
"prev_value": "",
"popovers": [
{
"iconName": "disk",
"text": "inp_popover_multisite"
},
{
"iconName": "info",
"text": "Custom header to add (HeaderName: HeaderValue)."
}
],
"containerClass": "z-13",
"method": "default"
}
},
"2": {
"CUSTOM_HEADER_2": {
"context": "multisite",
"default": "",
"help": "Custom header to add (HeaderName: HeaderValue).",
"id": "custom-header-2",
"label": "Custom header (HeaderName: HeaderValue)",
"regex": "^([\\w\\-]+: .+)?$",
"type": "text",
"multiple": "custom-headers",
"pattern": "^([\\w\\-]+: .+)?$",
"inpType": "input",
"columns": {
"pc": 4,
"tablet": 6,
"mobile": 12
},
"disabled": false,
"value": "dzdz",
"name": "Custom header (HeaderName: HeaderValue)",
"prev_value": "test",
"prev_value": "dzdz",
"popovers": [
{
"iconName": "disk",
Expand Down Expand Up @@ -10293,9 +10328,44 @@
"mobile": 12
},
"disabled": false,
"value": "test",
"value": "",
"name": "Custom header (HeaderName: HeaderValue)",
"prev_value": "",
"popovers": [
{
"iconName": "disk",
"text": "inp_popover_multisite"
},
{
"iconName": "info",
"text": "Custom header to add (HeaderName: HeaderValue)."
}
],
"containerClass": "z-13",
"method": "default"
}
},
"2": {
"CUSTOM_HEADER_2": {
"context": "multisite",
"default": "",
"help": "Custom header to add (HeaderName: HeaderValue).",
"id": "custom-header-2",
"label": "Custom header (HeaderName: HeaderValue)",
"regex": "^([\\w\\-]+: .+)?$",
"type": "text",
"multiple": "custom-headers",
"pattern": "^([\\w\\-]+: .+)?$",
"inpType": "input",
"columns": {
"pc": 4,
"tablet": 6,
"mobile": 12
},
"disabled": false,
"value": "dzdz",
"name": "Custom header (HeaderName: HeaderValue)",
"prev_value": "test",
"prev_value": "dzdz",
"popovers": [
{
"iconName": "disk",
Expand Down
3 changes: 2 additions & 1 deletion src/ui/client/tests/advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -3705,7 +3705,8 @@
},
"app1.example.com_LISTEN_STREAM": {"value": "yes", "global": True, "method": "default", "template": None},
"app1.example.com_REVERSE_PROXY_CUSTOM_HOST": {"value": "", "global": True, "method": "default", "template": None},
"app1.example.com_CUSTOM_HEADER": {"value": "test", "global": False, "method": "default", "template": None},
"app1.example.com_CUSTOM_HEADER": {"value": "", "global": True, "method": "default", "template": None},
"app1.example.com_CUSTOM_HEADER_2": {"value": "dzdz", "global": True, "method": "default", "template": None},
"app1.example.com_OPEN_FILE_CACHE_ERRORS": {"value": "yes", "global": True, "method": "default", "template": None},
"app1.example.com_LIMIT_REQ_URL": {"value": "/", "global": True, "method": "default", "template": None},
"app1.example.com_LIMIT_CONN_MAX_HTTP2": {"value": "100", "global": True, "method": "default", "template": None},
Expand Down
2 changes: 1 addition & 1 deletion src/ui/client/tests/advanced.txt

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions src/ui/client/tests/builder/advanced_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ def advanced_mode_builder(templates: list[dict], plugins: list, global_config: d
"""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",
Expand Down
41 changes: 22 additions & 19 deletions src/ui/client/tests/builder/utils/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def set_easy(template: list, plugins_base: list, settings: dict, is_new: bool) -
return steps


def set_raw(template: list, plugins_base: list, settings: dict) -> dict:
def set_raw(template: list, plugins_base: list, settings: dict, is_new: bool = False) -> dict:
"""
Set the raw form based on the template and plugins data.
It consists of keeping only the value or default value for each plugin settings.
Expand All @@ -167,29 +167,32 @@ def set_raw(template: list, plugins_base: list, settings: dict) -> dict:
for plugin in plugins:
for setting, value in plugin.get("settings").items():

# Avoid issue with multiple settings
if not setting in settings:
continue
is_multiple_setting = "multiple" in value

template_value, current_value, default_value, is_disabled_method, is_current_from_template, is_current_default, setting_value = get_setting_data(
template_settings,
settings,
setting,
value,
)
# By default, we will loop on one setting (not multiple)
total_settings = {setting: value}

# We want to show any methods on raw mode
# Case multiple, retrieve all settings that start with setting name
if is_multiple_setting:
# get all settings that start with setting name
total_settings = {k: v for k, v in settings.items() if k.startswith(f"{setting}")}

# if is_disabled_method :
# continue
# Loop in a same way it is a multiple or regular setting
for mult_setting, mult_value in total_settings.items():

if current_value is not None and not is_current_default:
raw_settings[setting] = current_value
continue
# Get setting data
# We need to send setting and not mult_setting because mult_setting is unknown on plugin side
template_value, current_value, default_value, is_disabled_method, is_current_from_template, is_current_default, setting_value = (
get_setting_data(template_settings, settings, mult_setting, mult_value)
)

if template_value is not None:
raw_settings[setting] = template_value
continue
if current_value is not None:
raw_settings[mult_setting] = current_value
continue

if template_value is not None:
raw_settings[mult_setting] = template_value
continue

return raw_settings

Expand Down
Loading

0 comments on commit 711e3b8

Please sign in to comment.