jenkins-bot has submitted this change and it was merged.
Change subject: Hygiene: Rewrite apis to gateways
......................................................................
Hygiene: Rewrite apis to gateways
* Remove dependency on Api module, switch to mw.Api (one less thing to
depend on in MobileFrontend)
* Creation of an instance of mw.Api should only be in init
- this allows us to make use of caching across the feature at a later basis
* Add documentation to defaults (previously missing) - currently incomplete
Bug: T115146
Change-Id: Icaf2d24c2764658fa775600965529f1a609262b6
---
M extension.json
M includes/Gather.hooks.php
R resources/ext.gather.api/CollectionsGateway.js
R resources/ext.gather.api/RelatedPagesGateway.js
M resources/ext.gather.collection.contentOverlay/CollectionsContentOverlay.js
M resources/ext.gather.collection.delete/CollectionDeleteOverlay.js
M resources/ext.gather.collection.editor/CollectionEditOverlay.js
M resources/ext.gather.collection.flag/CollectionFlagButton.js
M resources/ext.gather.collections.list/CollectionsList.js
M resources/ext.gather.init/init.js
M resources/ext.gather.moderation/init.js
M resources/ext.gather.page.search/CollectionPageList.js
M resources/ext.gather.page.search/CollectionSearchPanel.js
M resources/ext.gather.relatedpages/RelatedPages.js
M resources/ext.gather.routes/routes.js
M resources/ext.gather.special.collection/init.js
M resources/ext.gather.special.usercollections/init.js
M resources/ext.gather.watchstar/CollectionsWatchstar.js
R tests/qunit/ext.gather.api/test_RelatedPagesGateway.js
M
tests/qunit/ext.gather.collection.contentOverlay/test_CollectionsContentOverlay.js
M tests/qunit/ext.gather.collection.editor/test_CollectionEditOverlay.js
21 files changed, 135 insertions(+), 90 deletions(-)
Approvals:
Jhernandez: Looks good to me, approved
jenkins-bot: Verified
diff --git a/extension.json b/extension.json
index 3d9ad2f..c00a8f3 100644
--- a/extension.json
+++ b/extension.json
@@ -184,8 +184,8 @@
"mobile.startup"
],
"scripts": [
- "resources/ext.gather.api/CollectionsApi.js",
- "resources/ext.gather.api/RelatedPagesApi.js"
+
"resources/ext.gather.api/CollectionsGateway.js",
+
"resources/ext.gather.api/RelatedPagesGateway.js"
]
},
"ext.gather.collections.list": {
diff --git a/includes/Gather.hooks.php b/includes/Gather.hooks.php
index e5e3f3f..f37cf9d 100644
--- a/includes/Gather.hooks.php
+++ b/includes/Gather.hooks.php
@@ -285,7 +285,7 @@
$modules['qunit']['ext.gather.api.tests'] = $boilerplate +
array(
'scripts' => array(
- 'ext.gather.api/test_RelatedPagesApi.js',
+ 'ext.gather.api/test_RelatedPagesGateway.js',
),
'dependencies' => array( 'ext.gather.api' ),
);
diff --git a/resources/ext.gather.api/CollectionsApi.js
b/resources/ext.gather.api/CollectionsGateway.js
similarity index 88%
rename from resources/ext.gather.api/CollectionsApi.js
rename to resources/ext.gather.api/CollectionsGateway.js
index 9b304e9..5c9af6f 100644
--- a/resources/ext.gather.api/CollectionsApi.js
+++ b/resources/ext.gather.api/CollectionsGateway.js
@@ -1,19 +1,22 @@
/*jshint unused:vars */
( function ( M, $ ) {
- var Api = M.require( 'mobile.startup/api' ).Api,
- user = M.require( 'mobile.user/user' ),
- Page = M.require( 'mobile.startup/Page' ),
- CollectionsApi;
+ var user = M.require( 'mobile.user/user' ),
+ Page = M.require( 'mobile.startup/Page' );
/**
* API for managing collection items
*
- * @class CollectionApi
+ * @class CollectionGateway
* @extends Api
* @uses Page
+ * @param {mw.Api} api
*/
- CollectionsApi = Api.extend( {
+ function CollectionsGateway( api ) {
+ this.api = api;
+ }
+
+ CollectionsGateway.prototype = {
boilerplate: {
id: 0,
title: 'Watchlist',
@@ -32,7 +35,7 @@
* @return {jQuery.Deferred}
*/
addPagesToCollection: function ( id, titles ) {
- return this.postWithToken( 'watch', {
+ return this.api.postWithToken( 'watch', {
action: 'editlist',
id: id,
titles: titles
@@ -56,7 +59,7 @@
* @return {jQuery.Deferred}
*/
removePagesFromCollection: function ( id, titles ) {
- return this.postWithToken( 'watch', {
+ return this.api.postWithToken( 'watch', {
action: 'editlist',
id: id,
mode: 'remove',
@@ -80,7 +83,7 @@
*/
addCollection: function ( title ) {
var self = this;
- return this.postWithToken( 'watch', {
+ return this.api.postWithToken( 'watch', {
action: 'editlist',
perm: 'public',
label: title
@@ -103,7 +106,7 @@
* @param {Number} id unique identifier of collection
*/
removeCollection: function ( id ) {
- return this.postWithToken( 'watch', {
+ return this.api.postWithToken( 'watch', {
action: 'editlist',
mode: 'deletelist',
id: id
@@ -126,7 +129,7 @@
glsplimit: 50
};
- return this.get( params ).then( function ( resp ) {
+ return this.api.get( params ).then( function ( resp ) {
// Workaround for
https://phabricator.wikimedia.org/T95741
if ( !resp.query ) {
return [];
@@ -170,7 +173,7 @@
lstprop:
'label|description|public|image|count|owner'
};
- return this.get( args ).then( function ( resp ) {
+ return this.api.get( args ).then( function ( resp ) {
if ( resp.query && resp.query.lists &&
resp.query.lists[0] ) {
collection = self._mapCollection(
resp.query.lists[0] );
}
@@ -194,7 +197,7 @@
if ( page ) {
args.lsttitle = page.getTitle();
}
- return this.get( args ).then( function ( resp ) {
+ return this.api.get( args ).then( function ( resp ) {
var result = {
continueArgs: resp.continue ||
resp['query-continue']
};
@@ -239,7 +242,7 @@
if ( id !== null ) {
params.id = id;
}
- return this.postWithToken( 'watch', params );
+ return this.api.postWithToken( 'watch', params );
},
/**
* Set collection privacy
@@ -249,7 +252,7 @@
* @return {jQuery.Deferred}
*/
setPrivate: function ( id, isPrivate ) {
- return this.postWithToken( 'watch', {
+ return this.api.postWithToken( 'watch', {
action: 'editlist',
id: id,
perm: isPrivate ? 'private' : 'public'
@@ -263,14 +266,13 @@
* @return {jQuery.Deferred}
*/
setVisible: function ( id, isVisible ) {
- return this.postWithToken( 'watch', {
+ return this.api.postWithToken( 'watch', {
action: 'editlist',
id: id,
mode: isVisible ? 'showlist' : 'hidelist'
} );
}
- } );
+ };
- M.define( 'ext.gather.api/CollectionsApi', CollectionsApi );
-
+ M.define( 'ext.gather.api/CollectionsGateway', CollectionsGateway );
}( mw.mobileFrontend, jQuery ) );
diff --git a/resources/ext.gather.api/RelatedPagesApi.js
b/resources/ext.gather.api/RelatedPagesGateway.js
similarity index 78%
rename from resources/ext.gather.api/RelatedPagesApi.js
rename to resources/ext.gather.api/RelatedPagesGateway.js
index 1e7ac17..8abc98e 100644
--- a/resources/ext.gather.api/RelatedPagesApi.js
+++ b/resources/ext.gather.api/RelatedPagesGateway.js
@@ -1,15 +1,17 @@
( function ( M, $ ) {
- var Api = M.require( 'mobile.startup/api' ).Api,
- RelatedPagesApi;
-
/**
* API for managing collection items
*
- * @class RelatedPagesApi
+ * @class RelatedPagesGateway
* @extends Api
+ * @param {mw.Api} api
*/
- RelatedPagesApi = Api.extend( {
+ function RelatedPagesGateway( api ) {
+ this.api = api;
+ }
+
+ RelatedPagesGateway.prototype = {
/**
* @method
* @param {String} title Title of the page to find related
pages of.
@@ -19,7 +21,7 @@
getRelatedPages: function ( title, limit ) {
limit = limit || 3;
- return this.get( {
+ return this.api.get( {
action: 'query',
prop: 'pageimages',
piprop: 'thumbnail',
@@ -31,7 +33,7 @@
gsrlimit: limit
} ).then( cleanApiResults );
}
- } );
+ };
/**
* Clean api results by extracting query.pages into an array
@@ -47,6 +49,6 @@
}
}
- M.define( 'ext.gather.api/RelatedPagesApi', RelatedPagesApi );
+ M.define( 'ext.gather.api/RelatedPagesGateway', RelatedPagesGateway,
'ext.gather.api/RelatedPagesApi' );
}( mw.mobileFrontend, jQuery ) );
diff --git
a/resources/ext.gather.collection.contentOverlay/CollectionsContentOverlay.js
b/resources/ext.gather.collection.contentOverlay/CollectionsContentOverlay.js
index 6aa9767..2638106 100644
---
a/resources/ext.gather.collection.contentOverlay/CollectionsContentOverlay.js
+++
b/resources/ext.gather.collection.contentOverlay/CollectionsContentOverlay.js
@@ -9,7 +9,6 @@
Button = M.require( 'mobile.startup/Button' ),
ToastPanel = M.require( 'ext.gather.toastpanel/ToastPanel' ),
toastPanel = new ToastPanel().appendTo( document.body ),
- CollectionsApi = M.require( 'ext.gather.api/CollectionsApi' ),
CollectionsContentOverlayBase = M.require(
'ext.gather.collection.base/CollectionsContentOverlayBase' ),
ButtonWithSpinner = M.require(
'ext.gather.buttonspinner/ButtonWithSpinner' );
@@ -47,9 +46,10 @@
onExit: function () {
this.hide();
},
- /** @inheritdoc */
- hasFixedHeader: false,
- /** @inheritdoc */
+ /**
+ * @inheritdoc
+ * @cfg {CollectionsGateway} defaults.gateway
+ */
defaults: $.extend( {},
CollectionsContentOverlayBase.prototype.defaults, {
page: undefined,
/** @inheritdoc */
@@ -82,7 +82,7 @@
} ),
/** @inheritdoc */
initialize: function ( options ) {
- this.api = new CollectionsApi();
+ this.gateway = options.gateway;
this.createButton = new ButtonWithSpinner( {
label: this.defaults.createButtonLabel,
additionalClassNames: 'create-collection',
@@ -159,7 +159,7 @@
_loadCollections: function ( username, page, qs ) {
var self = this;
- return this.api.getCurrentUsersCollections( username,
page, qs ).done(
+ return this.gateway.getCurrentUsersCollections(
username, page, qs ).done(
function ( resp ) {
var reset,
s = self._scrollTop || 0,
@@ -343,7 +343,7 @@
*/
removeFromCollection: function ( collection, page ) {
var self = this;
- return this.api.removePageFromCollection(
collection.id, page ).done( function () {
+ return this.gateway.removePageFromCollection(
collection.id, page ).done( function () {
self._collectionStateChange( collection, false
);
self._notifyChanges( collection, false );
} ).fail( function ( errMsg ) {
@@ -362,7 +362,7 @@
*/
addToCollection: function ( collection, page ) {
var self = this;
- return this.api.addPageToCollection( collection.id,
page ).done( function () {
+ return this.gateway.addPageToCollection( collection.id,
page ).done( function () {
self._collectionStateChange( collection, true );
self._notifyChanges( collection, true );
} ).fail( function () {
@@ -391,12 +391,12 @@
*/
addCollection: function ( title, page ) {
var self = this,
- api = this.api;
+ gateway = this.gateway;
this.createButton.loading( true );
this.expandForm();
- return api.addCollection( title ).done( function (
collection ) {
- api.addPageToCollection( collection.id, page
).done( function () {
+ return gateway.addCollection( title ).done( function (
collection ) {
+ gateway.addPageToCollection( collection.id,
page ).done( function () {
self._collectionStateChange(
collection, true );
M.once( 'collection-edit-completed',
function ( newCollection ) {
collection = $.extend(
collection, newCollection );
diff --git a/resources/ext.gather.collection.delete/CollectionDeleteOverlay.js
b/resources/ext.gather.collection.delete/CollectionDeleteOverlay.js
index 4bd0aa3..3cd84a9 100644
--- a/resources/ext.gather.collection.delete/CollectionDeleteOverlay.js
+++ b/resources/ext.gather.collection.delete/CollectionDeleteOverlay.js
@@ -4,7 +4,7 @@
SchemaGather = M.require( 'ext.gather.logging/SchemaGather' ),
schema = new SchemaGather(),
toast = M.require( 'mobile.toast/toast' ),
- CollectionsApi = M.require( 'ext.gather.api/CollectionsApi' ),
+ CollectionsGateway = M.require(
'ext.gather.api/CollectionsGateway' ),
ConfirmationOverlay = M.require(
'ext.gather.collection.confirm/ConfirmationOverlay' );
/**
@@ -13,7 +13,11 @@
* @class CollectionDeleteOverlay
*/
CollectionDeleteOverlay = ConfirmationOverlay.extend( {
- /** @inheritdoc */
+ /**
+ * @inheritdoc
+ * @cfg {Object} defaults Default options hash.
+ * @cfg {mw.Api} defaults.api
+ */
defaults: $.extend( {}, ConfirmationOverlay.prototype.defaults,
{
deleteSuccessMsg: mw.msg(
'gather-delete-collection-success' ),
deleteFailedError: mw.msg(
'gather-delete-collection-failed-error' ),
@@ -28,8 +32,8 @@
'click .confirm': 'onDeleteClick'
},
/** @inheritdoc */
- initialize: function () {
- this.api = new CollectionsApi();
+ initialize: function ( options ) {
+ this.gateway = new CollectionsGateway( options.api );
ConfirmationOverlay.prototype.initialize.apply( this,
arguments );
},
/**
@@ -40,7 +44,7 @@
this.showSpinner();
// disable button and inputs
this.$( '.confirm, .cancel' ).prop( 'disabled', true );
- this.api.removeCollection( this.id ).done( function () {
+ this.gateway.removeCollection( this.id ).done( function
() {
schema.log( {
eventName: 'delete-collection'
} ).always( function () {
diff --git a/resources/ext.gather.collection.editor/CollectionEditOverlay.js
b/resources/ext.gather.collection.editor/CollectionEditOverlay.js
index 54ca225..5c5fd58 100644
--- a/resources/ext.gather.collection.editor/CollectionEditOverlay.js
+++ b/resources/ext.gather.collection.editor/CollectionEditOverlay.js
@@ -2,7 +2,7 @@
var CollectionEditOverlay,
toast = M.require( 'mobile.toast/toast' ),
- CollectionsApi = M.require( 'ext.gather.api/CollectionsApi' ),
+ CollectionsGateway = M.require(
'ext.gather.api/CollectionsGateway' ),
CollectionSearchPanel = M.require(
'ext.gather.page.search/CollectionSearchPanel' ),
Overlay = M.require( 'mobile.overlays/Overlay' ),
Icon = M.require( 'mobile.startup/Icon' ),
@@ -39,6 +39,7 @@
/**
* @inheritdoc
* @cfg {Object} defaults Default options hash.
+ * @cfg {mw.Api} defaults.api
* @cfg {Skin} defaults.skin the skin the overlay is operating
in
*/
defaults: $.extend( {}, Overlay.prototype.defaults, {
@@ -126,7 +127,8 @@
};
}
this.activePane = 'main';
- this.api = new CollectionsApi();
+ this.api = options.api;
+ this.gateway = new CollectionsGateway( this.api );
Overlay.prototype.initialize.apply( this, arguments );
this.$clear = this.$( '.search-header .clear' );
},
@@ -163,8 +165,9 @@
var self = this;
this.$( '.manage-members-pane' ).removeClass( 'hidden'
);
- this.api.getCollectionMembers( this.id ).done( function
( pages ) {
+ this.gateway.getCollectionMembers( this.id ).done(
function ( pages ) {
self.searchPanel = new CollectionSearchPanel( {
+ api: new mw.Api(),
collection: self.options.collection,
pages: pages,
el: self.$( '.panel' )
@@ -186,6 +189,7 @@
// If there is 1 to 3 elements set up related
results
if ( pages.length > 0 && pages.length < 4 ) {
self.relatedPanel = new RelatedPages( {
+ api: self.api,
title: $.map( pages, function (
p ) {
return p.title;
} ).join( '|' ),
@@ -304,6 +308,7 @@
*/
onDeleteActionClick: function () {
var deleteOverlay = new CollectionDeleteOverlay( {
+ api: this.api,
collection: this.options.collection
} );
deleteOverlay.show();
@@ -395,7 +400,7 @@
// disable button and inputs
this.showSpinner();
this.$( '.mw-ui-input, .save-description'
).prop( 'disabled', true );
- this.api.editCollection( this.id, title,
description, isPrivate ).done( function ( data ) {
+ this.gateway.editCollection( this.id, title,
description, isPrivate ).done( function ( data ) {
var eventParams = {
eventName: 'edit-collection'
};
diff --git a/resources/ext.gather.collection.flag/CollectionFlagButton.js
b/resources/ext.gather.collection.flag/CollectionFlagButton.js
index f2ee7a2..50cbbac 100644
--- a/resources/ext.gather.collection.flag/CollectionFlagButton.js
+++ b/resources/ext.gather.collection.flag/CollectionFlagButton.js
@@ -1,10 +1,9 @@
( function ( M ) {
- var CollectionsApi = M.require( 'ext.gather.api/CollectionsApi' ),
+ var CollectionsGateway = M.require( 'ext.gather.api/CollectionsGateway'
),
CollectionFlagOverlay = M.require(
'ext.gather.collection.flag/CollectionFlagOverlay' ),
Button = M.require( 'mobile.startup/Button' ),
Icon = M.require( 'mobile.startup/Icon' ),
- api = new CollectionsApi(),
CollectionFlagButton;
/**
@@ -13,7 +12,11 @@
* @extends Button
*/
CollectionFlagButton = Button.extend( {
- /** @inheritdoc */
+ /**
+ * @inheritdoc
+ * @cfg {Object} defaults Default options hash.
+ * @cfg {mw.Api} defaults.api
+ */
defaults: {
tagName: 'div',
additionalClassNames: new Icon( {
@@ -36,6 +39,7 @@
*/
onCollectionFlagButtonClick: function ( ev ) {
var flagOverlay,
+ gateway = new CollectionsGateway(
this.options.api ),
$flag = this.$el;
ev.stopPropagation();
ev.preventDefault();
@@ -43,7 +47,7 @@
if ( !$flag.hasClass( 'disabled' ) ) {
// Prevent multiple clicks
$flag.addClass( 'disabled' );
- api.getCollection( this.options.collectionId
).done( function ( collection ) {
+ gateway.getCollection(
this.options.collectionId ).done( function ( collection ) {
flagOverlay = new
CollectionFlagOverlay( {
collection: collection
} );
diff --git a/resources/ext.gather.collections.list/CollectionsList.js
b/resources/ext.gather.collections.list/CollectionsList.js
index 31db978..c26fca4 100644
--- a/resources/ext.gather.collections.list/CollectionsList.js
+++ b/resources/ext.gather.collections.list/CollectionsList.js
@@ -3,7 +3,7 @@
var CollectionsList,
InfiniteScroll = M.require(
'mobile.infiniteScroll/InfiniteScroll' ),
icons = M.require( 'mobile.startup/icons' ),
- CollectionsApi = M.require( 'ext.gather.api/CollectionsApi' ),
+ CollectionsGateway = M.require(
'ext.gather.api/CollectionsGateway' ),
toast = M.require( 'mobile.toast/toast' ),
View = M.require( 'mobile.view/View' ),
Icon = M.require( 'mobile.startup/Icon' ),
@@ -14,6 +14,8 @@
* @inheritdoc
* @cfg {Object} defaults Default options hash.
* @cfg {Skin} defaults.skin the skin the overlay is operating
in
+ * @cfg {mw.Api} defaults.api
+ * @cfg {String} defaults.userIconClass user profile icon
*/
defaults: {
skin: M.require( 'skins.minerva.scripts/skin' ),
@@ -30,13 +32,13 @@
image: mw.template.get( 'ext.gather.collections.list',
'CardImage.hogan' )
},
/** @inheritdoc */
- initialize: function () {
+ initialize: function ( options ) {
View.prototype.initialize.apply( this, arguments );
// After the initial render initialize the infinite
scrolling.
this.$pagination = this.$el.find(
'.collections-pagination' );
if ( this.$pagination.length ) {
this._replacePaginationControls();
- this.api = new CollectionsApi();
+ this.gateway = new CollectionsGateway(
options.api );
this.infiniteScroll = new InfiniteScroll();
this.infiniteScroll.setElement( this.$el );
this.infiniteScroll.on( 'load', $.proxy( this,
'_loadCollections' ) );
@@ -110,12 +112,12 @@
*/
_apiCallByMode: function () {
if ( this.options.mode === 'recent' ) {
- return this.api.getCollections( null, $.extend(
this.continueArgs, {
+ return this.gateway.getCollections( null,
$.extend( this.continueArgs, {
lstminitems: 4,
lstmode: 'allpublic'
} ) );
} else {
- return this.api.getCurrentUsersCollections(
this.options.owner, null, this.continueArgs );
+ return this.gateway.getCurrentUsersCollections(
this.options.owner, null, this.continueArgs );
}
},
/**
diff --git a/resources/ext.gather.init/init.js
b/resources/ext.gather.init/init.js
index d222cf9..b393d50 100644
--- a/resources/ext.gather.init/init.js
+++ b/resources/ext.gather.init/init.js
@@ -3,6 +3,7 @@
var $star, watchstar, pageActionPointer, actionOverlay,
bucket, useGatherStar,
+ CollectionsGateway = M.require(
'ext.gather.api/CollectionsGateway' ),
sampleRate = mw.config.get( 'wgGatherEnableSample' ),
CollectionsWatchstar = M.require(
'ext.gather.watchstar/CollectionsWatchstar' ),
Watchstar = M.require( 'mobile.watchstar/Watchstar' ),
@@ -128,6 +129,7 @@
$menuItem = revealCollectionsInMainMenu();
watchstar = new CollectionsWatchstar( {
+ gateway: new CollectionsGateway( new mw.Api() ),
page: page,
isAnon: user.isAnon(),
isWatched: $star.hasClass( 'watched' ),
diff --git a/resources/ext.gather.moderation/init.js
b/resources/ext.gather.moderation/init.js
index b4d969a..7936a14 100644
--- a/resources/ext.gather.moderation/init.js
+++ b/resources/ext.gather.moderation/init.js
@@ -1,8 +1,8 @@
( function ( M, $ ) {
- var CollectionsApi = M.require( 'ext.gather.api/CollectionsApi' ),
+ var CollectionsGateway = M.require( 'ext.gather.api/CollectionsGateway'
),
toast = M.require( 'mobile.toast/toast' ),
Icon = M.require( 'mobile.startup/Icon' ),
- api = new CollectionsApi();
+ gateway = new CollectionsGateway( new mw.Api() );
/**
* Initialize the moderation buttons
@@ -41,7 +41,7 @@
key = 'gather-lists-' + data.action + '-collection';
if ( window.confirm( mw.msg( key, data.label, data.owner ) ) ) {
- api.setVisible( data.id, data.action === 'show' ).done(
function () {
+ gateway.setVisible( data.id, data.action === 'show'
).done( function () {
$button.closest( 'li' ).remove();
key = 'gather-lists-' + data.action +
'-success-toast';
toast.show( mw.msg( key, data.label ), 'toast'
);
diff --git a/resources/ext.gather.page.search/CollectionPageList.js
b/resources/ext.gather.page.search/CollectionPageList.js
index 721910f..fd11838 100644
--- a/resources/ext.gather.page.search/CollectionPageList.js
+++ b/resources/ext.gather.page.search/CollectionPageList.js
@@ -2,7 +2,6 @@
var PageList = M.require( 'mobile.pagelist/PageList' ),
Page = M.require( 'mobile.startup/Page' ),
- CollectionsApi = M.require( 'ext.gather.api/CollectionsApi' ),
Icon = M.require( 'mobile.startup/Icon' ),
CollectionPageList;
@@ -17,6 +16,7 @@
CollectionPageList = PageList.extend( {
/**
* @inheritdoc
+ * @cfg {CollectionsGateway} defaults.collectionGateway
*/
defaults: {
pages: undefined,
@@ -41,11 +41,11 @@
item: mw.template.get( 'ext.gather.page.search',
'item.hogan' )
},
/** @inheritdoc */
- initialize: function () {
+ initialize: function ( options ) {
this._removals = [];
this._additions = [];
PageList.prototype.initialize.apply( this, arguments );
- this.api = new CollectionsApi();
+ this.collectionsGateway = options.collectionsGateway;
},
/**
* Event handler for when a member changes status in the
collection
@@ -104,10 +104,10 @@
if ( additions.length || removals.length ) {
if ( additions.length ) {
- calls.push(
this.api.addPagesToCollection( collection.id, additions ) );
+ calls.push(
this.collectionGateway.addPagesToCollection( collection.id, additions ) );
}
if ( removals.length ) {
- calls.push(
this.api.removePagesFromCollection( collection.id, removals ) );
+ calls.push(
this.collectionGateway.removePagesFromCollection( collection.id, removals ) );
}
return $.when.apply( $, calls );
} else {
diff --git a/resources/ext.gather.page.search/CollectionSearchPanel.js
b/resources/ext.gather.page.search/CollectionSearchPanel.js
index 65604e2..746d3e2 100644
--- a/resources/ext.gather.page.search/CollectionSearchPanel.js
+++ b/resources/ext.gather.page.search/CollectionSearchPanel.js
@@ -2,6 +2,7 @@
var Panel = M.require( 'mobile.startup/Panel' ),
Icon = M.require( 'mobile.startup/Icon' ),
+ CollectionsGateway = M.require(
'ext.gather.api/CollectionsGateway' ),
SearchGateway = M.require( 'mobile.search.api/SearchGateway' ),
SEARCH_DELAY = 200,
CollectionPageList = M.require(
'ext.gather.page.search/CollectionPageList' ),
@@ -24,6 +25,7 @@
/**
* @inheritdoc
* @cfg {Array} defaults.pages a list of pages in the collection
+ * @cfg {mw.Api} defaults.api
* @cfg {Object} defaults.collection the collection being
worked on
*/
className: 'panel visible collection-search-panel',
@@ -44,7 +46,8 @@
var self = this;
this.query = '';
// FIXME: In future we'll want to use CollectionApi for
this
- this.gateway = new SearchGateway( new mw.Api() );
+ this.searchGateway = new SearchGateway( options.api );
+ this.collectionGateway = new CollectionsGateway(
options.api );
this._members = {};
$.each( options.pages, function ( i, page ) {
self._members[page.title] = true;
@@ -107,6 +110,7 @@
} else {
this.pageList = new CollectionPageList( {
pages: pages,
+ collectionGateway:
this.collectionGateway,
collection: this.options.collection,
el: this.$( '.results' )
} );
@@ -171,7 +175,7 @@
this.$( '.spinner' ).show();
this.timer = setTimeout( function () {
- self._request =
self.gateway.search( query ).done( function ( data ) {
+ self._request =
self.searchGateway.search( query ).done( function ( data ) {
// check if we're
getting the rights response in case of out of
// order responses
(need to get the current value of the input)
if ( data.query ===
query ) {
diff --git a/resources/ext.gather.relatedpages/RelatedPages.js
b/resources/ext.gather.relatedpages/RelatedPages.js
index 1e1e9cd..c4b62a1 100644
--- a/resources/ext.gather.relatedpages/RelatedPages.js
+++ b/resources/ext.gather.relatedpages/RelatedPages.js
@@ -1,6 +1,7 @@
( function ( M, $ ) {
- var RelatedPagesApi = M.require( 'ext.gather.api/RelatedPagesApi' ),
+ var RelatedPagesGateway = M.require(
'ext.gather.api/RelatedPagesGateway' ),
+ CollectionsGateway = M.require(
'ext.gather.api/CollectionsGateway' ),
View = M.require( 'mobile.view/View' ),
Page = M.require( 'mobile.startup/Page' ),
CollectionPageList = M.require(
'ext.gather.page.search/CollectionPageList' ),
@@ -14,14 +15,21 @@
*/
RelatedPages = View.extend( {
className: 'related-pages',
+ /**
+ * @inheritdoc
+ * @cfg {mw.Api} defaults.api
+ * @cfg {String} defaults.spinner HTML for a spinner element
+ * @cfg {String} defaults.heading of related pages view.
+ */
defaults: {
spinner: icons.spinner().toHtmlString(),
heading: mw.msg( 'gather-edit-collection-related-pages'
)
},
template: mw.template.get( 'ext.gather.relatedpages',
'relatedpages.hogan' ),
/** @inheritdoc */
- initialize: function () {
- this.api = new RelatedPagesApi();
+ initialize: function ( options ) {
+ this.relatedGateway = new RelatedPagesGateway(
options.api );
+ this.collectionGateway = new CollectionsGateway(
options.api );
this.relatedPages = [];
this.pageList = null;
this._loading = true;
@@ -34,6 +42,8 @@
pages = this.relatedPages;
if ( !this.pageList ) {
this.pageList = new CollectionPageList( {
+ collectionGateway:
this.collectionGateway,
+ relatedGateway: this.relatedGateway,
pages: pages,
collection: this.options.collection,
el: this.$( '.results' )
@@ -63,7 +73,7 @@
title = this.options.title;
if ( title ) {
this.loading( true );
- return this.api.getRelatedPages( title
).always( function () {
+ return this.relatedGateway.getRelatedPages(
title ).always( function () {
self.loading( false );
} ).then( function ( relatedPages ) {
if ( relatedPages ) {
diff --git a/resources/ext.gather.routes/routes.js
b/resources/ext.gather.routes/routes.js
index dedcad3..2b5a6e3 100644
--- a/resources/ext.gather.routes/routes.js
+++ b/resources/ext.gather.routes/routes.js
@@ -1,6 +1,6 @@
( function ( M, $ ) {
- var CollectionsApi = M.require( 'ext.gather.api/CollectionsApi' ),
+ var CollectionsGateway = M.require( 'ext.gather.api/CollectionsGateway'
),
toast = M.require( 'mobile.toast/toast' ),
overlayManager = M.require( 'mobile.startup/overlayManager' ),
loader = M.require( 'mobile.overlays/moduleLoader' );
@@ -13,10 +13,10 @@
*/
function renderCollectionEditOverlay( id, showTutorial ) {
var d = $.Deferred(),
- api = new CollectionsApi();
+ gateway = new CollectionsGateway( new mw.Api() );
showTutorial = showTutorial || false;
- api.getCollection( id ).done( function ( collection ) {
+ gateway.getCollection( id ).done( function ( collection ) {
if ( collection ) {
loader.loadModule(
'ext.gather.collection.editor', true ).done( function ( loadingOverlay ) {
var CollectionEditOverlay = M.require(
'ext.gather.collection.edit/CollectionEditOverlay' ),
@@ -25,6 +25,7 @@
d.resolve(
new CollectionEditOverlay( {
skin: M.require(
'skins.minerva.scripts/skin' ),
+ api: new mw.Api(),
collection: collection,
reloadOnSave:
isSpecialPage,
showTutorial:
showTutorial
diff --git a/resources/ext.gather.special.collection/init.js
b/resources/ext.gather.special.collection/init.js
index a4cd16c..d8c1dd8 100644
--- a/resources/ext.gather.special.collection/init.js
+++ b/resources/ext.gather.special.collection/init.js
@@ -7,6 +7,7 @@
if ( !$collection.data( 'is-owner' ) ) {
new CollectionFlagButton( {
+ api: new mw.Api(),
collectionId: $collection.data( 'id' )
} ).prependTo( '.collection-moderation' );
}
diff --git a/resources/ext.gather.special.usercollections/init.js
b/resources/ext.gather.special.usercollections/init.js
index 1ba940e..7523f05 100644
--- a/resources/ext.gather.special.usercollections/init.js
+++ b/resources/ext.gather.special.usercollections/init.js
@@ -6,6 +6,7 @@
$( function () {
new CollectionsList( {
+ api: new mw.Api(),
skin: M.require( 'skins.minerva.scripts/skin' ),
el: $collectionsList,
enhance: true,
diff --git a/resources/ext.gather.watchstar/CollectionsWatchstar.js
b/resources/ext.gather.watchstar/CollectionsWatchstar.js
index ac408a7..940f181 100644
--- a/resources/ext.gather.watchstar/CollectionsWatchstar.js
+++ b/resources/ext.gather.watchstar/CollectionsWatchstar.js
@@ -51,6 +51,7 @@
/**
* @inheritdoc
* @cfg {Object} defaults Default options hash.
+ * @cfg {CollectionsGateway} defaults.gateway
* @cfg {Number} defaults.inCollections number of collections
the current page appears in
* @cfg {Array} defaults.collections definitions of the users
existing collections
* @cfg {Boolean} defaults.wasUserPrompted a flag which
identifies if the user was prompted
@@ -108,6 +109,7 @@
if ( !overlay ) {
// cache it so state changes internally for
this session
this.overlay = overlay = new
CollectionsContentOverlay( {
+ gateway: this.options.gateway,
page: options.page,
// FIXME: Should be retrievable from
Page
description: mw.config.get(
'wgMFDescription' ),
diff --git a/tests/qunit/ext.gather.api/test_RelatedPagesApi.js
b/tests/qunit/ext.gather.api/test_RelatedPagesGateway.js
similarity index 62%
rename from tests/qunit/ext.gather.api/test_RelatedPagesApi.js
rename to tests/qunit/ext.gather.api/test_RelatedPagesGateway.js
index fa62031..174a49c 100644
--- a/tests/qunit/ext.gather.api/test_RelatedPagesApi.js
+++ b/tests/qunit/ext.gather.api/test_RelatedPagesGateway.js
@@ -1,6 +1,5 @@
( function ( M, $ ) {
- var Api = M.require( 'mobile.startup/api' ).Api,
- RelatedPagesApi = M.require( 'ext.gather.api/RelatedPagesApi' ),
+ var RelatedPagesGateway = M.require(
'ext.gather.api/RelatedPagesGateway' ),
relatedPages = {
query: {
pages: {
@@ -29,18 +28,21 @@
} );
QUnit.test( 'Returns an array with the results when api responds', 2,
function ( assert ) {
- this.sandbox.stub( Api.prototype, 'get' ).returns(
$.Deferred().resolve( relatedPages ) );
- var api = new RelatedPagesApi();
- api.getRelatedPages( 'Oh' ).then( function ( results ) {
+ var api = new mw.Api(),
+ gateway = new RelatedPagesGateway( api );
+ this.sandbox.stub( api, 'get' ).returns( $.Deferred().resolve(
relatedPages ) );
+ gateway.getRelatedPages( 'Oh' ).then( function ( results ) {
assert.ok( $.isArray( results ), 'Results must be an
array' );
assert.strictEqual( results[0].title, 'Oh noes' );
} );
} );
QUnit.test( 'Empty related pages is handled fine.', 2, function (
assert ) {
- this.sandbox.stub( Api.prototype, 'get' ).returns(
$.Deferred().resolve( emptyRelatedPages ) );
- var api = new RelatedPagesApi();
- api.getRelatedPages( 'Oh' ).then( function ( results ) {
+ var api = new mw.Api(),
+ gateway = new RelatedPagesGateway( api );
+
+ this.sandbox.stub( api, 'get' ).returns( $.Deferred().resolve(
emptyRelatedPages ) );
+ gateway.getRelatedPages( 'Oh' ).then( function ( results ) {
assert.ok( $.isArray( results ), 'Results must be an
array' );
assert.strictEqual( results.length, 0 );
} );
diff --git
a/tests/qunit/ext.gather.collection.contentOverlay/test_CollectionsContentOverlay.js
b/tests/qunit/ext.gather.collection.contentOverlay/test_CollectionsContentOverlay.js
index ba253fa..51eb386 100644
---
a/tests/qunit/ext.gather.collection.contentOverlay/test_CollectionsContentOverlay.js
+++
b/tests/qunit/ext.gather.collection.contentOverlay/test_CollectionsContentOverlay.js
@@ -4,7 +4,7 @@
// update state
// mw.config.set( 'wgGatherCollections', state );
( function ( M, $ ) {
- var CollectionsApi = M.require( 'ext.gather.api/CollectionsApi' ),
+ var CollectionsGateway = M.require( 'ext.gather.api/CollectionsGateway'
),
Page = M.require( 'mobile.startup/Page' ),
CollectionsContentOverlay = M.require(
'ext.gather.watchstar/CollectionsContentOverlay' ),
Schema = M.require( 'mobile.startup/Schema' );
@@ -20,8 +20,9 @@
this.page = new Page( {
title: 'Gather test'
} );
- this.sandbox.stub( CollectionsApi.prototype,
'addCollection' ).returns( d );
- this.sandbox.stub( CollectionsApi.prototype,
'addPageToCollection' ).returns( d2 );
+ this.gateway = new CollectionsGateway();
+ this.sandbox.stub( this.gateway, 'addCollection'
).returns( d );
+ this.sandbox.stub( this.gateway, 'addPageToCollection'
).returns( d2 );
this.sandbox.stub( CollectionsContentOverlay.prototype,
'loadEditor' );
this.watchlist = {
id: 0,
@@ -40,6 +41,7 @@
QUnit.test( 'Internal updates to overlay', 2, function ( assert ) {
var overlay = new CollectionsContentOverlay( {
+ gateway: this.gateway,
collections: [ this.watchlist, this.collection ]
} );
overlay.addToCollection( this.collection, this.page ).done(
function () {
@@ -52,6 +54,7 @@
QUnit.test( 'Internal updates to overlay when new collection', 2,
function ( assert ) {
var overlay = new CollectionsContentOverlay( {
+ gateway: this.gateway,
collections: [ this.watchlist ]
} );
assert.strictEqual( overlay.options.collections.length, 1,
diff --git
a/tests/qunit/ext.gather.collection.editor/test_CollectionEditOverlay.js
b/tests/qunit/ext.gather.collection.editor/test_CollectionEditOverlay.js
index 065a221..752b452 100644
--- a/tests/qunit/ext.gather.collection.editor/test_CollectionEditOverlay.js
+++ b/tests/qunit/ext.gather.collection.editor/test_CollectionEditOverlay.js
@@ -1,6 +1,6 @@
( function ( M, $ ) {
var CollectionEditOverlay = M.require(
'ext.gather.collection.edit/CollectionEditOverlay' ),
- CollectionsApi = M.require( 'ext.gather.api/CollectionsApi' );
+ CollectionsGateway = M.require(
'ext.gather.api/CollectionsGateway' );
QUnit.module( 'Gather: CollectionEditOverlay', {
setup: function () {
@@ -13,11 +13,11 @@
title: 'Cool title',
description: 'Hey, I\'m a collection
description.'
};
- this.sandbox.stub( CollectionsApi.prototype,
'getCollectionMembers' )
+ this.sandbox.stub( CollectionsGateway.prototype,
'getCollectionMembers' )
.returns(
$.Deferred().resolve( {} )
);
- this.sandbox.stub( CollectionsApi.prototype,
'getCollection' )
+ this.sandbox.stub( CollectionsGateway.prototype,
'getCollection' )
.returns(
$.Deferred().resolve( {
query: {
--
To view, visit https://gerrit.wikimedia.org/r/250826
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Icaf2d24c2764658fa775600965529f1a609262b6
Gerrit-PatchSet: 12
Gerrit-Project: mediawiki/extensions/Gather
Gerrit-Branch: dev
Gerrit-Owner: Jdlrobson <[email protected]>
Gerrit-Reviewer: Jhernandez <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits