Browse Source

[search] Add see more or less on text facets

Romain Rigaux 11 năm trước cách đây
mục cha
commit
b975d24

+ 9 - 8
README.rst

@@ -12,12 +12,12 @@ It features:
 
       * File Browser for accessing HDFS
       * Hive Editor for developing and running Hive queries
-      * Impala App for executing Impala queries
-      * Search App for querying and exploring data with Solr
+      * Search App for querying, exploring, visualizing data and dashboards with Solr
+      * Impala App for executing interactive SQL queries
       * Spark Editor and Dashboard
       * Pig Editor for submitting Pig scripts
-      * Oozie App for submitting and monitoring workflows, coordinators and bundles
-      * HBase Browser for visualizing and modifying HBase tables
+      * Oozie Editor and Dashboard for submitting and monitoring workflows, coordinators and bundles
+      * HBase Browser for visualizing, querying and modifying HBase tables
       * Metastore Browser for accessing Hive metadata and HCatalog
       * Job Browser for accessing MapReduce jobs (MR1/MR2-YARN)
       * Job Designer for creating MapReduce/Streaming/Java jobs
@@ -150,12 +150,13 @@ namespace.  See ``apps/about/src/about/urls.py`` for an example.
 
 Main Stack
 ==========
+Hue would not be possible without:
 
    * Python 2.6 - 2.7
