mirror of
https://github.com/documize/community.git
synced 2025-07-27 17:19:42 +02:00
Add OrgName to board
This commit is contained in:
parent
93a11200b4
commit
e57ecb4b16
3 changed files with 79 additions and 23 deletions
|
@ -25,7 +25,7 @@ const labelsTemplate = `
|
||||||
<span class="trello-label" style="background-color: {{ $l.Color }}">{{ $l.Name }} ({{len $l.Boards}})</span>
|
<span class="trello-label" style="background-color: {{ $l.Color }}">{{ $l.Name }} ({{len $l.Boards}})</span>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{{range $idx, $brd := $l.Boards}}{{if gt $idx 0}}, {{end}}{{ $brd }}{{end}}.
|
{{range $idx, $brd := $l.Boards}}{{if gt $idx 0}}, {{end}}<a class="link" href="{{$brd.URL}}">{{$brd.OrgName}}::{{$brd.Name}}</a>{{end}}.
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
package trello
|
package trello
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"html/template"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
@ -29,6 +28,8 @@ type trelloConfig struct {
|
||||||
Boards []trelloBoard `json:"boards"`
|
Boards []trelloBoard `json:"boards"`
|
||||||
Since string `json:"since,omitempty"`
|
Since string `json:"since,omitempty"`
|
||||||
SincePtr *time.Time `json:"-"`
|
SincePtr *time.Time `json:"-"`
|
||||||
|
|
||||||
|
OrgByID map[string]trelloOrganization `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *trelloConfig) Clean() {
|
func (c *trelloConfig) Clean() {
|
||||||
|
@ -38,52 +39,65 @@ func (c *trelloConfig) Clean() {
|
||||||
|
|
||||||
// Trello objects based upon https://github.com/VojtechVitek/go-trello
|
// Trello objects based upon https://github.com/VojtechVitek/go-trello
|
||||||
|
|
||||||
|
type trelloOrganization struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
DisplayName string `json:"displayName"`
|
||||||
|
Desc string `json:"desc"`
|
||||||
|
DescData string `json:"descData"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
Website string `json:"website"`
|
||||||
|
LogoHash string `json:"logoHash"`
|
||||||
|
Products []string `json:"products"`
|
||||||
|
PowerUps []string `json:"powerUps"`
|
||||||
|
}
|
||||||
|
|
||||||
type trelloAction struct {
|
type trelloAction struct {
|
||||||
Id string `json:"id"`
|
ID string `json:"id"`
|
||||||
IdMemberCreator string `json:"idMemberCreator"`
|
IDMemberCreator string `json:"idMemberCreator"`
|
||||||
Data struct {
|
Data struct {
|
||||||
DateLastEdited string `json:"dateLastEdited"`
|
DateLastEdited string `json:"dateLastEdited"`
|
||||||
ListBefore struct {
|
ListBefore struct {
|
||||||
Id string `json:"id"`
|
ID string `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
} `json:"listBefore"`
|
} `json:"listBefore"`
|
||||||
ListAfter struct {
|
ListAfter struct {
|
||||||
Id string `json:"id"`
|
ID string `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
} `json:"listAfter"`
|
} `json:"listAfter"`
|
||||||
CheckItem struct {
|
CheckItem struct {
|
||||||
Id string `json:"id"`
|
ID string `json:"id"`
|
||||||
State string `json:"state"`
|
State string `json:"state"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
} `json:"checkItem"`
|
} `json:"checkItem"`
|
||||||
CheckList struct {
|
CheckList struct {
|
||||||
Id string `json:"id"`
|
ID string `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
} `json:"checklist"`
|
} `json:"checklist"`
|
||||||
List struct {
|
List struct {
|
||||||
Id string `json:"id"`
|
ID string `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
} `json:"list"`
|
} `json:"list"`
|
||||||
TextData struct {
|
TextData struct {
|
||||||
Emoji struct{} `json:"emoji"`
|
Emoji struct{} `json:"emoji"`
|
||||||
} `json:"textData"`
|
} `json:"textData"`
|
||||||
Board struct {
|
Board struct {
|
||||||
Id string `json:"id"`
|
ID string `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
ShortLink string `json:"shortLink"`
|
ShortLink string `json:"shortLink"`
|
||||||
} `json:"board"`
|
} `json:"board"`
|
||||||
Card struct {
|
Card struct {
|
||||||
Id string `json:"id"`
|
ID string `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
ShortLink string `json:"shortLink"`
|
ShortLink string `json:"shortLink"`
|
||||||
IdShort int `json:"idShort"`
|
IDShort int `json:"idShort"`
|
||||||
} `json:"card"`
|
} `json:"card"`
|
||||||
Text string `json:"text"`
|
Text string `json:"text"`
|
||||||
} `json:"data"`
|
} `json:"data"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Date string `json:"date"`
|
Date string `json:"date"`
|
||||||
MemberCreator struct {
|
MemberCreator struct {
|
||||||
Id string `json:"id"`
|
ID string `json:"id"`
|
||||||
AvatarHash string `json:"avatarHash"`
|
AvatarHash string `json:"avatarHash"`
|
||||||
FullName string `json:"fullName"`
|
FullName string `json:"fullName"`
|
||||||
Initials string `json:"initials"`
|
Initials string `json:"initials"`
|
||||||
|
@ -133,6 +147,7 @@ type trelloBoard struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Closed bool `json:"closed"`
|
Closed bool `json:"closed"`
|
||||||
OrganizationID string `json:"idOrganization"`
|
OrganizationID string `json:"idOrganization"`
|
||||||
|
OrgName string `json:"orgName"`
|
||||||
Pinned bool `json:"pinned"`
|
Pinned bool `json:"pinned"`
|
||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
ShortURL string `json:"shortUrl"`
|
ShortURL string `json:"shortUrl"`
|
||||||
|
@ -250,7 +265,7 @@ type trelloRenderBoard struct {
|
||||||
type trelloSharedLabel struct {
|
type trelloSharedLabel struct {
|
||||||
Name string
|
Name string
|
||||||
Color string
|
Color string
|
||||||
Boards []template.HTML
|
Boards []trelloBoard
|
||||||
}
|
}
|
||||||
|
|
||||||
type trelloBoardAssignCount struct {
|
type trelloBoardAssignCount struct {
|
||||||
|
|
|
@ -101,7 +101,7 @@ func (*Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http.R
|
||||||
provider.WriteJSON(w, render)
|
provider.WriteJSON(w, render)
|
||||||
|
|
||||||
case "boards":
|
case "boards":
|
||||||
render, err := getBoards(config)
|
render, err := getBoards(&config)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.IfErr(err)
|
log.IfErr(err)
|
||||||
|
@ -267,7 +267,44 @@ func (*Provider) Refresh(ctx *provider.Context, config, data string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helpers
|
// Helpers
|
||||||
func getBoards(config trelloConfig) (boards []trelloBoard, err error) {
|
|
||||||
|
func getOrg(config *trelloConfig, orgID string) (*trelloOrganization, error) {
|
||||||
|
if config.OrgByID == nil {
|
||||||
|
config.OrgByID = make(map[string]trelloOrganization)
|
||||||
|
}
|
||||||
|
if org, found := config.OrgByID[orgID]; found {
|
||||||
|
return &org, nil
|
||||||
|
}
|
||||||
|
req, err := http.NewRequest("GET", fmt.Sprintf(
|
||||||
|
"https://api.trello.com/1/organizations/%s?fields=name,desc&key=%s&token=%s",
|
||||||
|
orgID, config.AppKey, config.Token), nil)
|
||||||
|
log.IfErr(err)
|
||||||
|
client := &http.Client{}
|
||||||
|
res, err := client.Do(req)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if res.StatusCode != http.StatusOK {
|
||||||
|
return nil, fmt.Errorf("error: HTTP status code %d", res.StatusCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
b := trelloOrganization{}
|
||||||
|
|
||||||
|
defer res.Body.Close()
|
||||||
|
dec := json.NewDecoder(res.Body)
|
||||||
|
err = dec.Decode(&b)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
config.OrgByID[orgID] = b
|
||||||
|
return &b, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func getBoards(config *trelloConfig) (boards []trelloBoard, err error) {
|
||||||
req, err := http.NewRequest("GET", fmt.Sprintf(
|
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",
|
"https://api.trello.com/1/members/me/boards?fields=id,name,url,closed,prefs,idOrganization&key=%s&token=%s",
|
||||||
config.AppKey, config.Token), nil)
|
config.AppKey, config.Token), nil)
|
||||||
|
@ -296,6 +333,11 @@ func getBoards(config trelloConfig) (boards []trelloBoard, err error) {
|
||||||
// we only show open, team boards (not personal)
|
// we only show open, team boards (not personal)
|
||||||
for _, b := range b {
|
for _, b := range b {
|
||||||
if !b.Closed && len(b.OrganizationID) > 0 {
|
if !b.Closed && len(b.OrganizationID) > 0 {
|
||||||
|
if o, e := getOrg(config, b.OrganizationID); e == nil {
|
||||||
|
b.OrgName = o.Name
|
||||||
|
} else {
|
||||||
|
log.Error("failed to get organisation infomation", e)
|
||||||
|
}
|
||||||
boards = append(boards, b)
|
boards = append(boards, b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -521,7 +563,7 @@ func buildPayloadAnalysis(config *trelloConfig, render *trelloRender) {
|
||||||
// pre-process labels
|
// pre-process labels
|
||||||
type labT struct {
|
type labT struct {
|
||||||
color string
|
color string
|
||||||
boards map[string]bool
|
boards map[string]trelloBoard
|
||||||
}
|
}
|
||||||
labels := make(map[string]labT)
|
labels := make(map[string]labT)
|
||||||
|
|
||||||
|
@ -541,10 +583,9 @@ func buildPayloadAnalysis(config *trelloConfig, render *trelloRender) {
|
||||||
// process labels
|
// process labels
|
||||||
for _, lab := range crd.Labels {
|
for _, lab := range crd.Labels {
|
||||||
if _, exists := labels[lab.Name]; !exists {
|
if _, exists := labels[lab.Name]; !exists {
|
||||||
labels[lab.Name] = labT{color: lab.Color, boards: make(map[string]bool)}
|
labels[lab.Name] = labT{color: lab.Color, boards: make(map[string]trelloBoard)}
|
||||||
}
|
}
|
||||||
labels[lab.Name].boards[fmt.Sprintf(`<a class="link" href="%s">%s</a>`,
|
labels[lab.Name].boards[brd.Board.URL+"::"+brd.Board.Name] = brd.Board
|
||||||
brd.Board.URL, brd.Board.Name)] = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// process member stats
|
// process member stats
|
||||||
|
@ -589,12 +630,12 @@ func buildPayloadAnalysis(config *trelloConfig, render *trelloRender) {
|
||||||
brds = append(brds, bname)
|
brds = append(brds, bname)
|
||||||
}
|
}
|
||||||
sort.Strings(brds)
|
sort.Strings(brds)
|
||||||
htm := []template.HTML{}
|
lbrds := []trelloBoard{}
|
||||||
for _, h := range brds {
|
for _, h := range brds {
|
||||||
htm = append(htm, template.HTML(h))
|
lbrds = append(lbrds, labels[lname].boards[h])
|
||||||
}
|
}
|
||||||
render.SharedLabels = append(render.SharedLabels, trelloSharedLabel{
|
render.SharedLabels = append(render.SharedLabels, trelloSharedLabel{
|
||||||
Name: lname, Color: labels[lname].color, Boards: htm,
|
Name: lname, Color: labels[lname].color, Boards: lbrds,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue