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

[frontend] Add a download option for document results in the top search bar (#3090)

Johan Åhlén пре 3 година
родитељ
комит
a420f7f022

+ 10 - 0
desktop/core/src/desktop/js/ko/components/contextPopover/documentContext.js

@@ -90,6 +90,7 @@ class DocumentContext {
     self.errorText = ko.observable();
     self.template = TEMPLATE_NAME;
 
+    self.documentId = ko.observable();
     self.documentContents = ko.observable();
     self.loadDocument();
 
@@ -105,6 +106,14 @@ class DocumentContext {
     });
   }
 
+  download() {
+    if (this.documentId()) {
+      window.location.href = `${
+        window.HUE_BASE_URL
+      }/desktop/api2/doc/export?documents=[${this.documentId()}]`;
+    }
+  }
+
   open(entry) {
     huePubSub.publish('open.link', entry.details.link);
     huePubSub.publish('context.popover.hide');
@@ -129,6 +138,7 @@ class DocumentContext {
         silenceErrors: true
       })
       .done(response => {
+        this.documentId(response.document?.id);
         self.documentContents(response.data);
         self.loading(false);
       })

+ 6 - 3
desktop/core/src/desktop/js/ko/components/contextPopover/ko.contextPopover.js

@@ -56,10 +56,13 @@ const SUPPORT_TEMPLATES = `
         </a>
         <!-- ko if: isDocument -->
         <!-- ko with: contents -->
+        <!-- ko if: documentId -->
+        <a href="javascript: void(0);" class="inactive-action" data-bind="click: download">
+          <i style="font-size: 11px;" title="${I18n('Download')}" class="fa fa-download"></i> ${I18n('Download')}
+        </a>
+        <!-- /ko -->
         <a href="javascript: void(0);" class="inactive-action" data-bind="click: open">
-          <i style="font-size: 11px;" title="${I18n('Open')}" class="fa fa-file-o"></i> ${I18n(
-  'Open'
-)}
+          <i style="font-size: 11px;" title="${I18n('Open')}" class="fa fa-file-o"></i> ${I18n('Open')}
         </a>
         <!-- /ko -->
         <!-- /ko -->