<commit_before>/*
 *  Copyright (c) 2012-2015  <NAME> <<EMAIL>>,
 *                           <NAME> <<EMAIL>>,
 *                           AIP E-Science (www.aip.de)
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as
 *  published by the Free Software Foundation, either version 3 of the
 *  License, or (at your option) any later version.'ngCookies'
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

var app = angular.module('query',['table','modal','browser','plot','codemirror','samp','ngCookies']);

app.config(['$httpProvider', function($httpProvider) {
    $httpProvider.defaults.headers.common['Accept'] = 'application/json';
    $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
}]);

/* directives */

app.directive('daiquiriQueryQueuesGroup', ['$timeout','SubmitService', function($timeout,SubmitService) {
    return {
        restrict: 'C',
        transclude: true,
        scope: { id: '=' },
        template: '<div ng-transclude ng-hide="buttons"></div><div class="btn-group" data-toggle="buttons-radio" ng-show="buttons"><button type="button" class="btn" ng-repeat="button in buttons" ng-class="{\'active\': button.selected }" ng-click="changeQueue(button.value)"><div rel="tooltip" data-placement="bottom" data-original-title="{{button.tooltip}}">{{button.label}} queue</div></button></div>',
        link: {
            post: function(scope, element, attrs) {
                var id = element.attr('id');
                var buttons = [];

                var select = angular.element('select',element)
                var model = select.attr('ng-model').replace('values.','');
                var option = angular.element('option',select);

                if (option.length <= 3) {
                    angular.element('option',element).each(function(i, option) {
                        var e = angular.element(option);
                        buttons.push({
                            value: e.attr('value'),
                            label: e.text(),
                            selected: !angular.isUndefined(e.attr('selected')),
                            tooltip: select.attr('data-original-title-' + (i+1))
                        });
                    })

                    scope.buttons = buttons;
                    scope.changeQueue = function(value) {
                        SubmitService.values[model] = value;
                    };
                }
            }
        }
    };
}])

/* services */

