Преглед изворни кода

HUE-9066 [gist] Adding link in popup

Romain пре 6 година
родитељ
комит
18f395b1ad

+ 12 - 2
desktop/core/src/desktop/api2.py

@@ -823,9 +823,13 @@ def user_preferences(request, key=None):
 
 @api_error_handler
 def gist_create(request):
+  '''
+  Only supporting Editor currently.
+  '''
   response = {'status': 0}
 
   text = request.POST.get('text', '')
+  gist_type = request.POST.get('type', 'query-hive')
   name = request.POST.get('name', '')
   description = request.POST.get('description', '')
 
@@ -833,11 +837,13 @@ def gist_create(request):
     name=name,
     type='gist',
     owner=request.user,
-    data=json.dumps({'text': text})
+    data=json.dumps({'text': text}),
+    extra=gist_type
   )
 
   response['id'] = gist_doc.id
   response['uuid'] = gist_doc.uuid
+  response['link'] = '/gist?=%s' % gist_doc.uuid
 
   return JsonResponse(response)
 
@@ -847,7 +853,11 @@ def gist_get(request):
 
   gist_doc = _get_gist_document(uuid=gist_uuid)
 
-  return redirect('/hue/editor?gist=fdbe0862-cd1f-40b5-9801-a5abfb7c2f77&type=impala')
+  return redirect('%(host)s/hue/editor?gist=%(uuid)s&type=%s(type)' % {
+    'host': get_host(),
+    'uuid': gist_doc.uuid,
+    'type': gist_doc.extra.rsplit('-')[-1]
+  })
 
 
 def search_entities(request):

+ 4 - 2
desktop/core/src/desktop/js/apps/notebook/snippet.js

@@ -1924,13 +1924,15 @@ class Snippet {
           })
           .done(data => {
             if (data.status == 0) {
-              $(document).trigger('info', 'Gist created at ..' + data);
+              $(document).trigger('showGistModal', {
+                link: data.link
+              });
             } else {
               self._ajaxError(data);
             }
           });
       }
-      hueAnalytics.log('notebook', 'format');
+      hueAnalytics.log('gist', self.type());
     };
 
     self.format = function() {

+ 29 - 5
desktop/core/src/desktop/templates/common_header_footer_components.mako

@@ -280,11 +280,33 @@ from metadata.conf import has_optimizer, OPTIMIZER
   </div>
   <div class="modal-body">
     <table class="table table-condensed">
-
     </table>
   </div>
 </div>
 
+<div id="gistModal" class="modal hide fade">
+  <div class="modal-header">
+    <button type="button" class="close" data-dismiss="modal" aria-label="${ _('Close') }"><span aria-hidden="true">&times;</span></button>
+    <h2 class="modal-title">${ _('Shareable link') }</h2>
+  </div>
+  <div class="modal-body">
+    <div class="row-fluid">
+      <div class="span12">
+        <div>
+          <input class="input-xlarge" name="gist-link" type="text" placeholder="${ _('Link') }"/>
+        </div>
+        <div class="input-prepend">
+          <a class="btn" data-dismiss="modal">${_('Copy')}</a>
+          <span class="add-on muted"><i class="fa fa-clipboard"></i></span>
+        </div>
+      </div>
+    </div>
+  </div>
+  <div class="modal-footer">
+    <a class="btn" data-dismiss="modal">${_('Close')}</a>
+  </div>
+</div>
+
 <div class="clipboard-content"></div>
 
 <script type="text/javascript">
@@ -565,9 +587,12 @@ from metadata.conf import has_optimizer, OPTIMIZER
     };
   }
 
+  $(document).on('showGistModal', (e, data) => {
+    $('#gistModal input[name="gist-link"]').val(data['link']);
+    $('#gistModal').modal('show');
+  });
 
-  %if collect_usage:
-
+  % if collect_usage:
     (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
     (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
     m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
@@ -593,8 +618,7 @@ from metadata.conf import has_optimizer, OPTIMIZER
         });
       }
     }
-
-  %endif
+  % endif
 
 </script>
 </%def>

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

@@ -112,9 +112,8 @@ def editor(request, is_mobile=False, is_embeddable=False):
     return notebook(request)
 
   if editor_type == 'gist':
-    _get_gist_document(uuid=gist_id)
-    editor_type = 'query-impala'
-  #   manage unfurling
+    gist_doc = _get_gist_document(uuid=gist_id)
+    editor_type = gist_doc.extra
 
   if editor_id and not gist_id:  # Open existing saved editor document
     editor_type = _get_editor_type(editor_id)