mirror of
https://github.com/bunkerity/bunkerweb
synced 2026-05-24 09:28:37 +00:00
delete multiple on easy mode working
This commit is contained in:
parent
204fbee3ff
commit
57c458d504
1 changed files with 61 additions and 2 deletions
|
|
@ -89,7 +89,7 @@ export const createFormStore = (storeName, formType) => {
|
|||
|
||||
/**
|
||||
* @name delMultiple
|
||||
* @description This function will delete a group of multiples in the template.
|
||||
* @description This function is a wrapper for any mode that 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.
|
||||
* We will update the values of the group to default values.
|
||||
|
|
@ -101,6 +101,27 @@ export const createFormStore = (storeName, formType) => {
|
|||
function delMultiple(pluginId, multName, groupName) {
|
||||
if (!_isFormTypeAllowed(["advanced", "easy"])) return;
|
||||
|
||||
if (type.value === "advanced")
|
||||
return _delMultipleAdvanced(pluginId, multName, groupName);
|
||||
|
||||
if (type.value === "easy")
|
||||
return _delMultipleEasy(pluginId, multName, groupName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @name _delMultipleAdvanced
|
||||
* @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.
|
||||
* We will update the values of the group to default values.
|
||||
* @param {string} pluginId - id of the plugin on the template array.
|
||||
* @param {string} multName - Input id to update
|
||||
* @param {string|number} groupName - Input value to update
|
||||
* @returns {void}
|
||||
*/
|
||||
function _delMultipleAdvanced(pluginId, multName, groupName) {
|
||||
if (!_isFormTypeAllowed(["advanced"])) return;
|
||||
|
||||
// Get the index of plugin using pluginId
|
||||
const index = templateBase.value.findIndex(
|
||||
(plugin) => plugin.id === pluginId
|
||||
|
|
@ -118,6 +139,45 @@ export const createFormStore = (storeName, formType) => {
|
|||
_updateTempState();
|
||||
}
|
||||
|
||||
/**
|
||||
* @name _delMultipleEasy
|
||||
* @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.
|
||||
* We will update the values of the group to default values.
|
||||
* @param {string} pluginId - id of the plugin on the template array.
|
||||
* @param {string} multName - Input id to update
|
||||
* @param {string|number} groupName - Input value to update
|
||||
* @returns {void}
|
||||
*/
|
||||
function _delMultipleEasy(pluginId, multName, groupName) {
|
||||
if (!_isFormTypeAllowed(["easy"])) return;
|
||||
|
||||
for (let i = 0; i < templateBase.value.length; i++) {
|
||||
const step = templateBase.value[i];
|
||||
if (!"plugins" in step) continue;
|
||||
const plugins = step.plugins;
|
||||
// Get the index of plugin using pluginId
|
||||
const index = plugins.findIndex((plugin) => plugin.id === pluginId);
|
||||
if (index < 0) continue;
|
||||
|
||||
// For back end, we need to keep the group but updating values to default in order to delete it
|
||||
for (const [settName, setting] of Object.entries(
|
||||
templateBase.value[i]["plugins"][index].multiples[multName][groupName]
|
||||
)) {
|
||||
setting.value = setting.default;
|
||||
}
|
||||
|
||||
// For UI, we can delete the group to avoid rendering it
|
||||
delete templateUI.value[i]["plugins"][index].multiples[multName][
|
||||
groupName
|
||||
];
|
||||
break;
|
||||
}
|
||||
|
||||
_updateTempState();
|
||||
}
|
||||
|
||||
/**
|
||||
* @name addMultiple
|
||||
* @description This function is a wrapper for any mode that will add a group of multiple in the template with default values.
|
||||
|
|
@ -188,7 +248,6 @@ export const createFormStore = (storeName, formType) => {
|
|||
function _addMultipleEasy(pluginId, multName) {
|
||||
if (!_isFormTypeAllowed(["easy"])) return;
|
||||
|
||||
console.log(pluginId, multName);
|
||||
for (let i = 0; i < templateBase.value.length; i++) {
|
||||
const step = templateBase.value[i];
|
||||
if (!"plugins" in step) continue;
|
||||
|
|
|
|||
Loading…
Reference in a new issue