From fcc2e1ddfc152069704e664da9d60ef3259eba09 Mon Sep 17 00:00:00 2001 From: Moriel Schottlender Date: Mon, 12 Sep 2016 16:30:39 -0700 Subject: [PATCH] Allow for count cap display in Special:Notifications sidebar Some of the counts are capped (wiki counts) and some are not (page counts) - so we are adding a config option ('isCapped') to the widget to make sure that capped numbers appear with the proper i18n message ('99+' in English) and non-capped numbers appear as-is. Bug: T144707 Change-Id: I7332e7f5108621d0bd403edefe4feacca44b1f88 --- modules/ui/mw.echo.ui.PageFilterWidget.js | 15 +++-------- ...w.echo.ui.PageNotificationsOptionWidget.js | 25 +++++++++---------- 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/modules/ui/mw.echo.ui.PageFilterWidget.js b/modules/ui/mw.echo.ui.PageFilterWidget.js index b7eff73fc..f3dcd90a9 100644 --- a/modules/ui/mw.echo.ui.PageFilterWidget.js +++ b/modules/ui/mw.echo.ui.PageFilterWidget.js @@ -34,7 +34,8 @@ this.title = new mw.echo.ui.PageNotificationsOptionWidget( { label: config.title, title: config.title, - unreadCount: this.totalCount, + count: this.totalCount, + isCapped: true, data: null, classes: [ 'mw-echo-ui-pageFilterWidget-title' ] } ); @@ -49,16 +50,6 @@ OO.inheritClass( mw.echo.ui.PageFilterWidget, OO.ui.SelectWidget ); - /** - * Set the total count of this group - * - * @param {number} count Total count - */ - mw.echo.ui.PageFilterWidget.prototype.setTotalCount = function ( count ) { - this.totalCount = count; - this.title.setCount( this.totalCount ); - }; - /** * Set the total count of this group * @@ -82,7 +73,7 @@ label: isUserPage ? sourcePages[ title ].unprefixed : title, title: isUserPage ? sourcePages[ title ].unprefixed : title, icon: isUserPage ? 'userAvatar' : 'article', - unreadCount: sourcePages[ title ].count, + count: sourcePages[ title ].count, data: title, classes: [ 'mw-echo-ui-pageFilterWidget-page' ] } ); diff --git a/modules/ui/mw.echo.ui.PageNotificationsOptionWidget.js b/modules/ui/mw.echo.ui.PageNotificationsOptionWidget.js index 3cc4967cd..60fc61e27 100644 --- a/modules/ui/mw.echo.ui.PageNotificationsOptionWidget.js +++ b/modules/ui/mw.echo.ui.PageNotificationsOptionWidget.js @@ -9,9 +9,12 @@ * * @constructor * @param {Object} [config] Configuration object - * @cfg {number} [unreadCount] Number of unread notifications + * @cfg {number} [count] Number of unread notifications + * @cfg {boolean} [isCapped] The count for this widget is capped */ mw.echo.ui.PageNotificationsOptionWidget = function MwEchoUiPageNotificationsOptionWidget( config ) { + var countLabel; + config = config || {}; // Parent @@ -23,10 +26,16 @@ this.$label .addClass( 'mw-echo-ui-pageNotificationsOptionWidget-title-label' ); + this.count = config.count !== undefined ? config.count : 0; + + countLabel = mw.language.convertNumber( this.count ); + countLabel = config.isCapped ? + mw.msg( 'echo-badge-count', countLabel ) : countLabel; + this.unreadCountLabel = new OO.ui.LabelWidget( { - classes: [ 'mw-echo-ui-pageNotificationsOptionWidget-label-count' ] + classes: [ 'mw-echo-ui-pageNotificationsOptionWidget-label-count' ], + label: countLabel } ); - this.setCount( config.unreadCount || 0 ); // Initialization this.$element @@ -55,16 +64,6 @@ OO.mixinClass( mw.echo.ui.PageNotificationsOptionWidget, OO.ui.mixin.IconElement ); OO.mixinClass( mw.echo.ui.PageNotificationsOptionWidget, OO.ui.mixin.TitledElement ); - /** - * Set the page count - * - * @param {number} count Page count - */ - mw.echo.ui.PageNotificationsOptionWidget.prototype.setCount = function ( count ) { - this.count = count; - this.unreadCountLabel.setLabel( mw.language.convertNumber( this.count ) ); - }; - /** * Get the page count *