<commit_before>// Copyright 2012 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS-IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
 * @fileoverview Angular controllers for elements on an editor's question page.
 *
 * @author <EMAIL> (<NAME>)
 */

var END_DEST = '-1';
var QN_DEST_PREFIX = 'q-';
// TODO(sll): Internationalize these.
var END_STRING = 'END';
var GUI_EDITOR_URL = '/gui'
var YAML_EDITOR_URL = '/text'

// TODO(sll): Move all strings to the top of the file, particularly
// warning messages and activeInputData.name.
// TODO(sll): console.log is not supported in IE. Fix before launch.
// TODO(sll): CSS3 selectors of the form [..] aren't supported in all browsers.

var DEFAULT_CATEGORY_NAME = 'Default';
var DEFAULT_DESTS = {
    'finite': [],
    'none': [{'category': '', 'dest': END_DEST, 'text': ''}],
    'numeric': [{'category': DEFAULT_CATEGORY_NAME, 'dest': END_DEST, 'text': ''}],
    'set': [{'category': DEFAULT_CATEGORY_NAME, 'dest': END_DEST, 'text': ''}],
    'text': [{'category': DEFAULT_CATEGORY_NAME, 'dest': END_DEST, 'text': ''}]
};
// The following list maps input views to classifiers.
var CLASSIFIER_MAPPING = {
    'int': 'numeric',
    'multiple_choice': 'finite',
    'none': 'none',
    'set': 'set',
    'text': 'text'
};
var HUMAN_READABLE_INPUT_TYPE_MAPPING = {
    'int': 'Numeric',
    'multiple_choice': 'Multiple choice',
    'none': 'none',
    'set': 'Set',
    'text': 'Free text'
};

oppia.config(['$routeProvider', function($routeProvider) {
  $routeProvider.
      when(YAML_EDITOR_URL,
           {templateUrl: '/templates/yaml', controller: YamlEditor}).
      when(YAML_EDITOR_URL + '/:stateId',
           {templateUrl: '/templates/yaml', controller: YamlEditor}).
      when(GUI_EDITOR_URL,
           {templateUrl: '/templates/gui', controller: GuiEditor}).
      when(GUI_EDITOR_URL + '/:stateId',
           {templateUrl: '/templates/gui', controller: GuiEditor}).
      when('/', {templateUrl: '/templates/yaml', controller: ExplorationTab}).
      otherwise({redirectTo: '/'});
}]);


oppia.factory('explorationData', function($rootScope, $http, warningsData) {
  // Put exploration variables here.
  var explorationData = {};

  // The pathname should be: .../create/{exploration_id}[/{state_id}]
  var explorationUrl = '/create/' + pathnameArray[2];

  explorationData.getData = function() {
    var obj = this;
    console.log('Getting exploration data');
    $http.get(explorationUrl + '/data').success(function(data) {
      obj.data = data;
      obj.states = data.state_list;
      obj.initState = data.init_state_id;

      obj.broadcastExploration();
    }).error(function(data) {
      warningsData.addWarning('Server error: ' + data.error);
    });
  };

  explorationData.broadcastExploration = function() {
    $rootScope.$broadcast('explorationData');
  }

  return explorationData;
});


oppia.factory('stateData', function($rootScope, $http, warningsData) {
  // Put state variables here.
  var stateData = {};

  // The pathname should be: .../create/{exploration_id}[/{state_id}]
  var explorationUrl = '/create/' + pathnameArray[2];

  /**
   * Gets the data for a particular state.
   * @param {string} stateId The id of the state to get the data for.
   */
  // TODO(sll): Get this from the frontend if is already there.
  stateData.getData = function(stateId) {
    var obj = this;
    console.log('Getting state data');
    $http.post(
        explorationUrl + '/' + stateId, '',
        {headers: {'Content-Type': 'application/x-www-form-urlencoded'}}).
            success(function(data) {
              obj.data = data;
              console.log(data);
              for (var i =0 ;i < data.actions.length; i++) {
                console.log(data.actions[i].dest);
              }
              obj.stateName = data.stateName;
              obj.stateContent = data.stateContent;
              obj.inputType = data.inputType;
              obj.classifier = data.classifier;
              obj.yaml = data.yaml;

              obj.broadcastState();
            }).
            error(function(data) {
              warningsData.addWarning('Server error: ' + data.error);
            });
  };

  stateData.broadcastState = function() {
    $rootScope.$broadcast('stateData');
  }

  return stateData;
});


