mirror of
https://github.com/RoganDawes/P4wnP1_aloa.git
synced 2025-04-12 05:59:03 +02:00
Webclient,proto,service: store,deploy,load of MasterTemplate
This commit is contained in:
parent
2021ddcfc0
commit
1ad1c35318
@ -8,6 +8,8 @@
|
||||
grpc.proto
|
||||
|
||||
It has these top-level messages:
|
||||
MasterTemplate
|
||||
RequestMasterTemplateStorage
|
||||
BluetoothRequestSettingsStorage
|
||||
BluetoothSettings
|
||||
BluetoothAgentSettings
|
||||
@ -198,6 +200,16 @@ const (
|
||||
GPIONum_NUM_18 GPIONum = 17
|
||||
GPIONum_NUM_19 GPIONum = 18
|
||||
GPIONum_NUM_20 GPIONum = 19
|
||||
GPIONum_NUM_21 GPIONum = 20
|
||||
GPIONum_NUM_22 GPIONum = 21
|
||||
GPIONum_NUM_23 GPIONum = 22
|
||||
GPIONum_NUM_24 GPIONum = 23
|
||||
GPIONum_NUM_25 GPIONum = 24
|
||||
GPIONum_NUM_26 GPIONum = 25
|
||||
GPIONum_NUM_27 GPIONum = 26
|
||||
GPIONum_NUM_28 GPIONum = 27
|
||||
GPIONum_NUM_29 GPIONum = 28
|
||||
GPIONum_NUM_30 GPIONum = 29
|
||||
)
|
||||
|
||||
var GPIONum_name = map[int]string{
|
||||
@ -221,6 +233,16 @@ var GPIONum_name = map[int]string{
|
||||
17: "NUM_18",
|
||||
18: "NUM_19",
|
||||
19: "NUM_20",
|
||||
20: "NUM_21",
|
||||
21: "NUM_22",
|
||||
22: "NUM_23",
|
||||
23: "NUM_24",
|
||||
24: "NUM_25",
|
||||
25: "NUM_26",
|
||||
26: "NUM_27",
|
||||
27: "NUM_28",
|
||||
28: "NUM_29",
|
||||
29: "NUM_30",
|
||||
}
|
||||
var GPIONum_value = map[string]int{
|
||||
"NUM_1": 0,
|
||||
@ -243,6 +265,16 @@ var GPIONum_value = map[string]int{
|
||||
"NUM_18": 17,
|
||||
"NUM_19": 18,
|
||||
"NUM_20": 19,
|
||||
"NUM_21": 20,
|
||||
"NUM_22": 21,
|
||||
"NUM_23": 22,
|
||||
"NUM_24": 23,
|
||||
"NUM_25": 24,
|
||||
"NUM_26": 25,
|
||||
"NUM_27": 26,
|
||||
"NUM_28": 27,
|
||||
"NUM_29": 28,
|
||||
"NUM_30": 29,
|
||||
}
|
||||
|
||||
func (x GPIONum) String() string {
|
||||
@ -423,6 +455,212 @@ func (x EthernetInterfaceSettings_Mode) String() string {
|
||||
return EthernetInterfaceSettings_Mode_name[int(x)]
|
||||
}
|
||||
|
||||
// MasterTemplates
|
||||
type MasterTemplate struct {
|
||||
TemplateNameBluetooth string
|
||||
TemplateNameUsb string
|
||||
TemplateNameWifi string
|
||||
TemplateNameTriggerActions string
|
||||
TemplateNamesNetwork []string
|
||||
}
|
||||
|
||||
// GetTemplateNameBluetooth gets the TemplateNameBluetooth of the MasterTemplate.
|
||||
func (m *MasterTemplate) GetTemplateNameBluetooth() (x string) {
|
||||
if m == nil {
|
||||
return x
|
||||
}
|
||||
return m.TemplateNameBluetooth
|
||||
}
|
||||
|
||||
// GetTemplateNameUsb gets the TemplateNameUsb of the MasterTemplate.
|
||||
func (m *MasterTemplate) GetTemplateNameUsb() (x string) {
|
||||
if m == nil {
|
||||
return x
|
||||
}
|
||||
return m.TemplateNameUsb
|
||||
}
|
||||
|
||||
// GetTemplateNameWifi gets the TemplateNameWifi of the MasterTemplate.
|
||||
func (m *MasterTemplate) GetTemplateNameWifi() (x string) {
|
||||
if m == nil {
|
||||
return x
|
||||
}
|
||||
return m.TemplateNameWifi
|
||||
}
|
||||
|
||||
// GetTemplateNameTriggerActions gets the TemplateNameTriggerActions of the MasterTemplate.
|
||||
func (m *MasterTemplate) GetTemplateNameTriggerActions() (x string) {
|
||||
if m == nil {
|
||||
return x
|
||||
}
|
||||
return m.TemplateNameTriggerActions
|
||||
}
|
||||
|
||||
// GetTemplateNamesNetwork gets the TemplateNamesNetwork of the MasterTemplate.
|
||||
func (m *MasterTemplate) GetTemplateNamesNetwork() (x []string) {
|
||||
if m == nil {
|
||||
return x
|
||||
}
|
||||
return m.TemplateNamesNetwork
|
||||
}
|
||||
|
||||
// MarshalToWriter marshals MasterTemplate to the provided writer.
|
||||
func (m *MasterTemplate) MarshalToWriter(writer jspb.Writer) {
|
||||
if m == nil {
|
||||
return
|
||||
}
|
||||
|
||||
if len(m.TemplateNameBluetooth) > 0 {
|
||||
writer.WriteString(1, m.TemplateNameBluetooth)
|
||||
}
|
||||
|
||||
if len(m.TemplateNameUsb) > 0 {
|
||||
writer.WriteString(2, m.TemplateNameUsb)
|
||||
}
|
||||
|
||||
if len(m.TemplateNameWifi) > 0 {
|
||||
writer.WriteString(3, m.TemplateNameWifi)
|
||||
}
|
||||
|
||||
if len(m.TemplateNameTriggerActions) > 0 {
|
||||
writer.WriteString(4, m.TemplateNameTriggerActions)
|
||||
}
|
||||
|
||||
for _, val := range m.TemplateNamesNetwork {
|
||||
writer.WriteString(5, val)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Marshal marshals MasterTemplate to a slice of bytes.
|
||||
func (m *MasterTemplate) Marshal() []byte {
|
||||
writer := jspb.NewWriter()
|
||||
m.MarshalToWriter(writer)
|
||||
return writer.GetResult()
|
||||
}
|
||||
|
||||
// UnmarshalFromReader unmarshals a MasterTemplate from the provided reader.
|
||||
func (m *MasterTemplate) UnmarshalFromReader(reader jspb.Reader) *MasterTemplate {
|
||||
for reader.Next() {
|
||||
if m == nil {
|
||||
m = &MasterTemplate{}
|
||||
}
|
||||
|
||||
switch reader.GetFieldNumber() {
|
||||
case 1:
|
||||
m.TemplateNameBluetooth = reader.ReadString()
|
||||
case 2:
|
||||
m.TemplateNameUsb = reader.ReadString()
|
||||
case 3:
|
||||
m.TemplateNameWifi = reader.ReadString()
|
||||
case 4:
|
||||
m.TemplateNameTriggerActions = reader.ReadString()
|
||||
case 5:
|
||||
m.TemplateNamesNetwork = append(m.TemplateNamesNetwork, reader.ReadString())
|
||||
default:
|
||||
reader.SkipField()
|
||||
}
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
// Unmarshal unmarshals a MasterTemplate from a slice of bytes.
|
||||
func (m *MasterTemplate) Unmarshal(rawBytes []byte) (*MasterTemplate, error) {
|
||||
reader := jspb.NewReader(rawBytes)
|
||||
|
||||
m = m.UnmarshalFromReader(reader)
|
||||
|
||||
if err := reader.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return m, nil
|
||||
}
|
||||
|
||||
type RequestMasterTemplateStorage struct {
|
||||
TemplateName string
|
||||
Template *MasterTemplate
|
||||
}
|
||||
|
||||
// GetTemplateName gets the TemplateName of the RequestMasterTemplateStorage.
|
||||
func (m *RequestMasterTemplateStorage) GetTemplateName() (x string) {
|
||||
if m == nil {
|
||||
return x
|
||||
}
|
||||
return m.TemplateName
|
||||
}
|
||||
|
||||
// GetTemplate gets the Template of the RequestMasterTemplateStorage.
|
||||
func (m *RequestMasterTemplateStorage) GetTemplate() (x *MasterTemplate) {
|
||||
if m == nil {
|
||||
return x
|
||||
}
|
||||
return m.Template
|
||||
}
|
||||
|
||||
// MarshalToWriter marshals RequestMasterTemplateStorage to the provided writer.
|
||||
func (m *RequestMasterTemplateStorage) MarshalToWriter(writer jspb.Writer) {
|
||||
if m == nil {
|
||||
return
|
||||
}
|
||||
|
||||
if len(m.TemplateName) > 0 {
|
||||
writer.WriteString(1, m.TemplateName)
|
||||
}
|
||||
|
||||
if m.Template != nil {
|
||||
writer.WriteMessage(2, func() {
|
||||
m.Template.MarshalToWriter(writer)
|
||||
})
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Marshal marshals RequestMasterTemplateStorage to a slice of bytes.
|
||||
func (m *RequestMasterTemplateStorage) Marshal() []byte {
|
||||
writer := jspb.NewWriter()
|
||||
m.MarshalToWriter(writer)
|
||||
return writer.GetResult()
|
||||
}
|
||||
|
||||
// UnmarshalFromReader unmarshals a RequestMasterTemplateStorage from the provided reader.
|
||||
func (m *RequestMasterTemplateStorage) UnmarshalFromReader(reader jspb.Reader) *RequestMasterTemplateStorage {
|
||||
for reader.Next() {
|
||||
if m == nil {
|
||||
m = &RequestMasterTemplateStorage{}
|
||||
}
|
||||
|
||||
switch reader.GetFieldNumber() {
|
||||
case 1:
|
||||
m.TemplateName = reader.ReadString()
|
||||
case 2:
|
||||
reader.ReadMessage(func() {
|
||||
m.Template = m.Template.UnmarshalFromReader(reader)
|
||||
})
|
||||
default:
|
||||
reader.SkipField()
|
||||
}
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
// Unmarshal unmarshals a RequestMasterTemplateStorage from a slice of bytes.
|
||||
func (m *RequestMasterTemplateStorage) Unmarshal(rawBytes []byte) (*RequestMasterTemplateStorage, error) {
|
||||
reader := jspb.NewReader(rawBytes)
|
||||
|
||||
m = m.UnmarshalFromReader(reader)
|
||||
|
||||
if err := reader.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// Bluetooth
|
||||
type BluetoothRequestSettingsStorage struct {
|
||||
TemplateName string
|
||||
@ -6391,6 +6629,13 @@ type P4WNP1Client interface {
|
||||
// TriggerAction for cli (trigger group send and wait for group receive)
|
||||
WaitTriggerGroupReceive(ctx context.Context, in *TriggerGroupReceive, opts ...grpcweb.CallOption) (*Empty, error)
|
||||
FireActionGroupSend(ctx context.Context, in *ActionGroupSend, opts ...grpcweb.CallOption) (*Empty, error)
|
||||
// MasterTemplates
|
||||
DeployMasterTemplate(ctx context.Context, in *MasterTemplate, opts ...grpcweb.CallOption) (*Empty, error)
|
||||
StoreMasterTemplate(ctx context.Context, in *RequestMasterTemplateStorage, opts ...grpcweb.CallOption) (*Empty, error)
|
||||
GetStoredMasterTemplate(ctx context.Context, in *StringMessage, opts ...grpcweb.CallOption) (*MasterTemplate, error)
|
||||
DeployStoredMasterTemplate(ctx context.Context, in *StringMessage, opts ...grpcweb.CallOption) (*MasterTemplate, error)
|
||||
DeleteStoredMasterTemplate(ctx context.Context, in *StringMessage, opts ...grpcweb.CallOption) (*Empty, error)
|
||||
ListStoredMasterTemplate(ctx context.Context, in *Empty, opts ...grpcweb.CallOption) (*StringMessageArray, error)
|
||||
// DB backup&restore
|
||||
DBBackup(ctx context.Context, in *StringMessage, opts ...grpcweb.CallOption) (*Empty, error)
|
||||
DBRestore(ctx context.Context, in *StringMessage, opts ...grpcweb.CallOption) (*Empty, error)
|
||||
@ -7027,6 +7272,60 @@ func (c *p4WNP1Client) FireActionGroupSend(ctx context.Context, in *ActionGroupS
|
||||
return new(Empty).Unmarshal(resp)
|
||||
}
|
||||
|
||||
func (c *p4WNP1Client) DeployMasterTemplate(ctx context.Context, in *MasterTemplate, opts ...grpcweb.CallOption) (*Empty, error) {
|
||||
resp, err := c.client.RPCCall(ctx, "DeployMasterTemplate", in.Marshal(), opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return new(Empty).Unmarshal(resp)
|
||||
}
|
||||
|
||||
func (c *p4WNP1Client) StoreMasterTemplate(ctx context.Context, in *RequestMasterTemplateStorage, opts ...grpcweb.CallOption) (*Empty, error) {
|
||||
resp, err := c.client.RPCCall(ctx, "StoreMasterTemplate", in.Marshal(), opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return new(Empty).Unmarshal(resp)
|
||||
}
|
||||
|
||||
func (c *p4WNP1Client) GetStoredMasterTemplate(ctx context.Context, in *StringMessage, opts ...grpcweb.CallOption) (*MasterTemplate, error) {
|
||||
resp, err := c.client.RPCCall(ctx, "GetStoredMasterTemplate", in.Marshal(), opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return new(MasterTemplate).Unmarshal(resp)
|
||||
}
|
||||
|
||||
func (c *p4WNP1Client) DeployStoredMasterTemplate(ctx context.Context, in *StringMessage, opts ...grpcweb.CallOption) (*MasterTemplate, error) {
|
||||
resp, err := c.client.RPCCall(ctx, "DeployStoredMasterTemplate", in.Marshal(), opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return new(MasterTemplate).Unmarshal(resp)
|
||||
}
|
||||
|
||||
func (c *p4WNP1Client) DeleteStoredMasterTemplate(ctx context.Context, in *StringMessage, opts ...grpcweb.CallOption) (*Empty, error) {
|
||||
resp, err := c.client.RPCCall(ctx, "DeleteStoredMasterTemplate", in.Marshal(), opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return new(Empty).Unmarshal(resp)
|
||||
}
|
||||
|
||||
func (c *p4WNP1Client) ListStoredMasterTemplate(ctx context.Context, in *Empty, opts ...grpcweb.CallOption) (*StringMessageArray, error) {
|
||||
resp, err := c.client.RPCCall(ctx, "ListStoredMasterTemplate", in.Marshal(), opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return new(StringMessageArray).Unmarshal(resp)
|
||||
}
|
||||
|
||||
func (c *p4WNP1Client) DBBackup(ctx context.Context, in *StringMessage, opts ...grpcweb.CallOption) (*Empty, error) {
|
||||
resp, err := c.client.RPCCall(ctx, "DBBackup", in.Marshal(), opts...)
|
||||
if err != nil {
|
||||
|
1040
proto/grpc.pb.go
1040
proto/grpc.pb.go
File diff suppressed because it is too large
Load Diff
@ -100,6 +100,15 @@ service P4WNP1 {
|
||||
rpc FireActionGroupSend(ActionGroupSend) returns (Empty) {}
|
||||
|
||||
|
||||
//MasterTemplates
|
||||
rpc DeployMasterTemplate(MasterTemplate) returns (Empty) {}
|
||||
|
||||
rpc StoreMasterTemplate(RequestMasterTemplateStorage) returns (Empty) {}
|
||||
rpc GetStoredMasterTemplate(StringMessage) returns (MasterTemplate) {}
|
||||
rpc DeployStoredMasterTemplate(StringMessage) returns (MasterTemplate) {}
|
||||
rpc DeleteStoredMasterTemplate(StringMessage) returns (Empty) {}
|
||||
rpc ListStoredMasterTemplate(Empty) returns (StringMessageArray) {}
|
||||
|
||||
|
||||
// DB backup&restore
|
||||
rpc DBBackup(StringMessage) returns(Empty) {}
|
||||
@ -110,6 +119,19 @@ service P4WNP1 {
|
||||
rpc ListStoredDBBackups(Empty) returns (StringMessageArray) {}
|
||||
}
|
||||
|
||||
/* MasterTemplates */
|
||||
message MasterTemplate {
|
||||
string template_name_bluetooth = 1;
|
||||
string template_name_usb = 2;
|
||||
string template_name_wifi = 3;
|
||||
string template_name_trigger_actions = 4;
|
||||
repeated string template_names_network = 5;
|
||||
}
|
||||
|
||||
message RequestMasterTemplateStorage {
|
||||
string TemplateName = 1;
|
||||
MasterTemplate template = 2;
|
||||
}
|
||||
|
||||
|
||||
/* Bluetooth */
|
||||
@ -118,8 +140,6 @@ message BluetoothRequestSettingsStorage {
|
||||
BluetoothSettings settings = 2;
|
||||
}
|
||||
|
||||
|
||||
|
||||
message BluetoothSettings {
|
||||
BluetoothControllerInformation ci = 1; //Parts interpreted as settings: current_settings, name, service_network_server_nap, service_network_server_panu, service_network_server_gn
|
||||
BluetoothAgentSettings as = 2;
|
||||
@ -272,6 +292,16 @@ enum GPIONum {
|
||||
NUM_18 = 17;
|
||||
NUM_19 = 18;
|
||||
NUM_20 = 19;
|
||||
NUM_21 = 20;
|
||||
NUM_22 = 21;
|
||||
NUM_23 = 22;
|
||||
NUM_24 = 23;
|
||||
NUM_25 = 24;
|
||||
NUM_26 = 25;
|
||||
NUM_27 = 26;
|
||||
NUM_28 = 27;
|
||||
NUM_29 = 28;
|
||||
NUM_30 = 29;
|
||||
}
|
||||
message TriggerGPIOIn {
|
||||
GPIONum gpioNum = 1;
|
||||
|
@ -330,7 +330,12 @@ func (tam *TriggerActionManager) executeActionDeploySettingsTemplate(evt *pb.Eve
|
||||
|
||||
switch action.Type {
|
||||
case pb.ActionDeploySettingsTemplate_FULL_SETTINGS:
|
||||
// ToDo: Implement
|
||||
_,err := tam.rootSvc.SubSysRPC.DeployStoredMasterTemplate(context.Background(), &pb.StringMessage{Msg: action.TemplateName})
|
||||
if err == nil {
|
||||
fmt.Println("... stored settings deployed")
|
||||
} else {
|
||||
fmt.Println("... deploying stored settings failed: ", err.Error())
|
||||
}
|
||||
case pb.ActionDeploySettingsTemplate_NETWORK:
|
||||
_,err := tam.rootSvc.SubSysRPC.DeployStoredEthernetInterfaceSettings(context.Background(), &pb.StringMessage{Msg: action.TemplateName})
|
||||
if err == nil {
|
||||
@ -353,7 +358,12 @@ func (tam *TriggerActionManager) executeActionDeploySettingsTemplate(evt *pb.Eve
|
||||
fmt.Println("... deploying stored settings failed: ", err.Error())
|
||||
}
|
||||
case pb.ActionDeploySettingsTemplate_BLUETOOTH:
|
||||
// ToDo: Implement
|
||||
_,err := tam.rootSvc.SubSysRPC.DeployStoredBluetoothSettings(context.Background(), &pb.StringMessage{Msg: action.TemplateName})
|
||||
if err == nil {
|
||||
fmt.Println("... stored settings deployed")
|
||||
} else {
|
||||
fmt.Println("... deploying stored settings failed: ", err.Error())
|
||||
}
|
||||
case pb.ActionDeploySettingsTemplate_TRIGGER_ACTIONS:
|
||||
_,err := tam.rootSvc.SubSysRPC.DeployStoredTriggerActionSetReplace(context.Background(), &pb.StringMessage{Msg: action.TemplateName})
|
||||
if err == nil {
|
||||
|
@ -34,6 +34,7 @@ const (
|
||||
cSTORE_PREFIX_ETHERNET_INTERFACE_SETTINGS = "eis_"
|
||||
cSTORE_PREFIX_TRIGGER_ACTION_SET = "tas_"
|
||||
cSTORE_PREFIX_BLUETOOTH_SETTINGS = "bt_"
|
||||
cSTORE_PREFIX_MASTER_TEMPLATE = "master_"
|
||||
)
|
||||
|
||||
|
||||
@ -50,6 +51,73 @@ type server struct {
|
||||
listenAddrWeb string
|
||||
}
|
||||
|
||||
func (s *server) DeployMasterTemplate(ctx context.Context, mt *pb.MasterTemplate) (e *pb.Empty, err error) {
|
||||
e = &pb.Empty{}
|
||||
|
||||
//ignore templates with name of length 0
|
||||
if len(mt.TemplateNameTriggerActions) > 0 {
|
||||
_,err = s.DeployStoredTriggerActionSetReplace(ctx, &pb.StringMessage{Msg: mt.TemplateNameTriggerActions})
|
||||
if err != nil { return }
|
||||
|
||||
}
|
||||
|
||||
for _,nnw := range mt.TemplateNamesNetwork {
|
||||
_,err = s.DeployStoredEthernetInterfaceSettings(ctx, &pb.StringMessage{Msg: nnw})
|
||||
if err != nil { return }
|
||||
}
|
||||
|
||||
if len(mt.TemplateNameBluetooth) > 0 {
|
||||
_, err = s.DeployStoredBluetoothSettings(ctx, &pb.StringMessage{Msg: mt.TemplateNameBluetooth})
|
||||
if err != nil { return }
|
||||
}
|
||||
if len(mt.TemplateNameUsb) > 0 {
|
||||
_, err = s.DeployStoredUSBSettings(ctx, &pb.StringMessage{Msg: mt.TemplateNameUsb})
|
||||
if err != nil { return }
|
||||
}
|
||||
if len(mt.TemplateNameWifi) > 0 {
|
||||
_, err = s.DeployStoredWifiSettings(ctx, &pb.StringMessage{Msg: mt.TemplateNameWifi})
|
||||
if err != nil { return }
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (s *server) StoreMasterTemplate(ctx context.Context, r *pb.RequestMasterTemplateStorage) (e *pb.Empty, err error) {
|
||||
e = &pb.Empty{}
|
||||
|
||||
defer s.rootSvc.SubSysEvent.Emit(ConstructEventNotifyStateChange(common_web.STATE_CHANGE_EVT_TYPE_STORED_GLOBAL_SETTINGS_LIST))
|
||||
err = s.rootSvc.SubSysDataStore.Put(cSTORE_PREFIX_MASTER_TEMPLATE + r.TemplateName, r.Template, true)
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
func (s *server) GetStoredMasterTemplate(ctx context.Context, templateName *pb.StringMessage) (result *pb.MasterTemplate, err error) {
|
||||
result = &pb.MasterTemplate{}
|
||||
err = s.rootSvc.SubSysDataStore.Get(cSTORE_PREFIX_MASTER_TEMPLATE + templateName.Msg, result)
|
||||
return
|
||||
}
|
||||
|
||||
func (s *server) DeployStoredMasterTemplate(ctx context.Context, templateName *pb.StringMessage) (re *pb.MasterTemplate, err error) {
|
||||
re,err = s.GetStoredMasterTemplate(ctx,templateName)
|
||||
if err != nil { return }
|
||||
_,err = s.DeployMasterTemplate(ctx, re)
|
||||
return
|
||||
}
|
||||
|
||||
func (s *server) DeleteStoredMasterTemplate(ctx context.Context, templateName *pb.StringMessage) (e *pb.Empty, err error) {
|
||||
defer s.rootSvc.SubSysEvent.Emit(ConstructEventNotifyStateChange(common_web.STATE_CHANGE_EVT_TYPE_STORED_GLOBAL_SETTINGS_LIST))
|
||||
e = &pb.Empty{}
|
||||
err = s.rootSvc.SubSysDataStore.Delete(cSTORE_PREFIX_MASTER_TEMPLATE + templateName.Msg)
|
||||
return
|
||||
}
|
||||
|
||||
func (s *server) ListStoredMasterTemplate(ctx context.Context, e *pb.Empty) (sa *pb.StringMessageArray, err error) {
|
||||
sa = &pb.StringMessageArray{}
|
||||
res,err := s.rootSvc.SubSysDataStore.KeysPrefix(cSTORE_PREFIX_MASTER_TEMPLATE, true)
|
||||
if err != nil { return sa,err }
|
||||
sa.MsgArray = res
|
||||
return
|
||||
}
|
||||
|
||||
func (s *server) WaitTriggerGroupReceive(rpcCtx context.Context, triggerGR *pb.TriggerGroupReceive) (e *pb.Empty, err error) {
|
||||
e = &pb.Empty{}
|
||||
triggerVal := triggerGR.Value
|
||||
@ -414,7 +482,7 @@ func (s *server) Stop() error {
|
||||
}
|
||||
|
||||
func (s *server) StoreDeployedWifiSettings(ctx context.Context, m *pb.StringMessage) (e *pb.Empty, err error) {
|
||||
defer s.rootSvc.SubSysEvent.Emit(ConstructEventNotifyStateChange(common_web.STATE_CHANGE_EVT_TYPE_STORED_WIFI_SETTINGS_LIST))
|
||||
//defer s.rootSvc.SubSysEvent.Emit(ConstructEventNotifyStateChange(common_web.STATE_CHANGE_EVT_TYPE_STORED_WIFI_SETTINGS_LIST))
|
||||
return s.StoreWifiSettings(ctx, &pb.WifiRequestSettingsStorage{
|
||||
Settings: s.rootSvc.SubSysWifi.State.CurrentSettings,
|
||||
TemplateName: m.Msg,
|
||||
@ -429,7 +497,7 @@ func (s *server) DeployStoredWifiSettings(ctx context.Context, m *pb.StringMessa
|
||||
}
|
||||
|
||||
func (s *server) StoreWifiSettings(ctx context.Context, r *pb.WifiRequestSettingsStorage) (e *pb.Empty, err error) {
|
||||
defer s.rootSvc.SubSysEvent.Emit(ConstructEventNotifyStateChange(common_web.STATE_CHANGE_EVT_TYPE_WIFI))
|
||||
defer s.rootSvc.SubSysEvent.Emit(ConstructEventNotifyStateChange(common_web.STATE_CHANGE_EVT_TYPE_STORED_WIFI_SETTINGS_LIST))
|
||||
e = &pb.Empty{}
|
||||
err = s.rootSvc.SubSysDataStore.Put(cSTORE_PREFIX_WIFI_SETTINGS + r.TemplateName, r.Settings, true)
|
||||
return
|
||||
|
@ -121,10 +121,10 @@ const (
|
||||
<q-card-main>
|
||||
<div class="row gutter-sm">
|
||||
|
||||
<div class="col-6 col-sm""><q-btn class="fit" :loading="deploying" color="primary" @click="ApplyGadgetSettings" label="deploy" icon="launch"></q-btn></div>
|
||||
<div class="col-6 col-sm""><q-btn class="fit" color="primary" @click="updateStoredSettingsList(); showDeployStoredModal=true" label="deploy stored" icon="settings_backup_restore"></q-btn></div>
|
||||
<div class="col-6 col-sm""><q-btn class="fit" color="secondary" @click="UpdateFromDeployedGadgetSettings" label="reset" icon="autorenew"></q-btn></div>
|
||||
<div class="col-6 col-sm""><q-btn class="fit" color="secondary" @click="showStoreModal=true" label="store" icon="cloud_upload"></q-btn></div>
|
||||
<div class="col-6 col-sm"><q-btn class="fit" :loading="deploying" color="primary" @click="ApplyGadgetSettings" label="deploy" icon="launch"></q-btn></div>
|
||||
<div class="col-6 col-sm"><q-btn class="fit" color="primary" @click="updateStoredSettingsList(); showDeployStoredModal=true" label="deploy stored" icon="settings_backup_restore"></q-btn></div>
|
||||
<div class="col-6 col-sm"><q-btn class="fit" color="secondary" @click="UpdateFromDeployedGadgetSettings" label="reset" icon="autorenew"></q-btn></div>
|
||||
<div class="col-6 col-sm"><q-btn class="fit" color="secondary" @click="showStoreModal=true" label="store" icon="cloud_upload"></q-btn></div>
|
||||
<div class="col-12 col-sm"><q-btn class="fit" color="warning" @click="updateStoredSettingsList(); showLoadModal=true" label="load stored" icon="cloud_download"></q-btn></div>
|
||||
|
||||
</div>
|
||||
|
@ -8,26 +8,6 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
type jsMasterTemplate struct {
|
||||
*js.Object
|
||||
TemplateNameBluetooth string `js:"TemplateNameBluetooth"`
|
||||
TemplateNameUSB string `js:"TemplateNameUSB"`
|
||||
TemplateNameWiFi string `js:"TemplateNameWiFi"`
|
||||
TemplateNameTriggerActions string `js:"TemplateNameTriggerActions"`
|
||||
TemplateNamesNetwork []string `js:"TemplateNamesNetwork"`
|
||||
}
|
||||
|
||||
func NewMasterTemplate() (res *jsMasterTemplate) {
|
||||
res = &jsMasterTemplate{Object: O()}
|
||||
res.TemplateNameBluetooth = ""
|
||||
res.TemplateNameWiFi = ""
|
||||
res.TemplateNameUSB = ""
|
||||
res.TemplateNameTriggerActions = ""
|
||||
res.TemplateNamesNetwork = []string{}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
func InitComponentsGeneric() {
|
||||
|
||||
hvue.NewComponent(
|
||||
@ -48,7 +28,7 @@ func InitComponentsGeneric() {
|
||||
hvue.DataFunc(func(vm *hvue.VM) interface{} {
|
||||
data := &struct {
|
||||
*js.Object
|
||||
MasterTemplate *jsMasterTemplate `js:"MasterTemplate"`
|
||||
//MasterTemplate *jsMasterTemplate `js:"MasterTemplate"`
|
||||
|
||||
ShowTemplateSelectBluetooth bool `js:"ShowTemplateSelectBluetooth"`
|
||||
ShowTemplateSelectWiFi bool `js:"ShowTemplateSelectWiFi"`
|
||||
@ -56,17 +36,76 @@ func InitComponentsGeneric() {
|
||||
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.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",
|
||||
@ -209,19 +248,19 @@ func InitComponentsGeneric() {
|
||||
const compGeneric = `
|
||||
<q-page padding>
|
||||
<div class="row gutter-sm">
|
||||
<div class="col-12 col-lg">
|
||||
<master-template />
|
||||
<div class="col-12 col-xl">
|
||||
<master-template v-model="$store.state.CurrentMasterTemplate" />
|
||||
</div>
|
||||
|
||||
<div class="col-12 col-lg">
|
||||
<div class="col-12 col-xl">
|
||||
<startup-settings />
|
||||
</div>
|
||||
|
||||
<div class="col-12 col-lg">
|
||||
<div class="col-12 col-xl">
|
||||
<system />
|
||||
</div>
|
||||
|
||||
<div class="col-12 col-lg">
|
||||
<div class="col-12 col-xl">
|
||||
<database />
|
||||
</div>
|
||||
|
||||
@ -249,43 +288,145 @@ const compMasterTemplate = `
|
||||
Master Template
|
||||
</q-card-title>
|
||||
|
||||
{{ $data }}
|
||||
<!-- {{ $data }} -->
|
||||
|
||||
<q-card-main>
|
||||
|
||||
<select-string-from-array :values="$store.state.StoredMasterTemplateList" v-model="showLoadModal" title="Load USB Master Template" @load="load($event)" @delete="deleteStored($event)" with-delete></select-string-from-array>
|
||||
<select-string-from-array :values="$store.state.StoredMasterTemplateList" v-model="showDeployStoredModal" title="Deploy stored Master Template" @load="deployStored($event)" @delete="deleteStored($event)" with-delete></select-string-from-array>
|
||||
<modal-string-input v-model="showStoreModal" title="Store current Master Template" @save="store($event)"></modal-string-input>
|
||||
|
||||
|
||||
<div class="row gutter-sm">
|
||||
|
||||
<q-item tag="label">
|
||||
<select-string-from-array :values="$store.state.StoredUSBSettingsList" v-model="ShowTemplateSelectUSB" title="Select USB template" @load="MasterTemplate.TemplateNameUSB=$event"></select-string-from-array>
|
||||
<div class="col-12">
|
||||
<div class="row gutter-sm">
|
||||
<div class="col-6 col-sm"><q-btn class="fit" color="primary" @click="deploy(MasterTemplate)" label="deploy" icon="launch"></q-btn></div>
|
||||
<div class="col-6 col-sm"><q-btn class="fit" color="primary" @click="showDeployStoredModal=true" label="deploy stored" icon="settings_backup_restore"></q-btn></div>
|
||||
<div class="col-6 col-sm"><q-btn class="fit" color="secondary" @click="showStoreModal=true" label="store" icon="cloud_upload"></q-btn></div>
|
||||
<div class="col-6 col-sm"><q-btn class="fit" color="warning" @click="showLoadModal=true" label="load stored" icon="cloud_download"></q-btn></div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- TriggerActions template -->
|
||||
|
||||
<q-item tag="div" class="col-12">
|
||||
<select-string-from-array :values="$store.state.StoredTriggerActionSetsList" v-model="ShowTemplateSelectTriggerAction" title="Select TriggerActions template" @load="MasterTemplate.TemplateNameTriggerActions=$event"></select-string-from-array>
|
||||
<q-item-side icon="whatshot" color primary />
|
||||
<q-item-main>
|
||||
<q-item-tile label>TriggerActions Template</q-item-tile>
|
||||
<!--
|
||||
<q-item-tile sublabel>If not empty, the selected TriggerActions are deployed along with the master template</q-item-tile>
|
||||
-->
|
||||
<q-item-tile>
|
||||
<div class="row no-wrap">
|
||||
<div class="fit">
|
||||
<q-input v-model="MasterTemplate.TemplateNameTriggerActions" color="primary" inverted readonly clearable></q-input>
|
||||
</div>
|
||||
<div><q-btn icon="more" color="primary" @click="ShowTemplateSelectTriggerAction=true" flat /></div>
|
||||
<div><q-btn v-if="MasterTemplate.TemplateNameTriggerActions.length > 0" icon="clear" color="primary" @click="MasterTemplate.TemplateNameTriggerActions=''" flat /></div>
|
||||
</div>
|
||||
</q-item-tile>
|
||||
</q-item-main>
|
||||
</q-item>
|
||||
|
||||
|
||||
<!-- USB template -->
|
||||
<q-item tag="div" class="col-12">
|
||||
<select-string-from-array :values="$store.state.StoredUSBSettingsList" v-model="ShowTemplateSelectUSB" title="Select USB template" @load="MasterTemplate.TemplateNameUSB=$event"></select-string-from-array>
|
||||
<q-item-side icon="usb" color primary />
|
||||
<q-item-main>
|
||||
<q-item-tile label>USB Template</q-item-tile>
|
||||
<!--
|
||||
<q-item-tile sublabel>If not empty, the selected USB settings are deployed along with the master template</q-item-tile>
|
||||
-->
|
||||
<q-item-tile>
|
||||
<q-input @click="ShowTemplateSelectUSB=true" v-model="MasterTemplate.TemplateNameUSB" color="primary" inverted readonly :after="[{icon: 'more_horiz', handler(){}}]"></q-input>
|
||||
<div class="row no-wrap">
|
||||
<div class="fit">
|
||||
<q-input v-model="MasterTemplate.TemplateNameUSB" color="primary" inverted readonly clearable></q-input>
|
||||
</div>
|
||||
<div><q-btn icon="more" color="primary" @click="ShowTemplateSelectUSB=true" flat /></div>
|
||||
<div><q-btn v-if="MasterTemplate.TemplateNameUSB.length > 0" icon="clear" color="primary" @click="MasterTemplate.TemplateNameUSB=''" flat /></div>
|
||||
</div>
|
||||
|
||||
</q-item-tile>
|
||||
</q-item-main>
|
||||
</q-item>
|
||||
|
||||
<q-item tag="label">
|
||||
<select-network-templates
|
||||
:values="$store.state.StoredEthernetInterfaceSettingsList"
|
||||
:show="ShowTemplateSelectNetwork"
|
||||
@show="ShowTemplateSelectNetwork=$event"
|
||||
title="Select Network templates"
|
||||
v-model="MasterTemplate.TemplateNamesNetwork"
|
||||
/>
|
||||
<!-- WiFi template -->
|
||||
<q-item tag="div" class="col-12">
|
||||
<select-string-from-array :values="$store.state.StoredWifiSettingsList" v-model="ShowTemplateSelectWiFi" title="Select WiFi template" @load="MasterTemplate.TemplateNameWiFi=$event"></select-string-from-array>
|
||||
<q-item-side icon="wifi" color primary />
|
||||
<q-item-main>
|
||||
<q-item-tile label>WiFi Template</q-item-tile>
|
||||
<!--
|
||||
<q-item-tile sublabel>If not empty, the selected WiFi settings are deployed along with the master template</q-item-tile>
|
||||
-->
|
||||
<q-item-tile>
|
||||
<div class="row no-wrap">
|
||||
<div class="fit">
|
||||
<q-input v-model="MasterTemplate.TemplateNameWiFi" color="primary" inverted readonly clearable></q-input>
|
||||
</div>
|
||||
<div><q-btn icon="more" color="primary" @click="ShowTemplateSelectWiFi=true" flat /></div>
|
||||
<div><q-btn v-if="MasterTemplate.TemplateNameWiFi.length > 0" icon="clear" color="primary" @click="MasterTemplate.TemplateNameWiFi=''" flat /></div>
|
||||
</div>
|
||||
</q-item-tile>
|
||||
</q-item-main>
|
||||
</q-item>
|
||||
|
||||
<!-- Bluetooth template -->
|
||||
<q-item tag="div" class="col-12">
|
||||
<select-string-from-array :values="$store.state.StoredBluetoothSettingsList" v-model="ShowTemplateSelectBluetooth" title="Select Bluetooth template" @load="MasterTemplate.TemplateNameBluetooth=$event"></select-string-from-array>
|
||||
<q-item-side icon="bluetooth" color primary />
|
||||
<q-item-main>
|
||||
<q-item-tile label>Bluetooth Template</q-item-tile>
|
||||
<!--
|
||||
<q-item-tile sublabel>If not empty, the selected Bluetooth settings are deployed along with the master template</q-item-tile>
|
||||
-->
|
||||
<q-item-tile>
|
||||
<div class="row no-wrap">
|
||||
<div class="fit">
|
||||
<q-input v-model="MasterTemplate.TemplateNameBluetooth" color="primary" inverted readonly clearable></q-input>
|
||||
</div>
|
||||
<div><q-btn icon="more" color="primary" @click="ShowTemplateSelectBluetooth=true" flat /></div>
|
||||
<div><q-btn v-if="MasterTemplate.TemplateNameBluetooth.length > 0" icon="clear" color="primary" @click="MasterTemplate.TemplateNameBluetooth=''" flat /></div>
|
||||
</div>
|
||||
</q-item-tile>
|
||||
</q-item-main>
|
||||
</q-item>
|
||||
|
||||
<q-item tag="div" class="col-12">
|
||||
<select-network-templates
|
||||
:values="$store.state.StoredEthernetInterfaceSettingsList"
|
||||
:show="ShowTemplateSelectNetwork"
|
||||
@show="ShowTemplateSelectNetwork=$event"
|
||||
title="Select Network templates"
|
||||
v-model="MasterTemplate.TemplateNamesNetwork"
|
||||
/>
|
||||
<q-item-side icon="settings_ethernet" color primary />
|
||||
<q-item-main>
|
||||
<q-item-tile label>Networks templates</q-item-tile>
|
||||
<q-item-tile sublabel>Only one template could be selected per interface.</q-item-tile>
|
||||
<!--
|
||||
<q-item-tile sublabel>If not empty, the selected network templates are deployed along with the master template. Only one template could be selected per interface.</q-item-tile>
|
||||
-->
|
||||
<q-item-tile>
|
||||
<q-chips-input v-model="MasterTemplate.TemplateNamesNetwork" color="primary" inverted :after="[{icon: 'add', handler(){ShowTemplateSelectNetwork=true}}]" />
|
||||
<div class="row no-wrap">
|
||||
<div class="fit">
|
||||
<!--
|
||||
<q-chips-input v-model="MasterTemplate.TemplateNamesNetwork" color="primary" inverted clearable />
|
||||
-->
|
||||
<q-chips-input v-model="MasterTemplate.TemplateNamesNetwork" color="primary" inverted readonly />
|
||||
</div>
|
||||
<div><q-btn icon="more" color="primary" @click="ShowTemplateSelectNetwork=true" flat /></div>
|
||||
<div><q-btn v-if="MasterTemplate.TemplateNamesNetwork.length > 0" icon="clear" color="primary" @click="MasterTemplate.TemplateNamesNetwork=[]" flat /></div>
|
||||
</div>
|
||||
|
||||
</q-item-tile>
|
||||
</q-item-main>
|
||||
</q-item>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
</q-card-main>
|
||||
</q-card>
|
||||
|
@ -501,9 +501,9 @@ func InitComponentsTriggerActions() {
|
||||
aData := &jsActionDeploySettingsTemplate{Object: ta.ActionData}
|
||||
switch aData.Type {
|
||||
case TemplateTypeFullSettings:
|
||||
//ToDo: Implement
|
||||
return vm.Store.Get("state").Get("StoredMasterTemplateList")
|
||||
case TemplateTypeBluetooth:
|
||||
//ToDo: Implement
|
||||
return vm.Store.Get("state").Get("StoredBluetoothSettingsList")
|
||||
case TemplateTypeUSB:
|
||||
//return USB list
|
||||
return vm.Store.Get("state").Get("StoredUSBSettingsList")
|
||||
|
@ -14,6 +14,71 @@ import (
|
||||
var eNoLogEvent = errors.New("No log event")
|
||||
var eNoHidEvent = errors.New("No HID event")
|
||||
|
||||
|
||||
type jsMasterTemplate struct {
|
||||
*js.Object
|
||||
TemplateNameBluetooth string `js:"TemplateNameBluetooth"`
|
||||
TemplateNameUSB string `js:"TemplateNameUSB"`
|
||||
TemplateNameWiFi string `js:"TemplateNameWiFi"`
|
||||
TemplateNameTriggerActions string `js:"TemplateNameTriggerActions"`
|
||||
TemplateNamesNetwork []string `js:"TemplateNamesNetwork"`
|
||||
}
|
||||
|
||||
func (target *jsMasterTemplate) fromGo(src *pb.MasterTemplate) {
|
||||
target.TemplateNamesNetwork = src.TemplateNamesNetwork
|
||||
target.TemplateNameBluetooth = src.TemplateNameBluetooth
|
||||
target.TemplateNameWiFi = src.TemplateNameWifi
|
||||
target.TemplateNameUSB = src.TemplateNameUsb
|
||||
target.TemplateNameTriggerActions = src.TemplateNameTriggerActions
|
||||
}
|
||||
|
||||
func (src *jsMasterTemplate) toGo() (target *pb.MasterTemplate) {
|
||||
target = &pb.MasterTemplate{}
|
||||
target.TemplateNamesNetwork = src.TemplateNamesNetwork
|
||||
target.TemplateNameBluetooth = src.TemplateNameBluetooth
|
||||
target.TemplateNameWifi = src.TemplateNameWiFi
|
||||
target.TemplateNameUsb = src.TemplateNameUSB
|
||||
target.TemplateNameTriggerActions = src.TemplateNameTriggerActions
|
||||
return target
|
||||
}
|
||||
|
||||
func NewMasterTemplate() (res *jsMasterTemplate) {
|
||||
res = &jsMasterTemplate{Object: O()}
|
||||
res.TemplateNameBluetooth = ""
|
||||
res.TemplateNameWiFi = ""
|
||||
res.TemplateNameUSB = ""
|
||||
res.TemplateNameTriggerActions = ""
|
||||
res.TemplateNamesNetwork = []string{}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
type jsRequestMasterTemplateStorage struct {
|
||||
*js.Object
|
||||
TemplateName string `js:"TemplateName"`
|
||||
Template *jsMasterTemplate `js:"Template"`
|
||||
}
|
||||
|
||||
func (rs *jsRequestMasterTemplateStorage) toGo() *pb.RequestMasterTemplateStorage {
|
||||
return &pb.RequestMasterTemplateStorage{
|
||||
TemplateName: rs.TemplateName,
|
||||
Template: rs.Template.toGo(),
|
||||
}
|
||||
}
|
||||
|
||||
func (rs *jsRequestMasterTemplateStorage) fromGo(src *pb.RequestMasterTemplateStorage) {
|
||||
rs.TemplateName = src.TemplateName
|
||||
rs.Template = NewMasterTemplate()
|
||||
rs.Template.fromGo(src.Template)
|
||||
}
|
||||
|
||||
func NewRequestMasterTemplateStorage() (res *jsRequestMasterTemplateStorage) {
|
||||
res = &jsRequestMasterTemplateStorage{Object:O()}
|
||||
res.Template = NewMasterTemplate()
|
||||
res.TemplateName = ""
|
||||
return res
|
||||
}
|
||||
|
||||
type jsLoadHidScriptSourceMode int
|
||||
const (
|
||||
HID_SCRIPT_SOURCE_LOAD_MODE_PREPEND jsLoadHidScriptSourceMode = iota
|
||||
|
@ -111,6 +111,19 @@ const (
|
||||
|
||||
VUEX_MUTATION_SET_STORED_TRIGGER_ACTIONS_SETS_LIST = "setStoredTriggerActionSetsList"
|
||||
|
||||
//Master templates
|
||||
VUEX_ACTION_DEPLOY_MASTER_TEMPLATE = "deployMasterTemplate"
|
||||
VUEX_ACTION_UPDATE_STORED_MASTER_TEMPLATE_LIST = "updateStoredMasterTemplateList"
|
||||
VUEX_ACTION_STORE_MASTER_TEMPLATE = "storeMasterTemplate"
|
||||
VUEX_ACTION_LOAD_MASTER_TEMPLATE = "loadMasterTemplate"
|
||||
VUEX_ACTION_DEPLOY_STORED_MASTER_TEMPLATE = "deployStoredMasterTemplate"
|
||||
VUEX_ACTION_DELETE_STORED_MASTER_TEMPLATE = "deleteStoredMasterTemplate"
|
||||
|
||||
VUEX_MUTATION_SET_CURRENT_MASTER_TEMPLATE = "setCurrentMasterTemplate"
|
||||
VUEX_MUTATION_SET_STORED_MASTER_TEMPLATE_LIST = "setStoredMasterTemplateList"
|
||||
|
||||
|
||||
|
||||
//Bash scripts (used by TriggerActions)
|
||||
VUEX_ACTION_UPDATE_STORED_BASH_SCRIPTS_LIST = "updateStoredBashScriptsList"
|
||||
|
||||
@ -138,6 +151,7 @@ type GlobalState struct {
|
||||
WiFiState *jsWiFiState `js:"wifiState"`
|
||||
CurrentBluetoothControllerInformation *jsBluetoothControllerInformation `js:"CurrentBluetoothControllerInformation"`
|
||||
CurrentBluetoothAgentSettings *jsBluetoothAgentSettings `js:"CurrentBluetoothAgentSettings"`
|
||||
CurrentMasterTemplate *jsMasterTemplate `js:"CurrentMasterTemplate"`
|
||||
|
||||
StoredWifiSettingsList []string `js:"StoredWifiSettingsList"`
|
||||
StoredEthernetInterfaceSettingsList []string `js:"StoredEthernetInterfaceSettingsList"`
|
||||
@ -146,6 +160,7 @@ type GlobalState struct {
|
||||
StoredHIDScriptsList []string `js:"StoredHIDScriptsList"`
|
||||
StoredUSBSettingsList []string `js:"StoredUSBSettingsList"`
|
||||
StoredBluetoothSettingsList []string `js:"StoredBluetoothSettingsList"`
|
||||
StoredMasterTemplateList []string `js:"StoredMasterTemplateList"`
|
||||
|
||||
ConnectRetryCount int `js:"ConnectRetryCount"`
|
||||
EventListenerRunning bool `js:"EventListenerRunning"`
|
||||
@ -166,6 +181,7 @@ func createGlobalStateStruct() GlobalState {
|
||||
state.IsConnected = false
|
||||
state.IsModalEnabled = false
|
||||
state.FailedConnectionAttempts = 0
|
||||
state.CurrentMasterTemplate = NewMasterTemplate()
|
||||
|
||||
state.StoredWifiSettingsList = []string{}
|
||||
state.StoredEthernetInterfaceSettingsList = []string{}
|
||||
@ -174,6 +190,7 @@ func createGlobalStateStruct() GlobalState {
|
||||
state.StoredHIDScriptsList = []string{}
|
||||
state.StoredUSBSettingsList = []string{}
|
||||
state.StoredBluetoothSettingsList = []string{}
|
||||
state.StoredMasterTemplateList = []string{}
|
||||
|
||||
//Retrieve Interface settings
|
||||
state.InterfaceSettings = NewEthernetSettingsList()
|
||||
@ -230,6 +247,8 @@ func processEvent(evt *pb.Event, store *mvuex.Store, state *GlobalState) {
|
||||
store.Dispatch(VUEX_ACTION_UPDATE_STORED_BLUETOOTH_SETTINGS_LIST)
|
||||
case common_web.STATE_CHANGE_EVT_TYPE_STORED_TRIGGER_ACTION_SETS_LIST:
|
||||
store.Dispatch(VUEX_ACTION_UPDATE_STORED_TRIGGER_ACTION_SETS_LIST)
|
||||
case common_web.STATE_CHANGE_EVT_TYPE_STORED_GLOBAL_SETTINGS_LIST:
|
||||
store.Dispatch(VUEX_ACTION_UPDATE_STORED_MASTER_TEMPLATE_LIST)
|
||||
}
|
||||
default:
|
||||
// events which aren't of type "notify state change" are processed by the EventProcessor
|
||||
@ -258,6 +277,95 @@ func actionUpdateAllStates(store *mvuex.Store, context *mvuex.ActionContext, sta
|
||||
|
||||
}
|
||||
|
||||
func actionDeployMasterTemplate(store *mvuex.Store, context *mvuex.ActionContext, state *GlobalState, mt *jsMasterTemplate) {
|
||||
go func() {
|
||||
println("Vuex dispatch " + VUEX_ACTION_DEPLOY_MASTER_TEMPLATE)
|
||||
// convert to Go type
|
||||
err := RpcClient.DeployMasterTemplate(defaultTimeoutMid, mt.toGo())
|
||||
if err != nil {
|
||||
QuasarNotifyError("Error deploying stored master template", err.Error(), QUASAR_NOTIFICATION_POSITION_BOTTOM)
|
||||
}
|
||||
QuasarNotifySuccess("Master template deployed", "", QUASAR_NOTIFICATION_POSITION_TOP)
|
||||
}()
|
||||
}
|
||||
|
||||
func actionUpdateStoredMasterTemplateList(store *mvuex.Store, context *mvuex.ActionContext, state *GlobalState) {
|
||||
go func() {
|
||||
println("Trying to fetch master template list")
|
||||
//fetch deployed gadget settings
|
||||
mtList, err := RpcClient.GetStoredMasterTemplateList(defaultTimeout)
|
||||
if err != nil {
|
||||
println("Couldn't retrieve MasterTemplate list")
|
||||
return
|
||||
}
|
||||
|
||||
//commit to current
|
||||
|
||||
context.Commit(VUEX_MUTATION_SET_STORED_MASTER_TEMPLATE_LIST, mtList)
|
||||
}()
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func actionStoreMasterTemplate(store *mvuex.Store, context *mvuex.ActionContext, state *GlobalState, req *jsRequestMasterTemplateStorage) {
|
||||
go func() {
|
||||
println("Vuex dispatch store MasterTemplate: ", req.TemplateName)
|
||||
// convert to Go type
|
||||
err := RpcClient.StoreMasterTemplate(defaultTimeout, req.toGo())
|
||||
if err != nil {
|
||||
QuasarNotifyError("Error storing MasterTemplate", err.Error(), QUASAR_NOTIFICATION_POSITION_BOTTOM)
|
||||
}
|
||||
QuasarNotifySuccess("New MasterTemplate stored", "", QUASAR_NOTIFICATION_POSITION_TOP)
|
||||
}()
|
||||
}
|
||||
|
||||
func actionLoadMasterTemplate(store *mvuex.Store, context *mvuex.ActionContext, state *GlobalState, settingsName *js.Object) {
|
||||
go func() {
|
||||
println("Vuex dispatch load MasterTemplate: ", settingsName.String())
|
||||
// convert to Go type
|
||||
template, err := RpcClient.GetStoredMasterTemplate(defaultTimeout, &pb.StringMessage{Msg: settingsName.String()})
|
||||
if err != nil {
|
||||
QuasarNotifyError("Error fetching stored MasterTemplate", err.Error(), QUASAR_NOTIFICATION_POSITION_BOTTOM)
|
||||
}
|
||||
|
||||
jsMT := NewMasterTemplate()
|
||||
jsMT.fromGo(template)
|
||||
context.Commit(VUEX_MUTATION_SET_CURRENT_MASTER_TEMPLATE, jsMT)
|
||||
|
||||
QuasarNotifySuccess("New MasterTemplate loaded", "", QUASAR_NOTIFICATION_POSITION_TOP)
|
||||
}()
|
||||
}
|
||||
|
||||
func actionDeployStoredMasterTemplate(store *mvuex.Store, context *mvuex.ActionContext, state *GlobalState, templateName *js.Object) {
|
||||
go func() {
|
||||
println("Vuex dispatch load MasterTemplate: ", templateName.String())
|
||||
// convert to Go type
|
||||
goMT, err := RpcClient.DeployStoredMasterTemplate(defaultTimeoutMid, &pb.StringMessage{Msg: templateName.String()})
|
||||
if err != nil {
|
||||
QuasarNotifyError("Error deploying stored MasterTemplate", err.Error(), QUASAR_NOTIFICATION_POSITION_BOTTOM)
|
||||
}
|
||||
QuasarNotifySuccess("New MasterTemplate deployed", "", QUASAR_NOTIFICATION_POSITION_TOP)
|
||||
jsMT := NewMasterTemplate()
|
||||
jsMT.fromGo(goMT)
|
||||
context.Commit(VUEX_MUTATION_SET_CURRENT_MASTER_TEMPLATE, jsMT)
|
||||
}()
|
||||
}
|
||||
|
||||
func actionDeleteStoredMasterTemplate(store *mvuex.Store, context *mvuex.ActionContext, state *GlobalState, templateName *js.Object) {
|
||||
go func() {
|
||||
println("Vuex dispatch delete MasterTemplate: ", templateName.String())
|
||||
// convert to Go type
|
||||
err := RpcClient.DeleteStoredMasterTemplate(defaultTimeout, &pb.StringMessage{Msg: templateName.String()})
|
||||
if err != nil {
|
||||
QuasarNotifyError("Error deleting stored MasterTemplate", err.Error(), QUASAR_NOTIFICATION_POSITION_BOTTOM)
|
||||
}
|
||||
QuasarNotifySuccess("MasterTemplate deleted", "", QUASAR_NOTIFICATION_POSITION_TOP)
|
||||
actionUpdateStoredMasterTemplateList(store, context, state)
|
||||
}()
|
||||
}
|
||||
|
||||
|
||||
|
||||
func actionSendAndRunHIDScript(store *mvuex.Store, context *mvuex.ActionContext, state *GlobalState, scriptContent *js.Object) {
|
||||
go func() {
|
||||
strScriptContent := scriptContent.String()
|
||||
@ -1250,6 +1358,20 @@ func initMVuex() *mvuex.Store {
|
||||
state.HidJobList.DeleteEntry(int64(id))
|
||||
|
||||
}),
|
||||
mvuex.Mutation(VUEX_MUTATION_SET_CURRENT_MASTER_TEMPLATE, func(store *mvuex.Store, state *GlobalState, newMasterTemplate *jsMasterTemplate) {
|
||||
hvue.Set(state,"CurrentMasterTemplate", newMasterTemplate)
|
||||
}),
|
||||
mvuex.Mutation(VUEX_MUTATION_SET_STORED_MASTER_TEMPLATE_LIST, func(store *mvuex.Store, state *GlobalState, mtList []interface{}) {
|
||||
hvue.Set(state, "StoredMasterTemplateList", mtList)
|
||||
}),
|
||||
|
||||
|
||||
mvuex.Action(VUEX_ACTION_DEPLOY_MASTER_TEMPLATE, actionDeployMasterTemplate),
|
||||
mvuex.Action(VUEX_ACTION_UPDATE_STORED_MASTER_TEMPLATE_LIST, actionUpdateStoredMasterTemplateList),
|
||||
mvuex.Action(VUEX_ACTION_STORE_MASTER_TEMPLATE, actionStoreMasterTemplate),
|
||||
mvuex.Action(VUEX_ACTION_LOAD_MASTER_TEMPLATE, actionLoadMasterTemplate),
|
||||
mvuex.Action(VUEX_ACTION_DEPLOY_STORED_MASTER_TEMPLATE, actionDeployStoredMasterTemplate),
|
||||
mvuex.Action(VUEX_ACTION_DELETE_STORED_MASTER_TEMPLATE, actionDeleteStoredMasterTemplate),
|
||||
|
||||
|
||||
mvuex.Action(VUEX_ACTION_UPDATE_ALL_STATES, actionUpdateAllStates),
|
||||
|
@ -29,6 +29,56 @@ func NewRpcClient(addr string) Rpc {
|
||||
return rcl
|
||||
}
|
||||
|
||||
func (rpc *Rpc) DeployMasterTemplate(timeout time.Duration, mt *pb.MasterTemplate) (err error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||
defer cancel()
|
||||
_,err = rpc.Client.DeployMasterTemplate(ctx,mt)
|
||||
return
|
||||
}
|
||||
|
||||
func (rpc *Rpc) GetStoredMasterTemplateList(timeout time.Duration) (ws []string, err error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||
defer cancel()
|
||||
|
||||
ma, err := rpc.Client.ListStoredMasterTemplate(ctx, &pb.Empty{})
|
||||
if err != nil { return ws, err }
|
||||
return ma.MsgArray, err
|
||||
}
|
||||
|
||||
func (rpc *Rpc) StoreMasterTemplate(timeout time.Duration, req *pb.RequestMasterTemplateStorage) (err error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||
defer cancel()
|
||||
|
||||
_, err = rpc.Client.StoreMasterTemplate(ctx, req)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (rpc *Rpc) GetStoredMasterTemplate(timeout time.Duration, req *pb.StringMessage) (template *pb.MasterTemplate, err error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||
defer cancel()
|
||||
|
||||
template, err = rpc.Client.GetStoredMasterTemplate(ctx, req)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (rpc *Rpc) DeployStoredMasterTemplate(timeout time.Duration, req *pb.StringMessage) (state *pb.MasterTemplate, err error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||
defer cancel()
|
||||
|
||||
state, err = rpc.Client.DeployStoredMasterTemplate(ctx, req)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (rpc *Rpc) DeleteStoredMasterTemplate(timeout time.Duration, req *pb.StringMessage) (err error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||
defer cancel()
|
||||
_, err = rpc.Client.DeleteStoredMasterTemplate(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
func (rpc *Rpc) UploadContentToTempFile(timeout time.Duration, content []byte) (filename string, err error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||
defer cancel()
|
||||
|
Loading…
x
Reference in New Issue
Block a user