Robmoen has uploaded a new change for review.

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

Change subject: WIP: Add to collection from search
......................................................................

WIP: Add to collection from search

bug: T90991
Change-Id: I5e91476c256cdf9a63a91b482146248d081d2287
---
M resources/Resources.php
M resources/ext.gather.collection.editor/CollectionEditOverlay.js
M resources/ext.gather.collection.editor/content.hogan
A resources/ext.gather.search/CollectionPageList.js
A resources/ext.gather.search/CollectionPageListItem.hogan
A resources/ext.gather.search/CollectionSearchOverlay.js
6 files changed, 202 insertions(+), 1 deletion(-)


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

diff --git a/resources/Resources.php b/resources/Resources.php
index bd74619..ddacc55 100644
--- a/resources/Resources.php
+++ b/resources/Resources.php
@@ -154,6 +154,7 @@
 
        'ext.gather.collection.editor' => 
$wgGatherResourceFileModuleBoilerplate + array(
                'dependencies' => array(
+                       'ext.gather.search',
                        'ext.gather.logging',
                        'mobile.overlays',
                        'mobile.toast',
@@ -178,6 +179,23 @@
                ),
        ),
 
+       'ext.gather.search' => $wgGatherResourceFileModuleBoilerplate + array(
+               'dependencies' => array(
+                       'mobile.search',
+                       'ext.gather.watchstar',
+               ),
+               'templates' => array(
+                       'CollectionPageListItem.hogan' => 
'ext.gather.search/CollectionPageListItem.hogan',
+               ),
+               'messages' => array(
+                       'mobile-frontend-watchlist-modified'
+               ),
+               'scripts' => array(
+                       'ext.gather.search/CollectionPageList.js',
+                       'ext.gather.search/CollectionSearchOverlay.js',
+               ),
+       ),
+
        'ext.gather.collection.delete' => 
$wgGatherResourceFileModuleBoilerplate + array(
                'dependencies' => array(
                        'ext.gather.collection.base',
diff --git a/resources/ext.gather.collection.editor/CollectionEditOverlay.js 
b/resources/ext.gather.collection.editor/CollectionEditOverlay.js
index 482f6da..94afce2 100644
--- a/resources/ext.gather.collection.editor/CollectionEditOverlay.js
+++ b/resources/ext.gather.collection.editor/CollectionEditOverlay.js
@@ -3,6 +3,7 @@
        var CollectionEditOverlay,
                toast = M.require( 'toast' ),
                CollectionsApi = M.require( 
'ext.gather.watchstar/CollectionsApi' ),
+               CollectionSearchOverlay = M.require( 
'ext.gather.search/CollectionSearchOverlay' ),
                Overlay = M.require( 'Overlay' ),
                SchemaGather = M.require( 'ext.gather.logging/SchemaGather' ),
                schema = new SchemaGather(),
@@ -35,7 +36,8 @@
                } ),
                /** @inheritdoc */
                events: $.extend( {}, Overlay.prototype.events, {
-                       'click .save': 'onSaveClick'
+                       'click .save': 'onSaveClick',
+                       'click .collectionSearchInput': 
'onCollectionSearchInput'
                } ),
                /** @inheritdoc */
                templatePartials: $.extend( {}, 
Overlay.prototype.templatePartials, {
@@ -88,6 +90,15 @@
 
                },
                /**
+                * Reveal the search overlay
+                * @param {jQuery.Event} ev
+                * @ignore
+                */
+               onCollectionSearchInput: function () {
+                       var collection = this.options.collection;
+                       new CollectionSearchOverlay( { collection: collection } 
).show();
+               },
+               /**
                 * Tests if title is valid
                 * @param {[type]} title Proposed collection title
                 * @returns {Boolean}
diff --git a/resources/ext.gather.collection.editor/content.hogan 
b/resources/ext.gather.collection.editor/content.hogan
index 94a3ab4..58a8ed5 100644
--- a/resources/ext.gather.collection.editor/content.hogan
+++ b/resources/ext.gather.collection.editor/content.hogan
@@ -1,3 +1,4 @@
+<input class="collectionSearchInput" type="text">
 <div class="content">
        {{#collection}}
        <label>{{nameLabel}}</label>
diff --git a/resources/ext.gather.search/CollectionPageList.js 
b/resources/ext.gather.search/CollectionPageList.js
new file mode 100644
index 0000000..b3ce036
--- /dev/null
+++ b/resources/ext.gather.search/CollectionPageList.js
@@ -0,0 +1,52 @@
+( function ( M, $ ) {
+
+       var PageList = M.require( 'modules/PageList' ),
+               View = M.require( 'View' ),
+               Icon = M.require( 'Icon' ),
+               CollectionPageList;
+
+       /**
+        * List of items page view
+        * @class PageList
+        * @uses Page
+        * @uses WatchstarApi
+        * @uses Watchstar
+        * @extends View
+        */
+       CollectionPageList = PageList.extend( {
+               /**
+                * @inheritdoc
+                */
+               templatePartials: {
+                       item: mw.template.get( 'ext.gather.search', 
'CollectionPageListItem.hogan' )
+               },
+               defaults: {
+                       iconButton: new Icon( {
+                               name: 'tick',
+                               label: mw.msg( 'gather-collection-member' )
+                       } ).toHtmlString(),
+                       iconDisabledButton: new Icon( {
+                               name: 'tick-disabled',
+                               label: mw.msg( 'gather-collection-non-member' )
+                       } ).toHtmlString()
+               },
+               /**
+                * @inheritdoc
+                */
+               initialize: function () {
+                       View.prototype.initialize.apply( this, arguments );
+               },
+               /**
+                * @inheritdoc
+                * Loads watch stars for each page.
+                */
+               postRender: function () {
+                       View.prototype.postRender.apply( this, arguments );
+                       // TODO: Respond to clicks on the icons... bubble up 
events for adding / removing
+               }
+
+       } );
+
+       M.define( 'ext.gather.search/CollectionPageList', CollectionPageList );
+
+}( mw.mobileFrontend, jQuery ) );
diff --git a/resources/ext.gather.search/CollectionPageListItem.hogan 
b/resources/ext.gather.search/CollectionPageListItem.hogan
new file mode 100644
index 0000000..de84a63
--- /dev/null
+++ b/resources/ext.gather.search/CollectionPageListItem.hogan
@@ -0,0 +1,21 @@
+<li title="{{title}}" data-id="{{id}}" class="page-summary">
+  <a href="{{url}}" class="title {{additionalClasses}}"
+    {{#anchor}}name="{{anchor}}"{{/anchor}}
+    {{#latitude}}data-latlng="{{latitude}},{{longitude}}"{{/latitude}}
+    data-title="{{title}}">
+    <div class="list-thumb {{pageimageClass}}" 
style="{{listThumbStyleAttribute}}"></div>
+    <h3>{{{heading}}}</h3>
+    {{#lastModified}}
+    <div class="info">{{lastModifiedMsg 'hi'}} {{lastModified}}</div>
+    {{/lastModified}}
+    {{#proximity}}
+    <div class="info proximity">{{proximity}}</div>
+    {{/proximity}}
+  </a>
+{{^inCollection}}
+    {{{iconDisabledButton}}}
+{{/inCollection}}
+{{#inCollection}}
+    {{{iconButton}}}
+{{/inCollection}}
+</li>
diff --git a/resources/ext.gather.search/CollectionSearchOverlay.js 
b/resources/ext.gather.search/CollectionSearchOverlay.js
new file mode 100644
index 0000000..8b96254
--- /dev/null
+++ b/resources/ext.gather.search/CollectionSearchOverlay.js
@@ -0,0 +1,98 @@
+( function ( M, $ ) {
+
+       var SearchOverlay = M.require( 'modules/search/SearchOverlay' ),
+               CollectionPageList = M.require( 
'ext.gather.search/CollectionPageList' ),
+               CollectionSearchOverlay,
+               SEARCH_DELAY = 300;
+
+       /**
+        * Overlay displaying search results
+        * @class CollectionSearchOverlay
+        * @extends SearchOverlay
+        * @uses CollectionPageList
+        * @inheritdoc
+        */
+       CollectionSearchOverlay = SearchOverlay.extend( {
+               /** @inheritdoc */
+               initialize: function ( options ) {
+                       SearchOverlay.prototype.initialize.call( this, options 
);
+                       this.collection = options.collection;
+               },
+
+               /**
+                * Fade out if the browser supports animations
+                * @inheritdoc
+                */
+               hide: function () {
+                       SearchOverlay.prototype.hide.apply( this, arguments );
+                       // TODO: Decide if one api request will be made when 
closing overlay
+                       // OR when each page list item clicked
+               },
+
+               /**
+                * Perform search and render results inside current view.
+                * @method
+                */
+               performSearch: function () {
+                       var self = this,
+                               pageList,
+                               query = this.$input.val(),
+                               $results = this.$( '.results' );
+
+                       // it seems the input event can be fired when virtual 
keyboard is closed
+                       // (Chrome for Android)
+                       if ( query !== this.lastQuery ) {
+                               this.api.abort();
+                               clearTimeout( this.timer );
+                               self.$searchContent.hide();
+                               $results.empty();
+
+                               if ( query.length ) {
+                                       this.$( '.spinner' ).show();
+
+                                       this.timer = setTimeout( function () {
+                                               self.api.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 === 
self.$input.val() ) {
+                                                               
self.$searchContent
+                                                                       .show()
+                                                                       .find( 
'p' )
+                                                                       .hide()
+                                                                       
.filter( data.results.length ? '.with-results' : '.without-results' )
+                                                                       .show();
+                                                               self.$( 
'.spinner' ).hide();
+                                                               // Add 
inCollection property to data results
+                                                               $.each( 
data.results, function ( i, page ) {
+                                                                       var 
inCollection = false;
+                                                                       if ( 
self.collection.items.indexOf( page.title ) !== -1 ) {
+                                                                               
inCollection = true;
+                                                                       }
+                                                                       
data.results[i].inCollection = inCollection;
+                                                               } );
+
+                                                               pageList = new 
CollectionPageList( {
+                                                                       pages: 
data.results,
+                                                                       el: 
$results
+                                                               } );
+                                                               
pageList.renderPageImages();
+                                                               /**
+                                                                * @event 
search-results
+                                                                * Fired when 
search API returns results
+                                                                */
+                                                               M.emit( 
'search-results', self, data.results );
+                                                       }
+                                               } );
+                                       }, this.api.isCached( query ) ? 0 : 
SEARCH_DELAY );
+                               } else {
+                                       self.$( '.spinner' ).hide();
+                               }
+
+                               this.lastQuery = query;
+                       }
+               }
+       } );
+
+       M.define( 'ext.gather.search/CollectionSearchOverlay', 
CollectionSearchOverlay );
+
+}( mw.mobileFrontend, jQuery ) );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5e91476c256cdf9a63a91b482146248d081d2287
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Gather
Gerrit-Branch: master
Gerrit-Owner: Robmoen <rm...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to