fix: make the shelf menus actually work
This commit is contained in:
@@ -43,6 +43,7 @@ func NewApp(name, version, host string, logger *zap.Logger) *App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
app.assets = assets.NewAssets(logger, app.APIClient)
|
app.assets = assets.NewAssets(logger, app.APIClient)
|
||||||
|
app.shelves = shelves.NewShelves(logger, app.APIClient)
|
||||||
|
|
||||||
app.help = help.NewHelp(name, version)
|
app.help = help.NewHelp(name, version)
|
||||||
|
|
||||||
|
|||||||
@@ -21,9 +21,11 @@ func (app *App) switchToPreviousScreen() {
|
|||||||
var previousScreen string
|
var previousScreen string
|
||||||
switch app.currentPage {
|
switch app.currentPage {
|
||||||
case app.help.GetTitle():
|
case app.help.GetTitle():
|
||||||
previousScreen = app.assets.GetTitle()
|
previousScreen = app.shelves.GetTitle()
|
||||||
case app.assets.GetTitle():
|
case app.assets.GetTitle():
|
||||||
previousScreen = app.help.GetTitle()
|
previousScreen = app.help.GetTitle()
|
||||||
|
case app.shelves.GetTitle():
|
||||||
|
previousScreen = app.assets.GetTitle()
|
||||||
}
|
}
|
||||||
app.switchToScreen(previousScreen)
|
app.switchToScreen(previousScreen)
|
||||||
}
|
}
|
||||||
@@ -34,6 +36,8 @@ func (app *App) switchToNextScreen() {
|
|||||||
case app.help.GetTitle():
|
case app.help.GetTitle():
|
||||||
nextScreen = app.assets.GetTitle()
|
nextScreen = app.assets.GetTitle()
|
||||||
case app.assets.GetTitle():
|
case app.assets.GetTitle():
|
||||||
|
nextScreen = app.shelves.GetTitle()
|
||||||
|
case app.shelves.GetTitle():
|
||||||
nextScreen = app.help.GetTitle()
|
nextScreen = app.help.GetTitle()
|
||||||
}
|
}
|
||||||
app.switchToScreen(nextScreen)
|
app.switchToScreen(nextScreen)
|
||||||
@@ -45,6 +49,8 @@ func (app *App) setPageFocus(page string) {
|
|||||||
app.Application.SetFocus(app.help)
|
app.Application.SetFocus(app.help)
|
||||||
case app.assets.GetTitle():
|
case app.assets.GetTitle():
|
||||||
app.Application.SetFocus(app.assets)
|
app.Application.SetFocus(app.assets)
|
||||||
|
case app.shelves.GetTitle():
|
||||||
|
app.Application.SetFocus(app.shelves)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,5 +58,7 @@ func (app *App) updatePageData(page string) {
|
|||||||
switch page {
|
switch page {
|
||||||
case app.assets.GetTitle():
|
case app.assets.GetTitle():
|
||||||
app.assets.UpdateData()
|
app.assets.UpdateData()
|
||||||
|
case app.shelves.GetTitle():
|
||||||
|
app.shelves.UpdateData()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ type ShelfLocation struct {
|
|||||||
RoomNumber string `json:"room_number,omitempty"`
|
RoomNumber string `json:"room_number,omitempty"`
|
||||||
Description string `json:"description,omitempty"`
|
Description string `json:"description,omitempty"`
|
||||||
BuildingID *uint64 `json:"building_id"`
|
BuildingID *uint64 `json:"building_id"`
|
||||||
Building *Building `json:"-"`
|
Building *Building `json:"building"`
|
||||||
CreatedAt time.Time `json:"created_at"`
|
CreatedAt time.Time `json:"created_at"`
|
||||||
UpdatedAt time.Time `json:"updated_at"`
|
UpdatedAt time.Time `json:"updated_at"`
|
||||||
DeletedAt *time.Time `json:"deleted_at,omitempty"`
|
DeletedAt *time.Time `json:"deleted_at,omitempty"`
|
||||||
@@ -29,5 +29,5 @@ type CreateShelfRequest struct {
|
|||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
RoomNumber string `json:"room_number,omitempty"`
|
RoomNumber string `json:"room_number,omitempty"`
|
||||||
Description string `json:"description,omitempty"`
|
Description string `json:"description,omitempty"`
|
||||||
BuildingID *uint64 `json:"building_id"`
|
BuildingID *uint64 `json:"building_id,omitempty"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,13 +50,13 @@ func (a *Shelves) cdelete() {
|
|||||||
func (a *Shelves) cedit() {
|
func (a *Shelves) cedit() {
|
||||||
selectedItem := a.getSelectedItem()
|
selectedItem := a.getSelectedItem()
|
||||||
if selectedItem == nil {
|
if selectedItem == nil {
|
||||||
a.displayError("DELETE SHELF ERROR", fmt.Errorf("no shelves to edit"))
|
a.displayError("SHELF EDIT ERROR", fmt.Errorf("no shelves to edit"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
shelf, err := a.client.RetrieveShelfByID(selectedItem.id)
|
shelf, err := a.client.RetrieveShelfByID(selectedItem.id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.displayError("DELETE SHELF ERROR", fmt.Errorf("unable to retrieve shelf from server"))
|
a.displayError("SHELF EDIT ERROR", fmt.Errorf("unable to retrieve shelf from server"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,6 +72,11 @@ func (a *Shelves) edit() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if createReq.BuildingID == nil {
|
||||||
|
a.displayError("SHELF EDIT ERROR", fmt.Errorf("shelf building cannot be empty"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
_, err := a.client.UpdateShelf(selectedItem.id, createReq)
|
_, err := a.client.UpdateShelf(selectedItem.id, createReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.displayError("SHELF EDIT ERROR", err)
|
a.displayError("SHELF EDIT ERROR", err)
|
||||||
@@ -111,12 +116,12 @@ func (a *Shelves) delete() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *Shelves) crefresh() {
|
func (a *Shelves) crefresh() {
|
||||||
a.progressDialog.SetTitle("refreshing shelfs")
|
a.progressDialog.SetTitle("refreshing shelves")
|
||||||
a.progressDialog.Display()
|
a.progressDialog.Display()
|
||||||
|
|
||||||
ref := func() {
|
ref := func() {
|
||||||
a.UpdateShelfData()
|
a.UpdateShelfData()
|
||||||
a.UpdateShelfData()
|
a.UpdateBuildingData()
|
||||||
|
|
||||||
a.progressDialog.Hide()
|
a.progressDialog.Hide()
|
||||||
|
|
||||||
@@ -137,6 +142,11 @@ func (a *Shelves) create() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if createReq.BuildingID == nil {
|
||||||
|
a.displayError("SHELF CREATE ERROR", fmt.Errorf("shelf building cannot be empty"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
_, err := a.client.CreateShelf(createReq)
|
_, err := a.client.CreateShelf(createReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.displayError("SHELF CREATE ERROR", err)
|
a.displayError("SHELF CREATE ERROR", err)
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ func (a *Shelves) refresh() {
|
|||||||
SetExpansion(a.shelfTableExpansions[2]).
|
SetExpansion(a.shelfTableExpansions[2]).
|
||||||
SetAlign(tview.AlignLeft))
|
SetAlign(tview.AlignLeft))
|
||||||
|
|
||||||
a.shelfTable.SetCell(row, 2,
|
a.shelfTable.SetCell(row, 3,
|
||||||
tview.NewTableCell(shelf.RoomNumber).
|
tview.NewTableCell(shelf.RoomNumber).
|
||||||
SetExpansion(a.shelfTableExpansions[3]).
|
SetExpansion(a.shelfTableExpansions[3]).
|
||||||
SetAlign(tview.AlignLeft))
|
SetAlign(tview.AlignLeft))
|
||||||
|
|||||||
@@ -136,6 +136,20 @@ func NewShelves(logger *zap.Logger, client *api.APIClient) *Shelves {
|
|||||||
shelves.edit()
|
shelves.edit()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
shelves.SetShelfListFunc(func() ([]types.ShelfLocation, error) {
|
||||||
|
if shlvr, err := shelves.client.RetrieveAllShelves(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else {
|
||||||
|
var shlvo []types.ShelfLocation
|
||||||
|
|
||||||
|
for _, shelf := range shlvr {
|
||||||
|
shlvo = append(shlvo, *shelf)
|
||||||
|
}
|
||||||
|
|
||||||
|
return shlvo, nil
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
shelves.SetBuildingListFunc(func() (map[uint64]types.Building, error) {
|
shelves.SetBuildingListFunc(func() (map[uint64]types.Building, error) {
|
||||||
if resp, err := shelves.client.RetrieveAllBuildings(); err != nil {
|
if resp, err := shelves.client.RetrieveAllBuildings(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -47,7 +47,8 @@ type ShelfEditDialog struct {
|
|||||||
logger *zap.Logger
|
logger *zap.Logger
|
||||||
client *api.APIClient
|
client *api.APIClient
|
||||||
shelf *types.ShelfLocation
|
shelf *types.ShelfLocation
|
||||||
buildingList []*types.Building
|
|
||||||
|
buildingList []*types.Building
|
||||||
|
|
||||||
shelfNameField *tview.InputField
|
shelfNameField *tview.InputField
|
||||||
shelfRoomField *tview.InputField
|
shelfRoomField *tview.InputField
|
||||||
|
|||||||
Reference in New Issue
Block a user