<commit_before>'use strict';

define(['app/rest', 'app/gui', 'app/client', 'app/user'], function () {

    // Controllers

    function GridCtrl($scope, orders, orderStates, $timeout) {
        $scope.orders = [];
        $scope.filters = {};
        $scope.states = [];

        var sort = {};
        var timeoutPromise;

        $scope.$watch('filters', filtersChanged, true);

        var firstTime = true;
        function filtersChanged () {
            if (firstTime) {
                firstTime = false;
                return;
            }
            $scope.loading = true;
            $timeout.cancel(timeoutPromise);
            timeoutPromise = $timeout(loadGrid, 1000);
        }

        function loadGrid() {
            $scope.loading = true;
            var query = filtersToQuery();
            query.sort = sortToString();
            orders.readAll(query).success(function (data) {
                $scope.orders = data;
                $scope.loading = false;
            });
        }

        loadGrid();

        orderStates.readAll().success(function (data) {
            $scope.states = data;
        });

        function sortToString() {
            return sort.by ? (sort.dir === 'asc' ? '' : '-') + sort.by : null;
        }

        function filtersToQuery() {
            function recursive(filters, params, fullName) {
                fullName = fullName || '';
                if (typeof filters == 'string') {
                    params['filters[' + fullName + ']'] = filters;
                } else {
                    for (var name in filters) {
                        recursive(filters[name], params, fullName === '' ? name : fullName + '.' + name);
                    }
                }
            }
            var params = {};
            recursive($scope.filters, params);<commit_msg>fetching messages on orders' grid<commit_after>'use strict';

define(['app/rest', 'app/gui', 'app/client', 'app/user'], function () {

    // Controllers

    function GridCtrl($scope, orders, orderStates, $timeout, messages) {
        $scope.orders = [];
        $scope.filters = {};
        $scope.states = [];

        var sort = {};
        var timeoutPromise;

        $scope.$watch('filters', filtersChanged, true);

        var firstTime = true;
        function filtersChanged () {
            if (firstTime) {
                firstTime = false;
                return;
            }
            $scope.loading = true;
            $timeout.cancel(timeoutPromise);
            timeoutPromise = $timeout(loadGrid, 1000);
        }

        function loadGrid() {
            $scope.loading = true;
            var query = filtersToQuery();
            query.sort = sortToString();
            orders.readAll(query).success(function (data) {
                $scope.orders = data;
                $scope.loading = false;
            });
        }

        loadGrid();

        messages.readAll({fetch: true}).success(function () {
            loadGrid();
        });

        orderStates.readAll().success(function (data) {
            $scope.states = data;
        });

        function sortToString() {
            return sort.by ? (sort.dir === 'asc' ? '' : '-') + sort.by : null;
        }

        function filtersToQuery() {
            function recursive(filters, params, fullName) {
                fullName = fullName || '';
                if (typeof filters == 'string') {
                    params['filters[' + fullName + ']'] = filters;
                } else {
                    for (var name in filters) {
                        recursive(filters[name], params, fullName === '' ? name : fullName + '.' + name);
                    }
                }
            }
            var params = {};
            recursive($scope.filters, params);
{'fraction_non_alphanumeric': 0.13570487483530963, 'fraction_numerical': 0.002108036890645586, 'mean_word_length': 1.453781512605042, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '759244', 'n_tokens_mistral': 984, 'n_tokens_neox': 930, 'n_words': 203}