Passed
Push — master ( cddcf6...1d3855 )
by Alexander
01:59
created

tcms/testruns/static/testruns/js/search.js   A

Complexity

Total Complexity 18
Complexity/F 2

Size

Lines of Code 113
Function Count 9

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 0
eloc 74
c 3
b 0
f 0
nc 1
dl 0
loc 113
rs 10
wmc 18
mnd 1
bc 19
fnc 9
bpm 2.1111
cpm 2
noi 9

1 Function

Rating   Name   Duplication   Size   Complexity  
B $(document).ready 0 93 1
1
function pre_process_data(data) {
2
    var product_cache = {};
3
    var tags_cache = {};
4
5
    data.forEach(function(element) {
6
        // collect info about products
7
        addResourceToData(element, 'tag', 'Tag.filter', tags_cache);
8
9
        if (element.plan_id in product_cache) {
10
            element['product'] = product_cache[element.plan_id];
11
        } else {
12
            jsonRPC('TestPlan.filter', {pk: element.plan_id}, function(data) {
13
                element['product'] = data[0].product;
14
            }, true);
15
            product_cache[element.plan_id] = element.product;
16
        }
17
    });
18
}
19
20
21
$(document).ready(function() {
22
    var table = $("#resultsTable").DataTable({
23
        ajax: function(data, callback, settings) {
0 ignored issues
show
Unused Code introduced by
The parameter settings is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
24
            var params = {};
25
26
            if ($('#id_summary').val()) {
27
                params['summary__icontains'] = $('#id_summary').val();
28
            }
29
30
            if ($('#id_plan').val()) {
31
                params['plan'] = $('#id_plan').val();
32
            }
33
34
            if ($('#id_product').val()) {
35
                params['plan__product'] = $('#id_product').val();
36
            };
37
38
            if ($('#id_version').val()) {
39
                params['product_version'] = $('#id_version').val();
40
            };
41
42
            if ($('#id_build').val()) {
43
                params['build'] = $('#id_build').val();
44
            };
45
46
            if ($('#id_manager').val()) {
47
                params['manager__username__startswith'] = $('#id_manager').val();
48
            };
49
50
            if ($('#id_default_tester').val()) {
51
                params['default_tester__username__startswith'] = $('#id_default_tester').val();
52
            };
53
54
            updateParamsToSearchTags('#id_tag', params);
55
56
            params['stop_date__isnull'] = $('#id_running').is(':checked');
57
58
            dataTableJsonRPC('TestRun.filter', params, callback, pre_process_data);
59
        },
60
        columns: [
61
            { data: "run_id" },
62
            {
63
                data: null,
64
                render: function (data, type, full, meta) {
0 ignored issues
show
Unused Code introduced by
The parameter type is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter full is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter meta is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
65
                    result = '<a href="/runs/'+ data.run_id + '/" target="_parent">' + escapeHTML(data.summary) + '</a>';
0 ignored issues
show
Bug introduced by
The variable result seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.result.
Loading history...
66
                    if (data.stop_date) {
67
                        result += '<p class="help-block">' + data.stop_date + '</p>';
68
                    }
69
                    return result;
70
                }
71
            },
72
            {
73
                data: null,
74
                render: function (data, type, full, meta) {
0 ignored issues
show
Unused Code introduced by
The parameter type is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter meta is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter full is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
75
                    return '<a href="/plan/'+ data.plan_id + '/" target="_parent">TP-' + data.plan_id + ': ' + escapeHTML(data.plan) + '</a>';
76
                }
77
            },
78
            { data: "product" },
79
            { data: "product_version"},
80
            { data: "build"},
81
82
            { data: "manager" },
83
            { data: "default_tester" },
84
            {
85
                data: "tag",
86
                render: renderFromCache,
0 ignored issues
show
Bug introduced by
The variable renderFromCache seems to be never declared. If this is a global, consider adding a /** global: renderFromCache */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
87
            },
88
        ],
89
        dom: "t",
90
        language: {
91
            loadingRecords: '<div class="spinner spinner-lg"></div>',
92
            processing: '<div class="spinner spinner-lg"></div>',
93
            zeroRecords: "No records found"
94
        },
95
        order: [[ 0, 'asc' ]],
96
    });
97
98
    hookIntoPagination('#resultsTable', table);
99
100
    $('#btn_search').click(function() {
101
        table.ajax.reload();
102
        return false; // so we don't actually send the form
103
    });
104
105
    $('#id_product').change(function() {
106
        update_version_select_from_product();
107
        update_build_select_from_product(true);
108
    });
109
110
    $('.bootstrap-switch').bootstrapSwitch();
111
112
    $('.selectpicker').selectpicker();
113
});
114