// Filter that truncates long descriptors.
// TODO(sll): Strip out HTML tags before truncating.
oppia.filter('truncate', function() {
  return function(input, length, suffix) {
    if (!input)
      return '';
    if (isNaN(length))
      length = 50;
    if (suffix === undefined)
      suffix = '...';
    if (input.length <= length || input.length - suffix.length <= length)
      return input;
    else
      return String(input).substring(0, length - suffix.length) + suffix;
  }
});

// Receive events from the iframed widget repository.
oppia.run(function($rootScope) {
  window.addEventListener('message', function(event) {
    console.log(event);
    $rootScope.$broadcast('message', event);
  });
});


function ExplorationTab($scope) {
  // Changes the tab to the Exploration Editor view.
  $('#editorViewTab a[href="#explorationEditor"]').tab('show');
};

function EditorExploration($scope, $http, $location, $routeParams,
    stateData, explorationData, warningsData, activeInputData) {

  /********************************************
  * Methods affecting the URL location hash.
  ********************************************/
  /**
   * Gets the current mode from the URL location hash.
   */
  $scope.getMode = function() {
    if ($location.$$url.substring(0, GUI_EDITOR_URL.length) == GUI_EDITOR_URL) {
      return GUI_EDITOR_URL.substring(1);
    } else {
      return YAML_EDITOR_URL.substring(1);
    }
  };

  /**
   * Changes the state editor mode.
   * @param {string} mode The state editor mode to switch to (currently, gui or text).
   */
  $scope.changeMode = function(mode) {
    if (mode == GUI_EDITOR_URL.substring(1)) {
      $location.path(GUI_EDITOR_URL + '/' + $scope.stateId);
    } else if (mode == YAML_EDITOR_URL.substring(1)) {
      $location.path(YAML_EDITOR_URL + '/' + $scope.stateId);
    } else {
      warningsData.addWarning('Error: mode ' + mode + ' doesn\'t exist.');
    }
  };

  // Changes the location hash when the editorView tab is changed.
  $('#editorViewTab a[data-toggle="tab"]').on('shown', function (e) {
    console.log(e.target.hash);
    if (e.target.hash == '#stateEditor') {
      $scope.changeMode($scope.getMode());
    } else {
      $location.path('');
      explorationData.getData();
    }
    $scope.$apply();
  });
<commit_msg>Change default state editor mode to GUI mode<commit_after>// Copyright 2012 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS-IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
 * @fileoverview Angular controllers for elements on an editor's question page.
 *
 * @author <EMAIL> (<NAME>)
 */

var END_DEST = '-1';
var QN_DEST_PREFIX = 'q-';
// TODO(sll): Internationalize these.
var END_STRING = 'END';
var GUI_EDITOR_URL = '/gui'
var YAML_EDITOR_URL = '/text'

// TODO(sll): Move all strings to the top of the file, particularly
// warning messages and activeInputData.name.
// TODO(sll): console.log is not supported in IE. Fix before launch.
// TODO(sll): CSS3 selectors of the form [..] aren't supported in all browsers.

var DEFAULT_CATEGORY_NAME = 'Default';
var DEFAULT_DESTS = {
    'finite': [],
    'none': [{'category': '', 'dest': END_DEST, 'text': ''}],
    'numeric': [{'category': DEFAULT_CATEGORY_NAME, 'dest': END_DEST, 'text': ''}],
    'set': [{'category': DEFAULT_CATEGORY_NAME, 'dest': END_DEST, 'text': ''}],
    'text': [{'category': DEFAULT_CATEGORY_NAME, 'dest': END_DEST, 'text': ''}]
};
// The following list maps input views to classifiers.
var CLASSIFIER_MAPPING = {
    'int': 'numeric',
    'multiple_choice': 'finite',
    'none': 'none',
    'set': 'set',
    'text': 'text'
};
var HUMAN_READABLE_INPUT_TYPE_MAPPING = {
    'int': 'Numeric',
    'multiple_choice': 'Multiple choice',
    'none': 'none',
    'set': 'Set',
    'text': 'Free text'
};

oppia.config(['$routeProvider', function($routeProvider) {
  $routeProvider.
      when(YAML_EDITOR_URL,
           {templateUrl: '/templates/yaml', controller: YamlEditor}).
      when(YAML_EDITOR_URL + '/:stateId',
           {templateUrl: '/templates/yaml', controller: YamlEditor}).
      when(GUI_EDITOR_URL,
           {templateUrl: '/templates/gui', controller: GuiEditor}).
      when(GUI_EDITOR_URL + '/:stateId',
           {templateUrl: '/templates/gui', controller: GuiEditor}).
      when('/', {templateUrl: '/templates/yaml', controller: ExplorationTab}).
      otherwise({redirectTo: '/'});
}]);


oppia.factory('explorationData', function($rootScope, $http, warningsData) {
  // Put exploration variables here.
  var explorationData = {};

  // The pathname should be: .../create/{exploration_id}[/{state_id}]
  var explorationUrl = '/create/' + pathnameArray[2];

  explorationData.getData = function() {
    var obj = this;
    console.log('Getting exploration data');
    $http.get(explorationUrl + '/data').success(function(data) {
      obj.data = data;
      obj.states = data.state_list;
      obj.initState = data.init_state_id;

      obj.broadcastExploration();
    }).error(function(data) {
      warningsData.addWarning('Server error: ' + data.error);
    });
  };

  explorationData.broadcastExploration = function() {
    $rootScope.$broadcast('explorationData');
  }

  return explorationData;
});


oppia.factory('stateData', function($rootScope, $http, warningsData) {
  // Put state variables here.
  var stateData = {};

  // The pathname should be: .../create/{exploration_id}[/{state_id}]
  var explorationUrl = '/create/' + pathnameArray[2];

  /**
   * Gets the data for a particular state.
   * @param {string} stateId The id of the state to get the data for.
   */
  // TODO(sll): Get this from the frontend if is already there.
  stateData.getData = function(stateId) {
    var obj = this;
    console.log('Getting state data');
    $http.post(
        explorationUrl + '/' + stateId, '',
        {headers: {'Content-Type': 'application/x-www-form-urlencoded'}}).
            success(function(data) {
              obj.data = data;
              console.log(data);
              for (var i =0 ;i < data.actions.length; i++) {
                console.log(data.actions[i].dest);
              }
              obj.stateName = data.stateName;
              obj.stateContent = data.stateContent;
              obj.inputType = data.inputType;
              obj.classifier = data.classifier;
              obj.yaml = data.yaml;

              obj.broadcastState();
            }).
            error(function(data) {
              warningsData.addWarning('Server error: ' + data.error);
            });
  };

  stateData.broadcastState = function() {
    $rootScope.$broadcast('stateData');
  }

  return stateData;
});


// Filter that truncates long descriptors.
// TODO(sll): Strip out HTML tags before truncating.
oppia.filter('truncate', function() {
  return function(input, length, suffix) {
    if (!input)
      return '';
    if (isNaN(length))
      length = 50;
    if (suffix === undefined)
      suffix = '...';
    if (input.length <= length || input.length - suffix.length <= length)
      return input;
    else
      return String(input).substring(0, length - suffix.length) + suffix;
  }
});

// Receive events from the iframed widget repository.
oppia.run(function($rootScope) {
  window.addEventListener('message', function(event) {
    console.log(event);
    $rootScope.$broadcast('message', event);
  });
});


function ExplorationTab($scope) {
  // Changes the tab to the Exploration Editor view.
  $('#editorViewTab a[href="#explorationEditor"]').tab('show');
};

function EditorExploration($scope, $http, $location, $routeParams,
    stateData, explorationData, warningsData, activeInputData) {

  /********************************************
  * Methods affecting the URL location hash.
  ********************************************/
  /**
   * Gets the current mode from the URL location hash, with the GUI mode being
   * the default.
   */
  $scope.getMode = function() {
    if ($location.$$url.substring(0, YAML_EDITOR_URL.length) == YAML_EDITOR_URL) {
      return YAML_EDITOR_URL.substring(1);
    } else {
      return GUI_EDITOR_URL.substring(1);
    }
  };

  /**
   * Changes the state editor mode.
   * @param {string} mode The state editor mode to switch to (currently, gui or text).
   */
  $scope.changeMode = function(mode) {
    if (mode == GUI_EDITOR_URL.substring(1)) {
      $location.path(GUI_EDITOR_URL + '/' + $scope.stateId);
    } else if (mode == YAML_EDITOR_URL.substring(1)) {
      $location.path(YAML_EDITOR_URL + '/' + $scope.stateId);
    } else {
      warningsData.addWarning('Error: mode ' + mode + ' doesn\'t exist.');
    }
  };

  // Changes the location hash when the editorView tab is changed.
  $('#editorViewTab a[data-toggle="tab"]').on('shown', function (e) {
    console.log(e.target.hash);
    if (e.target.hash == '#stateEditor') {
      $scope.changeMode($scope.getMode());
    } else {
      $location.path('');
      explorationData.getData();
    }
    $scope.$apply();
  });

{'fraction_non_alphanumeric': 0.16235541535226078, 'fraction_numerical': 0.0029442691903259727, 'mean_word_length': 3.117171717171717, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '3006162', 'n_tokens_mistral': 4387, 'n_tokens_neox': 4292, 'n_words': 1114}