{"size": 2574, "ext": "js", "max_stars_repo_path": "59-html-reporting/ruby/output/js/table/table.js", "max_stars_repo_name": "tourdedave/selenium-tips", "max_stars_repo_stars_event_min_datetime": "2015-01-28T05:06:00.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-26T16:16:12.000Z", "max_issues_repo_path": "59-html-reporting/ruby/output/js/table/table.js", "max_issues_repo_name": "tourdedave/selenium-tips", "max_issues_repo_issues_event_min_datetime": "2015-03-04T07:32:52.000Z", "max_issues_repo_issues_event_max_datetime": "2019-06-28T10:16:44.000Z", "max_forks_repo_path": "59-html-reporting/ruby/output/js/table/table.js", "max_forks_repo_name": "tourdedave/selenium-tips", "max_forks_repo_forks_event_min_datetime": "2015-01-20T19:38:13.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-17T13:16:19.000Z"}
{"max_stars_count": 251, "max_issues_count": 23, "max_forks_count": 157, "avg_line_length": 34.32, "max_line_length": 73, "alphanum_fraction": 0.4704739705}
/*global angular*/
angular.module('allure.table', [])
    .directive('allureTable', function () {
        "use strict";
        return {
            replace: true,
            transclude: true,
            templateUrl: 'templates/table/table.html',
            scope: {
                sorting: '=?'
            },
            controller: 'AllureTableController',
            link: function (scope, elem, attrs, ctrl) {
                ctrl.transclude(function (clone) {
                    elem.append(clone);
                });
            }
        };
    })
    .directive('allureTableCol', function () {
        "use strict";
        return {
            require: '^allureTable',
            link: function (scope, elem, attrs, tableCtrl) {
                tableCtrl.addColumn(scope.$eval(attrs.allureTableCol));
            }
        };
    })
    .controller('AllureTableController', function ($scope, $transclude) {
        "use strict";
        var defaultConfig = {reverse: false, flex: 1};
        this.addColumn = function (column) {
            if (typeof column === 'string') {
                column = {
                    heading: column,
                    predicate: column.toLowerCase()
                };
            }
            column = angular.extend({}, defaultConfig, column);
            if (!this.findColumn(column.heading)) {
                $scope.columns.push(column);
            }
        };
        this.findColumn = function (heading) {
            return $scope.columns.filter(function (col) {
                return col.heading === heading;
            })[0];
        };
        this.transclude = $transclude;
        $scope.getWidth = function(column) {
            var totalFlex = $scope.columns.reduce(function(total, col) {
                return total + col.flex;
            }, 0);
            return 100/totalFlex*column.flex + '%';
        };
        $scope.columns = [];
        $scope.sorting = $scope.sorting || {};
        $scope.setPredicate = function (column) {
            if (column) {
                var newPredicate = column.predicate;
                if ($scope.sorting.predicate === newPredicate) {
                    $scope.sorting.reverse = !$scope.sorting.reverse;
                }
                else {
                    $scope.sorting.predicate = newPredicate;
                    $scope.sorting.reverse = column.reverse;
                }
            }
            else {
                delete $scope.sorting.predicate;
                delete $scope.sorting.reverse;
            }
        };
    });