app.factory('QueryService', ['$http','$timeout','$cookies','filterFilter','ModalService','PlotService',function($http,$timeout,$cookies,filterFilter,ModalService,PlotService) {
    // query options, will be set inside the template via ng-init
    var options = {};

    // account information, will be fetched via ajax
    var account = {
        active: {
            form: false,
            job: false
        },
        database: {},
        job: {},
        jobs: []
    };

    // dialog state, use for the different modal which will be displayed to the user
    var dialog = {
        values: {},
        errors: {},
        enabled: false
    };

    var base = angular.element('base').attr('href');

    function init() {
        startPolling();
        activateForm();
        $('[rel=tooltip]').tooltip();
    }

    function poll() {
        fetchAccount();
        if (options.polling.enabled == true) {
            $timeout(poll, options.polling.timeout);
        }
    }

    function startPolling() {
        poll();
    }

    function fetchAccount() {
        $http.get(base + '/query/account/').success(function(response) {
            account.jobs = response.jobs;
            account.database = response.database;

            // activate the current job again, if its status has changed
            if (account.active.job != false && account.job.status != 'success') {
                // get the index of the job in the jobs array (by magic)
                var id = account.job.id;
                // get the index of the job in the jobs array (by magic)
                var i = account.jobs.indexOf(filterFilter(account.jobs,{'id': id})[0]);
                if (account.jobs[i].status != account.job.status) {
                    account.job.status = activateJob(id);
                }
            }
        });
    }

    function activateForm(formName) {
        if (angular.isUndefined(formName)) {
            if (options.defaultForm == null) {
                formName = options.forms[0].key;
            } else {
                formName = options.defaultForm;
            }
        }

        account.active.form = formName;
        account.active.job = false;

        $('#submit-tab-header a').tab('show');
    }

    function activateJob(id) {
        $http.get(base + '/query/account/show-job/id/' + id)
            .success(function(response) {
                account.job = response.job;

                // codemirrorfy the query
                CodeMirror.runMode(account.job.query,"text/x-mysql",angular.element('#overview-query')[0]);

                // if a form was active, switch to job overview tab
                if (account.active.form != false) {<commit_msg>format plan in show-job<commit_after>/*
 *  Copyright (c) 2012-2015  <NAME> <<EMAIL>>,
 *                           <NAME> <<EMAIL>>,
 *                           AIP E-Science (www.aip.de)
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as
 *  published by the Free Software Foundation, either version 3 of the
 *  License, or (at your option) any later version.'ngCookies'
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

var app = angular.module('query',['table','modal','browser','plot','codemirror','samp','ngCookies']);

app.config(['$httpProvider', function($httpProvider) {
    $httpProvider.defaults.headers.common['Accept'] = 'application/json';
    $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
}]);

/* directives */

app.directive('daiquiriQueryQueuesGroup', ['$timeout','SubmitService', function($timeout,SubmitService) {
    return {
        restrict: 'C',
        transclude: true,
        scope: { id: '=' },
        template: '<div ng-transclude ng-hide="buttons"></div><div class="btn-group" data-toggle="buttons-radio" ng-show="buttons"><button type="button" class="btn" ng-repeat="button in buttons" ng-class="{\'active\': button.selected }" ng-click="changeQueue(button.value)"><div rel="tooltip" data-placement="bottom" data-original-title="{{button.tooltip}}">{{button.label}} queue</div></button></div>',
        link: {
            post: function(scope, element, attrs) {
                var id = element.attr('id');
                var buttons = [];

                var select = angular.element('select',element)
                var model = select.attr('ng-model').replace('values.','');
                var option = angular.element('option',select);

                if (option.length <= 3) {
                    angular.element('option',element).each(function(i, option) {
                        var e = angular.element(option);
                        buttons.push({
                            value: e.attr('value'),
                            label: e.text(),
                            selected: !angular.isUndefined(e.attr('selected')),
                            tooltip: select.attr('data-original-title-' + (i+1))
                        });
                    })

                    scope.buttons = buttons;
                    scope.changeQueue = function(value) {
                        SubmitService.values[model] = value;
                    };
                }
            }
        }
    };
}])

/* services */

app.factory('QueryService', ['$http','$timeout','$cookies','filterFilter','ModalService','PlotService',function($http,$timeout,$cookies,filterFilter,ModalService,PlotService) {
    // query options, will be set inside the template via ng-init
    var options = {};

    // account information, will be fetched via ajax
    var account = {
        active: {
            form: false,
            job: false
        },
        database: {},
        job: {},
        jobs: []
    };

    // dialog state, use for the different modal which will be displayed to the user
    var dialog = {
        values: {},
        errors: {},
        enabled: false
    };

    var base = angular.element('base').attr('href');

    function init() {
        startPolling();
        activateForm();
        $('[rel=tooltip]').tooltip();
    }

    function poll() {
        fetchAccount();
        if (options.polling.enabled == true) {
            $timeout(poll, options.polling.timeout);
        }
    }

    function startPolling() {
        poll();
    }

    function fetchAccount() {
        $http.get(base + '/query/account/').success(function(response) {
            account.jobs = response.jobs;
            account.database = response.database;

            // activate the current job again, if its status has changed
            if (account.active.job != false && account.job.status != 'success') {
                // get the index of the job in the jobs array (by magic)
                var id = account.job.id;
                // get the index of the job in the jobs array (by magic)
                var i = account.jobs.indexOf(filterFilter(account.jobs,{'id': id})[0]);
                if (account.jobs[i].status != account.job.status) {
                    account.job.status = activateJob(id);
                }
            }
        });
    }

    function activateForm(formName) {
        if (angular.isUndefined(formName)) {
            if (options.defaultForm == null) {
                formName = options.forms[0].key;
            } else {
                formName = options.defaultForm;
            }
        }

        account.active.form = formName;
        account.active.job = false;

        $('#submit-tab-header a').tab('show');
    }

    function activateJob(id) {
        $http.get(base + '/query/account/show-job/id/' + id)
            .success(function(response) {
                account.job = response.job;

                // codemirrorfy the query and the plan
                CodeMirror.runMode(account.job.query,"text/x-mysql",angular.element('#overview-query')[0]);
                if (!angular.isUndefined(account.job.plan)) {
                    CodeMirror.runMode(account.job.plan,"text/x-mysql",angular.element('#overview-plan')[0]);
                }

                // if a form was active, switch to job overview tab
                if (account.active.form != false) {
{'fraction_non_alphanumeric': 0.13736883184459284, 'fraction_numerical': 0.0025149596739224697, 'mean_word_length': 1.963762528912876, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4357010', 'n_tokens_mistral': 3139, 'n_tokens_neox': 2989, 'n_words': 745}