-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplugin-filter-status.js
65 lines (57 loc) · 2.28 KB
/
plugin-filter-status.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
var status_colormap = {
safe: 'success',
unsafe: 'warning',
unchecked: 'secondary',
unavailable: 'danger',
duplicates: 'info',
incorrect: 'incorrect'
};
// Initialize filter plugin
var basicPluginFilter = new ActionButtonPlugin('app-plugin-filter-generic', 'Filter', 'fas fa-sliders-h', '#app-content-plugins-filter');
basicPluginFilter.render();
// Register filter buttons
config.status.available.forEach(function (status) {
// Filter button
var filter_btn_span = $('<span id="badge-filter-' + status +'">0</span>')
.addClass('badge' + (status_colormap[status] ? ' badge-' + status_colormap[status] : ''));
var filter_btn = $('<button id="btn-filter-' + status +'" type="button">' + status +' </button>')
.addClass('btn btn-outline-light btn-filter')
.append(filter_btn_span);
basicPluginFilter.registerButton(filter_btn);
});
// Initialize filter button
enableButtonFilter('.btn-filter');
// Initialize Listeners
$('body').on('filteredStatus objectAdd statusChange objectDelete basicAppConfigLoaded datasetLoaded', function (e) {
$('.btn-filter').each(function(){
var idstr = 'btn-filter-';
var status = $(this).get(0).id.substring(idstr.length);
if ($(this).hasClass('active')) {
$('.status-ref-' + status).addClass('filtered-status');
} else {
$('.status-ref-' + status).removeClass('filtered-status');
}
countObjectsByStatus();
});
})
// click button to filter by status
function enableButtonFilter (selector) {
$(selector).on('click', function () {
$(this).toggleClass('active');
$(this).trigger('filteredStatus');
});
}
// Function is counting all data filter by status
function countObjectsByStatus () {
var counts = {};
config.status.available.forEach(function (status) {counts[status] = 0});
if(data_objects[config.a.JSONContainer]) {
asArray(data_objects[config.a.JSONContainer]).forEach(function(e){
// e.g. {counts: {safe: 1}}
counts[e[config.v.statusElement]]++;
})
}
config.status.available.forEach(function (status) {
document.getElementById('badge-filter-' + status).innerHTML = counts[status];
})
}