-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement editing of questions #5614
Changes from 1 commit
d9f2824
f0cb957
9c8e702
c93f186
f695dd6
066faec
07a11fb
2386f69
4360648
a68adef
dd9d25f
8a2c2bd
4782099
a20b0ab
4668f51
fd91189
2f4f1cc
3050886
6d52d8c
43807b1
7a4ff6f
41798c6
c496793
fbdaa83
732be38
7756f6d
17ca89f
5785784
13254ea
fc4981d
9ef2940
5861a5a
4ccea9c
0c589eb
c0ad966
9896d99
4d3c329
d37ab38
f6f7e09
5722ca1
3b5983f
c4c9b93
98227d0
5abc2c8
387a9cb
7a10a7b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,22 +24,24 @@ oppia.constant('CMD_UPDATE_QUESTION_PROPERTY', 'update_question_property'); | |
oppia.factory('QuestionUpdateService', [ | ||
'QuestionObjectFactory', | ||
'ChangeObjectFactory', | ||
'UndoRedoService', | ||
'QuestionUndoRedoService', | ||
'QUESTION_PROPERTY_LANGUAGE_CODE', | ||
'QUESTION_PROPERTY_QUESTION_STATE_DATA', | ||
'CMD_UPDATE_QUESTION_PROPERTY', | ||
function( | ||
QuestionObjectFactory, | ||
ChangeObjectFactory, | ||
UndoRedoService, | ||
QuestionUndoRedoService, | ||
QUESTION_PROPERTY_LANGUAGE_CODE, | ||
QUESTION_PROPERTY_QUESTION_STATE_DATA, | ||
CMD_UPDATE_QUESTION_PROPERTY) { | ||
var _changeCount = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see this being incremented in this file, only reset seems to be there. Isn't this available from QuestionUndoRedoService? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah my bad, I forgot to remove those |
||
|
||
var _applyChange = function(question, command, params, apply, reverse) { | ||
var changeDict = angular.copy(params); | ||
changeDict.cmd = command; | ||
var changeObj = ChangeObjectFactory.create(changeDict, apply, reverse); | ||
UndoRedoService.applyChange(changeObj, question); | ||
QuestionUndoRedoService.applyChange(changeObj, question); | ||
}; | ||
|
||
var _applyPropertyChange = function( | ||
|
@@ -81,6 +83,12 @@ oppia.factory('QuestionUpdateService', [ | |
}, function(changeDict, question) { | ||
question.setStateData(oldStateData); | ||
}); | ||
}, | ||
getChangeCount: function() { | ||
return this._changeCount; | ||
}, | ||
resetChangeCount: function() { | ||
_changeCount = 0; | ||
} | ||
}; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,12 +100,56 @@ oppia.directive('stateInteractionEditor', [ | |
interactionCustomizationArgs, false); | ||
}; | ||
|
||
console.log("set listener stateEditorInitialized"); | ||
var _updateInteractionPreviewAndAnswerChoices = function() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you reuse the logic in StateEditorService.getAnswerChoices()? Better than duplicating. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
$scope.interactionId = StateInteractionIdService.savedMemento; | ||
|
||
var currentCustomizationArgs = | ||
StateCustomizationArgsService.savedMemento; | ||
$scope.interactionPreviewHtml = _getInteractionPreviewTag( | ||
currentCustomizationArgs); | ||
|
||
// Special cases for multiple choice input and image click input. | ||
if ($scope.interactionId === 'MultipleChoiceInput') { | ||
$rootScope.$broadcast( | ||
'updateAnswerChoices', | ||
currentCustomizationArgs.choices.value.map(function(val, ind) { | ||
return { | ||
val: ind, | ||
label: val | ||
}; | ||
}) | ||
); | ||
} else if ($scope.interactionId === 'ImageClickInput') { | ||
var _answerChoices = []; | ||
var imageWithRegions = | ||
currentCustomizationArgs.imageAndRegions.value; | ||
for (var j = 0; j < imageWithRegions.labeledRegions.length; j++) { | ||
_answerChoices.push({ | ||
val: imageWithRegions.labeledRegions[j].label, | ||
label: imageWithRegions.labeledRegions[j].label | ||
}); | ||
} | ||
|
||
$rootScope.$broadcast('updateAnswerChoices', _answerChoices); | ||
} else if ($scope.interactionId === 'ItemSelectionInput' || | ||
$scope.interactionId === 'DragAndDropSortInput') { | ||
$rootScope.$broadcast( | ||
'updateAnswerChoices', | ||
currentCustomizationArgs.choices.value.map(function(val) { | ||
return { | ||
val: val, | ||
label: val | ||
}; | ||
}) | ||
); | ||
} else { | ||
$rootScope.$broadcast('updateAnswerChoices', null); | ||
} | ||
}; | ||
|
||
$scope.$on('stateEditorInitialized', function(evt, stateData) { | ||
console.log("receive stateEditorInitialized"); | ||
$scope.hasLoaded = false; | ||
InteractionDetailsCacheService.reset(); | ||
console.log("broadcast initializeAnswerGroups"); | ||
$rootScope.$broadcast('initializeAnswerGroups', { | ||
interactionId: stateData.interaction.id, | ||
answerGroups: stateData.interaction.answerGroups, | ||
|
@@ -415,53 +459,6 @@ oppia.directive('stateInteractionEditor', [ | |
_updateInteractionPreviewAndAnswerChoices(); | ||
}); | ||
}; | ||
|
||
var _updateInteractionPreviewAndAnswerChoices = function() { | ||
$scope.interactionId = StateInteractionIdService.savedMemento; | ||
|
||
var currentCustomizationArgs = | ||
StateCustomizationArgsService.savedMemento; | ||
$scope.interactionPreviewHtml = _getInteractionPreviewTag( | ||
currentCustomizationArgs); | ||
|
||
// Special cases for multiple choice input and image click input. | ||
if ($scope.interactionId === 'MultipleChoiceInput') { | ||
$rootScope.$broadcast( | ||
'updateAnswerChoices', | ||
currentCustomizationArgs.choices.value.map(function(val, ind) { | ||
return { | ||
val: ind, | ||
label: val | ||
}; | ||
}) | ||
); | ||
} else if ($scope.interactionId === 'ImageClickInput') { | ||
var _answerChoices = []; | ||
var imageWithRegions = | ||
currentCustomizationArgs.imageAndRegions.value; | ||
for (var j = 0; j < imageWithRegions.labeledRegions.length; j++) { | ||
_answerChoices.push({ | ||
val: imageWithRegions.labeledRegions[j].label, | ||
label: imageWithRegions.labeledRegions[j].label | ||
}); | ||
} | ||
|
||
$rootScope.$broadcast('updateAnswerChoices', _answerChoices); | ||
} else if ($scope.interactionId === 'ItemSelectionInput' || | ||
$scope.interactionId === 'DragAndDropSortInput') { | ||
$rootScope.$broadcast( | ||
'updateAnswerChoices', | ||
currentCustomizationArgs.choices.value.map(function(val) { | ||
return { | ||
val: val, | ||
label: val | ||
}; | ||
}) | ||
); | ||
} else { | ||
$rootScope.$broadcast('updateAnswerChoices', null); | ||
} | ||
}; | ||
} | ||
] | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,15 +30,17 @@ oppia.directive('questionsTab', [ | |
'MisconceptionObjectFactory', 'QuestionObjectFactory', | ||
'QuestionSuggestionObjectFactory', 'SuggestionThreadObjectFactory', | ||
'EVENT_QUESTION_SUMMARIES_INITIALIZED', | ||
'UndoRedoService', 'UrlService', function( | ||
'QuestionUndoRedoService', 'UrlService', | ||
'UndoRedoService', function( | ||
$scope, $http, $q, $uibModal, $window, AlertsService, | ||
TopicEditorStateService, QuestionCreationService, | ||
EditableQuestionBackendApiService, EditableSkillBackendApiService, | ||
MisconceptionObjectFactory, QuestionObjectFactory, | ||
QuestionSuggestionObjectFactory, SuggestionThreadObjectFactory, | ||
EVENT_QUESTION_SUMMARIES_INITIALIZED, | ||
UndoRedoService, UrlService) { | ||
$scope.UndoRedoService = UndoRedoService; | ||
QuestionUndoRedoService, UrlService, | ||
UndoRedoService) { | ||
$scope.QuestionUndoRedoService = QuestionUndoRedoService; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this used in the HTML file? If not, no need to have it in $scope. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is used in the html file now There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, but even then it only uses that single function. So, just surface that function to scope instead of the whole service. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
var _initTab = function() { | ||
$scope.questionEditorIsShown = false; | ||
$scope.question = null; | ||
|
@@ -77,13 +79,13 @@ oppia.directive('questionsTab', [ | |
$scope.questionIsBeingSaved = false; | ||
}); | ||
} else { | ||
if (UndoRedoService.hasChanges()) { | ||
console.log(UndoRedoService.getCommittableChangeList()); | ||
if (QuestionUndoRedoService.hasChanges()) { | ||
$scope.questionIsBeingSaved = true; | ||
// TODO(tjiang11): Allow user to specify a commit message. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this tracked anywhere (in an issue perhaps)? Presumably need to ensure this is done prior to the feature being launched. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Filed as #5690 (planning to do this next while submitting my PR for adding the questions tab to the skill editor) |
||
EditableQuestionBackendApiService.updateQuestion( | ||
$scope.questionId, $scope.question.getVersion(), 'test', | ||
UndoRedoService.getCommittableChangeList()).then(function() { | ||
UndoRedoService.clearChanges(); | ||
$scope.questionId, $scope.question.getVersion(), 'blank', | ||
QuestionUndoRedoService.getCommittableChangeList()).then(function() { | ||
QuestionUndoRedoService.clearChanges(); | ||
$scope.questionIsBeingSaved = false; | ||
}, function(error) { | ||
AlertsService.addWarning( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think 2 or 3 dependencies can be declared in a line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done