<commit_before>{% include "SGLiveChatBundle::DateToolkit.js.twig" %}

var SessionToolkit = {
    Global: {
        _timeOut: null,
        loadTimeout : function() {
            SessionToolkit.Visit._timeOut = window.setTimeout(function() {
                window.clearTimeout(SessionToolkit.Visit._timeOut);
                SessionToolkit.Global.refresh();
            }, 10000);
        },
        refresh: function() {
            jQuery.ajax({
                type : "GET",
                url : "{{ path('sglc_admin_console_sessions_service')}}",
                cache : false,
                dataType: 'json',
                success : function(json) {
                    SessionToolkit.Visit.Item.drawAll(json.visits);
                    SessionToolkit.Request.Item.drawAll(json.requests);
                    SessionToolkit.Global.Data.display(json.count);
                    SessionToolkit.Global.loadTimeout();
                },
                error : function(XMLHttpRequest) {
                    if (XMLHttpRequest.status == 401) {
                        location.href = '{{ path("_security_login")}}';
                    } else {
                        SessionToolkit.Global.loadTimeout();
                    }
                }
            });
        },
        Data: {
            display: function(json) {
                jQuery('#visitsCount').html(json.visits);
                jQuery('#requestChats h2').html('Requested Chats: ' + json.requests);
                jQuery('#operatorsOnlineCount').html(json.online_operators);

                var d = new Date();
                jQuery('#lastUpdate').html(d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds());
            }
        }
    },
    Visit: {
        _timeOut: null,
        loadTimeout : function() {
            SessionToolkit.Visit._timeOut = window.setTimeout(function() {
                window.clearTimeout(SessionToolkit.Visit._timeOut);
                SessionToolkit.Visit.refreshCurrentVisits();
            }, 10000);
        },
        refreshCurrentVisits:function() {
            jQuery('#currentVisits table tbody').html('');
            jQuery.ajax({
                type : "GET",
                url : "{{ path('sglc_admin_console_current_visits', {'_format': 'json'})}}",
                cache : false,
                dataType: 'json',
                success : function(json) {
                    SessionToolkit.Visit.loadTimeout();
                    SessionToolkit.Visit.Item.drawAll(json);
                },
                error : function(XMLHttpRequest) {
                    if (XMLHttpRequest.status == 401) {
                        location.href = '{{ path("_security_login")}}';
                    } else {
                        SessionToolkit.Visit.loadTimeout();
                    }
                }
            });
        },
        Item: {
            drawAll: function(json) {
                jQuery('#currentVisits table tbody').html('');
                jQuery.each(json, function(i, item) {
                    SessionToolkit.Visit.Item.draw(item);
                });
            },
            draw:function(item){
                var row = document.createElement('tr');
                jQuery(document.createElement('td')).html(item.visitor.id + '('+item.visitor.visits+')').appendTo(row);
                jQuery(document.createElement('td')).html(item.localtime).appendTo(row);
                jQuery(document.createElement('td')).html(item.hostname).appendTo(row);
                jQuery(document.createElement('td')).html(item.createdAt).appendTo(row);
                jQuery(document.createElement('td')).html(item.duration).appendTo(row);
                jQuery(document.createElement('td')).html(item.visitor.languages).appendTo(row);
                jQuery(document.createElement('td')).html(item.visitor.agent).appendTo(row);
                jQuery(document.createElement('td')).append(jQuery(document.createElement('a')).attr({href: item.visitor.currentPage}).html(item.visitor.currentPage)).appendTo(row);
                jQuery(document.createElement('td')).append(jQuery(document.createElement('a')).attr({href: item.visitor.currentPage}).html(item.visitor.referer)).appendTo(row);
                jQuery('#currentVisits table tbody').append(row);
                SessionToolkit.Visit.Item.drawHits(item);
            },
            drawHits: function (item) {
                var row = document.createElement('tr');
                jQuery(row).attr({
                    valign: 'top'
                });


                jQuery(document.createElement('td'))
                .append(jQuery(document.createElement('a')).attr({
                    href: '#'
                }).html('Hits +/-').click(function(){
                    jQuery('#visit_' + item.id).toggle();
                    return false;
                })).appendTo(row);

                jQuery(document.createElement('td')).attr({
                    colspan: 8
                })
                
                // div created
                .append(jQuery(document.createElement('div')).attr({ 
                    id: 'visit_'+item.id
                })

                // hits table created
                .append(jQuery(document.createElement('table')).attr({ 
                    width: '100%'
                }).css({
                    'background-color': '#EEE',
                    'color': '#000'
                }).append('<tr class="header"><td>Hit ID</td><td>Time</td><td>Duration</td><td>URL</td><td>Referrer</td></tr>'))).appendTo(row);

                // Hit row created
                jQuery.each(item.hits, function(j, item2){
                    jQuery(document.createElement('tr'))
                    .addClass(j % 2 == 0 ? 'td1' : '')
                    .append(jQuery(document.createElement('td')).html(item2.id))
                    .append(jQuery(document.createElement('td')).html(item2.createdAt))
                    .append(jQuery(document.createElement('td')).html(item2.duration))
                    .append(jQuery(document.createElement('td')).append(jQuery(document.createElement('a')).attr({href: item2.link}).html(item2.link)))
                    .append(jQuery(document.createElement('td')).append(jQuery(document.createElement('a')).attr({href: item2.referer}).html(item2.referer)))
                    .appendTo(jQuery(row).find('#visit_' + item.id + ' table'));
                });

                jQuery('#currentVisits table tbody').append(row);
                jQuery('#visit_' + item.id).toggle();
            }
        }
    },
    Request: {
        _timeOut: null,
        loadTimeout : function() {
            SessionToolkit.Request._timeOut = window.setTimeout(function() {
                window.clearTimeout(SessionToolkit.Request._timeOut);
                SessionToolkit.Request.refreshRequestedChats();
            }, 10000);
        },
        refreshRequestedChats : function() {
            jQuery.ajax({
                type : "GET",
                url : "{{ path('sglc_admin_console_requested_chats', {'_format': 'json'})}}",
                cache : false,
                dataType: 'json',
                success : function(json) {
                    SessionToolkit.Request.Item.drawAll(json);
                    SessionToolkit.Request.loadTimeout();
                },
                error : function(XMLHttpRequest) {
                    if (XMLHttpRequest.status == 401) {
                        location.href = '{{ path("_security_login")}}';
                    } else {
                        SessionToolkit.Request.loadTimeout();<commit_msg>Errors in hits table creation were resolved.<commit_after>{% include "SGLiveChatBundle::DateToolkit.js.twig" %}

var SessionToolkit = {
    Global: {
        _timeOut: null,
        loadTimeout : function() {
            SessionToolkit.Visit._timeOut = window.setTimeout(function() {
                window.clearTimeout(SessionToolkit.Visit._timeOut);
                SessionToolkit.Global.refresh();
            }, 10000);
        },
        refresh: function() {
            jQuery.ajax({
                type : "GET",
                url : "{{ path('sglc_admin_console_sessions_service')}}",
                cache : false,
                dataType: 'json',
                success : function(json) {
                    SessionToolkit.Visit.Item.drawAll(json.visits);
                    SessionToolkit.Request.Item.drawAll(json.requests);
                    SessionToolkit.Global.Data.display(json.count);
                    SessionToolkit.Global.loadTimeout();
                },
                error : function(XMLHttpRequest) {
                    if (XMLHttpRequest.status == 401) {
                        location.href = '{{ path("_security_login")}}';
                    } else {
                        SessionToolkit.Global.loadTimeout();
                    }
                }
            });
        },
        Data: {
            display: function(json) {
                jQuery('#visitsCount').html(json.visits);
                jQuery('#requestChats h2').html('Requested Chats: ' + json.requests);
                jQuery('#operatorsOnlineCount').html(json.online_operators);

                var d = new Date();
                jQuery('#lastUpdate').html(d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds());
            }
        }
    },
    Visit: {
        _timeOut: null,
        loadTimeout : function() {
            SessionToolkit.Visit._timeOut = window.setTimeout(function() {
                window.clearTimeout(SessionToolkit.Visit._timeOut);
                SessionToolkit.Visit.refreshCurrentVisits();
            }, 10000);
        },
        refreshCurrentVisits:function() {
            jQuery('#currentVisits table tbody').html('');
            jQuery.ajax({
                type : "GET",
                url : "{{ path('sglc_admin_console_current_visits', {'_format': 'json'})}}",
                cache : false,
                dataType: 'json',
                success : function(json) {
                    SessionToolkit.Visit.loadTimeout();
                    SessionToolkit.Visit.Item.drawAll(json);
                },
                error : function(XMLHttpRequest) {
                    if (XMLHttpRequest.status == 401) {
                        location.href = '{{ path("_security_login")}}';
                    } else {
                        SessionToolkit.Visit.loadTimeout();
                    }
                }
            });
        },
        Item: {
            drawAll: function(json) {
                jQuery('#currentVisits table:first tbody:first').html('');
                jQuery.each(json, function(i, item) {
                    SessionToolkit.Visit.Item.draw(item);
                });
            },
            draw:function(item){
                var row = document.createElement('tr');
                jQuery(document.createElement('td')).html(item.visitor.id + '('+item.visitor.visits+')').appendTo(row);
                jQuery(document.createElement('td')).html(item.localtime).appendTo(row);
                jQuery(document.createElement('td')).html(item.hostname).appendTo(row);
                jQuery(document.createElement('td')).html(item.createdAt).appendTo(row);
                jQuery(document.createElement('td')).html(item.duration).appendTo(row);
                jQuery(document.createElement('td')).html(item.visitor.languages).appendTo(row);
                jQuery(document.createElement('td')).html(item.visitor.agent).appendTo(row);
                jQuery(document.createElement('td')).append(jQuery(document.createElement('a')).attr({href: item.visitor.currentPage}).html(item.visitor.currentPage)).appendTo(row);
                jQuery(document.createElement('td')).append(jQuery(document.createElement('a')).attr({href: item.visitor.currentPage}).html(item.visitor.referer)).appendTo(row);
                jQuery('#currentVisits table:first tbody:first').append(row);
                SessionToolkit.Visit.Item.drawHits(item);
            },
            drawHits: function (item) {
                var row = document.createElement('tr');
                jQuery(row).attr({
                    valign: 'top'
                });


                jQuery(document.createElement('td'))
                .append(jQuery(document.createElement('a')).attr({
                    href: '#'
                }).html('Hits +/-').click(function(){
                    jQuery('#visit_' + item.id).toggle();
                    return false;
                })).appendTo(row);

                jQuery(document.createElement('td')).attr({
                    colspan: 8
                })
                
                // div created
                .append(jQuery(document.createElement('div')).attr({ 
                    id: 'visit_'+item.id
                })

                // hits table created
                .append(jQuery(document.createElement('table')).attr({ 
                    width: '100%'
                }).css({
                    'background-color': '#EEE',
                    'color': '#000'
                }).append('<tr class="header"><td>Hit ID</td><td>Time</td><td>Duration</td><td>URL</td><td>Referrer</td></tr>'))).appendTo(row);

                // Hit row created
                jQuery.each(item.hits, function(j, item2){
                    jQuery(document.createElement('tr'))
                    .addClass(j % 2 == 0 ? 'td1' : '')
                    .append(jQuery(document.createElement('td')).html(item2.id))
                    .append(jQuery(document.createElement('td')).html(item2.createdAt))
                    .append(jQuery(document.createElement('td')).html(item2.duration))
                    .append(jQuery(document.createElement('td')).append(jQuery(document.createElement('a')).attr({href: item2.link}).html(item2.link)))
                    .append(jQuery(document.createElement('td')).append(jQuery(document.createElement('a')).attr({href: item2.referer}).html(item2.referer)))
                    .appendTo(jQuery(row).find('#visit_' + item.id + ' table'));
                });

                jQuery('#currentVisits table:first tbody:first').append(row);
                jQuery('#visit_' + item.id).toggle();
            }
        }
    },
    Request: {
        _timeOut: null,
        loadTimeout : function() {
            SessionToolkit.Request._timeOut = window.setTimeout(function() {
                window.clearTimeout(SessionToolkit.Request._timeOut);
                SessionToolkit.Request.refreshRequestedChats();
            }, 10000);
        },
        refreshRequestedChats : function() {
            jQuery.ajax({
                type : "GET",
                url : "{{ path('sglc_admin_console_requested_chats', {'_format': 'json'})}}",
                cache : false,
                dataType: 'json',
                success : function(json) {
                    SessionToolkit.Request.Item.drawAll(json);
                    SessionToolkit.Request.loadTimeout();
                },
                error : function(XMLHttpRequest) {
                    if (XMLHttpRequest.status == 401) {
                        location.href = '{{ path("_security_login")}}';
                    } else {
                        SessionToolkit.Request.loadTimeout();
{'fraction_non_alphanumeric': 0.14309862817762173, 'fraction_numerical': 0.0055913139587803135, 'mean_word_length': 1.6097726501526977, 'pattern_counts': {'":': 4, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3437808', 'n_tokens_mistral': 4053, 'n_tokens_neox': 3774, 'n_words': 461}