Skip to content

Commit

Permalink
Clean up work on constants. (oppia#6919)
Browse files Browse the repository at this point in the history
* Applied stash

* Moved single use constants to page.constants

* Fix e2e by requiring the necessary constants file

* Moved single use constants to services/ where they belong

* Added presubmit check

* Added presubmit check to ensure singular declaration of constants

* Fix lint

* Removed individual declaration of INTERACTION_SPECS

* Test

* Address Review

* Fix tests

* Address review
  • Loading branch information
YashJipkate authored and seanlip committed Jun 17, 2019
1 parent d188598 commit 4e665fa
Show file tree
Hide file tree
Showing 56 changed files with 484 additions and 321 deletions.
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@
/core/jobs*.py @seanlip
/core/platform/ @seanlip
/core/templates/dev/head/App*.ts @ankita240796
/core/templates/dev/head/app.constants.ts @ankita240796
/core/templates/dev/head/pages/interaction-specs.constants.ts @vojtechjelinek
/core/templates/dev/head/I18nFooter.ts @seanlip
/core/templates/dev/head/services/TranslationFileHashLoaderService.ts @seanlip

Expand Down
99 changes: 5 additions & 94 deletions core/templates/dev/head/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
* @fileoverview Initialization and basic configuration for the Oppia module.
*/

require('I18nFooter.ts');
require('directives/FocusOnDirective.ts');

require('pages/Base.ts');
Expand Down Expand Up @@ -63,97 +62,11 @@ require('domain/sidebar/SidebarStatusService.ts');
require('domain/user/UserInfoObjectFactory.ts');
require('domain/utilities/UrlInterpolationService.ts');

oppia.constant(
'EXPLORATION_SUMMARY_DATA_URL_TEMPLATE', '/explorationsummarieshandler/data');

oppia.constant('EXPLORATION_AND_SKILL_ID_PATTERN', /^[a-zA-Z0-9_-]+$/);

// We use a slash because this character is forbidden in a state name.
oppia.constant('PLACEHOLDER_OUTCOME_DEST', '/');
oppia.constant('INTERACTION_DISPLAY_MODE_INLINE', 'inline');
oppia.constant('LOADING_INDICATOR_URL', '/activity/loadingIndicator.gif');
oppia.constant('OBJECT_EDITOR_URL_PREFIX', '/object_editor_template/');
// Feature still in development.
// NOTE TO DEVELOPERS: This should be synchronized with the value in feconf.
oppia.constant('ENABLE_ML_CLASSIFIERS', false);
// Feature still in development.
oppia.constant('INFO_MESSAGE_SOLUTION_IS_INVALID_FOR_EXPLORATION',
'The current solution does not lead to another card.');
oppia.constant('INFO_MESSAGE_SOLUTION_IS_INVALID_FOR_QUESTION',
'The current solution does not correspond to a correct answer.');
oppia.constant('INFO_MESSAGE_SOLUTION_IS_VALID',
'The solution is now valid!');
oppia.constant('INFO_MESSAGE_SOLUTION_IS_INVALID_FOR_CURRENT_RULE',
'The current solution is no longer valid.');
oppia.constant('PARAMETER_TYPES', {
REAL: 'Real',
UNICODE_STRING: 'UnicodeString'
});
oppia.constant('ACTION_ACCEPT_SUGGESTION', 'accept');
oppia.constant('ACTION_REJECT_SUGGESTION', 'reject');

// The maximum number of nodes to show in a row of the state graph.
oppia.constant('MAX_NODES_PER_ROW', 4);
// The following variable must be at least 3. It represents the maximum length,
// in characters, for the name of each node label in the state graph.
oppia.constant('MAX_NODE_LABEL_LENGTH', 15);

// If an $http request fails with the following error codes, a warning is
// displayed.
oppia.constant('FATAL_ERROR_CODES', [400, 401, 404, 500]);

// Do not modify these, for backwards-compatibility reasons.
oppia.constant('COMPONENT_NAME_CONTENT', 'content');
oppia.constant('COMPONENT_NAME_HINT', 'hint');
oppia.constant('COMPONENT_NAME_SOLUTION', 'solution');
oppia.constant('COMPONENT_NAME_FEEDBACK', 'feedback');
oppia.constant('COMPONENT_NAME_DEFAULT_OUTCOME', 'default_outcome');
oppia.constant('COMPONENT_NAME_EXPLANATION', 'explanation');
oppia.constant('COMPONENT_NAME_WORKED_EXAMPLE', 'worked_example');

// Enables recording playthroughs from learner sessions.
oppia.constant('CURRENT_ACTION_SCHEMA_VERSION', 1);
oppia.constant('CURRENT_ISSUE_SCHEMA_VERSION', 1);
oppia.constant('EARLY_QUIT_THRESHOLD_IN_SECS', 45);
oppia.constant('NUM_INCORRECT_ANSWERS_THRESHOLD', 3);
oppia.constant('NUM_REPEATED_CYCLES_THRESHOLD', 3);
oppia.constant('MAX_PLAYTHROUGHS_FOR_ISSUE', 5);

oppia.constant('ACTION_TYPE_EXPLORATION_START', 'ExplorationStart');
oppia.constant('ACTION_TYPE_ANSWER_SUBMIT', 'AnswerSubmit');
oppia.constant('ACTION_TYPE_EXPLORATION_QUIT', 'ExplorationQuit');

oppia.constant('ISSUE_TYPE_EARLY_QUIT', 'EarlyQuit');
oppia.constant(
'ISSUE_TYPE_MULTIPLE_INCORRECT_SUBMISSIONS', 'MultipleIncorrectSubmissions');
oppia.constant('ISSUE_TYPE_CYCLIC_STATE_TRANSITIONS', 'CyclicStateTransitions');
oppia.constant('SITE_NAME', 'Oppia.org');

oppia.constant('DEFAULT_PROFILE_IMAGE_PATH', '/avatar/user_blue_72px.png');
oppia.constant('FEEDBACK_POPOVER_PATH',
'/pages/exploration-player-page/templates/' +
'feedback-popup-container.template.html');

oppia.constant('LOGOUT_URL', '/logout');

// Whether to enable the promo bar functionality. This does not actually turn on
// the promo bar, as that is gated by a config value (see config_domain). This
// merely avoids checking for whether the promo bar is enabled for every Oppia
// page visited.
oppia.constant('ENABLE_PROMO_BAR', true);

// TODO(vojtechjelinek): Move these to separate file later, after we establish
// process to follow for Angular constants (#6731).
oppia.constant(
'TOPIC_MANAGER_RIGHTS_URL_TEMPLATE',
'/rightshandler/assign_topic_manager/<topic_id>/<assignee_id>');
oppia.constant(
'TOPIC_RIGHTS_URL_TEMPLATE', '/rightshandler/get_topic_rights/<topic_id>');
oppia.constant(
'SUBTOPIC_PAGE_EDITOR_DATA_URL_TEMPLATE',
'/subtopic_page_editor_handler/data/<topic_id>/<subtopic_id>');
oppia.constant(
'EDITABLE_TOPIC_DATA_URL_TEMPLATE', '/topic_editor_handler/data/<topic_id>');
require('app.constants.ts');

// The following file uses constants in app.constants.ts and hence needs to be
// loaded after app.constants.ts
require('I18nFooter.ts');

oppia.config([
'$compileProvider', '$cookiesProvider', '$httpProvider',
Expand Down Expand Up @@ -313,8 +226,6 @@ oppia.factory('$exceptionHandler', ['$log', function($log) {
};
}]);

oppia.constant('LABEL_FOR_CLEARING_FOCUS', 'labelForClearingFocus');

// Add a String.prototype.trim() polyfill for IE8.
if (typeof String.prototype.trim !== 'function') {
String.prototype.trim = function() {
Expand Down
4 changes: 0 additions & 4 deletions core/templates/dev/head/AppInit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,3 @@ var oppia = angular.module(
'toastr', 'ui.bootstrap', 'ui.sortable', 'ui.tree', 'ui.validate'
].concat(
window.GLOBALS ? (window.GLOBALS.ADDITIONAL_ANGULAR_MODULES || []) : []));

for (var constantName in constants) {
oppia.constant(constantName, constants[constantName]);
}
19 changes: 0 additions & 19 deletions core/templates/dev/head/I18nFooter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,6 @@
* @author milagro.teruel@gmail.com (Milagro Teruel)
*/

// Translations of strings that are loaded in the front page. They are listed
// here to be loaded synchronously with the script to prevent a FOUC or
// Flash of Untranslated Content.
// See http://angular-translate.github.io/docs/#/guide/12_asynchronous-loading
oppia.constant('DEFAULT_TRANSLATIONS', {
I18N_LIBRARY_PAGE_TITLE: 'Library',
I18N_LIBRARY_LOADING: 'Loading',
I18N_SIGNUP_PAGE_SUBTITLE: 'Registration',
I18N_SIGNUP_PAGE_TITLE: 'Oppia',
I18N_LIBRARY_SEARCH_PLACEHOLDER: 'What are you curious about?',
I18N_LIBRARY_ALL_LANGUAGES: 'All Languages',
I18N_LIBRARY_LANGUAGES_EN: 'English',
I18N_LIBRARY_ALL_CATEGORIES: 'All Categories',
I18N_TOPNAV_SIGN_IN: 'Sign in',
I18N_SPLASH_PAGE_TITLE: 'Oppia: Teach, Learn, Explore',
I18N_SIGNUP_REGISTRATION: 'Registration',
I18N_SIGNUP_LOADING: 'Loading'
});

oppia.controller('I18nFooter', [
'$cookies', '$http', '$rootScope', '$scope', '$timeout', '$translate',
'UserService',
Expand Down
162 changes: 162 additions & 0 deletions core/templates/dev/head/app.constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
// Copyright 2019 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 Shared constants for the Oppia module.
*/

for (var constantName in constants) {
oppia.constant(constantName, constants[constantName]);
}

// Translations of strings that are loaded in the front page. They are listed
// here to be loaded synchronously with the script to prevent a FOUC or
// Flash of Untranslated Content.
// See http://angular-translate.github.io/docs/#/guide/12_asynchronous-loading
oppia.constant('DEFAULT_TRANSLATIONS', {
I18N_LIBRARY_PAGE_TITLE: 'Library',
I18N_LIBRARY_LOADING: 'Loading',
I18N_SIGNUP_PAGE_SUBTITLE: 'Registration',
I18N_SIGNUP_PAGE_TITLE: 'Oppia',
I18N_LIBRARY_SEARCH_PLACEHOLDER: 'What are you curious about?',
I18N_LIBRARY_ALL_LANGUAGES: 'All Languages',
I18N_LIBRARY_LANGUAGES_EN: 'English',
I18N_LIBRARY_ALL_CATEGORIES: 'All Categories',
I18N_TOPNAV_SIGN_IN: 'Sign in',
I18N_SPLASH_PAGE_TITLE: 'Oppia: Teach, Learn, Explore',
I18N_SIGNUP_REGISTRATION: 'Registration',
I18N_SIGNUP_LOADING: 'Loading'
});

oppia.constant('RULE_SUMMARY_WRAP_CHARACTER_COUNT', 30);

oppia.constant(
'FEEDBACK_SUBJECT_MAX_CHAR_LIMIT',
constants.FEEDBACK_SUBJECT_MAX_CHAR_LIMIT);

/* Called always when learner moves to a new card.
Also called when card is selected by clicking on progress dots */
oppia.constant('EVENT_ACTIVE_CARD_CHANGED', 'activeCardChanged');
/* Called when the learner moves to a new card that they haven't seen before. */
oppia.constant('EVENT_NEW_CARD_OPENED', 'newCardOpened');
oppia.constant(
'EDITABLE_EXPLORATION_DATA_DRAFT_URL_TEMPLATE',
'/createhandler/data/<exploration_id>?apply_draft=<apply_draft>');
oppia.constant(
'EDITABLE_EXPLORATION_DATA_URL_TEMPLATE',
'/createhandler/data/<exploration_id>');
oppia.constant(
'EXPLORATION_DATA_URL_TEMPLATE',
'/explorehandler/init/<exploration_id>');
oppia.constant(
'EXPLORATION_VERSION_DATA_URL_TEMPLATE',
'/explorehandler/init/<exploration_id>?v=<version>');
oppia.constant(
'VOICEOVER_EXPLORATION_DATA_URL_TEMPLATE',
'/createhandler/voiceover/<exploration_id>');
/* New card is available but user hasn't gone to it yet (when oppia
gives a feedback and waits for user to press 'continue').
Not called when a card is selected by clicking progress dots */
oppia.constant('EVENT_NEW_CARD_AVAILABLE', 'newCardAvailable');

oppia.constant('WARNING_TYPES', {
// These must be fixed before the exploration can be saved.
CRITICAL: 'critical',
// These must be fixed before publishing an exploration to the public
// library.
ERROR: 'error'
});

oppia.constant('STATE_ERROR_MESSAGES', {
ADD_INTERACTION: 'Please add an interaction to this card.',
STATE_UNREACHABLE: 'This card is unreachable.',
UNABLE_TO_END_EXPLORATION: (
'There\'s no way to complete the exploration starting from this card. ' +
'To fix this, make sure that the last card in the chain starting from ' +
'this one has an \'End Exploration\' question type.'),
INCORRECT_SOLUTION: (
'The current solution does not lead to another card.'),
UNRESOLVED_ANSWER: (
'There is an answer among the top 10 which has no explicit feedback.')
});

oppia.constant(
'EXPLORATION_SUMMARY_DATA_URL_TEMPLATE', '/explorationsummarieshandler/data');

oppia.constant('EXPLORATION_AND_SKILL_ID_PATTERN', /^[a-zA-Z0-9_-]+$/);

// We use a slash because this character is forbidden in a state name.
oppia.constant('PLACEHOLDER_OUTCOME_DEST', '/');
oppia.constant('INTERACTION_DISPLAY_MODE_INLINE', 'inline');
oppia.constant('LOADING_INDICATOR_URL', '/activity/loadingIndicator.gif');
oppia.constant('OBJECT_EDITOR_URL_PREFIX', '/object_editor_template/');
// Feature still in development.
// NOTE TO DEVELOPERS: This should be synchronized with the value in feconf.
oppia.constant('ENABLE_ML_CLASSIFIERS', false);
// Feature still in development.
oppia.constant('INFO_MESSAGE_SOLUTION_IS_INVALID_FOR_EXPLORATION',
'The current solution does not lead to another card.');
oppia.constant('PARAMETER_TYPES', {
REAL: 'Real',
UNICODE_STRING: 'UnicodeString'
});

// The maximum number of nodes to show in a row of the state graph.
oppia.constant('MAX_NODES_PER_ROW', 4);
// The following variable must be at least 3. It represents the maximum length,
// in characters, for the name of each node label in the state graph.
oppia.constant('MAX_NODE_LABEL_LENGTH', 15);

// If an $http request fails with the following error codes, a warning is
// displayed.
oppia.constant('FATAL_ERROR_CODES', [400, 401, 404, 500]);

// Do not modify these, for backwards-compatibility reasons.
oppia.constant('COMPONENT_NAME_CONTENT', 'content');
oppia.constant('COMPONENT_NAME_HINT', 'hint');
oppia.constant('COMPONENT_NAME_SOLUTION', 'solution');
oppia.constant('COMPONENT_NAME_FEEDBACK', 'feedback');
oppia.constant('COMPONENT_NAME_EXPLANATION', 'explanation');
oppia.constant('COMPONENT_NAME_WORKED_EXAMPLE', 'worked_example');

oppia.constant('ACTION_TYPE_EXPLORATION_START', 'ExplorationStart');
oppia.constant('ACTION_TYPE_ANSWER_SUBMIT', 'AnswerSubmit');
oppia.constant('ACTION_TYPE_EXPLORATION_QUIT', 'ExplorationQuit');

oppia.constant('ISSUE_TYPE_EARLY_QUIT', 'EarlyQuit');
oppia.constant(
'ISSUE_TYPE_MULTIPLE_INCORRECT_SUBMISSIONS', 'MultipleIncorrectSubmissions');
oppia.constant('ISSUE_TYPE_CYCLIC_STATE_TRANSITIONS', 'CyclicStateTransitions');
oppia.constant('SITE_NAME', 'Oppia.org');

oppia.constant('DEFAULT_PROFILE_IMAGE_PATH', '/avatar/user_blue_72px.png');

oppia.constant('LOGOUT_URL', '/logout');

oppia.constant(
'EVENT_QUESTION_SUMMARIES_INITIALIZED', 'questionSummariesInitialized');

// TODO(vojtechjelinek): Move these to separate file later, after we establish
// process to follow for Angular constants (#6731).
oppia.constant(
'SUBTOPIC_PAGE_EDITOR_DATA_URL_TEMPLATE',
'/subtopic_page_editor_handler/data/<topic_id>/<subtopic_id>');
oppia.constant(
'EDITABLE_TOPIC_DATA_URL_TEMPLATE', '/topic_editor_handler/data/<topic_id>');

oppia.constant('LABEL_FOR_CLEARING_FOCUS', 'labelForClearingFocus');

// TODO(bhenning): This constant should be provided by the backend.
oppia.constant(
'COLLECTION_DATA_URL_TEMPLATE', '/collection_handler/data/<collection_id>');
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ require(
'hints-and-solution-manager.service.ts');
require(
'pages/exploration-player-page/services/hint-and-solution-modal.service.ts');
require('pages/exploration-player-page/exploration-player-page.constants.ts');
require('pages/exploration-player-page/services/player-position.service.ts');
require('pages/exploration-player-page/services/player-transcript.service.ts');
require('pages/exploration-player-page/services/stats-reporting.service.ts');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ require('domain/utilities/UrlInterpolationService.ts');
require('services/AlertsService.ts');
require('services/EditabilityService.ts');

oppia.constant('INTERACTION_SPECS', GLOBALS.INTERACTION_SPECS);
require('pages/interaction-specs.constants.ts');

oppia.directive('questionEditor', [
'UrlInterpolationService', function(UrlInterpolationService) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
/**
* @fileoverview Controller for the questions player directive.
*/
oppia.constant('INTERACTION_SPECS', GLOBALS.INTERACTION_SPECS);

require('domain/question/QuestionPlayerBackendApiService.ts');
require('domain/utilities/UrlInterpolationService.ts');
Expand Down Expand Up @@ -102,6 +101,8 @@ require(
'pages/exploration-player-page/layout-directives/' +
'learner-view-info.directive.ts');

require('pages/interaction-specs.constants.ts');

oppia.directive('questionPlayer', [
'$http', 'UrlInterpolationService',
function(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,24 +87,3 @@ oppia.factory('StatePropertyService', [
};
}
]);

oppia.constant('WARNING_TYPES', {
// These must be fixed before the exploration can be saved.
CRITICAL: 'critical',
// These must be fixed before publishing an exploration to the public
// library.
ERROR: 'error'
});

oppia.constant('STATE_ERROR_MESSAGES', {
ADD_INTERACTION: 'Please add an interaction to this card.',
STATE_UNREACHABLE: 'This card is unreachable.',
UNABLE_TO_END_EXPLORATION: (
'There\'s no way to complete the exploration starting from this card. ' +
'To fix this, make sure that the last card in the chain starting from ' +
'this one has an \'End Exploration\' question type.'),
INCORRECT_SOLUTION: (
'The current solution does not lead to another card.'),
UNRESOLVED_ANSWER: (
'There is an answer among the top 10 which has no explicit feedback.')
});
Loading

0 comments on commit 4e665fa

Please sign in to comment.