瀏覽代碼

HUE-7065 [dashboard] Integrate sharing button into the Dashboard

jdesjean 8 年之前
父節點
當前提交
5929e00

+ 3 - 0
desktop/libs/dashboard/src/dashboard/static/dashboard/js/search.ko.js

@@ -1502,6 +1502,9 @@ var SearchViewModel = function (collection_json, query_json, initial_json) {
     // Models
     self.initial = new NewTemplate(self, self.initialJson);
     self.collection = new Collection(self, self.collectionJson.collection);
+    self.isSaved = ko.computed(function() {
+      return !!self.collection.id();
+    });
     self.query = new Query(self, self.queryJson);
 
     // UI

+ 4 - 2
desktop/libs/dashboard/src/dashboard/templates/common_admin_collections.mako

@@ -184,8 +184,10 @@ ${ commonimportexport(request) | n,unicode }
   var viewModel = new SearchCollectionsModel(appProperties);
   ko.applyBindings(viewModel, $("#collectionsComponents")[0]);
 
-  shareViewModel = initSharing("#documentShareModal");
-  shareViewModel.setDocUuid('');
+  if (!shareViewModel) {
+    shareViewModel = initSharing("#documentShareModal");
+    shareViewModel.setDocUuid('');
+  }
 
   $(document).ready(function () {
     viewModel.updateCollections();

+ 15 - 1
desktop/libs/dashboard/src/dashboard/templates/common_search.mako

@@ -18,7 +18,7 @@
 from django.utils.translation import ugettext as _
 
 from desktop import conf
-from desktop.views import commonheader, commonfooter, _ko
+from desktop.views import commonheader, commonfooter, _ko, commonshare
 %>
 
 <%namespace name="dashboard" file="common_dashboard.mako" />
@@ -68,6 +68,12 @@ from desktop.views import commonheader, commonfooter, _ko
       <i class="fa fa-save"></i>
     </a>
     % endif
+    <a class="share-link btn" rel="tooltip" data-placement="bottom" data-bind="click: prepareShareModal,
+      attr: {'data-original-title': '${ _ko("Share") } ' + name},
+      css: {'isShared': isShared(), 'btn': true},
+      visible: isSaved()">
+      <i class="fa fa-users"></i>
+    </a>
     %if not is_embeddable:
     <a class="btn pointer" title="${ _('Player mode') }" rel="tooltip" data-placement="bottom" data-bind="click: function(){ hueUtils.goFullScreen(); $root.isEditing(false); $root.isPlayerMode(true); }">
       <i class="fa fa-expand"></i>
@@ -2755,6 +2761,9 @@ ${ dashboard.layout_skeleton(suffix='search') }
 
 ${ dashboard.import_layout(True) }
 
+% if not is_embeddable:
+<script src="${ static('desktop/js/share2.vm.js') }"></script>
+% endif
 <script src="${ static('dashboard/js/search.utils.js') }" type="text/javascript" charset="utf-8"></script>
 <script src="${ static('desktop/js/jquery.textsqueezer.js') }" type="text/javascript" charset="utf-8"></script>
 <script src="${ static('desktop/ext/js/bootstrap-editable.min.js') }" type="text/javascript" charset="utf-8"></script>
@@ -2812,6 +2821,11 @@ var HIT_OPTIONS = [
   { value: "ms", label: "${ _('Substract dates') }" },
 ];
 
+function prepareShareModal () {
+  shareViewModel.setDocUuid(this.collection.uuid());
+  openShareModal();
+}
+
 function getHitOption(value){
   for (var i=0; i < HIT_OPTIONS.length; i++){
     if (HIT_OPTIONS[i].value == value){

+ 6 - 1
desktop/libs/dashboard/src/dashboard/templates/no_collections.mako

@@ -17,6 +17,7 @@
 <%!
 from django.utils.translation import ugettext as _
 from desktop.views import commonheader, commonfooter
+from indexer.conf import ENABLE_NEW_INDEXER
 %>
 
 <%namespace name="macros" file="macros.mako" />
@@ -47,7 +48,11 @@ ${ commonheader(_('Dashboard'), "dashboard", user, request, "120px") | n,unicode
       % if user.is_superuser:
       <h1>
         ${ _('What about creating a') }
-        <a href="${ url('indexer:collections') }">${ _('new index') }</a> ?
+        % if ENABLE_NEW_INDEXER.get():
+          <a href="${ url('indexer:indexes') }">${ _('new index') }</a> ?
+        % else:
+          <a href="${ url('indexer:collections')  }">${ _('new index') }</a> ?
+        % endif
       </h1>
       % endif
     </div>

+ 2 - 1
desktop/libs/dashboard/src/dashboard/templates/search.mako

@@ -17,7 +17,7 @@
 <%!
 from django.utils.translation import ugettext as _
 
-from desktop.views import commonheader, commonfooter, _ko
+from desktop.views import commonheader, commonfooter, _ko, commonshare
 from desktop import conf
 %>
 
@@ -26,6 +26,7 @@ from desktop import conf
 
 %if not is_embeddable:
 ${ commonheader(_('Dashboard'), "dashboard", user, request, "80px") | n,unicode }
+${ commonshare() | n,unicode }
 ${ notebookKoComponents.downloadSnippetResults() }
 %endif