瀏覽代碼

HUE-3228 [dashboard] Refactor the dashboard configuration

Romain Rigaux 8 年之前
父節點
當前提交
34ea0a0

+ 68 - 33
desktop/libs/dashboard/src/dashboard/conf.py

@@ -15,59 +15,94 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from django.utils.translation import ugettext_lazy as _t
+from django.utils.translation import ugettext as _, ugettext_lazy as _t
 
 from desktop.conf import is_hue4
-from desktop.lib.conf import Config, UnspecifiedConfigSection, ConfigSection, coerce_json_dict, coerce_bool
+from desktop.lib.conf import Config, UnspecifiedConfigSection, ConfigSection, coerce_bool
+from desktop.appmanager import get_apps_dict
+from notebook.conf import get_ordered_interpreters
 
 
 IS_ENABLED = Config(
   key="is_enabled",
-  help=_t("Activate the app in the menu."),
+  help=_t("Activate the Dashboard link in the menu."),
   dynamic_default=is_hue4,
   private=True,
   type=coerce_bool
 )
 
-# ANALYTICS_ENABLED 
-SUPPORT_LATEST_SOLR = Config(
-  key="support_latest_solr",
-  help=_t("Use latest Solr 5+ functionalities like Analytics Facets and Nested Documents (warning: still in beta)."),
-  default=True,
-  type=coerce_bool
-)
+# [[properties]]
+#  [[[solr]]]
+#  analytics=false
+#  nesting=false
+#  [[sql]]]
+#  analytics=true
+#  nesting=false
+ 
+def get_properties():
+  if PROPERTIES.get():
+    engines = PROPERTIES.get()
+    return dict([
+      (i, {
+        'analytics': engines[i].ANALYTICS.get(),
+        'nesting': engines[i].NESTING.get()
+      }) for i in engines]
+    )
+  else:
+    return {
+      'solr': {
+        'analytics': False,
+        'nesting': False,
+      },
+      'sql': {
+        'analytics': True,
+        'nesting': False,
+      },
+    }
+    
+def get_engines(user):
+  engines = []
+  apps = get_apps_dict()
+  settings = get_properties()
+
+  if 'search' in apps:
+    engines.append({
+      'name': _('index (Solr)'),
+      'type': 'solr',
+      'analytics': settings.get('solr') and settings['solr'].get('analytics'),
+      'nesting': settings.get('solr') and settings['solr'].get('nesting'),
+    })
+
+  if 'beeswax' in apps or 'rdbms' in apps:
+    engines += [{
+          'name': _('table (%s)') % interpreter['name'],
+          'type': interpreter['type'],
+          'async': interpreter['interface'] == 'hiveserver2',
+          'analytics': settings.get('sql') and settings['sql'].get('analytics'),
+          'nesting': settings.get('sql') and settings['sql'].get('nesting'),
+      }
+      for interpreter in get_ordered_interpreters(user) if interpreter['interface'] in ('hiveserver2', 'jdbc', 'rdbms')
+    ]
+    
+  return engines
 
-NESTED_ENABLED = Config(
-  key="support_latest_solr",
-  help=_t("Use latest Solr 5+ functionalities like Analytics Facets and Nested Documents (warning: still in beta)."),
-  default=True,
-  type=coerce_bool
-)
 
-# TODO [[interfaces]] instead
-IS_SQL_ENABLED = Config(
-  key="is_sql_enabled",
-  help=_t("Offer to use SQL engines to compute the dashboards."),
-  dynamic_default=is_hue4,
-  private=True,
-  type=coerce_bool
-)
 
