<commit_before>'use strict';

angular.module('adagios.table', ['adagios.live',
                                 'adagios.table.actionbar',
                                 'adagios.filters',
                                 'adagios.table.cell_host',
                                 'adagios.table.cell_duration',
                                 'adagios.table.cell_service_check',
                                 'adagios.table.cell_last_check',
                                 'adagios.table.cell_hosts_host',
                                 'adagios.table.cell_host_address',
                                 'adagios.table.cell_host_status'
                                ])

    .value('tableConfig', { cells: { 'text': [], 'name': [] },
                            apiName: '',
                            filters: {},
                            cellToFieldsMap: {},
                            cellWrappableField: {},
                            noRepeatCell: '',
                            isWrappable: false,
                            refreshInterval: 0
                          })

    .controller('TableCtrl', ['$scope', '$interval', 'getServices', 'tableConfig', 'processColumnRepeat',
        function ($scope, $interval, getServices, tableConfig, processColumnRepeat) {

        var requestFields = [],
            filters = JSON.parse(tableConfig.filters),
            i;

        $scope.cellsName = tableConfig.cells.name;
        $scope.cellsText = tableConfig.cells.text;
        $scope.cellIndexes = [];

        for (i = 0; i < $scope.cellsName.length; i += 1) {
            $scope.cellIndexes.push(i);
        }

        angular.forEach($scope.cellsName, function (key) {
            angular.forEach(tableConfig.cellToFieldsMap[key], function (_value) {
                requestFields.push(_value);
            });
        });

        $scope.getData = 
            function (requestFields, filters, apiName) {
                getServices(requestFields, filters, tableConfig.apiName)
                    .success(function (data) {
                        var fieldToWrap = tableConfig.cellWrappableField[tableConfig.noRepeatCell],
                            cellFields = tableConfig.cellToFieldsMap[tableConfig.noRepeatCell];

                        if (tableConfig.noRepeatCell !== "") {
                            data = processColumnRepeat(data, fieldToWrap, cellFields, tableConfig.isWrappable);
                        }

                        $scope.entries = data;
                    });
            }

        $scope.getData(requestFields, filters, tableConfig.apiName);

        if (tableConfig.refreshInterval !== 0) {
            $interval(function() {
                $scope.getData(requestFields, filters, tableConfig.apiName);
            }, tableConfig.refreshInterval);
        }

    }])

    .directive('adgTable', ['$http', '$compile', 'tableConfig', function ($http, $compile, tableConfig) {
        return {
            restrict: 'E',
            compile: function () {
                return function (scope, element, attrs) {

                    if (!attrs.cellsText || !attrs.cellsName || !attrs.apiName || !attrs.isWrappable) {
                        throw new Error('<adg-table> "cells-text", "cells-name", "api-name"'
                                        + ' and "is-wrappable" attributes must be defined');
                    }

                    tableConfig.cells.text = attrs.cellsText.split(',');
                    tableConfig.cells.name = attrs.cellsName.split(',');
                    tableConfig.apiName = attrs.apiName;
                    tableConfig.isWrappable = attrs.isWrappable;
                    tableConfig.noRepeatCell = attrs.noRepeatCell;

                    if (!!attrs.refreshInterval) {
                        tableConfig.refreshInterval = attrs.refreshInterval;
                    }

                    if (!!attrs.filters) {
                        tableConfig.filters = attrs.filters;
                    }

                    var template = 'components/table/table.html';

                    $http.get(template, { cache: true })
                        .success(function (data) {
                            var elem = $compile(data)(scope);
                            element.append(elem);
                        });
                };
            }
        };
    }])

    .directive('adgCell', ['$http', '$compile', function ($http, $compile) {

        return {
            restrict: 'A',
            compile: function () {
                return function (scope, element, attrs) {
                    if (!attrs.cellName) {
                        throw new Error('<adg-cell> "cell-name" attribute must be defined');
                    }
<commit_msg>FIX: 0ms interval data refresh<commit_after>'use strict';

angular.module('adagios.table', ['adagios.live',
                                 'adagios.table.actionbar',
                                 'adagios.filters',
                                 'adagios.table.cell_host',
                                 'adagios.table.cell_duration',
                                 'adagios.table.cell_service_check',
                                 'adagios.table.cell_last_check',
                                 'adagios.table.cell_hosts_host',
                                 'adagios.table.cell_host_address',
                                 'adagios.table.cell_host_status'
                                ])

    .value('tableConfig', { cells: { 'text': [], 'name': [] },
                            apiName: '',
                            filters: {},
                            cellToFieldsMap: {},
                            cellWrappableField: {},
                            noRepeatCell: '',
                            isWrappable: false,
                            refreshInterval: '0'
                          })

    .controller('TableCtrl', ['$scope', '$interval', 'getServices', 'tableConfig', 'processColumnRepeat',
        function ($scope, $interval, getServices, tableConfig, processColumnRepeat) {

        var requestFields = [],
            filters = JSON.parse(tableConfig.filters),
            i;

        $scope.cellsName = tableConfig.cells.name;
        $scope.cellsText = tableConfig.cells.text;
        $scope.cellIndexes = [];

        for (i = 0; i < $scope.cellsName.length; i += 1) {
            $scope.cellIndexes.push(i);
        }

        angular.forEach($scope.cellsName, function (key) {
            angular.forEach(tableConfig.cellToFieldsMap[key], function (_value) {
                requestFields.push(_value);
            });
        });

        $scope.getData = 
            function (requestFields, filters, apiName) {
                getServices(requestFields, filters, tableConfig.apiName)
                    .success(function (data) {
                        var fieldToWrap = tableConfig.cellWrappableField[tableConfig.noRepeatCell],
                            cellFields = tableConfig.cellToFieldsMap[tableConfig.noRepeatCell];

                        if (tableConfig.noRepeatCell !== "") {
                            data = processColumnRepeat(data, fieldToWrap, cellFields, tableConfig.isWrappable);
                        }

                        $scope.entries = data;
                    });
            }

        $scope.getData(requestFields, filters, tableConfig.apiName);
        
        if (tableConfig.refreshInterval !== '0') {
            $interval(function() {
                $scope.getData(requestFields, filters, tableConfig.apiName);
            }, tableConfig.refreshInterval);
        }

    }])

    .directive('adgTable', ['$http', '$compile', 'tableConfig', function ($http, $compile, tableConfig) {
        return {
            restrict: 'E',
            compile: function () {
                return function (scope, element, attrs) {

                    if (!attrs.cellsText || !attrs.cellsName || !attrs.apiName || !attrs.isWrappable) {
                        throw new Error('<adg-table> "cells-text", "cells-name", "api-name"'
                                        + ' and "is-wrappable" attributes must be defined');
                    }

                    tableConfig.cells.text = attrs.cellsText.split(',');
                    tableConfig.cells.name = attrs.cellsName.split(',');
                    tableConfig.apiName = attrs.apiName;
                    tableConfig.isWrappable = attrs.isWrappable;
                    tableConfig.noRepeatCell = attrs.noRepeatCell;
                    
                    if (!!attrs.refreshInterval) {
                        tableConfig.refreshInterval = attrs.refreshInterval;
                    }

                    if (!!attrs.filters) {
                        tableConfig.filters = attrs.filters;
                    }

                    var template = 'components/table/table.html';

                    $http.get(template, { cache: true })
                        .success(function (data) {
                            var elem = $compile(data)(scope);
                            element.append(elem);
                        });
                };
            }
        };
    }])

    .directive('adgCell', ['$http', '$compile', function ($http, $compile) {

        return {
            restrict: 'A',
            compile: function () {
                return function (scope, element, attrs) {
                    if (!attrs.cellName) {
                        throw new Error('<adg-cell> "cell-name" attribute must be defined');
                    }

{'fraction_non_alphanumeric': 0.11280392361473443, 'fraction_numerical': 0.0009391631013252635, 'mean_word_length': 1.2694766753492777, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 22, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6411620', 'n_tokens_mistral': 2392, 'n_tokens_neox': 2287, 'n_words': 382}