aboutsummaryrefslogtreecommitdiffstats
path: root/termui
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-09-02 15:46:43 +0200
committerMichael Muré <batolettre@gmail.com>2018-09-02 15:46:43 +0200
commit919f98efdb10d57767cf129c3c0b3c357aaa29d2 (patch)
tree647b2e8092d8f26ae6cafcd3e18ae8db0c7ddac2 /termui
parent90a45b4c0979dd744aa5a28c84ececf243f027d2 (diff)
downloadgit-bug-919f98efdb10d57767cf129c3c0b3c357aaa29d2.tar.gz
cache: provide sorted (id, creation, edit) list of bugs
Diffstat (limited to 'termui')
-rw-r--r--termui/bug_table.go36
1 files changed, 11 insertions, 25 deletions
diff --git a/termui/bug_table.go b/termui/bug_table.go
index 6f83a471..00b0ffb4 100644
--- a/termui/bug_table.go
+++ b/termui/bug_table.go
@@ -212,22 +212,17 @@ func (bt *bugTable) disable(g *gocui.Gui) error {
}
func (bt *bugTable) paginate(max int) error {
- allIds, err := bt.repo.AllBugIds()
- if err != nil {
- return err
- }
+ bt.allIds = bt.repo.AllBugsOrderByCreation()
- bt.allIds = allIds
-
- return bt.doPaginate(allIds, max)
+ return bt.doPaginate(max)
}
-func (bt *bugTable) doPaginate(allIds []string, max int) error {
+func (bt *bugTable) doPaginate(max int) error {
// clamp the cursor
bt.pageCursor = maxInt(bt.pageCursor, 0)
- bt.pageCursor = minInt(bt.pageCursor, len(allIds))
+ bt.pageCursor = minInt(bt.pageCursor, len(bt.allIds))
- nb := minInt(len(allIds)-bt.pageCursor, max)
+ nb := minInt(len(bt.allIds)-bt.pageCursor, max)
if nb < 0 {
bt.bugs = []*cache.BugCache{}
@@ -235,7 +230,7 @@ func (bt *bugTable) doPaginate(allIds []string, max int) error {
}
// slice the data
- ids := allIds[bt.pageCursor : bt.pageCursor+nb]
+ ids := bt.allIds[bt.pageCursor : bt.pageCursor+nb]
bt.bugs = make([]*cache.BugCache, len(ids))
@@ -360,34 +355,25 @@ func (bt *bugTable) cursorClamp(v *gocui.View) error {
func (bt *bugTable) nextPage(g *gocui.Gui, v *gocui.View) error {
_, max := v.Size()
- allIds, err := bt.repo.AllBugIds()
- if err != nil {
- return err
- }
-
- bt.allIds = allIds
+ bt.allIds = bt.repo.AllBugsOrderByCreation()
- if bt.pageCursor+max >= len(allIds) {
+ if bt.pageCursor+max >= len(bt.allIds) {
return nil
}
bt.pageCursor += max
- return bt.doPaginate(allIds, max)
+ return bt.doPaginate(max)
}
func (bt *bugTable) previousPage(g *gocui.Gui, v *gocui.View) error {
_, max := v.Size()
- allIds, err := bt.repo.AllBugIds()
- if err != nil {
- return err
- }
- bt.allIds = allIds
+ bt.allIds = bt.repo.AllBugsOrderByCreation()
bt.pageCursor = maxInt(0, bt.pageCursor-max)
- return bt.doPaginate(allIds, max)
+ return bt.doPaginate(max)
}
func (bt *bugTable) newBug(g *gocui.Gui, v *gocui.View) error {