<commit_before>'use strict';

angular.module('wikidataTimeline.newTimelineView', ['ngRoute'])

.config(['$routeProvider', function($routeProvider) {
  $routeProvider.when('/new', {
    templateUrl: 'views/newTimelineView/newTimelineView.html',
    controller: 'NewTimelineViewCtrl'
  });
}])

.controller('NewTimelineViewCtrl', ['$scope', '$timeout', '$location', '$wikidata', 'Analytics', '$userSettings', '$urlParamManager',
function($scope, $timeout, $location, $wikidata, $analytics, $userSettings, $urlParamManager) {
  $analytics.trackPage('/new', document.title);

  // initialize bootstrap tooltips :/
  $('[data-toggle="tooltip"]').tooltip()

  // disclaimer
  $scope.$userSettings = $userSettings;

  // URLParam setup
  var defaultValues = {
    query: '',
    languages:   ['en', 'fr'],
    widthOfYear: 20,
    defaultEndTime: 'now',
    title:       ''
  };
  var urlManager = $urlParamManager(defaultValues);
  $scope.urlManager = urlManager;
  $scope.languages = urlManager.get('languages') ? urlManager.get('languages').join(',') : 'en,fr';

  $scope.title = urlManager.get('title');
  $scope.defaultEndTime = urlManager.get('defaultEndTime');
  $scope.activeToken = '';
  $scope.showAllWDQDocs = false;
  $scope.contextualDocsEnabled = true;
  $scope.toggleContextualDocs = function() {
    $scope.activeToken = '';
    $scope.contextualDocsEnabled = !$scope.contextualDocsEnabled;
  };
  $scope.saveButtonStates = {
    Def: 1,
    ValidatingWDQ: 2,
    InvalidWDQ: 3,
    PreparingToDraw: 4
  };
  $scope.saveButtonState = $scope.saveButtonStates.Def;
  $scope.wdqError = '';

  $scope.drawTimeline = function() {
    var wdq = queryEditor.getValue();
    $scope.wdqError = '';

    $scope.saveButtonState = $scope.saveButtonStates.ValidatingWDQ;
    $wikidata.WDQ(wdq, {noitems: 1})
    .then(function(response) {
      if (response.data.status.error !== 'OK') {
        $scope.wdqError = response.data.status.error;
        $scope.saveButtonState = $scope.saveButtonStates.InvalidWDQ;
        $timeout(function() {
          $scope.saveButtonState = $scope.saveButtonStates.Def;
        }, 1000);
      } else {
        $scope.saveButtonState = $scope.saveButtonStates.PreparingToDraw;
        $location.path('timeline').search({
          title: $scope.title,
          query: wdq,
          languages: $scope.languages
        });
      }
    });
  }

  var queryEditor = CodeMirror($('.query-editor')[0], {
    viewportMargin: Infinity,
    lineWrapping: true,
    matchBrackets: true,
    value: urlManager.get('query')
  });

  var getTokenUnderCursor = function(cm) {
    var token = cm.getTokenAt(cm.getCursor());

    if (token.type == 'keyword') {
      $scope.activeToken = token.string.toLowerCase();
      $scope.$digest();
    } else if (token.type == 'operator') {
      $scope.activeToken = 'operator';
      $scope.$digest();
    }<commit_msg>fix: defaultEndTime passed when clicking Draw<commit_after>'use strict';

angular.module('wikidataTimeline.newTimelineView', ['ngRoute'])

.config(['$routeProvider', function($routeProvider) {
  $routeProvider.when('/new', {
    templateUrl: 'views/newTimelineView/newTimelineView.html',
    controller: 'NewTimelineViewCtrl'
  });
}])

.controller('NewTimelineViewCtrl', ['$scope', '$timeout', '$location', '$wikidata', 'Analytics', '$userSettings', '$urlParamManager',
function($scope, $timeout, $location, $wikidata, $analytics, $userSettings, $urlParamManager) {
  $analytics.trackPage('/new', document.title);

  // initialize bootstrap tooltips :/
  $('[data-toggle="tooltip"]').tooltip()

  // disclaimer
  $scope.$userSettings = $userSettings;

  // URLParam setup
  var defaultValues = {
    query: '',
    languages:   ['en', 'fr'],
    widthOfYear: 20,
    defaultEndTime: 'now',
    title:       ''
  };
  var urlManager = $urlParamManager(defaultValues);
  $scope.urlManager = urlManager;
  $scope.languages = urlManager.get('languages') ? urlManager.get('languages').join(',') : 'en,fr';

  $scope.title = urlManager.get('title');
  $scope.defaultEndTime = urlManager.get('defaultEndTime');
  $scope.activeToken = '';
  $scope.showAllWDQDocs = false;
  $scope.contextualDocsEnabled = true;
  $scope.toggleContextualDocs = function() {
    $scope.activeToken = '';
    $scope.contextualDocsEnabled = !$scope.contextualDocsEnabled;
  };
  $scope.saveButtonStates = {
    Def: 1,
    ValidatingWDQ: 2,
    InvalidWDQ: 3,
    PreparingToDraw: 4
  };
  $scope.saveButtonState = $scope.saveButtonStates.Def;
  $scope.wdqError = '';

  $scope.drawTimeline = function() {
    var wdq = queryEditor.getValue();
    $scope.wdqError = '';

    $scope.saveButtonState = $scope.saveButtonStates.ValidatingWDQ;
    $wikidata.WDQ(wdq, {noitems: 1})
    .then(function(response) {
      if (response.data.status.error !== 'OK') {
        $scope.wdqError = response.data.status.error;
        $scope.saveButtonState = $scope.saveButtonStates.InvalidWDQ;
        $timeout(function() {
          $scope.saveButtonState = $scope.saveButtonStates.Def;
        }, 1000);
      } else {
        $scope.saveButtonState = $scope.saveButtonStates.PreparingToDraw;
        $location.path('timeline').search({
          title: $scope.title,
          query: wdq,
          languages: $scope.languages,
          defaultEndTime: $scope.defaultEndTime
        });
      }
    });
  }

  var queryEditor = CodeMirror($('.query-editor')[0], {
    viewportMargin: Infinity,
    lineWrapping: true,
    matchBrackets: true,
    value: urlManager.get('query')
  });

  var getTokenUnderCursor = function(cm) {
    var token = cm.getTokenAt(cm.getCursor());

    if (token.type == 'keyword') {
      $scope.activeToken = token.string.toLowerCase();
      $scope.$digest();
    } else if (token.type == 'operator') {
      $scope.activeToken = 'operator';
      $scope.$digest();
    }
{'fraction_non_alphanumeric': 0.1634434365907924, 'fraction_numerical': 0.004107479034742427, 'mean_word_length': 3.5979543666404408, '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': '2221545', 'n_tokens_mistral': 1914, 'n_tokens_neox': 1866, 'n_words': 299}