multiples action working

This commit is contained in:
Jordan Blasenhauer 2024-07-15 09:34:59 +02:00
parent 8eb833198f
commit 93ecef0373
7 changed files with 654 additions and 32 deletions

View file

@ -4765,6 +4765,74 @@
}
},
"checksum": null,
"multiples_schema": {
"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",
"pattern": "^([\\w\\-]+: .+)?$",
"inpType": "input",
"name": "Custom header (HeaderName: HeaderValue)",
"columns": {
"pc": 4,
"tablet": 6,
"mobile": 12
},
"disabled": false,
"value": "",
"popovers": [
{
"iconName": "disk",
"text": "inp_popover_multisite"
},
{
"iconName": "info",
"text": "Custom header to add (HeaderName: HeaderValue)."
}
],
"containerClass": "z-13"
}
},
"cookie-flags": {
"COOKIE_FLAGS": {
"context": "multisite",
"default": "* HttpOnly SameSite=Lax",
"help": "Cookie flags automatically added to all cookies (value accepted for nginx_cookie_flag_module).",
"id": "cookie-flags",
"label": "Cookie flags",
"regex": "^(\\*|[^;]+)( (HttpOnly|(SameSite)(?!.*\\4)(=(Lax|Strict))?)(?!.*\\3))*$",
"type": "text",
"multiple": "cookie-flags",
"pattern": "^(\\*|[^;]+)( (HttpOnly|(SameSite)(?!.*\\4)(=(Lax|Strict))?)(?!.*\\3))*$",
"inpType": "input",
"name": "Cookie flags",
"columns": {
"pc": 4,
"tablet": 6,
"mobile": 12
},
"disabled": false,
"value": "* HttpOnly SameSite=Lax",
"popovers": [
{
"iconName": "disk",
"text": "inp_popover_multisite"
},
{
"iconName": "info",
"text": "Cookie flags automatically added to all cookies (value accepted for nginx_cookie_flag_module)."
}
],
"containerClass": "z-12"
}
}
},
"multiples": {}
},
{
@ -5074,6 +5142,72 @@
}
},
"checksum": null,
"multiples_schema": {
"limit-req": {
"LIMIT_REQ_URL": {
"context": "multisite",
"default": "/",
"help": "URL (PCRE regex) where the limit request will be applied or special value / for all requests.",
"id": "limit-req-url",
"label": "Limit request URL",
"regex": "^.+$",
"type": "text",
"multiple": "limit-req",
"pattern": "^.+$",
"inpType": "input",
"name": "Limit request URL",
"columns": {
"pc": 4,
"tablet": 6,
"mobile": 12
},
"disabled": false,
"value": "/",
"popovers": [
{
"iconName": "disk",
"text": "inp_popover_multisite"
},
{
"iconName": "info",
"text": "URL (PCRE regex) where the limit request will be applied or special value / for all requests."
}
],
"containerClass": "z-6"
},
"LIMIT_REQ_RATE": {
"context": "multisite",
"default": "2r/s",
"help": "Rate to apply to the URL (s for second, m for minute, h for hour and d for day).",
"id": "limit-req-rate",
"label": "Limit request Rate",
"regex": "^\\d+r/[smhd]$",
"type": "text",
"multiple": "limit-req",
"pattern": "^\\d+r/[smhd]$",
"inpType": "input",
"name": "Limit request Rate",
"columns": {
"pc": 4,
"tablet": 6,
"mobile": 12
},
"disabled": false,
"value": "2r/s",
"popovers": [
{
"iconName": "disk",
"text": "inp_popover_multisite"
},
{
"iconName": "info",
"text": "Rate to apply to the URL (s for second, m for minute, h for hour and d for day)."
}
],
"containerClass": "z-5"
}
}
},
"multiples": {}
},
{
@ -7375,6 +7509,444 @@
}
},
"checksum": null,
"multiples_schema": {
"reverse-proxy": {
"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": "",
"popovers": [
{
"iconName": "disk",
"text": "inp_popover_multisite"
},
{
"iconName": "info",
"text": "Full URL of the proxied resource (proxy_pass)."
}
],
"containerClass": "z-26"
},
"REVERSE_PROXY_URL": {
"context": "multisite",
"default": "/",
"help": "Location URL that will be proxied.",
"id": "reverse-proxy-url",
"label": "Reverse proxy url",
"regex": "^.*$",
"type": "text",
"multiple": "reverse-proxy",
"pattern": "^.*$",
"inpType": "input",
"name": "Reverse proxy url",
"columns": {
"pc": 4,
"tablet": 6,
"mobile": 12
},
"disabled": false,
"value": "/",
"popovers": [
{
"iconName": "disk",
"text": "inp_popover_multisite"
},
{
"iconName": "info",
"text": "Location URL that will be proxied."
}
],
"containerClass": "z-25"
},
"REVERSE_PROXY_WS": {
"context": "multisite",
"default": "no",
"help": "Enable websocket on the proxied resource.",
"id": "reverse-proxy-ws",
"label": "Reverse proxy WS",
"regex": "^(yes|no)$",
"type": "check",
"multiple": "reverse-proxy",
"pattern": "^(yes|no)$",
"inpType": "checkbox",
"name": "Reverse proxy WS",
"columns": {
"pc": 4,
"tablet": 6,
"mobile": 12
},
"disabled": false,
"value": "no",
"popovers": [
{
"iconName": "disk",
"text": "inp_popover_multisite"
},
{
"iconName": "info",
"text": "Enable websocket on the proxied resource."
}
],
"containerClass": "z-24"
},
"REVERSE_PROXY_HEADERS": {
"context": "multisite",
"default": "",
"help": "List of HTTP headers to send to proxied resource separated with semicolons (values for proxy_set_header directive).",
"id": "reverse-proxy-headers",
"label": "Reverse proxy headers",
"regex": "^(?![; ])(;? ?([\\w\\-]+)(?!.*\\2 ) [^;]+)*$",
"type": "text",
"multiple": "reverse-proxy",
"pattern": "^(?![; ])(;? ?([\\w\\-]+)(?!.*\\2 ) [^;]+)*$",
"inpType": "input",
"name": "Reverse proxy headers",
"columns": {
"pc": 4,
"tablet": 6,
"mobile": 12
},
"disabled": false,
"value": "",
"popovers": [
{
"iconName": "disk",
"text": "inp_popover_multisite"
},
{
"iconName": "info",
"text": "List of HTTP headers to send to proxied resource separated with semicolons (values for proxy_set_header directive)."
}
],
"containerClass": "z-23"
},
"REVERSE_PROXY_HEADERS_CLIENT": {
"context": "multisite",
"default": "",
"help": "List of HTTP headers to send to client separated with semicolons (values for add_header directive).",
"id": "reverse-proxy-headers-client",
"label": "Reverse proxy headers-client",
"regex": "^(?![; ])(;? ?([\\w\\-]+)(?!.*\\2 ) [^;]+)*$",
"type": "text",
"multiple": "reverse-proxy",
"pattern": "^(?![; ])(;? ?([\\w\\-]+)(?!.*\\2 ) [^;]+)*$",
"inpType": "input",
"name": "Reverse proxy headers-client",
"columns": {
"pc": 4,
"tablet": 6,
"mobile": 12
},
"disabled": false,
"value": "",
"popovers": [
{
"iconName": "disk",
"text": "inp_popover_multisite"
},
{
"iconName": "info",
"text": "List of HTTP headers to send to client separated with semicolons (values for add_header directive)."
}
],
"containerClass": "z-22"
},
"REVERSE_PROXY_BUFFERING": {
"context": "multisite",
"default": "yes",
"help": "Enable or disable buffering of responses from proxied resource.",
"id": "reverse-proxy-buffering",
"label": "Reverse proxy buffering",
"regex": "^(yes|no)$",
"type": "check",
"multiple": "reverse-proxy",
"pattern": "^(yes|no)$",
"inpType": "checkbox",
"name": "Reverse proxy buffering",
"columns": {
"pc": 4,
"tablet": 6,
"mobile": 12
},
"disabled": false,
"value": "yes",
"popovers": [
{
"iconName": "disk",
"text": "inp_popover_multisite"
},
{
"iconName": "info",
"text": "Enable or disable buffering of responses from proxied resource."
}
],
"containerClass": "z-21"
},
"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"
},
"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
},
"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"
},
"REVERSE_PROXY_AUTH_REQUEST_SET": {
"context": "multisite",
"default": "",
"help": "List of variables to set from the authentication provider, separated with semicolons (values of auth_request_set directives).",
"id": "reverse-proxy-auth-request-set",
"label": "Reverse proxy auth request set",
"regex": "^(?! ;)(;? ?(\\$[a-z_\\-]+)(?!.*\\2 ) [^;]+)*$",
"type": "text",
"multiple": "reverse-proxy",
"pattern": "^(?! ;)(;? ?(\\$[a-z_\\-]+)(?!.*\\2 ) [^;]+)*$",
"inpType": "input",
"name": "Reverse proxy auth request set",
"columns": {
"pc": 4,
"tablet": 6,
"mobile": 12
},
"disabled": false,
"value": "",
"popovers": [
{
"iconName": "disk",
"text": "inp_popover_multisite"
},
{
"iconName": "info",
"text": "List of variables to set from the authentication provider, separated with semicolons (values of auth_request_set directives)."
}
],
"containerClass": "z-17"
},
"REVERSE_PROXY_CONNECT_TIMEOUT": {
"context": "multisite",
"default": "60s",
"help": "Timeout when connecting to the proxied resource.",
"id": "reverse-proxy-connect-timeout",
"label": "Reverse proxy connect timeout",
"regex": "^\\d+(ms?|[shdwMy])$",
"type": "text",
"multiple": "reverse-proxy",
"pattern": "^\\d+(ms?|[shdwMy])$",
"inpType": "input",
"name": "Reverse proxy connect timeout",
"columns": {
"pc": 4,
"tablet": 6,
"mobile": 12
},
"disabled": false,
"value": "60s",
"popovers": [
{
"iconName": "disk",
"text": "inp_popover_multisite"
},
{
"iconName": "info",
"text": "Timeout when connecting to the proxied resource."
}
],
"containerClass": "z-16"
},
"REVERSE_PROXY_READ_TIMEOUT": {
"context": "multisite",
"default": "60s",
"help": "Timeout when reading from the proxied resource.",
"id": "reverse-proxy-read-timeout",
"label": "Reverse proxy read timeout",
"regex": "^\\d+(ms?|[shdwMy])$",
"type": "text",
"multiple": "reverse-proxy",
"pattern": "^\\d+(ms?|[shdwMy])$",
"inpType": "input",
"name": "Reverse proxy read timeout",
"columns": {
"pc": 4,
"tablet": 6,
"mobile": 12
},
"disabled": false,
"value": "60s",
"popovers": [
{
"iconName": "disk",
"text": "inp_popover_multisite"
},
{
"iconName": "info",
"text": "Timeout when reading from the proxied resource."
}
],
"containerClass": "z-15"
},
"REVERSE_PROXY_SEND_TIMEOUT": {
"context": "multisite",
"default": "60s",
"help": "Timeout when sending to the proxied resource.",
"id": "reverse-proxy-send-timeout",
"label": "Reverse proxy send timeout",
"regex": "^\\d+(ms?|[shdwMy])$",
"type": "text",
"multiple": "reverse-proxy",
"pattern": "^\\d+(ms?|[shdwMy])$",
"inpType": "input",
"name": "Reverse proxy send timeout",
"columns": {
"pc": 4,
"tablet": 6,
"mobile": 12
},
"disabled": false,
"value": "60s",
"popovers": [
{
"iconName": "disk",
"text": "inp_popover_multisite"
},
{
"iconName": "info",
"text": "Timeout when sending to the proxied resource."
}
],
"containerClass": "z-14"
},
"REVERSE_PROXY_INCLUDES": {
"context": "multisite",
"default": "",
"help": "Additional configuration to include in the location block, separated with spaces.",
"id": "reverse-proxy-includes",
"label": "Reverse proxy includes",
"regex": "^(?! )( ?(\\w+)(?!.*\\b\\2\\b))*$",
"type": "text",
"multiple": "reverse-proxy",
"pattern": "^(?! )( ?(\\w+)(?!.*\\b\\2\\b))*$",
"inpType": "input",
"name": "Reverse proxy includes",
"columns": {
"pc": 4,
"tablet": 6,
"mobile": 12
},
"disabled": false,
"value": "",
"popovers": [
{
"iconName": "disk",
"text": "inp_popover_multisite"
},
{
"iconName": "info",
"text": "Additional configuration to include in the location block, separated with spaces."
}
],
"containerClass": "z-13"
}
}
},
"multiples": {
"reverse-proxy": {
"1": {
@ -7382,7 +7954,7 @@
"context": "multisite",
"default": "",
"help": "Full URL of the proxied resource (proxy_pass).",
"id": "reverse-proxy-host_1",
"id": "reverse-proxy-host-1",
"label": "Reverse proxy host",
"regex": "^.*$",
"type": "text",
@ -7418,7 +7990,7 @@
"context": "multisite",
"default": "/",
"help": "Location URL that will be proxied.",
"id": "reverse-proxy-url_1",
"id": "reverse-proxy-url-1",
"label": "Reverse proxy url",
"regex": "^.*$",
"type": "text",
@ -7449,7 +8021,7 @@
"context": "multisite",
"default": "no",
"help": "Enable websocket on the proxied resource.",
"id": "reverse-proxy-ws_1",
"id": "reverse-proxy-ws-1",
"label": "Reverse proxy WS",
"regex": "^(yes|no)$",
"type": "check",
@ -7480,7 +8052,7 @@
"context": "multisite",
"default": "",
"help": "List of HTTP headers to send to proxied resource separated with semicolons (values for proxy_set_header directive).",
"id": "reverse-proxy-headers_1",
"id": "reverse-proxy-headers-1",
"label": "Reverse proxy headers",
"regex": "^(?![; ])(;? ?([\\w\\-]+)(?!.*\\2 ) [^;]+)*$",
"type": "text",
@ -7511,7 +8083,7 @@
"context": "multisite",
"default": "",
"help": "List of HTTP headers to send to client separated with semicolons (values for add_header directive).",
"id": "reverse-proxy-headers-client_1",
"id": "reverse-proxy-headers-client-1",
"label": "Reverse proxy headers-client",
"regex": "^(?![; ])(;? ?([\\w\\-]+)(?!.*\\2 ) [^;]+)*$",
"type": "text",
@ -7542,7 +8114,7 @@
"context": "multisite",
"default": "yes",
"help": "Enable or disable buffering of responses from proxied resource.",
"id": "reverse-proxy-buffering_1",
"id": "reverse-proxy-buffering-1",
"label": "Reverse proxy buffering",
"regex": "^(yes|no)$",
"type": "check",
@ -7573,7 +8145,7 @@
"context": "multisite",
"default": "no",
"help": "Enable or disable keepalive connections with the proxied resource.",
"id": "reverse-proxy-keepalive_1",
"id": "reverse-proxy-keepalive-1",
"label": "Reverse proxy keepalive",
"regex": "^(yes|no)$",
"type": "check",
@ -7604,7 +8176,7 @@
"context": "multisite",
"default": "",
"help": "Enable authentication using an external provider (value of auth_request directive).",
"id": "reverse-proxy-auth-request_1",
"id": "reverse-proxy-auth-request-1",
"label": "Reverse proxy auth request",
"regex": "^(\\/[\\w\\].~:\\/?#\\[@!$\\&'\\(\\)*+,;=\\-]*|off)?$",
"type": "text",
@ -7635,7 +8207,7 @@
"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_1",
"id": "reverse-proxy-auth-request-signin-url-1",
"label": "Auth request signin URL",
"regex": "^(https?:\\/\\/[\\-\\w@:%.+~#=]+[\\-\\w\\(\\)!@:%+.~#?&\\/=$]*)?$",
"type": "text",
@ -7666,7 +8238,7 @@
"context": "multisite",
"default": "",
"help": "List of variables to set from the authentication provider, separated with semicolons (values of auth_request_set directives).",
"id": "reverse-proxy-auth-request-set_1",
"id": "reverse-proxy-auth-request-set-1",
"label": "Reverse proxy auth request set",
"regex": "^(?! ;)(;? ?(\\$[a-z_\\-]+)(?!.*\\2 ) [^;]+)*$",
"type": "text",
@ -7697,7 +8269,7 @@
"context": "multisite",
"default": "60s",
"help": "Timeout when connecting to the proxied resource.",
"id": "reverse-proxy-connect-timeout_1",
"id": "reverse-proxy-connect-timeout-1",
"label": "Reverse proxy connect timeout",
"regex": "^\\d+(ms?|[shdwMy])$",
"type": "text",
@ -7728,7 +8300,7 @@
"context": "multisite",
"default": "60s",
"help": "Timeout when reading from the proxied resource.",
"id": "reverse-proxy-read-timeout_1",
"id": "reverse-proxy-read-timeout-1",
"label": "Reverse proxy read timeout",
"regex": "^\\d+(ms?|[shdwMy])$",
"type": "text",
@ -7759,7 +8331,7 @@
"context": "multisite",
"default": "60s",
"help": "Timeout when sending to the proxied resource.",
"id": "reverse-proxy-send-timeout_1",
"id": "reverse-proxy-send-timeout-1",
"label": "Reverse proxy send timeout",
"regex": "^\\d+(ms?|[shdwMy])$",
"type": "text",
@ -7790,7 +8362,7 @@
"context": "multisite",
"default": "",
"help": "Additional configuration to include in the location block, separated with spaces.",
"id": "reverse-proxy-includes_1",
"id": "reverse-proxy-includes-1",
"label": "Reverse proxy includes",
"regex": "^(?! )( ?(\\w+)(?!.*\\b\\2\\b))*$",
"type": "text",

View file

@ -3320,6 +3320,8 @@ def set_multiples(template, format_plugins, service_settings):
del plugin["settings"][setting]
if len(multiples):
# Add multiple schema with default values to plugin
plugin["multiples_schema"] = 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, multiples)

File diff suppressed because one or more lines are too long

View file

@ -11,12 +11,13 @@ import Text from "@components/Widget/Text.vue";
import Filter from "@components/Widget/Filter.vue";
import GroupMultiple from "@components/Forms/Group/Multiple.vue";
import { plugin_types } from "@utils/variables";
import {
useCheckPluginsValidity,
useUpdateTemp,
useListenTempFields,
useUnlistenTempFields,
useDelAdvancedMult,
useAddAdvancedMult,
} from "@utils/form.js";
import { v4 as uuidv4 } from "uuid";
/**
@ -305,7 +306,15 @@ onUnmounted(() => {
<Fields :setting="setting" />
</template>
</Container>
<GroupMultiple v-if="plugin.multiples" :multiples="plugin.multiples" />
<GroupMultiple
@delete="
(multName, groupName) =>
useDelAdvancedMult(data.base, multName, groupName)
"
@add="(multName) => useAddAdvancedMult(data.base, multName)"
v-if="plugin.multiples"
:multiples="plugin.multiples"
/>
</Container>
</template>
<Button

View file

@ -2,6 +2,7 @@
import { reactive, defineProps, defineEmits } from "vue";
import { contentIndex } from "@utils/tabindex.js";
import ButtonGroup from "@components/Widget/ButtonGroup.vue";
import Button from "@components/Widget/Button.vue";
import Fields from "@components/Form/Fields.vue";
import Subtitle from "@components/Widget/Subtitle.vue";
import Container from "@components/Widget/Container.vue";
@ -177,7 +178,6 @@ const props = defineProps({
});
const multiples = reactive({
data: props.multiples,
invisible: [],
});
@ -242,7 +242,7 @@ const emits = defineEmits(["delete", "add"]);
</script>
<template>
<template :key="multObj" v-for="(multObj, multName, id) in multiples.data">
<template :key="multName" v-for="(multObj, multName, id) in props.multiples">
<Container
data-is="multiple"
class="layout-settings-multiple"
@ -251,15 +251,22 @@ const emits = defineEmits(["delete", "add"]);
>
<Container class="col-span-12 flex items-center">
<Subtitle :subtitle="multName.replaceAll('-', ' ')" />
<ButtonGroup
@click="toggleVisible(`${multName}${id}`)"
:buttons="[buttonAdd, buttonToggle]"
/>
<div class="flex justify-center">
<Button
v-bind="buttonAdd"
@click="$emit('add', multName)"
class="mx-2"
/>
<Button
@click="toggleVisible(`${multName}${id}`)"
v-bind="buttonToggle"
/>
</div>
</Container>
<template
:key="groupId"
v-for="(group, groupName, groupId) in multiples.data[multName]"
v-for="(group, groupName, groupId) in props.multiples[multName]"
>
<Container
data-group="multiple"

File diff suppressed because one or more lines are too long

View file

@ -464,7 +464,7 @@ function useUpdateTempMultiples(template, inpId, inpValue, target) {
}
/**
@name useDeleteMultGroup
@name useDelAdvancedMult
@description This function will delete a group of multiples in the template.
The way the backend is working is that to delete a group, we need to send the group name with all default values.
This function needs to be call from the multiples component parent with the template and the group name to delete.
@ -473,18 +473,50 @@ function useUpdateTempMultiples(template, inpId, inpValue, target) {
@param multName - Input id to update
@param groupName - Input value to update
*/
function useDeleteMultGroup(template, multName, groupName) {}
function useDelAdvancedMult(template, multName, groupName) {
for (let i = 0; i < template.length; i++) {
const plugin = template[i];
const multiples = plugin?.multiples;
if (!multiples) continue;
if (!(multName in multiples)) continue;
if (!(groupName in multiples[multName])) continue;
delete multiples[multName][groupName];
return;
}
}
/**
@name useAddMultGroup
@name useAddAdvancedMult
@description This function will add a group of multiple in the template with default values.
Each plugin has a key "multiples_schema" with each multiples group and their default values.
We will retrieve the wanted multiple group and add it on the "multiples" key that contains the multiples that apply to the plugin.
@param template - Template with plugins list and detail settings
@param multName - Input id to update
*/
function useAddMultGroup(template, multName) {
// TODO : add to format multiples_schema
function useAddAdvancedMult(template, multName) {
// Get the right multiple schema
let multipleSchema = {};
let plugin;
let nextGroupId;
for (let i = 0; i < template.length; i++) {
plugin = template[i];
const multiples = plugin?.multiples;
if (!multiples) continue;
if (!(multName in multiples)) continue;
multipleSchema = plugin?.multiples_schema[multName];
console.log(multipleSchema);
// Get the highest id in Object.keys(plugin?.multiples[multName])
nextGroupId = Math.max(...Object.keys(plugin?.multiples[multName])) + 1;
if (!multipleSchema) return;
break;
}
// Set the default values as value
for (const [key, value] of Object.entries(multipleSchema)) {
value.value = value.default;
}
// Add new group as first key of plugin.multiples.multName
plugin.multiples[multName][nextGroupId] = multipleSchema;
console.log(plugin.multiples[multName]);
}
export {
@ -496,6 +528,6 @@ export {
useUpdateTemp,
useListenTempFields,
useUnlistenTempFields,
useDeleteMultGroup,
useAddMultGroup,
useDelAdvancedMult,
useAddAdvancedMult,
};