forked from Q42/TrelloScrum
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrello2csv.js
More file actions
121 lines (103 loc) · 2.76 KB
/
trello2csv.js
File metadata and controls
121 lines (103 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
** TrelloScrum v0.54 - https://github.com/dusano/TrelloScrum
** Adds Scrum to your Trello (with Zemanta extensions)
**
** Export of Trello board to csv
**
** Original:
** Dusan Omercevic <https://github.com/dusano>
**
*/
//what to do when DOM loads
$(function(){
//Export data to CSV
$(document).on('DOMNodeInserted', ".pop-over .content", addCSVbutton);
});
function attachCSVdata(CSVbutton, cards) {
processing_complete = true;
for (var i = 0; i < cards.length; i++)
processing_complete &= cards[i]["complete"];
if (!processing_complete) {
setTimeout(function(){attachCSVdata(CSVbutton, cards)}, 100);
return;
}
var csvstring = "";
for (var i = 0; i < cards.length; i++) {
var card = cards[i];
regex = /\(([0-9]+)\)\s*/;
card_name = card
.name
.replace(regex, "")
.replace(/\"/g, "'");
no_points = -1
try {
matches = regex.exec(card.name);
no_points = parseInt(matches[1]);
} catch(err) {
console.error("Card " + card.name + " is not in valid format");
}
card_desc = card
.desc
.replace(/(\r\n|\n)/g, "<br />")
.replace(/\"/g, "'");
csvstring = csvstring +
"\"" + card_name + "\"," +
"\"" + card_desc + "\"," +
"\"" + card["checklist"] + "\"," +
no_points + "\n";
}
CSVbutton
.attr("href", "data:text/csv," + escape(csvstring))
.show();
}
function exportCardsToCSV(CSVbutton, cards) {
$.each(cards, function(ix, card) {
card["complete"] = false;
$.ajax({
type: "GET",
url: "https://trello.com/1/cards/" + card.id + "/checklists",
success: function(checklists) {
checklist_str = "";
$.each(checklists, function(iy, checklist) {
for (var i = 0; i < checklist.checkItems.length; i++) {
if (checklist_str != "")
checklist_str += "<br />";
checklist_str += checklist.checkItems[i].name;
}
});
card["checklist"] = checklist_str;
card["complete"] = true;
},
error: function(err) {
console.log("Error:" + JSON.stringify(err));
}
});
});
setTimeout(function(){attachCSVdata(CSVbutton, cards)}, 1);
}
function addCSVbutton() {
if (!$(this).find("a.js-export-csv").length) {
regex = /\/[^\/]*\/[^\/]*\/([^\/]*)\/?.*$/;
matches = regex.exec(window.document.location.pathname);
board_id = matches[1];
JSONbutton = $(this).find("a.js-export-json");
var CSVbutton = JSONbutton
.clone()
.removeClass("js-export-json")
.addClass("js-export-csv")
.attr("href", "#")
.text("CSV")
.appendTo(JSONbutton.parent())
.hide();
$.ajax({
type: "GET",
url: "https://trello.com/1/boards/" + board_id + "/cards",
success: function(cards) {
exportCardsToCSV(CSVbutton, cards);
},
error: function(err) {
console.log("Error:" + JSON.stringify(err));
}
});
}
}