From 9882898f9236dc267cd87e91c1e2100cfb3153a6 Mon Sep 17 00:00:00 2001 From: jdlrobson Date: Wed, 6 Aug 2014 12:29:17 -0700 Subject: [PATCH] Notification overlay Messages and Alerts sections Shift to new API to support 2 tab view When a new has no messages they will see the old style overlay with Notifications heading. I have added tests to assure this is the case! Later patches will: 1) Add the mark as read button only in message view 2) Note currently the tabs do not refresh when notifications is clear. We need some kind of EventEmitter to make this sort of thing easier. Change-Id: I62b590e81cd3fe867c4c13959cb43466aacfe2d5 --- Resources.php | 6 +- i18n/en.json | 2 + i18n/qqq.json | 2 + modules/base/ext.echo.base.js | 11 +- modules/overlay/ext.echo.overlay.js | 357 ++++++++++--------- modules/overlay/ext.echo.overlay.less | 23 ++ tests/qunit/overlay/test_ext.echo.overlay.js | 175 +++++++-- 7 files changed, 375 insertions(+), 201 deletions(-) diff --git a/Resources.php b/Resources.php index c7f686f8d..c7f3e2f2b 100644 --- a/Resources.php +++ b/Resources.php @@ -70,13 +70,13 @@ $wgResourceModules += array( 'mediawiki.language', ), 'messages' => array( - 'echo-overlay-title', - 'echo-overlay-title-overflow', 'echo-overlay-link', - 'echo-none', 'echo-mark-all-as-read', 'echo-more-info', 'echo-feedback', + 'echo-notification-alert', + 'echo-notification-message', + 'echo-email-batch-bullet' ), ), 'ext.echo.overlay.init' => $echoResourceTemplate + array( diff --git a/i18n/en.json b/i18n/en.json index f6d70b1b4..b951e0ff8 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -94,6 +94,8 @@ "echo-email-batch-body-default": "You have a new notification.", "echo-email-footer-default": "$2\n\nTo control which emails we send you, check your preferences:\n{{canonicalurl:{{#special:Preferences}}#mw-prefsection-echo}}\n\n$1", "echo-email-footer-default-html": "To control which emails we send you, check your preferences.
\n$1", + "echo-notification-alert": "Alerts", + "echo-notification-message": "Messages", "echo-overlay-link": "All notifications", "echo-overlay-title": "Notifications", "echo-overlay-title-overflow": "{{PLURAL:$1|Notifications}} (showing $1 of $2 unread)", diff --git a/i18n/qqq.json b/i18n/qqq.json index 59cc389aa..06ef5a958 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -112,6 +112,8 @@ "echo-email-batch-body-default": "Default message for Echo e-mail digest notifications", "echo-email-footer-default": "Default footer content for Echo text e-mail notifications. Parameters:\n* $1 - the address of the organization that sent the email\n* $2 - \"-------...\" ({{msg-mw|echo-email-batch-separator}})\n\nFor HTML version, see {{msg-mw|echo-email-footer-default-html}}.", "echo-email-footer-default-html": "Default footer content for Echo html e-mail notifications. Parameters:\n* $1 - the address of the organization that sent the email\n* $2 - the URL to the notification preference page\nFor plain-text version, see {{msg-mw|Echo-email-footer-default}}.", + "echo-notification-alert": "Label for alert notifications tab in Echo overlay.", + "echo-notification-message": "Label for message notifications tab in Echo overlay.", "echo-overlay-link": "Link to \"all notifications\" at the bottom of the overlay.\n{{Identical|All notifications}}", "echo-overlay-title": "Title at the top of the notifications overlay. Should include bold tags.", "echo-overlay-title-overflow": "Title at the top of the notifications overlay when there are additional unread notifications that are not being shown.\n\nParameters:\n* $1 - the number of unread notifications being shown\n* $2 - the total number of unread notifications that exist", diff --git a/modules/base/ext.echo.base.js b/modules/base/ext.echo.base.js index 1ad5d3960..da3a90fb1 100644 --- a/modules/base/ext.echo.base.js +++ b/modules/base/ext.echo.base.js @@ -1,4 +1,4 @@ -( function ( mw ) { +( function ( mw, $ ) { 'use strict'; mw.echo = { @@ -61,6 +61,13 @@ mw.loader.using( 'ext.eventLogging', function() { mw.eventLog.logEvent( 'EchoInteraction', myEvt ); } ); + }, + /** + * @method + * @return jQuery element corresponding to the badge reflecting the notification count + */ + getBadge: function() { + return $( '.mw-echo-notifications-badge' ); } }; @@ -74,4 +81,4 @@ } ); } ); } -} )( mediaWiki ); +} )( mediaWiki, jQuery ); diff --git a/modules/overlay/ext.echo.overlay.js b/modules/overlay/ext.echo.overlay.js index 8c34d950e..1aaf0a1d9 100644 --- a/modules/overlay/ext.echo.overlay.js +++ b/modules/overlay/ext.echo.overlay.js @@ -7,145 +7,56 @@ function EchoOverlay( apiResultNotifications ) { this.api = mw.echo.overlay.api; + // set internal properties + this.tabs = []; this._buildOverlay( apiResultNotifications ); } - EchoOverlay.prototype = { - /** - * @var array a list of unread notification ids that are visible in the UI - */ + function EchoOverlayTab( name, notifications ) { + this.api = mw.echo.overlay.api; + this.name = name; + this.unread = []; + this._buildList( notifications ); + } + + EchoOverlayTab.prototype = { unread: [], - /** - * @var object current count status of notification types - */ - notificationCount: { - /* @var integer length of all notifications (both unread and read) that will be visible in the overlay */ - all: 0, - /* @var string a string representation the current number of unread notifications (1, 99, 99+) */ - unread: '0', - /* @var integer the total number of all unread notifications including those not in the overlay */ - unreadRaw: 0 + getUnreadIds: function() { + return this.unread; }, /** - * @param newCount formatted count - * @param rawCount unformatted count + * Mark all unread notifications as read + * @method + * @return jQuery.Deferred */ - updateCount: function ( newCount, rawCount ) { - var $badge = $( '.mw-echo-notifications-badge' ); - $badge.text( newCount ); - - if ( rawCount !== '0' && rawCount !== 0 ) { - $badge.addClass( 'mw-echo-unread-notifications' ); + markAsRead: function() { + var self = this; + // only need to mark as read if there is unread item + if ( this.unread.length ) { + return this.api.post( mw.echo.desktop.appendUseLang( { + 'action' : 'echomarkread', + 'list' : this.unread.join( '|' ), + 'token': mw.user.tokens.get( 'editToken' ) + } ) ).then( function ( result ) { + return result.query.echomarkread[self.name]; + } ); } else { - $badge.removeClass( 'mw-echo-unread-notifications' ); + return new $.Deferred(); } - this.notificationCount.unread = newCount; - this.notificationCount.unreadRaw = rawCount; }, - - configuration: mw.config.get( 'wgEchoOverlayConfiguration' ), - - _getFooterElement: function() { - var $prefLink = $( '#pt-preferences a' ), - $overlayFooter = $( '
' ) - .attr( 'id', 'mw-echo-overlay-footer' ); - - // add link to notifications archive - $overlayFooter.append( - $( '' ) - .attr( 'id', 'mw-echo-overlay-link' ) - .addClass( 'mw-echo-grey-link' ) - .attr( 'href', getUrl( 'Special:Notifications' ) ) - .text( mw.msg( 'echo-overlay-link' ) ) - .click( function () { - mw.echo.logInteraction( 'ui-archive-link-click', 'flyout' ); - } ) - .hover( - function() { - $( this ).removeClass( 'mw-echo-grey-link' ); - }, - function() { - $( this ).addClass( 'mw-echo-grey-link' ); - } - ) - ); - - // add link to notification preferences - $overlayFooter.append( - $( '' ) - .html( $prefLink.html() ) - .attr( 'id', 'mw-echo-overlay-pref-link' ) - .addClass( 'mw-echo-grey-link' ) - .attr( 'href', $prefLink.attr( 'href' ) + '#mw-prefsection-echo' ) - .click( function () { - mw.echo.logInteraction( 'ui-prefs-click', 'flyout' ); - } ) - .hover( - function() { - $( this ).removeClass( 'mw-echo-grey-link' ); - }, - function() { - $( this ).addClass( 'mw-echo-grey-link' ); - } - ) - ); - return $overlayFooter; - }, - - _getTitleElement: function() { - var titleText, - counter = this.notificationCount, - notificationsCount = counter.all, - unreadRawTotalCount = counter.unreadRaw, - unreadTotalCount = counter.unread, - unreadCount = this.unread.length, - $title = $( '
' ).addClass( 'mw-echo-overlay-title' ); - - if ( notificationsCount > 0 ) { - if ( unreadRawTotalCount > unreadCount ) { - titleText = mw.msg( - 'echo-overlay-title-overflow', - mw.language.convertNumber( unreadCount ), - mw.language.convertNumber( unreadTotalCount ) - ); - } else { - titleText = mw.msg( 'echo-overlay-title' ); - } - } else { - titleText = mw.msg( 'echo-none' ); - } - - // Add the header to the title area - $( '
' ) - .attr( 'id', 'mw-echo-overlay-title-text' ) - .html( titleText ) - .appendTo( $title ); - - // Add help button - $( '' ) - .attr( 'href', mw.config.get( 'wgEchoHelpPage' ) ) - .attr( 'title', mw.msg( 'echo-more-info' ) ) - .attr( 'id', 'mw-echo-overlay-moreinfo-link' ) - .attr( 'target', '_blank' ) - .click( function () { - mw.echo.logInteraction( 'ui-help-click', 'flyout' ); - } ) - .appendTo( $title ); - return $title; - }, - /** * Builds an Echo notifications list * @method - * @param object as returned by the api of notification items + * @param string tabName the tab + * @param object notifications as returned by the api of notification items * @return jQuery element */ - _buildNotificationList: function( notifications ) { + _buildList: function( notifications ) { var self = this, $ul = $( '