-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.html
444 lines (395 loc) · 11.5 KB
/
index.html
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Trello to PDF</title>
<link
rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh"
crossorigin="anonymous"
/>
<script
defer
src="https://cdnjs.cloudflare.com/ajax/libs/mustache.js/3.1.0/mustache.min.js"
type="text/javascript"
></script>
<script
defer
src="https://cdnjs.cloudflare.com/ajax/libs/marked/0.8.2/marked.min.js"
type="text/javascript"
></script>
<script
async
defer
data-domain="trello.arlyon.dev"
src="https://plausible.io/js/plausible.js"
></script>
<style>
main {
min-width: 100vw;
min-height: 100vh;
margin: 0 auto;
}
div#board-select {
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
div#drop-zone {
z-index: 10;
position: fixed;
width: 100vw;
height: 100vh;
background-color: #026aa7;
color: white;
display: flex;
justify-content: center;
align-items: center;
opacity: 0;
transition: opacity 0.1s;
transition-delay: 0.05s;
pointer-events: none;
}
div#drop-zone.visible {
opacity: 1;
}
p#error-box {
opacity: 0;
}
p#error-box.visible {
opacity: 1;
}
h1 {
margin-top: 1em;
text-align: center;
}
h3 {
margin: 0em 0 1.5em 0;
}
h6.divider {
margin-top: 2em;
text-align: center;
font-weight: 600;
}
blockquote {
margin-left: 1em;
padding-left: 1em;
border-left: 3px solid var(--gray) !important;
color: var(--gray);
}
time {
font-size: 0.8em;
color: var(--gray);
}
ul.comments {
margin: 0;
padding: 0 1em;
list-style: none;
}
ul.comments > li {
padding-left: 1em;
border-left: 3px solid black;
}
section {
margin: 0 auto;
max-width: 800px;
}
section.selector {
padding: 2em 0;
width: max-content;
}
section.selector > h5 {
text-align: center;
}
input.form-control::placeholder {
color: rgb(79, 78, 87);
opacity: 1 !important;
}
div.seperator {
width: 400px;
margin: 2em 0;
color: #026aa7;
display: flex;
align-items: center;
justify-content: center;
text-align: center;
}
div.seperator > * {
margin: 0;
}
div.seperator::before,
div.seperator::after {
content: "";
flex: 1;
border-bottom: 1px solid #026aa7;
margin: 0 0.5em;
}
</style>
<style type="text/css" media="print">
section.selector {
display: none;
}
blockquote {
border: 0;
}
</style>
</head>
<body>
<div id="drop-zone">
<h1></h1>
</div>
<main>
<div id="board"></div>
<div id="board-select">
<h2 style="margin-bottom: 1em">Trello to PDF</h2>
<h6>Drop a JSON File Here:</h6>
<div class="custom-file" style="max-width: 400px; margin: 0.5em 0">
<input type="file" class="custom-file-input" id="custom-file" accept="application/json" />
<label class="custom-file-label" for="custom-file">Choose file</label>
</div>
<p style="color: var(--gray)">
<small>(don't worry, we don't upload anything)</small>
</p>
<div class="seperator">
<h6>OR</h6>
</div>
<h6>Paste The Public URL</h6>
<div class="custom-file" style="max-width: 400px; margin: 0.5em 0">
<input type="url" class="form-control" id="url" placeholder="Public URL" />
</div>
<p style="color: var(--red)" id="error-box"><small>error</small></p>
<p style="color: var(--gray); position: fixed; bottom: 1em">
<small>
version 1.3.0
<a
href="https://github.com/arlyon/trello-to-pdf"
style="color: inherit; text-decoration: underline"
>source</a
>
<a
href="https://help.trello.com/article/747-exporting-data-from-trello-1"
style="color: inherit; text-decoration: underline"
>how-to</a
>
</small>
</p>
</div>
</main>
<script type="text/html" id="template-output">
<section class="selector">
<h5 style="text-align:center">Display Lists</h5>
{{#lists}}
<input
type="checkbox"
title="{{name}}"
checked="checked"
onclick="(input => document.getElementById(`{{name}}`).hidden = !input.checked)(this)"
/>
{{/lists}}
</section>
{{#lists}}
<section id="{{name}}">
<h1>{{name}}</h1>
{{#cards}}
<div class="card-body">
<h3 class="card-title">{{name}}</h3>
{{#desc}}{{{desc}}}{{/desc}} {{^desc}}<span style="color: var(--gray)"
>No Description</span
>{{/desc}} {{#actions.length}}
<h6 class="divider">COMMENTS</h6>
<ul class="comments">
{{#actions}}
<li>
<span style="font-weight:600">{{author}} </span
><time datetime="{{date}}">{{date}}</time>
{{{text}}}
</li>
{{/actions}} {{/actions.length}}
</ul>
</div>
{{/cards}}
</section>
{{/lists}}
</script>
<script type="text/javascript">
const showBoard = (data) => {
board.innerHTML = Mustache.render(template, data);
boardSelect.hidden = true;
document.title = data.name;
};
const hideBoard = () => {
board.innerHTML = null;
boardSelect.hidden = false;
document.title = "Trello to PDF";
};
const parseData = (trelloJson) => {
const data = {
name: trelloJson.name,
shortLink: trelloJson.shortLink,
lists: [],
ref: {},
};
for (list of trelloJson.lists) {
if (list.closed) {
continue;
}
data.ref[list.id] = {
name: list.name,
cards: [],
};
data.lists.push(data.ref[list.id]);
}
for (card of trelloJson.cards) {
if (card.closed) {
continue;
}
data.ref[card.id] = {
name: card.name,
desc: marked(card.desc),
actions: [],
};
if (!data.ref[card.idList]) {
data.ref[card.idList] = { cards: [] };
}
data.ref[card.idList].cards.push(data.ref[card.id]);
}
for (action of trelloJson.actions) {
if (action.type != "commentCard") {
continue;
}
data.ref[action.id] = {
text: marked(action.data.text),
date: action.date.split("T")[0],
author: action.memberCreator.fullName,
username: action.memberCreator.username,
};
try {
data.ref[action.data.card.id].actions.unshift(data.ref[action.id]);
} catch (e) {}
}
return data;
};
const loadData = (data) => {
let json;
try {
json = JSON.parse(data);
} catch (e) {
throw new Error("Invalid JSON", e);
}
try {
return parseData(json);
} catch (e) {
throw new Error("Error when parsing Trello file", e);
}
};
const handleFileEvent = (event, errorBox) => {
let files;
if (event.type === "change") {
files = fileUpload.files;
} else if (event.type === "drop") {
files = event.dataTransfer.files;
}
loadFile(files[0], errorBox);
event.preventDefault();
};
const loadFile = (file, errorBox) => {
if (file) {
const reader = new FileReader();
reader.onload = (event) => {
try {
const data = loadData(reader.result);
showBoard(data);
history.pushState(data, data.name, `/b/${data.shortLink}`);
} catch (e) {
errorBox.innerHTML = e.message;
errorBox.className = "visible";
}
};
reader.readAsText(file);
}
messageBox.className = "";
};
const handleUrlEvent = async (event) => {
hideError();
if (event.target.value === "") return;
const id = trelloUrl.exec(event.target.value);
if (id === null) return showError("couldn't parse the url");
try {
const data = await loadBoardId(id[1]);
history.pushState(data, data.name, `/b/${data.shortLink}`);
} catch (e) {
showError(e);
}
};
const loadBoardId = async (id) => {
const url = `https://trello.com/b/${id}.json`;
showMessage("Fetching...");
try {
const response = await fetch(url);
if (response.status !== 200) {
throw "";
}
const data = loadData(await response.text());
showBoard(data);
return data;
} catch {
throw `couldn't get board '${id}'. is it public?`;
} finally {
hideMessage();
}
};
const showError = (message) => {
errorBox.className = "visible";
errorBox.children[0].textContent = message;
};
const hideError = () => {
errorBox.className = "";
};
const showMessage = (message) => {
messageBox.className = "visible";
messageBox.children[0].textContent = message;
};
const hideMessage = () => {
messageBox.className = "";
};
const trelloUrl = /.*\/b\/(\w+)/;
const template = document.getElementById("template-output").innerHTML;
// handles to various elements
const root = document.getElementsByTagName("main")[0];
const board = document.getElementById("board");
const boardSelect = document.getElementById("board-select");
const fileUpload = document.getElementById("custom-file");
const messageBox = document.getElementById("drop-zone");
const errorBox = document.getElementById("error-box");
const urlPaste = document.getElementById("url");
root.ondrop = (e) => handleFileEvent(e, errorBox);
fileUpload.onchange = (e) => handleFileEvent(e, errorBox);
root.ondragover = (event) => event.preventDefault();
root.ondragenter = () => showMessage("Drop!");
root.ondragexit = hideMessage;
urlPaste.oninput = handleUrlEvent;
window.onpopstate = ({ state }) => {
if (state == null) {
hideBoard();
} else {
showBoard(state);
}
};
window.onload = async () => {
const id = trelloUrl.exec(window.location.pathname);
if (id !== null) {
try {
const data = await loadBoardId(id[1]);
history.replaceState(data, data.name, `/b/${data.shortLink}`);
} catch (e) {
showError(e);
}
}
};
</script>
</body>
</html>