From 9488467c754230288934dde4a49b9046e658986c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Mur=C3=A9?= Date: Thu, 2 Aug 2018 16:48:07 +0200 Subject: [PATCH] termui: show the last edit in a dedicated column --- bug/snapshot.go | 4 +-- graphql/graph/gen_graph.go | 72 +++++++++++++++++++++++++++++--------- graphql/schema.graphql | 7 ++-- termui/bug_table.go | 14 +++++--- 4 files changed, 71 insertions(+), 26 deletions(-) diff --git a/bug/snapshot.go b/bug/snapshot.go index 9001d2c7bd5c588828df3efb4cb9b34e2793f0db..7f1d6099c1235a27adc8e16cec09c75c2a989b34 100644 --- a/bug/snapshot.go +++ b/bug/snapshot.go @@ -2,7 +2,6 @@ package bug import ( "fmt" - "github.com/dustin/go-humanize" "time" ) @@ -31,10 +30,9 @@ func (snap Snapshot) HumanId() string { } func (snap Snapshot) Summary() string { - return fmt.Sprintf("C:%d L:%d %s", + return fmt.Sprintf("C:%d L:%d", len(snap.Comments)-1, len(snap.Labels), - humanize.Time(snap.LastEdit()), ) } diff --git a/graphql/graph/gen_graph.go b/graphql/graph/gen_graph.go index 0bba58e3ffce22ae92bd7252f57ea06e36f5c110..63a0c9b5e45b8113874035ea322060fa57d219fe 100644 --- a/graphql/graph/gen_graph.go +++ b/graphql/graph/gen_graph.go @@ -341,12 +341,18 @@ func (ec *executionContext) _Bug(ctx context.Context, sel []query.Selection, obj out.Values[i] = ec._Bug_id(ctx, field, obj) case "humanId": out.Values[i] = ec._Bug_humanId(ctx, field, obj) - case "title": - out.Values[i] = ec._Bug_title(ctx, field, obj) case "status": out.Values[i] = ec._Bug_status(ctx, field, obj) + case "title": + out.Values[i] = ec._Bug_title(ctx, field, obj) case "labels": out.Values[i] = ec._Bug_labels(ctx, field, obj) + case "author": + out.Values[i] = ec._Bug_author(ctx, field, obj) + case "createdAt": + out.Values[i] = ec._Bug_createdAt(ctx, field, obj) + case "lastEdit": + out.Values[i] = ec._Bug_lastEdit(ctx, field, obj) case "comments": out.Values[i] = ec._Bug_comments(ctx, field, obj) case "operations": @@ -381,17 +387,6 @@ func (ec *executionContext) _Bug_humanId(ctx context.Context, field graphql.Coll return graphql.MarshalString(res) } -func (ec *executionContext) _Bug_title(ctx context.Context, field graphql.CollectedField, obj *bug.Snapshot) graphql.Marshaler { - rctx := graphql.GetResolverContext(ctx) - rctx.Object = "Bug" - rctx.Args = nil - rctx.Field = field - rctx.PushField(field.Alias) - defer rctx.Pop() - res := obj.Title - return graphql.MarshalString(res) -} - func (ec *executionContext) _Bug_status(ctx context.Context, field graphql.CollectedField, obj *bug.Snapshot) graphql.Marshaler { ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ Object: "Bug", @@ -422,6 +417,17 @@ func (ec *executionContext) _Bug_status(ctx context.Context, field graphql.Colle }) } +func (ec *executionContext) _Bug_title(ctx context.Context, field graphql.CollectedField, obj *bug.Snapshot) graphql.Marshaler { + rctx := graphql.GetResolverContext(ctx) + rctx.Object = "Bug" + rctx.Args = nil + rctx.Field = field + rctx.PushField(field.Alias) + defer rctx.Pop() + res := obj.Title + return graphql.MarshalString(res) +} + func (ec *executionContext) _Bug_labels(ctx context.Context, field graphql.CollectedField, obj *bug.Snapshot) graphql.Marshaler { rctx := graphql.GetResolverContext(ctx) rctx.Object = "Bug" @@ -442,6 +448,39 @@ func (ec *executionContext) _Bug_labels(ctx context.Context, field graphql.Colle return arr1 } +func (ec *executionContext) _Bug_author(ctx context.Context, field graphql.CollectedField, obj *bug.Snapshot) graphql.Marshaler { + rctx := graphql.GetResolverContext(ctx) + rctx.Object = "Bug" + rctx.Args = nil + rctx.Field = field + rctx.PushField(field.Alias) + defer rctx.Pop() + res := obj.Author + return ec._Person(ctx, field.Selections, &res) +} + +func (ec *executionContext) _Bug_createdAt(ctx context.Context, field graphql.CollectedField, obj *bug.Snapshot) graphql.Marshaler { + rctx := graphql.GetResolverContext(ctx) + rctx.Object = "Bug" + rctx.Args = nil + rctx.Field = field + rctx.PushField(field.Alias) + defer rctx.Pop() + res := obj.CreatedAt + return graphql.MarshalTime(res) +} + +func (ec *executionContext) _Bug_lastEdit(ctx context.Context, field graphql.CollectedField, obj *bug.Snapshot) graphql.Marshaler { + rctx := graphql.GetResolverContext(ctx) + rctx.Object = "Bug" + rctx.Args = nil + rctx.Field = field + rctx.PushField(field.Alias) + defer rctx.Pop() + res := obj.LastEdit() + return graphql.MarshalTime(res) +} + func (ec *executionContext) _Bug_comments(ctx context.Context, field graphql.CollectedField, obj *bug.Snapshot) graphql.Marshaler { args := map[string]interface{}{} var arg0 *string @@ -3202,11 +3241,12 @@ type BugEdge { type Bug { id: String! humanId: String! - title: String! status: Status! - - # A list of labels associated with the repository. + title: String! labels: [Label!]! + author: Person! + createdAt: Time! + lastEdit: Time! comments( # Returns the elements in the list that come after the specified cursor. diff --git a/graphql/schema.graphql b/graphql/schema.graphql index 970166cb77a6441243f3abb2dd51277daa557b6b..410ecde9e97e5d39ee19c89f5e7a24b765c01d5c 100644 --- a/graphql/schema.graphql +++ b/graphql/schema.graphql @@ -133,11 +133,12 @@ type BugEdge { type Bug { id: String! humanId: String! - title: String! status: Status! - - # A list of labels associated with the repository. + title: String! labels: [Label!]! + author: Person! + createdAt: Time! + lastEdit: Time! comments( # Returns the elements in the list that come after the specified cursor. diff --git a/termui/bug_table.go b/termui/bug_table.go index 55b451afc364bfa1a83fc2339003b465ed1ce8dd..f300c42227cd2df94794f84a6769baae501ab066 100644 --- a/termui/bug_table.go +++ b/termui/bug_table.go @@ -5,6 +5,7 @@ import ( "github.com/MichaelMure/git-bug/bug" "github.com/MichaelMure/git-bug/cache" "github.com/MichaelMure/git-bug/util" + "github.com/dustin/go-humanize" "github.com/jroimartin/gocui" ) @@ -243,11 +244,14 @@ func (bt *bugTable) getColumnWidths(maxX int) map[string]int { m["id"] = 10 m["status"] = 8 - left := maxX - 4 - m["id"] - m["status"] + left := maxX - 5 - m["id"] - m["status"] - m["summary"] = maxInt(30, left/3) + m["summary"] = maxInt(11, left/6) left -= m["summary"] + m["lastEdit"] = maxInt(19, left/6) + left -= m["lastEdit"] + m["author"] = maxInt(left*2/5, 15) m["title"] = maxInt(left-m["author"], 10) @@ -270,8 +274,9 @@ func (bt *bugTable) render(v *gocui.View, maxX int) { title := util.LeftPaddedString(snap.Title, columnWidths["title"], 2) author := util.LeftPaddedString(person.Name, columnWidths["author"], 2) summary := util.LeftPaddedString(snap.Summary(), columnWidths["summary"], 2) + lastEdit := util.LeftPaddedString(humanize.Time(snap.LastEdit()), columnWidths["lastEdit"], 2) - fmt.Fprintf(v, "%s %s %s %s %s\n", id, status, title, author, summary) + fmt.Fprintf(v, "%s %s %s %s %s %s\n", id, status, title, author, summary, lastEdit) } } @@ -283,9 +288,10 @@ func (bt *bugTable) renderHeader(v *gocui.View, maxX int) { title := util.LeftPaddedString("TITLE", columnWidths["title"], 2) author := util.LeftPaddedString("AUTHOR", columnWidths["author"], 2) summary := util.LeftPaddedString("SUMMARY", columnWidths["summary"], 2) + lastEdit := util.LeftPaddedString("LAST EDIT", columnWidths["lastEdit"], 2) fmt.Fprintf(v, "\n") - fmt.Fprintf(v, "%s %s %s %s %s\n", id, status, title, author, summary) + fmt.Fprintf(v, "%s %s %s %s %s %s\n", id, status, title, author, summary, lastEdit) }