JGonera has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/69131


Change subject: Clean up uploads dashboard code
......................................................................

Clean up uploads dashboard code

Remove placeholder code as it seems to have been replaced by a carousel
overlay completely + other small tweaks.

Change-Id: If36a642ca291c3e759fbb3ddbc8641cbda5875a3
---
M includes/Resources.php
M javascripts/specials/uploads.js
A templates/specials/uploads/photo.html
M tests/javascripts/specials/test_uploads.js
4 files changed, 56 insertions(+), 68 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend 
refs/changes/31/69131/1

diff --git a/includes/Resources.php b/includes/Resources.php
index a149185..9955f4a 100644
--- a/includes/Resources.php
+++ b/includes/Resources.php
@@ -625,6 +625,7 @@
        'mobile.uploads.plumbing' => $wgMFMobileResourceTemplateBoilerplate + 
array(
                'templates' => array(
                        'specials/uploads/carousel',
+                       'specials/uploads/photo',
                ),
        ),
        'mobile.uploads.scripts' => $wgMFMobileResourceBoilerplate + array(
diff --git a/javascripts/specials/uploads.js b/javascripts/specials/uploads.js
index bfcb890..b482411 100644
--- a/javascripts/specials/uploads.js
+++ b/javascripts/specials/uploads.js
@@ -4,42 +4,31 @@
        popup = M.require( 'notifications' ),
        View = M.require( 'view' ),
        CarouselOverlay = M.require( 'overlays/CarouselOverlay' ),
-       carousel,
-       m;
+       corsUrl = mw.config.get( 'wgMFPhotoUploadEndpoint' ),
+       IMAGE_WIDTH = 320,
+       Photo, UserGallery, userGallery, carousel;
 
-m = ( function() {
-       var IMAGE_WIDTH = 320,
-               corsUrl = mw.config.get( 'wgMFPhotoUploadEndpoint' ),
-               UserGallery = View.extend( {
-                       initialize: function( options ) {
-                               this.$placeholder = options.$placeholder;
-                       },
-                       isEmpty: function() {
-                               return this.$( 'li' ).length === 0;
-                       },
-                       removePlaceholder: function() {
-                               this.$placeholder.remove(); // remove 
placeholder text in case of first upload
-                       },
-                       templateItem: M.template.compile(
-                               '<li><a href="{{descriptionUrl}}" 
alt="{{description}}"><img src="{{url}}" 
width="{{width}}"></a><p>{{description}}</p></li>'
-                       ),
-                       addPhoto: function( photoData, notify ) {
-                               var msgKey, $li;
+       Photo = View.extend( {
+               template:       M.template.get( 'specials/uploads/photo' )
+       } );
+
+       UserGallery = View.extend( {
+               isEmpty: function() {
+                       return this.$( 'li' ).length === 0;
+               },
+               addPhoto: function( photoData, notify ) {
+                       var msgKey;
+                       new Photo( photoData ).prependTo( this.$el );
+                       if ( notify ) {
                                if ( this.isEmpty() ) {
-                                       this.removePlaceholder();
                                        msgKey = 
'mobile-frontend-donate-photo-first-upload-success';
                                } else {
                                        msgKey = 
'mobile-frontend-donate-photo-upload-success';
                                }
-                               $li = $( this.templateItem.render( photoData ) 
).
-                                       prependTo( this.$el );
-                               if ( notify ) {
-                                       $li.hide().slideDown();
-                                       popup.show( mw.msg( msgKey ), 'toast' );
-                               }
+                               popup.show( mw.msg( msgKey ), 'toast' );
                        }
-               } ),
-               userGallery;
+               }
+       } );
 
        /**
         * Returns a description based on the file name using
@@ -88,23 +77,17 @@
                                'withCredentials': true
                        }
                } ).done( function( resp ) {
-                       var pages = [];
+                       var pages;
 
                        if ( resp.query && resp.query.pages ) {
-                               pages = resp.query.pages;
-                               pages = $.map( pages, function ( p ) {
-                                       return getImageDataFromPage( p );
-                               } );
-                               // FIXME: API work around - in an ideal world 
imageData would be an array
-                               pages = pages.sort( function( a, b ) {
+                               // 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 );
                                } );
-                       }
-
-                       if ( pages.length === 0 ) {
+                       } else {
                                $( '.ctaUploadPhoto h2' ).hide(); // hide the 
count if 0 uploads have been made
                                carousel = new CarouselOverlay( {
                                        pages: [
@@ -138,9 +121,7 @@
                        username = mw.config.get( 'wgUserName' );
 
                userGallery = new UserGallery( {
-                       el: 'ul.mobileUserGallery',
-                       // FIXME: should be possible to do this more elegantly
-                       $placeholder: $( '#content p' ).eq( 0 )
+                       el: 'ul.mobileUserGallery'
                } );
 
                if ( photo.isSupported() ) {
@@ -156,7 +137,7 @@
                                        var $counter = $container.find( 'h2' 
).show().find( 'span' ), newCount;
                                        image.width = IMAGE_WIDTH;
                                        userGallery.addPhoto( image, true );
-                                       if ( $counter[ 0 ] ) {
+                                       if ( $counter.length ) {
                                                newCount = parseInt( 
$counter.text(), 10 ) + 1;
                                                $counter.parent().html( mw.msg( 
'mobile-frontend-photo-upload-user-count', newCount ) ).show();
                                        }
@@ -169,12 +150,11 @@
                        showGallery( username );
                }
        }
-       $( init );
-       return {
-               getDescription: getDescription
-       };
-}() );
 
-M.define( 'userGallery', m );
+       $( init );
+
+       M.define( 'specials/uploads', {
+               getDescription: getDescription
+       } );
 
 }( mw.mobileFrontend, jQuery ) );
diff --git a/templates/specials/uploads/photo.html 
b/templates/specials/uploads/photo.html
new file mode 100644
index 0000000..a56ed46
--- /dev/null
+++ b/templates/specials/uploads/photo.html
@@ -0,0 +1,6 @@
+<li>
+       <a href="{{descriptionUrl}}" alt="{{description}}">
+               <img src="{{url}}" width="{{width}}">
+       </a>
+       <p>{{description}}</p>
+</li>
diff --git a/tests/javascripts/specials/test_uploads.js 
b/tests/javascripts/specials/test_uploads.js
index 401d804..ca58910 100644
--- a/tests/javascripts/specials/test_uploads.js
+++ b/tests/javascripts/specials/test_uploads.js
@@ -1,25 +1,26 @@
 ( function ( M, $ ) {
 
-var m = M.require( 'userGallery' );
-QUnit.module( 'MobileFrontend donate image' );
+       var m = M.require( 'specials/uploads' );
 
-QUnit.test( 'getDescription', function() {
-       var tests = [
-                       [ 'File:Pirates in SF 2013-04-03 15-44.png', 'Pirates 
in SF' ],
-                       [ 'File:Unpadded 9 pirates in SF 2013-04-03 15-9.png', 
'Unpadded 9 pirates in SF' ],
-                       [ 'File:Jon lies next to volcano 2013-03-18 
13-37.jpeg', 'Jon lies next to volcano' ],
-                       [ 'hello world 37.jpg', 'hello world 37' ],
-                       [ 'hello world again.jpeg', 'hello world again' ],
-                       [ 'Fichier:French Photo Timestamp 2013-04-03 
15-44.jpg', 'French Photo Timestamp' ],
-                       [ 'Fichier:Full stop. Photo.unknownfileextension', 
'Full stop. Photo' ],
-                       [ 'File:No file extension but has a . in the title', 
'No file extension but has a . in the title' ],
-                       [ 'Fichier:French Photo.jpg', 'French Photo' ]
-               ];
-       QUnit.expect( tests.length );
-       $( tests ).each( function( i ) {
-               var val = m.getDescription( this[0] );
-               strictEqual( val, this[1], 'test ' + i );
+       QUnit.module( 'MobileFrontend uploads' );
+
+       QUnit.test( 'getDescription', function( assert ) {
+               var tests = [
+                               [ 'File:Pirates in SF 2013-04-03 15-44.png', 
'Pirates in SF' ],
+                               [ 'File:Unpadded 9 pirates in SF 2013-04-03 
15-9.png', 'Unpadded 9 pirates in SF' ],
+                               [ 'File:Jon lies next to volcano 2013-03-18 
13-37.jpeg', 'Jon lies next to volcano' ],
+                               [ 'hello world 37.jpg', 'hello world 37' ],
+                               [ 'hello world again.jpeg', 'hello world again' 
],
+                               [ 'Fichier:French Photo Timestamp 2013-04-03 
15-44.jpg', 'French Photo Timestamp' ],
+                               [ 'Fichier:Full stop. 
Photo.unknownfileextension', 'Full stop. Photo' ],
+                               [ 'File:No file extension but has a . in the 
title', 'No file extension but has a . in the title' ],
+                               [ 'Fichier:French Photo.jpg', 'French Photo' ]
+                       ];
+               QUnit.expect( tests.length );
+               $( tests ).each( function( i ) {
+                       var val = m.getDescription( this[0] );
+                       assert.strictEqual( val, this[1], 'test ' + i );
+               } );
        } );
-} );
 
 }( mw.mobileFrontend, jQuery ) );

-- 
To view, visit https://gerrit.wikimedia.org/r/69131
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: If36a642ca291c3e759fbb3ddbc8641cbda5875a3
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

Reply via email to