// +build js package main import ( "github.com/gopherjs/gopherjs/js" "github.com/mame82/hvue" "strings" ) func InitComponentsGeneric() { hvue.NewComponent( "generic", hvue.Template(compGeneric), ) hvue.NewComponent( "startup-settings", hvue.Template(compStartupSettings), hvue.DataFunc(func(vm *hvue.VM) interface{} { data := &struct { *js.Object ShowTemplateSelect bool `js:"ShowTemplateSelect"` }{Object: O()} data.ShowTemplateSelect = false return data }), hvue.Method("selectMasterTemplate", func(vm *hvue.VM, name *js.Object) { promise := vm.Store.Call("dispatch", VUEX_ACTION_SET_STARTUP_MASTER_TEMPLATE_NAME, name) promise.Call("then", func(val interface{}) { vm.Store.Call("dispatch", VUEX_ACTION_GET_STARTUP_MASTER_TEMPLATE_NAME) }) }), ) hvue.NewComponent( "system", hvue.Template(compSystem), hvue.Method("shutdown", func(vm *hvue.VM) { vm.Store.Call("dispatch", VUEX_ACTION_SHUTDOWN) }, ), hvue.Method("reboot", func(vm *hvue.VM) { vm.Store.Call("dispatch", VUEX_ACTION_REBOOT) }, ), ) hvue.NewComponent( "master-template", hvue.Template(compMasterTemplate), hvue.DataFunc(func(vm *hvue.VM) interface{} { data := &struct { *js.Object //MasterTemplate *jsMasterTemplate `js:"MasterTemplate"` ShowTemplateSelectBluetooth bool `js:"ShowTemplateSelectBluetooth"` ShowTemplateSelectWiFi bool `js:"ShowTemplateSelectWiFi"` ShowTemplateSelectUSB bool `js:"ShowTemplateSelectUSB"` ShowTemplateSelectTriggerAction bool `js:"ShowTemplateSelectTriggerAction"` ShowTemplateSelectNetwork bool `js:"ShowTemplateSelectNetwork"` ShowStoreModal bool `js:"showStoreModal"` ShowLoadModal bool `js:"showLoadModal"` ShowDeployStoredModal bool `js:"showDeployStoredModal"` }{Object: O()} //data.MasterTemplate = NewMasterTemplate() data.ShowTemplateSelectBluetooth = false data.ShowTemplateSelectWiFi = false data.ShowTemplateSelectUSB = false data.ShowTemplateSelectTriggerAction = false data.ShowTemplateSelectNetwork = false data.ShowStoreModal = false data.ShowLoadModal = false data.ShowDeployStoredModal = false return data }), hvue.PropObj("value", hvue.Required), hvue.ComputedWithGetSet( "MasterTemplate", func(vm *hvue.VM) interface{} { return vm.Get("value") }, func(vm *hvue.VM, newValue *js.Object) { vm.Emit("input", newValue) }, ), hvue.Method("deploy", func(vm *hvue.VM, masterTemplate *jsMasterTemplate) { vm.Get("$store").Call("dispatch", VUEX_ACTION_DEPLOY_MASTER_TEMPLATE, masterTemplate) }), hvue.Method("store", func(vm *hvue.VM, name *js.Object) { sReq := NewRequestMasterTemplateStorage() sReq.TemplateName = name.String() sReq.Template = &jsMasterTemplate{ Object: vm.Get("$store").Get("state").Get("CurrentMasterTemplate"), } println("Storing :", sReq) vm.Get("$store").Call("dispatch", VUEX_ACTION_STORE_MASTER_TEMPLATE, sReq) vm.Set("showStoreModal", false) }), hvue.Method("load", func(vm *hvue.VM, name *js.Object) { println("Loading :", name.String()) vm.Get("$store").Call("dispatch", VUEX_ACTION_LOAD_MASTER_TEMPLATE, name) }), hvue.Method("deleteStored", func(vm *hvue.VM, name *js.Object) { println("Loading :", name.String()) vm.Get("$store").Call("dispatch", VUEX_ACTION_DELETE_STORED_MASTER_TEMPLATE, name) }), hvue.Method("deployStored", func(vm *hvue.VM, name *js.Object) { println("Loading :", name.String()) vm.Get("$store").Call("dispatch", VUEX_ACTION_DEPLOY_STORED_MASTER_TEMPLATE, name) }), hvue.Method("updateStoredSettingsList", func(vm *hvue.VM) { vm.Store.Call("dispatch", VUEX_ACTION_UPDATE_STORED_MASTER_TEMPLATE_LIST) }), hvue.Mounted(func(vm *hvue.VM) { vm.Store.Call("dispatch", VUEX_ACTION_UPDATE_STORED_MASTER_TEMPLATE_LIST) }), ) hvue.NewComponent( "database", hvue.Template(compDatabase), hvue.DataFunc(func(vm *hvue.VM) interface{} { data := &struct { *js.Object ShowLoad bool `js:"ShowLoad"` ShowStore bool `js:"ShowStore"` }{Object: O()} data.ShowLoad = false data.ShowStore = false return data }), hvue.Method("load", func(vm *hvue.VM, val *js.Object) { vm.Store.Call("dispatch", VUEX_ACTION_RESTORE_DB, val) }), hvue.Method("store", func(vm *hvue.VM, val *js.Object) { vm.Store.Call("dispatch", VUEX_ACTION_BACKUP_DB, val) }), hvue.Method("updateList", func(vm *hvue.VM) { vm.Store.Call("dispatch", VUEX_ACTION_UPDATE_STORED_DB_BACKUP_LIST) }), ) hvue.NewComponent( "select-network-templates", hvue.Template(templateSelectNetworkTemplatesModal), hvue.DataFunc(func(vm *hvue.VM) interface{} { data := struct { *js.Object CurrentSelection []string `js:"CurrentSelection"` }{Object:O()} data.CurrentSelection = []string{} return &data }), /* hvue.Mounted(func(vm *hvue.VM) { vm.Set("CurrentSelection", vm.Get("values").Index(0)) // println("Index 0 on mount", vm.Get("values").Index(0)) }), */ hvue.Computed("options", func(vm *hvue.VM) interface{} { inVals := vm.Get("values") options := js.Global.Get("Array").New() for i:=0; i < inVals.Length(); i++ { val := inVals.Index(i).String() entry := struct{ *js.Object Label string `js:"label"` Value string `js:"value"` }{Object:O()} entry.Label = val entry.Value = val options.Call("push", entry) } return options }), hvue.ComputedWithGetSet( "visible", func(vm *hvue.VM) interface{} { return vm.Get("show") }, func(vm *hvue.VM, newValue *js.Object) { vm.Call("$emit", "show", newValue) }, ), hvue.ComputedWithGetSet("selection", func(vm *hvue.VM) interface{} { return vm.Get("value") }, func(vm *hvue.VM, newValue *js.Object) { vm.Call("$emit", "input", newValue) }), hvue.Computed("available", func(vm *hvue.VM) interface{} { sel := vm.Get("selection") selection := make(map[string]bool, 0) selectionPrefix := make(map[string]bool, 0) for i:=0; i
` const compStartupSettings = ` Startup Settings
Startup Master Template The template which is loaded on service start
` const compMasterTemplate = ` Master Template Editor
TriggerActions Template
USB Template
WiFi Template
Bluetooth Template
Networks templates Only one template could be selected per interface.
` const compSystem = ` System
` const compDatabase = ` Database
` const templateSelectNetworkTemplatesModal = ` {{ title }} Only one template could be selected per interface {{ name }} `