From b99a6bdb8ec92898232ea118bed3909ee95eebad Mon Sep 17 00:00:00 2001 From: Piotr Date: Sun, 28 Apr 2024 18:48:58 +0200 Subject: [PATCH] Add initialization actions to web editor module The web editor module now includes functions to initialize available actions. This allows the inclusion of action-related suggestions in the editor interface. A script has been added to render diagrams. Changes in the editor content now trigger diagram rendering and the action initiation process. This enhances the functionality and usability of the web editor. --- web/modules/editor/editor.go | 27 +++++++++++++++++- web/public/views/edytor.html | 53 ++++++++++++++++++++++++------------ 2 files changed, 62 insertions(+), 18 deletions(-) diff --git a/web/modules/editor/editor.go b/web/modules/editor/editor.go index 20b67a6..7070665 100644 --- a/web/modules/editor/editor.go +++ b/web/modules/editor/editor.go @@ -2,7 +2,10 @@ package editor import ( "encoding/json" + "fmt" "github.com/PiotrFerenc/mash2/api/types" + "github.com/PiotrFerenc/mash2/internal/configuration" + "github.com/PiotrFerenc/mash2/internal/executor" "github.com/labstack/echo/v4" "net/http" ) @@ -13,14 +16,36 @@ func CreateEditorHandler() func(c echo.Context) error { if err != nil { return err } - + initActions, err := initActions() + if err != nil { + return err + } data := map[string]interface{}{ "Title": "Edytor", "InitCommand": string(initCommand), + "Actions": initActions, } return c.Render(http.StatusOK, "edytor.html", data) } } +func initActions() (map[string]string, error) { + actions := executor.CreateActionMap(&configuration.Config{}) + result := make(map[string]string, len(actions)) + + for name, _ := range actions { + jsonString, err := json.MarshalIndent(types.Task{ + Sequence: 0, + Action: name, + Name: fmt.Sprintf("my-%s", name), + }, "", " ") + if err != nil { + return nil, err + } + result[name] = string(jsonString) + + } + return result, nil +} func initCommand() ([]byte, error) { initCommand := types.Pipeline{ diff --git a/web/public/views/edytor.html b/web/public/views/edytor.html index 4e5d693..578adf0 100644 --- a/web/public/views/edytor.html +++ b/web/public/views/edytor.html @@ -21,16 +21,24 @@
-            graph TD
-            asd[Client qwe] -->|tcp_123| B
-            B(Load Balancer)
-            B --> C[Server1]
-            B -->|tcp_456| D[Server2]
+
     
+ {{template "scripts" .}} -