Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trello in project #381

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added add card functionality to teem
  • Loading branch information
Kumar Shubham committed Aug 24, 2017
commit d61125dde6a295bcd41ca99044bbaee503447d97
15 changes: 6 additions & 9 deletions src/js/controllers/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 57,6 @@ angular.module('Teem')
.when('/trello/get/',{
controller: 'TrelloGetController',
template: '<h1>Redirecting ....</h1>'
})
.when('/trello/auth',{
template: '<h1>Redirecting to trello</h1>',
controller: 'TrelloAuthController'
});
}])
.controller('FetchProject', [
Expand Down Expand Up @@ -97,9 93,9 @@ angular.module('Teem')
}])
.controller('ProjectCtrl', [
'SessionSvc', '$scope', '$rootScope', '$location', '$route', '$timeout', 'swellRT', '$filter',
'SharedState', 'ProjectsSvc', 'Loading', '$window', 'CommunitiesSvc', 'User', 'Selector', '$http', '$translate',
'SharedState', 'ProjectsSvc', 'Loading', '$window', 'CommunitiesSvc', 'User', 'Selector', '$http', '$translate','trelloSvc',
function (SessionSvc, $scope, $rootScope, $location, $route, $timeout, swellRT, $filter,
SharedState, ProjectsSvc, Loading, $window, CommunitiesSvc, User, Selector, $http, $translate) {
SharedState, ProjectsSvc, Loading, $window, CommunitiesSvc, User, Selector, $http, $translate, trelloSvc) {

// Prevent users from forging the form parameter
// and set the form order
Expand Down Expand Up @@ -425,6 421,10 @@ angular.module('Teem')

};

$scope.getToken = function () {
trelloSvc.getToken();
};

$scope.archiveProject = function() {
// TODO
};
Expand All @@ -437,9 437,6 @@ angular.module('Teem')
ProjectsSvc.updateTrello();
});
}])
.controller('TrelloAuthController',['trelloSvc',function(trelloSvc){
trelloSvc.getToken();
}])
.directive(
'hideTabs',
function (SharedState, $timeout) {
Expand Down
43 changes: 17 additions & 26 deletions src/js/services/projectsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,38 326,18 @@ angular.module('Teem')
need.time = (new Date()).toJSON();
need.completed = 'false';

this.needs.push(need);
this.setTimestampAccess('needs', true);

if (this.trello) {
console.log('hello');
if (this.trello.boardId) {
if (!this.trello.listId){
console.log('No list Id found for the current board');
}
trelloSvc.addNewCard(this.trello, need);
}
else {
trelloSvc.createTrelloBoard(this, need).then((BoardData) => {
this.trello.boardId = BoardData.id;
trelloSvc.createNewList(this.trello)
.then((listdata) => {
trelloSvc.addNewCard(this.trello).then((cardData) => {
console.log(cardData);
})
.catch(err => console.log(err))
})
if (this.trello.boardId && this.trello.listId) {
trelloSvc.addNewCard(this.trello, need).
then((cardData) => {
need.trelloId = cardData.id;
this.needs.push(need);
})
.catch(err => console.log(err));
})
.catch((err) => {
console.log(err);
});
}
}
else {
console.log('creating a new trello thing');
trelloSvc.getToken();
}

return need;
}
Expand Down Expand Up @@ -630,6 610,17 @@ angular.module('Teem')
model.trello = {};
model.trello.token = localStorage.getItem('trelloTeemToken');
localStorage.removeItem('trelloTeemToken');
trelloSvc.createTrelloBoard(model).
then((BoardData) => {
model.trello.boardId = BoardData.id;
trelloSvc.registerWebhook(model.trello);
trelloSvc.createNewList(model.trello).
then((listData) => {
model.trello.listId = listData.id;
})
.catch(err => console.log(err));
})
.catch(err => console.error(err));
});
}

