1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-08-07 14:35:28 +02:00

initial trello smart section commit

This commit is contained in:
Harvey Kandola 2016-05-14 18:51:47 -07:00
parent 7c22a4a38c
commit b5569be15e
11 changed files with 347 additions and 7 deletions

View file

@ -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
}

View file

@ -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);
}
}
});

View file

@ -0,0 +1,4 @@
import Ember from 'ember';
export default Ember.Component.extend({
});

View file

@ -2,6 +2,7 @@ export function initialize( /*application*/ ) {
// address insecure jquery defaults (kudos: @nathanhammond)
$.globalEval = function() {};
$.ajaxSetup({
crossDomain: true,
converters: {
'text script': text => text
}

View file

@ -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);
}
});
},

View file

@ -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;

View file

@ -0,0 +1,109 @@
<style>
.board {
width: 100%;
padding: 10px;
}
.board-title {
font-weight: bold;
color: #fff;
font-size: 16px;
}
.list {
background-color: #e2e4e6;
padding: 10px;
border-radius: 3px;
margin-top: 10px;
max-width: 300px;
}
.list-title {
font-weight: bold;
color: #4c4c4c;
font-size: 14px;
margin-bottom: 10px;
}
.card {
color: #4c4c4c;
border-bottom: 1px solid #CDD2D4;
background-color: #fff;
border-radius: 3px;
padding: 7px 7px;
margin: 5px 0;
font-size: 14px;
font-family: "Helvetica Neue",Arial,Helvetica,sans-serif;
line-height: 18px;
overflow: hidden;
word-wrap: break-word;
}
</style>
{{#section/base-editor document=document folder=folder page=page busy=waiting tip="Trello, yellow, mellow" isDirty=(action 'isDirty') onCancel=(action 'onCancel') onAction=(action 'onAction')}}
<div class="pull-left width-45">
<div class="input-form">
<form>
<div class="heading">
<div class="title">Trello Authentication</div>
<div class="tip">Provide your Trello App Key</div>
</div>
<div class="input-control">
<div class="flat-button flat-blue" {{ action 'getAppKey' }}>Get App Key</div>
{{focus-input id="trello-appkey" type="text" value=config.appKey}}
</div>
<div class="regular-button button-blue" {{ action 'getAuthToken' }}>Authenticate</div>
</form>
</div>
</div>
{{#if authenticated}}
<div class="pull-left margin-left-40 width-45">
<div class="input-form">
<form>
<div class="heading">
<div class="title">Trello Boards / Lists</div>
<div class="tip">Select board and list to display</div>
</div>
<div class="pull-left width-45">
<div class="input-control">
<label>Board</label>
<div class="tip">Select board for display</div>
{{ui-select id="boards-dropdown"
content=boards
action=(action 'onBoardChange')
optionValuePath="id"
optionLabelPath="name"
selection=config.board}}
</div>
</div>
<div class="pull-right width-45">
<div class="input-control">
<label>List</label>
<div class="tip">Select list for display</div>
{{ui-select id="lists-dropdown"
content=lists
action=(action 'onListChange')
optionValuePath="id"
optionLabelPath="name"
selection=config.list}}
</div>
</div>
<div class="clearfix" />
<div class="board margin-top-20" style="background-color:{{config.board.prefs.backgroundColor}};">
<div class="board-title">{{config.board.name}}</div>
<div class="list">
<div class="list-title">{{config.list.name}}</div>
{{#each config.cards as |card|}}
<div class="card">{{card.name}}</div>
{{/each}}
</div>
</div>
</form>
</div>
</div>
{{/if}}
{{/section/base-editor}}

View file

@ -0,0 +1,4 @@
<style>
</style>
{{{page.body}}}

View file

@ -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) {

View file

@ -4,12 +4,11 @@
<!-- Read this: www.adobe.com/devnet/articles/crossdomain_policy_file_spec.html -->
<!-- Most restrictive policy: -->
<site-control permitted-cross-domain-policies="none"/>
<!--<site-control permitted-cross-domain-policies="none"/>-->
<!-- Least restrictive policy: -->
<!--
<site-control permitted-cross-domain-policies="all"/>
<!--<site-control permitted-cross-domain-policies="all"/>
<allow-access-from domain="*" to-ports="*" secure="false"/>
<allow-http-request-headers-from domain="*" headers="*" secure="false"/>
-->
<allow-http-request-headers-from domain="*" headers="*" secure="false"/>-->
</cross-domain-policy>

View file

@ -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
}