Browse Source

Rebase past all the recent CI work

jamesread 4 năm trước cách đây
mục cha
commit
39647c6d2d

+ 15 - 0
OliveTin.proto

@@ -9,6 +9,21 @@ message ActionButton {
 	string title = 2;
 	string title = 2;
 	string icon = 3;
 	string icon = 3;
 	bool canExec = 4;
 	bool canExec = 4;
+
+	repeated ActionArgument arguments = 5;
+}
+
+message ActionArgument {
+	string variable = 1;
+	string label = 2; 
+	string type = 3;
+
+	repeated ActionArgumentValue values = 4;
+}
+
+message ActionArgumentValue {
+	string value = 1;
+	string label = 2;
 }
 }
 
 
 message GetButtonsResponse {
 message GetButtonsResponse {

+ 13 - 0
internal/config/config.go

@@ -11,6 +11,19 @@ type ActionButton struct {
 	CSS         map[string]string `mapstructure:"omitempty"`
 	CSS         map[string]string `mapstructure:"omitempty"`
 	Timeout     int
 	Timeout     int
 	Permissions []PermissionsEntry
 	Permissions []PermissionsEntry
+	Arguments	[]ActionArgument
+}
+
+type ActionArgument struct {
+	Variable	string
+	Label		string
+	Type		string
+	Values 		[]ActionArgumentValue
+}
+
+type ActionArgumentValue struct {
+	Value		string
+	Label		string
 }
 }
 
 
 // Entity represents a "thing" that can have multiple actions associated with it.
 // Entity represents a "thing" that can have multiple actions associated with it.

+ 8 - 0
internal/grpcapi/grpcApi.go

@@ -73,6 +73,14 @@ func actionButtonsCfgToPb(cfgActionButtons []config.ActionButton, user *acl.User
 			CanExec: acl.IsAllowedExec(cfg, user, &action),
 			CanExec: acl.IsAllowedExec(cfg, user, &action),
 		}
 		}
 
 
+		for _, cfgArg := range action.Arguments {
+			pbArg := pb.ActionArgument {
+				Label: cfgArg.Label,
+			}
+
+			btn.Arguments = append(btn.Arguments, &pbArg)
+		}
+
 		res.Actions = append(res.Actions, &btn)
 		res.Actions = append(res.Actions, &btn)
 	}
 	}
 
 

+ 13 - 1
webui/js/ActionButton.js

@@ -1,4 +1,5 @@
 import { marshalLogsJsonToHtml } from './marshaller.js'
 import { marshalLogsJsonToHtml } from './marshaller.js'
+import "./ArgumentForm.js"
 
 
 class ActionButton extends window.HTMLButtonElement {
 class ActionButton extends window.HTMLButtonElement {
   constructFromJson (json) {
   constructFromJson (json) {
@@ -11,7 +12,18 @@ class ActionButton extends window.HTMLButtonElement {
 
 
     this.updateFromJson(json)
     this.updateFromJson(json)
 
 
-    this.onclick = () => { this.startAction() }
+    this.onclick = () => { 
+      if (json.arguments.length > 0) {
+        let frm = document.createElement('form', { is: 'argument-form' })
+        window.frm = frm
+        console.log(frm)
+        frm.setup(json, this.startAction)
+
+        document.body.appendChild(frm)
+      } else {
+        this.startAction() 
+      }
+    }
 
 
     this.constructTemplate()
     this.constructTemplate()
 
 

+ 19 - 0
webui/js/ArgumentForm.js

@@ -0,0 +1,19 @@
+
+class ArgumentForm extends window.HTMLFormElement {
+  setup(json, callback) {
+    this.setAttribute('class', 'actionArguments')
+    this.title = document.createElement("h1")
+    this.title.innerHTML = "Action Arguments"
+
+    this.appendChild(this.title);
+
+    let a = document.createElement("span")
+    a.innerText = "Hi"
+    frm.appendChild(a)
+
+
+    console.log(json)
+  }
+}
+
+window.customElements.define('argument-form', ArgumentForm, { extends: 'form' })

+ 10 - 0
webui/style.css

@@ -235,3 +235,13 @@ details[open] {
   margin-top: 1em;
   margin-top: 1em;
   display: block;
   display: block;
 }
 }
+
+form.actionArguments {
+	border-radius: 1em;
+	position: absolute;
+	top: 1em;
+	left: 1em;
+	right: 1em;
+	padding: 1em;
+	background-color: #fff;
+}