Skip to content

Commit

Permalink
add new queston in sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
saeedjassani committed Jul 1, 2017
1 parent 81f3b91 commit b72a6b9
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 5 deletions.
Expand Up @@ -31,6 +31,10 @@ oppia.factory('QuestionListObjectFactory', [function() {
return this._questions.slice();
};

QuestionList.prototype.getQuestionAt = function(i) {
return this._questions[i];
};

QuestionList.prototype.addQuestion = function(question) {
this._questions.push(question);
};
Expand Down
Expand Up @@ -76,10 +76,14 @@ oppia.factory('ScrollSyncService', [
// Scroll to an element in the editor given its id.
scrollTo: function(id) {
var element = angular.element($document[0].getElementById(id));
console.log(element);
// console.log(JSON.stringify(element));
if (element && element.offset()) {
$('html, body').animate({
scrollTop: element.offset().top - Y_OFFSET_SMOOTH_SCROLL
}, 'slow');
} else {
console.log('No element to scroll');
}
}
};
Expand Down
Expand Up @@ -147,8 +147,10 @@ oppia.factory('SimpleEditorManagerService', [
lastStateName, OutcomeObjectFactory.createEmpty(lastStateName));

var stateData = SimpleEditorShimService.getState(lastStateName);
// console.log(JSON.stringify(data.questionList.getQuestionCount()));
data.questionList.addQuestion(QuestionObjectFactory.create(
lastStateName, stateData.interaction, ''));
// console.log(JSON.stringify(data.questionList.getQuestionCount()));
},
deleteQuestion: function(question) {
// - Change destination of answer groups that point to it.
Expand Down
Expand Up @@ -40,6 +40,25 @@ oppia.directive('simpleEditorSidebar', [
$scope.questionList = SimpleEditorManagerService.getQuestionList();
$scope.ID_PREFIX = QuestionIdService.SIDEBAR_PREFIX;
$scope.sidebarModeService = SimpleEditorSidebarModeService;
$scope.addNewQuestion = function() {
if (!SimpleEditorManagerService.canAddNewQuestion()) {
return;
}
$scope.sidebarModeService.setModeToReadonly();
SimpleEditorManagerService.addNewQuestion();
$scope.questionList = SimpleEditorManagerService.getQuestionList();
var end = $scope.questionList.getQuestionAt(
$scope.questionList.getQuestionCount() - 1);
// for (var i = 0; i < $scope.questionList.getQuestionCount(); i++) {
// console.log($scope.questionList.getQuestionAt(1));
// }
// console.log(JSON.stringify($scope.questionList.getLastQuestion()));
// console.log(JSON.stringify(
//SimpleEditorManagerService.getQuestionList().getLastQuestion()));
$scope.scrollToQuestion(end);
// ScrollSyncService.scrollTo(end.getId());
};

$scope.getSidebarItemId = function(question, subfieldLabel) {
return QuestionIdService.getSidebarItemId(
question.getId(), subfieldLabel
Expand Down
Expand Up @@ -36,12 +36,12 @@
</li>
</ul>
</li>
<li class="sidebar-item">
<div id="5" class="sidebar-item-header">
<i ng-click="" class="collapse-icon material-icons">
&#xE5C7;
<li ng-hide="sidebarModeService.isSidebarInReadonlyMode()" class="sidebar-item">
<div class="sidebar-item-header">
<i ng-click="addNewQuestion();" class="add-icon material-icons">
&#xe145;
</i>
<strong ng-click="scrollToQuestion(question)">Add a question</strong>
<strong>Add new question</strong>
</div>
</li>
</ul>
Expand Down

0 comments on commit b72a6b9

Please sign in to comment.