浏览代码

[editor] Load back impala queries in the Impala mode of the editor

Reminder, document types are like 'query-hive'.

I tried to split it into type = 'query' and 'extra' = 'hive' but then we can't group documents in one shot.
Romain Rigaux 10 年之前
父节点
当前提交
eb3f452

+ 8 - 1
desktop/core/src/desktop/api2.py

@@ -37,7 +37,14 @@ LOG = logging.getLogger(__name__)
 
 
 def get_documents(request):
-  return JsonResponse({'documents': [doc.to_dict() for doc in Document2.objects.filter(owner=request.user)]})
+  filters = {
+      'owner': request.user
+  }
+
+  if request.GET.get('type'):
+    filters['type'] = json.loads(request.GET.get('type'))
+
+  return JsonResponse({'documents': [doc.to_dict() for doc in Document2.objects.filter(**filters)]})
 
 
 def get_document(request):

+ 6 - 0
desktop/core/src/desktop/models.py

@@ -576,6 +576,11 @@ class Document(models.Model):
         return staticfiles_storage.url('oozie/art/icon_oozie_bundle_48.png')
       elif self.extra == 'notebook':
         return staticfiles_storage.url('notebook/art/icon_notebook_48.png')
+      elif self.extra.startswith('query'):
+        if self.extra == 'query-impala':
+          return staticfiles_storage.url(apps['impala'].icon_path)
+        else:
+          return staticfiles_storage.url(apps['beeswax'].icon_path)
       elif self.extra.startswith('search'):
         return staticfiles_storage.url('search/art/icon_search_48.png')
       elif self.content_type.app_label == 'beeswax':
@@ -763,6 +768,7 @@ class Document2(models.Model):
 
   class Meta:
     unique_together = ('uuid', 'version', 'is_history')
+    ordering = ["-last_modified"]
 
   def natural_key(self):
     return (self.uuid, self.version, self.is_history)

+ 2 - 2
desktop/libs/notebook/src/notebook/templates/editor_components.mako

@@ -207,7 +207,7 @@ ${ require.config() }
         </a>
         % endif
 
-        <a class="btn" href="${ url('notebook:notebooks') }" title="${ _('Notebooks') }" rel="tooltip" data-placement="bottom">
+        <a class="btn" href="${ url('notebook:notebooks') }" title="${ _('Queries' if mode == 'editor' else 'Notebooks') }" rel="tooltip" data-placement="bottom">
           <i class="fa fa-tags"></i>
         </a>
       </div>
@@ -416,7 +416,7 @@ ${ login_modal(request).content | n,unicode }
     </div>
 
     <div data-bind="visible: status() == 'expired', css: resultsKlass" style="display:none;">
-      <pre class="margin-top-10 no-margin-bottom"><i class="fa fa-check muted"></i> ${ _("Result has expired.") }</pre>
+      <pre class="margin-top-10 no-margin-bottom"><i class="fa fa-check muted"></i> ${ _("Results have expired.") }</pre>
     </div>
 
     <div data-bind="visible: status() == 'available' && ! result.fetchedOnce(), css: resultsKlass" style="display:none;">

+ 10 - 9
desktop/libs/notebook/src/notebook/views.py

@@ -36,6 +36,14 @@ from notebook.conf import get_interpreters
 LOG = logging.getLogger(__name__)
 
 
+def notebooks(request):
+  notebooks = [d.content_object.to_dict() for d in Document.objects.get_docs(request.user, Document2, qfilter=Q(extra='notebook') | Q(extra__startswith='query')) if not d.content_object.is_history]
+
+  return render('notebooks.mako', request, {
+      'notebooks_json': json.dumps(notebooks, cls=JSONEncoderForHTML)
+  })
+
+
 @check_document_access_permission()
 def notebook(request):
   notebook_id = request.GET.get('notebook')
@@ -69,10 +77,11 @@ def editor(request):
 
   if editor_id:
     editor = Notebook(document=Document2.objects.get(id=editor_id))
+    editor_type = editor.get_data()['type'].rsplit('-', 1)[-1]
   else:
     editor = Notebook()
     data = editor.get_data()
-    data['name'] = 'Unsaved %s Query' % editor_type.title()
+    data['name'] = 'Untitled %s Query' % editor_type.title()
     data['type'] = 'query-%s' % editor_type
     editor.data = json.dumps(data)
 
@@ -142,14 +151,6 @@ def browse(request, database, table):
   })
 
 
-def notebooks(request):
-  notebooks = [d.content_object.to_dict() for d in Document.objects.get_docs(request.user, Document2, qfilter=Q(extra='notebook') | Q(extra__startswith='query')) if not d.content_object.is_history]
-
-  return render('notebooks.mako', request, {
-      'notebooks_json': json.dumps(notebooks, cls=JSONEncoderForHTML)
-  })
-
-
 @check_document_modify_permission()
 def delete(request):
   notebooks = json.loads(request.POST.get('notebooks', '[]'))