<commit_before>/* global angular: true */

angular.module('webPGQ.directives')
    .directive('resultValue', ['$window', '$', 'queueDigest', function($window, $, queueDigest)
    {
        var firstLineRE = /^([^\n]*)\n/;
        var newlineRE = /\n/g;

        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.editorConfig = angular.extend({}, scope.aceConfig || {}, { onLoad: onAceLoad, showGutter: false });
            scope.prettyPrint = true;
            scope.prettyPrintable = false;

            scope.togglePrettyPrint = function()
            {
                scope.prettyPrint = !scope.prettyPrint;
            }; // end scope.togglePrettyPrint

            var editor, needsResize = true;

            var dropdownSettings = {
                on: 'hover',
                delay: { show: 10 },
                transition: 'fade',
                onShow: function()
                {
                    $window.setTimeout(function()
                    {
                        if(editor && needsResize)
                        {
                            editor.resize();
                        } // end if
                    }, 0);
                } // end onShow
            }; // end dropdownSettings

            scope.$watch('resultValue', updateFirstLine);
            scope.$watch('resultFieldType', updateFirstLine);
            scope.$watch('prettyPrint', updateFirstLine);

            scope.$watch('firstLine', function()
            {
                $window.setTimeout(function()
                {
                    element.dropdown(dropdownSettings);
                }, 0);
            });

            function onAceLoad(_editor)
            {
                editor = _editor;
                scope.aceConfig.onLoad(editor);

                editor.setHighlightActiveLine(false);
                editor.setShowPrintMargin(false);

                queueDigest(updateFirstLine, 0);
            } // end onAceLoad

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

                switch(fieldType)
                {
                    case 'json':
                        firstLine = JSON.stringify(value);
                        displayValue = JSON.stringify(value, null, scope.prettyPrint ? '\t' : null);
                        editorMode = 'json';
                        /* falls through */
                    case 'text':
                        var match = firstLineRE.exec(firstLine);
                        if(match)
                        {
                            firstLine = match[1];
                        } // end if

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

                var looksLikeGeomField = geomFieldNameRE.test(fieldName);
                if(fieldType == 'text')<commit_msg>Corrected <result-value> so it doesn't explode if a text value is null.<commit_after>/* global angular: true */

angular.module('webPGQ.directives')
    .directive('resultValue', ['$window', '$', 'queueDigest', function($window, $, queueDigest)
    {
        var firstLineRE = /^([^\n]*)\n/;
        var newlineRE = /\n/g;

        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.editorConfig = angular.extend({}, scope.aceConfig || {}, { onLoad: onAceLoad, showGutter: false });
            scope.prettyPrint = true;
            scope.prettyPrintable = false;

            scope.togglePrettyPrint = function()
            {
                scope.prettyPrint = !scope.prettyPrint;
            }; // end scope.togglePrettyPrint

            var editor, needsResize = true;

            var dropdownSettings = {
                on: 'hover',
                delay: { show: 10 },
                transition: 'fade',
                onShow: function()
                {
                    $window.setTimeout(function()
                    {
                        if(editor && needsResize)
                        {
                            editor.resize();
                        } // end if
                    }, 0);
                } // end onShow
            }; // end dropdownSettings

            scope.$watch('resultValue', updateFirstLine);
            scope.$watch('resultFieldType', updateFirstLine);
            scope.$watch('prettyPrint', updateFirstLine);

            scope.$watch('firstLine', function()
            {
                $window.setTimeout(function()
                {
                    element.dropdown(dropdownSettings);
                }, 0);
            });

            function onAceLoad(_editor)
            {
                editor = _editor;
                scope.aceConfig.onLoad(editor);

                editor.setHighlightActiveLine(false);
                editor.setShowPrintMargin(false);

                queueDigest(updateFirstLine, 0);
            } // end onAceLoad

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

                switch(fieldType)
                {
                    case 'json':
                        firstLine = JSON.stringify(value);
                        displayValue = JSON.stringify(value, null, scope.prettyPrint ? '\t' : null);
                        editorMode = '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

                var looksLikeGeomField = geomFieldNameRE.test(fieldName);
                if(fieldType == 'text')
{'fraction_non_alphanumeric': 0.12992619412338113, 'fraction_numerical': 0.0044562038713271135, 'mean_word_length': 1.1776834445118254, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 8, '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': '7232311', 'n_tokens_mistral': 1941, 'n_tokens_neox': 1754, 'n_words': 325}