forked from men232/plus-for-trello
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreport.js
5063 lines (4448 loc) · 193 KB
/
report.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
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
/// <reference path="intellisense.js" />
var g_bLoaded = false; //needed because DOMContentLoaded gets called again when we modify the page
var g_mapETypeParam = { "ALL": "", "EINCR": 1, "EDECR": -1, "ENEW": 2 };
var g_iTabCur = null; //invalid initially
var ITAB_REPORT = 0;
var ITAB_BYUSER = 1;
var ITAB_BYBOARD = 2;
var ITAB_CHART = 3;
var g_colorDefaultOver = "#B9FFA9";
var g_colorDefaultUnder = "#FFD5BD";
var g_bShowKeywordFilter = false;
var KEY_FORMAT_PIVOT_USER = "formatPivotUser";
var KEY_FORMAT_PIVOT_BOARD = "formatPivotBoard";
var KEY_bEnableTrelloSync = "bEnableTrelloSync";
var KEY_bIgnoreZeroECards = "bIgnoreZeroECards";
var keybEnterSEByCardComments = "bEnterSEByCardComments"; //review zig reuse shared globals loader
var keyrgKeywordsforSECardComment = "rgKWFCC";
const g_postFixHeaderLast = "*"; //special postfix for column headers
var g_namedReport = null; //stores named report from initial url param
var g_excludedColumns = {};
var g_bAllowNegativeRemaining = false;
var g_bNoGroupChart = false;
const g_strMessageNoGroupChart = "To view this chart type, group by other than 'S/E rows'.";
var g_lastGroupSelection = "";
var g_mapColorFromName = {};
var g_interactions = [];
const g_heightLine = 28;
const g_maxLegendsPerColumn = 30;
const g_maxLegendColumns = 3;
const PROP_LS_bShowedDefaultCPMCountsListFilter = "plus_showed_default_cpm_counts_list_filter";
const CF_PREFIX = "cf:";
const g_chartViews = { //do not modify existing options, as those could be in saved user's bookmarks
s: "s",
e: "e",
r: "r",
ser: "ser",
e1vse: "e1vse",
echange: "echange",
cardcount: "cardcount",
burndown: "burndown"
};
//fixed colors only for g_chartViews that have a single color
const g_colorsFixed={
s:"#D25656",
e: "#2196F3",
r: "#519B51",
cardcount: "#026AA7"
};
//domains for the various charts
const g_dnames = {
ser: "ser",
s: "s",
e: "e",
r: "r",
cardcount: "cardcount"
};
//maps dependencies between a column and card fields.
//Those on the RIGHT have a unique LEFT property (a card can only have one team and one board, so it appears under team and board)
//used for detecting if a grouped report column contains unique or "last" (*) values.
//see also https://docs.google.com/a/plusfortrello.com/spreadsheets/d/1ECujO3YYTa3akMdnCrQ5ywgWnqybJDvXnVLwxZ2tT-M/edit?usp=sharing
const g_columnData = {
user: ["user"],
team: ["idTeamH","idBoardH","idCardH"],
board: ["idBoardH", "idCardH"],
nameList: ["nameList", "idCardH"],
hashtagFirst: ["hashtags", "hashtagFirst", "idCardH"],
card: ["idCardH"],
dowName: ["dateString"],
week: ["week", "dateString"],
month: ["month", "dateString"],
dateString: ["dateString"],
keyword: ["keyword"],
archived: ["archived", "idCardH"],
boardShortLink: ["idBoardH", "idCardH"],
cardNumber: ["idCardH"],
cardCount: ["idCardH"],
cardShortLink: ["idCardH"],
deleted: ["deleted", "idCardH"],
dateDue: ["dateDue", "idCardH"],
dateCreated: ["dateCreated", "idCardH"],
e: ["e"],
e1st: ["e1st"],
eType: ["eType"],
labels: ["labels", "idCardH"],
members: ["members","idCardH"],
note: ["comment"],
r: ["r"],
s: ["s"],
cf: ["cf", "idCardH"] //any custom field
};
const g_mapColorTrello = {
green : "#61bd4f",
yellow: "#f2d600",
orange: "#ff9f1a",
red: "#eb5a46",
purple: "#c377e0",
blue: "#0079bf",
sky: "#00c2e0",
lime: "#51e898",
pink: "#ff78cb",
black: "#4d4d4d",
nocolor: "#b6bbbf"
};
var g_colours = { //thanks http://stackoverflow.com/a/1573141/2213940
"aliceblue": "#f0f8ff", "antiquewhite": "#faebd7", "aqua": "#00ffff", "aquamarine": "#7fffd4", "azure": "#f0ffff",
"beige": "#f5f5dc", "bisque": "#ffe4c4", "black": "#000000", "blanchedalmond": "#ffebcd", "blue": "#0000ff", "blueviolet": "#8a2be2", "brown": "#a52a2a", "burlywood": "#deb887",
"cadetblue": "#5f9ea0", "chartreuse": "#7fff00", "chocolate": "#d2691e", "coral": "#ff7f50", "cornflowerblue": "#6495ed", "cornsilk": "#fff8dc", "crimson": "#dc143c", "cyan": "#00ffff",
"darkblue": "#00008b", "darkcyan": "#008b8b", "darkgoldenrod": "#b8860b", "darkgray": "#a9a9a9", "darkgreen": "#006400", "darkkhaki": "#bdb76b", "darkmagenta": "#8b008b", "darkolivegreen": "#556b2f",
"darkorange": "#ff8c00", "darkorchid": "#9932cc", "darkred": "#8b0000", "darksalmon": "#e9967a", "darkseagreen": "#8fbc8f", "darkslateblue": "#483d8b", "darkslategray": "#2f4f4f", "darkturquoise": "#00ced1",
"darkviolet": "#9400d3", "deeppink": "#ff1493", "deepskyblue": "#00bfff", "dimgray": "#696969", "dodgerblue": "#1e90ff",
"firebrick": "#b22222", "floralwhite": "#fffaf0", "forestgreen": "#228b22", "fuchsia": "#ff00ff",
"gainsboro": "#dcdcdc", "ghostwhite": "#f8f8ff", "gold": "#ffd700", "goldenrod": "#daa520", "gray": "#808080", "green": "#008000", "greenyellow": "#adff2f",
"honeydew": "#f0fff0", "hotpink": "#ff69b4",
"indianred ": "#cd5c5c", "indigo": "#4b0082", "ivory": "#fffff0", "khaki": "#f0e68c",
"lavender": "#e6e6fa", "lavenderblush": "#fff0f5", "lawngreen": "#7cfc00", "lemonchiffon": "#fffacd", "lightblue": "#add8e6", "lightcoral": "#f08080", "lightcyan": "#e0ffff", "lightgoldenrodyellow": "#fafad2",
"lightgrey": "#d3d3d3", "lightgreen": "#90ee90", "lightpink": "#ffb6c1", "lightsalmon": "#ffa07a", "lightseagreen": "#20b2aa", "lightskyblue": "#87cefa", "lightslategray": "#778899", "lightsteelblue": "#b0c4de",
"lightyellow": "#ffffe0", "lime": "#00ff00", "limegreen": "#32cd32", "linen": "#faf0e6",
"magenta": "#ff00ff", "maroon": "#800000", "mediumaquamarine": "#66cdaa", "mediumblue": "#0000cd", "mediumorchid": "#ba55d3", "mediumpurple": "#9370d8", "mediumseagreen": "#3cb371", "mediumslateblue": "#7b68ee",
"mediumspringgreen": "#00fa9a", "mediumturquoise": "#48d1cc", "mediumvioletred": "#c71585", "midnightblue": "#191970", "mintcream": "#f5fffa", "mistyrose": "#ffe4e1", "moccasin": "#ffe4b5",
"navajowhite": "#ffdead", "navy": "#000080",
"oldlace": "#fdf5e6", "olive": "#808000", "olivedrab": "#6b8e23", "orange": "#ffa500", "orangered": "#ff4500", "orchid": "#da70d6",
"palegoldenrod": "#eee8aa", "palegreen": "#98fb98", "paleturquoise": "#afeeee", "palevioletred": "#d87093", "papayawhip": "#ffefd5", "peachpuff": "#ffdab9", "peru": "#cd853f", "pink": "#ffc0cb", "plum": "#dda0dd", "powderblue": "#b0e0e6", "purple": "#800080",
"red": "#ff0000", "rosybrown": "#bc8f8f", "royalblue": "#4169e1",
"saddlebrown": "#8b4513", "salmon": "#fa8072", "sandybrown": "#f4a460", "seagreen": "#2e8b57", "seashell": "#fff5ee", "sienna": "#a0522d", "silver": "#c0c0c0", "skyblue": "#87ceeb", "slateblue": "#6a5acd", "slategray": "#708090", "snow": "#fffafa", "springgreen": "#00ff7f", "steelblue": "#4682b4",
"tan": "#d2b48c", "teal": "#008080", "thistle": "#d8bfd8", "tomato": "#ff6347", "turquoise": "#40e0d0",
"violet": "#ee82ee",
"wheat": "#f5deb3", "white": "#ffffff", "whitesmoke": "#f5f5f5",
"yellow": "#ffff00", "yellowgreen": "#9acd32"
};
var g_namedParams = { //review move all here
dontQuery: "dontQuery",//1 when set
fromMarkAllViewed: "fromMAV",//1 when set
sortListNamed: "sortList",
namedReport: "named" //popup inline reports use this
};
var NR_POPUP_REMAIN = "_remain"; //used in report and html
var NR_HOME_REMAIN = "_remainHome"; //in plus home
var g_cSyncSleep = 0; //for controlling sync abuse
var g_bIgnoreEnter = false; //review zig
var FILTER_DATE_ADVANCED = "advanced";
var g_bNeedSetLastRowViewed = false;
var g_bAddParamSetLastRowViewedToQuery = false;
var g_rowidLastSyncRemember = -1;
var g_bBuildSqlMode = false;
var g_sortListNamed = null; //when not null, this array specifies the sort list by column name
var g_orderByWhenSortList = null; //stores the last "order by" at the moment we generated g_sortListNamed
var PIVOT_BY = {
year: "year",
month: "month",
week: "", //review: weird way to make default
day: "day"
};
//cache formats to avoid overloading sync. "format" is saved to sync so short names there to reduce sync usage
var g_dataFormatUser = { key: KEY_FORMAT_PIVOT_USER, interval: null, cLastWrite: 0, cCur: 0, format: { u: { c: g_colorDefaultUnder, v: null }, o: { c: g_colorDefaultOver, v: null } } };
var g_dataFormatBoard = { key: KEY_FORMAT_PIVOT_BOARD, interval: null, cLastWrite: 0, cCur: 0, format: { u: { c: g_colorDefaultUnder, v: null }, o: { c: g_colorDefaultOver, v: null } } };
var g_rgTabs = []; //tab data
function getCleanHeaderName(name) {
if (!name)
return "";
var ret = name.split('\xa0')[0]; //hack: added   (g_hackPaddingTableSorter) to headers for tablesorter so remove them
var iLast = ret.indexOf(g_postFixHeaderLast);
if (iLast > 0)
ret = ret.substr(0, iLast);
//remove parenthesis (R case)
iLast = ret.indexOf("(");
if (iLast > 0)
ret = ret.substr(0, iLast);
return ret.trim();
}
function buildUrlFromParams(params, bNoPopupMode, prefixCustom) {
if (bNoPopupMode) {
params["popup"] = 0;
params[g_namedParams.namedReport] = "";
}
else {
if (params["popup"] === undefined && g_bPopupMode)
params["popup"] = "1";
}
assert(!g_bBuildSqlMode);
return commonBuildUrlFromParams(params, prefixCustom || "report.html");
}
function updateNamedReport(url) {
if (g_namedReport)
localStorage.setItem(g_namedParams.namedReport + ":" + g_namedReport, url);
}
window.onerror = function (msg, url, lineNo, columnNo, error) {
var string = msg.toLowerCase();
var substring = "script error";
var message;
if (string.indexOf(substring) > -1) {
message = 'Script Error: See background browser console for details. ' + msg;
} else {
message = [
'Message: ' + msg,
'URL: ' + url,
'Line: ' + lineNo,
'Error object: ' + JSON.stringify(error)
].join(' - ');
}
console.log(message);
alert(message);
return false;
};
function updateUrlState(params) {
if (g_namedReport)
params[g_namedParams.namedReport] = g_namedReport;
if (g_sortListNamed)
params[g_namedParams.sortListNamed] = JSON.stringify(g_sortListNamed);
var url = buildUrlFromParams(params);
window.history.replaceState('data', '', url);
updateNamedReport(url);
}
var g_msLastLoadedGlobals = 0;
function loadStorageGlobals(callback) {
g_msLastLoadedGlobals = Date.now();
chrome.storage.sync.get([SYNCPROP_NO_SE, SYNCPROP_NO_EST, KEY_bIgnoreZeroECards, KEY_FORMAT_PIVOT_USER, KEY_FORMAT_PIVOT_BOARD, KEY_bEnableTrelloSync, keybEnterSEByCardComments, keyrgKeywordsforSECardComment], function (objs) {
if (objs[KEY_FORMAT_PIVOT_USER] !== undefined)
g_dataFormatUser.format = objs[KEY_FORMAT_PIVOT_USER];
if (objs[KEY_FORMAT_PIVOT_BOARD] !== undefined)
g_dataFormatBoard.format = objs[KEY_FORMAT_PIVOT_BOARD];
g_bEnableTrelloSync = objs[KEY_bEnableTrelloSync] || false;
g_bNoSE = objs[SYNCPROP_NO_SE] || false;
g_bNoEst = objs[SYNCPROP_NO_EST] || false;
g_optEnterSEByComment.loadFromStrings(objs[keybEnterSEByCardComments], objs[keyrgKeywordsforSECardComment]);
g_bAllowNegativeRemaining = objs[KEY_bIgnoreZeroECards] || false;
chrome.storage.local.get([LOCALPROP_PRO_VERSION], function (obj) {
if (chrome.runtime.lastError) {
alert(chrome.runtime.lastError.message);
return;
}
g_bProVersion = obj[LOCALPROP_PRO_VERSION] || false; //not using g_msStartPro
callback();
});
});
}
function loadTabs(parent) {
if (g_bBuildSqlMode)
return;
var tabs = parent.children(".agile_tabselector_list").find("a");
var i = 0;
for (; i < tabs.length; i++) {
var elem = tabs.eq(i);
g_rgTabs.push(elem.attr("href"));
elem.off().click(function () {
selectTab(-1, $(this).attr("href"));
return false;
});
}
}
function doResizeFromParent() {
assert(g_bBuildSqlMode);
setTimeout(function () {
window.parent.resizeMe(document.body.clientHeight + 60);
}, 0);
}
window.addEventListener('resize', function () {
if (g_iTabCur != null)
selectTab(g_iTabCur, undefined, true);
if (g_iTabCur == ITAB_CHART) {
if (g_chartContainer)
g_chartContainer.redraw();
}
if (g_bBuildSqlMode)
doResizeFromParent();
});
function selectTab(iTab, href, bForce) {
if (iTab == null) {
assert(g_iTabCur == null); //happens first time we init g_iTabCur
iTab = 0;
}
if (g_bBuildSqlMode) {
g_iTabCur = iTab;
return;
}
function postSelect() {
if (g_iTabCur == ITAB_CHART)
setTimeout(fillChart, 100); //wait for final layout
}
if (iTab == g_iTabCur && !bForce) {
postSelect();
return; //ignore
}
var params = getUrlParams();
iTab = selectTabUI(iTab, href);
g_iTabCur = iTab;
postSelect();
if (params["tab"] != iTab) {
if (params["tab"] || iTab != 0) { //not just an optimization. Print (ctrl+print) causes a resize. updating the url causes the print dialog to go away in windows chrome.
params["tab"] = iTab;
updateUrlState(params);
}
}
}
/* selectTabUI
*
* select by iTab or href
* to select by href pass -1 to iTab
* RETURNS: iTab selected (useful for href case)
**/
function selectTabUI(iTab, href) {
if (g_bBuildSqlMode)
return iTab;
var i = 0;
var selector = null;
var classSelected = "agile_report_tabselector_selected";
var selectedOld = $("." + classSelected);
selectedOld.removeClass(classSelected);
//selectedOld.parent().css("border-color", "#E8EBEE");
var elemsHide = null;
selectedOld.parent().removeClass("agile_tabcell_selected");
for (; i < g_rgTabs.length; i++) {
var cur = g_rgTabs[i];
if (i == iTab || (href && href == cur)) {
iTab = i;//for the href case
selector = cur;
}
else {
if (elemsHide)
elemsHide = elemsHide.add($(cur));
else
elemsHide = $(cur);
}
}
if (selector) {
var elem = $(selector);
var selectedNew = $(".agile_tabselector_list").find("a[href='" + selector + "']");
selectedNew.addClass(classSelected);
selectedNew.parent().addClass("agile_tabcell_selected");
function fixScroller() {
if (elemsHide)
elemsHide.hide();
var heightWindow = window.innerHeight;
elem.show();
if (g_bPopupMode && heightWindow > 470)
heightWindow = 470; //prevent weird animations in popup when we exceed the original height in calculations
var scroller = elem.find(iTab == ITAB_REPORT ? ".agile_tooltip_scroller" : ".agile_report_containerScroll");
setScrollerHeight(heightWindow, scroller, scroller);
}
setTimeout(function () {
fixScroller(); //this allows the tabs to refresh in case the tab is large (report tab)
}, 10);
}
return iTab;
}
function findMatchingKeywords(term, autoResponse) {
if (term == "*")
term = "";
var rg = [];
if (g_optEnterSEByComment.IsEnabled())
rg = g_optEnterSEByComment.rgKeywords;
autoResponse(term == "" ? rg : rg.filter(function (item) {
return (item.indexOf(term) >= 0);
}));
}
function findMatchingTeams(term, autoResponse) {
if (term == "*")
term = "";
var sql = "SELECT name FROM teams";
var sqlPost = " ORDER BY LOWER(name) ASC";
var paramsSql = [];
if (term != "") {
sql = sql + " where name LIKE ?";
paramsSql.push("%" + term + "%");
}
getSQLReport(sql + sqlPost, paramsSql, function (response) {
var rows = response.rows;
if (response.status != STATUS_OK || !rows) {
autoResponse([]);
return;
}
var ret = rows.map(v => v.name);
autoResponse(ret);
});
}
function findMatchingBoards(term, autoResponse) {
if (term == "*")
term = "";
var nameTeam = $("#team").val().trim();
var cWhere = 0;
var sql = "SELECT B.name FROM boards B";
var sqlPost = " ORDER BY LOWER(B.name) ASC";
var paramsSql = [];
if (nameTeam != "") {
sql = sql + " LEFT OUTER JOIN TEAMS T ON B.idTeam=T.idTeam where T.name LIKE ?";
paramsSql.push("%" + nameTeam + "%");
cWhere++;
}
if (term != "") {
if (cWhere == 0) {
sql = sql + " WHERE";
}
else {
sql = sql + " AND";
}
cWhere++;
sql = sql + " B.name LIKE ?";
paramsSql.push("%" + term + "%");
}
getSQLReport(sql + sqlPost, paramsSql, function (response) {
var rows = response.rows;
if (response.status != STATUS_OK || !rows) {
autoResponse([]);
return;
}
var ret = rows.map(v => v.name);
autoResponse(ret);
});
}
function findMatchingLabels(term, autoResponse) {
if (term == "*")
term = "";
var nameBoard = $("#board").val().trim();
var idBoard = $("#idBoard").val().trim();
var sql = null;
var sqlPost = " ORDER BY LOWER(labels.name) ASC";
var params = [];
var cWhere = 0;
if (idBoard.length > 0) {
sql = "SELECT labels.name FROM labels where idBoardShort = ?";
cWhere++;
params.push(idBoard);
}
else if (nameBoard.length > 0) {
sql = "SELECT distinct(labels.name) FROM labels join boards on labels.idBoardShort=boards.idBoard where boards.name LIKE ?";
cWhere++;
params.push("%" + nameBoard + "%");
}
else {
sql = "SELECT distinct(labels.name) FROM labels";
}
if (term != "") {
if (cWhere == 0) {
sql = sql + " WHERE";
}
else {
sql = sql + " AND";
}
cWhere++;
sql = sql + " labels.name LIKE ?";
if (g_bDummyLabel)
sql = sql + " AND labels.idLabel<>'" + IDLABEL_DUMMY + "'";
params.push("%" + term + "%");
}
getSQLReport(sql + sqlPost, params, function (response) {
var rows = response.rows;
if (response.status != STATUS_OK || !rows) {
autoResponse([]);
return;
}
var ret = rows.map(v => v.name);
autoResponse(ret);
});
}
function findMatchingLists(term, autoResponse) {
if (term == "*")
term = "";
var nameBoard = $("#board").val().trim();
var idBoard = $("#idBoard").val().trim();
var sql = null;
var sqlPost = " ORDER BY LOWER(lists.name) ASC";
var params = [];
var cWhere = 0;
if (idBoard.length > 0) {
sql = "SELECT lists.name FROM lists where idBoard = ?";
cWhere++;
params.push(idBoard);
}
else if (nameBoard.length > 0) {
sql = "SELECT distinct(lists.name) FROM lists join boards on lists.idBoard=boards.idBoard where boards.name LIKE ?";
cWhere++;
params.push("%" + nameBoard + "%");
}
else {
sql = "SELECT distinct(lists.name) FROM lists";
}
if (term != "") {
if (cWhere == 0) {
sql = sql + " WHERE";
}
else {
sql = sql + " AND";
}
cWhere++;
sql = sql + " lists.name LIKE ?";
params.push("%" + term + "%");
}
getSQLReport(sql + sqlPost, params, function (response) {
var rows = response.rows;
if (response.status != STATUS_OK || !rows) {
autoResponse([]);
return;
}
var ret = rows.map(v => v.name);
autoResponse(ret);
});
}
function findMatchingUsers(term, autoResponse) {
if (term == "*")
term = "";
var sql = "SELECT distinct(user) FROM history";
var sqlPost = " ORDER BY LOWER(user) ASC";
var params = [];
if (term != "") {
sql = sql + " where user LIKE ?";
params.push("%" + term + "%");
}
sql = sql + sqlPost;
getSQLReport(sql, params, function (response) {
var rows = response.rows;
if (response.status != STATUS_OK || !rows) {
autoResponse([]);
return;
}
console.warn('[findMatchingUsers]', response);
var ret = rows.map(v => v.user);
autoResponse(ret);
});
}
function findMatchingWeeks(term, autoResponse) {
if (term == "*")
term = "";
var date = new Date();
var rg = [];
var daysDelta = 7;
for (var i = 0; i < 53; i++) {
rg.push(getCurrentWeekNum(date));
date.setDate(date.getDate() - daysDelta);
}
autoResponse(term == "" ? rg : rg.filter(function (item) {
return (item.indexOf(term) >= 0);
}));
}
function findMatchingMonths(term, autoResponse) {
if (term == "*")
term = "";
var date = new Date();
var rg = [];
var daysDelta = 7;
date.setDate(1);
for (var i = 0; i < 24; i++) {
rg.push(getCurrentMonthFormatted(date));
date.setMonth(date.getMonth() - 1);
}
autoResponse(term == "" ? rg : rg.filter(function (item) {
return (item.indexOf(term) >= 0);
}));
}
var g_portBackground = null;
function setupNotifications() {
if (g_portBackground != null)
return;
g_portBackground = chrome.runtime.connect({ name: "registerForChanges" });
g_portBackground.onMessage.addListener(function (msg) {
if (msg.status != STATUS_OK)
return;
if (msg.event == EVENTS.DB_CHANGED) {
hiliteOnce($("#agile_reload_page").show(), 10000);
}
});
}
function updateURLPart(part) {
var params = getUrlParams();
var elem = $("#" + part);
var val = elem.val();
if (elem[0].type == "checkbox")
val = (elem[0].checked ? "true" : "");
if (params[part] != val) {
params[part] = val;
updateUrlState(params);
}
}
//Report bookmarks
//
//we create a special "Plus reports" folder inside Chrome Bookmarks bar.
//we use chrome sync to store the folder id (assumes Chrome keeps folder id of synced bookmarks)
//REVIEW: verify claim above
//if the sync id is invalid or nonexistent, we search by folder name. If that fails we create the folder.
//before saving the bookmark, the url is updated to reflect current report inputs
function createReportBookmark() {
const SYNCPROP_idFolderParentBookmark = "idFolderParentBookmark";
const nameFolderParent = "Plus reports";
var url = buildUrlFromParams(getUrlParams(), true); //cleans up url
chrome.storage.sync.get([SYNCPROP_idFolderParentBookmark], function (objs) {
var idFolderPlus = objs[SYNCPROP_idFolderParentBookmark] || null;
if (idFolderPlus) {
chrome.bookmarks.get(idFolderPlus, function (bookmarks) {
if (bookmarks && bookmarks.length == 1)
saveBookmark(bookmarks[0].id);
else
stepFindFolder();
});
} else {
stepFindFolder();
}
});
function stepFindFolder() {
chrome.bookmarks.search({ url: null, title: nameFolderParent }, function (nodes) {
if (nodes && nodes.length > 0) {
stepSaveFolderAndBookmark(nodes[0].id);
} else {
stepCreateFolder();
}
});
}
function stepCreateFolder() {
const idChromeBookmarksBar = "1"; //https://bugs.chromium.org/p/chromium/issues/detail?id=21330#c4
chrome.bookmarks.create({ parentId: idChromeBookmarksBar, title: nameFolderParent }, function (bookmark) {
if (bookmark)
stepSaveFolderAndBookmark(bookmark.id);
});
}
function stepSaveFolderAndBookmark(idBookmark) {
var pair = {};
pair[SYNCPROP_idFolderParentBookmark] = idBookmark;
chrome.storage.sync.set(pair, function () {
var err = chrome.runtime.lastError; //just reference it, but we proceed even in failure
saveBookmark(idBookmark);
});
}
function saveBookmark(idParent) {
var title = window.prompt('Bookmark name:');
if (!title)
return;
title = title.trim();
chrome.bookmarks.create({ parentId: idParent, title: title, url: url }, function (bookmark) {
if (!bookmark)
alert('Error saving bookmark :(');
else {
chrome.bookmarks.get(idParent, function (bookmarks) {
if (bookmarks && bookmarks.length == 1)
sendDesktopNotification("Saved in '"+bookmarks[0].title+"' Chrome bookmark folder.", 4000);
});
}
});
}
}
//see https://docs.google.com/a/plusfortrello.com/spreadsheets/d/1ECujO3YYTa3akMdnCrQ5ywgWnqybJDvXnVLwxZ2tT-M/edit?usp=sharing
var g_mapNameFieldToInternal = {
team: "idTeamH",
board: "idBoardH",
list: "nameList",
card: "idCardH",
hashtag: "hashtagFirst",
hashtag1: "hashtagFirst",
hashtags: "hashtags",
labels: "labels",
user: "user",
keyword: "keyword",
date: "dateString",
dowName: "dowName",
week: "week",
month: "month",
note: "comment"
};
function refreshBuildSqlMode(params) {
if (params["board"] || !params["idBoard"]) {
$("#team").parent().show();
$("#board").parent().show();
}
else {
$("#board").parent().hide();
$("#team").parent().hide();
}
}
function updateOutputFormat(format) {
var msg;
if (!format || format == "csv")
msg = "Can cause <A href='http://stackoverflow.com/questions/4438589' target='_blank'>issues with special characters</A> when opening in Excel.";
else
msg = "Note about the <A href='https://support.microsoft.com/en-us/help/948615' target='_blank'>warning in Excel</A>.";
$("#noteExportFormat").html(msg);
}
document.addEventListener('DOMContentLoaded', function () {
g_progress.init();
loadStorageGlobals(function () {
loadAll();
});
//setTimeout(loadAll,100); //review this might help reduce timing issues
});
function loadAll() {
//chrome Content Security Policy (CSP) needs DOMContentLoaded
if (g_bLoaded)
return;
g_bLoaded = true;
//any params that do not have a UI counterpart will be stripped later, so get them here and set a few global states
var params = getUrlParams();
var bDisableSort = false;
var namedReport = params[g_namedParams.namedReport];
var bNeedReplaceState = false;
g_bPopupMode = (params["popup"] == "1"); //this one wins over saved one
g_bBuildSqlMode = (params["getsql"] == "1");
function cleanText(text) {
text = text.replace(/<br>/g, '\n');
text = text.replace(/<br \/>/g, '\n');
text = text.replace(/<br\/>/g, '\n');
text = text.replace(/<.*>/g, '');
return text;
}
if (g_bBuildSqlMode) {
$(".agile_report_filter").each(function () {
var elem = $(this);
var text = elem.prev('.report_tooltip').text();
if (text.length == 0)
return;
elem.prop("title", cleanText(text));
});
}
if (!g_bBuildSqlMode) {
$(".agile_report_filter").each(function () {
$(this).qtip({
content: $(this).prev('.report_tooltip'),
hide: {
fixed: true, //to click anchors
delay: 700 //stay up a little so its harder to accidentally move a little the mouse and close it
},
style: {
classes: "qtip-light"
},
my: 'top left',
at: 'bottom right',
effect: false,
position: {
target: false,
viewport: $(window),
adjust: {
method: 'flip flip'
}
},
show: {
solo: true
},
}
);
});
}
$("#selectAllColumns").bsmSelect({
addItemTarget: 'bottom',
animate: true,
highlight: true,
listClass: "bsmListCustomColumns",
plugins: [
$.bsmSelect.plugins.sortable({ axis: 'y', opacity: 0.5 }, { }),
$.bsmSelect.plugins.compatibility()
]
});
$("#checkCustomColumns").change(function () {
var bChecked = ($("#checkCustomColumns")[0].checked == true);
var elemSection = $("#section_customColumns");
if (!bChecked) {
elemSection.hide();
} else {
elemSection.show();
}
});
$("#checkOutputReport").change(function () {
var elemOutputFormatHelp = $("#noteExportFormat");
if (this.checked)
elemOutputFormatHelp.show();
else
elemOutputFormatHelp.hide();
});
$("#outputFormat").change(function () {
updateOutputFormat($(this).val());
});
addTableSorterParsers();
if (!g_bBuildSqlMode)
hitAnalytics("Reports", "open-" + (g_bPopupMode ? "inPopup" : "window"), true);
if (namedReport) {
g_namedReport = namedReport;
if (params["useStoredNamed"]) {
var urlNew = localStorage.getItem(g_namedParams.namedReport + ":" + namedReport);
if (urlNew) {
params = getUrlParams(urlNew);
//for safety prevent bad params from getting stuck
params["popup"] = (g_bPopupMode ? "1" : "0");
params["getsql"] = (g_bBuildSqlMode ? "1" : "0");
bNeedReplaceState = true;
}
}
if (g_namedReport == NR_POPUP_REMAIN || g_namedReport == NR_HOME_REMAIN) {
bDisableSort = true;
params["orderBy"] = "remain"; //force. we disable it so user could get stuck if someone the combo changes (in theory shouldnt change thou)
bNeedReplaceState = true;
}
}
if (bNeedReplaceState) {
if (g_namedReport)
params[g_namedParams.namedReport] = g_namedReport;
window.history.replaceState('data', '', buildUrlFromParams(params));
}
if (!g_bPopupMode)
$("body").removeClass("agile_report_minSize");
else
$(".agile_report_filters").addClass("agile_report_filters_smaller");
if (g_bBuildSqlMode) {
$("#tabs").hide();
$("#agile_title_header_report").hide();
$("#groupBy").parent().hide();
$("#pivotBy").parent().hide();
$("#orderBy").parent().hide();
$("body").css("margin-top", "0px");
$("#report_top_section").css("margin-bottom", "0px");
$("#buttonFilter").appendTo($(".agile_alternate_filterPos"));
refreshBuildSqlMode(params);
doResizeFromParent();
}
loadTabs($("#tabs"));
if (g_bNoSE)
$(".agile_tab_pivot").hide();
if (bDisableSort)
$("#orderBy").prop('disabled', true);
if (g_bNoSE) {
$("#pivotBy").parent().hide();
$("#user").parent().hide();
$("#comment").parent().hide();
$("#groupBy option[value*='user']").remove();
$("#groupBy option[value*='comment']").remove();
$("#groupBy option[value='']").remove();
$("#orderBy option[value='spent']").remove();
$("#orderBy option[value='est']").remove();
$("#orderBy option[value='user']").remove();
}
if (g_bNoSE || g_bNoEst) {
$("#orderBy option[value*='remain']").remove();
$("#eType").parent().hide();
}
if (g_bPopupMode) {
$("#spanChartHeight").hide();
$("#team").parent().hide();
$("#archived").parent().hide();
$("#deleted").parent().hide();
$("#eType").parent().hide();
if (g_bPopupMode && !bDisableSort) {
$("#orderBy option[value*='remain']").remove();
}
$("#card").parent().hide();
//$("#list").parent().hide();
$("#comment").parent().hide();
if (params["orderBy"] == "remain") {
$("#sinceSimple").parent().hide();
$("#pivotBy").parent().hide();
$(".agile_tab_rest").hide();
$(".agile_tab_chart").show();
}
}
else {
$("#spanChartHeight").show();
$("#archived").parent().show();
$("#deleted").parent().show();
}
if (g_bPopupMode) {
$("#report_title_rightLinks").hide();
//$("body").height(470); //these two are also duplicated in report.html body so that reports opened from the popup (spent this week) has the right size (prevent flicker)
//$("body").width(685);
var dockOut = $("#dockoutImg");
dockOut.attr("src", chrome.extension.getURL("images/dockout.png"));
dockOut.show();
dockOut.css("cursor", "pointer");
var back = $("#backImg");
back.attr("src", chrome.extension.getURL("images/back.png"));
back.show();
back.css("cursor", "pointer");
back.off().click(function () {
window.history.back();
return false;
});
} else {
$("#report_title_rightLinks").show();
}
openPlusDb(function (response) {
if (response.status != STATUS_OK) {
return;
}
if (!g_bBuildSqlMode)
setupNotifications();
$("#agile_reload_page_link").off().click(function (e) {
e.preventDefault();
var params = getUrlParams();
if (g_bAddParamSetLastRowViewedToQuery)
params["setLastRowViewed"] = "true";
configReport(params, true);
});
$("#chartView").change(function () {