monitor.js 2.15 KB
Newer Older
1
var results_table = null;
Administrator committed
2

3 4 5
function coop_init_datatable(params, data, cols, action_btn) {
    var buttons = [];
    var columns = [];
Administrator committed
6 7


8 9
    $.each(cols, function(i, e) {
        columns.push(e);
Administrator committed
10 11 12 13 14
    });



    var settings = {
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
        dom: '<lf<t>ip><"clear"><B>',
        lengthMenu : [
            [
                50,
                100,
                150,
                200,
                -1
            ],
            [
                50,
                100,
                150,
                200,
                'Tout'
            ]
        ],
        pageLength : 50,
        buttons: buttons,
Administrator committed
34

35 36 37 38 39 40
        columns: columns,
        //select: select ,
        rowId : "_id",
        data : data,
        language: {url : '/static/js/datatables/french.json'}
    };
Administrator committed
41 42


43
    return $('#results').DataTable(settings);
Administrator committed
44 45 46 47
}

var viewJSErrors = function() {
    $.get('/monitor/js_errors', {dataType: 'json'})
48 49 50 51 52 53 54 55 56 57
        .done(function(rData) {
            if (typeof rData.res.content != "undefined") {
                if (results_table) results_table.destroy();
                var data = [];
                var cols = [
                    {data: 'date', title: "Date"},
                    {data: 'module', title: "Module"},
                    {data: 'agent', title: "Signature nav."},
                    {data: 'context', title: "Contexte"},
                    {data: 'message', title: "Message"}
Administrator committed
58

59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
                ];

                rData.res.content.forEach(function(e) {
                    var line = e;

                    if (typeof e.data == 'object') {
                        line.context = e.data.ctx;
                        line.message = e.data.msg;
                        delete e.data;
                    } else {
                        line.context = '?';
                        line.message = e.data;
                    }
                    data.push(line);
                });
                console.log(data);
                results_table = coop_init_datatable(null, data, cols);
            }
        });
};
Administrator committed
79 80 81

$(document).ready(function() {
    if (coop_is_connected()) {
82 83
        $('header').show();
        $('.nav-list .js_errors').click(viewJSErrors);
Administrator committed
84
    }
85
});