This repository has been archived by the owner on Aug 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 94
/
table.js
201 lines (181 loc) · 5.99 KB
/
table.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
define(['jquery', 'bootstrap', 'chroma', 'tablesorter', 'stickykit'],
function($, bootstrap, chroma, tablesorter, stickykit) {
var placeCount = placeCount || 260,
colorSteps = ['#ff0000', '#edcf3b', '#7ab800'],
colorScale = chroma.scale(colorSteps).domain([0, 100]),
naString = 'n/a',
$dataTable = $('.data-table'),
$scoreDisplay = $('.score'),
popover_tmpl = '<div class="popover" role="tooltip"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content"></div></div>',
tablesorterPlaceOptions = {
sortList: [[1, 0]],
headers: {
2: {sorter: false},
3: {sorter: false},
4: {sorter: false},
5: {sorter: false},
6: {sorter: false},
7: {sorter: false},
8: {sorter: false},
9: {sorter: false},
10: {sorter: false},
11: {sorter: false}
}
},
tablesorterPlaceIndexOptions = {
sortList: [[0, 0]],
headers: {
2: {sorter: false},
3: {sorter: false},
4: {sorter: false},
5: {sorter: false},
6: {sorter: false},
7: {sorter: false},
8: {sorter: false},
9: {sorter: false},
10: {sorter: false},
11: {sorter: false}
}
},
tablesorterDatasetOptions = {
sortList: [[0, 0]],
headers: {
2: {sorter: false},
3: {sorter: false}
}
},
tablesorterSliceOptions = {
sortList: [[1, 0]],
headers: {
2: {sorter: false},
3: {sorter: false},
4: {sorter: false},
6: {sorter: false}
}
},
tablesorterSliceIndexOptions = {
sortList: [[0, 0]],
headers: {
2: {sorter: false},
3: {sorter: false},
4: {sorter: false},
6: {sorter: false}
}
},
tablesorterPlaceSliceOptions = {
sortList: [[4, 1]],
headers: {
1: {sorter: false},
2: {sorter: false},
3: {sorter: false},
5: {sorter: false}
}
},
tablesorterPlaceSliceIndexOptions = {
sortList: [[3, 1]],
headers: {
1: {sorter: false},
2: {sorter: false}
}
},
sortFlag = true;
$('#places_overview_table').tablesorter(tablesorterPlaceOptions);
$('#places_overview_table_index').tablesorter(tablesorterPlaceIndexOptions);
$('#datasets_overview_table').tablesorter(tablesorterDatasetOptions);
$('#slice-table').tablesorter(tablesorterSliceOptions);
$('#slice-table-index').tablesorter(tablesorterSliceIndexOptions);
$('#place-slice-table').tablesorter(tablesorterPlaceSliceOptions);
$('#place-slice-table-index').tablesorter(tablesorterPlaceSliceIndexOptions);
$('#datasets_overview_table thead').stick_in_parent();
$('#slice-table thead').stick_in_parent();
$('.content').on('click', '.sort_rank, .sort_place',
function(e) {
$('#places_overview_table, #places_overview_table_index').trigger('sorton',
[[[$(e.target).hasClass('sort_place') / 1, sortFlag]]]);
$('.headerSortDown').removeClass('headerSortDown');
$('.headerSortUp').removeClass('headerSortUp');
$(e.target).addClass((sortFlag) ? 'headerSortUp' : 'headerSortDown');
sortFlag = !sortFlag;
}
);
// Ensure .details and .submissions table rows appear under their
// appropriate parent row, even after sorting.
$('.slice-table').bind('sortEnd', function() {
$('.slice-table .entry').each(function(i, el) {
$('.slice-table .submission-' + el.id).insertAfter(el);
$('.slice-table #detail-' + el.id).insertAfter(el);
});
$('.slice-table .submission').each(function(i, el) {
$('.slice-table #detail-' + el.id).insertAfter(el);
});
});
function filterTable(table, query) {
if (query.length < 2) {
return;
}
table.find('tbody tr').each(function(index, value) {
if ($(this).data('name').toLowerCase().indexOf(query) === -1) {
$(this).hide();
} else {
$(this).show();
}
});
}
function setInteractions() {
$("[data-toggle='tooltip']").tooltip({html: true});
$('[data-toggle="popover"]').popover({
trigger: 'click',
'placement': 'bottom',
'html': true,
'show': true,
'template': popover_tmpl
});
$('[data-toggle="popover"]').on('click', function() {
$('[data-toggle="popover"]').not(this).popover('hide');
});
$('body').on('click', 'td.showpopover', function() {
var $this = $(this);
// check if the one clicked is now shown
if ($this.data('popover').tip().hasClass('in')) {
// if another was showing, hide it
if ($visiblePopover) {
$visiblePopover.popover('hide');
}
// then store reference to current popover
$visiblePopover = $this;
} else { // if it was hidden, then nothing must be showing
$visiblePopover = '';
}
});
$('.filter-table').on('keyup', function() {
var query = $(this).val().toLowerCase().replace(' ', '-')
.replace(',', '');
filterTable($dataTable, query);
});
$.each($scoreDisplay, function(index, el) {
var score,
$el = $(el);
if ($el.data('score') === naString) {
score = 0;
} else {
score = parseInt($el.data('score'), 10);
}
$el.css({
'background-color': colorScale(score).hex(),
'color': 'white'
});
});
}
function setColumnTHWidths() {
$('thead th').each(function() {
$(this).css('width', $(this).outerWidth());
});
}
function initializeTable() {
setInteractions();
setColumnTHWidths();
}
return {
init: initializeTable
};
});