-   * Django 1.4 https://docs.djangoproject.com/en/1.4/
-   * Mako
-   * jQuery
-   * Bootstrap
+   * Django 1.4 (https://docs.djangoproject.com/en/1.4/)
+   * Knockout.js (http://knockoutjs.com/)
+   * jQuery (http://jquery.com/)
+   * Bootstrap (http://getbootstrap.com/)
 
 
 Community

+ 26 - 10
apps/search/src/search/templates/search2.mako

@@ -356,18 +356,34 @@ ${ commonheader(_('Search'), "search", user, "80px") | n,unicode }
         <div data-bind="foreach: $parent.counts">
           <div>
             <a href="javascript: void(0)">              
-              <!-- ko if: ! $data.selected -->
-                <span data-bind="text: $data.value, click: function(){ $root.query.toggleFacet({facet: $data, widget_id: $parent.id()}) }"></span>
-                <span class="counter" data-bind="text: ' (' + $data.count + ')', click: function(){ $root.query.toggleFacet({facet: $data, widget_id: $parent.id()}) }"></span>                
-              <!-- /ko -->
-              <!-- ko if: $data.selected -->
-                <span data-bind="click: function(){ $root.query.toggleFacet({facet: $data, widget_id: $parent.id()}) }">
-                  <span data-bind="text: $data.value"></span>
-                  <i class="fa fa-times"></i>
-                </span>
+              <!-- ko if: $index() != $parent.properties.limit() -->
+                <!-- ko if: ! $data.selected -->
+                  <span data-bind="text: $data.value, click: function(){ $root.query.toggleFacet({facet: $data, widget_id: $parent.id()}) }"></span>
+                  <span class="counter" data-bind="text: ' (' + $data.count + ')', click: function(){ $root.query.toggleFacet({facet: $data, widget_id: $parent.id()}) }"></span>                
+                <!-- /ko -->
+                <!-- ko if: $data.selected -->
+                  <span data-bind="click: function(){ $root.query.toggleFacet({facet: $data, widget_id: $parent.id()}) }">
+                    <span data-bind="text: $data.value"></span>
+                    <i class="fa fa-times"></i>
+                  </span>
+                <!-- /ko -->
               <!-- /ko -->
               <!-- ko if: $index() == $parent.properties.limit() -->
-                </br>${ _('Show more...') }
+                <!-- ko if: $parent.properties.prevLimit == undefined || $parent.properties.prevLimit == $parent.properties.limit() -->
+                  <span data-bind="click: function(){ $root.collection.upDownFacetLimit($parent.id(), 'up') }">
+                    ${ _('Show more...') }
+                  </span>
+                <!-- /ko -->
+                <!-- ko if: $parent.properties.prevLimit != undefined && $parent.properties.prevLimit != $parent.properties.limit() -->
+                  <span data-bind="click: function(){ $root.collection.upDownFacetLimit($parent.id(), 'up') }">
+                    ${ _('Show more') }
+                  </span> 
+                  /             
+                  <span data-bind="click: function(){ $root.collection.upDownFacetLimit($parent.id(), 'down') }">
+                    ${ _('less...') }
+                  </span>                    
+                </span>
+                <!-- /ko -->
               <!-- /ko -->
             </a>
           </div>

+ 16 - 0
apps/search/static/js/search.ko.js

@@ -594,6 +594,22 @@ var Collection = function (vm, collection) {
   
     vm.search();
   };
+  
+  self.upDownFacetLimit = function (facet_id, direction) {
+    var facet = self.getFacetById(facet_id);
+    
+    if (facet.properties.prevLimit == undefined) {
+      facet.properties.prevLimit = facet.properties.limit();
+    }
+    
+    if (direction == 'up') {
+      facet.properties.limit(facet.properties.limit() + 10);
+    } else {
+      facet.properties.limit(facet.properties.limit() - 10);
+    }
+    
+    vm.search();
+  };
 };
 
 var NewTemplate = function (vm, initial) {

+ 11 - 0
desktop/core/static/ext/js/knockout-switch-case.min.js

@@ -0,0 +1,11 @@
+/*
+ SWITCH/CASE binding for Knockout http://knockoutjs.com/
+ (c) Michael Best
+ License: MIT (http://www.opensource.org/licenses/mit-license.php)
+ Version 2.0.1
+*/
+(function(b,h){"function"===typeof define&&define.amd?define(["knockout"],h):h(b.ko)})(this,function(b){function h(a,c){var f=p(c.$switchValueAccessor());return"boolean"==typeof f?a?f:!f:"boolean"==typeof a?a:a instanceof Array?-1!==b.utils.arrayIndexOf(a,f):a==f}function v(a,b){return!h(a,b)}function w(a){return function(){return a}}function g(a,c,f){var q=c?v:h;a||(a="if");f||(f=w);return{flags:d[a].flags,init:function(f,c,q,k,e){if(!e.$switchSkipNextArray)throw Error("case binding must only be used with a switch binding");
+if(e.$switchIndex!==m)throw Error("case binding cannot be nested");e.$switchIndex=e.$switchSkipNextArray.push(b.observable(!1))-1;if(d[a].init)return d[a].init(f,function(){return{}},q,k,e)},update:function(b,c,k,h,e){var g=e.$switchIndex,m=g===e.$switchSkipNextArray.length-1,n,l;g&&e.$switchSkipNextArray[g-1]()?(c=!1,n=!0):(c=p(c()),c===e.$else?(c=e.$switchDefault()||m,n=!1):l=n=c=q(c,e));d[a].update(b,f(c),k,h,e);e.$switchSkipNextArray[g](n);l?e.$switchDefault(!1):!n&&m&&e.$switchDefault(!0)}}}
+function r(a,c,b){k.allowedBindings[a]&&(k.allowedBindings[b]=!0);return g(a,"casenot"===c)}function x(a,c,b){return r(c,a,b)}function s(a,b){d[a]=g("if",b);t[a]=!1;k.allowedBindings[a]=!0;d[a].makeSubkeyHandler=x;d[a].getNamespacedHandler=r}var m;if(!b.virtualElements)throw Error("Switch-case requires at least Knockout 2.1");var k=b.virtualElements,l=b.bindingFlags||{},t=b.bindingRewriteValidators||b.jsonExpressionRewriting.bindingRewriteValidators,p=b.utils.unwrapObservable,d=b.bindingHandlers,
+u={};d["switch"]={flags:l.contentBind|l.canUseVirtual|l.noValue,init:function(a,c,f,d,g){var h={$switchSkipNextArray:[],$switchValueAccessor:c,$switchDefault:b.observable(!0),$default:u,$else:u},l=[];b.computed(function(){var a=p(c());h.$value=a;b.utils.arrayForEach(l,function(b){b.$value=a})},null,{disposeWhenNodeIsRemoved:a});for(f=k.firstChild(a);a=f;)switch(f=k.nextSibling(a),a.nodeType){case 1:case 8:d=g.extend(h),d.$switchIndex=m,b.applyBindings(d,a),d.$switchIndex!==m&&l.push(d)}return{controlsDescendantBindings:!0}},
+preprocess:function(a){return a||"true"}};t["switch"]=!1;k.allowedBindings["switch"]=!0;s("case");s("casenot",!0);d["case.visible"]=g("visible");d["casenot.visible"]=g("visible",!0);d["switch"].makeCaseHandler=g});