// Copyright 2014 The Oppia Authors. 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 Controllers for the unresolved answers section of the
 *   state editor.
 *
 * @author sll@google.com (Sean Lip)
 */

oppia.controller('StateStatistics', [
    '$scope', 'explorationData', 'editorContextService', 'explorationStatesService',
    function($scope, explorationData, editorContextService, explorationStatesService) {
  $scope.unresolvedAnswersList = [];

  $scope.initStateStatistics = function(data) {
    $scope.unresolvedAnswers = data.unresolved_answers;
    $scope.generateUnresolvedAnswersList();
  };

  $scope.$on('refreshStateEditor', function(evt) {
    $scope.stateName = editorContextService.getActiveStateName();
    var stateData = explorationStatesService.getState($scope.stateName);
    $scope.initStateStatistics(stateData);
  });

  $scope.generateUnresolvedAnswersList = function() {
    $scope.unresolvedAnswersList = [];
    for (var answerItem in $scope.unresolvedAnswers) {
      $scope.unresolvedAnswersList.push({
        'answer': answerItem,
        'count': $scope.unresolvedAnswers[answerItem]
      });
    }
  };

  $scope.deleteUnresolvedAnswer = function(answer) {
    $scope.unresolvedAnswers[answer] = 0;
    explorationData.resolveAnswers($scope.stateName, [answer]);
    $scope.generateUnresolvedAnswersList();
  };
}]);

@@ -1005,84 +1005,324 @@
 %0A%0A  
-$scope.initStateStatistics = function(data) %7B%0A    $scope.unresolvedAnswers =
+var INTERACTIONS_WITHOUT_UNRESOLVED_ANSWERS = %5B'Continue'%5D;%0A%0A  $scope.initStateStatistics = function(data) %7B%0A    // Do not show unresolved answers if the interaction is of type 'Continue'.%0A    $scope.unresolvedAnswers = (%0A      INTERACTIONS_WITHOUT_UNRESOLVED_ANSWERS.indexOf(data.interaction.id) !== -1 ?%0A      %7B%7D :
  dat
@@ -1341,16 +1341,17 @@
 _answers
+)
 ;%0A    $s

Fix issue 764: do not show unhandled answers for the Continue interaction.