Skip to content
This repository has been archived by the owner on Jun 12, 2018. It is now read-only.

Commit

Permalink
Fix part of oppia#3826: Change and rename graphDataService in pages/e…
Browse files Browse the repository at this point in the history
…xploration_editor/EditorServices.js (oppia#4490)
  • Loading branch information
EvsChen authored and DubeySandeep committed Jan 13, 2018
1 parent 5ed7fa6 commit df5b03e
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 64 deletions.
39 changes: 0 additions & 39 deletions core/templates/dev/head/pages/exploration_editor/EditorServices.js
Original file line number Diff line number Diff line change
Expand Up @@ -795,45 +795,6 @@ oppia.factory('stateSolutionService', [
}
]);

// Service for computing graph data.
oppia.factory('graphDataService', [
'explorationStatesService', 'explorationInitStateNameService',
'ComputeGraphService',
function(
explorationStatesService, explorationInitStateNameService,
ComputeGraphService) {
var _graphData = null;

// Returns an object which can be treated as the input to a visualization
// for a directed graph. The returned object has the following keys:
// - nodes: an object whose keys are node ids (equal to node names) and
// whose values are node names
// - links: a list of objects. Each object represents a directed link
// between two nodes, and has keys 'source' and 'target', the values
// of which are the names of the corresponding nodes.
// - initStateName: the name of the initial state.
// - finalStateName: the name of the final state.
var _recomputeGraphData = function() {
if (!explorationInitStateNameService.savedMemento) {
return;
}

var states = explorationStatesService.getStates();
var initStateId = explorationInitStateNameService.savedMemento;
_graphData = ComputeGraphService.compute(initStateId, states);
};

return {
recompute: function() {
_recomputeGraphData();
},
getGraphData: function() {
return angular.copy(_graphData);
}
};
}
]);

