mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-30 18:45:07 +00:00
ApiUnreadNotificationPages: Output pages as an array rather than an object
Make the frontend code based on page titles rather than page IDs. Change-Id: I79c6a0e3a7178acdb14039a0c5208e90a7341044
This commit is contained in:
parent
e4b79c1bc2
commit
6c4bf99da8
|
@ -39,8 +39,7 @@ class ApiEchoUnreadNotificationPages extends ApiCrossWikiBase {
|
|||
$apis = $this->foreignNotifications->getApiEndpoints( $this->getRequestedWikis() );
|
||||
foreach ( $result as $wiki => $data ) {
|
||||
$result[$wiki]['source'] = $apis[$wiki];
|
||||
// StdClass to ensure empty data is json_encoded to `{}` instead of `[]`
|
||||
$result[$wiki]['pages'] = $data['pages'] ?: new StdClass;
|
||||
$result[$wiki]['pages'] = $data['pages'] ?: array();
|
||||
}
|
||||
|
||||
$this->getResult()->addValue( 'query', $this->getModuleName(), $result );
|
||||
|
@ -82,7 +81,7 @@ class ApiEchoUnreadNotificationPages extends ApiCrossWikiBase {
|
|||
$result = array();
|
||||
$titles = Title::newFromIDs( array_keys( $pages ) );
|
||||
foreach ( $titles as $title ) {
|
||||
$result[$title->getArticleID()] = array(
|
||||
$result[] = array(
|
||||
'title' => $title->getPrefixedText(),
|
||||
'count' => $pages[$title->getArticleID()],
|
||||
);
|
||||
|
|
|
@ -131,7 +131,7 @@
|
|||
{
|
||||
continue: continueValue,
|
||||
readState: filters.getReadState(),
|
||||
titles: filters.getSourcePagesModel().getCurrentPageTitle()
|
||||
titles: filters.getSourcePagesModel().getCurrentPage()
|
||||
}
|
||||
)
|
||||
.then( function ( data ) {
|
||||
|
|
|
@ -63,34 +63,13 @@
|
|||
return this.currentSource;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the current page or pages' id.
|
||||
* Returns null if no page is selected.
|
||||
*
|
||||
* @return {number|number[]} Current page id
|
||||
*/
|
||||
mw.echo.dm.SourcePagesModel.prototype.getCurrentPage = function () {
|
||||
return this.currentPage;
|
||||
};
|
||||
/**
|
||||
* Get the current source
|
||||
*
|
||||
* @return {string} Current source
|
||||
*/
|
||||
mw.echo.dm.SourcePagesModel.prototype.getCurrentSource = function () {
|
||||
return this.currentSource;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the title of the currently selected page
|
||||
*
|
||||
* @return {string} Page title
|
||||
*/
|
||||
mw.echo.dm.SourcePagesModel.prototype.getCurrentPageTitle = function () {
|
||||
return this.getPageTitle(
|
||||
this.getCurrentSource(),
|
||||
this.getCurrentPage()
|
||||
);
|
||||
mw.echo.dm.SourcePagesModel.prototype.getCurrentPage = function () {
|
||||
return this.currentPage;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -144,36 +123,12 @@
|
|||
* Get all pages in a source
|
||||
*
|
||||
* @param {string} source Symbolic name of the source
|
||||
* @return {Object} Page definitions in this source
|
||||
* @return {Object[]} Page definitions in this source
|
||||
*/
|
||||
mw.echo.dm.SourcePagesModel.prototype.getSourcePages = function ( source ) {
|
||||
return this.sources[ source ] && this.sources[ source ].pages;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get a specific page's title
|
||||
*
|
||||
* @param {string} source Symbolic name for source
|
||||
* @param {number} pageId Page ID
|
||||
* @return {string} Page title
|
||||
*/
|
||||
mw.echo.dm.SourcePagesModel.prototype.getPageTitle = function ( source, pageId ) {
|
||||
return this.getPageTitleById( source, pageId );
|
||||
};
|
||||
|
||||
/**
|
||||
* Get page title by the source and page ID
|
||||
*
|
||||
* @param {string} source Symbolic name of the source
|
||||
* @param {number} pageId Page ID
|
||||
* @return {string} Page title
|
||||
*/
|
||||
mw.echo.dm.SourcePagesModel.prototype.getPageTitleById = function ( source, pageId ) {
|
||||
return this.sources[ source ] &&
|
||||
this.sources[ source ].pages[ pageId ] &&
|
||||
this.sources[ source ].pages[ pageId ].title;
|
||||
};
|
||||
|
||||
/**
|
||||
* Reset the data
|
||||
*/
|
||||
|
@ -189,24 +144,11 @@
|
|||
* @param {Object} details Details object
|
||||
*/
|
||||
mw.echo.dm.SourcePagesModel.prototype.setSourcePagesDetails = function ( source, details ) {
|
||||
var id, pageDetails;
|
||||
|
||||
// Source information
|
||||
this.sources[ source ] = {
|
||||
title: details.source.title,
|
||||
base: details.source.base,
|
||||
totalCount: details.totalCount,
|
||||
pages: {}
|
||||
pages: details.pages
|
||||
};
|
||||
|
||||
// Fill in pages
|
||||
for ( id in details.pages ) {
|
||||
pageDetails = details.pages[ id ];
|
||||
this.sources[ source ].pages[ id ] = {
|
||||
title: pageDetails.title,
|
||||
count: pageDetails.count,
|
||||
id: id
|
||||
};
|
||||
}
|
||||
};
|
||||
} )( mediaWiki );
|
||||
|
|
|
@ -102,12 +102,12 @@
|
|||
*/
|
||||
mw.echo.ui.CrossWikiUnreadFilterWidget.prototype.onPageFilterChoose = function ( widget, item ) {
|
||||
var source = widget.getSource(),
|
||||
pageId = item && item.getData();
|
||||
page = item && item.getData();
|
||||
|
||||
if ( item ) {
|
||||
this.setItemSelected( item );
|
||||
// Emit a choice
|
||||
this.emit( 'filter', source, pageId );
|
||||
this.emit( 'filter', source, page );
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -158,10 +158,10 @@
|
|||
* Respond to unread page filter
|
||||
*
|
||||
* @param {string} source Source symbolic name
|
||||
* @param {number} pageId Page Id
|
||||
* @param {string} page Page name
|
||||
*/
|
||||
mw.echo.ui.NotificationsInboxWidget.prototype.onSourcePageFilter = function ( source, pageId ) {
|
||||
this.controller.setFilter( 'sourcePage', source, pageId );
|
||||
mw.echo.ui.NotificationsInboxWidget.prototype.onSourcePageFilter = function ( source, page ) {
|
||||
this.controller.setFilter( 'sourcePage', source, page );
|
||||
this.populateNotifications();
|
||||
};
|
||||
|
||||
|
|
|
@ -71,24 +71,23 @@
|
|||
* Populate the widget from the model
|
||||
*/
|
||||
mw.echo.ui.PageFilterWidget.prototype.populateDataFromModel = function () {
|
||||
var id, title, widget,
|
||||
var i, title, widget,
|
||||
optionWidgets = [],
|
||||
sourcePages = this.model.getSourcePages( this.source );
|
||||
|
||||
for ( id in sourcePages ) {
|
||||
title = this.model.getPageTitle( this.source, id );
|
||||
if ( !title ) {
|
||||
continue;
|
||||
if ( !sourcePages ) {
|
||||
return;
|
||||
}
|
||||
for ( i = 0; i < sourcePages.length; i++ ) {
|
||||
widget = new mw.echo.ui.PageNotificationsOptionWidget( {
|
||||
label: title,
|
||||
label: sourcePages[ i ].title,
|
||||
// TODO: Pages that are a user page should
|
||||
// have a user icon
|
||||
icon: 'article',
|
||||
unreadCount: sourcePages[ id ].count,
|
||||
unreadCount: sourcePages[ i ].count,
|
||||
// TODO: When we group pages, this should be
|
||||
// an array of IDs
|
||||
data: id,
|
||||
// an array of titles
|
||||
data: sourcePages[ i ].title,
|
||||
classes: [ 'mw-echo-ui-pageFilterWidget-page' ]
|
||||
} );
|
||||
optionWidgets.push( widget );
|
||||
|
|
Loading…
Reference in a new issue