Browse Source

fix: make the shelf menus actually work

master
Brett Bender 2 years ago
parent
commit
4e301c29fc
7 changed files with 43 additions and 9 deletions
  1. +1
    -0
      internal/app/app.go
  2. +9
    -1
      internal/app/screens.go
  3. +2
    -2
      internal/types/shelves.go
  4. +14
    -4
      internal/ui/shelves/command.go
  5. +1
    -1
      internal/ui/shelves/refresh.go
  6. +14
    -0
      internal/ui/shelves/shelves.go
  7. +2
    -1
      internal/ui/shelves/shlvdialogs/edit.go

+ 1
- 0
internal/app/app.go View File

@ -43,6 +43,7 @@ func NewApp(name, version, host string, logger *zap.Logger) *App {
}
app.assets = assets.NewAssets(logger, app.APIClient)
app.shelves = shelves.NewShelves(logger, app.APIClient)
app.help = help.NewHelp(name, version)


+ 9
- 1
internal/app/screens.go View File

@ -21,9 +21,11 @@ func (app *App) switchToPreviousScreen() {
var previousScreen string
switch app.currentPage {
case app.help.GetTitle():
previousScreen = app.assets.GetTitle()
previousScreen = app.shelves.GetTitle()
case app.assets.GetTitle():
previousScreen = app.help.GetTitle()
case app.shelves.GetTitle():
previousScreen = app.assets.GetTitle()
}
app.switchToScreen(previousScreen)
}
@ -34,6 +36,8 @@ func (app *App) switchToNextScreen() {
case app.help.GetTitle():
nextScreen = app.assets.GetTitle()
case app.assets.GetTitle():
nextScreen = app.shelves.GetTitle()
case app.shelves.GetTitle():
nextScreen = app.help.GetTitle()
}
app.switchToScreen(nextScreen)
@ -45,6 +49,8 @@ func (app *App) setPageFocus(page string) {
app.Application.SetFocus(app.help)
case app.assets.GetTitle():
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 {
case app.assets.GetTitle():
app.assets.UpdateData()
case app.shelves.GetTitle():
app.shelves.UpdateData()
}
}

+ 2
- 2
internal/types/shelves.go View File

@ -19,7 +19,7 @@ type ShelfLocation struct {
RoomNumber string `json:"room_number,omitempty"`
Description string `json:"description,omitempty"`
BuildingID *uint64 `json:"building_id"`
Building *Building `json:"-"`
Building *Building `json:"building"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt *time.Time `json:"deleted_at,omitempty"`
@ -29,5 +29,5 @@ type CreateShelfRequest struct {
Name string `json:"name"`
RoomNumber string `json:"room_number,omitempty"`
Description string `json:"description,omitempty"`
BuildingID *uint64 `json:"building_id"`
BuildingID *uint64 `json:"building_id,omitempty"`
}

+ 14
- 4
internal/ui/shelves/command.go View File

@ -50,13 +50,13 @@ func (a *Shelves) cdelete() {
func (a *Shelves) cedit() {
selectedItem := a.getSelectedItem()
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
}
shelf, err := a.client.RetrieveShelfByID(selectedItem.id)
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
}
@ -72,6 +72,11 @@ func (a *Shelves) edit() {
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)
if err != nil {
a.displayError("SHELF EDIT ERROR", err)
@ -111,12 +116,12 @@ func (a *Shelves) delete() {
}
func (a *Shelves) crefresh() {
a.progressDialog.SetTitle("refreshing shelfs")
a.progressDialog.SetTitle("refreshing shelves")
a.progressDialog.Display()
ref := func() {
a.UpdateShelfData()
a.UpdateShelfData()
a.UpdateBuildingData()
a.progressDialog.Hide()
@ -137,6 +142,11 @@ func (a *Shelves) create() {
return
}
if createReq.BuildingID == nil {
a.displayError("SHELF CREATE ERROR", fmt.Errorf("shelf building cannot be empty"))
return
}
_, err := a.client.CreateShelf(createReq)
if err != nil {
a.displayError("SHELF CREATE ERROR", err)


+ 1
- 1
internal/ui/shelves/refresh.go View File

@ -42,7 +42,7 @@ func (a *Shelves) refresh() {
SetExpansion(a.shelfTableExpansions[2]).
SetAlign(tview.AlignLeft))
a.shelfTable.SetCell(row, 2,
a.shelfTable.SetCell(row, 3,
tview.NewTableCell(shelf.RoomNumber).
SetExpansion(a.shelfTableExpansions[3]).
SetAlign(tview.AlignLeft))


+ 14
- 0
internal/ui/shelves/shelves.go View File

@ -136,6 +136,20 @@ func NewShelves(logger *zap.Logger, client *api.APIClient) *Shelves {
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) {
if resp, err := shelves.client.RetrieveAllBuildings(); err != nil {
return nil, err


+ 2
- 1
internal/ui/shelves/shlvdialogs/edit.go View File

@ -47,7 +47,8 @@ type ShelfEditDialog struct {
logger *zap.Logger
client *api.APIClient
shelf *types.ShelfLocation
buildingList []*types.Building
buildingList []*types.Building
shelfNameField *tview.InputField
shelfRoomField *tview.InputField


Loading…
Cancel
Save