oppia.constant('WARNING_TYPES', {
// These must be fixed before the exploration can be saved.
CRITICAL: 'critical',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ oppia.controller('ExplorationEditor', [
'explorationLanguageCodeService', 'ExplorationRightsService',
'explorationInitStateNameService', 'explorationTagsService',
'EditabilityService', 'explorationStatesService', 'RouterService',
'graphDataService', 'StateEditorTutorialFirstTimeService',
'GraphDataService', 'StateEditorTutorialFirstTimeService',
'explorationParamSpecsService', 'explorationParamChangesService',
'ExplorationWarningsService', '$templateCache', 'ExplorationContextService',
'ExplorationAdvancedFeaturesService', '$uibModal', 'ChangeListService',
Expand All @@ -56,7 +56,7 @@ oppia.controller('ExplorationEditor', [
explorationLanguageCodeService, ExplorationRightsService,
explorationInitStateNameService, explorationTagsService,
EditabilityService, explorationStatesService, RouterService,
graphDataService, StateEditorTutorialFirstTimeService,
GraphDataService, StateEditorTutorialFirstTimeService,
explorationParamSpecsService, explorationParamChangesService,
ExplorationWarningsService, $templateCache, ExplorationContextService,
ExplorationAdvancedFeaturesService, $uibModal, ChangeListService,
Expand Down Expand Up @@ -91,7 +91,7 @@ oppia.controller('ExplorationEditor', [
};

$scope.$on('refreshGraph', function() {
graphDataService.recompute();
GraphDataService.recompute();
ExplorationWarningsService.updateWarnings();
});

Expand Down Expand Up @@ -151,7 +151,7 @@ oppia.controller('ExplorationEditor', [
EditabilityService.markEditable();
}

graphDataService.recompute();
GraphDataService.recompute();

if (!EditorStateService.getActiveStateName() ||
!explorationStatesService.getState(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
*/

oppia.factory('ExplorationWarningsService', [
'$injector', 'graphDataService', 'explorationStatesService',
'$injector', 'GraphDataService', 'explorationStatesService',
'ExpressionInterpolationService', 'explorationParamChangesService',
'ParameterMetadataService', 'INTERACTION_SPECS',
'WARNING_TYPES', 'STATE_ERROR_MESSAGES', 'RULE_TYPE_CLASSIFIER',
function(
$injector, graphDataService, explorationStatesService,
$injector, GraphDataService, explorationStatesService,
ExpressionInterpolationService, explorationParamChangesService,
ParameterMetadataService, INTERACTION_SPECS,
WARNING_TYPES, STATE_ERROR_MESSAGES, RULE_TYPE_CLASSIFIER) {
Expand Down Expand Up @@ -179,8 +179,8 @@ oppia.factory('ExplorationWarningsService', [
stateWarnings = {};
hasCriticalStateWarning = false;

graphDataService.recompute();
var _graphData = graphDataService.getGraphData();
GraphDataService.recompute();
var _graphData = GraphDataService.getGraphData();

var _states = explorationStatesService.getStates();
_states.getStateNames().forEach(function(stateName) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright 2018 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 Service for computing graph data.
*/

oppia.factory('GraphDataService', [
'explorationStatesService', 'explorationInitStateNameService',
'ComputeGraphService',
function(
explorationStatesService, explorationInitStateNameService,
ComputeGraphService) {
var _graphData = null;

// Returns an object which can be treated as the input to a visualization
// for a directed graph. The returned object has the following keys:
// - nodes: an object whose keys are node ids (equal to node names) and
// whose values are node names
// - links: a list of objects. Each object represents a directed link
// between two nodes, and has keys 'source' and 'target', the values
// of which are the names of the corresponding nodes.
// - initStateName: the name of the initial state.
// - finalStateName: the name of the final state.
var _recomputeGraphData = function() {
if (!explorationInitStateNameService.savedMemento) {
return;
}

var states = explorationStatesService.getStates();
var initStateId = explorationInitStateNameService.savedMemento;
_graphData = ComputeGraphService.compute(initStateId, states);
};

return {
recompute: function() {
_recomputeGraphData();
},
getGraphData: function() {
return angular.copy(_graphData);
}
};
}
]);
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@

oppia.factory('ParameterMetadataService', [
'explorationStatesService', 'ExpressionInterpolationService',
'explorationParamChangesService', 'graphDataService',
'explorationParamChangesService', 'GraphDataService',
function(
explorationStatesService, ExpressionInterpolationService,
explorationParamChangesService, graphDataService) {
explorationParamChangesService, GraphDataService) {
var PARAM_ACTION_GET = 'get';
var PARAM_ACTION_SET = 'set';

Expand Down Expand Up @@ -148,7 +148,7 @@ oppia.factory('ParameterMetadataService', [
// (e.g. one parameter may be set based on the value assigned to
// another parameter).
getUnsetParametersInfo: function(initNodeIds) {
var graphData = graphDataService.getGraphData();
var graphData = GraphDataService.getGraphData();

var states = explorationStatesService.getStates();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
oppia.controller('ExplorationGraph', [
'$scope', '$uibModal', 'EditorStateService', 'AlertsService',
'explorationStatesService', 'EditabilityService', 'RouterService',
'graphDataService', 'UrlInterpolationService',
'GraphDataService', 'UrlInterpolationService',
function(
$scope, $uibModal, EditorStateService, AlertsService,
explorationStatesService, EditabilityService, RouterService,
graphDataService, UrlInterpolationService) {
$scope.getGraphData = graphDataService.getGraphData;
GraphDataService, UrlInterpolationService) {
$scope.getGraphData = GraphDataService.getGraphData;
$scope.isEditable = EditabilityService.isEditable;

// We hide the graph at the outset in order not to confuse new exploration
Expand Down Expand Up @@ -62,11 +62,11 @@ oppia.controller('ExplorationGraph', [
windowClass: 'oppia-large-modal-window',
controller: [
'$scope', '$uibModalInstance', 'EditorStateService',
'graphDataService', 'isEditable',
'GraphDataService', 'isEditable',
function($scope, $uibModalInstance, EditorStateService,
graphDataService, isEditable) {
GraphDataService, isEditable) {
$scope.currentStateName = EditorStateService.getActiveStateName();
$scope.graphData = graphDataService.getGraphData();
$scope.graphData = GraphDataService.getGraphData();
$scope.isEditable = isEditable;

$scope.deleteState = function(stateName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
oppia.factory('ResponsesService', [
'$rootScope', 'stateInteractionIdService', 'INTERACTION_SPECS',
'AnswerGroupsCacheService', 'EditorStateService', 'ChangeListService',
'explorationStatesService', 'graphDataService', 'OutcomeObjectFactory',
'explorationStatesService', 'GraphDataService', 'OutcomeObjectFactory',
'stateSolutionService', 'SolutionVerificationService', 'AlertsService',
'ExplorationContextService', 'ExplorationWarningsService',
'INFO_MESSAGE_SOLUTION_IS_VALID', 'INFO_MESSAGE_SOLUTION_IS_INVALID',
'INFO_MESSAGE_SOLUTION_IS_INVALID_FOR_CURRENT_RULE',
function(
$rootScope, stateInteractionIdService, INTERACTION_SPECS,
AnswerGroupsCacheService, EditorStateService, ChangeListService,
explorationStatesService, graphDataService, OutcomeObjectFactory,
explorationStatesService, GraphDataService, OutcomeObjectFactory,
stateSolutionService, SolutionVerificationService, AlertsService,
ExplorationContextService, ExplorationWarningsService,
INFO_MESSAGE_SOLUTION_IS_VALID, INFO_MESSAGE_SOLUTION_IS_INVALID,
Expand Down Expand Up @@ -91,7 +91,7 @@ oppia.factory('ResponsesService', [
}
}

graphDataService.recompute();
GraphDataService.recompute();
_answerGroupsMemento = angular.copy(newAnswerGroups);
}
};
Expand Down Expand Up @@ -126,7 +126,7 @@ oppia.factory('ResponsesService', [
EditorStateService.getActiveStateName(),
angular.copy(newDefaultOutcome));

graphDataService.recompute();
GraphDataService.recompute();
_defaultOutcomeMemento = angular.copy(newDefaultOutcome);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ oppia.controller('StateInteraction', [
'AlertsService', 'EditorStateService', 'HtmlEscaperService',
'INTERACTION_SPECS', 'stateInteractionIdService',
'stateCustomizationArgsService', 'EditabilityService',
'explorationStatesService', 'graphDataService',
'explorationStatesService', 'GraphDataService',
'InteractionDetailsCacheService',
'ExplorationHtmlFormatterService', 'UrlInterpolationService',
'SubtitledHtmlObjectFactory', 'stateSolutionService', 'stateContentService',
function($scope, $http, $rootScope, $uibModal, $injector, $filter,
AlertsService, EditorStateService, HtmlEscaperService,
INTERACTION_SPECS, stateInteractionIdService,
stateCustomizationArgsService, EditabilityService,
explorationStatesService, graphDataService,
explorationStatesService, GraphDataService,
InteractionDetailsCacheService,
ExplorationHtmlFormatterService, UrlInterpolationService,
SubtitledHtmlObjectFactory, stateSolutionService, stateContentService) {
Expand Down Expand Up @@ -144,7 +144,7 @@ oppia.controller('StateInteraction', [
'onInteractionIdChanged', stateInteractionIdService.savedMemento);
}

graphDataService.recompute();
GraphDataService.recompute();
_updateInteractionPreviewAndAnswerChoices();
};

Expand Down Expand Up @@ -354,7 +354,7 @@ oppia.controller('StateInteraction', [
stateSolutionService.saveDisplayedValue();
$rootScope.$broadcast(
'onInteractionIdChanged', stateInteractionIdService.savedMemento);
graphDataService.recompute();
GraphDataService.recompute();
_updateInteractionPreviewAndAnswerChoices();
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@
<script src="{{TEMPLATE_DIR_PREFIX}}/pages/exploration_editor/AutosaveInfoModalsService.js"></script>
<script src="{{TEMPLATE_DIR_PREFIX}}/pages/exploration_editor/EditorStateService.js"></script>
<script src="{{TEMPLATE_DIR_PREFIX}}/pages/exploration_editor/EditorFirstTimeEventsService.js"></script>
<script src="{{TEMPLATE_DIR_PREFIX}}/pages/exploration_editor/GraphDataService.js"></script>
<script src="{{TEMPLATE_DIR_PREFIX}}/pages/exploration_editor/AngularNameService.js"></script>
<script src="{{TEMPLATE_DIR_PREFIX}}/pages/exploration_editor/UserEmailPreferencesService.js"></script>
<script src="{{TEMPLATE_DIR_PREFIX}}/pages/exploration_editor/ExplorationDiffService.js"></script>
Expand Down

0 comments on commit df5b03e

Please sign in to comment.