package assets
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"git.brettb.xyz/goinv/client/internal/ui/dialogs"
|
|
"git.brettb.xyz/goinv/client/internal/ui/style"
|
|
)
|
|
|
|
func (a *Assets) runCommand(cmd string) {
|
|
switch cmd {
|
|
case "create asset", "view asset":
|
|
a.cNotImplemented()
|
|
return
|
|
case "delete asset":
|
|
a.cdelete()
|
|
return
|
|
case "refresh":
|
|
a.crefresh()
|
|
}
|
|
}
|
|
|
|
func (a *Assets) cNotImplemented() {
|
|
a.displayError("not implemented", fmt.Errorf("this command has not been implemented"))
|
|
}
|
|
|
|
// Confirm deletion
|
|
func (a *Assets) cdelete() {
|
|
selectedItem := a.getSelectedItem()
|
|
|
|
// Empty table
|
|
if selectedItem == nil {
|
|
a.displayError("DELETE ASSET ERROR", fmt.Errorf("no assets to delete"))
|
|
return
|
|
}
|
|
|
|
title := "delete asset"
|
|
a.confirmDialog.SetTitle(title)
|
|
a.confirmData = status_CONFIRM_DELETE_ASSET
|
|
bgColor := style.GetColorHex(style.DialogBorderColor)
|
|
fgColor := style.GetColorHex(style.DialogFgColor)
|
|
|
|
assetName := fmt.Sprintf("[%s:%s:b]ASSET NAME:[:-:-] %s", fgColor, bgColor, selectedItem.item)
|
|
assetQuantity := fmt.Sprintf(" [%s:%s:b]QUANTITY:[:-:-] %s", fgColor, bgColor, selectedItem.quantity)
|
|
|
|
confirmMsg := fmt.Sprintf("%s\n%s\nAre you sure you want to delete the selected asset ?", assetName, assetQuantity)
|
|
a.confirmDialog.SetText(confirmMsg)
|
|
a.confirmDialog.Display()
|
|
}
|
|
|
|
func (a *Assets) delete() {
|
|
selectedItem := a.getSelectedItem()
|
|
|
|
a.progressDialog.SetTitle(fmt.Sprintf("deleting asset %s", selectedItem.id))
|
|
a.progressDialog.Display()
|
|
|
|
del := func() {
|
|
_, err := a.client.DeleteAssetByID(selectedItem.id)
|
|
|
|
a.progressDialog.Hide()
|
|
|
|
if err != nil {
|
|
a.displayError("DELETE ASSET ERROR", err)
|
|
|
|
return
|
|
}
|
|
|
|
// display success message
|
|
a.messageDialog.SetTitle(fmt.Sprintf("deleting asset %s", selectedItem.id))
|
|
a.messageDialog.SetText(dialogs.MessageGeneric, "Success!", fmt.Sprintf("Asset %s successfully deleted.", selectedItem.id))
|
|
a.messageDialog.Display()
|
|
|
|
a.UpdateAssetData()
|
|
}
|
|
|
|
del()
|
|
}
|
|
|
|
func (a *Assets) crefresh() {
|
|
a.progressDialog.SetTitle("refreshing assets")
|
|
a.progressDialog.Display()
|
|
|
|
ref := func() {
|
|
a.UpdateShelfData()
|
|
a.UpdateAssetData()
|
|
|
|
a.progressDialog.Hide()
|
|
|
|
if !a.errorDialog.IsDisplay() {
|
|
a.messageDialog.SetTitle(fmt.Sprintf("asset refresh"))
|
|
a.messageDialog.SetText(dialogs.MessageGeneric, "Refreshed!", "Successfully refreshed page.")
|
|
a.messageDialog.Display()
|
|
}
|
|
}
|
|
|
|
ref()
|
|
}
|
|
|
|
func (a *Assets) displayError(title string, err error) {
|
|
a.errorDialog.SetTitle(title)
|
|
a.errorDialog.SetText(fmt.Sprintf("%v", err))
|
|
a.errorDialog.Display()
|
|
}
|