JGonera has uploaded a new change for review.
https://gerrit.wikimedia.org/r/69132
Change subject: Rewrite parts of the uplaods dashboard code
......................................................................
Rewrite parts of the uplaods dashboard code
Create UserGalleryApi which inherits from Api, untangle carousel code
(remove the module-global carousel variable).
Change-Id: I15723385d0acce2c3b96511270f74cee34f790f9
---
M includes/Resources.php
M includes/specials/SpecialUploads.php
M javascripts/specials/uploads.js
A templates/specials/uploads/userGallery.html
4 files changed, 72 insertions(+), 59 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend
refs/changes/32/69132/1
diff --git a/includes/Resources.php b/includes/Resources.php
index 9955f4a..cec175a 100644
--- a/includes/Resources.php
+++ b/includes/Resources.php
@@ -626,6 +626,7 @@
'templates' => array(
'specials/uploads/carousel',
'specials/uploads/photo',
+ 'specials/uploads/userGallery',
),
),
'mobile.uploads.scripts' => $wgMFMobileResourceBoilerplate + array(
diff --git a/includes/specials/SpecialUploads.php
b/includes/specials/SpecialUploads.php
index bcb4cf9..271bd61 100644
--- a/includes/specials/SpecialUploads.php
+++ b/includes/specials/SpecialUploads.php
@@ -43,7 +43,6 @@
$html .= Html::openElement( 'h2', $attrs ) .
$msg . Html::closeElement( 'h2' );
$html .= '</div>';
}
- $html .= '<ul class="mobileUserGallery"></ul>';
}
$output->addHTML( $html );
}
diff --git a/javascripts/specials/uploads.js b/javascripts/specials/uploads.js
index b482411..dd2325e 100644
--- a/javascripts/specials/uploads.js
+++ b/javascripts/specials/uploads.js
@@ -2,23 +2,79 @@
var
photo = M.require( 'photo' ),
popup = M.require( 'notifications' ),
+ Api = M.require( 'api' ).Api,
View = M.require( 'view' ),
CarouselOverlay = M.require( 'overlays/CarouselOverlay' ),
corsUrl = mw.config.get( 'wgMFPhotoUploadEndpoint' ),
+ userName = mw.config.get( 'wgUserName' ),
IMAGE_WIDTH = 320,
- Photo, UserGallery, userGallery, carousel;
+ UserGalleryApi, Photo, UserGallery, userGallery;
+
+ UserGalleryApi = Api.extend( {
+ getPhotos: function() {
+ var result = $.Deferred();
+
+ this.get( {
+ action: 'query',
+ generator: 'allimages',
+ gaisort: 'timestamp',
+ gaidir: 'descending',
+ gaiuser: userName,
+ gailimit: 10,
+ prop: 'imageinfo',
+ origin: corsUrl ? M.getOrigin() : undefined,
+ // FIXME: have to request timestamp since api
returns a json rather than an array thus we need a way to sort
+ iiprop: 'url|timestamp',
+ iiurlwidth: IMAGE_WIDTH
+ }, {
+ url: corsUrl || M.getApiUrl(),
+ xhrFields: { withCredentials: true }
+ } ).done( function( resp ) {
+ if ( resp.query && resp.query.pages ) {
+ // FIXME: API work around - in an ideal
world imageData would be a sorted array
+ result.resolve( $.map(
resp.query.pages, getImageDataFromPage ).sort( function( a, b ) {
+ return a.timestamp >
b.timestamp ? 1 : -1;
+ } ) );
+ } else {
+ result.reject();
+ }
+ } );
+
+ return result;
+ }
+ } );
Photo = View.extend( {
template: M.template.get( 'specials/uploads/photo' )
} );
UserGallery = View.extend( {
+ template: M.template.get( 'specials/uploads/userGallery' ),
+ initialize: function() {
+ // how close a spinner needs to be to the viewport to
trigger loading (px)
+ this.threshold = 500;
+ this.api = new UserGalleryApi();
+
+ },
+ postRender: function() {
+ var self = this;
+ this.$end = this.$( '.end' );
+
+ this.api.getPhotos().done( function( photos ) {
+ $.each( photos, function() {
+ self.addPhoto( this );
+ } );
+ } ).fail( function() {
+ self.$end.hide();
+ self.emit( 'empty' );
+ } );
+ },
isEmpty: function() {
return this.$( 'li' ).length === 0;
},
addPhoto: function( photoData, notify ) {
var msgKey;
- new Photo( photoData ).prependTo( this.$el );
+ new Photo( photoData ).prependTo( this.$( 'ul' ) );
if ( notify ) {
if ( this.isEmpty() ) {
msgKey =
'mobile-frontend-donate-photo-first-upload-success';
@@ -55,41 +111,14 @@
};
}
- function showGallery( username ) {
- // FIXME: use api module
- $.ajax( {
- url: corsUrl || M.getApiUrl(),
- data: {
- action: 'query',
- generator: 'allimages',
- format: 'json',
- gaisort: 'timestamp',
- gaidir: 'descending',
- gaiuser: username,
- gailimit: 10,
- prop: 'imageinfo',
- origin: corsUrl ? M.getOrigin() : undefined,
- // FIXME: have to request timestamp since api
returns a json rather than an array thus we need a way to sort
- iiprop: 'url|timestamp',
- iiurlwidth: IMAGE_WIDTH
- },
- xhrFields: {
- 'withCredentials': true
- }
- } ).done( function( resp ) {
- var pages;
+ function init() {
+ var $container;
- if ( resp.query && resp.query.pages ) {
- // FIXME: API work around - in an ideal world
imageData would be a sorted array
- pages = $.map( resp.query.pages,
getImageDataFromPage ).sort( function( a, b ) {
- return a.timestamp > b.timestamp ? 1 :
-1;
- } );
- $.each( pages, function() {
- userGallery.addPhoto( this );
- } );
- } else {
+ userGallery = new UserGallery().
+ appendTo( '#content' ).
+ on( 'empty', function() {
$( '.ctaUploadPhoto h2' ).hide(); // hide the
count if 0 uploads have been made
- carousel = new CarouselOverlay( {
+ new CarouselOverlay( {
pages: [
{
caption: mw.msg(
'mobile-frontend-first-upload-wizard-new-page-1-header' ),
@@ -107,22 +136,8 @@
className: 'page-3',
id: 3
}
]
- } );
- carousel.show();
- $( function() {
- window.scrollTo( 0, $( '.header'
).offset().top );
- } );
- }
- } );
- }
-
- function init() {
- var $container,
- username = mw.config.get( 'wgUserName' );
-
- userGallery = new UserGallery( {
- el: 'ul.mobileUserGallery'
- } );
+ } ).show();
+ } );
if ( photo.isSupported() ) {
$container = $( '.ctaUploadPhoto' );
@@ -141,17 +156,13 @@
newCount = parseInt(
$counter.text(), 10 ) + 1;
$counter.parent().html( mw.msg(
'mobile-frontend-photo-upload-user-count', newCount ) ).show();
}
- if ( carousel ) {
- carousel.remove();
- }
} );
- }
- if ( username ) {
- showGallery( username );
}
}
- $( init );
+ if ( userName ) {
+ $( init );
+ }
M.define( 'specials/uploads', {
getDescription: getDescription
diff --git a/templates/specials/uploads/userGallery.html
b/templates/specials/uploads/userGallery.html
new file mode 100644
index 0000000..3abb903
--- /dev/null
+++ b/templates/specials/uploads/userGallery.html
@@ -0,0 +1,2 @@
+<ul class="mobileUserGallery"></ul>
+<div class="end loading"></div>
--
To view, visit https://gerrit.wikimedia.org/r/69132
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I15723385d0acce2c3b96511270f74cee34f790f9
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: JGonera <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits