From b5569be15ec3b679d7fc6def15b15581661bb4bc Mon Sep 17 00:00:00 2001 From: Harvey Kandola Date: Sat, 14 May 2016 18:51:47 -0700 Subject: [PATCH] initial trello smart section commit --- app/app/components/section/trello/code.go | 40 ++++++ .../components/section/trello/type-editor.js | 133 ++++++++++++++++++ .../section/trello/type-renderer.js | 4 + app/app/initializers/application.js | 1 + app/app/services/session.js | 7 +- app/app/styles/base.scss | 6 + .../components/section/trello/type-editor.hbs | 109 ++++++++++++++ .../section/trello/type-renderer.hbs | 4 + app/app/utils/model.js | 2 +- app/public/crossdomain.xml | 9 +- documize/section/trello.go | 39 +++++ 11 files changed, 347 insertions(+), 7 deletions(-) create mode 100644 app/app/components/section/trello/code.go create mode 100644 app/app/components/section/trello/type-editor.js create mode 100644 app/app/components/section/trello/type-renderer.js create mode 100644 app/app/templates/components/section/trello/type-editor.hbs create mode 100644 app/app/templates/components/section/trello/type-renderer.hbs create mode 100644 documize/section/trello.go diff --git a/app/app/components/section/trello/code.go b/app/app/components/section/trello/code.go new file mode 100644 index 00000000..77b8a20f --- /dev/null +++ b/app/app/components/section/trello/code.go @@ -0,0 +1,40 @@ +package section + +import ( + "net/http" +) + +type code struct { +} + +func init() { + sectionsMap["code"] = &code{} +} + +func (*code) Meta() TypeMeta { + section := TypeMeta{} + + section.ID = "4f6f2b02-8397-483d-9bb9-eea1fef13304" + section.Title = "Code" + section.Description = "Code snippets supporting 50+ languages" + section.ContentType = "code" + section.IconFontLigature = "code" + section.Order = 9997 + + return section +} + +// Command stub. +func (*code) Command(w http.ResponseWriter, r *http.Request) { + writeEmpty(w) +} + +// Render just sends back HMTL as-is. +func (*code) Render(config, data string) string { + return data +} + +// Refresh just sends back data as-is. +func (*code) Refresh(config, data string) string { + return data +} diff --git a/app/app/components/section/trello/type-editor.js b/app/app/components/section/trello/type-editor.js new file mode 100644 index 00000000..5974177d --- /dev/null +++ b/app/app/components/section/trello/type-editor.js @@ -0,0 +1,133 @@ +/*global Trello*/ +import Ember from 'ember'; +import NotifierMixin from '../../../mixins/notifier'; +import TooltipMixin from '../../../mixins/tooltip'; + +export default Ember.Component.extend(NotifierMixin, TooltipMixin, { + sectionService: Ember.inject.service('section'), + isDirty: false, + waiting: false, + authenticated: false, + config: { + appKey: "", + board: null, + list: null, + cards: null + }, + boards: null, + lists: null, + + hasAppKey: function() { + console.log(is.not.empty(this.get('config.appKey'))); + return is.empty(this.get('config.appKey')) ? false : true; + }.property('config'), + + didReceiveAttrs() {}, + + willDestroyElement() { + this.destroyTooltips(); + }, + + getBoardLists() { + let self = this; + let board = this.get('config.board'); + + Trello.get(`boards/${board.id}/lists/open`, + function(lists) { + self.set('lists', lists); + + if (lists.length) { + self.set('config.list', lists[0]); + } + + self.getListCards(); + }); + }, + + getListCards() { + let self = this; + let list = this.get('config.list'); + + Trello.get(`lists/${list.id}/cards`, + function(cards) { + self.set('config.cards', cards); + console.log(cards); + }); + }, + + actions: { + isDirty() { + return this.get('isDirty'); + }, + + getAppKey() { + window.open("https://trello.com/app-key", "Trello App Key", ""); + }, + + getAuthToken() { + let appKey = this.get('config.appKey'); + let self = this; + + if (is.empty(appKey)) { + $("#trello-appkey").addClass("error").focus(); + return; + } + + Ember.$.getScript("https://api.trello.com/1/client.js?key=" + appKey, function() { + Trello.authorize({ + type: "popup", + name: "Documize", + scope: { + read: true, + write: false + }, + expiration: "never", + persist: true, + success: function() { + self.set('authenticated', true); + Trello.get("members/me/boards?fields=id,name,url,closed,prefs,idOrganization", + function(boards) { + self.set('boards', boards.filterBy("closed", false)); + let board = boards.length ? boards[0] : null; + self.set('config.board', board); + self.getBoardLists(); + }); + + Trello.get("members/me/organizations", + function(orgs) { + self.set('orgs', orgs); + console.log(orgs); + }); + + }, + error: function(error) { + self.showNotification("Unable to authenticate"); + console.log(error); + } + }); + }); + }, + + onBoardChange(board) { + this.set('config.board', board); + this.getBoardLists(); + }, + + onListChange(list) { + this.set('config.list', list); + this.getListCards(); + }, + + onCancel() { + this.attrs.onCancel(); + }, + + onAction(title) { + let page = this.get('page'); + let meta = this.get('meta'); + page.set('title', title); + + this.attrs.onAction(page, meta); + } + } +}); \ No newline at end of file diff --git a/app/app/components/section/trello/type-renderer.js b/app/app/components/section/trello/type-renderer.js new file mode 100644 index 00000000..926b6130 --- /dev/null +++ b/app/app/components/section/trello/type-renderer.js @@ -0,0 +1,4 @@ +import Ember from 'ember'; + +export default Ember.Component.extend({ +}); diff --git a/app/app/initializers/application.js b/app/app/initializers/application.js index 9418df90..29fb4035 100644 --- a/app/app/initializers/application.js +++ b/app/app/initializers/application.js @@ -2,6 +2,7 @@ export function initialize( /*application*/ ) { // address insecure jquery defaults (kudos: @nathanhammond) $.globalEval = function() {}; $.ajaxSetup({ + crossDomain: true, converters: { 'text script': text => text } diff --git a/app/app/services/session.js b/app/app/services/session.js index a31a5bcd..72b8f420 100644 --- a/app/app/services/session.js +++ b/app/app/services/session.js @@ -117,8 +117,13 @@ export default Ember.Service.extend({ this.storeSessionItem('token', token); this.storeSessionItem('user', JSON.stringify(user)); + let self = this; + $.ajaxPrefilter(function(options, originalOptions, jqXHR) { - jqXHR.setRequestHeader('Authorization', 'Bearer ' + token); + // We only tack on auth header for Documize API calls + if (is.startWith(options.url, self.get('appMeta.url'))) { + jqXHR.setRequestHeader('Authorization', 'Bearer ' + token); + } }); }, diff --git a/app/app/styles/base.scss b/app/app/styles/base.scss index 88c5a92a..a8466b81 100644 --- a/app/app/styles/base.scss +++ b/app/app/styles/base.scss @@ -60,6 +60,12 @@ $i: 150; $i: $i - 5; } +$i: 100; +@while $i > 0 { + .width-#{$i} { width: #{$i}#{"%"}; } + $i: $i - 5; +} + .no-outline { outline:none !important; diff --git a/app/app/templates/components/section/trello/type-editor.hbs b/app/app/templates/components/section/trello/type-editor.hbs new file mode 100644 index 00000000..81dbad32 --- /dev/null +++ b/app/app/templates/components/section/trello/type-editor.hbs @@ -0,0 +1,109 @@ + + +{{#section/base-editor document=document folder=folder page=page busy=waiting tip="Trello, yellow, mellow" isDirty=(action 'isDirty') onCancel=(action 'onCancel') onAction=(action 'onAction')}} + +
+
+
+
+
Trello Authentication
+
Provide your Trello App Key
+
+
+
Get App Key
+ {{focus-input id="trello-appkey" type="text" value=config.appKey}} +
+
Authenticate
+
+
+
+ +{{#if authenticated}} +
+
+
+
+
Trello Boards / Lists
+
Select board and list to display
+
+
+
+ +
Select board for display
+ {{ui-select id="boards-dropdown" + content=boards + action=(action 'onBoardChange') + optionValuePath="id" + optionLabelPath="name" + selection=config.board}} +
+
+
+
+ +
Select list for display
+ {{ui-select id="lists-dropdown" + content=lists + action=(action 'onListChange') + optionValuePath="id" + optionLabelPath="name" + selection=config.list}} +
+
+
+
+
{{config.board.name}}
+
+
{{config.list.name}}
+ {{#each config.cards as |card|}} +
{{card.name}}
+ {{/each}} +
+
+ +
+
+{{/if}} + +{{/section/base-editor}} \ No newline at end of file diff --git a/app/app/templates/components/section/trello/type-renderer.hbs b/app/app/templates/components/section/trello/type-renderer.hbs new file mode 100644 index 00000000..e9a277b8 --- /dev/null +++ b/app/app/templates/components/section/trello/type-renderer.hbs @@ -0,0 +1,4 @@ + + +{{{page.body}}} \ No newline at end of file diff --git a/app/app/utils/model.js b/app/app/utils/model.js index ed2adfe8..ef31b346 100644 --- a/app/app/utils/model.js +++ b/app/app/utils/model.js @@ -25,7 +25,7 @@ let AppMeta = BaseModel.extend({ init() { this.set('host', config.apiHost); this.set('namespace', config.apiNamespace); - this.set('url', [config.host, config.namespace, ""].join('/')); + this.set('url', [config.apiHost, config.apiNamespace, ""].join('/')); }, getUrl(endpoint) { diff --git a/app/public/crossdomain.xml b/app/public/crossdomain.xml index 29a035d7..511fb2d6 100644 --- a/app/public/crossdomain.xml +++ b/app/public/crossdomain.xml @@ -4,12 +4,11 @@ - + - + --> + diff --git a/documize/section/trello.go b/documize/section/trello.go new file mode 100644 index 00000000..77e35afc --- /dev/null +++ b/documize/section/trello.go @@ -0,0 +1,39 @@ +package section + +import ( + "net/http" +) + +type trello struct { +} + +func init() { + sectionsMap["trello"] = &trello{} +} + +func (*trello) Meta() TypeMeta { + section := TypeMeta{} + + section.ID = "c455a552-202e-441c-ad79-397a8152920b" + section.Title = "Trello" + section.Description = "Trello boards" + section.ContentType = "trello" + section.IconFontLigature = "dashboard" + + return section +} + +// Command stub. +func (*trello) Command(w http.ResponseWriter, r *http.Request) { + writeEmpty(w) +} + +// Render just sends back HMTL as-is. +func (*trello) Render(config, data string) string { + return data +} + +// Refresh just sends back data as-is. +func (*trello) Refresh(config, data string) string { + return data +}