<commit_before>'use strict';

/*
 * Copyright 2016 Next Century Corporation
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

/**
 * This visualization shows all data in a table.
 * @namespace neonDemo.controllers
 * @class dataTableController
 * @constructor
 */
angular.module('neonDemo.controllers').controller('dataTableController', ['$scope', 'linkify', '$sce', '$timeout', function($scope, linkify, $sce, $timeout) {
    // Unique field name used for the SlickGrid column containing the URLs for the external apps.
    // This name should be one that is highly unlikely to be a column name in a real database.
    var EXTERNAL_APP_FIELD_NAME = "neonExternalApps";

    $scope.active.ASCENDING = neon.query.ASCENDING;
    $scope.active.DESCENDING = neon.query.DESCENDING;

    $scope.active.sortByField = {};
    $scope.active.sortDirection = $scope.bindings.sortDirection || $scope.active.ASCENDING;
    $scope.active.limit = $scope.bindings.limit || 100;

    $scope.active.gridOptions = {
        columnDefs: [],
        rowData: [],
        enableColResize: true,
        enableSorting: true,
        showToolPanel: false,
        toolPanelSuppressPivot: true,
        toolPanelSuppressValues: true,
        suppressRowClickSelection: true,
        onColumnVisible: handleColumnVisibiltyChange
    };

    var hiddenFields = [];

    var handleColumnVisibiltyChange = function(event) {
        if(event.column.visible && hiddenFields[event.column.colId]) {
            delete hiddenFields[event.column.colId];
            XDATA.userALE.log({
                activity: "add",
                action: "click",
                elementId: "column-" + event.column.colId,
                elementType: "datagrid",
                elementGroup: "table_group",
                source: "user",
                tags: ["options", "datagrid", "column", event.column.colId]
            });
        } else {
            hiddenFields[event.column.colId] = true;
            XDATA.userALE.log({
                activity: "remove",
                action: "click",
                elementId: "column-" + event.column.colId,
                elementType: "datagrid",
                elementGroup: "table_group",
                source: "user",
                tags: ["options", "datagrid", "column", event.column.colId]
            });
        }
    };

    $scope.functions.createMenuText = function() {
        return ($scope.active.count && $scope.active.total) ? $scope.active.count + " of " + $scope.active.total + " Records" : "No Data";
    };

    $scope.functions.showMenuText = function() {
        return true;
    };

    $scope.functions.onUpdateFields = function() {
        $scope.active.fields.forEach(function(field) {
            if(field.hide) {
                hiddenFields[field.columnName] = true;
            }
        });

        $scope.active.sortByField = $scope.functions.findFieldObject("sortField", neonMappings.SORT);
    };

    $scope.functions.onChangeOption = function() {
        updateColumns();
    };

    /**
     * Queries for field names list and sets up table columns
     * @method updateColumns
     * @private
     */
    var updateColumns = function() {
        // Based on neon.helpers.getNestedValues
        var getCellText = function(data, fields) {
            var values = data[fields[0]];

            if(_.isArray(values)) {
                return "[" + [].concat.apply([], values.map(function(item) {
                    if((_.isArray(item) || _.isObject(item)) && fields.length > 1) {
                        return getCellText(item, fields.slice(1));
                    }
                    return _.isArray(item) ? item.join(",") : (_.isObject(item) ? "{...}" : item);
                })).join(",") + "]";
            }

            if(_.isObject(values) && fields.length > 1 && typeof values[fields[1]] !== "undefined") {
                return getCellText(values, fields.slice(1));
            }

            return "" + values;
        };

        // Use the fields in the order they are defined in the Neon dashboard configuration (so we can't use sorted $scope.active.fields) for the order of the columns.
        var columnDefinitions = _.map($scope.functions.getUnsortedFields(), function(fieldObject) {
            var config = {
                field: fieldObject.columnName,
                headerName: fieldObject.prettyName,
                onCellClicked: handleRowClick,
                suppressSizeToFit: true,
                cellRenderer: function(params) {
                    return getCellText(params.data, params.colDef.field.split("."));
                }
            };
<commit_msg>Fixed a minor bug in the data table with displaying objects as strings.<commit_after>'use strict';

/*
 * Copyright 2016 Next Century Corporation
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

/**
 * This visualization shows all data in a table.
 * @namespace neonDemo.controllers
 * @class dataTableController
 * @constructor
 */
angular.module('neonDemo.controllers').controller('dataTableController', ['$scope', 'linkify', '$sce', '$timeout', function($scope, linkify, $sce, $timeout) {
    // Unique field name used for the SlickGrid column containing the URLs for the external apps.
    // This name should be one that is highly unlikely to be a column name in a real database.
    var EXTERNAL_APP_FIELD_NAME = "neonExternalApps";

    $scope.active.ASCENDING = neon.query.ASCENDING;
    $scope.active.DESCENDING = neon.query.DESCENDING;

    $scope.active.sortByField = {};
    $scope.active.sortDirection = $scope.bindings.sortDirection || $scope.active.ASCENDING;
    $scope.active.limit = $scope.bindings.limit || 100;

    $scope.active.gridOptions = {
        columnDefs: [],
        rowData: [],
        enableColResize: true,
        enableSorting: true,
        showToolPanel: false,
        toolPanelSuppressPivot: true,
        toolPanelSuppressValues: true,
        suppressRowClickSelection: true,
        onColumnVisible: handleColumnVisibiltyChange
    };

    var hiddenFields = [];

    var handleColumnVisibiltyChange = function(event) {
        if(event.column.visible && hiddenFields[event.column.colId]) {
            delete hiddenFields[event.column.colId];
            XDATA.userALE.log({
                activity: "add",
                action: "click",
                elementId: "column-" + event.column.colId,
                elementType: "datagrid",
                elementGroup: "table_group",
                source: "user",
                tags: ["options", "datagrid", "column", event.column.colId]
            });
        } else {
            hiddenFields[event.column.colId] = true;
            XDATA.userALE.log({
                activity: "remove",
                action: "click",
                elementId: "column-" + event.column.colId,
                elementType: "datagrid",
                elementGroup: "table_group",
                source: "user",
                tags: ["options", "datagrid", "column", event.column.colId]
            });
        }
    };

    $scope.functions.createMenuText = function() {
        return ($scope.active.count && $scope.active.total) ? $scope.active.count + " of " + $scope.active.total + " Records" : "No Data";
    };

    $scope.functions.showMenuText = function() {
        return true;
    };

    $scope.functions.onUpdateFields = function() {
        $scope.active.fields.forEach(function(field) {
            if(field.hide) {
                hiddenFields[field.columnName] = true;
            }
        });

        $scope.active.sortByField = $scope.functions.findFieldObject("sortField", neonMappings.SORT);
    };

    $scope.functions.onChangeOption = function() {
        updateColumns();
    };

    /**
     * Queries for field names list and sets up table columns
     * @method updateColumns
     * @private
     */
    var updateColumns = function() {
        var OBJECT = "{...}";

        // Based on neon.helpers.getNestedValues
        var getCellText = function(data, fields) {
            var values = data[fields[0]];

            if(_.isArray(values)) {
                return "[" + [].concat.apply([], values.map(function(item) {
                    if((_.isArray(item) || _.isObject(item)) && fields.length > 1) {
                        return getCellText(item, fields.slice(1));
                    }
                    return _.isArray(item) ? item.join(",") : (_.isObject(item) ? OBJECT : item);
                })).join(",") + "]";
            }

            if(_.isObject(values) && fields.length > 1 && typeof values[fields[1]] !== "undefined") {
                return getCellText(values, fields.slice(1));
            }

            return _.isObject(values) ? OBJECT : ("" + values);
        };

        // Use the fields in the order they are defined in the Neon dashboard configuration (so we can't use sorted $scope.active.fields) for the order of the columns.
        var columnDefinitions = _.map($scope.functions.getUnsortedFields(), function(fieldObject) {
            var config = {
                field: fieldObject.columnName,
                headerName: fieldObject.prettyName,
                onCellClicked: handleRowClick,
                suppressSizeToFit: true,
                cellRenderer: function(params) {
                    return getCellText(params.data, params.colDef.field.split("."));
                }
            };

{'fraction_non_alphanumeric': 0.1197398622800306, 'fraction_numerical': 0.0032517214996174446, 'mean_word_length': 2.188109756097561, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4435449', 'n_tokens_mistral': 2887, 'n_tokens_neox': 2760, 'n_words': 711}