Skip to content

Commit

Permalink
Fixes #210
Browse files Browse the repository at this point in the history
  • Loading branch information
superyass committed Aug 8, 2016
1 parent 05e3e92 commit 01aeb07
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.githubIssueRow {
cursor:pointer;
}
.trelloTaskRow {
cursor:pointer;
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
<template name="projectOpenTasks">
<section id="open-tasks" class="row bg-white">

<!--show trello bloc only if there is a trello link-->
<!--start trello -->
<!--show trello bloc only if there is a trello link-->
{{#if isListEmpty project.links 'trello'}}
{{> trelloLists project}}
<div class="col-lg-10 col-lg-offset-1">
<h2 class="column-heading">Open tasks from Trello</h2>
</div>
<div class="col-lg-10 col-lg-offset-1">
<div class="col-lg-7" style="padding:0;">
<p>
If you have the right skillset and experience, you are more than welcome to help out.
<br/> All positions are most likely available to everybody worldwide.
</p>
</div>
</div>
{{#each getTrelloBoards project.links}}
{{#if showBoard (getCardsCount this) }}
{{> trelloBoard}}
{{/if}}
{{/each}}
{{/if}}
<!--end github-->

<!--start github -->
<!--show github bloc only if there is a github link-->
Expand Down Expand Up @@ -35,45 +52,44 @@ <h2 class="column-heading">Issues from Github</h2>
</template>

<!-- trello templates -->
<template name="trelloLists">
<div class="col-lg-10 col-lg-offset-1">
<h2 class="column-heading">Open tasks from Trello</h2>
</div>
<template name="trelloBoard">

<div class="col-lg-10 col-lg-offset-1">

<div class="col-lg-7" style="padding:0;">
<p>
If you have the right skillset and experience, you are more than welcome to help out.
<br/> All positions are most likely available to everybody worldwide.
</p>
{{#if showBoardName}}
<h3>Tasks in Board: {{ getBoardName url }}</h3>
{{/if}}
</div>
<div class="col-lg-2 col-lg-offset-2">
<a href="{{spitMeTrelloURL links }}" class="btn">Go to Trello</a>
<a href="{{ url }}" class="btn">Go to Trello</a>
</div>
</div>

<div class="col-lg-10 col-lg-offset-1">
<table class="table">
<thead>
<tr>
<th>Tasks</th>
<th>Status</th>
<th>Status</th>
<th>Card</th>
<th>Description</th>
<th>Labels</th>
<th>Bulletpoints</th>
</tr>
</thead>
<tbody>
{{#each getData (spitMeTrelloURL links)}} {{> trelloListsTableRow }} {{/each}}
{{#each getCards url }}
{{> trelloTasksTableRow }}
{{/each}}
</tbody>
</table>
</div>
</template>

<template name="trelloListsTableRow">
<tr>
<template name="trelloTasksTableRow">
<tr class="trelloTaskRow">
<td>{{name}}</td>
<td>Copy</td>
<td>To-do</td>
<td>{{desc}}</td>
<td>{{getLabels labels}}</td>
<td>{{countCheckItems idChecklists}}</td>
</tr>
</template>

Expand Down
142 changes: 126 additions & 16 deletions projects/view/client/projectProfileTemplates/client/projectOpenTasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ Template.projectOpenTasks.helpers({
});
},
isListEmpty: function(list, typ) {
console.log("--->",list);
var urlList = _.where(list, {
type: typ
});
if(typ=="github"){
Session.set("githubLinksCount",urlList.length);
}else if(typ=="trello"){
Session.set("trelloLinksCount",urlList.length);
}
return !_.isEmpty(urlList);
},
Expand All @@ -21,49 +22,130 @@ Template.projectOpenTasks.helpers({
});
return lis;
},
getTrelloBoards: function(list) {
var lis = _.where(list, {
type: 'trello'
});
return lis;
},
getIssuesCount: function(list){
var url = githubIssuesUrlParser(list.url);
Meteor.http.call("GET", url, function(error, result) {
if (error) {
console.log("ProjectOpenTasks.js >getDataGitub >Error:" + error);
console.error("ProjectOpenTasks.js >getIssuesCount >Error:" + error);
}
if (result) {
Session.set("issuesListCount"+url,result.data.length);
}
});
return Session.get("issuesListCount"+url);
},
getCardsCount: function(list){
url = trelloCardsCountUrlParser(list.url);
Meteor.http.call("GET", url, function(error, result) {
if (error) {
console.error("ProjectOpenTasks.js >getCardsCount >Error:" + error);
}
if (result) {
Session.set("cardsCount"+url,result.data.length);
}
});
return Session.get("cardsCount"+url);
},
showRepo: function(issuesCount){
if(issuesCount==0 && Session.get("githubLinksCount")!=1){
return false;
}else{
return true;
}
},
showBoard: function(cardsCount){
if(cardsCount==0 && Session.get("trelloLinksCount")!=1){
return false;
}else{
return true;
}
}
});

Template.trelloLists.helpers({
spitMeTrelloURL: function(list) {
return _.findWhere(list, {
type: 'trello'
}).url;
},
getData: function(url) {
Template.trelloBoard.helpers({
getCards: function(url) {
//url = "https://api.trello.com/1/boards/rbpEfMld";
url = trelloUrlParser(url);
Meteor.http.call("GET", url, function(error, result) {
if (error) {
console.log("ProjectOpenTasks.js >getDataTrello >Error:" + error);
console.error("ProjectOpenTasks.js >getCards >Error:" + error);
}
if (result) {
//limit result to the first 5 issues.
//because we can only get the result in callback we can't
//directly return it, so we're storing it in the Session...
Session.set("trelloLists", _.first(result.data, 5));
Session.set("trelloLists"+url, result.data);
}
});
return Session.get("trelloLists");
return Session.get("trelloLists"+url);
},
getBoardName: function(url){
url = trelloBoardNameUrlParser(url);
Meteor.http.call("GET", url, function(error, result) {
if (error) {
console.error("ProjectOpenTasks.js >getBoardName >Error:" + error);
}
if (result) {
//limit result to the first 5 issues.
//because we can only get the result in callback we can't
//directly return it, so we're storing it in the Session...
// Session.set("repoName"+url, result.data.name);
Session.set("boardName"+url, result.data.name);
}
});
return Session.get("boardName"+url);
},
showBoardName: function(){
if(Session.get("trelloLinksCount")>1){
return true
}else{
return false;
}
}
});

Template.trelloTasksTableRow.helpers({
getLabels: function(lab) {
var labels = "";
for (var i = 0; i < lab.length; i++) {
labels = labels + lab[i].name + ", ";
}
//delete the last ', '
labels = labels.substring(0, labels.length - 2);
return labels;
},
countCheckItems: function(checklistsIds){
if(_.isEmpty(checklistsIds)){
return 0;
}else{
checklistsIds.forEach(function(entry){
var url = trelloCheckItemsCountUrlParser("https://api.trello.com/1/checklists/"+entry);
Meteor.http.call("GET", url, function(error, result) {
if (error) {
console.error("ProjectOpenTasks.js >countCheckItems >Error:" + error);
}
if (result) {
console.log("count:",result.data.length);
Session.set("checkItemsCount"+url,result.data.checkItems.length);
}
});
return Session.get("checkItemsCount"+url);
});
}
}
});

Template.trelloTasksTableRow.events({
"click .trelloTaskRow": function(event, template) {
//open issue link
window.open(this.shortUrl, "_blank");
}
});

Template.githubRepo.helpers({
Expand All @@ -72,7 +154,7 @@ Template.githubRepo.helpers({
url = githubIssuesUrlParser(url);
Meteor.http.call("GET", url, function(error, result) {
if (error) {
console.log("ProjectOpenTasks.js >getDataGitub >Error:" + error);
console.error("ProjectOpenTasks.js >getDataGitub >Error:" + error);
}
if (result) {
//limit result to the first 5 issues.
Expand All @@ -87,7 +169,7 @@ Template.githubRepo.helpers({
url = githubRepoNameUrlParser(url);
Meteor.http.call("GET", url, function(error, result) {
if (error) {
console.log("ProjectOpenTasks.js >getDataGitub >Error:" + error);
console.error("ProjectOpenTasks.js >getDataGitub >Error:" + error);
}
if (result) {
//limit result to the first 5 issues.
Expand Down Expand Up @@ -127,7 +209,6 @@ Template.githubIssuesTableRow.events({
}
});


//trying to parse and fix trello url
function trelloUrlParser(url) {
//https://trello.com/b/rbpEfMld/data-science
Expand All @@ -139,7 +220,36 @@ function trelloUrlParser(url) {
url = url.replace("https://trello.com/b", "https://api.trello.com/1/boards");
//delete the humain readable name (data-science)
url = url.substr(0, url.lastIndexOf("/"));
url = url + "/lists";
url = url + "/cards?closed=false&fields=id,name,shortUrl,labels,desc,idChecklists&limit=5";
return url;
}
}

function trelloCardsCountUrlParser(url) {
//https://trello.com/b/rbpEfMld/data-science
if (url.includes("trello.com")) {
if (!url.includes("http"))
url = "https://" + url;
url = url.replace("http://", "https://");
url = url.replace("https://www", "https://");
url = url.replace("https://trello.com/b", "https://api.trello.com/1/boards");
//delete the humain readable name (data-science)
url = url.substr(0, url.lastIndexOf("/"));
url = url + "/cards?closed=false&fields=id";
return url;
}
}

function trelloBoardNameUrlParser(url) {
//https://trello.com/b/rbpEfMld/data-science
if (url.includes("trello.com")) {
if (!url.includes("http"))
url = "https://" + url;
url = url.replace("http://", "https://");
url = url.replace("https://www", "https://");
url = url.replace("https://trello.com/b", "https://api.trello.com/1/boards");
//delete the humain readable name (data-science)
url = url.substr(0, url.lastIndexOf("/"));
return url;
}
}
Expand Down

0 comments on commit 01aeb07

Please sign in to comment.