Skip to content

Commit

Permalink
format multiple working
Browse files Browse the repository at this point in the history
  • Loading branch information
syrk4web committed Jul 10, 2024
1 parent 8e1bd26 commit 6a58d05
Show file tree
Hide file tree
Showing 6 changed files with 636 additions and 692 deletions.
1,083 changes: 462 additions & 621 deletions src/client/tests/globalconfig.json

Large diffs are not rendered by default.

65 changes: 33 additions & 32 deletions src/client/tests/globalconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -3015,8 +3015,7 @@
"ERRORS": {"value": "", "global": True, "method": "scheduler"},
"USE_UI": {"value": "yes", "global": True, "method": "ui"},
"USE_CORS": {"value": "yes", "global": True, "method": "scheduler"},
"REVERSE_PROXY_HOST_1": {"value": "service1", "global": True, "method": "ui"},
"REVERSE_PROXY_HOST": {"value": "service", "global": True, "method": "ui"},
"REVERSE_PROXY_HOST_1": {"value": "yes", "global": True, "method": "scheduler"},
}


Expand Down Expand Up @@ -3170,7 +3169,7 @@ def set_advanced(template, plugins_base, service_settings):
return plugins


def get_multiple_from_template(template, plugins):
def get_multiple_from_template(template, multiples):
"""
We are gonna loop on each plugins multiples group, in case a setting is matching a template setting,
we will create a group using the prefix as key (or "0" if no prefix) with default settings at first.
Expand All @@ -3180,10 +3179,7 @@ def get_multiple_from_template(template, plugins):
"""
# Loop on each plugin and loop on multiples key
# Check if the name us matching a template key
multiple_plugins = {}
for plugin in plugins:
for setting, value in plugin.get("multiples").items():
multiple_plugins.update(plugin["multiples"])
multiple_plugin = copy.deepcopy(multiples)

multiple_template = {}
for setting, value in template.get("settings").items():
Expand All @@ -3196,32 +3192,33 @@ def get_multiple_from_template(template, plugins):
prefix = setting_split[-1]
format_setting = "_".join(setting_split[:-1])
# loop on settings of a multiple group
for mult_name, mult_settings in multiple_plugins.items():
for mult_name, mult_settings in multiple_plugin.items():
# Check if at least one multiple plugin setting is matching the template setting
if format_setting in mult_settings:
multiple_template[mult_name] = {}
if not mult_name in multiple_template:
multiple_template[mult_name] = {}
# Case it is, we will check if already a group with the right prefix exists
# If not, we will create it
if not prefix in multiple_template:
if not prefix in multiple_template[mult_name]:
# We want each settings to have the prefix if exists
# We will get the value of the setting without the prefix and create a prefix key with the same value
# And after that we can delete the original setting
new_multiple_group = {}
for multSett, multValue in mult_settings.items():
new_multiple_group[f"{multSett}{f'_{prefix}' if prefix != '0' else ''}"] = multValue

multiple_template[mult_name][prefix] = new_multiple_group
multiple_template[mult_name][prefix] = copy.deepcopy(new_multiple_group)

# We can now add the template value to setting using the same setting name with prefix
multiple_template[mult_name][prefix][setting]["value"] = value

# Sort key incrementally
for mult_name, mult_settings in multiple_template.items():
multiple_template[mult_name] = dict(sorted(mult_settings.items(), key=lambda item: int(item[0])))

# Sort key incrementally
for mult_name, mult_settings in multiple_template.items():
multiple_template[mult_name] = dict(sorted(mult_settings.items(), key=lambda item: int(item[0])))
return multiple_template


