forked from psd/pivotal-cards
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pivotal-cards.js
208 lines (183 loc) · 5 KB
/
pivotal-cards.js
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/*
*
* Print a https://www.pivotaltracker.com view as index cards
*
* depends on jQuery and Underscore and the Pivotal code ..
*
* released under the WTFPL licence
*
* https://github.com/psd/pivotal-cards
*
*/
(function ($) {
var options = {
"filing-colours": true,
"rubber-stamp": true,
"double-sided": true,
"white-backs": true
};
var make_front = _.template(
'<div class="<%= story_type %> card" id="front-<%= cardno %>">' +
' <div class="front side">' +
' <div class="header">' +
' <span class="labels">' +
'<% _.each(labels, function(label) { %> <span class="label"><%= label %></span> <% }); %>' +
' <span>' +
' </div>' +
' <div class="middle">' +
' <div class="story-title"><%= name %></div>' +
' <div class="story-type"><%= story_type %></div>' +
' </div>' +
' <div class="footer">' +
' <span class="epic_name"><%= epic_name %></span>' +
' <span class="points points<%= points %>"><span><%= points %></span></span>' +
' </div>' +
' </div>' +
'</div>');
var make_back = _.template(
'<div class="<%= story_type %> card" id="back-<%= cardno %>">' +
' <div class="back side">' +
' <div class="header">' +
' <span class="project"><%= project_name %></span>' +
' <span class="id"><%= id %></span>' +
' </div>' +
' <div class="middle">' +
' <div class="story-title"><%= name %></div>' +
' <div class="description"><%= description %></div>' +
' <table class="tasks">' +
'<% _.each(tasks, function(task) { %><tr>' +
' <td class="check <%= task._complete ? "complete" : "incomplete" %>"><%= task._complete ? "☑" : "☐" %></td>' +
' <td class="task"><%= task._description %></td>' +
'</tr><% }); %>' +
' </table>' +
' </div>' +
' <div class="footer">' +
' <% if (requester) { %><span class="requester"><%= requester %></span><% } %>' +
' <% if (owner) { %><span class="owner"><%= owner %></span><% } %>' +
' </div>' +
' </div>' +
'</div>');
/*
* overlay with printable pages
*
* TBD: really should make a dismissable overlay
*/
$('body > *').hide();
var main = $('<div id="pivotal-cards-pages"></div>');
_.each(options, function(value, option) {
if (value) {
main.addClass(option);
}
});
$('body').append(main);
/*
* Find visible items
*/
var ids = [];
var items = $('.item > .selected'); // use the selected items
if (items.length == 0) { // if there are no selected items ...
items = $('.item'); // ... then use all items
}
items.each(function() {
var id = this.id || "";
var matches = id.match(/_(story|epic)([0-9]+)/);
if (matches) {
ids.push(matches[1] + ":" + matches[2]);
}
});
/*
* build cards
*/
var cardno = 0;
var fronts = [];
var backs = [];
ids = _.uniq(ids);
_.each(ids, function (id) {
var matches = id.split(":");
var item;
var card;
var story = (matches[0] === "epic")
? app.project.getEpicById(matches[1])
: app.project.getStoryById(matches[1]);
if (story) {
var labels = [];
var epic_name = "";
_.each(story.getLabels(), function(label) {
if (app.project.getEpicByLabel(label)) {
epic_name = label;
} else {
labels.push(label);
}
});
var points = story.getEstimate && story.getEstimate();
var name = story.getName() || "";
name = name.replace(/\band\b|&/g, '<span class="amp">&</span>');
item = {
cardno: cardno,
story_type: story._storyType ? story._storyType._name : matches[0],
id: matches[1],
name: name,
description: story._description || "",
epic_name: epic_name,
project_name: app.project.getName(),
labels: labels,
tasks: story.getTasks && story.getTasks(),
requester: story.getRequestedBy && story.getRequestedBy().displayName,
owner: story.getOwnedBy && story.getOwnedBy() && story.getOwnedBy().displayName,
points: points > 0 ? points : ""
};
if (item.story_type === "chore" && item.name.match(/\?\s*$/)) {
item.story_type = "spike";
}
/*
* make cards using templates
*/
card = make_front(item);
fronts.push($(card));
card = make_back(item);
backs.push($(card));
cardno++;
}
});
/*
* layout cards
*/
function double_sided() {
var cardno;
var front_page;
var back_page;
for (cardno = 0; cardno < fronts.length; cardno++) {
if ((cardno % 4) === 0) {
front_page = $('<div class="page fronts"></div>');
main.append(front_page);
back_page = $('<div class="page backs"></div>');
main.append(back_page);
}
front_page.append(fronts[cardno]);
back_page.append(backs[cardno]);
/*
if (!(cardno % 2)) {
} else {
$(back_page).children().last().before(backs[cardno]);
}
*/
}
}
function single_sided() {
var cardno;
var page;
for (cardno = 0; cardno < fronts.length; cardno++) {
if ((cardno % 2) === 0) {
page = $('<div class="page"></div>');
main.append(page);
}
page.append(fronts[cardno]);
page.append(backs[cardno]);
}
}
if (options['double-sided']) {
double_sided();
} else {
single_sided();
}
}(jQuery));