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

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

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

    $scope.isSourceVisible = route.locals.viewSource;

    $scope.sourceHref = $scope.isSourceVisible ?
      $location.url().replace('src', '') : $location.path() + '/src#' + $location.hash();

    $scope.queryExecuting = false;

    $scope.newVisualization = undefined;

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

    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.$parent.pageTitle = "Query Fiddle";

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

    $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) {<commit_msg>#121: source button to play nice with hashes - cont'd<commit_after>(function() {
  'use strict';

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

    $scope.dirty = undefined;
    $scope.isOwner = false;
    $scope.canEdit = 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() {
      $scope.sourceHref = $scope.isSourceVisible ?
        $location.url().replace('src', '') : $location.path() + '/src#' + $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.$parent.pageTitle = "Query Fiddle";

    $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) {
{'fraction_non_alphanumeric': 0.15855387523629488, 'fraction_numerical': 0.0016540642722117202, 'mean_word_length': 2.630360205831904, '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': '5001509', 'n_tokens_mistral': 1352, 'n_tokens_neox': 1307, 'n_words': 254}