diff --git a/web_client/hvueComponentsGeneric.go b/web_client/hvueComponentsGeneric.go index 4156378..15f1af9 100644 --- a/web_client/hvueComponentsGeneric.go +++ b/web_client/hvueComponentsGeneric.go @@ -17,6 +17,24 @@ func InitComponentsGeneric() { hvue.NewComponent( "startup-settings", hvue.Template(compStartupSettings), + hvue.DataFunc(func(vm *hvue.VM) interface{} { + data := &struct { + *js.Object + MasterTemplateName string `js:"MasterTemplateName"` + + ShowTemplateSelect bool `js:"ShowTemplateSelect"` + }{Object: O()} + + data.ShowTemplateSelect = false + data.MasterTemplateName = "startup" + //data.MasterTemplate = NewMasterTemplate() + return data + }), + hvue.Method("selectMasterTemplate", + func(vm *hvue.VM, name *js.Object) { + println("Selecting Startup Master Template :", name.String()) + vm.Set("MasterTemplateName", name) + }), ) hvue.NewComponent( "system", @@ -276,6 +294,22 @@ const compStartupSettings = `
+ + + + + Startup Master Template + The template which is loaded on service start + +
+
+ +
+
+
+
+
+
@@ -291,7 +325,7 @@ const compMasterTemplate = ` - + diff --git a/web_client/hvueComponentsTriggerActions.go b/web_client/hvueComponentsTriggerActions.go index e210547..0721262 100644 --- a/web_client/hvueComponentsTriggerActions.go +++ b/web_client/hvueComponentsTriggerActions.go @@ -151,11 +151,12 @@ func generateSelectOptionsTemplateTypes() *js.Object { return tts } +/* type TriggerActionCompData struct { *js.Object - EditMode bool `js:"EditMode"` + Edit bool `js:"Edit"` } - +*/ func InitComponentsTriggerActions() { @@ -176,9 +177,23 @@ func InitComponentsTriggerActions() { data.TemplateName = "" return &data }), + hvue.Method("editTa", + func(vm *hvue.VM, taID *js.Object) { + vm.Get("$refs").Index(taID.Int()).Index(0).Call("setEditMode", true) + }), hvue.Method("addTA", func(vm *hvue.VM) { - vm.Get("$store").Call("dispatch", VUEX_ACTION_ADD_NEW_TRIGGER_ACTION) + promise := vm.Get("$store").Call("dispatch", VUEX_ACTION_ADD_NEW_TRIGGER_ACTION) + promise.Call("then", + func(value *js.Object) { + // set the trigger action into edit mode + vm.Call("editTa", value) + }, + func(reason *js.Object) { + println("add TriggerAction failed", reason) + }, + ) + }), hvue.Method("storeTAS", func(vm *hvue.VM, name *js.Object) { @@ -219,6 +234,9 @@ func InitComponentsTriggerActions() { hvue.Mounted(func(vm *hvue.VM) { vm.Store.Call("dispatch", VUEX_ACTION_UPDATE_CURRENT_TRIGGER_ACTIONS_FROM_SERVER) vm.Store.Call("dispatch", VUEX_ACTION_UPDATE_GPIO_NAMES_LIST) + + js.Global.Set("tam",vm) + }), ) @@ -227,13 +245,64 @@ func InitComponentsTriggerActions() { hvue.NewComponent( "TriggerAction", hvue.Template(templateTriggerAction), + hvue.DataFunc(func(vm *hvue.VM) interface{} { + data := &struct { + *js.Object + Edit bool `js:"Edit"` + }{Object:O()} + data.Edit = false + return data + }), hvue.PropObj("ta"), + hvue.PropObj("edit", + hvue.Types(hvue.PBoolean), + ), + hvue.Method("setEditMode", + func(vm *hvue.VM, enabled bool) { + vm.Data.Set("Edit", enabled) + }), + hvue.Mounted(func(vm *hvue.VM) { + vm.Set("Edit", vm.Get("edit")) + }), ) hvue.NewComponent( "TriggerActionOverview", hvue.Template(templateTriggerActionOverview), hvue.PropObj("ta"), + hvue.PropObj("edit", + hvue.Types(hvue.PBoolean), + ), +/* + hvue.Mounted(func(vm *hvue.VM) { + data := TriggerActionCompData{Object: vm.Data} + data.Edit = vm.Get("edit").Bool() + }), +*/ + /* + hvue.DataFunc(func(vm *hvue.VM) interface{} { + data := &TriggerActionCompData{Object: O()} + data.Edit = false + + return data + }), + */ + hvue.ComputedWithGetSet("EditMode", + func(vm *hvue.VM) interface{} { + /* + data := TriggerActionCompData{Object: vm.Data} + return data.Edit + */ + return vm.Get("edit") + }, + func(vm *hvue.VM, newValue *js.Object) { +/* + data := TriggerActionCompData{Object: vm.Data} + data.Edit = newValue.Bool() +*/ + // Emit event for editmode change + vm.Emit("edit", newValue) + }), hvue.Computed("computedColor", func(vm *hvue.VM) interface{} { ta := &jsTriggerAction{Object: vm.Get("ta")} switch { @@ -329,22 +398,7 @@ func InitComponentsTriggerActions() { } return strAction }), - hvue.Mounted(func(vm *hvue.VM) { - data := TriggerActionCompData{Object: vm.Data} - data.EditMode = vm.Get("overview").Bool() - }), - hvue.DataFunc(func(vm *hvue.VM) interface{} { - data := &TriggerActionCompData{Object: O()} - data.EditMode = false - return data - }), - hvue.Method( - "enableEditMode", - func(vm *hvue.VM) { - data := TriggerActionCompData{Object: vm.Data} - data.EditMode = true - }), hvue.Method( "updateTA", func(vm *hvue.VM) { @@ -603,7 +657,7 @@ func InitComponentsTriggerActions() { const templateTriggerAction = `
- +
` const templateTriggerActionOverview = ` @@ -632,7 +686,7 @@ const templateTriggerActionOverview = `
- +
@@ -710,7 +764,7 @@ const templateTrigger = ` Value The numeric value which has to be received to activate the trigger - + @@ -778,7 +832,7 @@ const templateTrigger = ` Debounce duration Successive edge events in this duration are ignored - + @@ -857,7 +911,7 @@ const templateAction = ` Value The numeric value which is sent to the group channel - + @@ -919,7 +973,7 @@ const templateTriggerActionManager = `
- +
diff --git a/web_client/mvuexGlobalState.go b/web_client/mvuexGlobalState.go index 7c263e5..00b41b6 100644 --- a/web_client/mvuexGlobalState.go +++ b/web_client/mvuexGlobalState.go @@ -1136,7 +1136,8 @@ func actionUpdateStoredTriggerActionSetsList(store *mvuex.Store, context *mvuex. return } -func actionUpdateCurrentTriggerActionsFromServer(store *mvuex.Store, context *mvuex.ActionContext, state *GlobalState) { +func actionUpdateCurrentTriggerActionsFromServer(store *mvuex.Store, context *mvuex.ActionContext, state *GlobalState) *js.Object{ +/* go func() { println("Trying to fetch current TriggerActions from server") tastate, err := RpcClient.GetDeployedTriggerActionSet(defaultTimeout) @@ -1157,18 +1158,59 @@ func actionUpdateCurrentTriggerActionsFromServer(store *mvuex.Store, context *mv }() return +*/ + return NewPromise(func() (res interface{}, err error) { + println("Trying to fetch current TriggerActions from server") + tastate, err := RpcClient.GetDeployedTriggerActionSet(defaultTimeout) + if err != nil { + QuasarNotifyError("Error fetching deployed TriggerActions", err.Error(), QUASAR_NOTIFICATION_POSITION_TOP) + return false,err + } + + // ToDo: Clear list berfore adding back elements + state.TriggerActionList.Flush() + + for _, ta := range tastate.TriggerActions { + + jsTA := NewTriggerAction() + jsTA.fromGo(ta) + state.TriggerActionList.UpdateEntry(jsTA) + } + + return true,err + }).Object + } -func actionAddNewTriggerAction(store *mvuex.Store, context *mvuex.ActionContext, state *GlobalState) { - go func() { +func actionAddNewTriggerAction(store *mvuex.Store, context *mvuex.ActionContext, state *GlobalState) interface{} { + return NewPromise(func() (res interface{}, err error) { newTA := NewTriggerAction() newTA.IsActive = false // don't activate by default - RpcClient.DeployTriggerActionsSetAdd(defaultTimeout, &pb.TriggerActionSet{TriggerActions: []*pb.TriggerAction{newTA.toGo()}}) + added,_ := RpcClient.DeployTriggerActionsSetAdd(defaultTimeout, &pb.TriggerActionSet{TriggerActions: []*pb.TriggerAction{newTA.toGo()}}) + if added != nil && (len(added.TriggerActions) == 1) { + res = added.TriggerActions[0].Id + println("TriggerAction with ID", res, "added") + + } else { + err = errors.New("couldn't add TriggerAction") + } + + return + }).Call("then", + func(resAddPromise *js.Object) interface{} { + // set the trigger action into edit mode + updatePromise := actionUpdateCurrentTriggerActionsFromServer(store, context, state) + + return updatePromise.Call("then", + func(resUpdatePromise *js.Object) interface{} { + // set the trigger action into edit mode + return resAddPromise + }, + ) + }, + ) - actionUpdateCurrentTriggerActionsFromServer(store, context, state) - }() - return } func actionUpdateTriggerActions(store *mvuex.Store, context *mvuex.ActionContext, state *GlobalState, jsTas *jsTriggerActionSet) { diff --git a/web_client/promise.go b/web_client/promise.go index bbb62a7..909ea1e 100644 --- a/web_client/promise.go +++ b/web_client/promise.go @@ -49,4 +49,4 @@ func NewPromise(pf PromiseFunc) (p *Promise) { Object: jsP, } return -} \ No newline at end of file +}