forked from llad/export-for-trello
-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathtrelloexport.js
More file actions
3970 lines (3592 loc) · 190 KB
/
trelloexport.js
File metadata and controls
3970 lines (3592 loc) · 190 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
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
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* TrelloExport
*
* A Chrome extension for Trello, that allows to export boards to Excel spreadsheets, HTML with Twig templates, Markdown and OPML.
*
* Forked by @trapias (Alberto Velo)
* https://github.com/trapias/trelloExport
* From:
* https://github.com/llad/trelloExport
* Started from:
* https://github.com/Q42/TrelloScrum
*
* = = = VERSION HISTORY = = =
* Whatsnew for version 1.8.8:
- export Trello Plus Spent and Estimate data
- export checklists
- export comments (see commentLimit, default 100)
- export attachments
- export votes
- use updated version of xlsx.js, modified by me (escapeXML)
- use updated version of jquery, 2.1.0
* Whatsnew for version 1.8.9:
- added column Card #
- added columns memberCreator, datetimeCreated, datetimeDone and memberDone pulling modifications from https://github.com/bmccormack/export-for-trello/blob/5b2b8b102b98ed2c49241105cb9e00e44d4e1e86/trelloexport.js
- added linq.min.js library to support linq queries for the above modifications
* Whatsnew for version 1.9.0:
- switched to SheetJS library to export to excel, cfr https://github.com/SheetJS/js-xlsx
- unicode characters are now correctly exported
* Whatsnew for version 1.9.1:
- fixed button loading
- some code cleaning
* Whatsnew for version 1.9.2:
- fixed blocking error when duedate specified
- new button loading function
* Whatsnew for version 1.9.3:
- restored archived cards sheet
* Whatsnew for version 1.9.4:
- fix exporting when there are no archived cards
* Whatsnew for version 1.9.5:
- code lint
- ignore case in finding 'Done' lists (thanks https://disqus.com/by/AlvonsiusAlbertNainupu/)
* Whatsnew for version 1.9.6:
- order checklist items by position (issue #4)
- minor code changes
* Whatsnew for version 1.9.7:
- fix issue #3 (copied comments missing in export)
* Whatsnew for version 1.9.8:
- use trello api to get data
* Whatsnew for version 1.9.9:
- MAXCHARSPERCELL limit to avoid import errors in Excel (see https://support.office.com/en-nz/article/Excel-specifications-and-limits-16c69c74-3d6a-4aaf-ba35-e6eb276e8eaa)
- removed commentLimit, all comments are loaded (but attention to MAXCHARSPERCELL limit above, since comments go to a single cell)
- growl notifications with jquery-growl http://ksylvest.github.io/jquery-growl/
* Whatsnew for version 1.9.10:
- adapt inject script to modified Trello layout
* Whatsnew for version 1.9.11:
- options dialog
- export full board or choosen list(s) only
- add who and when item was completed to checklist items (issue #5 at GitHub)
* Whatsnew for version 1.9.12:
- bugfix: the previously used BoardID was kept when navigating to another board
* Whatsnew for version 1.9.13:
- new 'DoneTime' column holding card completion time in days, hours, minutes and seconds as per ISO8601 (cfr https://en.wikipedia.org/wiki/ISO_8601)
- name (prefix) of 'Done' lists is now configurable, default "Done"
- larger options dialog
- export multiple (selected) boards
- export multiple (selected) cards in a list
* Whatsnew for v. 1.9.14:
- handle multiple nameListDone
- fix getMoveCardAction and getCreateCardAction to properly handle actions when exporting from multiple boards
- added a new function (getCommentCardActions) to load comments with a dedicated query
- format dates according to locale
- new capability to filter exported lists by name when exporting multiple boards
* Whatsnew for v. 1.9.15:
- finally fix comments and done calculation exporting: thanks @fepsch
* Whatsnew for v. 1.9.16:
- new icon
- investigating issues reported by @fepsch
* Whatsnew for v. 1.9.17:
- finally fix exporting ALL comments per card: now loading comments per single card, way slower but assures all comments are exported
* Whatsnew for v. 1.9.18:
- improve UI: better feedback message timing, yet still blocking UI during export due to sync ajax requests
- removed data limit setting from options dialog - just use 1000, maximum allowed by Trello APIs
- fix filename (YYYYMMDDhhmmss)
- fix some UI issues
* Whatsnew for v. 1.9.19:
- refactoring export flow
- updated jQuery Growl to version 1.3.1
- new markdown export mode
* Whatsnew for v. 1.9.20:
- fixes due to Trello UI changes
* Whatsnew for v. 1.9.21:
- some UI (CSS) improvements
- improved options dialog, resetting options when switching export type
- new columns for Excel export: 'Total Checklist items' and 'Completed Checklist items'
- better checklists formatting for Excel export
- export to HTML
* Whatsnew for v. 1.9.22:
- fix improper .md encoding as per issue #8 https://github.com/trapias/TrelloExport/issues/8
- new option to decide whether to export archived items
* Whatsnew for v. 1.9.23:
- OPML export
- add memberDone to markdown and HTML exports
* Whatsnew for v. 1.9.24:
- checkboxes to enable/disable exporting of comments, checklist items and attachments
- new option to export checklist items to rows, for Excel only
* Whatsnew for v. 1.9.25:
- paginate cards loading so to be able to load all cards, even if exceeding the API limit of 1000 records per call
* Whatsnew for v. 1.9.26 (thanks chris https://github.com/collisdigital):
- export points estimate and consumed from Card titles based on Scrum for Trello
- improved regex for Trello Plus estimate/spent in card titles
* Whatsnew for v. 1.9.27:
- fix ajax.fail functions
- fix loading boards when current board does not belong to any organization
* Whatsnew for v. 1.9.28:
- fix cards loading: something is broken with the paginated loading introduced with 1.9.25; to be further investigated
* Whatsnew for v. 1.9.29:
- fix bug using user fullName, might not be available (thanks Natalia L.)
- new css to format HTML exported files
* Whatsnew for v. 1.9.30:
- fix 1.9.29 beta
- finalize new css for HTML exports
* Whatsnew for v. 1.9.31:
- fix due date format in Excel export (issue #12)
- fix missing export of archived cards (issue #13)
* Whatsnew for v. 1.9.32:
- hopefully fixed bug with member fullName reading
- new option to export labels and members to Excel rows, like already available for checklist items (issue #15 https://github.com/trapias/TrelloExport/issues/15)
- new option to show attached images inline for Markdown and HTML exports (issue #16 https://github.com/trapias/TrelloExport/issues/16)
* Whatsnew for v. 1.9.33:
- new data field dateLastActivity exported (issue #18)
- new data field numberOfComments exported (issue #19)
- new option to choose which columns to export to Excel (issue #17)
* Whatsnew for v. 1.9.34:
- only show columns chooser for Excel exports
- can now set a custom css for HTML export
- can now check/uncheck all columns to export
* Whatsnew for v. 1.9.35:
- fix Trello header css height
* Whatsnew for v. 1.9.36:
- filter by list name, card name or label name
- help tooltips
* Whatsnew for v. 1.9.37:
- bugfix multiple css issues and a bad bug avoiding the "add member" function to work properly, all due to the introduction of bootstrap css and javascript to use the bootstrap-multiselect plugin; now removed bootstrap and manually handled multiselect missing functionalities
* Whatsnew for v. 1.9.38:
- css cleanup
- re-enabled tooltips
- export custom fields (pluginData handled with the "Custom Fields" Power-Up) to Excel
* Whatsnew for v. 1.9.39:
- fix custom fields loading (issue #27)
- fix card info export to MD (issue #25)
* Whatsnew for v. 1.9.40:
- https://github.com/trapias/TrelloExport/issues/28 ok with Done prefix
- contains vs startsWith filters
* Whatsnew for v. 1.9.41:
- persist TrelloExport options to localStorage: CSS, selected export mode, selected export type, name of 'Done' list (issue #24)
- fix due date locale
- expand flag to export archived cards to all kind of items, and filter consequently
- list boards from all available organizations with the "multiple boards" export type
* Whatsnew for v. 1.9.42:
- new organization name column in Excel exports (issue https://github.com/trapias/TrelloExport/issues/30)
- custom fields working again following Trello API changes (issue https://github.com/trapias/TrelloExport/issues/31), but not for multiple boards
* Whatsnew for v. 1.9.43:
- new SPONSORED feature: Twig templates for HTML export https://github.com/trapias/TrelloExport/issues/35 and https://github.com/trapias/TrelloExport/issues/36
- added card dueComplete field from Trello updated API, used in HTML Twig template
- fix filtering options
- Twig template selection (local templates)
- Default and Bibliography HTML Twig templates (SPONSORED)
- fixed issue #39 "Board menu not open" error https://github.com/trapias/TrelloExport/issues/39
- save last template used to localStorage, and reload next time
- scrollable options dialog
- template sets: load custom Twig templates from any https URL
- Default, Bibliography and Newsletter HTML Twig templates
* Whatsnew for v. 1.9.44:
- Dummy release needed to update Chrome Web Store, wrong blog article link!
* Whatsnew for v. 1.9.45:
- button to clear all settings saved to localStorage
- new jsonLabels array for labels
* Whatsnew for v. 1.9.46:
- fix new "clear localStorage" button position
* Whatsnew for v. 1.9.47:
- responsive images in Bibliography template
- fix double encoding of card description
* Whatsnew for v. 1.9.48:
- bugfix HTML encoding for multiple properties
- small fixes in templates
- two Newsletter templates
* Whatsnew for v. 1.9.49:
- bugfix encoding (again), https://github.com/trapias/TrelloExport/issues/43
* Whatsnew for v. 1.9.50:
- bugfix due date exported as "invalid date" in excel and markdown
- filters back working, https://github.com/trapias/TrelloExport/issues/45
* Whatsnew for v. 1.9.51:
- bugfix export of checklists, comments and attachments to Excel
- change "prefix" filters to "string": all filters act as "string contains", no more "string starts with" since 1.9.40
* Whatsnew for v. 1.9.52:
- avoid saving local CSS to localstorage
- fix filters (reopened issue https://github.com/trapias/TrelloExport/issues/45)
- paginate loading of cards in bunchs of 300 (fix issue https://github.com/trapias/TrelloExport/issues/47)
* Whatsnew for v. 1.9.53:
- new look: the options dialog is now built with Tingle https://robinparisi.github.io/tingle/
- sponsor: support open source development!
* Whatsnew for v. 1.9.54:
- bugfix: export checklists with no items when selecting "one row per each checklist item"
- new feature: save selected columns to localStorage (issue https://github.com/trapias/TrelloExport/issues/48)
* Whatsnew for v. 1.9.55:
- fix exporting of custom fields (include only if requested)
- fix exporting of custom fields saved to localstorage
* Whatsnew for v. 1.9.56:
- enable export of custom fields for the 'Multiple Boards' type of export
* Whatsnew for v. 1.9.57:
- fix columns loading
* Whatsnew for v. 1.9.58:
- modified description in manifest to hopefully improve Chrome Web Store indexing
- really fix columns loading
- fix custom fields duplicates in excel
* Whatsnew for v. 1.9.59:
- HTML Twig: added "linkdoi" function to automatically link Digital Object Identifier (DOI) numbers to their URL, see http://www.doi.org/
- Apply filters with AND (all must match) or OR (match any) condition (issue #38)
* Whatsnew for v. 1.9.60:
- added MIT License (thanks Mathias https://github.com/mtn-gc)
- updated Bridge24 adv
* Whatsnew for v. 1.9.61:
- fix error in markdown export https://github.com/trapias/TrelloExport/issues/56
* Whatsnew for v. 1.9.62:
- fix issue #55, Export Done and Done By is missing for archived cards
- sort labels alphabetically
* Whatsnew for v. 1.9.63:
- fix unshowing button on team boards (issue #65, thanks https://github.com/varmais)
* Whatsnew for v. 1.9.64:
- fix some UI defects for the "export columns" dropdown
- new CSV export type
* Whatsnew for v. 1.9.65:
- fix exporting of Archived items to Excel and CSV
* Whatsnew for v. 1.9.66:
- added dueComplete field to exported columns
* Whatsnew for v. 1.9.67:
- added header x-trello-user-agent-extension to all AJAX calls to Trello, trying to find a solution for https://github.com/trapias/TrelloExport/issues/81
* Whatsnew for v. 1.9.68:
- avoid duplicate header row before archived cards in CSV export (issue #76)
- export the cards "start" field (issue #84)
* Whatsnew for v. 1.9.69:
- bugfix columns handling in loading data #74
* Whatsnew for v. 1.9.70:
- Load Trello Plus Spent/Estimate in comments
* Whatsnew for v. 1.9.71:
- manifest v3
- checklist items' due date, assignee and status added to checklists' mode excel export
* Whatsnew for v. 1.9.72:
- finally restored the capability to load templates from external URLs, issues #86 and #87
* Whatsnew for v. 1.9.73:
- update jquery
- fix OPML export of comments due date, issue #91
- improvements for issue #29
* Whatsnew for v. 1.9.74:
- fixed injection to adapt to modified Trello website
* Whatsnew for v. 1.9.75:
- actually fixed injection to adapt to modified Trello website
* Whatsnew for v. 1.9.76:
- Improved injection of TrelloExport button in menu
- Added error monitoring for 429 (rate limit) and 504 (timeout) errors
- Added small delays between API requests to reduce rate limit issues
* Whatsnew for v. 1.9.77:
- fix UI for HTML export
* Whatsnew for v. 1.9.78:
- Injection of TrelloExport button for Chinese (Traditional) language
* Whatsnew for v. 1.9.79:
- async data loading
- fix exporting cards in a list when requesting to export checklists
* Whatsnew for v. 1.9.80:
- complete async data loading
* Whatsnew for v. 1.9.81:
- fix loop in loading cards when using "select lists in current board" option
* Whatsnew for v. 1.9.82:
- fix error 403 in loading many cards: added automatic retry with exponential backoff for 403 errors
- optimize API requests: only request checklists/attachments/comments when needed based on selected columns
- removed unnecessary API parameters (organization_fields, membersInvited) that could trigger 403
- reduced member_fields from 'all' to 'fullName,username'
*/
var VERSION = '1.9.82';
/**
* Build optimized API URL parameters based on selected columns and export options
* This reduces payload size by only requesting necessary nested data (checklists, members, etc.)
* while keeping all card fields to ensure processing logic works correctly.
*
* The optimization focuses on the EXTRA params (checklists, attachments, members, actions)
* which are the heaviest part of the response. Card fields are always 'all' because
* the processing code accesses labels, idMembers, etc. regardless of column selection.
*
* @param {Array} selectedColumns - Array of selected column names
* @param {Boolean} bExportChecklists - Whether checklists export is enabled
* @param {Boolean} bExportComments - Whether comments export is enabled
* @param {Boolean} bExportAttachments - Whether attachments export is enabled
* @returns {Object} Object with { fields: string, params: string }
*/
function buildOptimizedApiParams(selectedColumns, bExportChecklists, bExportComments, bExportAttachments) {
// Always use all fields - the processing code accesses labels, idMembers, etc.
// regardless of which columns are selected for export
var fields = 'all';
// Build additional params - this is where we can optimize
var additionalParams = '';
// If no columns selected, use full params for backwards compatibility
if (!selectedColumns || selectedColumns.length === 0) {
return {
fields: 'all',
params: '&checklists=all&members=true&member_fields=fullName,username&attachments=true&actions=commentCard,copyCommentCard,updateCheckItemStateOnCard'
};
}
// Members handling - needed if Members column is selected
// Note: reduced member_fields from 'all' to only what we need
var needsMembers = selectedColumns.indexOf('Members') !== -1 ||
selectedColumns.indexOf('CreatedBy') !== -1 ||
selectedColumns.indexOf('DoneBy') !== -1;
if (needsMembers) {
additionalParams += '&members=true&member_fields=fullName,username';
}
// Checklists handling - needed if any checklist columns selected OR bExportChecklists is true
var checklistColumns = ['Total Checklist items', 'Completed Checklist items', 'Checklists',
'Checklist item', 'Completed', 'DateCompleted', 'CompletedBy',
'Checklist item Due', 'Checklist item idMember', 'Checklist item Member', 'Checklist item State'];
var needsChecklists = bExportChecklists || checklistColumns.some(function(col) {
return selectedColumns.indexOf(col) !== -1;
});
if (needsChecklists) {
additionalParams += '&checklists=all';
}
// Attachments handling - this can be a heavy response
var needsAttachments = bExportAttachments || selectedColumns.indexOf('Attachments') !== -1;
if (needsAttachments) {
additionalParams += '&attachments=true';
}
// Actions needed for comments and checklist completion tracking
var actionsNeeded = [];
var needsComments = bExportComments ||
selectedColumns.indexOf('NumberOfComments') !== -1 ||
selectedColumns.indexOf('Comments') !== -1;
if (needsComments) {
actionsNeeded.push('commentCard', 'copyCommentCard');
}
// updateCheckItemStateOnCard needed for checklist item completion dates
if (needsChecklists) {
actionsNeeded.push('updateCheckItemStateOnCard');
}
if (actionsNeeded.length > 0) {
additionalParams += '&actions=' + actionsNeeded.join(',');
}
console.log('[TrelloExport] Optimized API params - fields: ' + fields + ', params: ' + additionalParams);
return {
fields: fields,
params: additionalParams
};
}
// TWIG templates definition
var availableTwigTemplates = [
{ name: 'html', url: chrome.runtime.getURL('/templates/html.twig'), description: 'Default HTML' },
{ name: 'bibliography', url: chrome.runtime.getURL('/templates/bibliography.twig'), description: 'Bibliography HTML', css: chrome.runtime.getURL('/templates/bibliography.css'), },
{ name: 'newsletter', url: chrome.runtime.getURL('/templates/newsletter.twig'), description: 'Newsletter with buttons HTML', css: chrome.runtime.getURL('/templates/newsletter.css'), },
{ name: 'newsletter2', url: chrome.runtime.getURL('/templates/newsletter2.twig'), description: 'Newsletter with links HTML', css: chrome.runtime.getURL('/templates/newsletter.css'), }
];
var localTwigTemplates = availableTwigTemplates;
function loadTemplateSetFromURL(sUrl) {
console.log('loadTemplateSetFromURL:' + sUrl);
return new Promise(function (resolve, reject) {
if (!sUrl)
resolve(availableTwigTemplates);
var xhr = new XMLHttpRequest();
xhr.open("GET", sUrl, true);
xhr.onload = function () {
if (xhr.status == 200) {
// console.log('template set loaded: ' + JSON.parse(xhr.response));
resolve(xhr.response);
}
else {
reject({
status: xhr.status,
statusText: xhr.statusText
});
}
};
xhr.onerror = function () {
// Crossdomain request denied
if (xhr.status === 0) {
console.error(xhr.response)
}
reject({
status: xhr.status,
statusText: xhr.statusText
});
};
xhr.crossDomain = true;
xhr.withCredentials = false;
xhr.send();
});
}
function CleanLocalStorage() {
localStorage.TrelloExportCSS = '';
localStorage.TrelloExportMode = '';
localStorage.TrelloExportListDone = '';
localStorage.TrelloExportType = '';
localStorage.TrelloExportTwigTemplate = '';
localStorage.TrelloExportTwigTemplatesURL = '';
localStorage.TrelloExportSelectedColumns = '';
$.growl({
title: "TrelloExport",
message: "LocalStorage settings cleaned successfully. Please close and re-open TrelloExport.",
fixed: false
});
}
/**
* http://stackoverflow.com/questions/784586/convert-special-characters-to-html-in-javascript
* (c) 2012 Steven Levithan <http://slevithan.com/>
* MIT license
*/
if (!String.prototype.codePointAt) {
String.prototype.codePointAt = function(pos) {
pos = isNaN(pos) ? 0 : pos;
var str = String(this),
code = str.charCodeAt(pos),
next = str.charCodeAt(pos + 1);
// If a surrogate pair
if (0xD800 <= code && code <= 0xDBFF && 0xDC00 <= next && next <= 0xDFFF) {
return ((code - 0xD800) * 0x400) + (next - 0xDC00) + 0x10000;
}
return code;
};
}
/**
* Encodes special html characters
* @param string
* @return {*}
*/
function html_encode(string) {
var ret_val = '';
for (var i = 0; i < string.length; i++) {
var iC = string.codePointAt(i);
if (iC > 127) {
ret_val += '&#' + string.codePointAt(i) + ';';
} else {
switch (iC) {
case 34:
ret_val += """;
break;
case 38:
ret_val += "&";
break;
case 60:
ret_val += "<";
break;
case 62:
ret_val += ">";
break;
default:
ret_val += string.charAt(i);
break;
}
}
}
return ret_val;
}
String.prototype.replaceAll = function(search, replacement) {
var target = this;
return target.replace(new RegExp(search, 'g'), replacement);
};
function escape4XML(s) {
s = s.replaceAll('"', '"');
s = s.replaceAll("'", ''');
s = s.replaceAll('<', '<');
s = s.replaceAll('>', '>');
s = s.replaceAll('&', '&');
s = html_encode(s);
return s;
}
function sortByKeyDesc(array, key) {
return array.sort(function(a, b) {
var x = a[key];
var y = b[key];
return ((x > y) ? -1 : ((x < y) ? 1 : 0));
});
}
var $,
byteString,
xlsx,
ArrayBuffer,
Uint8Array,
actionsCreateCard = [],
actionsMoveCard = [],
actionsCommentCard = [],
idBoard,
nProcessedBoards = 0,
nProcessedLists = 0,
nProcessedCards = 0,
$excel_btn,
dataLimit = 1000, // limit the number of items retrieved from Trello (1000 is max allowed by Trello API server)
MAXCHARSPERCELL = 32767,
exportlists = [],
exportboards = [],
exportcards = [],
nameListDone = "Done",
filterListsNames = [],
pageSize = 25, // cfr https://trello.com/c/8MJOLSCs/10-limit-actions-for-cards-requests
customFields = [];
var allColumns = null;
function sheet_from_array_of_arrays(data, opts) {
var ws = {};
var range = {
s: {
c: 10000000,
r: 10000000
},
e: {
c: 0,
r: 0
}
};
for (var R = 0; R != data.length; ++R) {
for (var C = 0; C != data[R].length; ++C) {
if (range.s.r > R) range.s.r = R;
if (range.s.c > C) range.s.c = C;
if (range.e.r < R) range.e.r = R;
if (range.e.c < C) range.e.c = C;
var cell = {
v: data[R][C]
};
if (cell.v === null) continue;
var cell_ref = XLSX.utils.encode_cell({
c: C,
r: R
});
if (typeof cell.v === 'number') cell.t = 'n';
else if (typeof cell.v === 'boolean') cell.t = 'b';
else if (cell.v instanceof Date) {
cell.t = 'n';
cell.z = XLSX.SSF._table[14];
cell.v = datenum(cell.v);
} else cell.t = 's';
ws[cell_ref] = cell;
}
}
if (range.s.c < 10000000) ws['!ref'] = XLSX.utils.encode_range(range);
return ws;
}
function Workbook() {
if (!(this instanceof Workbook)) return new Workbook();
this.SheetNames = [];
this.Sheets = {};
}
function dd(s) {
return ('0' + s).slice(-2);
}
function s2ab(s) {
var buf = new ArrayBuffer(s.length);
var view = new Uint8Array(buf);
for (var i = 0; i != s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;
return buf;
}
if (typeof String.prototype.startsWith != 'function') {
String.prototype.startsWith = function(str) {
return this.indexOf(str) === 0;
};
}
if (typeof String.prototype.stringContains != 'function') {
String.prototype.stringContains = function(str) {
// console.log(this + ' CONTAINS ' + str + ' ? ' + this.indexOf(str) >= 0);
return this.indexOf(str) >= 0;
};
}
if (!String.prototype.endsWith) {
String.prototype.endsWith = function(search, this_len) {
if (this_len === undefined || this_len > this.length) {
this_len = this.length;
}
return this.substring(this_len - search.length, this_len) === search;
};
}
async function getCommentCardActions(boardID, idCard) {
for (var n = 0; n < actionsCommentCard.length; n++) {
if (actionsCommentCard[n].card === idCard) {
var query = Enumerable.From(actionsCommentCard[n].data)
.Where(function(x) {
if (x.data.card) {
return x.data.card.id == idCard;
}
})
.OrderByDescending(function(x) {
return x.date;
})
.ToArray();
return query.length > 0 ? query : false;
}
}
try {
const actionsData = await $.ajax({
headers: { 'x-trello-user-agent-extension': 'TrelloExport'},
url: 'https://trello.com/1/card/' + idCard + '/actions?filter=commentCard,copyCommentCard&limit=' + dataLimit,
// url:'https://trello.com/1/boards/' + boardID + '/actions?filter=commentCard,copyCommentCard&limit=' + dataLimit,
dataType: 'json'
});
var a = {
card: idCard,
data: actionsData,
};
actionsCommentCard.push(a);
var selectedActions = null;
for (var i = 0; i < actionsCommentCard.length; i++) {
if (actionsCommentCard[i].card === idCard) {
selectedActions = actionsCommentCard[i].data;
break;
}
}
var query2 = Enumerable.From(selectedActions)
.Where(function(x) {
if (x.data.card) {
return x.data.card.id == idCard;
}
})
.OrderByDescending(function(x) {
return x.date;
})
.ToArray();
return query2.length > 0 ? query2 : false;
} catch (error) {
console.error('Error fetching comment card actions:', error);
return false;
}
}
async function getCreateCardAction(boardID, idCard) {
for (var n = 0; n < actionsCreateCard.length; n++) {
if (actionsCreateCard[n].board === boardID) {
var query = Enumerable.From(actionsCreateCard[n].data)
.Where(function(x) {
if (x.data.card) {
return x.data.card.id == idCard;
}
})
.ToArray();
return query.length > 0 ? query[0] : false;
}
}
try {
const actionsData = await $.ajax({
headers: { 'x-trello-user-agent-extension': 'TrelloExport'},
url: 'https://trello.com/1/boards/' + boardID + '/actions?filter=createCard&limit=' + dataLimit,
dataType: 'json'
});
var a = {
board: boardID,
data: actionsData,
};
actionsCreateCard.push(a);
var selectedActions = null;
// get the right actions for board
for (var i = 0; i < actionsCreateCard.length; i++) {
if (actionsCreateCard[i].board === boardID) {
selectedActions = actionsCreateCard[i].data;
break;
}
}
var query2 = Enumerable.From(selectedActions)
.Where(function(x) {
if (x.data.card) {
return x.data.card.id == idCard;
}
})
.ToArray();
return query2.length > 0 ? query2[0] : false;
} catch (error) {
console.error('Error fetching create card action:', error);
return false;
}
}
async function getMoveCardAction(boardID, idCard, nameList) {
//console.log('getMoveCardAction ' + idCard + ' to list ' + nameList);
for (var n = 0; n < actionsMoveCard.length; n++) {
if (actionsMoveCard[n].board === boardID) {
var query = Enumerable.From(actionsMoveCard[n].data)
.Where(function(x) {
if (x.data.card && x.data.listAfter) {
if (x.data.card.id == idCard)
return x.data.card.id == idCard && x.data.listAfter.name.toLowerCase().stringContains(nameList.trim().toLowerCase());
//return x.data.card.id == idCard && x.data.listAfter.name == nameList;
}
})
.OrderByDescending(function(x) {
return x.date;
})
.ToArray();
//console.log('query.length: ' + query.length);
return query.length > 0 ? query[0] : false;
}
}
try {
const actionsData = await $.ajax({
headers: { 'x-trello-user-agent-extension': 'TrelloExport'},
url: 'https://trello.com/1/boards/' + boardID + '/actions?filter=updateCard&limit=' + dataLimit,
dataType: 'json'
});
var a = {
board: boardID,
data: actionsData,
};
actionsMoveCard.push(a);
var selectedActions = null;
// get the right actions for board
for (var i = 0; i < actionsMoveCard.length; i++) {
if (actionsMoveCard[i].board === boardID) {
selectedActions = actionsMoveCard[i].data;
break;
}
}
var query2 = Enumerable.From(selectedActions)
.Where(function(x) {
if (x.data.card && x.data.listAfter) {
return x.data.card.id == idCard && x.data.listAfter.name == nameList;
}
})
.OrderByDescending(function(x) {
return x.date;
})
.ToArray();
return query2.length > 0 ? query2[0] : false;
} catch (error) {
console.error('Error fetching move card action:', error);
return false;
}
}
function searchupdateCheckItemStateOnCardAction(checkitemid, actions) {
var completedObject = {};
$.each(actions, function(j, action) {
if (action.type == 'updateCheckItemStateOnCard') {
if (action.data.checkItem.id == checkitemid) {
var d = new Date(action.date);
if (d) {
var sActionDate = d.toLocaleDateString() + ' ' + d.toLocaleTimeString();
completedObject.date = sActionDate;
}
if (action.memberCreator !== undefined) {
completedObject.by = (action.memberCreator.fullName !== undefined ? action.memberCreator.fullName : action.memberCreator.username);
} else {
completedObject.by = '';
}
return completedObject;
}
}
});
return completedObject;
}
async function TrelloExportOptions() {
try {
// Check if extension context is still valid
if (!chrome.runtime?.id) {
console.error('[TrelloExport] Extension context invalidated');
alert('TrelloExport extension has been updated or reloaded. Please refresh the page and try again.');
return;
}
exportboards = []; // reset
exportlists = [];
exportcards = [];
filterListsNames = [];
nProcessedBoards = 0;
nProcessedLists = 0;
nProcessedCards = 0;
idBoard = document.location.pathname.split('/')[2];
var columnHeadings = [];
customFields = []; // reset
// Try to load column headings with error handling
try {
columnHeadings = await setColumnHeadings(0);
console.log('[TrelloExport] Loaded ' + columnHeadings.length + ' column headings');
} catch (error) {
console.error('[TrelloExport] Error loading column headings:', error);
// Fallback to default columns if API fails
columnHeadings = [
'Organization', 'Board', 'List', 'Card #', 'Title', 'Link', 'Description',
'Total Checklist items', 'Completed Checklist items', 'Checklists',
'NumberOfComments', 'Comments', 'Attachments', 'Votes', 'Spent', 'Estimate',
'Points Estimate', 'Points Consumed', 'Created', 'CreatedBy', 'LastActivity', 'Due',
'Done', 'DoneBy', 'DoneTime', 'Members', 'Labels'
];
$.growl.warning({
title: "TrelloExport",
message: "Using default columns due to loading error"
});
}
// https://github.com/davidstutz/bootstrap-multiselect
var options = [];
for (var x = 0; x < columnHeadings.length; x++) {
var isSelected = "selected";
// 1.9.54 saved selected columns
if (localStorage.TrelloExportSelectedColumns) {
isSelected = '';
var savedOptions = localStorage.TrelloExportSelectedColumns.split(',');
if ($.inArray(columnHeadings[x], savedOptions) > -1) {
isSelected = "selected";
}
}
var o = '<option value="' + columnHeadings[x] + '" ' + (isSelected === 'selected' ? 'selected="selected"' : '') + '>' + columnHeadings[x] + '</option>';
options.push(o);
}
var theCSS = chrome.runtime.getURL('/templates/default.css') || 'https://trapias.github.io/assets/TrelloExport/default.css';
if (localStorage.TrelloExportCSS && !localStorage.TrelloExportCSS.startsWith('chrome'))
theCSS = localStorage.TrelloExportCSS;
var selectedMode = 'XLSX';
if (localStorage.TrelloExportMode)
selectedMode = localStorage.TrelloExportMode;
// nameListDone
if (localStorage.TrelloExportListDone)
nameListDone = localStorage.TrelloExportListDone;
var selectedType = 'board';
if (localStorage.TrelloExportType)
selectedType = localStorage.TrelloExportType;
var twigTemplate = chrome.runtime.getURL('/templates/html.twig');
if (localStorage.TrelloExportTwigTemplate)
twigTemplate = localStorage.TrelloExportTwigTemplate;
// load templates from URL, e.g. https://trapias.github.io/assets/TrelloExport/templates.json
var templateSetURL = '';
if (localStorage.TrelloExportTwigTemplatesURL) {
templateSetURL = localStorage.TrelloExportTwigTemplatesURL;
loadTemplateSetFromURL(templateSetURL).then(function(tplset) {
var jtplset = JSON.parse(tplset);
availableTwigTemplates = jtplset.templates;
// console.log('availableTwigTemplates = ' + availableTwigTemplates);
$.growl({
title: "TrelloExport",
message: "Templates loaded successfully",
fixed: false
});
}, function(err) {
console.error('ERROR: ' + err);
});
}
var availableTwigTemplatesOptions = [];
for (var t = 0; t < availableTwigTemplates.length; t++) {
availableTwigTemplatesOptions.push('<option value="' + availableTwigTemplates[t].url + '">' + availableTwigTemplates[t].description + '</option>');
}
var customFieldsON = false;
if (localStorage.TrelloExportCustomFields)
customFieldsON = true;
var sDialog = '<span class="half"><h1>TrelloExport ' + VERSION + '</h1></span><span class="half blog-link"><h3><a target="_blank" href="https://github.com/trapias/TrelloExport/wiki">Help</a> <a target="_blank" href="https://trelloexport.trapias.it/blog/">Read the Blog!</a></h3></span><table id="optionslist">' +
'<tr><td><span data-toggle="tooltip" data-placement="right" data-container="body" title="Choose the type of file you want to export">Export to:</span></td><td><select id="exportmode"><option value="XLSX">Excel</option><option value="MD">Markdown</option><option value="HTML">HTML</option><option value="OPML">OPML</option><option value="CSV">CSV</option></select></td></tr>' +
'<tr><td><span data-toggle="tooltip" data-placement="right" data-container="body" title="Check all the kinds of items you want to export">Export:</span></td><td><input type="checkbox" id="exportArchived" title="Export archived items">Archived items ' +
'<input type="checkbox" id="comments" title="Export comments">Comments<br/><input type="checkbox" id="checklists" title="Export checklists">Checklists <input type="checkbox" id="attachments" title="Export attachments">Attachments <input type="checkbox" id="customfields" ' + (customFieldsON ? 'checked' : '') + ' title="Export Custom Fields">Custom Fields</td></tr>' +
'<tr id="cklAsRowsRow"><td><span data-toggle="tooltip" data-placement="right" data-container="body" title="Create one Excel row per each card, checklist item, label or card member">One row per each:</span></td><td><input type="radio" id="cardsAsRows" checked name="asrows" value="0"> <label for="cardsAsRows" >Card</label> <input type="radio" id="cklAsRows" name="asrows" value="1"> <label for="cklAsRows">Checklist item</label> <input type="radio" id="lblAsRows" name="asrows" value="2"> <label for="lblAsRows">Label</label> <input type="radio" id="membersAsRows" name="asrows" value="3"> <label for="membersAsRows">Member</label> </td></tr>' +
'<tr id="xlsColumns">' +
'<td><span data-toggle="tooltip" data-placement="right" data-container="body" title="Choose columns to be exported to Excel">Export columns</span></td>' +
'<td><select multiple="multiple" id="selectedColumns">' + options.join('') + '</select></td>' +
'</tr>' +
'<tr id="ckHTMLCardInfoRow" style="display:none"><td><span data-toggle="tooltip" data-placement="right" data-container="body" title="Set options for the target HTML">Options:</span></td><td><input type="checkbox" checked id="ckHTMLCardInfo" title="Export card info"> Export card info (created, createdby) <br/><input type="checkbox" checked id="chkHTMLInlineImages" title="Show attachment images"> Show attachment images' + '</td></tr>' +
'<tr id="renderingOptions" style="display:none"><td><span>Rendering Options:</span></td><td>Stylesheet: <input id="trelloExportCss" type="text" name="css" value="' + theCSS + '"> ' +
'<br>Template set:<input type="text" id="templateSetURL" placeholder="Insert URL or leave blank" title="Template-set URL - leave blank to use local templates" value="' + templateSetURL + '"><br>Template: <select id="twigTemplate" name="twigTemplate">' +
availableTwigTemplatesOptions.join(',') +
'</select></td></tr>' +
'<tr><td><span data-toggle="tooltip" data-placement="right" data-container="body" title="Set the List name string used to recognize your completed lists. See https://trapias.github.io/blog/trelloexport-1-9-13">Done lists name:</span></td><td><input type="text" size="4" name="setnameListDone" id="setnameListDone" value="' + nameListDone + '" placeholder="Set string or leave empty"></td></tr>' +
'<tr><td><span data-toggle="tooltip" data-placement="right" data-container="body" title="Only include items whose name contains the specified string">Filter:</span></td><td>' +
'<select id="filterMode"><option value="List">On List name</option><option value="Label">On Label name</option><option value="Card">On card name</option></select>' +
'<br/><input type="checkbox" id="chkANDORFilter"> <span title="Check to match all filters with an AND condition, uncheck to match any filter with an OR condition">Enable AND filter</span><br/>' +
'<input type="text" size="30" name="filterListsNames" class="filterListsNames" value="" placeholder="Set string or leave empty" /></td></tr>' +
'<tr><td><span data-toggle="tooltip" data-placement="right" data-container="body" title="Choose what data to export">Type of export:</span></td><td><select id="exporttype"><option value="board">Current Board</option><option value="list">Select Lists in current Board</option><option value="boards">Multiple Boards</option><option value="cards">Select cards in a list</option></select></td></tr>' +
'</table>';
var modal = new tingle.modal({
footer: true,
stickyFooter: true,
closeMethods: ['overlay', 'button', 'escape'],
closeLabel: "Close",
// cssClass: ['custom-class-1', 'custom-class-2'],
onOpen: function() {
// Small delay to ensure DOM is ready
setTimeout(function() {
initializeModal();
}, 100);
},
// onClose: function() {
// // console.log('modal closed');
// },
beforeClose: function() {
return true; // close the modal
// return false; // nothing happens
}
});
modal.setContent(sDialog);
modal.setFooterContent('<span class="sponsor"><a target="_new" href="https://bridge24.com/trello/?afmc=1w">Need interactive charts or custom reports for your cards? Try Bridge24! <img src="https://bridge24.com/wp-content/uploads/2017/12/bridge24-logo-header_dark-grey_2x.png" /></a></span>');
modal.addFooterBtn('Close', 'tingle-btn tingle-btn--default tingle-btn--pull-right', function() {
modal.close();
});
modal.addFooterBtn('Export', 'tingle-btn tingle-btn--trelloexport tingle-btn--pull-right', function() {
var mode = $('#exportmode').val();
localStorage.TrelloExportMode = mode;
nameListDone = $('#setnameListDone').val();
localStorage.TrelloExportListDone = nameListDone;
var sfilterListsNames, filters, bexportArchived, bExportComments, bExportChecklists, bExportAttachments, iExcelItemsAsRows, bckHTMLCardInfo, bchkHTMLInlineImages;
bexportArchived = $('#exportArchived').is(':checked');
bExportComments = $('#comments').is(':checked');
bExportChecklists = $('#checklists').is(':checked');
bExportAttachments = $('#attachments').is(':checked');
iExcelItemsAsRows = 0;
iExcelItemsAsRows = $('input[name=asrows]:checked').val();
bckHTMLCardInfo = $('#ckHTMLCardInfo').is(':checked');
bchkHTMLInlineImages = $('#chkHTMLInlineImages').is(':checked');
var bExportCustomFields = $('#customfields').is(':checked');
if (!bExportChecklists && iExcelItemsAsRows.toString() === '1') {
// checklist items as rows only available if checklists are exported
iExcelItemsAsRows = 0;
}
// export type
var sexporttype = $('#exporttype').val();
localStorage.TrelloExportType = sexporttype;
sfilterListsNames = $('.filterListsNames').val();
if (sfilterListsNames.trim() !== '') {
// parse list name filters
filters = sfilterListsNames.split(','); // OR filters
for (var nd = 0; nd < filters.length; nd++) {
filterListsNames.push(filters[nd].toString().trim());
}
}
switch (sexporttype) {
case 'list':
if ($('#choosenlist').length <= 0) {
// console.log('wait for lists to load');
return false;
} else {
$('#choosenlist > option:selected').each(function() {
exportlists.push($(this).val());
});
}
break;
case 'boards':
if ($('#choosenboards').length <= 0) {
// console.log('wait for lists to load');
return false;
} else {
$('#choosenboards > option:selected').each(function() {
exportboards.push($(this).val());
});
}
break;