Expand Down
47 changes: 31 additions & 16 deletions src/js/services/trelloService.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 4,8 @@
angular
.module('Teem')
.factory('trelloSvc', trelloSvc);
trelloSvc.$inject = ['$http', '$location', '$window', '$rootScope', '$timeout', '$q'];
function trelloSvc($http, $location, $window, $rootScope, $timeout, $q) {
const AUTH_ROUTE = 'https://trello.com/1/authorize';
trelloSvc.$inject = ['$http', '$location', '$window', '$q'];
function trelloSvc($http, $location, $window, $q) {

function getToken() {
localStorage.setItem('projectUrl', $location.path());
Expand All @@ -18,16 17,16 @@
console.log(urlString);
}

function createTrelloBoard(prObj, need) {
function createTrelloBoard(prObj) {
let deferred = $q.defer();
if (!prObj.trello.token) {
getToken();
deferred.resolve();
return deferred.promise;
}
const BoardApiURL = `https://api.trello.com/1/boards/?name=${prObj.id}&key=09e4aced60041e389dbb27b9accadd65&token=${prObj.trello.token}`;
console.log(prObj);
const BoardApiURL = `https://api.trello.com/1/boards/?name=${prObj.title}&key=09e4aced60041e389dbb27b9accadd65&token=${prObj.trello.token}`;
$http.post(BoardApiURL).then((result) => {
console.log(result);
deferred.resolve(result.data);
})
.catch((err) => {
Expand All @@ -44,30 43,46 @@
else {
const listAPIendPoint = `https://api.trello.com/1/lists?name=Teem&idBoard=${trelloObj.boardId}&key=09e4aced60041e389dbb27b9accadd65&token=${trelloObj.token}`;
$http.post(listAPIendPoint)
.then((data) => {
console.log(data);
.then((result) => {
deferred.resolve(result.data);
})
.catch(err => console.log(err));
.catch(err => deferred.reject(err));
}
return deferred.promise;
}

function addNewcard(trelloObj,need){
function addNewCard(trelloObj, need) {
let deferred = $q.defer();
deferred.resolve(need);
const newCardURL = `https://api.trello.com/1/cards?idList=${trelloObj.listId}&name=${need.text}&key=09e4aced60041e389dbb27b9accadd65&token=${trelloObj.token}`;
$http.post(newCardURL).
then(result => deferred.resolve(result.data))
.catch(err => deferred.resolve(err));
return deferred.promise;
// const newCardURL = `https://api.trello.com/1/cards?idList=${trelloObj.listId}&`
}

function registerWebhook(trelloObj){
const webhookURL = `https://api.trello.com/1/webhooks/?idModel=${trelloObj.boardId}&key=09e4aced60041e389dbb27b9accadd65&token=${trelloObj.token}&callbackURL=http://13.126.145.126:9500/`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, key to config file.

$http.post(webhookURL)
.then(result => console.log(result.data))
.catch(err => console.log(err));
}

// 59967ddfa49283757bd8a2ac

let service = {
function deleteWebhook(trelloObj){
const unregisterWebhookURL = `https://api.trello.com/1/webhooks/${trelloObj.webhookId}&key=09e4aced60041e389dbb27b9accadd65&token=${trelloObj.token}`;
$http.delete(unregisterWebhookURL)
.then(result => console.log(result.data))
.catch(err => console.log(err));
}

return {
getToken: getToken,
parseTokenFromUrl: parseTokenFromUrl,
createTrelloBoard: createTrelloBoard,
createNewList: createNewList,
addNewcard: addNewcard
addNewCard: addNewCard,
registerWebhook: registerWebhook
};

return service;
}
})();
2 changes: 1 addition & 1 deletion src/templates/projects/project/desktop.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 54,7 @@
<div class="col-md-4">
<div sticky class="project-utils">
<div project-people></div>
<button ng-if="!project.trello" class="btn btn-primary btn-block" type="button"><i class="material-icons">credit_card</i> Integrate Trello</button>
<button ng-if="!project.trello" ng-click="getToken()" class="btn btn-primary btn-block" type="button"><i class="material-icons">credit_card</i> Integrate Trello</button>
<h2 translate>need.nav.title</h2>
<div class="project-needs-section">
<div need-list project="project" needs="project.needs" display="panel" class="flex-container" ng-class="project.isParticipant() ? '' : 'has-cta'"></div>
Expand Down