Skip to content

Commit

Permalink
Change controllers to components (Part 1) (#9317)
Browse files Browse the repository at this point in the history
* Change about-page to component

* Change community-dashboard-page to component

* Change creator-dashboard-page to component

* Change preferences-page to component

* Change profile-page to component

* Change teach-page to component

* Change splash-page to component

* Change thanks-page to component

* Change moderator-page to component

* Change signup-page to component

* Change notifications-dashboard--page to component

* Change delete-account-page to component

* Change error-page to component

* Fix lint app.ts list for upgraded services

* Add components templates and ts to karma test runner

* Fix script

* Update script for update_changelog_and_credits

* Change import directive to component

* Add removed code
  • Loading branch information
marianadasilvadev authored May 30, 2020
1 parent 9d17803 commit 459bf9e
Show file tree
Hide file tree
Showing 74 changed files with 2,298 additions and 2,393 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
/LICENSE @seanlip
/NOTICE @seanlip
/core/templates/pages/about-page/ @DubeySandeep
/core/templates/pages/about-page/about-page.directive.html @seanlip
/core/templates/pages/about-page/about-page.component.html @seanlip
/core/templates/pages/privacy-page/ @DubeySandeep
/core/templates/pages/privacy-page/privacy-page.mainpage.html @seanlip
/core/templates/pages/terms-page/ @DubeySandeep
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ QA Team
* Milestone 3.2 (3th PR) - Increase coverage for three services (#8569)
* Fix part of #4057: Increase frontend test services from Milestone 3.2 (2nd PR) (#8560)
* Fix part of #4057: Increase frontend test services from Milestone 3.2 (1st PR) (#8530)
* Increase coverage for notifications-dashboard-page.controller.ts and mark-all-audio-and-translations-as-needing-update.controller.ts (#8528)
* Increase coverage for notifications-dashboard-page.component.ts and mark-all-audio-and-translations-as-needing-update.controller.ts (#8528)
* Milestone 3.1 (3rd PR) - Increase coverage for hints-and-solution-manager.service.ts (#8525)
* Milestone 3.1 (2nd PR) - Increase coverage for three services (#8524)
* Fix part of #4057: Adds test for UserEmailPreferencesService (#8513)
Expand Down
33 changes: 19 additions & 14 deletions core/templates/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,24 +92,29 @@ angular.module('oppia').config([
'AlertsService', 'BackgroundMaskService', 'BrowserCheckerService',
'CodeReplRulesService', 'CollectionCreationBackendService',
'CollectionCreationBackendService',
'ContextService', 'CsrfTokenService', 'DateTimeFormatService',
'DebouncerService', 'DeviceInfoService',
'ContextService', 'CreatorDashboardBackendApiService', 'CsrfTokenService',
'DateTimeFormatService', 'DebouncerService', 'DeviceInfoService',
'DocumentAttributeCustomizationService',
'ExplorationHtmlFormatterService', 'ExplorationObjectFactory',
'ExpressionParserService', 'ExtensionTagAssemblerService',
'ExtractImageFilenamesFromStateService', 'HtmlEscaperService',
'IdGenerationService', 'InteractionObjectFactory',
'InteractionRulesRegistryService', 'LoaderService', 'LoggerService',
'ExtractImageFilenamesFromStateService',
'HtmlEscaperService', 'IdGenerationService', 'InteractionObjectFactory',
'InteractionRulesRegistryService', 'LanguageUtilService',
'LoaderService', 'LocalStorageService', 'LoggerService',
'MetaTagCustomizationService', 'NormalizeWhitespacePipe',
'NormalizeWhitespacePunctuationAndCasePipe',
'PencilCodeEditorRulesService', 'SidebarStatusService',
'SiteAnalyticsService', 'SkillObjectFactory', 'SolutionObjectFactory',
'StateCardObjectFactory', 'StateImprovementSuggestionService',
'StateInteractionStatsService', 'StateObjectFactory',
'StatesObjectFactory', 'TextInputRulesService', 'UrlInterpolationService',
'UrlService', 'UserInfoObjectFactory', 'UtilsService',
'ValidatorsService', 'WindowDimensionsService', 'WindowRef'
];
'NormalizeWhitespacePunctuationAndCasePipe', 'PageTitleService',
'PencilCodeEditorRulesService', 'RatingComputationService',
'SchemaDefaultValueService', 'SchemaUndefinedLastElementService',
'SidebarStatusService', 'SiteAnalyticsService', 'SkillObjectFactory',
'SolutionObjectFactory', 'StateCardObjectFactory',
'StateImprovementSuggestionService', 'StateInteractionStatsService',
'StateObjectFactory', 'StatesObjectFactory', 'SuggestionsService',
'SuggestionThreadObjectFactory', 'TextInputRulesService',
'ThreadMessageObjectFactory', 'ThreadMessageSummaryObjectFactory',
'ThreadStatusDisplayService', 'TranslationLanguageService',
'UrlInterpolationService', 'UrlService', 'UserInfoObjectFactory',
'UtilsService', 'ValidatorsService', 'WindowDimensionsService',
'WindowRef'];
for (let [key, value] of Object.entries(ugs.getUpgradedServices())) {
if (servicesToProvide.includes(key)) {
$provide.value(key, value);
Expand Down
2 changes: 1 addition & 1 deletion core/templates/combined-tests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ getTestBed().initTestEnvironment(
// The 'domhandler/src/index.spec.ts' is excluded from the tests since it is
// coming from third party library.
/* eslint-disable max-len */
const context = require.context('../../', true, /((\.s|S)pec\.ts$|(?<!services_sources)\/[\w\d.\-]*(controller|directive|service|Factory)\.ts$)(?<!combined-tests\.spec\.ts)(?<!state-content-editor\.directive\.spec\.ts)(?<!music-notes-input\.spec\.ts)(?<!state-interaction-editor\.directive\.spec\.ts)(?<!state-name-editor\.directive\.spec\.ts)(?<!domhandler\/src\/index\.spec\.ts)/);
const context = require.context('../../', true, /((\.s|S)pec\.ts$|(?<!services_sources)\/[\w\d.\-]*(component|controller|directive|service|Factory)\.ts$)(?<!combined-tests\.spec\.ts)(?<!state-content-editor\.directive\.spec\.ts)(?<!music-notes-input\.spec\.ts)(?<!state-interaction-editor\.directive\.spec\.ts)(?<!state-name-editor\.directive\.spec\.ts)(?<!domhandler\/src\/index\.spec\.ts)/);
/* eslint-enable max-len */

// And load the modules.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,18 @@

import { WindowRef } from 'services/contextual/window-ref.service';

require('pages/about-page/about-page.component.ts');

describe('About Page', function() {
var $scope = null;
var ctrl = null;
var windowRef = new WindowRef();

beforeEach(angular.mock.module('oppia'));
beforeEach(angular.mock.module('oppia', function($provide) {
$provide.value('WindowRef', windowRef);
}));
beforeEach(angular.mock.inject(function($injector) {
var $rootScope = $injector.get('$rootScope');
$scope = $rootScope.$new();
var directive = $injector.get('aboutPageDirective')[0];
ctrl = $injector.instantiate(directive.controller, {
$rootScope: $scope
});
beforeEach(angular.mock.inject(function($componentController) {
ctrl = $componentController('aboutPage');
}));

afterEach(function() {
Expand Down
90 changes: 90 additions & 0 deletions core/templates/pages/about-page/about-page.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// Copyright 2016 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 Controllers for the about page.
*/

require(
'components/common-layout-directives/common-elements/' +
'background-banner.component.ts');

require('domain/utilities/url-interpolation.service.ts');

angular.module('oppia').component('aboutPage', {
template: require('./about-page.component.html'),
controller: [
'UrlInterpolationService', 'WindowRef',
function(UrlInterpolationService, WindowRef) {
const ctrl = this;
const listOfNamesToThank = [
'Alex Kauffmann', 'Allison Barros',
'Amy Latten', 'Brett Barros',
'Crystal Kwok', 'Daniel Hernandez',
'Divya Siddarth', 'Ilwon Yoon',
'Jennifer Chen', 'John Cox',
'John Orr', 'Katie Berlent',
'Michael Wawszczak', 'Mike Gainer',
'Neil Fraser', 'Noah Falstein',
'Nupur Jain', 'Peter Norvig',
'Philip Guo', 'Piotr Mitros',
'Rachel Chen', 'Rahim Nathwani',
'Robyn Choo', 'Tricia Ngoon',
'Vikrant Nanda', 'Vinamrata Singal',
'Yarin Feigenbaum'];
// Define constant for each tab on the page.
ctrl.TAB_ID_ABOUT = 'about';
ctrl.TAB_ID_FOUNDATION = 'foundation';
ctrl.TAB_ID_CREDITS = 'credits';

const ALLOWED_TABS = [
ctrl.TAB_ID_ABOUT, ctrl.TAB_ID_FOUNDATION, ctrl.TAB_ID_CREDITS];

ctrl.activeTabName = ctrl.TAB_ID_ABOUT;

ctrl.onTabClick = function(tabName: string) {
// Update hash
WindowRef.nativeWindow.location.hash = '#' + tabName;
ctrl.activeTabName = tabName;
};
ctrl.getStaticImageUrl = function(imagePath: string) {
return UrlInterpolationService.getStaticImageUrl(imagePath);
};
ctrl.$onInit = function() {
const hash = WindowRef.nativeWindow.location.hash.slice(1);
if (hash === 'license') {
ctrl.activeTabName = ctrl.TAB_ID_FOUNDATION;
} else if (ALLOWED_TABS.includes(hash)) {
ctrl.activeTabName = hash;
}

ctrl.listOfNames = listOfNamesToThank
.slice(0, listOfNamesToThank.length - 1).join(', ') +
' & ' + listOfNamesToThank[listOfNamesToThank.length - 1];
ctrl.aboutPageMascotImgUrl = UrlInterpolationService
.getStaticImageUrl('/general/about_page_mascot.png');

WindowRef.nativeWindow.onhashchange = function() {
const hashChange = window.location.hash.slice(1);
if (hashChange === 'license') {
ctrl.activeTabName = ctrl.TAB_ID_FOUNDATION;
WindowRef.nativeWindow.location.reload(true);
} else if (ALLOWED_TABS.includes(hashChange)) {
ctrl.activeTabName = hashChange;
}
};
};
}
]
});
98 changes: 0 additions & 98 deletions core/templates/pages/about-page/about-page.controller.ts

This file was deleted.

2 changes: 1 addition & 1 deletion core/templates/pages/about-page/about-page.scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
require('pages/about-page/about-page.module.ts');
require('App.ts');

require('pages/about-page/about-page.controller.ts');
require('pages/about-page/about-page.component.ts');
require('base-components/base-content.directive.ts');
Loading

0 comments on commit 459bf9e

Please sign in to comment.