Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove base controller from HTML tag to after Angular bootstrap and convert I18NFooter and Thanks to component directives. #7283

Merged
merged 15 commits into from
Aug 5, 2019
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,9 @@
/core/templates/dev/head/combined-tests.spec.ts @ankita240796
/core/templates/dev/head/pages/interaction-specs.constants.ts @vojtechjelinek @Jamesjay4199
/core/templates/dev/head/I18nFooter.ts @DubeySandeep
/core/templates/dev/head/i18n-footer.directive.html @DubeySandeep
/core/templates/dev/head/services/contextual/DocumentAttributeCustomizationService.ts @YashJipkate
/core/templates/dev/head/services/contextual/MetaTagCustomizationService.ts @YashJipkate
/core/templates/dev/head/services/TranslationFileHashLoaderService.ts @DubeySandeep


Expand Down
68 changes: 39 additions & 29 deletions core/templates/dev/head/I18nFooter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,47 @@

require('services/TranslationFileHashLoaderService.ts');

angular.module('oppia').controller('I18nFooter', [
'$http', '$scope', '$timeout', '$translate', 'UserService',
function($http, $scope, $timeout, $translate, UserService) {
// Changes the language of the translations.
var preferencesDataUrl = '/preferenceshandler/data';
var siteLanguageUrl = '/save_site_language';
$scope.supportedSiteLanguages = constants.SUPPORTED_SITE_LANGUAGES;
angular.module('oppia').directive('i18nFooter', [
'UrlInterpolationService', function(UrlInterpolationService) {
return {
restrict: 'E',
scope: {},
bindToController: {},
templateUrl: UrlInterpolationService.getDirectiveTemplateUrl(
'/i18n-footer.directive.html'),
controllerAs: '$ctrl',
controller: [
'$http', '$timeout', '$translate', 'UserService',
function($http, $timeout, $translate, UserService) {
var ctrl = this;
// Changes the language of the translations.
var preferencesDataUrl = '/preferenceshandler/data';
var siteLanguageUrl = '/save_site_language';
ctrl.supportedSiteLanguages = constants.SUPPORTED_SITE_LANGUAGES;

// The $timeout seems to be necessary for the dropdown to show anything
// at the outset, if the default language is not English.
$timeout(function() {
// $translate.use() returns undefined until the language file is fully
// loaded, which causes a blank field in the dropdown, hence we use
// $translate.proposedLanguage() as suggested in
// http://stackoverflow.com/a/28903658
$scope.currentLanguageCode = $translate.use() ||
$translate.proposedLanguage();
}, 50);
// The $timeout seems to be necessary for the dropdown to show
// anything at the outset, if the default language is not English.
$timeout(function() {
// $translate.use() returns undefined until the language file is
// fully loaded, which causes a blank field in the dropdown, hence
// we use $translate.proposedLanguage() as suggested in
// http://stackoverflow.com/a/28903658
ctrl.currentLanguageCode = $translate.use() ||
$translate.proposedLanguage();
}, 50);

$scope.changeLanguage = function() {
$translate.use($scope.currentLanguageCode);
UserService.getUserInfoAsync().then(function(userInfo) {
if (userInfo.isLoggedIn()) {
$http.put(siteLanguageUrl, {
site_language_code: $scope.currentLanguageCode
});
}
});
};
}
]);
ctrl.changeLanguage = function() {
$translate.use(ctrl.currentLanguageCode);
UserService.getUserInfoAsync().then(function(userInfo) {
if (userInfo.isLoggedIn()) {
$http.put(siteLanguageUrl, {
site_language_code: ctrl.currentLanguageCode
});
}
});
};
}]};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ']' should move to the next line to match the opening indentation.

The '}' should move to the line after that.

In general, when you see a gap that's too big between indentation levels, please fix it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in #7066.

}]);

