From b72a6b9636191e9bd8fabad2b0a5545a10a41342 Mon Sep 17 00:00:00 2001 From: Saeed Jassani Date: Sat, 1 Jul 2017 17:46:19 +0530 Subject: [PATCH] add new queston in sidebar --- .../exploration/QuestionListObjectFactory.js | 4 ++++ .../simple_editor_tab/ScrollSyncService.js | 4 ++++ .../SimpleEditorManagerService.js | 2 ++ .../SimpleEditorSidebarDirective.js | 19 +++++++++++++++++++ .../simple_editor_sidebar_directive.html | 10 +++++----- 5 files changed, 34 insertions(+), 5 deletions(-) diff --git a/core/templates/dev/head/domain/exploration/QuestionListObjectFactory.js b/core/templates/dev/head/domain/exploration/QuestionListObjectFactory.js index 5153dbed8e18..c9bfe5d600d7 100644 --- a/core/templates/dev/head/domain/exploration/QuestionListObjectFactory.js +++ b/core/templates/dev/head/domain/exploration/QuestionListObjectFactory.js @@ -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); }; diff --git a/core/templates/dev/head/pages/exploration_editor/simple_editor_tab/ScrollSyncService.js b/core/templates/dev/head/pages/exploration_editor/simple_editor_tab/ScrollSyncService.js index 3096aff5dbb1..d9c770df7be4 100644 --- a/core/templates/dev/head/pages/exploration_editor/simple_editor_tab/ScrollSyncService.js +++ b/core/templates/dev/head/pages/exploration_editor/simple_editor_tab/ScrollSyncService.js @@ -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'); } } }; diff --git a/core/templates/dev/head/pages/exploration_editor/simple_editor_tab/SimpleEditorManagerService.js b/core/templates/dev/head/pages/exploration_editor/simple_editor_tab/SimpleEditorManagerService.js index cbf8233a5b51..fe5c328093b3 100644 --- a/core/templates/dev/head/pages/exploration_editor/simple_editor_tab/SimpleEditorManagerService.js +++ b/core/templates/dev/head/pages/exploration_editor/simple_editor_tab/SimpleEditorManagerService.js @@ -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. diff --git a/core/templates/dev/head/pages/exploration_editor/simple_editor_tab/SimpleEditorSidebarDirective.js b/core/templates/dev/head/pages/exploration_editor/simple_editor_tab/SimpleEditorSidebarDirective.js index dc73b2771249..5a6a95c8dc7f 100644 --- a/core/templates/dev/head/pages/exploration_editor/simple_editor_tab/SimpleEditorSidebarDirective.js +++ b/core/templates/dev/head/pages/exploration_editor/simple_editor_tab/SimpleEditorSidebarDirective.js @@ -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 diff --git a/core/templates/dev/head/pages/exploration_editor/simple_editor_tab/simple_editor_sidebar_directive.html b/core/templates/dev/head/pages/exploration_editor/simple_editor_tab/simple_editor_sidebar_directive.html index 3ab9682357de..8e627eb524c5 100644 --- a/core/templates/dev/head/pages/exploration_editor/simple_editor_tab/simple_editor_sidebar_directive.html +++ b/core/templates/dev/head/pages/exploration_editor/simple_editor_tab/simple_editor_sidebar_directive.html @@ -36,12 +36,12 @@ -