<commit_before>/* jshint browser:true, globalstrict:true */
/* global angular:true */
"use strict";

angular.module('webPGQ.directives')
    .directive('resultValue', ['$window', '$', '_', 'hljs', 'queueDigest', function($window, $, _, hljs, queueDigest)
    {
        var prettyPrint = true;

        // Number of pixels to subtract from the available space when setting max width/height of the detail popup.
        var sizeAdjustment = 10;

        var defaultPopupSettings = {
            on: 'click',
            //position: 'top center', //FIXME: If we use 'top center', semantic ONLY checks '* center' positions!
            position: 'top left',
            variation: 'inverted',
            className: { popup: 'code ui popup' },
        };

        var firstLineRE = /^([^\n]*)\n/;

        var geomFieldNameRE = /geo|shape|wk[bt]|[gk]ml|svg|x3d/i;

        var maybeJSONRE = /^\s*(?:\{[^]*\}|\[[^]*\]|".*"|\d+(?:\.\d*)?|\.\d+|null)\s*$/;
        var maybeEWKTRE = /^\s*(?:SRID\s*=\s*\d+\s*;\s*)?\w+\s*\([^]*\)\s*$/;
        var maybeXMLRE = /^\s*<[a-z!?][^]*>\s*$/i;

        function link(scope, element)//, attrs)
        {
            scope.$watch('resultValue', queueDigest.bind(null, updateFirstLine, 10));
            scope.$watch('resultFieldType', queueDigest.bind(null, updateFirstLine, 10));

            element.attr('data-html', '<div class="wrapper"><pre></pre></div>');

            function updateFirstLine()
            {
                var value = scope.resultValue;
                var fieldType = scope.resultFieldType, fieldName = scope.resultFieldName;
                var displayValue = value, prettyDisplayValue = value, firstLine = value, language, prettyPrintable;

                if(value === null)
                {
                    scope.isNull = true;
                    return;
                } // end if

                switch(fieldType)
                {
                    case 'json':
                        firstLine = displayValue = JSON.stringify(value);
                        prettyDisplayValue = JSON.stringify(value, null, scope.indent || '    ');
                        language = 'json';
                        /* falls through */
                    case 'text':
                        var match = firstLineRE.exec(firstLine);
                        if(match)
                        {
                            firstLine = match[1];
                        } // end if

                        if(firstLine && firstLine.length > 50)
                        {
                            firstLine = firstLine.slice(0, 50) + '\u2026';
                        } // end if
                        break;
                    default:
                        // Nothing.
                } // end switch
<commit_msg>Made the max line length for the first line of a result value more easily modifiable.<commit_after>/* jshint browser:true, globalstrict:true */
/* global angular:true */
"use strict";

angular.module('webPGQ.directives')
    .directive('resultValue', ['$window', '$', '_', 'hljs', 'queueDigest', function($window, $, _, hljs, queueDigest)
    {
        var prettyPrint = true;

        // Number of pixels to subtract from the available space when setting max width/height of the detail popup.
        var sizeAdjustment = 10;

        var defaultPopupSettings = {
            on: 'click',
            //position: 'top center', //FIXME: If we use 'top center', semantic ONLY checks '* center' positions!
            position: 'top left',
            variation: 'inverted',
            className: { popup: 'code ui popup' },
        };

        var firstLineRE = /^([^\n]*)\n/;
        var firstLineMaxLength = 100;

        var geomFieldNameRE = /geo|shape|wk[bt]|[gk]ml|svg|x3d/i;

        var maybeJSONRE = /^\s*(?:\{[^]*\}|\[[^]*\]|".*"|\d+(?:\.\d*)?|\.\d+|null)\s*$/;
        var maybeEWKTRE = /^\s*(?:SRID\s*=\s*\d+\s*;\s*)?\w+\s*\([^]*\)\s*$/;
        var maybeXMLRE = /^\s*<[a-z!?][^]*>\s*$/i;

        function link(scope, element)//, attrs)
        {
            scope.$watch('resultValue', queueDigest.bind(null, updateFirstLine, 10));
            scope.$watch('resultFieldType', queueDigest.bind(null, updateFirstLine, 10));

            element.attr('data-html', '<div class="wrapper"><pre></pre></div>');

            function updateFirstLine()
            {
                var value = scope.resultValue;
                var fieldType = scope.resultFieldType, fieldName = scope.resultFieldName;
                var displayValue = value, prettyDisplayValue = value, firstLine = value, language, prettyPrintable;

                if(value === null)
                {
                    scope.isNull = true;
                    return;
                } // end if

                switch(fieldType)
                {
                    case 'json':
                        firstLine = displayValue = JSON.stringify(value);
                        prettyDisplayValue = JSON.stringify(value, null, scope.indent || '    ');
                        language = 'json';
                        /* falls through */
                    case 'text':
                        var match = firstLineRE.exec(firstLine);
                        if(match)
                        {
                            firstLine = match[1];
                        } // end if

                        if(firstLine && firstLine.length > firstLineMaxLength)
                        {
                            firstLine = firstLine.slice(0, firstLineMaxLength) + '\u2026';
                        } // end if
                        break;
                    default:
                        // Nothing.
                } // end switch

{'fraction_non_alphanumeric': 0.14448336252189142, 'fraction_numerical': 0.005779334500875657, 'mean_word_length': 1.4291790727350064, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, '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': '6067261', 'n_tokens_mistral': 1611, 'n_tokens_neox': 1478, 'n_words': 340}