mirror of
https://github.com/OliveTin/OliveTin
synced 2025-12-15 18:45:33 +00:00
Started work on argument form
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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
19
webui/js/ArgumentForm.js
Normal 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' })
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user