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

  function queryLink() {
    return {
      restrict: 'E',
      scope: {
        'query': '=',
        'visualization': '=?'
      },
      template: '<a ng-href="{{link}}" class="query-link">{{query.name}}</a>',
      link: function(scope, element) {
        var hash = null;
        if (scope.visualization) {
          if (scope.visualization.type === 'TABLE') {
            // link to hard-coded table tab instead of the (hidden) visualization tab
            hash = 'table';
          } else {
            hash = scope.visualization.id;
          }
        }
        scope.link = scope.query.getUrl(false, hash);
      }
    }
  }

  function querySourceLink($location) {
    return {
      restrict: 'E',
      template: '<span ng-show="query.id && canViewSource">\
                    <a ng-show="!sourceMode"\
                      ng-href="{{query.getUrl(true, selectedTab)}}" class="btn btn-default">Show Source\
                    </a>\
                    <a ng-show="sourceMode"\
                      ng-href="{{query.getUrl(false, selectedTab)}}" class="btn btn-default">Hide Source\
                    </a>\
                </span>'
    }
  }

  function queryResultLink() {
    return {
      restrict: 'A',
      link: function (scope, element, attrs) {

        var fileType = attrs.fileType ? attrs.fileType : "csv";
        scope.$watch('queryResult && queryResult.getData()', function(data) {
          if (!data) {
            return;
          }

          if (scope.queryResult.getId() == null) {
            element.attr('href', '');
          } else {
            element.attr('href', 'api/queries/' + scope.query.id + '/results/' + scope.queryResult.getId() + '.' + fileType);
            element.attr('download', scope.query.name.replace(" ", "_") + moment(scope.queryResult.getUpdatedAt()).format("_YYYY_MM_DD") + "." + fileType);
          }
        });
      }
    }
  }

  // By default Ace will try to load snippet files for the different modes and fail. We don't need them, so we use these
  // placeholders until we define our own.
  function defineDummySnippets(mode) {
    ace.define("ace/snippets/" + mode, ["require", "exports", "module"], function(require, exports, module) {
      "use strict";

      exports.snippetText = "";
      exports.scope = mode;
    });
  };

  defineDummySnippets("python");
  defineDummySnippets("sql");
  defineDummySnippets("json");

  var editorScope;
  var editorInstance;

  function queryEditor(QuerySnippet) {
    return {
      restrict: 'E',
      scope: {
        'query': '=',
        'lock': '=',
        'schema': '=',
        'syntax': '='
      },
      template: '<style>.ace_editor.fullScreen {\
          height: 448px;\
          width: auto;\
          border: 0;\
          margin: 0;\
          position: fixed !important;\
          top: 0;\
          bottom: 0;\
          left: 0;\
          right: 0;\
          z-index: 10;}\
        .fullScreen {\
          overflow: hidden;}\
      </style><div ui-ace="editorOptions" ng-model="query.query"></div>',
      link: {
        pre: function ($scope, element) {
          $scope.syntax = $scope.syntax || 'sql';

          $scope.editorOptions = {
            theme: 'solarized_dark',
            mode: 'json',
            require: ['ace/ext/language_tools'],
            advanced: {
              behavioursEnabled: true,
              enableSnippets: true,
              enableBasicAutocompletion: true,
              enableLiveAutocompletion: true,
              autoScrollEditorIntoView: true,
            },
            onLoad: function(editor) {
              QuerySnippet.query(function(snippets) {
                var snippetManager = ace.require("ace/snippets").snippetManager;
                var m = {
                  snippetText: ''
                };
                m.snippets = snippetManager.parseSnippetFile(m.snippetText);
                _.each(snippets, function(snippet) {
                  m.snippets.push(snippet.getSnippet());
                });

                snippetManager.register(m.snippets || [], m.scope);
              });

              editor.$blockScrolling = Infinity;
              editor.getSession().setUseWrapMode(true);
              editor.setShowPrintMargin(false);

              $scope.$watch('syntax', function(syntax) {
                var newMode = 'ace/mode/' + syntax;
                editor.getSession().setMode(newMode);
              });

              $scope.$watch('schema', function(newSchema, oldSchema) {
                if (newSchema !== oldSchema) {
                  var tokensCount = _.reduce(newSchema, function(totalLength, table) { return totalLength + table.columns.length }, 0);
                  // If there are too many tokens we disable live autocomplete, as it makes typing slower.
                  if (tokensCount > 5000) {
                    editor.setOption('enableLiveAutocompletion', false);
                  } else {
                    editor.setOption('enableLiveAutocompletion', true);
                  }
                }

                $scope.fullScreenEditor = function fullScreenEditor(editor, resize_height){

                    var fullScreen = dom.toggleCssClass(document.body, "fullScreen")
                    angular.element('.ace_editor.fullScreen').css('height', '');
                    dom.setCssClass(editor.container, "fullScreen", fullScreen)
                    editor.setAutoScrollEditorIntoView(!fullScreen)
                    document.querySelector('.navbar').classList.toggle("hide")

                    if (angular.element('.ace_editor.fullScreen')){
                        angular.element('.ace_editor.fullScreen').css('height', $scope.resize_height);
                    }

                    editor.resize();
                    editor.focus();
                }

                var resize_height;
                editorScope = $scope;
                editorInstance = editor;
                var dom = ace.require("ace/lib/dom");

                editor.commands.addCommand({
                    name: "Toggle Fullscreen",
                    bindKey: {win: "Esc", mac: "Esc"},
                    exec: function(editor) {
                        $scope.fullScreenEditor(editor, resize_height)
                    }
                })

              });

              $scope.$parent.$on("angular-resizable.resizing", function (event, args) {

                editor.resize();

                $scope.resize_height = (448 + args.height - 300).toString();
                angular.element('.ace_editor.fullScreen').css('height', $scope.resize_height);

              });
              $scope.query.editor = editor;

              editor.focus();
            }
          };

          var langTools = ace.require("ace/ext/language_tools");

          var schemaCompleter = {
            getCompletions: function(state, session, pos, prefix, callback) {
              if (prefix.length === 0 || !$scope.schema) {
                callback(null, []);
                return;
              }

              if (!$scope.schema.keywords) {
                var keywords = {};

                _.each($scope.schema, function (table) {
                  keywords[table.name] = 'Table';

                  _.each(table.columns, function (c) {
                    keywords[c] = 'Column';<commit_msg>enlarge no fullscreen<commit_after>(function() {
  'use strict'

  function queryLink() {
    return {
      restrict: 'E',
      scope: {
        'query': '=',
        'visualization': '=?'
      },
      template: '<a ng-href="{{link}}" class="query-link">{{query.name}}</a>',
      link: function(scope, element) {
        var hash = null;
        if (scope.visualization) {
          if (scope.visualization.type === 'TABLE') {
            // link to hard-coded table tab instead of the (hidden) visualization tab
            hash = 'table';
          } else {
            hash = scope.visualization.id;
          }
        }
        scope.link = scope.query.getUrl(false, hash);
      }
    }
  }

  function querySourceLink($location) {
    return {
      restrict: 'E',
      template: '<span ng-show="query.id && canViewSource">\
                    <a ng-show="!sourceMode"\
                      ng-href="{{query.getUrl(true, selectedTab)}}" class="btn btn-default">Show Source\
                    </a>\
                    <a ng-show="sourceMode"\
                      ng-href="{{query.getUrl(false, selectedTab)}}" class="btn btn-default">Hide Source\
                    </a>\
                </span>'
    }
  }

  function queryResultLink() {
    return {
      restrict: 'A',
      link: function (scope, element, attrs) {

        var fileType = attrs.fileType ? attrs.fileType : "csv";
        scope.$watch('queryResult && queryResult.getData()', function(data) {
          if (!data) {
            return;
          }

          if (scope.queryResult.getId() == null) {
            element.attr('href', '');
          } else {
            element.attr('href', 'api/queries/' + scope.query.id + '/results/' + scope.queryResult.getId() + '.' + fileType);
            element.attr('download', scope.query.name.replace(" ", "_") + moment(scope.queryResult.getUpdatedAt()).format("_YYYY_MM_DD") + "." + fileType);
          }
        });
      }
    }
  }

  // By default Ace will try to load snippet files for the different modes and fail. We don't need them, so we use these
  // placeholders until we define our own.
  function defineDummySnippets(mode) {
    ace.define("ace/snippets/" + mode, ["require", "exports", "module"], function(require, exports, module) {
      "use strict";

      exports.snippetText = "";
      exports.scope = mode;
    });
  };

  defineDummySnippets("python");
  defineDummySnippets("sql");
  defineDummySnippets("json");

  var editorScope;
  var editorInstance;

  function queryEditor(QuerySnippet) {
    return {
      restrict: 'E',
      scope: {
        'query': '=',
        'lock': '=',
        'schema': '=',
        'syntax': '='
      },
      template: '<style>.ace_editor.fullScreen {\
          height: 448px;\
          width: auto;\
          border: 0;\
          margin: 0;\
          position: fixed !important;\
          top: 0;\
          bottom: 0;\
          left: 0;\
          right: 0;\
          z-index: -10;}\
          .remove-t-padding { padding-top: 0 !important}\
      </style><div ui-ace="editorOptions" ng-model="query.query"></div>',
      link: {
        pre: function ($scope, element) {
          $scope.syntax = $scope.syntax || 'sql';

          $scope.editorOptions = {
            theme: 'solarized_dark',
            mode: 'json',
            require: ['ace/ext/language_tools'],
            advanced: {
              behavioursEnabled: true,
              enableSnippets: true,
              enableBasicAutocompletion: true,
              enableLiveAutocompletion: true,
              autoScrollEditorIntoView: true,
            },
            onLoad: function(editor) {
              QuerySnippet.query(function(snippets) {
                var snippetManager = ace.require("ace/snippets").snippetManager;
                var m = {
                  snippetText: ''
                };
                m.snippets = snippetManager.parseSnippetFile(m.snippetText);
                _.each(snippets, function(snippet) {
                  m.snippets.push(snippet.getSnippet());
                });

                snippetManager.register(m.snippets || [], m.scope);
              });

              editor.$blockScrolling = Infinity;
              editor.getSession().setUseWrapMode(true);
              editor.setShowPrintMargin(false);

              $scope.$watch('syntax', function(syntax) {
                var newMode = 'ace/mode/' + syntax;
                editor.getSession().setMode(newMode);
              });

              $scope.$watch('schema', function(newSchema, oldSchema) {
                if (newSchema !== oldSchema) {
                  var tokensCount = _.reduce(newSchema, function(totalLength, table) { return totalLength + table.columns.length }, 0);
                  // If there are too many tokens we disable live autocomplete, as it makes typing slower.
                  if (tokensCount > 5000) {
                    editor.setOption('enableLiveAutocompletion', false);
                  } else {
                    editor.setOption('enableLiveAutocompletion', true);
                  }
                }

                $scope.fullScreenEditor = function fullScreenEditor(editor){

                    document.querySelector('.navbar').classList.toggle("hide")
                    document.querySelector('.container .row.bg-white.m-t-10').classList.toggle("hide")
                    document.querySelector('.schema-container').classList.toggle("hide")
                    angular.element('.pace-done').toggleClass('remove-t-padding')
                    angular.element('.container .editor-box').removeClass('col-md-9')
                    angular.element('.container .editor-box').toggleClass('col-md-12')

                    editor.resize();
                    editor.focus();
                }

                editorScope = $scope;
                editorInstance = editor;
                var dom = ace.require("ace/lib/dom");

                editor.commands.addCommand({
                    name: "Toggle Fullscreen",
                    bindKey: {win: "Esc", mac: "Esc"},
                    exec: function(editor) {
                        $scope.fullScreenEditor(editor)
                    }
                })

              });

              $scope.$parent.$on("angular-resizable.resizing", function (event, args) {
                editor.resize();
              });
              $scope.query.editor = editor;

              editor.focus();
            }
          };\

          var langTools = ace.require("ace/ext/language_tools");

          var schemaCompleter = {
            getCompletions: function(state, session, pos, prefix, callback) {
              if (prefix.length === 0 || !$scope.schema) {
                callback(null, []);
                return;
              }

              if (!$scope.schema.keywords) {
                var keywords = {};

                _.each($scope.schema, function (table) {
                  keywords[table.name] = 'Table';

                  _.each(table.columns, function (c) {
                    keywords[c] = 'Column';
{'fraction_non_alphanumeric': 0.13603802176608348, 'fraction_numerical': 0.003168480506956881, 'mean_word_length': 1.5862130388314928, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2760233', 'n_tokens_mistral': 3978, 'n_tokens_neox': 3732, 'n_words': 737}