From b9ec7b9e51a831aba6dae535e333d02f6241a759 Mon Sep 17 00:00:00 2001 From: Elliott Stoneham Date: Wed, 29 Jun 2016 21:26:28 +0100 Subject: [PATCH] improve issue display --- .../components/section/github/type-editor.js | 28 +---- .../components/section/github/type-editor.hbs | 5 +- documize/section/github/github.go | 110 +++++++++--------- documize/section/github/model.go | 99 +++++++++------- 4 files changed, 117 insertions(+), 125 deletions(-) diff --git a/app/app/components/section/github/type-editor.js b/app/app/components/section/github/type-editor.js index c8171da7..43c21823 100644 --- a/app/app/components/section/github/type-editor.js +++ b/app/app/components/section/github/type-editor.js @@ -28,9 +28,6 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin, showLabels: false, didReceiveAttrs() { - $.datetimepicker.setLocale('en'); - $('#branch-since').datetimepicker(); - let self = this; let page = this.get('page'); @@ -53,7 +50,6 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin, branchURL: "", branchSince: "", branchLines: "30", - issueNum: "1" }; try { @@ -64,7 +60,6 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin, config.lists = metaConfig.lists; config.branchSince = metaConfig.branchSince; config.branchLines = metaConfig.branchLines; - config.issueNum = metaConfig.issueNum; } catch (e) {} self.set('config', config); @@ -161,11 +156,7 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin, }; reports[1] = { id: "issues_data", // used as method for fetching Go data - name: "Open Issues" - }; - reports[2] = { - id: "issuenum_data", // used as method for fetching Go data - name: "Individual issue activity" + name: "Issues" }; this.set("reports", reports); @@ -187,6 +178,9 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin, renderSwitch(thisReport) { + $.datetimepicker.setLocale('en'); + $('#branch-since').datetimepicker(); + let bl = this.get('config.branchLines'); if (is.undefined(bl) || bl === "" || bl <= 0) { this.set('config.branchLines', "30"); @@ -194,7 +188,6 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin, this.set('showCommits', false); this.set('showLabels', false); - this.set('showIssueNum', false); switch (thisReport.id) { case 'commits_data': this.set('showCommits', true); @@ -204,10 +197,6 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin, this.set('showLabels', true); this.getLabelLists(); break; - case "issuenum_data": - this.set('showIssueNum', true); - this.set('busy', false); - break; } }, @@ -315,11 +304,6 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin, let lists = this.get('config.lists'); let list = lists.findBy('id', id); - // restore the list of branches to the default state - // lists.forEach(function(lst) { - // Ember.set(lst, 'included', false); - // }); - if (list !== null) { Ember.set(list, 'included', !list.included); } @@ -379,10 +363,6 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin, this.getReportLists(); }, - checkLinesChange(thisLines) { - console.log("onLinesChange", thisLines); - }, - onCancel() { this.attrs.onCancel(); }, diff --git a/app/app/templates/components/section/github/type-editor.hbs b/app/app/templates/components/section/github/type-editor.hbs index 40fe2d70..bcd2fdab 100644 --- a/app/app/templates/components/section/github/type-editor.hbs +++ b/app/app/templates/components/section/github/type-editor.hbs @@ -36,9 +36,6 @@ Show items since {{input id="branch-since" value=config.branchSince type="text" }}
Number of items to show {{input id="branch-lines" value=config.branchLines type="number" min="1" step="1" max="100" }}
- {{#if showIssueNum}} - Issue Number: {{input id="issue-number" value=config.issueNum type="number" min="1" step="1" }} - {{/if}} {{#if showCommits}}
@@ -62,6 +59,8 @@
Select labels - an issue must have all labels to be shown, if no label is selected all issues are shown.
+ TODO: Open/Closed
+ TODO: Issue Numbers
{{#each config.lists as |list|}}
diff --git a/documize/section/github/github.go b/documize/section/github/github.go index adf541db..a53267b0 100644 --- a/documize/section/github/github.go +++ b/documize/section/github/github.go @@ -142,16 +142,16 @@ func (t *Provider) Command(w http.ResponseWriter, r *http.Request) { provider.WriteJSON(w, render) - case "issuenum_data": + /*case "issuenum_data": - render, err := t.getIssueNum(client, config) - if err != nil { - log.Error("github getIssueNum:", err) - provider.WriteError(w, "github", err) - return - } + render, err := t.getIssueNum(client, config) + if err != nil { + log.Error("github getIssueNum:", err) + provider.WriteError(w, "github", err) + return + } - provider.WriteJSON(w, render) + provider.WriteJSON(w, render)*/ case "owners": @@ -290,6 +290,7 @@ func (*Provider) githubClient(config githubConfig) *gogithub.Client { return gogithub.NewClient(tc) } +/* func (*Provider) getIssueNum(client *gogithub.Client, config githubConfig) ([]githubIssueActivity, error) { ret := []githubIssueActivity{} @@ -301,8 +302,8 @@ func (*Provider) getIssueNum(client *gogithub.Client, config githubConfig) ([]gi a := "" p := issue.User if p != nil { - if p.Name != nil { - n = *p.Name + if p.Login != nil { + n = *p.Login } if p.AvatarURL != nil { a = *p.AvatarURL @@ -310,24 +311,24 @@ func (*Provider) getIssueNum(client *gogithub.Client, config githubConfig) ([]gi } ret = append(ret, githubIssueActivity{ Name: n, - Event: "TITLE", + Event: "created", Message: template.HTML(*issue.Title), - Date: issue.UpdatedAt.Format("January 2 2006, 15:04"), + Date: "on " + issue.UpdatedAt.Format("January 2 2006, 15:04"), Avatar: a, URL: template.URL(*issue.HTMLURL), }) ret = append(ret, githubIssueActivity{ Name: n, - Event: "DESCRIPTION", + Event: "described", Message: template.HTML(*issue.Body), - Date: issue.UpdatedAt.Format("January 2 2006, 15:04"), + Date: "on " + issue.UpdatedAt.Format("January 2 2006, 15:04"), Avatar: a, URL: template.URL(*issue.HTMLURL), }) ret = append(ret, githubIssueActivity{ Name: "", - Event: "NOTE", - Message: template.HTML("Issue timeline below is in reverse order"), + Event: "Note", + Message: template.HTML("the issue timeline below is in reverse order"), Date: "", Avatar: githubGravatar, URL: template.URL(*issue.HTMLURL), @@ -371,8 +372,8 @@ func (*Provider) getIssueNum(client *gogithub.Client, config githubConfig) ([]gi u = *ic.HTMLURL p := ic.User if p != nil { - if p.Name != nil { - n = *p.Name + if p.Login != nil { + n = *p.Login } if p.AvatarURL != nil { a = *p.AvatarURL @@ -385,7 +386,7 @@ func (*Provider) getIssueNum(client *gogithub.Client, config githubConfig) ([]gi Name: n, Event: *v.Event, Message: template.HTML(m), - Date: v.CreatedAt.Format("January 2 2006, 15:04"), + Date: "on " + v.CreatedAt.Format("January 2 2006, 15:04"), Avatar: a, URL: template.URL(u), }) @@ -395,11 +396,12 @@ func (*Provider) getIssueNum(client *gogithub.Client, config githubConfig) ([]gi return ret, nil } +*/ func (*Provider) getIssues(client *gogithub.Client, config githubConfig) ([]githubIssue, error) { opts := &gogithub.IssueListByRepoOptions{ - Sort: "created", + Sort: "updated", ListOptions: gogithub.ListOptions{PerPage: config.BranchLines}} if config.SincePtr != nil { @@ -436,9 +438,11 @@ func (*Provider) getIssues(client *gogithub.Client, config githubConfig) ([]gith Name: n, Message: *v.Title, Date: v.CreatedAt.Format("January 2 2006, 15:04"), + Updated: v.UpdatedAt.Format("January 2 2006, 15:04"), URL: template.URL(*v.HTMLURL), Labels: template.HTML(l), ID: *v.Number, + IsOpen: v.ClosedAt == nil, }) } @@ -537,18 +541,18 @@ func (t *Provider) Refresh(configJSON, data string) string { c.Clean() switch c.ReportInfo.ID { - case "issuenum_data": - refreshed, err := t.getIssueNum(t.githubClient(c), c) - if err != nil { - log.Error("unable to get github issue number activity", err) - return data - } - j, err := json.Marshal(refreshed) - if err != nil { - log.Error("unable to marshall github issue number activity", err) - return data - } - return string(j) + /*case "issuenum_data": + refreshed, err := t.getIssueNum(t.githubClient(c), c) + if err != nil { + log.Error("unable to get github issue number activity", err) + return data + } + j, err := json.Marshal(refreshed) + if err != nil { + log.Error("unable to marshall github issue number activity", err) + return data + } + return string(j)*/ case "issues_data": refreshed, err := t.getIssues(t.githubClient(c), c) @@ -602,31 +606,31 @@ func (p *Provider) Render(config, data string) string { } switch c.ReportInfo.ID { - case "issuenum_data": - payload.IssueNum = c.IssueNum - raw := []githubIssueActivity{} + /* case "issuenum_data": + payload.IssueNum = c.IssueNum + raw := []githubIssueActivity{} - if len(data) > 0 { - err = json.Unmarshal([]byte(data), &raw) + if len(data) > 0 { + err = json.Unmarshal([]byte(data), &raw) + if err != nil { + log.Error("unable to unmarshall github issue activity data", err) + return "Documize internal github json umarshall issue activity data error: " + err.Error() + } + } + + opt := &gogithub.MarkdownOptions{Mode: "gfm", Context: c.Owner + "/" + c.Repo} + client := p.githubClient(c) + for k, v := range raw { + if v.Event == "commented" { + output, _, err := client.Markdown(string(v.Message), opt) if err != nil { - log.Error("unable to unmarshall github issue activity data", err) - return "Documize internal github json umarshall issue activity data error: " + err.Error() + log.Error("convert commented text to markdown", err) + } else { + raw[k].Message = template.HTML(output) } } - - opt := &gogithub.MarkdownOptions{Mode: "gfm", Context: c.Owner + "/" + c.Repo} - client := p.githubClient(c) - for k, v := range raw { - if v.Event == "commented" { - output, _, err := client.Markdown(string(v.Message), opt) - if err != nil { - log.Error("convert commented text to markdown", err) - } else { - raw[k].Message = template.HTML(output) - } - } - } - payload.IssueNumActivity = raw + } + payload.IssueNumActivity = raw */ case "issues_data": raw := []githubIssue{} diff --git a/documize/section/github/model.go b/documize/section/github/model.go index 898419b7..913ba2eb 100644 --- a/documize/section/github/model.go +++ b/documize/section/github/model.go @@ -20,17 +20,17 @@ import ( ) type githubRender struct { - Config githubConfig - Repo githubRepo - List []githubBranch - ShowList bool - BranchCommits []githubBranchCommits - CommitCount int - Issues []githubIssue - IssueNum int - IssueNumActivity []githubIssueActivity - Limit int - DateMessage string + Config githubConfig + Repo githubRepo + List []githubBranch + ShowList bool + BranchCommits []githubBranchCommits + CommitCount int + Issues []githubIssue + //IssueNum int + //IssueNumActivity []githubIssueActivity + Limit int + DateMessage string } var renderTemplates = map[string]string{ @@ -86,14 +86,20 @@ var renderTemplates = map[string]string{
  • - - - -
    + {{if $data.IsOpen}} + + + + {{else}} + + + + {{end}} +
  • {{$data.Message}} {{$data.Labels}}
    - #{{$data.ID}} opened on {{$data.Date}} by {{$data.Name}} + #{{$data.ID}} opened on {{$data.Date}} by {{$data.Name}}, last updated {{$data.Updated}}
    @@ -104,35 +110,34 @@ var renderTemplates = map[string]string{
    `, - "issuenum_data": ` -
    -

    - Activity for issue #{{.IssueNum}} in repository {{.Repo.Name}}. - Up to {{ .Limit }} items are shown{{ .DateMessage }}. -

    -
    -
      - {{range $data := .IssueNumActivity}} -
    • -
      - @{{$data.Name}} -
      -
      -
      - - {{$data.Event}}: - - {{$data.Message}} -
      -
      {{$data.Name}} committed on {{$data.Date}}
      -
      -
      -
    • - {{end}} -
    -
    -
    -`, + /* "issuenum_data": ` +
    +

    + Activity for issue #{{.IssueNum}} in repository {{.Repo.Name}}. + Up to {{ .Limit }} items are shown{{ .DateMessage }}. +

    +
    +
      + {{range $data := .IssueNumActivity}} +
    • +
      + @{{$data.Name}} +
      +
      + {{$data.Name}} {{$data.Event}} {{$data.Date}} +
      +
      +
      + {{$data.Message}} +
      +
      +
      +
    • + {{end}} +
    +
    +
    + `,*/ } type githubReport struct { @@ -180,13 +185,16 @@ type githubCommit struct { type githubIssue struct { ID int `json:"id"` Date string `json:"date"` + Updated string `json:"dated"` Message string `json:"message"` URL template.URL `json:"url"` Name string `json:"name"` Avatar string `json:"avatar"` Labels template.HTML `json:"labels"` + IsOpen bool `json:"isopen"` } +/* type githubIssueActivity struct { Date string `json:"date"` Event string `json:"event"` @@ -195,6 +203,7 @@ type githubIssueActivity struct { Name string `json:"name"` Avatar string `json:"avatar"` } +*/ type githubConfig struct { AppKey string `json:"appKey"` // TODO keep?