mirror of
https://github.com/documize/community.git
synced 2025-07-24 23:59:47 +02:00
1st cut of various overview sub-reports, a WIP
This commit is contained in:
parent
772aeff93d
commit
36b2767a6d
10 changed files with 445 additions and 46 deletions
|
@ -188,6 +188,7 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
|
||||||
.then(function (boards) {
|
.then(function (boards) {
|
||||||
self.set('busy', false);
|
self.set('busy', false);
|
||||||
self.set('boards', boards);
|
self.set('boards', boards);
|
||||||
|
self.set('config.boards', boards); // save the boards in the config too
|
||||||
self.getBoardLists();
|
self.getBoardLists();
|
||||||
}, function (error) { //jshint ignore: line
|
}, function (error) { //jshint ignore: line
|
||||||
self.set('busy', false);
|
self.set('busy', false);
|
||||||
|
|
17
core/section/trello/archive_template.go
Normal file
17
core/section/trello/archive_template.go
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
||||||
|
//
|
||||||
|
// This software (Documize Community Edition) is licensed under
|
||||||
|
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
||||||
|
//
|
||||||
|
// You can operate outside the AGPL restrictions by purchasing
|
||||||
|
// Documize Enterprise Edition and obtaining a commercial license
|
||||||
|
// by contacting <sales@documize.com>.
|
||||||
|
//
|
||||||
|
// https://documize.com
|
||||||
|
|
||||||
|
package trello
|
||||||
|
|
||||||
|
const archiveTemplate = `
|
||||||
|
Archive?<br>
|
||||||
|
<br>
|
||||||
|
`
|
17
core/section/trello/boards_template.go
Normal file
17
core/section/trello/boards_template.go
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
||||||
|
//
|
||||||
|
// This software (Documize Community Edition) is licensed under
|
||||||
|
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
||||||
|
//
|
||||||
|
// You can operate outside the AGPL restrictions by purchasing
|
||||||
|
// Documize Enterprise Edition and obtaining a commercial license
|
||||||
|
// by contacting <sales@documize.com>.
|
||||||
|
//
|
||||||
|
// https://documize.com
|
||||||
|
|
||||||
|
package trello
|
||||||
|
|
||||||
|
const boardsTemplate = `
|
||||||
|
All Boards<br>
|
||||||
|
<br>
|
||||||
|
`
|
28
core/section/trello/graphs_template.go
Normal file
28
core/section/trello/graphs_template.go
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
||||||
|
//
|
||||||
|
// This software (Documize Community Edition) is licensed under
|
||||||
|
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
||||||
|
//
|
||||||
|
// You can operate outside the AGPL restrictions by purchasing
|
||||||
|
// Documize Enterprise Edition and obtaining a commercial license
|
||||||
|
// by contacting <sales@documize.com>.
|
||||||
|
//
|
||||||
|
// https://documize.com
|
||||||
|
|
||||||
|
package trello
|
||||||
|
|
||||||
|
const graphsTemplate = `
|
||||||
|
<b>Single Boards (graphs)</b><br>
|
||||||
|
{{range $b := .Boards}}
|
||||||
|
<div>
|
||||||
|
<p>There are {{ $b.CardCount }} cards across {{ $b.ListCount }} lists for board <a href="{{ $b.Board.URL }}">{{$b.Board.Name}}.</a></p>
|
||||||
|
<div>
|
||||||
|
{{range $data := $b.Data}}
|
||||||
|
<div style="background-color: {{$b.Board.Prefs.BackgroundColor}}">
|
||||||
|
<progress value="{{len $data.Cards}}" max="{{ $b.CardCount }}"></progress> {{ $data.List.Name }}
|
||||||
|
</div>
|
||||||
|
{{end}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{end}}
|
||||||
|
`
|
24
core/section/trello/labels_template.go
Normal file
24
core/section/trello/labels_template.go
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
||||||
|
//
|
||||||
|
// This software (Documize Community Edition) is licensed under
|
||||||
|
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
||||||
|
//
|
||||||
|
// You can operate outside the AGPL restrictions by purchasing
|
||||||
|
// Documize Enterprise Edition and obtaining a commercial license
|
||||||
|
// by contacting <sales@documize.com>.
|
||||||
|
//
|
||||||
|
// https://documize.com
|
||||||
|
|
||||||
|
package trello
|
||||||
|
|
||||||
|
const labelsTemplate = `
|
||||||
|
<b>Labels</b><br>
|
||||||
|
{{range $l := .SharedLabels}}
|
||||||
|
<span style="background-color: {{ $l.Color }}">{{ $l.Name }}</span>
|
||||||
|
{{range $brd := $l.Boards}}
|
||||||
|
{{ $brd }},
|
||||||
|
{{end}}
|
||||||
|
<br>
|
||||||
|
{{end}}
|
||||||
|
<br>
|
||||||
|
`
|
87
core/section/trello/master_template.go
Normal file
87
core/section/trello/master_template.go
Normal file
|
@ -0,0 +1,87 @@
|
||||||
|
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
||||||
|
//
|
||||||
|
// This software (Documize Community Edition) is licensed under
|
||||||
|
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
||||||
|
//
|
||||||
|
// You can operate outside the AGPL restrictions by purchasing
|
||||||
|
// Documize Enterprise Edition and obtaining a commercial license
|
||||||
|
// by contacting <sales@documize.com>.
|
||||||
|
//
|
||||||
|
// https://documize.com
|
||||||
|
|
||||||
|
package trello
|
||||||
|
|
||||||
|
const renderTemplate = `
|
||||||
|
<h3>Header for Trello Multi-Board Test (in master_template.go)</h3>
|
||||||
|
` + labelsTemplate +
|
||||||
|
boardsTemplate +
|
||||||
|
graphsTemplate +
|
||||||
|
membersTemplate +
|
||||||
|
archiveTemplate +
|
||||||
|
tradTemplate +
|
||||||
|
``
|
||||||
|
|
||||||
|
const oldSave = `
|
||||||
|
<b>Labels</b><br>
|
||||||
|
{{range $l := .SharedLabels}}
|
||||||
|
<span style="background-color: {{ $l.Color }}">{{ $l.Name }}</span>
|
||||||
|
{{range $brd := $l.Boards}}
|
||||||
|
{{ $brd }},
|
||||||
|
{{end}}
|
||||||
|
<br>
|
||||||
|
{{end}}
|
||||||
|
<br>
|
||||||
|
All Boards<br>
|
||||||
|
<br>
|
||||||
|
<b>Single Boards (graphs)</b><br>
|
||||||
|
{{range $b := .Boards}}
|
||||||
|
<div>
|
||||||
|
<p>There are {{ $b.CardCount }} cards across {{ $b.ListCount }} lists for board <a href="{{ $b.Board.URL }}">{{$b.Board.Name}}.</a></p>
|
||||||
|
<div>
|
||||||
|
{{range $data := $b.Data}}
|
||||||
|
<div style="background-color: {{$b.Board.Prefs.BackgroundColor}}">
|
||||||
|
<progress value="{{len $data.Cards}}" max="{{ $b.CardCount }}"></progress> {{ $data.List.Name }}
|
||||||
|
</div>
|
||||||
|
{{end}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{end}}
|
||||||
|
|
||||||
|
<br>
|
||||||
|
<b>Member Stats</b><br>
|
||||||
|
{{range $m := .MemberBoardAssign}}
|
||||||
|
<img src="https://trello-avatars.s3.amazonaws.com/{{$m.AvatarHash}}/50.png">
|
||||||
|
{{$m.MemberName}} :
|
||||||
|
{{range $ac := $m.AssignCounts}}
|
||||||
|
{{$ac.BoardName}} ({{$ac.Count}}),
|
||||||
|
{{end}}
|
||||||
|
<br>
|
||||||
|
{{end}}
|
||||||
|
<br>
|
||||||
|
Archive?<br>
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<b>Previous version</b>
|
||||||
|
|
||||||
|
{{range $b := .Boards}}
|
||||||
|
<p class="non-printable-message">Non-printable</p>
|
||||||
|
<div class="section-trello-render non-printable">
|
||||||
|
<p>There are {{ $b.CardCount }} cards across {{ $b.ListCount }} lists for board <a href="{{ $b.Board.URL }}">{{$b.Board.Name}}.</a></p>
|
||||||
|
<div class="trello-board" style="background-color: {{$b.Board.Prefs.BackgroundColor}}">
|
||||||
|
<a href="{{ $b.Board.URL }}"><div class="trello-board-title">{{$b.Board.Name}}</div></a>
|
||||||
|
{{range $data := $b.Data}}
|
||||||
|
<div class="trello-list">
|
||||||
|
<div class="trello-list-title">{{ $data.List.Name }}</div>
|
||||||
|
{{range $card := $data.Cards}}
|
||||||
|
<a href="{{ $card.URL }}">
|
||||||
|
<div class="trello-card">
|
||||||
|
{{ $card.Name }}
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
{{end}}
|
||||||
|
</div>
|
||||||
|
{{end}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{end}}
|
||||||
|
`
|
25
core/section/trello/members_template.go
Normal file
25
core/section/trello/members_template.go
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
||||||
|
//
|
||||||
|
// This software (Documize Community Edition) is licensed under
|
||||||
|
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
||||||
|
//
|
||||||
|
// You can operate outside the AGPL restrictions by purchasing
|
||||||
|
// Documize Enterprise Edition and obtaining a commercial license
|
||||||
|
// by contacting <sales@documize.com>.
|
||||||
|
//
|
||||||
|
// https://documize.com
|
||||||
|
|
||||||
|
package trello
|
||||||
|
|
||||||
|
const membersTemplate = `
|
||||||
|
<b>Member Stats</b><br>
|
||||||
|
{{range $m := .MemberBoardAssign}}
|
||||||
|
<img src="https://trello-avatars.s3.amazonaws.com/{{$m.AvatarHash}}/50.png">
|
||||||
|
{{$m.MemberName}} :
|
||||||
|
{{range $ac := $m.AssignCounts}}
|
||||||
|
{{$ac.BoardName}} ({{$ac.Count}}),
|
||||||
|
{{end}}
|
||||||
|
<br>
|
||||||
|
{{end}}
|
||||||
|
<br>
|
||||||
|
`
|
|
@ -13,37 +13,16 @@ package trello
|
||||||
|
|
||||||
import "strings"
|
import "strings"
|
||||||
|
|
||||||
const renderTemplate = `
|
|
||||||
<p class="non-printable-message">Non-printable</p>
|
|
||||||
<div class="section-trello-render non-printable">
|
|
||||||
<p>There are {{ .CardCount }} cards across {{ .ListCount }} lists for board <a href="{{ .Board.URL }}">{{.Board.Name}}.</a></p>
|
|
||||||
<div class="trello-board" style="background-color: {{.Board.Prefs.BackgroundColor}}">
|
|
||||||
<a href="{{ .Board.URL }}"><div class="trello-board-title">{{.Board.Name}}</div></a>
|
|
||||||
{{range $data := .Data}}
|
|
||||||
<div class="trello-list">
|
|
||||||
<div class="trello-list-title">{{ $data.List.Name }}</div>
|
|
||||||
{{range $card := $data.Cards}}
|
|
||||||
<a href="{{ $card.URL }}">
|
|
||||||
<div class="trello-card">
|
|
||||||
{{ $card.Name }}
|
|
||||||
</div>
|
|
||||||
</a>
|
|
||||||
{{end}}
|
|
||||||
</div>
|
|
||||||
{{end}}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
`
|
|
||||||
|
|
||||||
type secrets struct {
|
type secrets struct {
|
||||||
Token string `json:"token"`
|
Token string `json:"token"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type trelloConfig struct {
|
type trelloConfig struct {
|
||||||
AppKey string `json:"appKey"`
|
AppKey string `json:"appKey"`
|
||||||
Token string `json:"token"`
|
Token string `json:"token"`
|
||||||
Board trelloBoard `json:"board"`
|
Board trelloBoard `json:"board"` // TODO review
|
||||||
Lists []trelloList `json:"lists"`
|
Lists []trelloList `json:"lists"` // TODO review
|
||||||
|
Boards []trelloBoard `json:"boards"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *trelloConfig) Clean() {
|
func (c *trelloConfig) Clean() {
|
||||||
|
@ -197,9 +176,35 @@ type trelloListCards struct {
|
||||||
Cards []trelloCard
|
Cards []trelloCard
|
||||||
}
|
}
|
||||||
|
|
||||||
type trelloRender struct {
|
type trelloRenderBoard struct {
|
||||||
Board trelloBoard
|
Board trelloBoard
|
||||||
Data []trelloListCards
|
Data []trelloListCards
|
||||||
CardCount int
|
CardCount int
|
||||||
ListCount int
|
ListCount int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type trelloSharedLabel struct {
|
||||||
|
Name string
|
||||||
|
Color string
|
||||||
|
Boards []string
|
||||||
|
}
|
||||||
|
|
||||||
|
type trelloBoardAssignCount struct {
|
||||||
|
BoardName string
|
||||||
|
Count int
|
||||||
|
}
|
||||||
|
|
||||||
|
type trelloBoardAssign struct {
|
||||||
|
AvatarHash string
|
||||||
|
MemberName string
|
||||||
|
AssignCounts []trelloBoardAssignCount
|
||||||
|
}
|
||||||
|
|
||||||
|
type trelloRender struct {
|
||||||
|
Boards []trelloRenderBoard
|
||||||
|
|
||||||
|
// items below are generated during the render phase
|
||||||
|
SharedLabels []trelloSharedLabel
|
||||||
|
MembersByID map[string]trelloMember
|
||||||
|
MemberBoardAssign []trelloBoardAssign
|
||||||
|
}
|
||||||
|
|
38
core/section/trello/trad_template.go
Normal file
38
core/section/trello/trad_template.go
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
||||||
|
//
|
||||||
|
// This software (Documize Community Edition) is licensed under
|
||||||
|
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
||||||
|
//
|
||||||
|
// You can operate outside the AGPL restrictions by purchasing
|
||||||
|
// Documize Enterprise Edition and obtaining a commercial license
|
||||||
|
// by contacting <sales@documize.com>.
|
||||||
|
//
|
||||||
|
// https://documize.com
|
||||||
|
|
||||||
|
package trello
|
||||||
|
|
||||||
|
const tradTemplate = `
|
||||||
|
<b>Previous version</b>
|
||||||
|
|
||||||
|
{{range $b := .Boards}}
|
||||||
|
<p class="non-printable-message">Non-printable</p>
|
||||||
|
<div class="section-trello-render non-printable">
|
||||||
|
<p>There are {{ $b.CardCount }} cards across {{ $b.ListCount }} lists for board <a href="{{ $b.Board.URL }}">{{$b.Board.Name}}.</a></p>
|
||||||
|
<div class="trello-board" style="background-color: {{$b.Board.Prefs.BackgroundColor}}">
|
||||||
|
<a href="{{ $b.Board.URL }}"><div class="trello-board-title">{{$b.Board.Name}}</div></a>
|
||||||
|
{{range $data := $b.Data}}
|
||||||
|
<div class="trello-list">
|
||||||
|
<div class="trello-list-title">{{ $data.List.Name }}</div>
|
||||||
|
{{range $card := $data.Cards}}
|
||||||
|
<a href="{{ $card.URL }}">
|
||||||
|
<div class="trello-card">
|
||||||
|
{{ $card.Name }}
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
{{end}}
|
||||||
|
</div>
|
||||||
|
{{end}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{end}}
|
||||||
|
`
|
|
@ -18,10 +18,11 @@ import (
|
||||||
"html/template"
|
"html/template"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"sort"
|
||||||
|
|
||||||
"github.com/documize/community/core/api/request"
|
"github.com/documize/community/core/api/request"
|
||||||
"github.com/documize/community/core/section/provider"
|
|
||||||
"github.com/documize/community/core/log"
|
"github.com/documize/community/core/log"
|
||||||
|
"github.com/documize/community/core/section/provider"
|
||||||
)
|
)
|
||||||
|
|
||||||
var meta provider.TypeMeta
|
var meta provider.TypeMeta
|
||||||
|
@ -147,25 +148,20 @@ func (*Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http.R
|
||||||
log.IfErr(ctx.SaveSecrets(string(b)))
|
log.IfErr(ctx.SaveSecrets(string(b)))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render just sends back HMTL as-is.
|
// Render the payload using the template.
|
||||||
func (*Provider) Render(ctx *provider.Context, config, data string) string {
|
func (*Provider) Render(ctx *provider.Context, config, data string) string {
|
||||||
raw := []trelloListCards{}
|
var payload = trelloRender{}
|
||||||
payload := trelloRender{}
|
|
||||||
var c = trelloConfig{}
|
var c = trelloConfig{}
|
||||||
|
|
||||||
json.Unmarshal([]byte(data), &raw)
|
json.Unmarshal([]byte(data), &payload)
|
||||||
json.Unmarshal([]byte(config), &c)
|
json.Unmarshal([]byte(config), &c)
|
||||||
|
|
||||||
payload.Board = c.Board
|
buildPayloadAnalysis(&c, &payload)
|
||||||
payload.Data = raw
|
|
||||||
payload.ListCount = len(raw)
|
|
||||||
|
|
||||||
for _, list := range raw {
|
|
||||||
payload.CardCount += len(list.Cards)
|
|
||||||
}
|
|
||||||
|
|
||||||
t := template.New("trello")
|
t := template.New("trello")
|
||||||
t, _ = t.Parse(renderTemplate)
|
var err error
|
||||||
|
t, err = t.Parse(renderTemplate)
|
||||||
|
log.IfErr(err)
|
||||||
|
|
||||||
buffer := new(bytes.Buffer)
|
buffer := new(bytes.Buffer)
|
||||||
t.Execute(buffer, payload)
|
t.Execute(buffer, payload)
|
||||||
|
@ -178,13 +174,41 @@ func (*Provider) Refresh(ctx *provider.Context, config, data string) string {
|
||||||
var c = trelloConfig{}
|
var c = trelloConfig{}
|
||||||
json.Unmarshal([]byte(config), &c)
|
json.Unmarshal([]byte(config), &c)
|
||||||
|
|
||||||
refreshed, err := getCards(c)
|
save := trelloRender{}
|
||||||
|
save.Boards = make([]trelloRenderBoard, 0, len(c.Boards))
|
||||||
|
|
||||||
if err != nil {
|
for _, board := range c.Boards {
|
||||||
return data
|
|
||||||
|
var payload = trelloRenderBoard{}
|
||||||
|
|
||||||
|
c.Board = board
|
||||||
|
c.AppKey = request.ConfigString(meta.ConfigHandle(), "appKey")
|
||||||
|
|
||||||
|
lsts, err := getLists(c)
|
||||||
|
log.IfErr(err)
|
||||||
|
if err == nil {
|
||||||
|
c.Lists = lsts
|
||||||
|
}
|
||||||
|
|
||||||
|
for l := range c.Lists {
|
||||||
|
c.Lists[l].Included = true
|
||||||
|
}
|
||||||
|
|
||||||
|
refreshed, err := getCards(c)
|
||||||
|
log.IfErr(err)
|
||||||
|
|
||||||
|
payload.Board = c.Board
|
||||||
|
payload.Data = refreshed
|
||||||
|
payload.ListCount = len(refreshed)
|
||||||
|
|
||||||
|
for _, list := range refreshed {
|
||||||
|
payload.CardCount += len(list.Cards)
|
||||||
|
}
|
||||||
|
|
||||||
|
save.Boards = append(save.Boards, payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
j, err := json.Marshal(refreshed)
|
j, err := json.Marshal(save)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("unable to marshall trello cards", err)
|
log.Error("unable to marshall trello cards", err)
|
||||||
|
@ -197,6 +221,7 @@ func (*Provider) Refresh(ctx *provider.Context, config, data string) string {
|
||||||
// Helpers
|
// Helpers
|
||||||
func getBoards(config trelloConfig) (boards []trelloBoard, err error) {
|
func getBoards(config trelloConfig) (boards []trelloBoard, err error) {
|
||||||
req, err := http.NewRequest("GET", fmt.Sprintf("https://api.trello.com/1/members/me/boards?fields=id,name,url,closed,prefs,idOrganization&key=%s&token=%s", config.AppKey, config.Token), nil)
|
req, err := http.NewRequest("GET", fmt.Sprintf("https://api.trello.com/1/members/me/boards?fields=id,name,url,closed,prefs,idOrganization&key=%s&token=%s", config.AppKey, config.Token), nil)
|
||||||
|
log.IfErr(err)
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
res, err := client.Do(req)
|
res, err := client.Do(req)
|
||||||
|
|
||||||
|
@ -230,7 +255,9 @@ func getBoards(config trelloConfig) (boards []trelloBoard, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func getLists(config trelloConfig) (lists []trelloList, err error) {
|
func getLists(config trelloConfig) (lists []trelloList, err error) {
|
||||||
req, err := http.NewRequest("GET", fmt.Sprintf("https://api.trello.com/1/boards/%s/lists/open?key=%s&token=%s", config.Board.ID, config.AppKey, config.Token), nil)
|
uri := fmt.Sprintf("https://api.trello.com/1/boards/%s/lists/open?key=%s&token=%s", config.Board.ID, config.AppKey, config.Token)
|
||||||
|
req, err := http.NewRequest("GET", uri, nil)
|
||||||
|
log.IfErr(err)
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
res, err := client.Do(req)
|
res, err := client.Do(req)
|
||||||
|
|
||||||
|
@ -264,6 +291,7 @@ func getCards(config trelloConfig) (listCards []trelloListCards, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", fmt.Sprintf("https://api.trello.com/1/lists/%s/cards?key=%s&token=%s", list.ID, config.AppKey, config.Token), nil)
|
req, err := http.NewRequest("GET", fmt.Sprintf("https://api.trello.com/1/lists/%s/cards?key=%s&token=%s", list.ID, config.AppKey, config.Token), nil)
|
||||||
|
log.IfErr(err)
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
res, err := client.Do(req)
|
res, err := client.Do(req)
|
||||||
|
|
||||||
|
@ -294,3 +322,132 @@ func getCards(config trelloConfig) (listCards []trelloListCards, err error) {
|
||||||
|
|
||||||
return listCards, nil
|
return listCards, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func fetchMember(config *trelloConfig, render *trelloRender, memberID string) (memberInfo trelloMember) {
|
||||||
|
memberInfo.FullName = "(unknown)"
|
||||||
|
|
||||||
|
if render.MembersByID == nil {
|
||||||
|
render.MembersByID = make(map[string]trelloMember)
|
||||||
|
}
|
||||||
|
found := false
|
||||||
|
if memberInfo, found = render.MembersByID[memberID]; found {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
render.MembersByID[memberID] = memberInfo // write unknown, so that we do not retry on errors
|
||||||
|
|
||||||
|
if len(config.AppKey) == 0 {
|
||||||
|
config.AppKey = request.ConfigString(meta.ConfigHandle(), "appKey")
|
||||||
|
}
|
||||||
|
uri := fmt.Sprintf("https://api.trello.com/1/members/%s?key=%s&token=%s", memberID, config.AppKey, config.Token)
|
||||||
|
req, err := http.NewRequest("GET", uri, nil)
|
||||||
|
if err != nil {
|
||||||
|
log.IfErr(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
client := &http.Client{}
|
||||||
|
res, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
log.IfErr(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if res.StatusCode != http.StatusOK {
|
||||||
|
log.ErrorString("Trello fetch member HTTP status not OK")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
defer res.Body.Close()
|
||||||
|
|
||||||
|
dec := json.NewDecoder(res.Body)
|
||||||
|
err = dec.Decode(&memberInfo)
|
||||||
|
if err != nil {
|
||||||
|
log.IfErr(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
render.MembersByID[memberID] = memberInfo
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildPayloadAnalysis(config *trelloConfig, render *trelloRender) {
|
||||||
|
|
||||||
|
// pre-process labels
|
||||||
|
type labT struct {
|
||||||
|
color string
|
||||||
|
boards map[string]bool
|
||||||
|
}
|
||||||
|
labels := make(map[string]labT)
|
||||||
|
|
||||||
|
// pre-process member stats
|
||||||
|
memberBoardCount := make(map[string]map[string]int)
|
||||||
|
|
||||||
|
// main loop
|
||||||
|
for _, brd := range render.Boards {
|
||||||
|
for _, lst := range brd.Data {
|
||||||
|
for _, crd := range lst.Cards {
|
||||||
|
|
||||||
|
// process labels
|
||||||
|
for _, lab := range crd.Labels {
|
||||||
|
if _, exists := labels[lab.Name]; !exists {
|
||||||
|
labels[lab.Name] = labT{color: lab.Color, boards: make(map[string]bool)}
|
||||||
|
}
|
||||||
|
labels[lab.Name].boards[brd.Board.Name] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// process member stats
|
||||||
|
for _, mem := range crd.MembersID {
|
||||||
|
if _, exists := memberBoardCount[mem]; !exists {
|
||||||
|
memberBoardCount[mem] = make(map[string]int)
|
||||||
|
}
|
||||||
|
memberBoardCount[mem][brd.Board.ID]++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//post-process labels
|
||||||
|
labs := make([]string, 0, len(labels))
|
||||||
|
for lname := range labels {
|
||||||
|
labs = append(labs, lname)
|
||||||
|
}
|
||||||
|
sort.Strings(labs)
|
||||||
|
for _, lname := range labs {
|
||||||
|
thisLabel := labels[lname].boards
|
||||||
|
if l := len(thisLabel); l > 1 {
|
||||||
|
brds := make([]string, 0, l)
|
||||||
|
for bname := range thisLabel {
|
||||||
|
brds = append(brds, bname)
|
||||||
|
}
|
||||||
|
sort.Strings(brds)
|
||||||
|
render.SharedLabels = append(render.SharedLabels, trelloSharedLabel{
|
||||||
|
Name: lname, Color: labels[lname].color, Boards: brds,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//post-process member stats
|
||||||
|
mNames := make([]string, 0, len(memberBoardCount))
|
||||||
|
for mID := range memberBoardCount {
|
||||||
|
memInfo := fetchMember(config, render, mID)
|
||||||
|
mNames = append(mNames, memInfo.FullName)
|
||||||
|
}
|
||||||
|
sort.Strings(mNames)
|
||||||
|
for _, mNam := range mNames {
|
||||||
|
for mem, brdCounts := range memberBoardCount {
|
||||||
|
memInfo := fetchMember(config, render, mem)
|
||||||
|
if mNam == memInfo.FullName {
|
||||||
|
render.MemberBoardAssign = append(render.MemberBoardAssign, trelloBoardAssign{MemberName: mNam, AvatarHash: memInfo.AvatarHash})
|
||||||
|
for _, b := range render.Boards {
|
||||||
|
if count, ok := brdCounts[b.Board.ID]; ok {
|
||||||
|
render.MemberBoardAssign[len(render.MemberBoardAssign)-1].AssignCounts =
|
||||||
|
append(render.MemberBoardAssign[len(render.MemberBoardAssign)-1].AssignCounts,
|
||||||
|
trelloBoardAssignCount{BoardName: b.Board.Name, Count: count})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
goto found
|
||||||
|
}
|
||||||
|
}
|
||||||
|
found:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue