Jhernandez has uploaded a new change for review.

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

Change subject: Fully render collections list with templates
......................................................................

Fully render collections list with templates

And add a JS view to take care of that content. View is enhanced so no much
happening right now.

Future patch will take care of the loading button, and transform it into
infinite scrolling.

Bug: T97459
Change-Id: I9ecea478e553b3fbf1688bc780ea37b8fc945fac
---
M includes/views/CollectionsList.php
M resources/Resources.php
A resources/ext.gather.collections.list/CollectionsList.js
A resources/ext.gather.special.usercollections/init.js
A templates/CollectionsList.mustache
5 files changed, 71 insertions(+), 13 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Gather 
refs/changes/77/207177/1

diff --git a/includes/views/CollectionsList.php 
b/includes/views/CollectionsList.php
index 12db333..ba31431 100644
--- a/includes/views/CollectionsList.php
+++ b/includes/views/CollectionsList.php
@@ -6,6 +6,7 @@
 namespace Gather\views;
 
 use Gather\models;
+use Gather\views\helpers\Template;
 use Html;
 
 /**
@@ -25,16 +26,15 @@
         * @return string Html
         */
        public static function getListItemsHtml( $collectionsList ) {
-               $html = Html::openElement( 'div', array( 'class' => 
'collection-cards' ) );
                foreach ( $collectionsList as $item ) {
-                       $view = new CollectionsListItemCard( $item );
-                       $html .= $view->getHtml();
+                       $html .= (new CollectionsListItemCard( $item 
))->getHtml();
                }
-               $url = $collectionsList->getContinueUrl();
                if ( $url ) {
-                       $html .= Pagination::more( $url, wfMessage( 
'gather-lists-more' )->text() );
+                       $html .= Pagination::more(
+                               $collectionsList->getContinueUrl(),
+                               wfMessage( 'gather-lists-more' )->text()
+                       );
                }
-               $html .= Html::closeElement( 'div' );
                return $html;
        }
 
@@ -54,13 +54,9 @@
         * @inheritdoc
         */
        public function getHtml( $data = array() ) {
-               $html = Html::openElement(
-                       'div',
-                       array( 'class' => 'collections-list content 
view-border-box' )
+               $defaults = array(
+                       'items' => $this->getListItemsHtml( 
$this->collectionsList )
                );
-               // Get items
-               $html .= $this->getListItemsHtml( $this->collectionsList );
-               $html .= Html::closeElement( 'div' );
-               return $html;
+               return Template::render( 'CollectionsList', array_merge( 
$defaults, $data ) );
        }
 }
diff --git a/resources/Resources.php b/resources/Resources.php
index 836d5ef..831ea10 100644
--- a/resources/Resources.php
+++ b/resources/Resources.php
@@ -116,6 +116,22 @@
                ),
        ),
 
+       'ext.gather.collections.list' => $wgGatherResourceFileModuleBoilerplate 
+ array(
+               'dependencies' => array(
+               ),
+               'styles' => array(
+               ),
+               'messages' => array(
+               ),
+               'templates' => array(
+                       'CollectionsList.hogan' => 
'../templates/CollectionsList.mustache',
+                       'CollectionsListItemCard.hogan' => 
'../templates/CollectionsListItemCard.mustache',
+               ),
+               'scripts' => array(
+                       'ext.gather.collections.list/CollectionsList.js',
+               ),
+       ),
+
        'ext.gather.collection.base' => $wgGatherResourceFileModuleBoilerplate 
+ array(
                'dependencies' => array(
                        'ext.gather.logging',
@@ -353,6 +369,10 @@
        'ext.gather.special.usercollections' => 
$wgGatherMobileSpecialPageResourceBoilerplate + array(
                'dependencies' => array(
                        'ext.gather.special.base',
+                       'ext.gather.collections.list',
+               ),
+               'scripts' => array(
+                       'ext.gather.special.usercollections/init.js',
                ),
        ),
 
diff --git a/resources/ext.gather.collections.list/CollectionsList.js 
b/resources/ext.gather.collections.list/CollectionsList.js
new file mode 100644
index 0000000..5fe050e
--- /dev/null
+++ b/resources/ext.gather.collections.list/CollectionsList.js
@@ -0,0 +1,26 @@
+( function ( M ) {
+
+       var CollectionsList,
+               View = M.require( 'View' );
+
+       CollectionsList = View.extend( {
+               defaults: {
+                       enhance: false,
+                       collections: []
+               },
+               template: mw.template.get( 'ext.gather.collections.list', 
'CollectionsList.hogan' ),
+               templatePartials: {
+                       item: mw.template.get( 'ext.gather.collections.list', 
'CollectionsListItemCard.hogan' )
+               },
+               /** @inheritdoc */
+               initialize: function ( options ) {
+                       if ( options.enhance ) {
+                               this.template = false;
+                       }
+                       View.prototype.initialize.apply( this, arguments );
+               }
+       } );
+
+       M.define( 'ext.gather.collections.list/CollectionsList', 
CollectionsList );
+
+} )( mw.mobileFrontend, jQuery );
diff --git a/resources/ext.gather.special.usercollections/init.js 
b/resources/ext.gather.special.usercollections/init.js
new file mode 100644
index 0000000..a658633
--- /dev/null
+++ b/resources/ext.gather.special.usercollections/init.js
@@ -0,0 +1,11 @@
+( function ( M, $ ) {
+       var CollectionsList = M.require( 
'ext.gather.collections.list/CollectionsList' );
+
+       $( function () {
+               new CollectionsList( {
+                       el: $( '.collections-list' ),
+                       enhance: true
+               } );
+       } );
+
+}( mw.mobileFrontend, jQuery ) );
diff --git a/templates/CollectionsList.mustache 
b/templates/CollectionsList.mustache
new file mode 100644
index 0000000..fa7b2b8
--- /dev/null
+++ b/templates/CollectionsList.mustache
@@ -0,0 +1,5 @@
+<div class='collections-list content view-border-box'>
+  <div class='collection-cards'>
+    {{{items}}}
+  </div>
+</div>

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9ecea478e553b3fbf1688bc780ea37b8fc945fac
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Gather
Gerrit-Branch: master
Gerrit-Owner: Jhernandez <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to