From 3988f8b84918d3f369215f337eaa985155f37fc1 Mon Sep 17 00:00:00 2001 From: MaMe82 Date: Fri, 12 Oct 2018 15:27:01 +0200 Subject: [PATCH] TriggerAction: finalized webclient+gRPC, minor fix, mobile vie adjustments --- service/rpc_server.go | 12 ++++-- web_client/hvueComponentsTriggerActions.go | 28 +++++++++++-- web_client/mvuexGlobalState.go | 47 ++++++++++++++++++---- 3 files changed, 73 insertions(+), 14 deletions(-) diff --git a/service/rpc_server.go b/service/rpc_server.go index 44da1ee..8efbe97 100644 --- a/service/rpc_server.go +++ b/service/rpc_server.go @@ -88,10 +88,14 @@ func (s *server) DeployTriggerActionSetReplace(ctx context.Context, tas *pb.Trig } func (s *server) DeployTriggerActionSetAdd(ctx context.Context, tas *pb.TriggerActionSet) (resTas *pb.TriggerActionSet, err error) { - addedTA := make([]*pb.TriggerAction, len(tas.TriggerActions)) - for idx,ta := range tas.TriggerActions { - addedTA[idx],err = s.rootSvc.SubSysTriggerActions.AddTriggerAction(ta) - if err != nil { return s.rootSvc.SubSysTriggerActions.GetCurrentTriggerActionSet(),err } + addedTA := make([]*pb.TriggerAction, 0) + for _,ta := range tas.TriggerActions { + // we don't allow adding immutable settings via RPC call + if !ta.Immutable { + added,err := s.rootSvc.SubSysTriggerActions.AddTriggerAction(ta) + if err != nil { return s.rootSvc.SubSysTriggerActions.GetCurrentTriggerActionSet(),err } + addedTA = append(addedTA, added) + } } resTas = &pb.TriggerActionSet{TriggerActions:addedTA, Name: "Added TriggerActions"} diff --git a/web_client/hvueComponentsTriggerActions.go b/web_client/hvueComponentsTriggerActions.go index 867588e..3f10329 100644 --- a/web_client/hvueComponentsTriggerActions.go +++ b/web_client/hvueComponentsTriggerActions.go @@ -316,11 +316,17 @@ func InitComponentsTriggerActions() { "updateTA", func(vm *hvue.VM) { println("update ta: ", vm.Get("ta")) + //Replace the whole TriggerActionSet of server with the current one from vuex store + // ToDo: This has to be changed to update a single action (inconssistnecy with multiple clients, all TA IDs change, overhead of transferring a whole set) -> has to be implemented like deleteTA logic + currentTas := vm.Get("$store").Get("state").Get("triggerActionList") //Current TriggerActionSet of ViewModel + vm.Get("$store").Call("dispatch", VUEX_ACTION_DEPLOY_TRIGGER_ACTION_SET_REPLACE, currentTas) }), hvue.Method( "cancelUpdateTA", func(vm *hvue.VM) { println("cancel update ta: ", vm.Get("ta")) + //Reload the whole TriggerActionSet from server and overwrite the current one of vuex store + vm.Get("$store").Call("dispatch", VUEX_ACTION_UPDATE_CURRENT_TRIGGER_ACTIONS_FROM_SERVER) }), hvue.Method( "deleteTA", @@ -486,7 +492,7 @@ const templateTriggerActionOverview = ` - + @@ -496,7 +502,7 @@ const templateTriggerActionOverview = ` {{ ta.Immutable ? "immutable, " : "" }} {{ ta.IsActive ? "enabled" : "disabled" }} - TriggerAction + TriggerAction (ID {{ ta.Id }}) @@ -519,7 +525,7 @@ const templateTriggerActionEdit = ` TriggerAction ID {{ ta.Id }} - + @@ -749,12 +755,28 @@ const templateTriggerActionManager = `
+ + TriggerAction Manager + + + + +
+
+
+
+
+
+
+ +
diff --git a/web_client/mvuexGlobalState.go b/web_client/mvuexGlobalState.go index 6aa8d92..8c80002 100644 --- a/web_client/mvuexGlobalState.go +++ b/web_client/mvuexGlobalState.go @@ -24,12 +24,14 @@ const ( VUEX_ACTION_UPDATE_CURRENT_TRIGGER_ACTIONS_FROM_SERVER = "updateCurrentTriggerActionsFromServer" - VUEX_ACTION_ADD_NEW_TRIGGER_ACTION = "addTriggerAction" - VUEX_ACTION_REMOVE_TRIGGER_ACTIONS = "removeTriggerActions" - VUEX_ACTION_STORE_TRIGGER_ACTION_SET = "storeTriggerActionSet" - VUEX_ACTION_UPDATE_STORED_TRIGGER_ACTION_SETS_LIST = "updateStoredTriggerActionSetsList" - VUEX_ACTION_DEPLOY_STORED_TRIGGER_ACTION_SET_REPLACE = "deployStoredTriggerActionSetReplace" + VUEX_ACTION_ADD_NEW_TRIGGER_ACTION = "addTriggerAction" + VUEX_ACTION_REMOVE_TRIGGER_ACTIONS = "removeTriggerActions" + VUEX_ACTION_STORE_TRIGGER_ACTION_SET = "storeTriggerActionSet" + VUEX_ACTION_UPDATE_STORED_TRIGGER_ACTION_SETS_LIST = "updateStoredTriggerActionSetsList" + VUEX_ACTION_DEPLOY_STORED_TRIGGER_ACTION_SET_REPLACE = "deployStoredTriggerActionSetReplace" VUEX_ACTION_DEPLOY_STORED_TRIGGER_ACTION_SET_ADD = "deployStoredTriggerActionSetAdd" + VUEX_ACTION_DEPLOY_TRIGGER_ACTION_SET_REPLACE = "deployCurrentTriggerActionSetReplace" + VUEX_ACTION_DEPLOY_TRIGGER_ACTION_SET_ADD = "deployCurrentTriggerActionSetAdd" VUEX_ACTION_UPDATE_STORED_WIFI_SETTINGS_LIST = "updateStoredWifiSettingsList" VUEX_ACTION_STORE_WIFI_SETTINGS = "storeWifiSettings" @@ -309,6 +311,37 @@ func actionStoreTriggerActionSet(store *mvuex.Store, context *mvuex.ActionContex }() } +func actionDeployTriggerActionSetReplace(store *mvuex.Store, context *mvuex.ActionContext, state *GlobalState, tasToDeploy *jsTriggerActionSet) { + go func() { + tas := tasToDeploy.toGo() + + _,err := RpcClient.DeployTriggerActionsSetReplace(defaultTimeout, tas) + if err != nil { + QuasarNotifyError("Error replacing TriggerActionSet with given one", err.Error(), QUASAR_NOTIFICATION_POSITION_BOTTOM) + return + } + QuasarNotifySuccess("Replaced TriggerActionSet with given one", "", QUASAR_NOTIFICATION_POSITION_TOP) + + actionUpdateCurrentTriggerActionsFromServer(store,context,state) + }() +} + +func actionDeployTriggerActionSetAdd(store *mvuex.Store, context *mvuex.ActionContext, state *GlobalState, tasToDeploy *jsTriggerActionSet) { + go func() { + tas := tasToDeploy.toGo() + _,err := RpcClient.DeployTriggerActionsSetAdd(defaultTimeout, tas) + if err != nil { + QuasarNotifyError("Error adding given TriggerActionSet to server", err.Error(), QUASAR_NOTIFICATION_POSITION_BOTTOM) + return + } + QuasarNotifySuccess("Added TriggerActionSet to server", "", QUASAR_NOTIFICATION_POSITION_TOP) + + actionUpdateCurrentTriggerActionsFromServer(store,context,state) + }() +} + + + func actionDeployStoredTriggerActionSetReplace(store *mvuex.Store, context *mvuex.ActionContext, state *GlobalState, jsName *js.Object) { go func() { name := jsName.String() @@ -347,8 +380,6 @@ func actionDeployStoredTriggerActionSetAdd(store *mvuex.Store, context *mvuex.Ac }() } - - func actionDeployCurrentGadgetSettings(store *mvuex.Store, context *mvuex.ActionContext, state *GlobalState) { go func() { @@ -451,6 +482,8 @@ func initMVuex() *mvuex.Store { mvuex.Action(VUEX_ACTION_UPDATE_STORED_TRIGGER_ACTION_SETS_LIST, actionUpdateStoredTriggerActionSetsList), mvuex.Action(VUEX_ACTION_DEPLOY_STORED_TRIGGER_ACTION_SET_REPLACE, actionDeployStoredTriggerActionSetReplace), mvuex.Action(VUEX_ACTION_DEPLOY_STORED_TRIGGER_ACTION_SET_ADD, actionDeployStoredTriggerActionSetAdd), + mvuex.Action(VUEX_ACTION_DEPLOY_TRIGGER_ACTION_SET_REPLACE, actionDeployTriggerActionSetReplace), + mvuex.Action(VUEX_ACTION_DEPLOY_TRIGGER_ACTION_SET_ADD, actionDeployTriggerActionSetAdd), mvuex.Getter("triggerActions", func(state *GlobalState) interface{} { return state.TriggerActionList.TriggerActions