Skip to content

Commit

Permalink
users can now load and start a room with simple flags
Browse files Browse the repository at this point in the history
  • Loading branch information
ewilliams0305 committed Dec 20, 2023
1 parent 3c4675b commit 82d31b8
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 15 deletions.
8 changes: 5 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
"-f", "C:\\Users\\ewilliams\\OneDrive - cenero.com\\Documents\\Projects\\Wharton\\Gacialis\\Programs\\Wharton_Glacialis_QsysCR_v3.0.0.lpz",
"-n", "Wharton Template"
],

},
{

"name": "Create Room",
"name": "Create And Run Room",
"type": "go",
"request": "launch",
"mode": "auto",
Expand All @@ -45,7 +45,9 @@
"args": [
"-h", "10.0.0.111",
"-t","eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6Ijk0NDliMDM0LTcyNWEtNDM0Ny04YTMzLTc5Zjg2MDNlYjUyYiIsImx2IjoiRGVmYXVsdCBMZXZlbCIsInZlciI6IjEuMCIsImV4cGkiOiIwIn0.oMs434gmWR-x4sTGKonmndOA5F62FdzrwYZQYSGNd2A",
"-r", "MYROOM"
"-f", "C:\\Users\\ewilliams\\OneDrive - cenero.com\\Documents\\Projects\\Wharton\\Gacialis\\Programs\\Wharton_Glacialis_QsysCR_v3.0.0.lpz",
"-r", "MYROOM",
"-n", "Glacialis"
],

}
Expand Down
40 changes: 30 additions & 10 deletions pkg/tui/actions_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,30 @@ func (m ActionsModel) Init() tea.Cmd {
Name: ProgramName,
}
cmd = CreateProgramAction(ops)
return tea.Batch(cmd, actionsTickCmd())
}

if m.action == createRoom {
ops := &vc.RoomOptions{
Name: RoomID,
ProgramInstanceId: RoomID,
ProgramLibraryId: 186,
if m.action == loadAndCreate {

//t := time.Now()
//zone, offset := t.Zone()

///fmt.Print(offset)

pops := &vc.ProgramOptions{
AppFile: ProgramFile,
Name: ProgramName,
}
rops := &vc.RoomOptions{
Name: RoomID,
ProgramInstanceId: RoomID,
AddressSetsLocation: true,
//TimeZone: zone,
}
cmd = CreateRoomAction(ops)
cmd = CreateAndRunRoomAction(pops, rops)
return tea.Batch(cmd, actionsTickCmd())
}

// if m.action == loadAndCreate {
// state = rooms
// }

return tea.Batch(cmd, actionsTickCmd())
}

Expand Down Expand Up @@ -175,9 +184,20 @@ func CreateProgramAction(options *vc.ProgramOptions) tea.Cmd {
}
}

func CreateAndRunRoomAction(progOps *vc.ProgramOptions, roomOps *vc.RoomOptions) tea.Cmd {

return func() tea.Msg {
return CreateAndRunProgram(progOps, roomOps)
}
}

func CreateRoomAction(options *vc.RoomOptions) tea.Cmd {

return func() tea.Msg {
return CreateRoom(*options)
}
}

func CreateErrorAction() tea.Msg {
return fmt.Errorf("FAILED TO PROCESS THE APPLICATION FLAGS, VALID COMBINATIONS REQUIRE -F && -N || -F && -N && -R ")
}
9 changes: 9 additions & 0 deletions pkg/tui/programs.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,15 @@ func CreateNewProgram(options vc.ProgramOptions) tea.Msg {
return result
}

func CreateAndRunProgram(progOps *vc.ProgramOptions, roomOps *vc.RoomOptions) tea.Msg {

result, err := server.CreateAndRunProgram(progOps, roomOps)
if err != nil {
return err
}
return result
}

func EditProgram(options vc.ProgramOptions) tea.Msg {

result, err := server.EditProgram(options)
Expand Down
5 changes: 3 additions & 2 deletions pkg/tui/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,10 @@ func initServer() vc.VirtualControl {

func initActions() (tea.Model, error) {

if len(RoomID) > 0 && len(ProgramFile) == 0 {
return InitialActionModel(fmt.Sprintf("Creating new room %s", RoomID), createRoom), nil
if len(RoomID) > 0 && len(ProgramFile) > 0 && len(ProgramName) > 0 {
return InitialActionModel(fmt.Sprintf("Uploading and creating new room %s", RoomID), loadAndCreate), nil
}

if len(ProgramFile) > 0 && len(ProgramName) > 0 {
return InitialActionModel(fmt.Sprintf("Loading new program %s", ProgramFile), loadProgram), nil
}
Expand Down
11 changes: 11 additions & 0 deletions pkg/vc/programs.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ type VcProgramApi interface {
CreateProgram(options ProgramOptions) (result ProgramUploadResult, err VirtualControlError)
EditProgram(options ProgramOptions) (result ProgramUploadResult, err VirtualControlError)
DeleteProgram(id int) (result ProgramDeleteResult, err VirtualControlError)

CreateAndRunProgram(progOps *ProgramOptions, roomOps *RoomOptions) (result RoomCreatedResult, err VirtualControlError)
}

func (v *VC) GetPrograms() (Programs, VirtualControlError) {
Expand All @@ -50,6 +52,15 @@ func (v *VC) CreateProgram(options ProgramOptions) (result ProgramUploadResult,
return postProgram(v, options)
}

func (v *VC) CreateAndRunProgram(progOps *ProgramOptions, roomOps *RoomOptions) (result RoomCreatedResult, err VirtualControlError) {
pResult, err := v.CreateProgram(*progOps)
if err != nil {
return RoomCreatedResult{}, err
}
roomOps.ProgramLibraryId = int(pResult.ProgramID)
return v.CreateRoom(*roomOps)
}

func (v *VC) EditProgram(options ProgramOptions) (result ProgramUploadResult, err VirtualControlError) {
return editProgram(v, options)
}
Expand Down

0 comments on commit 82d31b8

Please sign in to comment.