diff --git a/app/app/components/section/trello/type-editor.js b/app/app/components/section/trello/type-editor.js index b5297996..ba71ad3b 100644 --- a/app/app/components/section/trello/type-editor.js +++ b/app/app/components/section/trello/type-editor.js @@ -28,12 +28,14 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin, try { config = JSON.parse(this.get('meta.config')); - } catch (e) {} + } + catch (e) {} if (is.empty(config)) { config = { appKey: "", token: "", + user: null, board: null, lists: [] }; @@ -41,10 +43,7 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin, this.set('config', config); - if (this.get('config.appKey') !== "" && - this.get('config.token') !== "") { - console.log(this.get('isReadonly')); - console.log(this.get('isMine')); + if (this.get('config.appKey') !== "" && this.get('config.token') !== "") { this.send('auth'); } }, @@ -59,20 +58,21 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin, let self = this; let boards = this.get('boards'); let board = this.get('config.board'); - let page = this.get('page'); + let page = this.get('page'); if (is.null(board) || is.undefined(board)) { if (boards.length) { board = boards[0]; this.set('config.board', board); } - } else { + } + else { this.set('config.board', boards.findBy('id', board.id)); } - this.get('sectionService').fetch(page, "lists", self.get('config')) - .then(function(lists) { - let savedLists = self.get('config.lists'); + this.get('sectionService').fetch(page, "lists", self.get('config')) + .then(function(lists) { + let savedLists = self.get('config.lists'); if (savedLists === null) { savedLists = []; } @@ -88,39 +88,12 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin, self.set('config.lists', lists); self.set('busy', false); - }, function(error) { //jshint ignore: line - self.set('busy', false); + }, function(error) { //jshint ignore: line + self.set('busy', false); self.set('authenticated', false); self.showNotification("Unable to fetch board lists"); console.log(error); - }); - - - // Trello.get(`boards/${board.id}/lists/open?fields=id,name,url`, - // function(lists) { - // let savedLists = self.get('config.lists'); - // if (savedLists === null) { - // savedLists = []; - // } - // - // lists.forEach(function(list) { - // let saved = savedLists.findBy("id", list.id); - // let included = true; - // if (is.not.undefined(saved)) { - // included = saved.included; - // } - // list.included = included; - // }); - // - // self.set('config.lists', lists); - // self.set('busy', false); - // }, - // function(error) { - // self.set('busy', false); - // self.set('authenticated', false); - // self.showNotification("Unable to fetch board lists"); - // console.log(error); - // }); + }); }, actions: { @@ -155,7 +128,7 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin, } let self = this; - let page = this.get('page'); + let page = this.get('page'); self.set('busy', true); @@ -175,31 +148,23 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin, self.set('config.token', Trello.token()); self.set('busy', true); - self.get('sectionService').fetch(page, "boards", self.get('config')) - .then(function(boards) { - self.set('busy', false); - self.set('boards', boards.filterBy("closed", false)); + Trello.members.get("me", function(user) { + self.set('config.user', user); + }, function(error) { + console.log(error); + }); + + self.get('sectionService').fetch(page, "boards", self.get('config')) + .then(function(boards) { + self.set('busy', false); + self.set('boards', boards); self.getBoardLists(); - }, function(error) { //jshint ignore: line - self.set('busy', false); + }, function(error) { //jshint ignore: line + self.set('busy', false); self.set('authenticated', false); self.showNotification("Unable to fetch boards"); console.log(error); - }); - - // Trello.get("members/me/boards?fields=id,name,url,closed,prefs,idOrganization", - // function(boards) { - // self.set('busy', false); - // self.set('boards', boards.filterBy("closed", false)); - // self.getBoardLists(); - // }, - // function(error) { - // self.set('busy', false); - // self.set('authenticated', false); - // self.showNotification("Unable to fetch boards"); - // console.log(error); - // } - // ); + }); }, error: function(error) { self.set('busy', false); @@ -246,7 +211,5 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin, } }); -// no private boards? -// show who owner is -- logout // app key really required? // pass/save global section config? diff --git a/app/app/mixins/section.js b/app/app/mixins/section.js index e40a6209..0b2b1725 100644 --- a/app/app/mixins/section.js +++ b/app/app/mixins/section.js @@ -1,11 +1,11 @@ // Copyright 2016 Documize Inc. . All rights reserved. // -// This software (Documize Community Edition) is licensed under +// 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 . +// by contacting . // // https://documize.com @@ -13,14 +13,15 @@ import Ember from 'ember'; export default Ember.Mixin.create({ isReadonly: function() { - if (this.get('page.userId') !== this.session.user.id) { - return "readonly"; - } else { + if (this.get('page.userId') === this.session.user.id) { return undefined; } + else { + return "readonly"; + } }.property('page'), isMine: function() { - return this.get('page.userId') !== this.session.user.id; + return this.get('page.userId') === this.session.user.id; }.property('page') -}); \ No newline at end of file +}); diff --git a/app/app/templates/components/section/trello/type-editor.hbs b/app/app/templates/components/section/trello/type-editor.hbs index 1a1602a4..998a1e30 100644 --- a/app/app/templates/components/section/trello/type-editor.hbs +++ b/app/app/templates/components/section/trello/type-editor.hbs @@ -1,100 +1,95 @@ - -{{#section/base-editor document=document folder=folder page=page busy=busy tip="Trello is the visual way to manage your projects and organize anything (https://trello.com)" isDirty=(action 'isDirty') onCancel=(action 'onCancel') onAction=(action 'onAction')}} +{{#section/base-editor document=document folder=folder page=page busy=busy tip="Trello is the visual way to manage your projects and organize anything (https://trello.com)" isDirty=(action 'isDirty') onCancel=(action 'onCancel') onAction=(action + 'onAction')}} -
-
-
-
-
Authentication
-
Provide Trello App Key and then authenticate
-
-
- -
Use plain old button below to grab the magic key -- you might need to log into Trello
- {{focus-input id="trello-appkey" type="password" value=config.appKey}} -
- {{#if authenticated}} -
Logout
- {{else}} -
Get App Key
-
-
Authenticate
- {{/if}} - +
+
+
+
+
Authentication
+
Provide Trello App Key and then authenticate
+
+
+ +
Use plain old button below to grab the magic key -- you might need to log into Trello
+ {{focus-input id="trello-appkey" type="password" value=config.appKey readonly=isReadonly}} +
+ {{#if authenticated}} +
Logout {{config.user.fullName}}
+ {{else}} +
Get App Key
+
+
Authenticate
+ {{/if}} + +
-
-{{#if authenticated}} -
-
-
-
Select Board & Lists
-
Choose lists to include from board
-
-
- -
Select board
- {{ui-select id="boards-dropdown" - content=boards - action=(action 'onBoardChange') - optionValuePath="id" - optionLabelPath="name" - selection=config.board - readonly=isReadonly}} -
-
- -
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}} + {{#if authenticated}} +
+
+
+
Select Board & Lists
+
Choose lists to include from board
+
+
+ +
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}} +
- {{/each}} -
+
-
-
-{{/if}} - -{{/section/base-editor}} \ No newline at end of file + {{/if}} + +{{/section/base-editor}} diff --git a/documize/section/trello.go b/documize/section/trello.go index aae7cf64..e864ab70 100644 --- a/documize/section/trello.go +++ b/documize/section/trello.go @@ -176,10 +176,18 @@ func getBoards(config trelloConfig) (boards []trelloBoard, err error) { return nil, fmt.Errorf("error: HTTP status code %d", res.StatusCode) } - defer res.Body.Close() + b := []trelloBoard{} + defer res.Body.Close() dec := json.NewDecoder(res.Body) - err = dec.Decode(&boards) + err = dec.Decode(&b) + + // we only show open, team boards (not personal) + for _, b := range b { + if !b.Closed && len(b.OrganizationID) > 0 { + boards = append(boards, b) + } + } if err != nil { fmt.Println(err) @@ -267,6 +275,44 @@ func (c *trelloConfig) Clean() { c.Token = strings.TrimSpace(c.Token) } +// Trello objects based upon https://github.com/VojtechVitek/go-trello +type trelloMember struct { + ID string `json:"id"` + AvatarHash string `json:"avatarHash"` + Bio string `json:"bio"` + BioData struct { + Emoji interface{} `json:"emoji,omitempty"` + } `json:"bioData"` + Confirmed bool `json:"confirmed"` + FullName string `json:"fullName"` + PremOrgsAdminID []string `json:"idPremOrgsAdmin"` + Initials string `json:"initials"` + MemberType string `json:"memberType"` + Products []int `json:"products"` + Status string `json:"status"` + URL string `json:"url"` + Username string `json:"username"` + AvatarSource string `json:"avatarSource"` + Email string `json:"email"` + GravatarHash string `json:"gravatarHash"` + BoardsID []string `json:"idBoards"` + BoardsPinnedID []string `json:"idBoardsPinned"` + OrganizationsID []string `json:"idOrganizations"` + LoginTypes []string `json:"loginTypes"` + NewEmail string `json:"newEmail"` + OneTimeMessagesDismissed []string `json:"oneTimeMessagesDismissed"` + Prefs struct { + SendSummaries bool `json:"sendSummaries"` + MinutesBetweenSummaries int `json:"minutesBetweenSummaries"` + MinutesBeforeDeadlineToNotify int `json:"minutesBeforeDeadlineToNotify"` + ColorBlind bool `json:"colorBlind"` + Locale string `json:"locale"` + } `json:"prefs"` + Trophies []string `json:"trophies"` + UploadedAvatarHash string `json:"uploadedAvatarHash"` + PremiumFeatures []string `json:"premiumFeatures"` +} + type trelloBoard struct { ID string `json:"id"` Name string `json:"name"`