diff --git a/.github/workflows/docker_dev.yml b/.github/workflows/docker_dev.yml index d2c868ac..3a4ed6c5 100755 --- a/.github/workflows/docker_dev.yml +++ b/.github/workflows/docker_dev.yml @@ -3,12 +3,12 @@ name: docker on: push: branches: - - '**' + - main tags: - '*.*.*' pull_request: branches: - - master + - main jobs: docker_dev: diff --git a/front/css/app.css b/front/css/app.css index afb72dae..06523a0a 100755 --- a/front/css/app.css +++ b/front/css/app.css @@ -1868,6 +1868,11 @@ input[readonly] { display: contents; } +.workflow-card .panel-title +{ + padding: 10px; +} + .workflow-card, .condition-list, .actions-list { display: grid; diff --git a/front/workflowsCore.php b/front/workflowsCore.php index 818ddf2f..c44ce020 100755 --- a/front/workflowsCore.php +++ b/front/workflowsCore.php @@ -47,7 +47,7 @@ let operatorTypes = [ ]; let actionTypes = [ - "update_field", "run_plugin" + "update_field", "run_plugin", "delete_device" ]; // -------------------------------------- @@ -60,11 +60,16 @@ function getData() { $.get('php/server/query_json.php?file=workflows.json', function (res) { workflows = res; console.log(workflows); + + // Store the updated workflows object back into cache + setCache('workflows', JSON.stringify(workflows)); + renderWorkflows(); hideSpinner(); }); } + // -------------------------------------- // Render all workflows function renderWorkflows() { @@ -80,18 +85,18 @@ function renderWorkflows() { // -------------------------------------- // Generate UI for a single workflow -function generateWorkflowUI(wf, index) { +function generateWorkflowUI(wf, wfIndex) { let $wfContainer = $("
", { class: "workflow-card box box-solid box-primary panel panel-default", - id: `wf-${index}-container` + id: `wf-${wfIndex}-container` }); // Workflow Name let $wfLinkWrap = $("
", { class: " ", - id: `wf-${index}-header` + id: `wf-${wfIndex}-header` } ) @@ -101,7 +106,7 @@ function generateWorkflowUI(wf, index) { "data-toggle": "collapse", "data-parent": "#workflowContainer", "aria-expanded": false, - "href" : `#wf-${index}-collapsible-panel` + "href" : `#wf-${wfIndex}-collapsible-panel` } ) @@ -114,15 +119,26 @@ function generateWorkflowUI(wf, index) { $wfContainer.append($wfHeaderLink.append($wfLinkWrap.append($wfHeaderHeading))); // Collapsible panel start + + // Get saved state from localStorage + let panelState = localStorage.getItem(`wf-${wfIndex}-collapsible-panel`); + let isOpen = panelState === "true"; // Convert stored string to boolean + + console.log(`panel isOpen: ${isOpen}` ); + + let $wfCollapsiblePanel = $("
", { - class: "panel-collapse collapse ", - id: `wf-${index}-collapsible-panel` + class: `panel-collapse collapse ${isOpen ? 'in' : ''}`, + id: `wf-${wfIndex}-collapsible-panel` }); - let $wfNameInput = createEditableInput("Workflow name", wf.name, `wf-name-${index}`, "workflow-name-input", function(newValue) { - console.log(`Saved new value: ${newValue}`); - wf.name = newValue; // Update the workflow object with the new name - }); + let $wfNameInput = createEditableInput( + `[${wfIndex}].name`, + "Workflow name", + wf.name, + `wf-${wfIndex}-name`, + "workflow-name-input" + ); $wfCollapsiblePanel.append($wfNameInput) @@ -133,13 +149,21 @@ function generateWorkflowUI(wf, index) { } ).append("Trigger: "); - let $triggerTypeDropdown = createEditableDropdown("Trigger Type", triggerTypes, wf.trigger.object_type, `trigger-${index}-type`, function(newValue) { - wf.trigger.object_type = newValue; // Update trigger's object_type - }); + let $triggerTypeDropdown = createEditableDropdown( + `[${wfIndex}].trigger.object_type`, + "Trigger Type", + triggerTypes, + wf.trigger.object_type, + `wf-${wfIndex}-trigger-object-type` + ); - let $eventTypeDropdown = createEditableDropdown("Event Type", ["update", "create", "delete"], wf.trigger.event_type, `event-${index}-type`, function(newValue) { - wf.trigger.event_type = newValue; // Update trigger's event_type - }); + let $eventTypeDropdown = createEditableDropdown( + `[${wfIndex}].trigger.event_type`, + "Event Type", + ["update", "create", "delete"], + wf.trigger.event_type, + `wf-${wfIndex}-trigger-event-type` + ); $triggerSection.append($triggerTypeDropdown); $triggerSection.append($eventTypeDropdown); @@ -147,7 +171,7 @@ function generateWorkflowUI(wf, index) { // Conditions let $conditionsContainer = $("
").append("Conditions:"); - $conditionsContainer.append(renderConditions(wf.conditions)); + $conditionsContainer.append(renderConditions(wfIndex, `[${wfIndex}]`, 0, wf.conditions)); $wfCollapsiblePanel.append($conditionsContainer); @@ -159,36 +183,53 @@ function generateWorkflowUI(wf, index) { } ).append("Actions:"); - $.each(wf.actions, function (_, action) { + lastActionIndex = 0 + $.each(wf.actions, function (actionIndex, action) { let $actionEl = $("
"); // Dropdown for action.field - let $fieldDropdown = createEditableDropdown("Field", fieldOptions, action.field, `action-${index}-field`, function(newValue) { - action.field = newValue; // Update action.field when a new value is selected - }); + let $fieldDropdown = createEditableDropdown( + `[${wfIndex}].actions[${actionIndex}].field`, + "Field", + fieldOptions, + action.field, + `wf-${wfIndex}-actionIndex-${actionIndex}-field` + ); // Dropdown for action.type - let $actionDropdown= createEditableDropdown("Action", actionTypes, action.field, `action-${index}-type`, function(newValue) { - action.field = newValue; // Update action.field when a new value is selected - }); + let $actionDropdown= createEditableDropdown( + `[${wfIndex}].actions[${actionIndex}].type`, + "Type", + actionTypes, + action.field, + `wf-${wfIndex}-actionIndex-${actionIndex}-type` + ); // Action Value Input (Editable) - let $actionValueInput = createEditableInput("Value", action.value, `action-${index}-value`, "action-value-input", function(newValue) { - action.value = newValue; // Update action.value when saved - }); + let $actionValueInput = createEditableInput( + `[${wfIndex}].actions[${actionIndex}].value`, + "Value", + action.value, + `wf-${wfIndex}-actionIndex-${actionIndex}-value`, + "action-value-input" + ); $actionEl.append($actionDropdown); $actionEl.append($fieldDropdown); $actionEl.append($actionValueInput); $actionsContainer.append($actionEl); + + lastActionIndex = actionIndex }); - // add conditions group button + // add actions group button let $actionAddButton = $("