Эх сурвалжийг харах

[search] Adding template for result pagination

Romain Rigaux 11 жил өмнө
parent
commit
5d260ef980

+ 17 - 0
apps/search/src/search/models.py

@@ -594,6 +594,23 @@ def augment_solr_response(response, facets, solr_query):
         else:
           normalized_facets[uuid] = facet
 
+    if response and response.get('response'):
+      pages_to_show = 5 # always use an odd number since we do it symmetrically
+
+#      beginning = 0
+#      previous = int(solr_query["start"]) - int(solr_query["rows"])
+#      next = int(solr_query["start"]) + int(solr_query["rows"])
+#
+#      pages_after = (pages_to_show - 1) / 2
+#      pages_total = solr_query['total_pages']+1
+#      real_pages_after =  pages_total - solr_query["current_page"]
+#      symmetric_start = solr_query["current_page"] < pages_total - pages_after
+#      symmetric_end = solr_query["current_page"] > pages_after
+#
+#      pagination_start = solr_query["current_page"] > (pages_to_show - 1)/2 and (symmetric_start and solr_query["current_page"] - (pages_to_show - 1)/2 or solr_query["current_page"] - pages_to_show + real_pages_after ) or 1
+#      pagination_end = solr_query["current_page"] < solr_query['total_pages']+1-(pages_to_show - 1)/2 and (symmetric_end and solr_query["current_page"] + (pages_to_show - 1)/2 + 1 or solr_query["current_page"] + (pages_to_show - solr_query["current_page"]) + 1) or solr_query['total_pages']+1
+      
+
   for ordered_uuid in facets.get('order', []):
     try:
       augmented['normalized_facets'].append(normalized_facets[ordered_uuid])

+ 11 - 4
apps/search/src/search/templates/search2.mako

@@ -285,7 +285,6 @@ ${ commonheader(_('Search'), "search", user, "60px") | n,unicode }
       <div data-bind="visible: $root.isEditing()" class="widget-settings-section">
         <ul class="unstyled" style="margin: 10px">
           <li>Name: <input type="text" data-bind="value: name" class="input-mini" /></li>
-          ## Could add here extra non widget settings like facet or see for a nice popover
         </ul>
       </div>
     </div>
@@ -329,9 +328,9 @@ ${ commonheader(_('Search'), "search", user, "60px") | n,unicode }
 
 <script type="text/html" id="resultset-widget">
   <div data-bind="visible: $root.isEditing" style="margin-bottom: 20px">
-      ${_('Results type')}
-      &nbsp;<a href="javascript: void(0)" data-bind="css:{'btn': true, 'btn-inverse': $root.collection.template.isGridLayout()}, click: function(){$root.collection.template.isGridLayout(true)}"><i class="fa fa-th"></i></a>
-      &nbsp;<a href="javascript: void(0)" data-bind="css:{'btn': true, 'btn-inverse': !$root.collection.template.isGridLayout()}, click: function(){$root.collection.template.isGridLayout(false)}"><i class="fa fa-code"></i></a>
+    ${_('Results type')}
+    &nbsp;<a href="javascript: void(0)" data-bind="css:{'btn': true, 'btn-inverse': $root.collection.template.isGridLayout()}, click: function(){$root.collection.template.isGridLayout(true)}"><i class="fa fa-th"></i></a>
+    &nbsp;<a href="javascript: void(0)" data-bind="css:{'btn': true, 'btn-inverse': !$root.collection.template.isGridLayout()}, click: function(){$root.collection.template.isGridLayout(false)}"><i class="fa fa-code"></i></a>
   </div>
 
   <!-- ko if: $root.collection.template.isGridLayout() -->
@@ -374,6 +373,10 @@ ${ commonheader(_('Search'), "search", user, "60px") | n,unicode }
       ${ _('Your search did not match any documents.') }
     </div>
     
+    <!-- ko if: $root.response().response -->
+      <div data-bind="template: {name: 'resultset-pagination', data: $root.response() }"></div>
+    <!-- /ko -->
+    
 	<!-- ko if: $root.collection.template.isGridLayout() -->
     <table id="result-container" data-bind="visible: !($root.isRetrievingResults())" style="margin-top: 0">
       <thead>
@@ -403,6 +406,10 @@ ${ commonheader(_('Search'), "search", user, "60px") | n,unicode }
   </div>
 </script>
 
+<script type="text/html" id="resultset-pagination">
+  <span data-bind="text: $data.response.numFound"></span> ${ _(' results') } 
+</script>
+
 <script type="text/html" id="timeline-widget">
   This is the timeline widget
 </script>

+ 1 - 1
apps/search/static/js/search.ko.js

@@ -319,7 +319,7 @@ var SearchViewModel = function (collection_json, query_json) {
       query: ko.mapping.toJSON(self.query),
       layout: ko.mapping.toJSON(self.columns)
     }, function (data) {
-      self.response(data); // If error we should probably update only the facets
+      self.response(data); // Content not observable for performance
       self.results.removeAll();
       if (data.error) {
         $(document).trigger("error", data.error);