def get_multiple_from_settings(settings, plugins):
def get_multiple_from_settings(settings, multiples):
"""
We are gonna loop on each plugins multiples group, in case a setting is matching a service / global config setting,
we will create a group using the prefix as key (or "0" if no prefix) with default settings at first.
Expand All @@ -3232,10 +3229,7 @@ def get_multiple_from_settings(settings, plugins):

# Loop on each plugin and loop on multiples key
# Check if the name us matching a template key
multiple_plugins = {}
for plugin in plugins:
for setting, value in plugin.get("multiples").items():
multiple_plugins.update(plugin["multiples"])
multiple_plugins = copy.deepcopy(multiples)

multiple_settings = {}
for setting, value in settings.items():
Expand All @@ -3251,7 +3245,9 @@ def get_multiple_from_settings(settings, plugins):
for mult_name, mult_settings in multiple_plugins.items():
# Check if at least one multiple plugin setting is matching the template setting
if format_setting in mult_settings:
multiple_settings[mult_name] = {}

if not mult_name in multiple_settings:
multiple_settings[mult_name] = {}
# Case it is, we will check if already a group with the right prefix exists
# If not, we will create it
if not prefix in multiple_settings:
Expand All @@ -3262,10 +3258,18 @@ def get_multiple_from_settings(settings, plugins):
for multSett, multValue in mult_settings.items():
new_multiple_group[f"{multSett}{f'_{prefix}' if prefix != '0' else ''}"] = multValue

multiple_settings[mult_name][prefix] = new_multiple_group
multiple_settings[mult_name][prefix] = copy.deepcopy(new_multiple_group)
# We can now add the template value to setting using the same setting name with prefix
multiple_settings[mult_name][prefix][setting]["value"] = value.get("value", multiple_settings[mult_name][prefix][setting]["value"])
multiple_settings[mult_name][prefix][setting]["method"] = value.get("method", "ui")
multiple_settings[mult_name][prefix][setting]["disabled"] = False if value.get("method", "ui") in ("ui", "default", "manual") else True
if multiple_settings[mult_name][prefix][setting].get("disabled", False):
multiple_settings[mult_name][prefix][setting]["popovers"] = [
{
"iconName": "trespass",
"text": "inp_popover_method_disabled",
}
] + multiple_settings[mult_name][prefix][setting].get("popovers", [])
return multiple_settings


Expand All @@ -3275,8 +3279,6 @@ def set_multiples(template, format_plugins, service_settings):
"""
# copy of format plugins
for plugin in format_plugins:
# Prepare multiples key
plugin["multiples"] = {}
# Get multiples
multiples = {}
settings_to_delete = []
Expand Down Expand Up @@ -3304,14 +3306,13 @@ def set_multiples(template, format_plugins, service_settings):
del plugin["settings"][setting]

if len(multiples):
plugin["multiples"].update(multiples)

# Now that we have for each plugin the multiples settings, we need to do the following
# Get all settings from template that are multiples
template_multiples = get_multiple_from_template(template, format_plugins)
# Get all settings from service settings / global config that are multiples
service_multiples = get_multiple_from_settings(service_settings, format_plugins)
# We need
# Now that we have for each plugin the multiples settings, we need to do the following
# Get all settings from template that are multiples
template_multiples = get_multiple_from_template(template, multiples)
# Get all settings from service settings / global config that are multiples
service_multiples = get_multiple_from_settings(service_settings, multiples)
# Get service multiples if at least one, else use template multiples
plugin["multiples"] = service_multiples if len(service_multiples) else template_multiples

return format_plugins

Expand Down
2 changes: 1 addition & 1 deletion src/client/tests/globalconfig64.txt

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/client/vite/input.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

