Bläddra i källkod

HUE-3294 [core] Added editor_embeddable and loader

Enrico Berti 9 år sedan
förälder
incheckning
6c5e48b1e7

+ 38 - 3
desktop/core/src/desktop/templates/responsive.mako

@@ -343,6 +343,10 @@ ${ hueIcons.symbols() }
       </a>
       ##<div data-bind='component: currentApp'></div>
       <div data-bind='text: currentApp'></div>
+      <!-- ko if: isLoadingEmbeddable -->
+      <i class="fa fa-spinner fa-spin"></i>
+      <!-- /ko -->
+      <div id="embeddable"></div>
     </div>
   </div>
 </div>
@@ -381,15 +385,45 @@ ${ assist.assistPanel() }
 
 
 <script type="text/javascript" charset="utf-8">
+
     var OnePageViewModel = function () {
       var self = this;
 
-      self.currentApp = ko.observable('editor');
+      self.EMBEDDABLE_PAGE_URLS = {
+        editor: '/notebook/editor_embeddable'
+      }
+
+      self.embeddable_cache = {};
+
+      self.currentApp = ko.observable('');
+      self.isLoadingEmbeddable = ko.observable(false);
+
+      self.currentApp.subscribe(function(newVal){
+        self.isLoadingEmbeddable(true);
+        if (typeof self.embeddable_cache[newVal] === 'undefined'){
+          $.ajax({
+            url: self.EMBEDDABLE_PAGE_URLS[newVal],
+            beforeSend:function (xhr) {
+              xhr.setRequestHeader('X-Requested-With', 'Hue');
+            },
+            dataType:'html',
+            success:function (response) {
+              self.embeddable_cache[newVal] = response;
+              $('#embeddable').html(response);
+              self.isLoadingEmbeddable(false);
+            }
+          });
+        }
+        else {
+          $('#embeddable').html(self.embeddable_cache[newVal]);
+          self.isLoadingEmbeddable(false);
+        }
+      });
 
       huePubSub.subscribe('switch.app', function (name) {
         console.log(name);
         self.currentApp(name);
-      })
+      });
     }
 
     var AssistViewModel = function (options) {
@@ -409,7 +443,8 @@ ${ assist.assistPanel() }
         }
       };
 
-      ko.applyBindings(new OnePageViewModel(), $('.page-content')[0]);
+      window.vm = new OnePageViewModel();
+      ko.applyBindings(window.vm, $('.page-content')[0]);
 
       //ko.applyBindings({}, $('.left-nav')[0])
       ko.applyBindings(new AssistViewModel(options), $('#assist-container')[0])

+ 45 - 0
desktop/libs/notebook/src/notebook/templates/editor_embeddable.mako

@@ -0,0 +1,45 @@
+## Licensed to Cloudera, Inc. under one
+## or more contributor license agreements.  See the NOTICE file
+## distributed with this work for additional information
+## regarding copyright ownership.  Cloudera, Inc. licenses this file
+## to you under the Apache License, Version 2.0 (the
+## "License"); you may not use this file except in compliance
+## with the License.  You may obtain a copy of the License at
+##
+##     http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+<%!
+  from desktop.views import commonheader, commonfooter
+  from desktop import conf
+  from django.utils.translation import ugettext as _
+%>
+
+<%namespace name="assist" file="/assist.mako" />
+<%namespace name="configKoComponents" file="/config_ko_components.mako" />
+<%namespace name="editorComponents" file="editor_components.mako" />
+<%namespace name="notebookKoComponents" file="notebook_ko_components.mako" />
+
+${ editorComponents.includes() }
+
+<style type="text/css">
+  .snippet {
+    margin-right: 10px;
+  }
+</style>
+
+${ editorComponents.topBar() }
+${ editorComponents.commonHTML() }
+
+${ assist.assistPanel() }
+${ assist.assistJSModels() }
+${ configKoComponents.config() }
+${ notebookKoComponents.downloadSnippetResults() }
+${ notebookKoComponents.snippetDbSelection() }
+
+${ editorComponents.commonJS() }
+

+ 1 - 0
desktop/libs/notebook/src/notebook/urls.py

@@ -41,6 +41,7 @@ urlpatterns = patterns('notebook.views',
   url(r'^copy/?$', 'copy', name='copy'),
 
   url(r'^editor/?$', 'editor', name='editor'),
+  url(r'^editor_embeddable/?$', 'editor_embeddable', name='editor_embeddable'),
   url(r'^editor_m/?$', 'editor_m', name='editor_m'),
   url(r'^browse/(?P<database>\w+)/(?P<table>\w+)/?$', 'browse', name='browse'),
   url(r'^execute_and_watch/?$', 'execute_and_watch', name='execute_and_watch'),

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

@@ -88,7 +88,7 @@ def notebook(request):
 
 
 @check_document_access_permission()
-def editor(request, is_mobile=False):
+def editor(request, is_mobile=False, is_embeddable=False):
   editor_id = request.GET.get('editor')
   editor_type = request.GET.get('type', 'hive')
 
@@ -96,7 +96,11 @@ def editor(request, is_mobile=False):
     document = Document2.objects.get(id=editor_id)
     editor_type = document.type.rsplit('-', 1)[-1]
 
-  template = 'editor_m.mako' if is_mobile else 'editor.mako'
+  template = 'editor.mako'
+  if is_mobile:
+    template = 'editor_m.mako'
+  if is_embeddable:
+    template = 'editor_embeddable.mako'
 
   return render(template, request, {
       'editor_id': editor_id or None,
@@ -112,6 +116,9 @@ def editor(request, is_mobile=False):
       })
   })
 
+@check_document_access_permission()
+def editor_embeddable(request):
+  return editor(request, False, True)
 
 @check_document_access_permission()
 def editor_m(request):