<commit_before>(function () {
    'use strict';

    var QueryViewCtrl = function ($scope, $window, $route, $http, $location, growl, notifications, Query, Visualization, DataSource) {
        var DEFAULT_TAB = 'table';
        var pristineHash = "";
        var leavingPageText = "You will lose your changes if you leave";
        var route = $route.current;

        $scope.dataSources = DataSource.get();

        $scope.dirty = undefined;
        $scope.isNewQuery = false;
        $scope.isOwner = false;
        $scope.canEdit = false;
        $scope.canFork = false;

        $scope.isSourceVisible = route.locals.viewSource;

        $scope.queryExecuting = false;

        $scope.newVisualization = undefined;

        updateSourceHref();

        $window.onbeforeunload = function () {
            if ($scope.canEdit && $scope.dirty) {
                return leavingPageText;
            }
        }

        function updateSourceHref() {
            if ($scope.query && $scope.query.id) {
                $scope.sourceHref = $scope.isSourceVisible ?
                    $location.url().replace('source', '') : getQuerySourceUrl($scope.query.id);
            }
        };

        function getQuerySourceUrl(queryId) {
            return '/queries/' + queryId + '/source#' + $location.hash();
        };

        Mousetrap.bindGlobal("meta+s", function (e) {
            e.preventDefault();

            if ($scope.canEdit) {
                $scope.saveQuery();
            }
        });

        $scope.$on('$locationChangeStart', function (event, next, current) {
            if (next.split("#")[0] == current.split("#")[0]) {
                return;
            }

            if (!$scope.canEdit) {
                return;
            }

            if ($scope.dirty && !confirm(leavingPageText + "\n\nAre you sure you want to leave this page?")) {
                event.preventDefault();
            } else {
                Mousetrap.unbind("meta+s");
            }
        });

        $scope.$watch(function () {
            return $location.hash()
        }, function (hash) {
            $scope.selectedTab = hash || DEFAULT_TAB;
            updateSourceHref();
        });

        $scope.lockButton = function (lock) {
            $scope.queryExecuting = lock;
        };

        $scope.formatQuery = function () {
            $scope.editorOptions.readOnly = 'nocursor';

            $http.post('/api/queries/format', {
                'query': $scope.query.query
            }).success(function (response) {
                $scope.query.query = response;
                $scope.editorOptions.readOnly = false;
            })
        }

        $scope.saveQuery = function (duplicate, oldId) {
            if (!oldId) {
                oldId = $scope.query.id;
            }

            delete $scope.query.latest_query_data;
            $scope.query.$save(function (q) {
                pristineHash = q.getHash();
                $scope.dirty = false;

                if (duplicate) {
                    growl.addSuccessMessage("Query forked");
                } else {
                    growl.addSuccessMessage("Query saved");
                }

                if (oldId != q.id) {
                    $location.url(getQuerySourceUrl(q.id)).replace();
                }
            }, function (httpResponse) {
                growl.addErrorMessage("Query could not be saved");
            });
        };
<commit_msg>Unless data source set already, set it to the first one.<commit_after>(function () {
    'use strict';

    var QueryViewCtrl = function ($scope, $window, $route, $http, $location, growl, notifications, Query, Visualization, DataSource) {
        var DEFAULT_TAB = 'table';
        var pristineHash = "";
        var leavingPageText = "You will lose your changes if you leave";
        var route = $route.current;

        $scope.dataSources = DataSource.get(function(dataSources) {
            $scope.query.data_source_id = $scope.query.data_source_id || dataSources[0].id;
        });

        $scope.dirty = undefined;
        $scope.isNewQuery = false;
        $scope.isOwner = false;
        $scope.canEdit = false;
        $scope.canFork = false;

        $scope.isSourceVisible = route.locals.viewSource;

        $scope.queryExecuting = false;

        $scope.newVisualization = undefined;

        updateSourceHref();

        $window.onbeforeunload = function () {
            if ($scope.canEdit && $scope.dirty) {
                return leavingPageText;
            }
        }

        function updateSourceHref() {
            if ($scope.query && $scope.query.id) {
                $scope.sourceHref = $scope.isSourceVisible ?
                    $location.url().replace('source', '') : getQuerySourceUrl($scope.query.id);
            }
        };

        function getQuerySourceUrl(queryId) {
            return '/queries/' + queryId + '/source#' + $location.hash();
        };

        Mousetrap.bindGlobal("meta+s", function (e) {
            e.preventDefault();

            if ($scope.canEdit) {
                $scope.saveQuery();
            }
        });

        $scope.$on('$locationChangeStart', function (event, next, current) {
            if (next.split("#")[0] == current.split("#")[0]) {
                return;
            }

            if (!$scope.canEdit) {
                return;
            }

            if ($scope.dirty && !confirm(leavingPageText + "\n\nAre you sure you want to leave this page?")) {
                event.preventDefault();
            } else {
                Mousetrap.unbind("meta+s");
            }
        });

        $scope.$watch(function () {
            return $location.hash()
        }, function (hash) {
            $scope.selectedTab = hash || DEFAULT_TAB;
            updateSourceHref();
        });

        $scope.lockButton = function (lock) {
            $scope.queryExecuting = lock;
        };

        $scope.formatQuery = function () {
            $scope.editorOptions.readOnly = 'nocursor';

            $http.post('/api/queries/format', {
                'query': $scope.query.query
            }).success(function (response) {
                $scope.query.query = response;
                $scope.editorOptions.readOnly = false;
            })
        }

        $scope.saveQuery = function (duplicate, oldId) {
            if (!oldId) {
                oldId = $scope.query.id;
            }

            delete $scope.query.latest_query_data;

            $scope.query.$save(function (q) {
                pristineHash = q.getHash();
                $scope.dirty = false;

                if (duplicate) {
                    growl.addSuccessMessage("Query forked");
                } else {
                    growl.addSuccessMessage("Query saved");
                }

                if (oldId != q.id) {
                    $location.url(getQuerySourceUrl(q.id)).replace();
                }
            }, function (httpResponse) {
                growl.addErrorMessage("Query could not be saved");
            });
        };

{'fraction_non_alphanumeric': 0.13036093418259023, 'fraction_numerical': 0.0007077140835102619, 'mean_word_length': 1.5353426623609616, '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': '2639938', 'n_tokens_mistral': 1952, 'n_tokens_neox': 1851, 'n_words': 355}