Started work on argument form

This commit is contained in:
jamesread
2021-10-17 20:58:02 +01:00
parent 03d7250cf6
commit d68dba13bd
6 changed files with 78 additions and 1 deletions

View File

@@ -9,6 +9,21 @@ message ActionButton {
string title = 2;
string icon = 3;
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 {

View File

@@ -11,6 +11,19 @@ type ActionButton struct {
CSS map[string]string `mapstructure:"omitempty"`
Timeout int
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.

View File

@@ -61,6 +61,14 @@ func (api *oliveTinAPI) GetButtons(ctx ctx.Context, req *pb.GetButtonsRequest) (
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)
}

View File

@@ -1,4 +1,5 @@
import { marshalLogsJsonToHtml } from './marshaller.js';
import "./ArgumentForm.js"
class ActionButton extends window.HTMLButtonElement {
constructFromJson (json) {
@@ -11,7 +12,18 @@ class ActionButton extends window.HTMLButtonElement {
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()

19
webui/js/ArgumentForm.js Normal file
View File

@@ -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' })

View File

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