mirror of
https://github.com/RoganDawes/P4wnP1_aloa.git
synced 2025-03-18 05:41:55 +01:00
Replaced custom CodeMirror Vue component with 'vue-codemirror'; some formatting
This commit is contained in:
parent
2a7d5375dc
commit
2b32f25188
2
ToDo.txt
2
ToDo.txt
@ -63,7 +63,7 @@ OTHER:
|
||||
- Load&Store runtime configuration from/to templates (accessible via web client)
|
||||
- Network events (interface down, DHCP lease/release)
|
||||
- add classes to all html elements of web client, to allow styling by sbd. who's able to do it better than me
|
||||
|
||||
- add reboot/shutdown option accessible from webclient
|
||||
|
||||
TO FIX:
|
||||
- remove dependencies of CLI client on service package
|
||||
|
40
dist/www/index.html
vendored
40
dist/www/index.html
vendored
@ -15,7 +15,6 @@
|
||||
|
||||
<!--
|
||||
<link rel="stylesheet" type="text/css" href="p4wnp1.css">
|
||||
<link rel="stylesheet" href="/fontawesome-free-5.2.0-web/css/solid.min.css">
|
||||
-->
|
||||
<script>
|
||||
window.FontAwesomeConfig = {
|
||||
@ -27,7 +26,7 @@
|
||||
<style>
|
||||
.CodeMirror {
|
||||
font-family: monospace;
|
||||
height: 500px;
|
||||
height: auto;
|
||||
color: black;
|
||||
direction: ltr;
|
||||
}
|
||||
@ -40,15 +39,13 @@
|
||||
|
||||
|
||||
<div id="app">
|
||||
<q-layout view="lHh Lpr fff">
|
||||
<q-layout view="lHh Lpr fFf">
|
||||
<q-layout-header>
|
||||
<q-toolbar>
|
||||
<q-toolbar-title>
|
||||
P4wnP1 web-frontend
|
||||
<div slot="subtitle">by MaMe82</div>
|
||||
</q-toolbar-title>
|
||||
</q-toolbar>
|
||||
|
||||
<q-tabs>
|
||||
<q-route-tab default slot="title" to="usb" name="tab-usb" icon="usb" label="USB Settings"></q-route-tab>
|
||||
<q-route-tab slot="title" to="hid" name="tab-hid-script" icon="code" label="HID Script"></q-route-tab>
|
||||
@ -57,24 +54,29 @@
|
||||
<q-route-tab slot="title" to="network" name="tab-network" icon="settings_ethernet" label="Network settings"></q-route-tab>
|
||||
<q-route-tab slot="title" to="wifi" name="tab-wifi" icon="wifi" label="WiFi settings"></q-route-tab>
|
||||
</q-tabs>
|
||||
|
||||
</q-layout-header>
|
||||
|
||||
|
||||
<q-layout-footer>
|
||||
<q-toolbar>
|
||||
<q-toolbar-title>
|
||||
<div slot="subtitle">by MaMe82</div>
|
||||
</q-toolbar-title>
|
||||
</q-toolbar>
|
||||
</q-layout-footer>
|
||||
|
||||
<q-page-container>
|
||||
<q-page padding>
|
||||
<router-view></router-view>
|
||||
|
||||
<q-modal v-model="!$store.state.isConnected" minimized no-route-dismiss no-esc-dismiss no-backdrop-dismiss>
|
||||
<div style="padding: 50px">
|
||||
<div class="q-display-1 q-mb-md">No connection to server</div>
|
||||
<p>Trying to reconnect ... (attempt {{ $store.state.failedConnectionAttempts }})</p>
|
||||
</div>
|
||||
</q-modal>
|
||||
|
||||
</q-page>
|
||||
<router-view></router-view>
|
||||
|
||||
<q-modal v-model="!$store.state.isConnected" minimized no-route-dismiss no-esc-dismiss no-backdrop-dismiss>
|
||||
<div style="padding: 50px">
|
||||
<div class="q-display-1 q-mb-md">No connection to server</div>
|
||||
<p>Trying to reconnect ... (attempt {{ $store.state.failedConnectionAttempts }})</p>
|
||||
</div>
|
||||
</q-modal>
|
||||
</q-page-container>
|
||||
|
||||
|
||||
</q-layout>
|
||||
</div>
|
||||
|
||||
@ -89,6 +91,10 @@
|
||||
<script src="codemirror/mode/javascript/javascript.js"></script>
|
||||
<script src="codemirror/addon/edit/closebrackets.js"></script>
|
||||
<script src="codemirror/addon/hint/show-hint.js"></script>
|
||||
<script type="text/javascript" src="lib/vue-codemirror.js"></script>
|
||||
<script type="text/javascript">
|
||||
Vue.use(window.VueCodemirror)
|
||||
</script>
|
||||
<script src="javascript-p4wnp1-hint.js"></script>
|
||||
<script type="text/javascript" src="webapp.js"></script>
|
||||
|
||||
|
1
dist/www/lib/vue-codemirror.js
vendored
Normal file
1
dist/www/lib/vue-codemirror.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@ -1,105 +0,0 @@
|
||||
// +build js
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/gopherjs/gopherjs/js"
|
||||
"github.com/HuckRidgeSW/hvue"
|
||||
)
|
||||
|
||||
//https://github.com/cnu4/vue-codemirror-lite/blob/master/codemirror.vue
|
||||
|
||||
type CodeMirrorOptionsType struct {
|
||||
*js.Object
|
||||
Mode interface{} `js:"mode"`
|
||||
LineNumbers bool `js:"lineNumbers"`
|
||||
LineWrapping bool `js:"lineWrapping"`
|
||||
AutoCloseBrackets bool `js:"autoCloseBrackets"`
|
||||
ExtraKeys interface{} `js:"extraKeys"`
|
||||
}
|
||||
|
||||
type CompCodeEditorData struct {
|
||||
*js.Object
|
||||
ScriptContent string `js:"scriptContent"`
|
||||
CodeMirrorOptions *CodeMirrorOptionsType `js:"codemirrorOptions"`
|
||||
|
||||
}
|
||||
|
||||
func NewCodeEditorData(vm *hvue.VM) interface{} {
|
||||
data := &CompCodeEditorData{ Object: O() }
|
||||
data.ScriptContent = ""
|
||||
cmo := &CodeMirrorOptionsType{Object: O()}
|
||||
|
||||
mode := struct{
|
||||
*js.Object
|
||||
Name string `js:"name"`
|
||||
GlobalVars bool `js:"globalVars"`
|
||||
}{ Object: O() }
|
||||
mode.Name = "text/javascript"
|
||||
mode.GlobalVars = true //expose globalVars of mode for auto-complete with addon/hint/show-hint.js, addon/hint/javascript-hint.js"
|
||||
cmo.Mode = &mode
|
||||
|
||||
|
||||
extraKeys := struct{
|
||||
*js.Object
|
||||
CtrlSpace string `js:"Ctrl-Space"`
|
||||
}{ Object: O() }
|
||||
extraKeys.CtrlSpace = "autocomplete"
|
||||
cmo.ExtraKeys = &extraKeys
|
||||
|
||||
|
||||
|
||||
cmo.LineNumbers = true
|
||||
cmo.LineWrapping = true
|
||||
cmo.AutoCloseBrackets = true
|
||||
data.CodeMirrorOptions = cmo
|
||||
return data
|
||||
}
|
||||
|
||||
|
||||
|
||||
func initCodeMirror(vm *hvue.VM) {
|
||||
// this.value = this.scriptContent (copy "value" property over to "scriptContent")
|
||||
val := vm.Get("value")
|
||||
vm.Set("scriptContent", val)
|
||||
|
||||
|
||||
//this.editor = CodeMirror.fromTextArea(this.$el.querySelector('#CodeEditor'), this.codemirrorOptions)
|
||||
editorEl := vm.El.Call("querySelector","#CodeEditor")
|
||||
editor := js.Global.Get("CodeMirror").Call("fromTextArea", editorEl, vm.Get("codemirrorOptions"))
|
||||
|
||||
//copy value property to initial editor state
|
||||
editor.Call("setValue", val)
|
||||
|
||||
editor.Call("on", "change", func(cm *js.Object) {
|
||||
newVal := cm.Call("getValue")
|
||||
|
||||
//update ViewModel data scriptContent
|
||||
vm.Set("scriptContent", newVal)
|
||||
//propagate up change
|
||||
vm.Emit("change", newVal)
|
||||
vm.Emit("input", newVal)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func InitCompCodeEditor() {
|
||||
hvue.NewComponent(
|
||||
"code-editor",
|
||||
hvue.Template(compCodeEditorTemplate),
|
||||
hvue.DataFunc(NewCodeEditorData),
|
||||
hvue.PropObj("value",hvue.Types(hvue.PString),hvue.Default("type('Hello');")),
|
||||
hvue.Mounted(initCodeMirror),
|
||||
|
||||
)
|
||||
}
|
||||
|
||||
const(
|
||||
compCodeEditorTemplate = `
|
||||
<div>
|
||||
<textarea id="CodeEditor"></textarea>
|
||||
</div>
|
||||
`
|
||||
)
|
||||
|
||||
|
@ -142,7 +142,7 @@ ScriptSource string `js:"textSource"`
|
||||
|
||||
//{ "evtype": 0, "vmId": 2, "jobId": 3, "hasError": false, "result": "null", "error": "", "message": "Script started", "time": "2018-07-30 04:56:42.297533 +0000 UTC m=+7625.097825001" }
|
||||
compHIDJobOverviewTemplate = `
|
||||
<q-card class="q-ma-sm" :inline="$q.platform.is.desktop">
|
||||
<q-card class="q-ma-sm">
|
||||
<q-list>
|
||||
<q-list-header>HID Script jobs</q-list-header>
|
||||
<hid-job-overview-item v-for="job in jobs" :job="job" :key="job.id"></hid-job-overview-item>
|
||||
@ -153,9 +153,6 @@ ScriptSource string `js:"textSource"`
|
||||
//{ "evtype": 0, "vmId": 2, "jobId": 3, "hasError": false, "result": "null", "error": "", "message": "Script started", "time": "2018-07-30 04:56:42.297533 +0000 UTC m=+7625.097825001" }
|
||||
compHIDJobEventOverviewTemplate = `
|
||||
<q-page>
|
||||
<hid-job-overview></hid-job-overview>
|
||||
|
||||
|
||||
<div>
|
||||
<table border="1">
|
||||
<tr>
|
||||
|
@ -8,66 +8,79 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type CompHIDScriptData struct {
|
||||
type CompHIDScriptCodeEditorData struct {
|
||||
*js.Object
|
||||
//ScriptContent string `js:"scriptContent"`
|
||||
CodeMirrorOptions *CodeMirrorOptionsType `js:"codemirrorOptions"`
|
||||
}
|
||||
|
||||
func (data *CompHIDScriptData) SendAndRun(vm *hvue.VM) {
|
||||
func (data *CompHIDScriptCodeEditorData) SendAndRun(vm *hvue.VM) {
|
||||
sourceCode := vm.Get("scriptContent").String()
|
||||
|
||||
md5 := StringToMD5(sourceCode) //Calculate MD5 hexstring of current script content
|
||||
//js.Global.Call("alert", md5)
|
||||
|
||||
go func() {
|
||||
timeout := uint32(0)
|
||||
err := UploadHIDScript(md5, sourceCode)
|
||||
if err != nil {
|
||||
notification := &QuasarNotification{Object: O()}
|
||||
notification.Message = "Error uploading script"
|
||||
notification.Detail = err.Error()
|
||||
notification.Position = QUASAR_NOTIFICATION_POSITION_TOP
|
||||
notification.Type = QUASAR_NOTIFICATION_TYPE_NEGATIVE
|
||||
notification.Timeout = 5000
|
||||
QuasarNotify(notification)
|
||||
QuasarNotifyError("Error uploading script", err.Error(), QUASAR_NOTIFICATION_POSITION_TOP)
|
||||
return
|
||||
}
|
||||
job,err := RunHIDScript(md5, timeout)
|
||||
if err != nil {
|
||||
notification := &QuasarNotification{Object: O()}
|
||||
notification.Message = "Error starting script as background job"
|
||||
notification.Detail = err.Error()
|
||||
notification.Position = QUASAR_NOTIFICATION_POSITION_TOP
|
||||
notification.Type = QUASAR_NOTIFICATION_TYPE_NEGATIVE
|
||||
notification.Timeout = 5000
|
||||
QuasarNotify(notification)
|
||||
QuasarNotifyError("Error starting script as background job", err.Error(), QUASAR_NOTIFICATION_POSITION_TOP)
|
||||
return
|
||||
}
|
||||
|
||||
notification := &QuasarNotification{Object: O()}
|
||||
notification.Message = "Script started successfully"
|
||||
notification.Detail = "Job ID " + strconv.Itoa(int(job.Id))
|
||||
notification.Position = QUASAR_NOTIFICATION_POSITION_TOP
|
||||
notification.Type = QUASAR_NOTIFICATION_TYPE_POSITIVE
|
||||
notification.Timeout = 5000
|
||||
QuasarNotify(notification)
|
||||
QuasarNotifySuccess("Script started successfully", "Job ID " + strconv.Itoa(int(job.Id)), QUASAR_NOTIFICATION_POSITION_TOP)
|
||||
}()
|
||||
}
|
||||
|
||||
func newCompHIDScriptData(vm *hvue.VM) interface{} {
|
||||
newVM := &CompHIDScriptData{
|
||||
Object: js.Global.Get("Object").New(),
|
||||
}
|
||||
//newVM.ScriptContent = "layout('us');\ntype('hello');"
|
||||
return newVM
|
||||
type CodeMirrorMode struct {
|
||||
*js.Object
|
||||
Name string `js:"name"`
|
||||
GlobalVars bool `js:"globalVars"`
|
||||
}
|
||||
|
||||
func InitCompHIDScript() {
|
||||
type CodeMirrorExtraKeys struct {
|
||||
*js.Object
|
||||
CtrlSpace string `js:"Ctrl-Space"`
|
||||
}
|
||||
|
||||
type CodeMirrorOptionsType struct {
|
||||
*js.Object
|
||||
Mode *CodeMirrorMode `js:"mode"`
|
||||
LineNumbers bool `js:"lineNumbers"`
|
||||
LineWrapping bool `js:"lineWrapping"`
|
||||
AutoCloseBrackets bool `js:"autoCloseBrackets"`
|
||||
ExtraKeys *CodeMirrorExtraKeys `js:"extraKeys"`
|
||||
}
|
||||
|
||||
func newCompHIDScriptCodeEditorData(vm *hvue.VM) interface{} {
|
||||
data := &CompHIDScriptCodeEditorData{ Object: O() }
|
||||
|
||||
data.CodeMirrorOptions = &CodeMirrorOptionsType{Object: O()}
|
||||
|
||||
data.CodeMirrorOptions.Mode = &CodeMirrorMode{ Object: O() }
|
||||
data.CodeMirrorOptions.Mode.Name = "text/javascript"
|
||||
data.CodeMirrorOptions.Mode.GlobalVars = true //expose globalVars of mode for auto-complete with addon/hint/show-hint.js, addon/hint/javascript-hint.js"
|
||||
|
||||
data.CodeMirrorOptions.ExtraKeys = &CodeMirrorExtraKeys{ Object: O() }
|
||||
data.CodeMirrorOptions.ExtraKeys.CtrlSpace = "autocomplete"
|
||||
|
||||
data.CodeMirrorOptions.LineNumbers = true
|
||||
//data.CodeMirrorOptions.LineWrapping = true
|
||||
data.CodeMirrorOptions.AutoCloseBrackets = true
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
|
||||
func InitComponentsHIDScript() {
|
||||
hvue.NewComponent(
|
||||
"hid-script",
|
||||
hvue.Template(compHIDScriptTemplate),
|
||||
hvue.DataFunc(newCompHIDScriptData),
|
||||
hvue.MethodsOf(&CompHIDScriptData{}),
|
||||
"hid-script-code-editor",
|
||||
hvue.Template(compHIDScriptCodeEditorTemplate),
|
||||
hvue.DataFunc(newCompHIDScriptCodeEditorData),
|
||||
hvue.MethodsOf(&CompHIDScriptCodeEditorData{}),
|
||||
hvue.ComputedWithGetSet(
|
||||
"scriptContent",
|
||||
func(vm *hvue.VM) interface{} {
|
||||
@ -77,15 +90,34 @@ func InitCompHIDScript() {
|
||||
vm.Get("$store").Call("commit", VUEX_MUTATION_SET_CURRENT_HID_SCRIPT_SOURCE_TO, newScriptContent)
|
||||
}),
|
||||
)
|
||||
|
||||
hvue.NewComponent(
|
||||
"hid-script",
|
||||
hvue.Template(compHIDScriptTemplate),
|
||||
)
|
||||
}
|
||||
|
||||
const (
|
||||
|
||||
compHIDScriptTemplate = `
|
||||
<q-page class="row item-start">
|
||||
<q-page>
|
||||
<div class="row content-stretch">
|
||||
<div class="col-10 self-stretch">
|
||||
<hid-script-code-editor></hid-script-code-editor>
|
||||
</div>
|
||||
<div class="col-2">
|
||||
<hid-job-overview></hid-job-overview>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row content-stretch">
|
||||
<hid-job-event-overview></hid-job-event-overview>
|
||||
</div>
|
||||
|
||||
|
||||
<q-card class="q-ma-sm" :inline="$q.platform.is.desktop">
|
||||
|
||||
</q-page>
|
||||
`
|
||||
compHIDScriptCodeEditorTemplate = `
|
||||
<q-card class="q-ma-sm">
|
||||
<q-card-title>
|
||||
HIDScript editor
|
||||
</q-card-title>
|
||||
@ -99,15 +131,10 @@ const (
|
||||
<q-card-separator />
|
||||
|
||||
<q-card-main>
|
||||
<code-editor v-model="scriptContent"></code-editor>
|
||||
<codemirror v-model="scriptContent" :options="codemirrorOptions"></codemirror>
|
||||
</q-card-main>
|
||||
|
||||
</q-card>
|
||||
|
||||
|
||||
<hid-job-overview></hid-job-overview>
|
||||
|
||||
|
||||
<q-page>
|
||||
`
|
||||
)
|
||||
|
||||
|
@ -57,6 +57,7 @@ func InitCompLogger() {
|
||||
const (
|
||||
|
||||
compLoggerTemplate = `
|
||||
<q-page>
|
||||
<div class="logger">
|
||||
<table class="log-entries">
|
||||
<tr>
|
||||
@ -73,7 +74,7 @@ const (
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
</q-page>
|
||||
`
|
||||
)
|
||||
|
||||
|
@ -71,8 +71,7 @@ func main() {
|
||||
InitCompEthernetAddresses2()
|
||||
InitCompToggleSwitch()
|
||||
InitCompUSBSettings()
|
||||
InitCompCodeEditor()
|
||||
InitCompHIDScript()
|
||||
InitComponentsHIDScript()
|
||||
InitCompLogger()
|
||||
InitCompState()
|
||||
InitComponentsNetwork()
|
||||
|
@ -13,17 +13,16 @@ var globalState *GlobalState
|
||||
const (
|
||||
maxLogEntries = 500
|
||||
|
||||
VUEX_ACTION_UPDATE_RUNNING_HID_JOBS = "updateRunningHidJobs"
|
||||
VUEX_ACTION_UPDATE_RUNNING_HID_JOBS = "updateRunningHidJobs"
|
||||
VUEX_ACTION_DEPLOY_CURRENT_GADGET_SETTINGS = "deployCurrentGadgetSettings"
|
||||
VUEX_ACTION_UPDATE_GADGET_SETTINGS_FROM_DEPLOYED = "updateCurrentGadgetSettingsFromDeployed"
|
||||
VUEX_ACTION_DEPLOY_ETHERNET_INTERFACE_SETTINGS = "deployEthernetInterfaceSettings"
|
||||
VUEX_ACTION_UPDATE_WIFI_SETTINGS_FROM_DEPLOYED = "updateCurrentWifiSettingsFromDeployed"
|
||||
VUEX_ACTION_DEPLOY_WIFI_SETTINGS = "deployWifiSettings"
|
||||
VUEX_ACTION_DEPLOY_ETHERNET_INTERFACE_SETTINGS = "deployEthernetInterfaceSettings"
|
||||
VUEX_ACTION_UPDATE_WIFI_SETTINGS_FROM_DEPLOYED = "updateCurrentWifiSettingsFromDeployed"
|
||||
VUEX_ACTION_DEPLOY_WIFI_SETTINGS = "deployWifiSettings"
|
||||
|
||||
|
||||
VUEX_MUTATION_SET_CURRENT_GADGET_SETTINGS_TO = "setCurrentGadgetSettings"
|
||||
VUEX_MUTATION_SET_CURRENT_WIFI_SETTINGS = "setCurrentWifiSettings"
|
||||
VUEX_MUTATION_SET_CURRENT_HID_SCRIPT_SOURCE_TO = "setCurrentHIDScriptSource"
|
||||
VUEX_MUTATION_SET_CURRENT_GADGET_SETTINGS_TO = "setCurrentGadgetSettings"
|
||||
VUEX_MUTATION_SET_CURRENT_WIFI_SETTINGS = "setCurrentWifiSettings"
|
||||
VUEX_MUTATION_SET_CURRENT_HID_SCRIPT_SOURCE_TO = "setCurrentHIDScriptSource"
|
||||
|
||||
initHIDScript = `layout('us'); // US keyboard layout
|
||||
typingSpeed(100,150) // Wait 100ms between key strokes + an additional random value between 0ms and 150ms (natural)
|
||||
@ -53,25 +52,24 @@ for (var i = 3; i < 10; i++) {
|
||||
|
||||
type GlobalState struct {
|
||||
*js.Object
|
||||
Title string `js:"title"`
|
||||
CurrentHIDScriptSource string `js:"currentHIDScriptSource"`
|
||||
CurrentGadgetSettings *jsGadgetSettings `js:"currentGadgetSettings"`
|
||||
CurrentlyDeployingGadgetSettings bool `js:"deployingGadgetSettings"`
|
||||
EventReceiver *jsEventReceiver `js:"eventReceiver"`
|
||||
HidJobList *jsHidJobStateList `js:"hidJobList"`
|
||||
IsModalEnabled bool `js:"isModalEnabled"`
|
||||
IsConnected bool `js:"isConnected"`
|
||||
FailedConnectionAttempts int `js:"failedConnectionAttempts"`
|
||||
InterfaceSettings *jsEthernetSettingsList `js:"InterfaceSettings"`
|
||||
WiFiSettings *jsWiFiSettings `js:"wifiSettings"`
|
||||
Title string `js:"title"`
|
||||
CurrentHIDScriptSource string `js:"currentHIDScriptSource"`
|
||||
CurrentGadgetSettings *jsGadgetSettings `js:"currentGadgetSettings"`
|
||||
CurrentlyDeployingGadgetSettings bool `js:"deployingGadgetSettings"`
|
||||
EventReceiver *jsEventReceiver `js:"eventReceiver"`
|
||||
HidJobList *jsHidJobStateList `js:"hidJobList"`
|
||||
IsModalEnabled bool `js:"isModalEnabled"`
|
||||
IsConnected bool `js:"isConnected"`
|
||||
FailedConnectionAttempts int `js:"failedConnectionAttempts"`
|
||||
InterfaceSettings *jsEthernetSettingsList `js:"InterfaceSettings"`
|
||||
WiFiSettings *jsWiFiSettings `js:"wifiSettings"`
|
||||
|
||||
Counter int `js:"count"`
|
||||
Text string `js:"text"`
|
||||
Counter int `js:"count"`
|
||||
Text string `js:"text"`
|
||||
}
|
||||
|
||||
|
||||
func createGlobalStateStruct() GlobalState {
|
||||
state := GlobalState{Object:O()}
|
||||
state := GlobalState{Object: O()}
|
||||
state.Title = "P4wnP1 by MaMe82"
|
||||
state.CurrentHIDScriptSource = initHIDScript
|
||||
state.CurrentGadgetSettings = NewUSBGadgetSettings()
|
||||
@ -84,11 +82,15 @@ func createGlobalStateStruct() GlobalState {
|
||||
state.FailedConnectionAttempts = 0
|
||||
//Retrieve Interface settings
|
||||
// ToDo: Replace panics by default values
|
||||
ifSettings,err := RpcClient.GetAllDeployedEthernetInterfaceSettings(time.Second*5)
|
||||
if err != nil { panic("Couldn't retrieve interface settings") }
|
||||
ifSettings, err := RpcClient.GetAllDeployedEthernetInterfaceSettings(time.Second * 5)
|
||||
if err != nil {
|
||||
panic("Couldn't retrieve interface settings")
|
||||
}
|
||||
state.InterfaceSettings = ifSettings
|
||||
wifiSettings,err := RpcClient.GetDeployedWiFiSettings(time.Second * 5)
|
||||
if err != nil { panic("Couldn't retrieve WiFi settings") }
|
||||
wifiSettings, err := RpcClient.GetDeployedWiFiSettings(time.Second * 5)
|
||||
if err != nil {
|
||||
panic("Couldn't retrieve WiFi settings")
|
||||
}
|
||||
state.WiFiSettings = wifiSettings
|
||||
|
||||
state.Counter = 1337
|
||||
@ -99,13 +101,13 @@ func createGlobalStateStruct() GlobalState {
|
||||
func actionUpdateGadgetSettingsFromDeployed(store *mvuex.Store, context *mvuex.ActionContext, state *GlobalState) {
|
||||
go func() {
|
||||
//fetch deployed gadget settings
|
||||
dGS,err := RpcClient.RpcGetDeployedGadgetSettings(time.Second * 5)
|
||||
dGS, err := RpcClient.RpcGetDeployedGadgetSettings(time.Second * 5)
|
||||
if err != nil {
|
||||
println("Couldn't retrieve deployed gadget settings")
|
||||
return
|
||||
}
|
||||
//convert to JS version
|
||||
jsGS := &jsGadgetSettings{Object:O()}
|
||||
jsGS := &jsGadgetSettings{Object: O()}
|
||||
jsGS.fromGS(dGS)
|
||||
|
||||
//commit to current
|
||||
@ -118,7 +120,7 @@ func actionUpdateGadgetSettingsFromDeployed(store *mvuex.Store, context *mvuex.A
|
||||
func actionUpdateWifiSettingsFromDeployed(store *mvuex.Store, context *mvuex.ActionContext, state *GlobalState) {
|
||||
go func() {
|
||||
//fetch deployed gadget settings
|
||||
dWS,err := RpcClient.GetDeployedWiFiSettings(time.Second * 5)
|
||||
dWS, err := RpcClient.GetDeployedWiFiSettings(time.Second * 5)
|
||||
if err != nil {
|
||||
println("Couldn't retrieve deployed WiFi settings")
|
||||
return
|
||||
@ -131,7 +133,6 @@ func actionUpdateWifiSettingsFromDeployed(store *mvuex.Store, context *mvuex.Act
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
func actionDeployWifiSettings(store *mvuex.Store, context *mvuex.ActionContext, state *GlobalState, settings *jsWiFiSettings) {
|
||||
go func() {
|
||||
println("Vuex dispatch deploy WiFi settings")
|
||||
@ -139,35 +140,36 @@ func actionDeployWifiSettings(store *mvuex.Store, context *mvuex.ActionContext,
|
||||
goSettings := settings.toGo()
|
||||
|
||||
err := RpcClient.DeployeWifiSettings(time.Second*3, goSettings)
|
||||
if err != nil {Alert(err)}
|
||||
if err != nil {
|
||||
Alert(err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func actionUpdateRunningHidJobs(store *mvuex.Store, context *mvuex.ActionContext, state *GlobalState) {
|
||||
go func() {
|
||||
//fetch deployed gadget settings
|
||||
jobstates,err := RpcClient.RpcGetRunningHidJobStates(time.Second * 10)
|
||||
jobstates, err := RpcClient.RpcGetRunningHidJobStates(time.Second * 10)
|
||||
if err != nil {
|
||||
println("Couldn't retrieve stateof running HID jobs", err)
|
||||
return
|
||||
}
|
||||
|
||||
for _,jobstate := range jobstates {
|
||||
for _, jobstate := range jobstates {
|
||||
println("updateing jobstate", jobstate)
|
||||
state.HidJobList.UpdateEntry(jobstate.Id, jobstate.VmId, false,false, "initial job state", "",time.Now().String(),jobstate.Source)
|
||||
state.HidJobList.UpdateEntry(jobstate.Id, jobstate.VmId, false, false, "initial job state", "", time.Now().String(), jobstate.Source)
|
||||
}
|
||||
}()
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
func actionDeployCurrentGadgetSettings(store *mvuex.Store, context *mvuex.ActionContext, state *GlobalState) {
|
||||
go func() {
|
||||
|
||||
// ToDo: Indicate deployment process via global state
|
||||
state.CurrentlyDeployingGadgetSettings = true
|
||||
defer func() {state.CurrentlyDeployingGadgetSettings = false}()
|
||||
defer func() { state.CurrentlyDeployingGadgetSettings = false }()
|
||||
|
||||
//get current GadgetSettings
|
||||
curGS := state.CurrentGadgetSettings.toGS()
|
||||
@ -175,36 +177,17 @@ func actionDeployCurrentGadgetSettings(store *mvuex.Store, context *mvuex.Action
|
||||
//try to set them via gRPC (the server holds an internal state, setting != deploying)
|
||||
err := RpcClient.RpcSetRemoteGadgetSettings(curGS, time.Second)
|
||||
if err != nil {
|
||||
|
||||
//ToDo: use global store to return something, or allow actions to return promises (latter is too much JavaScript)
|
||||
//Alert(err.Error())
|
||||
notification := &QuasarNotification{Object: O()}
|
||||
notification.Message = "Error in pre-check of new USB gadget settings"
|
||||
notification.Detail = err.Error()
|
||||
notification.Position = QUASAR_NOTIFICATION_POSITION_TOP
|
||||
notification.Type = QUASAR_NOTIFICATION_TYPE_NEGATIVE
|
||||
notification.Timeout = 5000
|
||||
QuasarNotify(notification)
|
||||
QuasarNotifyError("Error in pre-check of new USB gadget settings", err.Error(), QUASAR_NOTIFICATION_POSITION_TOP)
|
||||
return
|
||||
}
|
||||
|
||||
//try to deploy the, now set, remote GadgetSettings via gRPC
|
||||
_,err = RpcClient.RpcDeployRemoteGadgetSettings(time.Second*10)
|
||||
_, err = RpcClient.RpcDeployRemoteGadgetSettings(time.Second * 10)
|
||||
if err != nil {
|
||||
//ToDo: use global store to return something, or allow actions to return promises (latter is too much JavaScript)
|
||||
//Alert(err.Error())
|
||||
notification := &QuasarNotification{Object: O()}
|
||||
notification.Message = "Error while deploying new USB gadget settings"
|
||||
notification.Detail = err.Error()
|
||||
notification.Position = QUASAR_NOTIFICATION_POSITION_TOP
|
||||
notification.Type = QUASAR_NOTIFICATION_TYPE_NEGATIVE
|
||||
notification.Timeout = 5000
|
||||
QuasarNotify(notification)
|
||||
QuasarNotifyError("Error while deploying new USB gadget settings", err.Error(), QUASAR_NOTIFICATION_POSITION_TOP)
|
||||
return
|
||||
}
|
||||
|
||||
//ToDo: If we're here, we succeeded and should indicate this via global state
|
||||
//Alert("GadgetSettings deployed successfully")
|
||||
notification := &QuasarNotification{Object: O()}
|
||||
notification.Message = "New Gadget Settings deployed successfully"
|
||||
notification.Position = QUASAR_NOTIFICATION_POSITION_TOP
|
||||
@ -217,7 +200,6 @@ func actionDeployCurrentGadgetSettings(store *mvuex.Store, context *mvuex.Action
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
func actionDeployEthernetInterfaceSettings(store *mvuex.Store, context *mvuex.ActionContext, state *GlobalState, settings *jsEthernetInterfaceSettings) {
|
||||
go func() {
|
||||
println("Vuex dispatch deploy ethernet interface settings")
|
||||
@ -225,7 +207,9 @@ func actionDeployEthernetInterfaceSettings(store *mvuex.Store, context *mvuex.Ac
|
||||
goSettings := settings.toGo()
|
||||
|
||||
err := RpcClient.DeployedEthernetInterfaceSettings(time.Second*3, goSettings)
|
||||
if err != nil {Alert(err)}
|
||||
if err != nil {
|
||||
Alert(err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
@ -236,40 +220,40 @@ func initMVuex() *mvuex.Store {
|
||||
mvuex.State(state),
|
||||
mvuex.Action("actiontest", func(store *mvuex.Store, context *mvuex.ActionContext, state *GlobalState) {
|
||||
go func() {
|
||||
for i:=0; i<10; i++ {
|
||||
for i := 0; i < 10; i++ {
|
||||
println(state.Counter)
|
||||
time.Sleep(1*time.Second)
|
||||
context.Commit("increment",5)
|
||||
time.Sleep(1 * time.Second)
|
||||
context.Commit("increment", 5)
|
||||
}
|
||||
|
||||
}()
|
||||
|
||||
}),
|
||||
mvuex.Mutation("setModalEnabled", func (store *mvuex.Store, state *GlobalState, enabled bool) {
|
||||
mvuex.Mutation("setModalEnabled", func(store *mvuex.Store, state *GlobalState, enabled bool) {
|
||||
state.IsModalEnabled = enabled
|
||||
return
|
||||
}),
|
||||
mvuex.Mutation("increment", func (store *mvuex.Store, state *GlobalState, add int) {
|
||||
mvuex.Mutation("increment", func(store *mvuex.Store, state *GlobalState, add int) {
|
||||
state.Counter += add
|
||||
return
|
||||
}),
|
||||
mvuex.Mutation("decrement", func (store *mvuex.Store, state *GlobalState) {
|
||||
mvuex.Mutation("decrement", func(store *mvuex.Store, state *GlobalState) {
|
||||
state.Counter--
|
||||
return
|
||||
}),
|
||||
mvuex.Mutation("setText", func (store *mvuex.Store, state *GlobalState, newText string) {
|
||||
mvuex.Mutation("setText", func(store *mvuex.Store, state *GlobalState, newText string) {
|
||||
state.Text = newText
|
||||
return
|
||||
}),
|
||||
mvuex.Mutation(VUEX_MUTATION_SET_CURRENT_HID_SCRIPT_SOURCE_TO, func (store *mvuex.Store, state *GlobalState, newText string) {
|
||||
mvuex.Mutation(VUEX_MUTATION_SET_CURRENT_HID_SCRIPT_SOURCE_TO, func(store *mvuex.Store, state *GlobalState, newText string) {
|
||||
state.CurrentHIDScriptSource = newText
|
||||
return
|
||||
}),
|
||||
mvuex.Mutation(VUEX_MUTATION_SET_CURRENT_GADGET_SETTINGS_TO, func (store *mvuex.Store, state *GlobalState, settings *jsGadgetSettings) {
|
||||
mvuex.Mutation(VUEX_MUTATION_SET_CURRENT_GADGET_SETTINGS_TO, func(store *mvuex.Store, state *GlobalState, settings *jsGadgetSettings) {
|
||||
state.CurrentGadgetSettings = settings
|
||||
return
|
||||
}),
|
||||
mvuex.Mutation(VUEX_MUTATION_SET_CURRENT_WIFI_SETTINGS, func (store *mvuex.Store, state *GlobalState, settings *jsWiFiSettings) {
|
||||
mvuex.Mutation(VUEX_MUTATION_SET_CURRENT_WIFI_SETTINGS, func(store *mvuex.Store, state *GlobalState, settings *jsWiFiSettings) {
|
||||
state.WiFiSettings = settings
|
||||
return
|
||||
}),
|
||||
@ -289,6 +273,28 @@ func initMVuex() *mvuex.Store {
|
||||
mvuex.Action(VUEX_ACTION_DEPLOY_ETHERNET_INTERFACE_SETTINGS, actionDeployEthernetInterfaceSettings),
|
||||
mvuex.Action(VUEX_ACTION_UPDATE_WIFI_SETTINGS_FROM_DEPLOYED, actionUpdateWifiSettingsFromDeployed),
|
||||
mvuex.Action(VUEX_ACTION_DEPLOY_WIFI_SETTINGS, actionDeployWifiSettings),
|
||||
|
||||
mvuex.Getter("testgetterProperty", func(state *GlobalState) interface{} {
|
||||
//Note: GlobalState is a custom struct, used for the vuex store state
|
||||
println("getter returning a property, for given state", state)
|
||||
return state
|
||||
}),
|
||||
|
||||
mvuex.Getter("testgetterPropertyMulti", func(state *GlobalState) (string, int) {
|
||||
println("getter returning a property with multiple results converted to an array, for given state", state)
|
||||
return "two", 2
|
||||
}),
|
||||
|
||||
mvuex.Getter("testgetterMethodWithArg", func(state interface{}) interface{} {
|
||||
println("getter returning a function which takes an argument, input state isn't casted to known struct", state)
|
||||
return func(i int) int { return i * 2 } // function returning given int multiplied by two
|
||||
}),
|
||||
mvuex.Getter("testgetterConsumeGetters", func(state *GlobalState, getters *js.Object) interface{} {
|
||||
println("getter consuming state and getters as input", state)
|
||||
println("getter3 getters", getters)
|
||||
return getters
|
||||
}),
|
||||
|
||||
)
|
||||
|
||||
// fetch deployed gadget settings
|
||||
@ -310,4 +316,4 @@ func initMVuex() *mvuex.Store {
|
||||
|
||||
func InitGlobalState() *mvuex.Store {
|
||||
return initMVuex()
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,8 @@ const (
|
||||
QUASAR_NOTIFICATION_POSITION_BOTTOM = "bottom"
|
||||
QUASAR_NOTIFICATION_POSITION_BOTTOM_LEFT = "bottom-left"
|
||||
QUASAR_NOTIFICATION_POSITION_BOTTOM_RIGHT = "bottom-right"
|
||||
|
||||
QUASAR_NOTIFICATION_TIMEOUT = 5000
|
||||
)
|
||||
|
||||
type Quasar struct {
|
||||
@ -59,3 +61,22 @@ func QuasarNotify(notification *QuasarNotification) {
|
||||
GlobalQuasar.Plugins["Notify"].Call("create", notification)
|
||||
}
|
||||
|
||||
func QuasarNotifyError(errorMessage string, messageDetails string, position string) {
|
||||
notification := &QuasarNotification{Object: O()}
|
||||
notification.Message = errorMessage
|
||||
notification.Detail = messageDetails
|
||||
notification.Position = position
|
||||
notification.Type = QUASAR_NOTIFICATION_TYPE_NEGATIVE
|
||||
notification.Timeout = QUASAR_NOTIFICATION_TIMEOUT
|
||||
QuasarNotify(notification)
|
||||
}
|
||||
|
||||
func QuasarNotifySuccess(message string, detailMessage string, position string) {
|
||||
notification := &QuasarNotification{Object: O()}
|
||||
notification.Message = message
|
||||
notification.Detail = detailMessage
|
||||
notification.Position = position
|
||||
notification.Type = QUASAR_NOTIFICATION_TYPE_POSITIVE
|
||||
notification.Timeout = QUASAR_NOTIFICATION_TIMEOUT
|
||||
QuasarNotify(notification)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user