174 changes: 138 additions & 36 deletions src/client/vite/src/components/Forms/Group/Multiple.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,137 @@ import Container from "@components/Widget/Container.vue";
{
"columns": {"pc": 6, "tablet": 12, "mobile": 12},
"multiples": {
"custom-headers": {
"CUSTOM_HEADER": {
"context": "multisite",
"default": "",
"help": "Custom header to add (HeaderName: HeaderValue).",
"id": "custom-header",
"label": "Custom header (HeaderName: HeaderValue)",
"regex": "^([\\w\\-]+: .+)?$",
"type": "text",
"multiple": "custom-headers",
"containerClass": "z-13",
"pattern": "^([\\w\\-]+: .+)?$",
"inpType": "input",
"name": "Custom header (HeaderName: HeaderValue)",
"columns": {
"pc": 4,
"tablet": 6,
"mobile": 12
"reverse-proxy": {
"0": {
"REVERSE_PROXY_HOST": {
"context": "multisite",
"default": "",
"help": "Full URL of the proxied resource (proxy_pass).",
"id": "reverse-proxy-host",
"label": "Reverse proxy host",
"regex": "^.*$",
"type": "text",
"multiple": "reverse-proxy",
"pattern": "^.*$",
"inpType": "input",
"name": "Reverse proxy host",
"columns": {
"pc": 4,
"tablet": 6,
"mobile": 12
},
"disabled": false,
"value": "service",
"popovers": [
{
"iconName": "disk",
"text": "inp_popover_multisite"
},
{
"iconName": "info",
"text": "Full URL of the proxied resource (proxy_pass)."
}
],
"containerClass": "z-26",
"method": "ui"
},
"REVERSE_PROXY_KEEPALIVE": {
"context": "multisite",
"default": "no",
"help": "Enable or disable keepalive connections with the proxied resource.",
"id": "reverse-proxy-keepalive",
"label": "Reverse proxy keepalive",
"regex": "^(yes|no)$",
"type": "check",
"multiple": "reverse-proxy",
"pattern": "^(yes|no)$",
"inpType": "checkbox",
"name": "Reverse proxy keepalive",
"columns": {
"pc": 4,
"tablet": 6,
"mobile": 12
},
"disabled": false,
"value": "no",
"popovers": [
{
"iconName": "disk",
"text": "inp_popover_multisite"
},
{
"iconName": "info",
"text": "Enable or disable keepalive connections with the proxied resource."
}
],
"containerClass": "z-20"
},
"disabled": false,
"value": "",
"popovers": [
{
"iconName": "disk",
"text": "inp_popover_multisite"
"REVERSE_PROXY_AUTH_REQUEST": {
"context": "multisite",
"default": "",
"help": "Enable authentication using an external provider (value of auth_request directive).",
"id": "reverse-proxy-auth-request",
"label": "Reverse proxy auth request",
"regex": "^(\\/[\\w\\].~:\\/?#\\[@!$\\&'\\(\\)*+,;=\\-]*|off)?$",
"type": "text",
"multiple": "reverse-proxy",
"pattern": "^(\\/[\\w\\].~:\\/?#\\[@!$\\&'\\(\\)*+,;=\\-]*|off)?$",
"inpType": "input",
"name": "Reverse proxy auth request",
"columns": {
"pc": 4,
"tablet": 6,
"mobile": 12
},
{
"iconName": "info",
"text": "Custom header to add (HeaderName: HeaderValue)."
}
]
"disabled": false,
"value": "",
"popovers": [
{
"iconName": "disk",
"text": "inp_popover_multisite"
},
{
"iconName": "info",
"text": "Enable authentication using an external provider (value of auth_request directive)."
}
],
"containerClass": "z-19"
},
"REVERSE_PROXY_AUTH_REQUEST_SIGNIN_URL": {
"context": "multisite",
"default": "",
"help": "Redirect clients to sign-in URL when using REVERSE_PROXY_AUTH_REQUEST (used when auth_request call returned 401).",
"id": "reverse-proxy-auth-request-signin-url",
"label": "Auth request signin URL",
"regex": "^(https?:\\/\\/[\\-\\w@:%.+~#=]+[\\-\\w\\(\\)!@:%+.~#?&\\/=$]*)?$",
"type": "text",
"multiple": "reverse-proxy",
"pattern": "^(https?:\\/\\/[\\-\\w@:%.+~#=]+[\\-\\w\\(\\)!@:%+.~#?&\\/=$]*)?$",
"inpType": "input",
"name": "Auth request signin URL",
"columns": {
"pc": 4,
"tablet": 6,
"mobile": 12
},
"disabled": false,
"value": "",
"popovers": [
{
"iconName": "disk",
"text": "inp_popover_multisite"
},
{
"iconName": "info",
"text": "Redirect clients to sign-in URL when using REVERSE_PROXY_AUTH_REQUEST (used when auth_request call returned 401)."
}
],
"containerClass": "z-18"
},
},
}
},
}
}
},
@param {object<object>} multiples - The multiples settings to display. This needs to be a dict of settings using default field format.
@param {object} [columns={"pc": "12", "tablet": "12", "mobile": "12}] - Field has a grid system. This allow to get multiple field in the same row if needed.
Expand Down Expand Up @@ -106,7 +204,6 @@ function addGroup() {}

<template>
<template v-for="(multObj, multName, id) in props.multiples">
{{ id }}
<Container
data-is="multiple"
class="layout-settings-multiple"
Expand All @@ -118,11 +215,16 @@ function addGroup() {}
<ButtonGroup :buttons="[buttonAdd, buttonToggle]" />
</Container>

<Container class="layout-settings-multiple-group">
<template v-for="(setting, value) in props.multiples[multName]">
<Fields :setting="setting" :tabId="props.tabId" />
</template>
</Container>
<template v-for="(group, groupName, id) in props.multiples[multName]">
<Container class="layout-settings-multiple-group">
<Subtitle
:subtitle="`${multName.replaceAll('-', ' ')} #${+groupName + 1}`"
/>
<template v-for="(setting, settingName, id) in group">
<Fields :setting="setting" :tabId="props.tabId" />
</template>
</Container>
</template>
</Container>
</template>
</template>
2 changes: 1 addition & 1 deletion src/client/vite/src/pages/global-config/index.html

Large diffs are not rendered by default.

0 comments on commit 6a58d05

Please sign in to comment.