<commit_before>﻿/**
 * @fileoverview
 * Templates used by the http logger views
 */

window.templates = window.templates || ( window.templates = {} );

/**
 * Render the a definition list with a dt for each header and the dd with
 * the value. Add link to the relevant header spec if we have the URL
 */
 window.templates.header_definition_list = function(headers)
{
    var alphaheaders = [];
    for (name in headers) {alphaheaders.push(name)}
    alphaheaders = alphaheaders.sort();
    
    var dlbody = [];
    
    for (var i=0, name; name=alphaheaders[i]; i++)
    {
        var value = headers[name];e
        var dt = ['dt', name + ": "]
        if (name in http_header_specification_urls)
        {
            dt.push(['a', '(spec)',
                          'href', http_header_specification_urls[name],
                          'target', '_blank']);
        }
        
        dlbody.push(dt);
        
        if (typeof value == "string")
        {
            var dd = ['dd', value]
        }
        else
        {
            var dd = [];
            for (var n=0, e; e=value[n]; n++)
            {
                dd.push(['dd', e]);
            }
        }
        dlbody.push(dd);
    }
    var dl = ['dl', dlbody,
              'class', 'headerlist'
             ];
    
    return dl;
}

/**
 * Renders a single row of request data in the request list
 */
window.templates.request_list_row = function(n, r, sel)
{
    var a = [ 'tr',
        ['th',
             http_map_mime_to_type(get_mime_from_extension(r.request.path))             
         ],
        ['td', r.request.headers["Host" || "?" ] ],
        ['td', r.request.path],
        ['td', r.request.method],
        ['td', (r.response ? r.response.status : "-"), 'class', 'status-cell'],
        ['td', (r.duration != null ? r.duration : "-"), 'class', 'time-cell'],
        'data-requestid', r.id,
        'handler', 'request-list-select',
        'class', 'typeicon mime-' + http_map_mime_to_type(http_get_mime_from_extension(r.request.path))
        //,
        //'class', (r.id==sel ? 'request-list-select' : '')
    ];
    return a;
}

window.templates.request_summary = function(req)
{
    pairs = [];
    for (key in req.request.queryDict) { pairs.push([key, req.request.queryDict[key]]) }<commit_msg>Forgot to rename a function from the http resource refactor<commit_after>﻿/**
 * @fileoverview
 * Templates used by the http logger views
 */

window.templates = window.templates || ( window.templates = {} );

/**
 * Render the a definition list with a dt for each header and the dd with
 * the value. Add link to the relevant header spec if we have the URL
 */
 window.templates.header_definition_list = function(headers)
{
    var alphaheaders = [];
    for (name in headers) {alphaheaders.push(name)}
    alphaheaders = alphaheaders.sort();
    
    var dlbody = [];
    
    for (var i=0, name; name=alphaheaders[i]; i++)
    {
        var value = headers[name];e
        var dt = ['dt', name + ": "]
        if (name in http_header_specification_urls)
        {
            dt.push(['a', '(spec)',
                          'href', http_header_specification_urls[name],
                          'target', '_blank']);
        }
        
        dlbody.push(dt);
        
        if (typeof value == "string")
        {
            var dd = ['dd', value]
        }
        else
        {
            var dd = [];
            for (var n=0, e; e=value[n]; n++)
            {
                dd.push(['dd', e]);
            }
        }
        dlbody.push(dd);
    }
    var dl = ['dl', dlbody,
              'class', 'headerlist'
             ];
    
    return dl;
}

/**
 * Renders a single row of request data in the request list
 */
window.templates.request_list_row = function(n, r, sel)
{
    var a = [ 'tr',
        ['th',
             http_map_mime_to_type(http_get_mime_from_extension(r.request.path))             
         ],
        ['td', r.request.headers["Host" || "?" ] ],
        ['td', r.request.path],
        ['td', r.request.method],
        ['td', (r.response ? r.response.status : "-"), 'class', 'status-cell'],
        ['td', (r.duration != null ? r.duration : "-"), 'class', 'time-cell'],
        'data-requestid', r.id,
        'handler', 'request-list-select',
        'class', 'typeicon mime-' + http_map_mime_to_type(http_get_mime_from_extension(r.request.path))
        //,
        //'class', (r.id==sel ? 'request-list-select' : '')
    ];
    return a;
}

window.templates.request_summary = function(req)
{
    pairs = [];
    for (key in req.request.queryDict) { pairs.push([key, req.request.queryDict[key]]) }
{'fraction_non_alphanumeric': 0.15872331248652147, 'fraction_numerical': 0.0008626266982963123, 'mean_word_length': 1.9096612296110413, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, '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': '918268', 'n_tokens_mistral': 1452, 'n_tokens_neox': 1437, 'n_words': 339}