-INTERPRETERS = UnspecifiedConfigSection(
-  "connectors",
+PROPERTIES = UnspecifiedConfigSection(
+  "properties",
   help="One entry for each type of snippet.",
   each=ConfigSection(
-    help=_t("Define the name and how to connect and execute the language."),
+    help=_t("Name of the interface to use as query engine for the dashboard, e.g. solr, sql."),
     members=dict(
-      ANALYTICS_SUPPORT=Config(
-          "name",
-          help=_t("The name of the snippet."),
+      ANALYTICS=Config(
+          "analytics",
+          help=_t("Support analytics facets or not."),
           default=False,
           type=coerce_bool,
       ),
-      NESTED_SUPPORT=Config(
-          "name",
-          help=_t("The name of the snippet."),
+      NESTING=Config(
+          "nesting",
+          help=_t("Support nested documents or not."),
           default=False,
           type=coerce_bool,
       ),

+ 1 - 18
desktop/libs/dashboard/src/dashboard/models.py

@@ -30,9 +30,7 @@ from desktop.lib.i18n import smart_unicode, smart_str
 from desktop.models import get_data_link
 
 from libsolr.api import SolrApi
-from notebook.conf import get_ordered_interpreters
 
-from dashboard.conf import IS_SQL_ENABLED, SUPPORT_LATEST_SOLR
 from dashboard.dashboard_api import get_engine
 
 
@@ -102,7 +100,7 @@ class Collection2(object):
     for field in props['collection']['template']['fieldsAttributes']:
       if 'type' not in field:
         field['type'] = 'string'
-    if 'nested' not in props['collection'] and SUPPORT_LATEST_SOLR.get():
+    if 'nested' not in props['collection']:
       props['collection']['nested'] = {
         'enabled': False,
         'schema': []
@@ -753,21 +751,6 @@ def _convert_nested_to_augmented_pivot_nd(facet_fields, facet_id, counts, select
     c['fq_values'] = fq_values
 
 
-def get_engines(user):
-  engines = [{'name': _('index (Solr)'), 'type': 'solr'}]
-
-  if IS_SQL_ENABLED.get():
-    engines += [{
-          'name': _('table (%s)') % interpreter['name'],
-          'type': interpreter['type'],
-          'async': interpreter['interface'] == 'hiveserver2'
-      }
-      for interpreter in get_ordered_interpreters(user) if interpreter['interface'] in ('hiveserver2', 'jdbc', 'rdbms')
-    ]
-
-  return engines
-
-
 def augment_solr_exception(response, collection):
   response.update(
   {

+ 8 - 4
desktop/libs/dashboard/src/dashboard/static/dashboard/js/search.ko.js

@@ -461,7 +461,12 @@ var Collection = function (vm, collection) {
   self.queryResult = ko.observable(new QueryResult(self, {
     type: self.engine(),
   }));
-  //self.hasAnalytics = ko.observable(typeof collection.hasAnalytics != "undefined" && collection.hasAnalytics != null ? collection.hasAnalytics : false);
+  self.supportAnalytics = ko.pureComputed(function() {
+    return self.engine()['analytics'];
+  });
+  self.supportNesting = ko.pureComputed(function() {
+    return self.engine()['nesting'];
+  });
   self.nested = ko.mapping.fromJS(collection.nested);
   self.nestedNames = ko.computed(function() {
     function flatten(values) {
@@ -1205,7 +1210,7 @@ var Collection = function (vm, collection) {
         }
     }).fail(function (xhr, textStatus, errorThrown) {});
 
-    if (vm.isLatest()) {
+    if (self.supportNesting()) {
       self.getNestedDocuments();
     }
   };
@@ -1474,12 +1479,11 @@ var SearchViewModel = function (collection_json, query_json, initial_json) {
 
   self.intervalOptions = ko.observableArray(ko.bindingHandlers.daterangepicker.INTERVAL_OPTIONS);
   self.isNested = ko.observable(false);
-  self.isLatest = ko.mapping.fromJS(typeof initial_json.is_latest != "undefined" ? initial_json.is_latest : false);
 
   // Models
+  self.initial = new NewTemplate(self, initial_json);
   self.collection = new Collection(self, collection_json.collection);
   self.query = new Query(self, query_json);
-  self.initial = new NewTemplate(self, initial_json);
 
   // UI
   self.selectedQDefinition = ko.observable();

+ 17 - 17
desktop/libs/dashboard/src/dashboard/templates/common_search.mako

@@ -203,7 +203,7 @@ from desktop.views import commonheader, commonfooter, _ko
          </a>
     </div>
 
-    <div data-bind="visible: $root.isLatest,
+    <div data-bind="visible: $root.collection.supportAnalytics,
                     css: { 'draggable-widget': true, 'disabled': !availableDraggableNumbers() },
                     draggable: {data: draggableCounter(), isEnabled: availableDraggableNumbers,
                     options: {'start': function(event, ui){lastWindowScrollPosition = $(window).scrollTop();$('.card-body').slideUp('fast');},
@@ -216,7 +216,7 @@ from desktop.views import commonheader, commonfooter, _ko
       </%def>
 
       <%def name="widgets()">
-    <div data-bind="visible: ! $root.isLatest(), css: { 'draggable-widget': true, 'disabled': !availableDraggableChart() },
+    <div data-bind="visible: ! $root.collection.supportAnalytics(), css: { 'draggable-widget': true, 'disabled': !availableDraggableChart() },
                     draggable: {data: draggableFacet(), isEnabled: availableDraggableChart,
                     options: {'start': function(event, ui){lastWindowScrollPosition = $(window).scrollTop();$('.card-body').slideUp('fast');},
                               'stop': function(event, ui){$('.card-body').slideDown('fast', function(){$(window).scrollTop(lastWindowScrollPosition)});}}}"
@@ -225,7 +225,7 @@ from desktop.views import commonheader, commonfooter, _ko
                        <i class="fa fa-sort-amount-asc"></i>
          </a>
     </div>
-    <div data-bind="visible: $root.isLatest(), css: { 'draggable-widget': true, 'disabled': !availableDraggableChart() },
+    <div data-bind="visible: $root.collection.supportAnalytics(), css: { 'draggable-widget': true, 'disabled': !availableDraggableChart() },
                     draggable: {data: draggableTextFacet(), isEnabled: availableDraggableChart,
                     options: {'start': function(event, ui){lastWindowScrollPosition = $(window).scrollTop();$('.card-body').slideUp('fast');},
                               'stop': function(event, ui){$('.card-body').slideDown('fast', function(){$(window).scrollTop(lastWindowScrollPosition)});}}}"
@@ -234,7 +234,7 @@ from desktop.views import commonheader, commonfooter, _ko
                        <i class="fa fa-sort-amount-asc"></i>
          </a>
     </div>
-    <div data-bind="visible: ! $root.isLatest(), css: { 'draggable-widget': true, 'disabled': !availableDraggableChart() },
+    <div data-bind="visible: ! $root.collection.supportAnalytics(), css: { 'draggable-widget': true, 'disabled': !availableDraggableChart() },
                     draggable: {data: draggablePie(), isEnabled: availableDraggableChart,
                     options: {'start': function(event, ui){lastWindowScrollPosition = $(window).scrollTop();$('.card-body').slideUp('fast');},
                               'stop': function(event, ui){$('.card-body').slideDown('fast', function(){$(window).scrollTop(lastWindowScrollPosition)});}}}"
@@ -243,7 +243,7 @@ from desktop.views import commonheader, commonfooter, _ko
                        <i class="hcha hcha-pie-chart"></i>
          </a>
     </div>
-    <div data-bind="visible: $root.isLatest(), css: { 'draggable-widget': true, 'disabled': !availableDraggableChart() },
+    <div data-bind="visible: $root.collection.supportAnalytics(), css: { 'draggable-widget': true, 'disabled': !availableDraggableChart() },
                     draggable: {data: draggablePie2(), isEnabled: availableDraggableChart,
                     options: {'start': function(event, ui){lastWindowScrollPosition = $(window).scrollTop();$('.card-body').slideUp('fast');},
                               'stop': function(event, ui){$('.card-body').slideDown('fast', function(){$(window).scrollTop(lastWindowScrollPosition)});}}}"
@@ -252,7 +252,7 @@ from desktop.views import commonheader, commonfooter, _ko
                        <i class="fa fa-pie-chart"></i>
          </a>
     </div>
-    <div data-bind="visible: ! $root.isLatest(),
+    <div data-bind="visible: ! $root.collection.supportAnalytics(),
                     css: { 'draggable-widget': true, 'disabled': !availableDraggableChart() },
                     draggable: {data: draggableBar(), isEnabled: availableDraggableChart,
                     options: {'start': function(event, ui){lastWindowScrollPosition = $(window).scrollTop();$('.card-body').slideUp('fast');},
@@ -262,7 +262,7 @@ from desktop.views import commonheader, commonfooter, _ko
                        <i class="hcha hcha-bar-chart"></i>
          </a>
     </div>
-    <div data-bind="visible: $root.isLatest(),
+    <div data-bind="visible: $root.collection.supportAnalytics(),
                     css: { 'draggable-widget': true, 'disabled': ! availableDraggableChart() },
                     draggable: {data: draggableBucket(), isEnabled: availableDraggableChart,
                     options: {'start': function(event, ui){lastWindowScrollPosition = $(window).scrollTop();$('.card-body').slideUp('fast');},
@@ -272,7 +272,7 @@ from desktop.views import commonheader, commonfooter, _ko
                        <i class="fa fa-bar-chart"></i>
          </a>
     </div>
-    <div data-bind="visible: ! $root.isLatest(),
+    <div data-bind="visible: ! $root.collection.supportAnalytics(),
                     css: { 'draggable-widget': true, 'disabled': !availableDraggableNumbers() },
                     draggable: {data: draggableLine(), isEnabled: availableDraggableNumbers,
                     options: {'start': function(event, ui){lastWindowScrollPosition = $(window).scrollTop();$('.card-body').slideUp('fast');},
@@ -282,7 +282,7 @@ from desktop.views import commonheader, commonfooter, _ko
                        <i class="hcha hcha-line-chart"></i>
          </a>
     </div>
-    <div data-bind="visible: ! $root.isLatest(), css: { 'draggable-widget': true, 'disabled': false },
+    <div data-bind="visible: ! $root.collection.supportAnalytics(), css: { 'draggable-widget': true, 'disabled': false },
                     draggable: {data: draggableTree(), isEnabled: true,
                     options: {'start': function(event, ui){lastWindowScrollPosition = $(window).scrollTop();$('.card-body').slideUp('fast');},
                               'stop': function(event, ui){$('.card-body').slideDown('fast', function(){$(window).scrollTop(lastWindowScrollPosition)});}}}"
@@ -291,7 +291,7 @@ from desktop.views import commonheader, commonfooter, _ko
                        <i class="fa fa-sitemap fa-rotate-270"></i>
          </a>
     </div>
-    <div data-bind="visible: $root.isLatest(), css: { 'draggable-widget': true, 'disabled': false },
+    <div data-bind="visible: $root.collection.supportAnalytics(), css: { 'draggable-widget': true, 'disabled': false },
                     draggable: {data: draggableTree2(), isEnabled: true,
                     options: {'start': function(event, ui){lastWindowScrollPosition = $(window).scrollTop();$('.card-body').slideUp('fast');},
                               'stop': function(event, ui){$('.card-body').slideDown('fast', function(){$(window).scrollTop(lastWindowScrollPosition)});}}}"
@@ -300,7 +300,7 @@ from desktop.views import commonheader, commonfooter, _ko
                        <i class="fa fa-sitemap fa-rotate-270"></i>
          </a>
     </div>
-    <div data-bind="visible: ! $root.isLatest(),
+    <div data-bind="visible: ! $root.collection.supportAnalytics(),
                     css: { 'draggable-widget': true, 'disabled': false },
                     draggable: {data: draggableHeatmap(), isEnabled: true,
                     options: {'start': function(event, ui){lastWindowScrollPosition = $(window).scrollTop();$('.card-body').slideUp('fast');},
@@ -310,7 +310,7 @@ from desktop.views import commonheader, commonfooter, _ko
                        <i class="fa fa-th"></i>
          </a>
     </div>
-    <div data-bind="visible: ! $root.isLatest(), css: { 'draggable-widget': true, 'disabled': ! availableDraggableHistogram() },
+    <div data-bind="visible: ! $root.collection.supportAnalytics(), css: { 'draggable-widget': true, 'disabled': ! availableDraggableHistogram() },
                     draggable: {data: draggableHistogram(), isEnabled: availableDraggableHistogram,
                     options: {'start': function(event, ui){lastWindowScrollPosition = $(window).scrollTop();$('.card-body').slideUp('fast');},
                               'stop': function(event, ui){$('.card-body').slideDown('fast', function(){$(window).scrollTop(lastWindowScrollPosition)});}}}"
@@ -319,7 +319,7 @@ from desktop.views import commonheader, commonfooter, _ko
                        <i class="hcha hcha-timeline-chart"></i>
          </a>
     </div>
-    <div data-bind="visible: $root.isLatest(), css: { 'draggable-widget': true, 'disabled': ! availableTimeline() },
+    <div data-bind="visible: $root.collection.supportAnalytics(), css: { 'draggable-widget': true, 'disabled': ! availableTimeline() },
                     draggable: {data: draggableTimeline(), isEnabled: availableTimeline,
                     options: {'start': function(event, ui){lastWindowScrollPosition = $(window).scrollTop();$('.card-body').slideUp('fast');},
                               'stop': function(event, ui){$('.card-body').slideDown('fast', function(){$(window).scrollTop(lastWindowScrollPosition)});}}}"
@@ -328,7 +328,7 @@ from desktop.views import commonheader, commonfooter, _ko
                        <i class="fa fa-line-chart"></i>
          </a>
     </div>
-    <div data-bind="visible: ! $root.isLatest(), css: { 'draggable-widget': true, 'disabled': ! availableDraggableMap() },
+    <div data-bind="visible: ! $root.collection.supportAnalytics(), css: { 'draggable-widget': true, 'disabled': ! availableDraggableMap() },
                     draggable: {data: draggableMap(), isEnabled: availableDraggableMap,
                     options: {'start': function(event, ui){lastWindowScrollPosition = $(window).scrollTop();$('.card-body').slideUp('fast');},
                               'stop': function(event, ui){$('.card-body').slideDown('fast', function(){$(window).scrollTop(lastWindowScrollPosition)});}}}"
@@ -337,7 +337,7 @@ from desktop.views import commonheader, commonfooter, _ko
                        <i class="hcha hcha-map-chart"></i>
          </a>
    </div>
-    <div data-bind="visible: $root.isLatest(), css: { 'draggable-widget': true, 'disabled': ! availableDraggableMap() },
+    <div data-bind="visible: $root.collection.supportAnalytics(), css: { 'draggable-widget': true, 'disabled': ! availableDraggableMap() },
                     draggable: {data: draggableGradienMap(), isEnabled: availableDraggableMap,
                     options: {'start': function(event, ui){lastWindowScrollPosition = $(window).scrollTop();$('.card-body').slideUp('fast');},
                               'stop': function(event, ui){$('.card-body').slideDown('fast', function(){$(window).scrollTop(lastWindowScrollPosition)});}}}"
@@ -2524,7 +2524,7 @@ ${ dashboard.layout_skeleton() }
                 </label>
               </div>
             </div>
-            <!-- ko if: $root.isLatest -->
+            <!-- ko if: $root.collection.supportAnalytics -->
             <div class="control-group">
               <label class="control-label">${ _('Nested documents') }</label>
               <div class="controls">
@@ -2725,7 +2725,7 @@ ${ dashboard.layout_skeleton() }
 
 
 <script type="text/html" id="nested-document-filter">
-  <!-- ko if: $root.isLatest -->
+  <!-- ko if: $root.collection.supportAnalytics -->
   <span data-bind="visible: $root.collection.nested.enabled" >
     <a class="btn pointer" title="${ _('Nested schema') }" rel="tooltip" data-placement="bottom" data-toggle="modal" data-target="#settingsDemiModal">
       <i class="fa fa-sitemap"></i>

+ 4 - 2
desktop/libs/dashboard/src/dashboard/views.py

@@ -31,7 +31,8 @@ from search.conf import LATEST
 
 from dashboard.dashboard_api import get_engine
 from dashboard.decorators import allow_owner_only
-from dashboard.models import Collection2, get_engines
+from dashboard.models import Collection2
+from dashboard.conf import get_engines
 from dashboard.controller import DashboardController, can_edit_index
 
 
@@ -131,7 +132,8 @@ def new_search_embeddable(request):
   return new_search(request, True)
 
 def browse(request, name, is_mobile=False):
-  collections = DashboardController(request.user).get_all_indexes() # TODO convert
+  engine = request.GET.get('engine', 'solr')
+  collections = get_engine(request.user, engine).datasets()
   if not collections:
     return no_collections(request)
 

+ 1 - 1
desktop/libs/notebook/src/notebook/conf.py

@@ -25,7 +25,7 @@ from django.utils.translation import ugettext_lazy as _t
 from desktop import appmanager
 from desktop.conf import is_hue4
 from desktop.lib.conf import Config, UnspecifiedConfigSection, ConfigSection,\
-  coerce_json_dict, coerce_string, coerce_bool, coerce_csv
+  coerce_json_dict, coerce_bool, coerce_csv
 
 
 def is_oozie_enabled():