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
Prev Previous commit
Next Next commit
Incomplete work
  • Loading branch information
YashJipkate committed Jul 7, 2019
commit b300849f6b5fff3edf744485b3d87f052aba828e
1 change: 0 additions & 1 deletion core/templates/dev/head/base_components/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<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')]>">
Expand Down
107 changes: 62 additions & 45 deletions core/templates/dev/head/pages/Base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,67 +16,84 @@ require('domain/sidebar/SidebarStatusService.ts');
require('domain/utilities/UrlInterpolationService.ts');
require('services/AlertsService.ts');
require('services/CsrfTokenService.ts');
require('services/contextual/DocumentAttributeCustomizationService.ts');
require('services/contextual/UrlService.ts');
require('services/contextual/MetaTagCustomizationService.ts');
require('services/stateful/BackgroundMaskService.ts');

require('app.constants.ts');

/**
* @fileoverview Oppia's base controller.
* @fileoverview Oppia's base directive.
*/

var oppia = require('AppInit.ts').module;

oppia.controller('Base', [
'$document', '$http', '$rootScope', '$scope', 'AlertsService',
'BackgroundMaskService', 'CsrfTokenService', 'SidebarStatusService',
'UrlInterpolationService', 'UrlService', 'DEV_MODE',
'SITE_FEEDBACK_FORM_URL', 'SITE_NAME',
function($document, $http, $rootScope, $scope, AlertsService,
BackgroundMaskService, CsrfTokenService, SidebarStatusService,
UrlInterpolationService, UrlService, DEV_MODE,
SITE_FEEDBACK_FORM_URL, SITE_NAME) {
$scope.siteName = SITE_NAME;
$scope.AlertsService = AlertsService;
$scope.currentLang = 'en';
$scope.iframed = UrlService.isIframed();
$scope.siteFeedbackFormUrl = SITE_FEEDBACK_FORM_URL;
$scope.pageUrl = UrlService.getCurrentLocation().href;
$scope.getAssetUrl = function(path) {
return UrlInterpolationService.getFullStaticAssetUrl(path);
};
oppia.directive('base', ['UrlInterpolationService', function(
UrlInterpolationService) {
return {
restrict: 'E',
scope: {},
bindToController: {},
templateUrl: UrlInterpolationService.getDirectiveTemplateUrl(
'/pages/base.directive.html'),
controllerAs: '$ctrl',
controller: [
'$document', '$http', '$rootScope', '$scope', 'AlertsService',
'DocumentAttributeCustomizationService', 'BackgroundMaskService',
'CsrfTokenService', 'MetaTagCustomizationService', 'SidebarStatusService',
'UrlInterpolationService', 'UrlService', 'DEV_MODE',
'SITE_FEEDBACK_FORM_URL', 'SITE_NAME',
function($document, $http, $rootScope, $scope, AlertsService,
DocumentAttributeCustomizationService, BackgroundMaskService,
CsrfTokenService, MetaTagCustomizationService, SidebarStatusService,
UrlInterpolationService, UrlService, DEV_MODE,
SITE_FEEDBACK_FORM_URL, SITE_NAME) {
var ctrl = this;
$scope.AlertsService = AlertsService;
$scope.currentLang = 'en';
$scope.iframed = UrlService.isIframed();
$scope.siteFeedbackFormUrl = SITE_FEEDBACK_FORM_URL;
$scope.pageUrl = UrlService.getCurrentLocation().href;
$scope.getAssetUrl = function(path) {
return UrlInterpolationService.getFullStaticAssetUrl(path);
};

$rootScope.DEV_MODE = DEV_MODE;
// If this is nonempty, the whole page goes into 'Loading...' mode.
$rootScope.loadingMessage = '';
$rootScope.DEV_MODE = DEV_MODE;
// If this is nonempty, the whole page goes into 'Loading...' mode.
$rootScope.loadingMessage = '';

$scope.isSidebarShown = SidebarStatusService.isSidebarShown;
$scope.closeSidebarOnSwipe = SidebarStatusService.closeSidebar;
$scope.isSidebarShown = SidebarStatusService.isSidebarShown;
$scope.closeSidebarOnSwipe = SidebarStatusService.closeSidebar;

$scope.isBackgroundMaskActive = BackgroundMaskService.isMaskActive;
$scope.isBackgroundMaskActive = BackgroundMaskService.isMaskActive;

CsrfTokenService.initializeToken();
CsrfTokenService.initializeToken();
MetaTagCustomizationService.addMetaTag('application-name', SITE_NAME);

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

// TODO(sll): use 'touchstart' for mobile.
$document.on('click', function() {
SidebarStatusService.onDocumentClick();
$scope.$apply();
});
DocumentAttributeCustomizationService.addAttribute('lang', $scope.currentLang);

$scope.skipToMainContent = function() {
var mainContentElement = document.getElementById('oppia-main-content');
// TODO(sll): use 'touchstart' for mobile.
$document.on('click', function() {
SidebarStatusService.onDocumentClick();
$scope.$apply();
});

if (!mainContentElement) {
throw Error('Variable mainContentElement is undefined.');
$scope.skipToMainContent = function() {
var mainContentElement = document.getElementById('oppia-main-content');

if (!mainContentElement) {
throw Error('Variable mainContentElement is undefined.');
}
mainContentElement.tabIndex = -1;
mainContentElement.scrollIntoView();
mainContentElement.focus();
};
}
mainContentElement.tabIndex = -1;
mainContentElement.scrollIntoView();
mainContentElement.focus();
};
}
]);
]};
}]);
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html ng-app="oppia" lang="<[currentLang]>" ng-controller="Base" itemscope itemtype="http://schema.org/Organization">
<html ng-app="oppia" ng-controller="Base" itemscope itemtype="http://schema.org/Organization">
<head>
@require('../../base_components/header.html', {"title": "About us - Oppia"})
</head>
Expand Down
105 changes: 105 additions & 0 deletions core/templates/dev/head/pages/base.directive.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
{% macro warnings_and_loader() -%}
<div tabindex="0" aria-label="Oppia Main Content" id="oppia-main-content" class="protractor-test-main-content" ng-cloak>
<div class="oppia-toast-container toast-top-center">
<div ng-repeat="warning in ($ctrl.AlertsService.warnings | limitTo:5) track by $index" class="toast toast-warning oppia-toast">
<button type="button" class="toast-close-button" ng-click="$ctrl.AlertsService.deleteWarning(warning)" role="button">&times;</button>
<div class="toast-message">
<[warning.content]>
</div>
</div>
</div>

<div>
<div ng-repeat="message in $ctrl.AlertsService.messages track by $index">
<alert-message message-object="message" message-index="$index"></alert-message>
</div>
</div>

<div ng-show="loadingMessage" class="oppia-loading-fullpage">
<div class="oppia-align-center">
<span translate="<[loadingMessage]>"></span>
<span class="oppia-loading-dot-one">.</span>
<span class="oppia-loading-dot-two">.</span>
<span class="oppia-loading-dot-three">.</span>
</div>
</div>
<div ng-show="!loadingMessage">
{% block content %}
{% endblock %}
{% block footer %}
{% endblock %}
</div>
</div>
{%- endmacro %}

<div ng-if="$ctrl.iframed">
{{ warnings_and_loader() }}
</div>
<div ng-if="!$ctrl.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>
</div>
</nav>

<div class="oppia-top-of-page-padding">
</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>
</div>
</div>
</noscript>

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

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

<a ng-if="$ctrl.siteFeedbackFormUrl" ng-href="<[$ctrl.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>

@require('footer_js_libs.html')
{% block footer_js %}
{% endblock footer_js %}
109 changes: 2 additions & 107 deletions core/templates/dev/head/pages/base.html
Original file line number Diff line number Diff line change
@@ -1,39 +1,5 @@
{% macro warnings_and_loader() -%}
<div tabindex="0" aria-label="Oppia Main Content" id="oppia-main-content" class="protractor-test-main-content" ng-cloak>
<div class="oppia-toast-container toast-top-center">
<div ng-repeat="warning in (AlertsService.warnings | limitTo:5) track by $index" class="toast toast-warning oppia-toast">
<button type="button" class="toast-close-button" ng-click="AlertsService.deleteWarning(warning)" role="button">&times;</button>
<div class="toast-message">
<[warning.content]>
</div>
</div>
</div>

<div>
<div ng-repeat="message in AlertsService.messages track by $index">
<alert-message message-object="message" message-index="$index"></alert-message>
</div>
</div>

<div ng-show="loadingMessage" class="oppia-loading-fullpage">
<div class="oppia-align-center">
<span translate="<[loadingMessage]>"></span>
<span class="oppia-loading-dot-one">.</span>
<span class="oppia-loading-dot-two">.</span>
<span class="oppia-loading-dot-three">.</span>
</div>
</div>
<div ng-show="!loadingMessage">
{% block content %}
{% endblock %}
{% block footer %}
{% endblock %}
</div>
</div>
{%- endmacro %}

<!DOCTYPE html>
<html ng-app="oppia" lang="<[currentLang]>" ng-controller="Base" itemscope itemtype="http://schema.org/Organization">
<html ng-app="oppia" ng-controller="Base" itemscope itemtype="http://schema.org/Organization">
<head>
{% block prerender %}
{% endblock prerender %}
Expand All @@ -43,7 +9,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 @@ -93,76 +58,6 @@
</head>

<body>
<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>
</div>
</nav>

<div class="oppia-top-of-page-padding">
</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>
</div>
</div>
</noscript>

<side-navigation-bar></side-navigation-bar>
</div>
</div>
</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>
</div>

@require('footer_js_libs.html')
{% block footer_js %}
{% endblock footer_js %}
<base></base>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html ng-app="oppia" lang="<[currentLang]>" ng-controller="Base" itemscope itemtype="http://schema.org/Organization">
<html ng-app="oppia" ng-controller="Base" itemscope itemtype="http://schema.org/Organization">

<head>
@require('../../base_components/header.html', {"title": "Contact- Oppia"})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html ng-app="oppia" lang="<[currentLang]>" ng-controller="Base" itemscope itemtype="http://schema.org/Organization">
<html ng-app="oppia" ng-controller="Base" itemscope itemtype="http://schema.org/Organization">

<head>
@require('../../base_components/header.html', {"title": "Donate - Oppia"})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html ng-app="oppia" lang="<[currentLang]>" ng-controller="Base" itemscope itemtype="http://schema.org/Organization">
<html ng-app="oppia" ng-controller="Base" itemscope itemtype="http://schema.org/Organization">

<head>
@require('../../base_components/header.html', {"title": "Email Dashboard - Oppia"})
Expand Down
Loading