From b42fc1f84d1c0228fb902248806bb865475f7347 Mon Sep 17 00:00:00 2001 From: Elliott Stoneham Date: Tue, 23 Aug 2016 17:11:31 +0100 Subject: [PATCH] 1st cut rejigged edit page, unused code commented out for now --- .../components/section/github/type-editor.js | 72 +++++++- .../components/section/github/type-editor.hbs | 61 +------ core/section/github/lists.go | 169 +++++++++++------- core/section/github/model.go | 55 +++--- core/section/github/sort.go | 7 + 5 files changed, 221 insertions(+), 143 deletions(-) diff --git a/app/app/components/section/github/type-editor.js b/app/app/components/section/github/type-editor.js index a07327d5..3d8fe094 100644 --- a/app/app/components/section/github/type-editor.js +++ b/app/app/components/section/github/type-editor.js @@ -112,10 +112,10 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin, getOwnerLists() { this.set('busy', true); - let self = this; + //let self = this; let owners = this.get('owners'); let thisOwner = this.get('config.owner'); - let page = this.get('page'); + //let page = this.get('page'); if (is.null(thisOwner) || is.undefined(thisOwner)) { if (owners.length) { @@ -128,6 +128,7 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin, this.set('owner', thisOwner); + /* this.get('sectionService').fetch(page, "repos", self.get('config')) .then(function (lists) { self.set('busy', false); @@ -139,8 +140,18 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin, self.showNotification("Unable to fetch repositories"); console.log(error); }); + */ + this.getOrgReposLists(); + + if (is.undefined(this.get('initDateTimePicker'))) { + $.datetimepicker.setLocale('en'); + $('#branch-since').datetimepicker(); + this.set('initDateTimePicker', "Done"); + } + }, + /* getRepoLists() { this.set('busy', true); @@ -266,7 +277,53 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin, console.log(error); }); }, + */ + getOrgReposLists() { + this.set('busy', true); + + let self = this; + let page = this.get('page'); + + this.get('sectionService').fetch(page, "orgrepos", self.get('config')) + .then(function (lists) { + let savedLists = self.get('config.lists'); + if (savedLists === null) { + savedLists = []; + } + + if (lists.length > 0) { + let noIncluded = true; + + lists.forEach(function (list) { + let included = false; + var saved; + if (is.not.undefined(savedLists)) { + saved = savedLists.findBy("id", list.id); + } + if (is.not.undefined(saved)) { + included = saved.included; + noIncluded = false; + } + list.included = included; + }); + + if (noIncluded) { + lists[0].included = true; // make the first entry the default + } + } + + self.set('config.lists', lists); + self.set('busy', false); + }, function (error) { //jshint ignore: line + self.set('busy', false); + self.set('authenticated', false); + self.showNotification("Unable to fetch repository branches"); + console.log(error); + }); + }, + + /* getLabelLists() { this.set('busy', true); @@ -330,6 +387,7 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin, console.log(error); }); }, + */ actions: { isDirty() { @@ -341,15 +399,16 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin, let list = lists.findBy('id', id); // restore the list of branches to the default state - lists.forEach(function (lst) { - Ember.set(lst, 'included', false); - }); + //lists.forEach(function (lst) { + // Ember.set(lst, 'included', false); + //}); if (list !== null) { Ember.set(list, 'included', !list.included); } }, + /* onLabelCheckbox(id) { let lists = this.get('config.lists'); let list = lists.findBy('id', id); @@ -358,6 +417,7 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin, Ember.set(list, 'included', !list.included); } }, + */ authStage2() { let self = this; @@ -399,6 +459,7 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin, this.getOwnerLists(); }, + /* onRepoChange(thisRepo) { this.set('isDirty', true); this.set('config.repo', thisRepo); @@ -411,6 +472,7 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin, this.set('config.report', thisReport); this.getReportLists(); }, + */ onStateChange(thisState) { this.set('config.state', thisState); diff --git a/app/app/templates/components/section/github/type-editor.hbs b/app/app/templates/components/section/github/type-editor.hbs index 28ac93e7..2fc44c6b 100644 --- a/app/app/templates/components/section/github/type-editor.hbs +++ b/app/app/templates/components/section/github/type-editor.hbs @@ -7,12 +7,12 @@
-
Select Repository
+
Select Repositories
Choose source of code information to be displayed
- -
Select organization or username
+ +
Select organization or username whose repositories you want to show
{{ui-select id="owners-dropdown" content=owners action=(action 'onOwnerChange') optionValuePath="id" optionLabelPath="name" selection=config.owner}}
{{#if noRepos}} @@ -21,22 +21,8 @@
{{else}}
- -
Select repository
- {{ui-select id="repos-dropdown" content=repos action=(action 'onRepoChange') optionValuePath="id" optionLabelPath="name" selection=config.repo}} -
-
- -
Select report type
- {{ui-select id="report-dropdown" content=reports action=(action 'onReportChange') optionValuePath="id" optionLabelPath="name" selection=config.report}} -
-
- - {{input id="branch-since" value=config.branchSince type="text" }} -
-
- - {{input id="branch-lines" value=config.branchLines type="number" min="1" step="1" max="100" }} + + {{input id="branch-since" value=config.branchSince type="text" }}
{{/if}}
@@ -46,10 +32,9 @@
- {{#if showCommits}}
- -
Select branch
+ +
Select the repositories to show
{{#each config.lists as |list|}}
@@ -58,42 +43,12 @@ {{else}} check_box_outline_blank {{/if}} - {{list.name}} + {{list.repo}} {{#if list.private}}(private){{/if}}
{{/each}}
- {{/if}} - {{#if showLabels}} -
- -
Open, Closed or All issues
- {{ui-select id="issue-state-dropdown" content=states action=(action 'onStateChange') optionValuePath="id" optionLabelPath="name" selection=config.state}} -
-
- -
A comma separated list of issue numbers e.g. 42, 1066, 1966 (other selection criteria are ignored)
- {{input id="github-issues" value=config.issues type="text" }} -
-
- -
Select labels - an issue must have all labels to be shown, if no label is selected all issues are shown.
-
- {{#each config.lists as |list|}} -
- {{#if list.included}} - check_box - {{else}} - check_box_outline_blank - {{/if}} - {{list.name}} -
- {{/each}} -
-
-
- {{/if}}
diff --git a/core/section/github/lists.go b/core/section/github/lists.go index 3879335b..87804370 100644 --- a/core/section/github/lists.go +++ b/core/section/github/lists.go @@ -52,9 +52,84 @@ func listFailed(method string, config githubConfig, client *gogithub.Client, w h provider.WriteJSON(w, owners) - case "repos": + /* + case "repos": - var render []githubRepo + var render []githubRepo + if config.Owner != "" { + + me, _, err := client.Users.Get("") + if err != nil { + log.Error("github get user details:", err) + provider.WriteError(w, "github", err) + return + } + + var repos []*gogithub.Repository + if config.Owner == *me.Login { + repos, _, err = client.Repositories.List(config.Owner, nil) + } else { + opt := &gogithub.RepositoryListByOrgOptions{ + ListOptions: gogithub.ListOptions{PerPage: 100}, + } + repos, _, err = client.Repositories.ListByOrg(config.Owner, opt) + } + if err != nil { + log.Error("github get user/org repositories:", err) + provider.WriteError(w, "github", err) + return + } + for _, vr := range repos { + private := "" + if *vr.Private { + private = " (private)" + } + render = append(render, + githubRepo{ + Name: config.Owner + "/" + *vr.Name + private, + ID: fmt.Sprintf("%s:%s", config.Owner, *vr.Name), + Owner: config.Owner, + Repo: *vr.Name, + Private: *vr.Private, + URL: *vr.HTMLURL, + }) + } + } + render = sortRepos(render) + + provider.WriteJSON(w, render) + + case "branches": + + if config.Owner == "" || config.Repo == "" { + provider.WriteJSON(w, []githubBranch{}) // we have nothing to return + return + } + branches, _, err := client.Repositories.ListBranches(config.Owner, config.Repo, + &gogithub.ListOptions{PerPage: 100}) + if err != nil { + log.Error("github get branch details:", err) + provider.WriteError(w, "github", err) + return + } + render := make([]githubBranch, len(branches)) + for kc, vb := range branches { + render[kc] = githubBranch{ + Owner: config.Owner, + Repo: config.Repo, + Name: *vb.Name, + ID: fmt.Sprintf("%s:%s:%s", config.Owner, config.Repo, *vb.Name), + Included: false, + URL: "https://github.com/" + config.Owner + "/" + config.Repo + "/tree/" + *vb.Name, + } + } + + provider.WriteJSON(w, render) + */ + + case "orgrepos": + + var render []githubBranch if config.Owner != "" { me, _, err := client.Users.Get("") @@ -79,76 +154,48 @@ func listFailed(method string, config githubConfig, client *gogithub.Client, w h return } for _, vr := range repos { - private := "" - if *vr.Private { - private = " (private)" - } render = append(render, - githubRepo{ - Name: config.Owner + "/" + *vr.Name + private, - ID: fmt.Sprintf("%s:%s", config.Owner, *vr.Name), - Owner: config.Owner, - Repo: *vr.Name, - Private: *vr.Private, - URL: *vr.HTMLURL, + githubBranch{ + Name: "master", + ID: fmt.Sprintf("%s:%s", config.Owner, *vr.Name), + Owner: config.Owner, + Repo: *vr.Name, + Private: *vr.Private, + Included: false, + URL: *vr.HTMLURL, }) } } - render = sortRepos(render) + render = sortBranches(render) provider.WriteJSON(w, render) - case "branches": + /* + case "labels": - if config.Owner == "" || config.Repo == "" { - provider.WriteJSON(w, []githubBranch{}) // we have nothing to return - return - } - branches, _, err := client.Repositories.ListBranches(config.Owner, config.Repo, - &gogithub.ListOptions{PerPage: 100}) - if err != nil { - log.Error("github get branch details:", err) - provider.WriteError(w, "github", err) - return - } - render := make([]githubBranch, len(branches)) - for kc, vb := range branches { - render[kc] = githubBranch{ - Owner: config.Owner, - Repo: config.Repo, - Name: *vb.Name, - ID: fmt.Sprintf("%s:%s:%s", config.Owner, config.Repo, *vb.Name), - Included: false, - URL: "https://github.com/" + config.Owner + "/" + config.Repo + "/tree/" + *vb.Name, + if config.Owner == "" || config.Repo == "" { + provider.WriteJSON(w, []githubBranch{}) // we have nothing to return + return } - } - - provider.WriteJSON(w, render) - - case "labels": - - if config.Owner == "" || config.Repo == "" { - provider.WriteJSON(w, []githubBranch{}) // we have nothing to return - return - } - labels, _, err := client.Issues.ListLabels(config.Owner, config.Repo, - &gogithub.ListOptions{PerPage: 100}) - if err != nil { - log.Error("github get labels:", err) - provider.WriteError(w, "github", err) - return - } - render := make([]githubBranch, len(labels)) - for kc, vb := range labels { - render[kc] = githubBranch{ - Name: *vb.Name, - ID: fmt.Sprintf("%s:%s:%s", config.Owner, config.Repo, *vb.Name), - Included: false, - Color: *vb.Color, + labels, _, err := client.Issues.ListLabels(config.Owner, config.Repo, + &gogithub.ListOptions{PerPage: 100}) + if err != nil { + log.Error("github get labels:", err) + provider.WriteError(w, "github", err) + return + } + render := make([]githubBranch, len(labels)) + for kc, vb := range labels { + render[kc] = githubBranch{ + Name: *vb.Name, + ID: fmt.Sprintf("%s:%s:%s", config.Owner, config.Repo, *vb.Name), + Included: false, + Color: *vb.Color, + } } - } - provider.WriteJSON(w, render) + provider.WriteJSON(w, render) + */ default: return true // failed to get a list diff --git a/core/section/github/model.go b/core/section/github/model.go index dcf6bc24..632ae6df 100644 --- a/core/section/github/model.go +++ b/core/section/github/model.go @@ -12,7 +12,6 @@ package github import ( - "fmt" "sort" "strings" "time" @@ -86,6 +85,7 @@ type githubBranch struct { URL string `json:"url"` Color string `json:"color,omitempty"` Comma bool `json:"comma"` + Private bool `json:"private"` } type githubLabel struct { @@ -155,37 +155,44 @@ func (c *githubConfig) Clean() { c.Since = (*c.SincePtr).Format(issuesTimeFormat) // TEST DATA INSERTION DEBUG ONLY! - debugList := map[string][]string{ - "community": []string{"master"}, - "enterprise": []string{"master"}, - "test-data": []string{"master"}, - } - c.Lists = make([]githubBranch, 0, len(debugList)*3) - for repo, branches := range debugList { - render := make([]githubBranch, len(branches)) - for kc, vb := range branches { - render[kc] = githubBranch{ - Owner: "documize", - Repo: repo, - Name: vb, - ID: fmt.Sprintf("%s:%s:%s", "documize", repo, vb), - Included: true, - URL: "https://github.com/" + "documize" + "/" + repo + "/tree/" + vb, - } + /* + debugList := map[string][]string{ + "community": []string{"master"}, + "enterprise": []string{"master"}, + "test-data": []string{"master"}, } - c.Lists = append(c.Lists, render...) - } - c.Owner = "documize" + c.Lists = make([]githubBranch, 0, len(debugList)*3) + for repo, branches := range debugList { + render := make([]githubBranch, len(branches)) + for kc, vb := range branches { + render[kc] = githubBranch{ + Owner: "documize", + Repo: repo, + Name: vb, + ID: fmt.Sprintf("%s:%s:%s", "documize", repo, vb), + Included: true, + URL: "https://github.com/" + "documize" + "/" + repo + "/tree/" + vb, + } + } + c.Lists = append(c.Lists, render...) + } + c.Owner = "documize" + */ c.ReportOrder = []string{tagSummaryData, tagMilestonesData, tagIssuesData /*, tagPullRequestData*/, tagCommitsData} c.BranchLines = 100 // overide js default of 30 with maximum allowable in one call sort.Stable(branchesToSort(c.Lists)) // get the configured branches in a sensible order for printing + + lastItem := 0 for i := range c.Lists { - if i != len(c.Lists)-1 { - c.Lists[i].Comma = true // put the commas in the right places + c.Lists[i].Comma = true + if c.Lists[i].Included { + lastItem = i } } - + if lastItem < len(c.Lists) { + c.Lists[lastItem].Comma = false + } } type githubCallbackT struct { diff --git a/core/section/github/sort.go b/core/section/github/sort.go index 4c78437f..55f08d9e 100644 --- a/core/section/github/sort.go +++ b/core/section/github/sort.go @@ -42,3 +42,10 @@ func sortOwners(in []githubOwner) []githubOwner { sort.Sort(sts) return []githubOwner(sts) } + +// sort branches in order that that should be presented. +func sortBranches(in []githubBranch) []githubBranch { + sts := branchesToSort(in) + sort.Sort(sts) + return []githubBranch(sts) +}