<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 exploration page.
 *
 * @author <EMAIL> (<NAME>)
 */

var END_DEST = 'END';
var QN_DEST_PREFIX = 'q-';
// TODO(sll): Internationalize these.
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.

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

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

  // Valid state properties
  var validStateProperties = [
    'content',
    'interactive_widget',
    'interactive_params',
    'interactive_rulesets',
    'param_changes',
    'state_name',
    'yaml_file'
  ];

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

  // There should be one GET request made for an exploration when the editor page
  // is initially loaded. This results in a broadcast that will initialize the
  // relevant frontend controllers.
  // Any further GET requests will be state-specific and will be obtained by
  // calling getStateData(stateId).
  // Thereafter, any updates to the model would be PUT by calling
  // saveStateData(). This would send a PUT request to the backend to update the
  // backend model. On success, it will update the model stored here, too.

  // TODO(sll): Find a fix for multiple users editing the same exploration
  // concurrently.

  explorationData.getData = function(stateId) {
    // Retrieve data from the server.
    console.log('Retrieving exploration data from the server');

    $http.get(explorationUrl + '/data').success(
      function(data) {
        explorationData.data = data;
        explorationData.broadcastExploration();
        explorationData.stateId = null;
        if (stateId && stateId in explorationData.data.states) {
          explorationData.broadcastState(stateId);
        }
      }).error(function(errorResponse) {
        warningsData.addWarning('Server error: ' + errorResponse.error);
      });
  };

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

  explorationData.broadcastState = function(stateId) {
    if (!stateId) {
      return;
    }
    explorationData.stateId = stateId;
    console.log('Broadcasting data for state ' + explorationData.stateId);
    $rootScope.$broadcast('explorationData');
  };

  explorationData.getStateData = function(stateId) {
    if (!stateId) {
      return;
    }
    console.log('Getting state data for state ' + stateId);
    explorationData.stateId = stateId;
    if ('states' in explorationData.data && stateId in explorationData.data.states) {
      return explorationData.data.states[stateId];
    } else {
      explorationData.getData(stateId);
    }
  };

  explorationData.getStateProperty = function(stateId, property) {
    if (!stateId) {
      return;
    }
    // NB: This does not broadcast an event.
    console.log(
        'Getting state property ' + property + ' for state ' + stateId);
    var stateData = explorationData.getStateData(stateId);
    if (!stateData) {
      warningsData.addWarning('Cannot get data for state ' + stateId);
      return;
    }
    if (!stateData.hasOwnProperty(property)) {
      warningsData.addWarning('Invalid property name: ' + property);
      return;
    }
    return stateData[property];
  };

  // Saves data for a given state to the backend, and, on a success callback,
  // updates the data for that state in the frontend and broadcasts an
  // 'state updated' event.
  explorationData.saveStateData = function(stateId, propertyValueMap) {
    for (var property in propertyValueMap) {
      if (validStateProperties.indexOf(property) < 0) {<commit_msg>Fixing an error in explorationData.getData()<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 exploration page.
 *
 * @author <EMAIL> (<NAME>)
 */

var END_DEST = 'END';
var QN_DEST_PREFIX = 'q-';
// TODO(sll): Internationalize these.
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.

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

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

  // Valid state properties
  var validStateProperties = [
    'content',
    'interactive_widget',
    'interactive_params',
    'interactive_rulesets',
    'param_changes',
    'state_name',
    'yaml_file'
  ];

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

  // There should be one GET request made for an exploration when the editor page
  // is initially loaded. This results in a broadcast that will initialize the
  // relevant frontend controllers.
  // Any further GET requests will be state-specific and will be obtained by
  // calling getStateData(stateId).
  // Thereafter, any updates to the model would be PUT by calling
  // saveStateData(). This would send a PUT request to the backend to update the
  // backend model. On success, it will update the model stored here, too.

  // TODO(sll): Find a fix for multiple users editing the same exploration
  // concurrently.

  explorationData.getData = function() {
    // Retrieve data from the server.
    console.log('Retrieving exploration data from the server');

    $http.get(explorationUrl + '/data').success(
      function(data) {
        explorationData.data = data;
        explorationData.broadcastExploration();
      }).error(function(errorResponse) {
        warningsData.addWarning('Server error: ' + errorResponse.error);
      });
  };

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

  explorationData.broadcastState = function(stateId) {
    if (!stateId) {
      return;
    }
    explorationData.stateId = stateId;
    console.log('Broadcasting data for state ' + explorationData.stateId);
    $rootScope.$broadcast('explorationData');
  };

  explorationData.getStateData = function(stateId) {
    if (!stateId) {
      return;
    }
    console.log('Getting state data for state ' + stateId);
    explorationData.stateId = stateId;
    if ('states' in explorationData.data && stateId in explorationData.data.states) {
      return explorationData.data.states[stateId];
    } else {
      explorationData.getData();
      return explorationData.data.states[stateId];
    }
  };

  explorationData.getStateProperty = function(stateId, property) {
    if (!stateId) {
      return;
    }
    // NB: This does not broadcast an event.
    console.log(
        'Getting state property ' + property + ' for state ' + stateId);
    var stateData = explorationData.getStateData(stateId);
    if (!stateData) {
      warningsData.addWarning('Cannot get data for state ' + stateId);
      return;
    }
    if (!stateData.hasOwnProperty(property)) {
      warningsData.addWarning('Invalid property name: ' + property);
      return;
    }
    return stateData[property];
  };

  // Saves data for a given state to the backend, and, on a success callback,
  // updates the data for that state in the frontend and broadcasts an
  // 'state updated' event.
  explorationData.saveStateData = function(stateId, propertyValueMap) {
    for (var property in propertyValueMap) {
      if (validStateProperties.indexOf(property) < 0) {
{'fraction_non_alphanumeric': 0.11414921732059362, 'fraction_numerical': 0.0020329335230737954, 'mean_word_length': 3.365128660159716, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '527041', 'n_tokens_mistral': 2762, 'n_tokens_neox': 2726, 'n_words': 870}