Completed
Push — master ( 56c982...731a12 )
by Matthew
03:00
created

web/static/js/autoedits.js   A

Complexity

Total Complexity 7
Complexity/F 1.75

Size

Lines of Code 51
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 7
c 2
b 0
f 1
dl 0
loc 51
rs 10
cc 0
nc 1
mnd 1
bc 8
fnc 4
bpm 2
cpm 1.75
noi 1
1
$(function() {
2
    var newData;
3
4
    $('.tools-table').on('click', '.tools-toggle', function () {
5
        if (!newData) {
6
            // countsByTool must be cloned
7
            newData = Object.assign({}, window.countsByTool);
8
        }
9
10
        var index = $(this).data('index'),
11
            tool = $(this).data('tool'),
12
            $row = $(this).parents('tr');
0 ignored issues
show
Unused Code introduced by
The variable $row seems to be never used. Consider removing it.
Loading history...
13
14
        // must use .attr instead of .prop as sorting script will clone DOM elements
15
        if ($(this).attr('data-disabled') === 'true') {
16
            newData[tool] = window.countsByTool[tool];
17
            window.toolsChart.data.datasets[0].data[index] = parseInt(newData[tool], 10);
18
            $(this).attr('data-disabled', 'false');
19
        } else {
20
            delete newData[tool];
21
            window.toolsChart.data.datasets[0].data[index] = null;
22
            $(this).attr('data-disabled', 'true');
23
        }
24
25
        // gray out row in table
26
        $(this).parents('tr').toggleClass('excluded');
27
28
        // change the hover icon from a 'x' to a '+'
29
        $(this).find('.glyphicon').toggleClass('glyphicon-remove').toggleClass('glyphicon-plus');
30
31
        // update stats
32
        var total = 0;
33
        Object.keys(newData).forEach(function (tool) {
34
            total += parseInt(newData[tool], 10);
35
        });
36
        var toolsCount = Object.keys(newData).length;
37
        $('.tools--tools').text(
38
            toolsCount.toLocaleString() + " " +
39
            $.i18n('num-tools', toolsCount)
40
        );
41
        $('.tools--count').text(total.toLocaleString());
42
43
        window.toolsChart.update();
44
    });
45
46
    if ($('.non-auto-edits-container')[0]) {
47
        $.getJSON('/api/nonautomated_edits/en.wikipedia.org/L235/all/0').then(function (data) {
48
            $('.non-auto-edits-container').html(data.markup);
49
        });
50
    }
51
});
52