Browse Source

HUE-2868 [hbase] Fix cell upload

Johan Ahlen 10 năm trước cách đây
mục cha
commit
10e853d330

+ 9 - 5
apps/hbase/src/hbase/static/hbase/js/utils.js

@@ -93,7 +93,7 @@ function launchModal(modal, data) {
   element.is('.ajaxSubmit') ? element.submit(bindSubmit) : '';
   switch (modal) {
     case 'cell_edit_modal':
-      if (data.mime.split('/')[0] == 'text') {
+      if (data.mime().split('/')[0] == 'text') {
         var target = document.getElementById('codemirror_target');
         var mime = data.mime;
         if (mime == "text/json") {
@@ -138,8 +138,10 @@ function launchModal(modal, data) {
           fileFieldLabel: 'hbase_file',
           multiple: false,
           onComplete: function (id, fileName, response) {
-            data.content.reload();
-            data.value(data.content.value);
+            data.content.reload(function() {
+              data.value(data.content.value());
+              data.mime(detectMimeType(data.value()))
+            });
           }
         });
       }
@@ -184,7 +186,7 @@ function showFullEditor(cellContent) {
     readOnly: ko.observable(false),
     timestamp: ko.observable(cellContent.timestamp),
     content: cellContent,
-    mime: detectMimeType(currentValue),
+    mime: ko.observable(detectMimeType(currentValue)),
 
     updateCodeMirror: function() {
       if (this.codeMirror) {
@@ -198,14 +200,16 @@ function showFullEditor(cellContent) {
         this.currentValue(this.value());
       }
       this.value(item.value);
+      this.mime(detectMimeType(this.value()));
       this.updateCodeMirror();
       this.showingCurrent(false);
-      this.timestamp(item.timestamp)
+      this.timestamp(item.timestamp);
     },
 
     switchToCurrent: function() {
       if (!this.showingCurrent()) {
         this.value(this.currentValue());
+        this.mime(detectMimeType(this.value()));
         this.showingCurrent(true);
         this.timestamp(this.content.timestamp);
         this.updateCodeMirror();

+ 4 - 4
apps/hbase/src/hbase/templates/app.mako

@@ -376,7 +376,7 @@ ${ commonheader(None, "hbase", user) | n,unicode }
               <input type="hidden" data-bind="value: $data.content.parent.row"/>
               <input type="hidden" data-bind="value: $data.content.name"/>
               <!-- /ko -->
-              <!-- ko template: {name: 'cell_' + mime.split('/')[0].toLowerCase() + '_template'} -->
+              <!-- ko template: {name: 'cell_' + mime().split('/')[0].toLowerCase() + '_template'} -->
               <!-- /ko -->
             </div>
             <div class="span3">
@@ -396,7 +396,7 @@ ${ commonheader(None, "hbase", user) | n,unicode }
         <!-- ko if: showingCurrent -->
           <button class="btn" data-dismiss="modal" aria-hidden="true">${_('Cancel')}</button>
           <a id="file-upload-btn" class="btn fileChooserBtn" aria-hidden="true"><i class="fa fa-upload"></i> ${_('Upload')}</a>
-          <input data-bind="visible: mime.split('/')[0].toLowerCase() != 'application' && mime.split('/')[0].toLowerCase() != 'image'" type="submit" class="btn btn-primary" value="${_('Save')}">
+          <input data-bind="visible: mime().split('/')[0].toLowerCase() != 'application' && mime().split('/')[0].toLowerCase() != 'image'" type="submit" class="btn btn-primary" value="${_('Save')}">
         <!-- /ko -->
         <!-- ko ifnot: showingCurrent -->
           <button class="btn" data-dismiss="modal" aria-hidden="true">${_('Cancel')}</button>
@@ -406,7 +406,7 @@ ${ commonheader(None, "hbase", user) | n,unicode }
     </script>
 
     <script id="cell_image_template" type="text/html">
-      <img data-bind="attr: {src: 'data:image/' + $data.mime + ';base64,' + value()}"/>
+      <img data-bind="attr: {src: 'data:image/' + $data.mime() + ';base64,' + value()}"/>
       <input type="hidden" data-bind="value: value"/>
     </script>
 
@@ -415,7 +415,7 @@ ${ commonheader(None, "hbase", user) | n,unicode }
     </script>
 
     <script id="cell_application_template" type="text/html">
-      <iframe width="100%" height="100%" data-bind="attr: {src: 'data:' + $data.mime + ';base64,' + value()}"></iframe>
+      <iframe width="100%" height="100%" data-bind="attr: {src: 'data:' + $data.mime() + ';base64,' + value()}"></iframe>
       <input type="hidden" data-bind="value: value"/>
     </script>