Skip to content

Commit

Permalink
Added correctness editor of an answer group (oppia#4270)
Browse files Browse the repository at this point in the history
* updated but not working-properly

* correct_part works, only the default outcome case remains, and linting errors to be removed

* done except that settings part checking for linting issues

* corrected linting of correctEditor and ResponseService

* added new line in the end of the file

* updated response_header_directive.html

* Updated the classes

* Added the correctness option for an answer group

* Updated the files according to the review

* Updated the AnswerGroupCorrectnessLabelEditor.js

* corrected some linting issues

* Updated state_editor_responses.html and StateResponses.js

* added boolean setting

* Updated the function name to isEnabled

* updated answer_group_editor.html
  • Loading branch information
ishucr7 authored and seanlip committed Dec 30, 2017
1 parent e162f29 commit c1c6a90
Show file tree
Hide file tree
Showing 13 changed files with 219 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// 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 Directive for the correctness label editor for answer groups.
*/

// This directive controls an editor for selecting whether the answers
// which fall under this answer group are correct or not. It also includes
// 'Cancel' and 'Save' buttons. The 'Save' button calls 'onSaveCallback'
// when clicked.
oppia.directive('correctnessLabelEditor', [
'$log', 'UrlInterpolationService', function($log, UrlInterpolationService) {
return {
restrict: 'E',
scope: {
isEditable: '&isEditable',
onSaveCorrectnessLabel: '&',
labelledAsCorrect: '='
},
templateUrl: UrlInterpolationService.getDirectiveTemplateUrl(
'/components/' + 'correct_editor_directive.html'),
controller: [
'$scope', 'ResponsesService', function(
$scope, ResponsesService) {
var onExternalSave = function() {
// The reason for this guard is because, when the editor page for an
// exploration is first opened, the 'initializeAnswerGroups' event
// (which fires an 'externalSave' event) only fires after the
// $scope.savedCorrectnessLabel is set above. Until then,
// $scope.savedCorrectnessLabel is undefined.
if ($scope.savedCorrectnessLabel === undefined) {
$scope.savedCorrectnessLabel = angular.copy(
$scope.labelledAsCorrect);
}

if ($scope.correctnessLabelEditorIsOpen) {
if ($scope.editCorrectnessLabelForm.form.$valid) {
$scope.saveCorrectnessLabel($scope.labelledAsCorrect);
} else {
$scope.cancelEdit();
}
}
};

$scope.$on('externalSave', function() {
onExternalSave();
});

$scope.$on('onInteractionIdChanged', function() {
onExternalSave();
});

$scope.openCorrectnessLabelEditor = function() {
if ($scope.isEditable()) {
$scope.correctnessLabelEditorIsOpen = true;
}
};
$scope.cancelEdit = function() {
$scope.labelledAsCorrect = angular.copy(
$scope.savedCorrectnessLabel);
$scope.correctnessLabelEditorIsOpen = false;
};

$scope.saveCorrectnessLabel = function(tempCorrect) {
$scope.correctnessLabelEditorIsOpen = false;
$scope.savedCorrectnessLabel = angular.copy(
tempCorrect);
$scope.onSaveCorrectnessLabel()($scope.savedCorrectnessLabel);
};

$scope.init = function() {
$scope.savedCorrectnessLabel = angular.copy(
$scope.labelledAsCorrect);
$scope.correctnessLabelEditorIsOpen = false;
$scope.editCorrectnessLabelForm = {};

// Select a default correct value, if one isn't already there.
if ($scope.labelledAsCorrect === null) {
$scope.labelledAsCorrect = false;
}
};

$scope.init();
}
]
};
}]);
12 changes: 11 additions & 1 deletion core/templates/dev/head/components/AnswerGroupEditorDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ oppia.directive('answerGroupEditor', [
getOnSaveAnswerGroupDestFn: '&onSaveAnswerGroupDest',
getOnSaveAnswerGroupFeedbackFn: '&onSaveAnswerGroupFeedback',
getOnSaveAnswerGroupRulesFn: '&onSaveAnswerGroupRules',
getOnSaveAnswerGroupCorrectnessLabelFn:
'&onSaveAnswerGroupCorrectnessLabel',
outcome: '=',
suppressWarnings: '&',
labelledAsCorrect: '=',
rules: '='
},
templateUrl: UrlInterpolationService.getDirectiveTemplateUrl(
Expand All @@ -36,13 +39,20 @@ oppia.directive('answerGroupEditor', [
'$scope', 'stateInteractionIdService', 'ResponsesService',
'EditorStateService', 'AlertsService', 'INTERACTION_SPECS',
'RULE_TYPE_CLASSIFIER', 'RuleObjectFactory',
'explorationCorrectnessFeedbackService',
function(
$scope, stateInteractionIdService, ResponsesService,
EditorStateService, AlertsService, INTERACTION_SPECS,
RULE_TYPE_CLASSIFIER, RuleObjectFactory) {
RULE_TYPE_CLASSIFIER, RuleObjectFactory,
explorationCorrectnessFeedbackService) {
$scope.rulesMemento = null;
$scope.activeRuleIndex = ResponsesService.getActiveRuleIndex();
$scope.editAnswerGroupForm = {};
$scope.answerGroupIsDefault = ($scope.rules !== null);

$scope.isCorrectnessFeedbackEnabled = function() {
return explorationCorrectnessFeedbackService.isEnabled();
};

$scope.getAnswerChoices = function() {
return ResponsesService.getAnswerChoices();
Expand Down
9 changes: 7 additions & 2 deletions core/templates/dev/head/components/ResponseHeaderDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,18 @@ oppia.directive('responseHeader', [
getShortSummary: '&shortSummary',
isActive: '&isActive',
getOnDeleteFn: '&onDeleteFn',
getCorrect: '&labelledAsCorrect',
getNumRules: '&numRules'
},
templateUrl: UrlInterpolationService.getDirectiveTemplateUrl(
'/components/' +
'response_header_directive.html'),
controller: [
'$scope', 'editabilityService', 'EditorStateService', 'RouterService',
'PLACEHOLDER_OUTCOME_DEST',
'PLACEHOLDER_OUTCOME_DEST', 'explorationCorrectnessFeedbackService',
function(
$scope, editabilityService, EditorStateService, RouterService,
PLACEHOLDER_OUTCOME_DEST) {
PLACEHOLDER_OUTCOME_DEST, explorationCorrectnessFeedbackService) {
$scope.editabilityService = editabilityService;

$scope.isOutcomeLooping = function() {
Expand All @@ -46,6 +47,10 @@ oppia.directive('responseHeader', [
return outcome && (outcome.dest === activeStateName);
};

$scope.isCorrectnessFeedbackEnabled = function() {
return explorationCorrectnessFeedbackService.isEnabled();
};

$scope.isCreatingNewState = function() {
var outcome = $scope.getOutcome();
return outcome && outcome.dest === PLACEHOLDER_OUTCOME_DEST;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
answer-group-editor .oppia-delete-rule-button:hover {
opacity: 1;
}
answer-group-editor .oppia-correctness-label-editor {
margin-top: 25px;
}
</style>

<div style="height: 100%;">
Expand Down Expand Up @@ -92,4 +95,9 @@
outcome="outcome"
suppress-warnings="suppressWarnings()">
</outcome-editor>

<div class="oppia-correctness-label-editor" ng-if="answerGroupIsDefault && isCorrectnessFeedbackEnabled()">
<correctness-label-editor is-editable="isEditable" on-save-correctness-label="getOnSaveAnswerGroupCorrectnessLabelFn()" labelled-as-correct="labelledAsCorrect">
</correctness-label-editor>
</div>
</div>
38 changes: 38 additions & 0 deletions core/templates/dev/head/components/correct_editor_directive.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<div ng-if="!correctnessLabelEditorIsOpen"
title="<[isEditable() ? 'Edit correctness setting' : '']>"
style="height: 100%;">
<div class="oppia-readonly-rule-tile"
ng-class="{'oppia-editable-section': isEditable()}">
<div class="oppia-rule-details-header">
<div class="oppia-click-to-start-editing"
ng-if="isEditable()" ng-click="openCorrectnessLabelEditor()">
<i ng-if="isEditable()" class="material-icons oppia-editor-edit-icon pull-right"
title="Edit Correctness setting">&#xE254;
</i>
</div>

<strong>The answers falling under this group are
<span ng-if="labelledAsCorrect" style="color: rgb(20, 180, 15)">
correct
</span>
<span ng-if="!labelledAsCorrect" style="color: rgb(243, 13, 13)">
incorrect
</span>
</strong>
</div>
</div>
</div>

<div style="position: relative;" ng-if="isEditable() && correctnessLabelEditorIsOpen">
<strong>Answers caught by this answer group should be considered correct</strong>
<form class="form-inline" role="form" name="editCorrectnessLabelForm.form">
<input type="checkbox" ng-model="labelledAsCorrect" ng-disabled="isDisabled()">
</form>
<div class="oppia-rule-save-cancel-buttons">
<div class="pull-right">
<button type="button" class="btn btn-default" ng-click="cancelEdit()">Cancel</button>
<button type="button" class="btn btn-success" ng-disabled="editCorrectnessLabelForm.form.$invalid" ng-click="saveCorrectnessLabel(labelledAsCorrect)">Save</button>
</div>
<div style="clear: both;"></div>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
</style>
<div class="oppia-response-header-block">
<div class="oppia-response-header">
<i class="material-icons md-18" ng-if='!getCorrect() && isCorrectnessFeedbackEnabled()'>&#x2718;</i>
<i class="material-icons md-18" ng-if='getCorrect() && isCorrectnessFeedbackEnabled()'>&#10004;</i>
<span ng-if="!isActive()" ng-attr-title="<[getSummary()]>">
<[getShortSummary()]>
<span ng-if="getNumRules() > 1" class="label label-primary" style="position: relative; bottom: 4px;">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,15 @@ oppia.factory('explorationCorrectnessFeedbackService', [
return (typeof value === 'boolean');
};

child.isEnabled = function() {
return child.savedMemento;
};

child.toggleCorrectnessFeedback = function() {
child.displayed = !child.displayed;
child.saveDisplayedValue();
};

return child;
}
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ oppia.factory('ResponsesService', [
if (updates.dest) {
answerGroup.outcome.dest = updates.dest;
}
answerGroup.correct = false;
if (updates.hasOwnProperty('labelledAsCorrect')) {
answerGroup.labelledAsCorrect = updates.labelledAsCorrect;
}
_saveAnswerGroups(_answerGroups);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,13 @@ oppia.controller('StateResponses', [
});
};

$scope.saveActiveAnswerGroupCorrectnessLabel = function(
updatedCorrectnessLabel) {
ResponsesService.updateActiveAnswerGroup({
labelledAsCorrect: updatedCorrectnessLabel
});
};

$scope.saveDefaultOutcomeFeedback = function(updatedOutcome) {
ResponsesService.updateDefaultOutcome({
feedback: updatedOutcome.feedback
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
is-active="$index === activeAnswerGroupIndex"
on-delete-fn="deleteAnswerGroup"
outcome="answerGroup.outcome"
labelled-as-correct="answerGroup.labelledAsCorrect"
num-rules="answerGroup.rules.length">
</response-header>
</a>
Expand All @@ -41,8 +42,10 @@
on-save-answer-group-feedback="saveActiveAnswerGroupFeedback"
on-save-answer-group-dest="saveActiveAnswerGroupDest"
on-save-answer-group-rules="saveActiveAnswerGroupRules"
on-save-answer-group-correctness-label="saveActiveAnswerGroupCorrectnessLabel"
is-editable="editabilityService.isEditable()"
display-feedback="!isLinearWithNoFeedback(answerGroup.outcome)"
labelled-as-correct="answerGroup.labelledAsCorrect"
class="protractor-test-response-body">
</answer-group-editor>
</div>
Expand All @@ -66,6 +69,7 @@
is-active="$index === activeAnswerGroupIndex"
summary="defaultOutcome|summarizeDefaultOutcome:getCurrentInteractionId():answerGroups.length:false"
short-summary="defaultOutcome|summarizeDefaultOutcome:getCurrentInteractionId():answerGroups.length:true"
labelled-as-correct="false"
outcome="defaultOutcome">
</response-header>
</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@
<script src="{{TEMPLATE_DIR_PREFIX}}/components/CodemirrorMergeviewDirective.js"></script>
<script src="{{TEMPLATE_DIR_PREFIX}}/components/HintEditorDirective.js"></script>
<script src="{{TEMPLATE_DIR_PREFIX}}/components/ClassifierRulePanelDirective.js"></script>
<script src="{{TEMPLATE_DIR_PREFIX}}/components/AnswerGroupCorrectnessLabelEditorDirective.js"></script>
<script src="{{TEMPLATE_DIR_PREFIX}}/components/OutcomeEditorDirective.js"></script>
<script src="{{TEMPLATE_DIR_PREFIX}}/components/OutcomeDestinationEditorDirective.js"></script>
<script src="{{TEMPLATE_DIR_PREFIX}}/components/OutcomeFeedbackEditorDirective.js"></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ oppia.controller('SettingsTab', [
'EXPLORATION_TITLE_INPUT_FOCUS_LABEL', 'UserEmailPreferencesService',
'EditableExplorationBackendApiService', 'UrlInterpolationService',
'explorationAutomaticTextToSpeechService',
'explorationCorrectnessFeedbackService',
function(
$scope, $http, $window, $uibModal,
$rootScope, ExplorationDataService,
Expand All @@ -41,7 +42,8 @@ oppia.controller('SettingsTab', [
ExplorationAdvancedFeaturesService, ALL_CATEGORIES,
EXPLORATION_TITLE_INPUT_FOCUS_LABEL, UserEmailPreferencesService,
EditableExplorationBackendApiService, UrlInterpolationService,
explorationAutomaticTextToSpeechService) {
explorationAutomaticTextToSpeechService,
explorationCorrectnessFeedbackService) {
$scope.EXPLORATION_TITLE_INPUT_FOCUS_LABEL = (
EXPLORATION_TITLE_INPUT_FOCUS_LABEL);

Expand Down Expand Up @@ -181,6 +183,11 @@ oppia.controller('SettingsTab', [
$scope.toggleAutomaticTextToSpeech = (
explorationAutomaticTextToSpeechService.toggleAutomaticTextToSpeech);

$scope.isCorrectnessFeedbackEnabled = (
explorationCorrectnessFeedbackService.isEnabled);
$scope.toggleCorrectnessFeedback = (
explorationCorrectnessFeedbackService.toggleCorrectnessFeedback);

/********************************************
* Methods for rights management.
********************************************/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,28 @@ <h3>Advanced Features</h3>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12">
<div role="form" class="form-horizontal">
<label for="enableCorrectnessFeedback" class="col-lg-2 col-md-2 col-sm-2">
Correctness Feedback
</label>
<span class="col-lg-2 col-md-2 col-sm-2">
<button type="button" class="btn btn-default" ng-click="toggleCorrectnessFeedback()" style="margin-top: 16px">
<span ng-if="!isCorrectnessFeedbackEnabled()">
Enable
</span>
<span ng-if="isCorrectnessFeedbackEnabled()">
Disable
</span>
</button>
</span>
<span class="col-lg-8 col-md-8 col-sm-8 help-block" style="font-size: smaller;">
This allows the user to categorise answer groups as correct or incorrect.
</span>
</div>
</div>
</div>
</div>
</md-card>

Expand Down

0 comments on commit c1c6a90

Please sign in to comment.