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
This commit is contained in:
Moriel Schottlender 2016-09-12 16:30:39 -07:00
parent 5e8377b2f6
commit fcc2e1ddfc
2 changed files with 15 additions and 25 deletions

View file

@ -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' ]
} );

View file

@ -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
*