From 1e37c68d9931f05959f970a3de85f9113b4af917 Mon Sep 17 00:00:00 2001 From: Elliott Stoneham Date: Fri, 9 Sep 2016 16:28:51 +0100 Subject: [PATCH] select which boards and date since, individual board not working yet --- .../components/section/trello/type-editor.js | 18 +++- .../components/section/trello/type-editor.hbs | 94 ++++++++++++------- core/section/trello/graphs_template.go | 24 +++-- core/section/trello/master_template.go | 2 +- core/section/trello/model.go | 20 ++-- core/section/trello/trad_template.go | 3 +- core/section/trello/trello.go | 92 +++++++++++------- 7 files changed, 166 insertions(+), 87 deletions(-) diff --git a/app/app/components/section/trello/type-editor.js b/app/app/components/section/trello/type-editor.js index 26123f97..c9a08b60 100644 --- a/app/app/components/section/trello/type-editor.js +++ b/app/app/components/section/trello/type-editor.js @@ -50,7 +50,8 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin, token: "", user: null, board: null, - lists: [] + lists: [], + boards: [] }; } @@ -101,6 +102,12 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin, this.set('noBoards', false); + if (is.undefined(self.get('initDateTimePicker'))) { + $.datetimepicker.setLocale('en'); + $('#trello-since').datetimepicker(); + self.set('initDateTimePicker', "Done"); + } + if (is.null(board) || is.undefined(board)) { if (boards.length) { board = boards[0]; @@ -150,6 +157,15 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin, } }, + onBoardCheckbox(id) { + let boards = this.get('config.boards'); + let board = boards.findBy('id', id); + + if (board !== null) { + Ember.set(board, 'included', !board.included); + } + }, + auth() { if (this.get('appKey') === "") { $("#trello-appkey").addClass('error').focus(); diff --git a/app/app/templates/components/section/trello/type-editor.hbs b/app/app/templates/components/section/trello/type-editor.hbs index 48e9939a..abe80c8a 100644 --- a/app/app/templates/components/section/trello/type-editor.hbs +++ b/app/app/templates/components/section/trello/type-editor.hbs @@ -3,45 +3,71 @@ isDirty=(action 'isDirty') onCancel=(action 'onCancel') onAction=(action 'onAction')}} {{#if authenticated}} - -
-
-
-
Select Board & Lists
-
Choose lists to include from board
+ {{#if noBoards}} +
+
You have no team boards to share - personal boards are never shown.
- {{#if noBoards}} -
-
You have no team boards to share - personal boards are never shown.
-
- {{else}} -
- -
Select board
- {{ui-select id="boards-dropdown" content=boards action=(action 'onBoardChange') optionValuePath="id" optionLabelPath="name" selection=config.board}} + {{else}} + +
+
+
+
Select Board & Lists
+
Choose lists to include from board
- -
Select lists to include
-
-
{{config.board.name}}
- {{#each config.lists as |list|}} -
- {{#if list.included}} - check_box - {{else}} - check_box_outline_blank - {{/if}} - {{list.name}} -
- {{/each}} -
+ + {{input id="trello-since" value=config.since type="text" }}
+
+ +
+ +
All boards are selectd by default
+
+ {{#each config.boards as |board|}} +
+ {{#if board.included}} + check_box + {{else}} + check_box_outline_blank + {{/if}} + {{board.name}} +
+ {{/each}} +
+
+
+
+
+
+
+
+ +
Select board
+ {{ui-select id="boards-dropdown" content=boards action=(action 'onBoardChange') optionValuePath="id" optionLabelPath="name" selection=config.board}} +
+
+ +
Select lists to include
+
+
{{config.board.name}}
+ {{#each config.lists as |list|}} +
+ {{#if list.included}} + check_box + {{else}} + check_box_outline_blank + {{/if}} + {{list.name}} +
+ {{/each}} +
+
- {{/if}} -
-
- +
+ {{/if}} + {{else}}
diff --git a/core/section/trello/graphs_template.go b/core/section/trello/graphs_template.go index 770e9b98..3bb41687 100644 --- a/core/section/trello/graphs_template.go +++ b/core/section/trello/graphs_template.go @@ -12,17 +12,21 @@ package trello const graphsTemplate = ` -Single Boards (graphs)
-{{range $b := .Boards}} -
-

There are {{ $b.CardCount }} cards across {{ $b.ListCount }} lists for board {{$b.Board.Name}}.

+{{if false}} + + Single Boards (graphs)
+ {{range $b := .Boards}}
- {{range $data := $b.Data}} -
- {{ $data.List.Name }} -
- {{end}} +

There are {{ $b.CardCount }} cards across {{ $b.ListCount }} lists for board {{$b.Board.Name}}.

+
+ {{range $data := $b.Data}} +
+ {{ $data.List.Name }} +
+ {{end}} +
-
+ {{end}} + {{end}} ` diff --git a/core/section/trello/master_template.go b/core/section/trello/master_template.go index dbd39848..0faa6b70 100644 --- a/core/section/trello/master_template.go +++ b/core/section/trello/master_template.go @@ -15,7 +15,7 @@ const renderTemplate = `

Header for Trello Multi-Board Test (in master_template.go)

` + labelsTemplate + boardsTemplate + - // graphsTemplate + + graphsTemplate + membersTemplate + archiveTemplate + tradTemplate + diff --git a/core/section/trello/model.go b/core/section/trello/model.go index 117e7154..6af968f6 100644 --- a/core/section/trello/model.go +++ b/core/section/trello/model.go @@ -11,18 +11,23 @@ package trello -import "strings" +import ( + "strings" + "time" +) type secrets struct { Token string `json:"token"` } type trelloConfig struct { - AppKey string `json:"appKey"` - Token string `json:"token"` - Board trelloBoard `json:"board"` // TODO review - Lists []trelloList `json:"lists"` // TODO review - Boards []trelloBoard `json:"boards"` + AppKey string `json:"appKey"` + Token string `json:"token"` + Board trelloBoard `json:"board"` + Lists []trelloList `json:"lists"` + Boards []trelloBoard `json:"boards"` + Since string `json:"since,omitempty"` + SincePtr *time.Time `json:"-"` } func (c *trelloConfig) Clean() { @@ -162,6 +167,7 @@ type trelloBoard struct { Blue string `json:"blue"` Purple string `json:"purple"` } `json:"labelNames"` + Included bool `json:"included"` // indicates whether we display this board } type trelloBoardBackground struct { @@ -258,6 +264,8 @@ type trelloBoardAssign struct { } type trelloRender struct { + Config trelloConfig + Boards []trelloRenderBoard Since string diff --git a/core/section/trello/trad_template.go b/core/section/trello/trad_template.go index 59fcc6d1..eafdf68b 100644 --- a/core/section/trello/trad_template.go +++ b/core/section/trello/trad_template.go @@ -12,8 +12,7 @@ package trello const tradTemplate = ` -{{if eq 1 (len .Boards)}} -

#Board Name

+{{if false}} {{range $b := .Boards}}

Non-printable

diff --git a/core/section/trello/trello.go b/core/section/trello/trello.go index 22d3ba3d..36b6a142 100644 --- a/core/section/trello/trello.go +++ b/core/section/trello/trello.go @@ -183,45 +183,67 @@ func (*Provider) Render(ctx *provider.Context, config, data string) string { // Refresh just sends back data as-is. func (*Provider) Refresh(ctx *provider.Context, config, data string) string { var c = trelloConfig{} - json.Unmarshal([]byte(config), &c) + log.IfErr(json.Unmarshal([]byte(config), &c)) save := trelloRender{} + save.Config = c save.Boards = make([]trelloRenderBoard, 0, len(c.Boards)) - for _, board := range c.Boards { - - 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 + if len(c.Since) >= len("yyyy/mm/dd hh:ss") { + var since time.Time + tt := []byte("yyyy-mm-ddThh:mm:00Z") + for _, i := range []int{0, 1, 2, 3, 5, 6, 8, 9, 11, 12, 14, 15} { + tt[i] = c.Since[i] } - - for l := range c.Lists { - c.Lists[l].Included = true + err := since.UnmarshalText(tt) + if err != nil { + log.ErrorString("Date unmarshall '" + c.Since + "'->'" + string(tt) + "' error: " + err.Error()) + } else { + c.SincePtr = &since } - - 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) - } - - payload.Actions, payload.Archived = fetchBoardActions(&c, &save, board.ID, nil) // TODO pass in date - - save.Boards = append(save.Boards, payload) } + dateMessage := "" + if c.SincePtr == nil { + dateMessage = " (the last 7 days)" + since := time.Now().AddDate(0, 0, -7) + c.SincePtr = &since + c.Since = (*c.SincePtr).Format("2006/01/02 ") + } + save.Since = (*c.SincePtr).Format("January 2, 2006") + dateMessage - save.Since = "# 1 Aug 2016 #" + for _, board := range c.Boards { + if board.Included { + 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) + } + + payload.Actions, payload.Archived = fetchBoardActions(&c, &save, board.ID, c.Since) + + save.Boards = append(save.Boards, payload) + } + } j, err := json.Marshal(save) @@ -268,6 +290,10 @@ func getBoards(config trelloConfig) (boards []trelloBoard, err error) { return nil, err } + for bx := range boards { + boards[bx].Included = true // include boards by default + } + return boards, nil } @@ -387,9 +413,9 @@ func fetchMember(config *trelloConfig, render *trelloRender, memberID string) (m return } -func fetchBoardActions(config *trelloConfig, render *trelloRender, boardID string, since *time.Time) (actions []trelloAction, archived []trelloCard) { +func fetchBoardActions(config *trelloConfig, render *trelloRender, boardID string, since string) (actions []trelloAction, archived []trelloCard) { - sinceString := "2016-08-01" // TODO + sinceString := since[:10] if len(config.AppKey) == 0 { config.AppKey = request.ConfigString(meta.ConfigHandle(), "appKey")