angular.module('oppia').config([
'$translateProvider', 'DEFAULT_TRANSLATIONS',
Expand Down
7 changes: 0 additions & 7 deletions core/templates/dev/head/base_components/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,13 @@
<meta name="referrer" content="no-referrer">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=yes">
<meta name="description" content="Oppia is a free site for sharing knowledge via interactive lessons called explorations. Learn from user-created explorations, or teach and create your own.">
<meta name="application-name" content="<[siteName]>">
<meta name="msapplication-square310x310logo" content="<[getAssetUrl('/assets/images/logo/msapplication-large.png')]>">
<meta name="msapplication-wide310x150logo" content="<[getAssetUrl('/assets/images/logo/msapplication-wide.png')]>">
<meta name="msapplication-square150x150logo" content="<[getAssetUrl('/assets/images/logo/msapplication-square.png')]>">
<meta name="msapplication-square70x70logo" content="<[getAssetUrl('/assets/images/logo/msapplication-tiny.png')]>">
<meta itemprop="name" content="<%= htmlWebpackPlugin.options.meta.name %>">
<meta itemprop="description" content="<%= htmlWebpackPlugin.options.meta.description %>">
<!-- The og tags are for Facebook sharing. -->
<meta property="og:title" content="<%= htmlWebpackPlugin.options.meta.name %>">
<meta property="og:type" content="article">
<meta property="og:site_name" content="Oppia">
<meta property="og:description" content="<%= htmlWebpackPlugin.options.meta.description %>">
<meta property="og:url" content="<[pageUrl]>">
<meta property="og:image" content="<[getAssetUrl('/assets/images/logo/288x288_logo_mint.png')]>">

<link rel="apple-touch-icon" href="/assets/images/logo/favicon.png">
<title itemprop="name"><%= title %></title>
Expand Down
8 changes: 8 additions & 0 deletions core/templates/dev/head/i18n-footer.directive.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<ul>
<select ng-model="$ctrl.currentLanguageCode"
ng-change="$ctrl.changeLanguage()"
ng-options="language.id as language.text for language in $ctrl.supportedSiteLanguages"
class="oppia-language-selector protractor-test-i18n-language-selector"
style="color: black;" aria-label="Change languages">
</select>
</ul>
48 changes: 48 additions & 0 deletions core/templates/dev/head/pages/Base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
require('domain/sidebar/SidebarStatusService.ts');
require('domain/utilities/UrlInterpolationService.ts');
require('services/CsrfTokenService.ts');
require('services/contextual/DocumentAttributeCustomizationService.ts');
require('services/contextual/MetaTagCustomizationService.ts');
require('services/contextual/UrlService.ts');

require('app.constants.ts');
Expand All @@ -25,10 +27,12 @@ require('app.constants.ts');

angular.module('oppia').controller('Base', [
'$document', '$rootScope', '$scope', 'CsrfTokenService',
'DocumentAttributeCustomizationService', 'MetaTagCustomizationService',
'SidebarStatusService', 'UrlInterpolationService', 'UrlService', 'DEV_MODE',
'SITE_NAME',
function(
$document, $rootScope, $scope, CsrfTokenService,
DocumentAttributeCustomizationService, MetaTagCustomizationService,
SidebarStatusService, UrlInterpolationService, UrlService, DEV_MODE,
SITE_NAME) {
$scope.siteName = SITE_NAME;
Expand All @@ -43,12 +47,56 @@ angular.module('oppia').controller('Base', [
$rootScope.loadingMessage = '';

CsrfTokenService.initializeToken();
MetaTagCustomizationService.addMetaTags([
{
propertyType: 'name',
propertyValue: 'application-name',
content: SITE_NAME
},
{
propertyType: 'name',
propertyValue: 'msapplication-square310x310logo',
content: $scope.getAssetUrl(
'/assets/images/logo/msapplication-large.png')
},
{
propertyType: 'name',
propertyValue: 'msapplication-wide310x150logo',
content: $scope.getAssetUrl(
'/assets/images/logo/msapplication-wide.png')
},
{
propertyType: 'name',
propertyValue: 'msapplication-square150x150logo',
content: $scope.getAssetUrl(
'/assets/images/logo/msapplication-square.png')
},
{
propertyType: 'name',
propertyValue: 'msapplication-square70x70logo',
content: $scope.getAssetUrl(
'/assets/images/logo/msapplication-tiny.png')
},
{
propertyType: 'property',
propertyValue: 'og:url',
content: $scope.pageUrl
},
{
propertyType: 'property',
propertyValue: 'og:image',
content: $scope.getAssetUrl('/assets/images/logo/288x288_logo_mint.png')
}
]);

// Listener function to catch the change in language preference.
$rootScope.$on('$translateChangeSuccess', function(evt, response) {
$scope.currentLang = response.language;
});

DocumentAttributeCustomizationService.addAttribute(
'lang', $scope.currentLang);

// TODO(sll): use 'touchstart' for mobile.
$document.on('click', function() {
SidebarStatusService.onDocumentClick();
Expand Down
30 changes: 16 additions & 14 deletions core/templates/dev/head/pages/about-page/about-page.mainpage.html
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
<!DOCTYPE html>
<html ng-app="oppia" lang="<[currentLang]>" ng-controller="Base" itemscope itemtype="http://schema.org/Organization">
<html ng-app="oppia" itemscope itemtype="http://schema.org/Organization">
<head>
@require('../../base_components/header.html', {"title": "About us - Oppia"})
</head>
<body>
<service-bootstrap></service-bootstrap>
<base-content>
<navbar-breadcrumb>
<ul class="nav navbar-nav oppia-navbar-breadcrumb">
<li>
<span class="oppia-navbar-breadcrumb-separator"></span>
About
</li>
</ul>
</navbar-breadcrumb>
<div ng-controller="Base">
<base-content>
<navbar-breadcrumb>
<ul class="nav navbar-nav oppia-navbar-breadcrumb">
<li>
<span class="oppia-navbar-breadcrumb-separator"></span>
About
</li>
</ul>
</navbar-breadcrumb>

<content>
<about-page></about-page>
</content>
</base-content>
<content>
<about-page></about-page>
</content>
</base-content>
</div>

@require('../footer_js_libs.html')
</body>
Expand Down
111 changes: 56 additions & 55 deletions core/templates/dev/head/pages/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
{%- endmacro %}

<!DOCTYPE html>
<html ng-app="oppia" lang="<[currentLang]>" ng-controller="Base" itemscope itemtype="http://schema.org/Organization">
<html ng-app="oppia" itemscope itemtype="http://schema.org/Organization">
<head>
{% block prerender %}
{% endblock prerender %}
Expand All @@ -43,7 +43,6 @@
<meta name="description" content="Oppia is a free site for sharing knowledge via interactive lessons called explorations. Learn from user-created explorations, or teach and create your own.">

<!-- Tiles for Internet Explorer. -->
<meta name="application-name" content="<[siteName]>">
<meta name="msapplication-TileColor" content="#ffffff">
<meta name="msapplication-square70x70logo" content="{{get_complete_static_resource_url(DOMAIN_URL, '/assets/images/logo/msapplication-tiny.png')}}">
<meta name="msapplication-square150x150logo" content="{{get_complete_static_resource_url(DOMAIN_URL, '/assets/images/logo/msapplication-square.png')}}">
Expand Down Expand Up @@ -94,72 +93,74 @@

<body>
<service-bootstrap></service-bootstrap>
<div ng-if="iframed">
{{ warnings_and_loader() }}
</div>
<div ng-if="!iframed">
<div role="button" tabindex="0" ng-click="skipToMainContent()" class="oppia-skip-to-content protractor-test-skip-link">Skip to Main Content</div>
<promo-bar>
</promo-bar>
<div ng-if="isBackgroundMaskActive()" class="ng-cloak oppia-background-mask">
<div ng-controller="Base">
<div ng-if="iframed">
{{ warnings_and_loader() }}
</div>
<div ng-if="!iframed">
<div role="button" tabindex="0" ng-click="skipToMainContent()" class="oppia-skip-to-content protractor-test-skip-link">Skip to Main Content</div>
<promo-bar>
</promo-bar>
<div ng-if="isBackgroundMaskActive()" class="ng-cloak oppia-background-mask">
</div>

<div class="oppia-base-container"
ng-class="{'oppia-sidebar-menu-open': isSidebarShown(), 'oppia-sidebar-menu-closed': !isSidebarShown()}"
ng-swipe-left="closeSidebarOnSwipe()" ng-swipe-disable-mouse="false">
<div class="oppia-content-container">
<div id="wrapper">
<div class="oppia-main-body">
<nav class="navbar navbar-default oppia-navbar oppia-prevent-selection" role="navigation" headroom tolerance="0" offset="0">
<div class="navbar-container">
<top-navigation-bar></top-navigation-bar>
<div class="collapse navbar-collapse oppia-navbar-collapse ng-cloak">
{% block navbar_breadcrumb %}
{% endblock navbar_breadcrumb %}

{% block local_top_nav_options %}
{% endblock local_top_nav_options %}
<div class="oppia-base-container"
ng-class="{'oppia-sidebar-menu-open': isSidebarShown(), 'oppia-sidebar-menu-closed': !isSidebarShown()}"
ng-swipe-left="closeSidebarOnSwipe()" ng-swipe-disable-mouse="false">
<div class="oppia-content-container">
<div id="wrapper">
<div class="oppia-main-body">
<nav class="navbar navbar-default oppia-navbar oppia-prevent-selection" role="navigation" headroom tolerance="0" offset="0">
<div class="navbar-container">
<top-navigation-bar></top-navigation-bar>
<div class="collapse navbar-collapse oppia-navbar-collapse ng-cloak">
{% block navbar_breadcrumb %}
{% endblock navbar_breadcrumb %}

{% block local_top_nav_options %}
{% endblock local_top_nav_options %}
</div>
</div>
</nav>

<div class="oppia-top-of-page-padding">
</div>
</nav>

<div class="oppia-top-of-page-padding">
{{ warnings_and_loader() }}
</div>

{{ warnings_and_loader() }}
</div>

<noscript>
<div class="oppia-page-cards-container">
<div class="md-default-theme oppia-page-card oppia-long-text">
<!-- Note to developers: We replicate the translated text inline because, without JavaScript enabled, the translation engine doesn't kick in.-->
<h2>
<span translate="I18N_SPLASH_JAVASCRIPT_ERROR_TITLE">We Need JavaScript in Your Browser</span>
<i class="material-icons">&#xE811;</i>
</h2>
<p translate="I18N_SPLASH_JAVASCRIPT_ERROR_DESCRIPTION"
translate-values="{hrefUrl: 'http://www.enable-javascript.com/'}">
Oppia is a free, open-source learning platform full of interactive activities called 'explorations'. Sadly, Oppia requires JavaScript to be enabled in your web browser in order to function properly and your web browser has JavaScript disabled. If you need help enabling JavaScript, <a href="http://www.enable-javascript.com">click here.</a>
</p>
<p translate="I18N_SPLASH_JAVASCRIPT_ERROR_THANKS">Thank you.</p>
<noscript>
<div class="oppia-page-cards-container">
<div class="md-default-theme oppia-page-card oppia-long-text">
<!-- Note to developers: We replicate the translated text inline because, without JavaScript enabled, the translation engine doesn't kick in.-->
<h2>
<span translate="I18N_SPLASH_JAVASCRIPT_ERROR_TITLE">We Need JavaScript in Your Browser</span>
<i class="material-icons">&#xE811;</i>
</h2>
<p translate="I18N_SPLASH_JAVASCRIPT_ERROR_DESCRIPTION"
translate-values="{hrefUrl: 'http://www.enable-javascript.com/'}">
Oppia is a free, open-source learning platform full of interactive activities called 'explorations'. Sadly, Oppia requires JavaScript to be enabled in your web browser in order to function properly and your web browser has JavaScript disabled. If you need help enabling JavaScript, <a href="http://www.enable-javascript.com">click here.</a>
</p>
<p translate="I18N_SPLASH_JAVASCRIPT_ERROR_THANKS">Thank you.</p>
</div>
</div>
</div>
</noscript>
</noscript>

<side-navigation-bar></side-navigation-bar>
<side-navigation-bar></side-navigation-bar>
</div>
</div>
</div>
</div>

<div ng-if="DEV_MODE" class="oppia-dev-mode" ng-cloak>
Dev Mode
</div>
<div ng-if="DEV_MODE" class="oppia-dev-mode" ng-cloak>
Dev Mode
</div>

<a ng-if="siteFeedbackFormUrl" ng-href="<[siteFeedbackFormUrl]>" target="_blank"
rel="noopener" class="oppia-site-feedback oppia-transition-200">
<i class="material-icons md-18">&#xE87F;</i>
<span translate="I18N_SPLASH_SITE_FEEDBACK"></span>
</a>
<a ng-if="siteFeedbackFormUrl" ng-href="<[siteFeedbackFormUrl]>" target="_blank"
rel="noopener" class="oppia-site-feedback oppia-transition-200">
<i class="material-icons md-18">&#xE87F;</i>
<span translate="I18N_SPLASH_SITE_FEEDBACK"></span>
</a>
</div>
</div>

@require('footer_js_libs.html')
Expand Down
Loading