Skip to content

Commit

Permalink
Update editor interface and capitalize JSON field
Browse files Browse the repository at this point in the history
The editor interface update includes initialization of the command on creation of the editor handler. A function to initialize the command with pre-filled details (Pipeline, Parameters and Tasks) has been added. In "pipeline.go", the json annotation of the 'parameters' field has been corrected to 'Parameters' for consistency.
  • Loading branch information
PiotrFerenc committed Apr 28, 2024
1 parent d1f98bc commit 19f409b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
2 changes: 1 addition & 1 deletion api/types/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "github.com/go-playground/validator/v10"

type Pipeline struct {
Tasks []Task `json:"Tasks" validate:"required"`
Parameters map[string]interface{} `json:"parameters" validate:"required"`
Parameters map[string]interface{} `json:"Parameters" validate:"required"`
}

func (p *Pipeline) Validate() error {
Expand Down
30 changes: 29 additions & 1 deletion web/modules/editor/editor.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,43 @@
package editor

import (
"encoding/json"
"github.com/PiotrFerenc/mash2/api/types"
"github.com/labstack/echo/v4"
"net/http"
)

func CreateEditorHandler() func(c echo.Context) error {
return func(c echo.Context) error {
initCommand, err := initCommand()
if err != nil {
return err
}

data := map[string]interface{}{
"Title": "Edytor",
"Title": "Edytor",
"InitCommand": string(initCommand),
}
return c.Render(http.StatusOK, "edytor.html", data)
}
}

func initCommand() ([]byte, error) {
initCommand := types.Pipeline{
Parameters: map[string]interface{}{
"my-console.text": "hallo word",
},
Tasks: []types.Task{
types.Task{
Sequence: 1,
Action: "console",
Name: "my-console",
},
},
}
initCommandBytes, err := json.MarshalIndent(initCommand, "", " ")
if err != nil {
return nil, err
}
return initCommandBytes, nil
}
11 changes: 4 additions & 7 deletions web/public/views/edytor.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<div id="container" style="height:600px;"></div>
</div>
<div class="col-6">
<pre class="mermaid">
<pre id="mermaid">
graph TD
asd[Client qwe] -->|tcp_123| B
B(Load Balancer)
Expand All @@ -32,6 +32,8 @@
</div>
</div>
<script>
const initialPipeline = '{{.InitCommand}}'

require.config({paths: {'vs': '/assets/monaco/vs'}});

require(['vs/editor/editor.main'], function () {
Expand Down Expand Up @@ -64,18 +66,13 @@
});

monaco.editor.create(document.getElementById('container'), {
value: '' +
'{\n "Parameters": {\n "console.text":"hallo word"\n },\n "Tasks": [\n {\n "Sequence": 1,\n "Name": "log",\n "Action": "console"\n }\n ]\n}',
value: initialPipeline,
language: 'json'
});

});
</script>
{{template "scripts" .}}
<script type="module">
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs';

mermaid.initialize({startOnLoad: true});
</script>
</body>
</html>

0 comments on commit 19f409b

Please sign in to comment.