浏览代码

HUE-4064 [editor] Format creation and update date on the table details popover

Enrico Berti 9 年之前
父节点
当前提交
4365e9f8f2

+ 6 - 0
desktop/core/src/desktop/static/desktop/ext/js/filesize.min.js

@@ -0,0 +1,6 @@
+/*
+ 2016 
+ @version 3.2.1
+ */
+"use strict";!function(a){function b(a){var b=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],e=[],f=0,g=void 0,h=void 0,i=void 0,j=void 0,k=void 0,l=void 0,m=void 0,n=void 0,o=void 0,p=void 0,q=void 0;if(isNaN(a))throw new Error("Invalid arguments");return i=b.bits===!0,o=b.unix===!0,h=b.base||2,n=void 0!==b.round?b.round:o?1:2,p=void 0!==b.spacer?b.spacer:o?"":" ",q=b.symbols||b.suffixes||{},m=b.output||"string",g=void 0!==b.exponent?b.exponent:-1,l=Number(a),k=0>l,j=h>2?1e3:1024,k&&(l=-l),0===l?(e[0]=0,e[1]=o?"":i?"b":"B"):((-1===g||isNaN(g))&&(g=Math.floor(Math.log(l)/Math.log(j)),0>g&&(g=0)),g>8&&(g=8),f=2===h?l/Math.pow(2,10*g):l/Math.pow(1e3,g),i&&(f=8*f,f>j&&8>g&&(f/=j,g++)),e[0]=Number(f.toFixed(g>0?n:0)),e[1]=10===h&&1===g?i?"kb":"kB":d[i?"bits":"bytes"][g],o&&(e[1]=e[1].charAt(0),c.test(e[1])&&(e[0]=Math.floor(e[0]),e[1]=""))),k&&(e[0]=-e[0]),e[1]=q[e[1]]||e[1],"array"===m?e:"exponent"===m?g:"object"===m?{value:e[0],suffix:e[1],symbol:e[1]}:e.join(p)}var c=/^(b|B)$/,d={bits:["b","Kb","Mb","Gb","Tb","Pb","Eb","Zb","Yb"],bytes:["B","KB","MB","GB","TB","PB","EB","ZB","YB"]};"undefined"!=typeof exports?module.exports=b:"function"==typeof define&&define.amd?define(function(){return b}):a.filesize=b}("undefined"!=typeof window?window:global);
+//# sourceMappingURL=filesize.min.js.map

+ 7 - 2
desktop/core/src/desktop/templates/common_header.mako

@@ -201,6 +201,7 @@ if USE_NEW_EDITOR.get():
   <script src="${ static('desktop/ext/js/bootstrap.min.js') }"></script>
   <script src="${ static('desktop/ext/js/bootstrap-better-typeahead.min.js') }"></script>
   <script src="${ static('desktop/ext/js/fileuploader.js') }"></script>
+  <script src="${ static('desktop/ext/js/filesize.min.js') }"></script>
   <script src="${ static('desktop/js/popover-extra-placements.js') }"></script>
   <script src="${ static('desktop/ext/js/moment-with-locales.min.js') }" type="text/javascript" charset="utf-8"></script>
 
@@ -208,10 +209,14 @@ if USE_NEW_EDITOR.get():
 
     moment.locale(window.navigator.userLanguage || window.navigator.language);
     localeFormat = function (time) {
+      var mTime = time;
       if (typeof ko !== 'undefined' && ko.isObservable(time)) {
-        return moment(time()).format("L LT");
+        mTime = time();
       }
-      return moment(time).format("L LT");
+      if (moment(mTime).isValid()) {
+        return moment(mTime).format("L LT");
+      }
+      return mTime;
     }
 
     //Add CSRF Token to all XHR Requests

+ 11 - 1
desktop/core/src/desktop/templates/table_stats.mako

@@ -43,7 +43,7 @@ from desktop.views import _ko
       <!-- ko if: statRows().length -->
       <table class="table table-striped">
         <tbody data-bind="foreach: statRows">
-          <tr><th data-bind="text: data_type, style:{'border-top-color': $index() == 0 ? '#ffffff' : '#e5e5e5'}" style="background-color: #FFF"></th><td data-bind="text: comment, style:{'border-top-color': $index() == 0 ? '#ffffff' : '#e5e5e5'}" style="background-color: #FFF"></td></tr>
+          <tr><th data-bind="text: data_type, style:{'border-top-color': $index() == 0 ? '#ffffff' : '#e5e5e5'}" style="background-color: #FFF"></th><td data-bind="text: $root.formatAnalysisValue(data_type, comment), style:{'border-top-color': $index() == 0 ? '#ffffff' : '#e5e5e5'}" style="background-color: #FFF"></td></tr>
         </tbody>
       </table>
       <!-- /ko -->
@@ -173,6 +173,7 @@ from desktop.views import _ko
       }
     }(function (ko, TableStats) {
 
+
       function TableStatsViewModel(params, element) {
         var self = this;
         self.params = params;
@@ -191,6 +192,15 @@ from desktop.views import _ko
         self.enabled = params.tableName || params.columnName;
         self.alwaysActive = params.alwaysActive || false;
         self.analysisStats = ko.observable(null);
+        self.formatAnalysisValue = function (type, val) {
+          if (type === 'last_modified_time' || type === 'transient_lastDdlTime') {
+            return localeFormat(val * 1000);
+          }
+          if (type.toLowerCase().indexOf('size') > -1) {
+            return filesize(val);
+          }
+          return val;
+        }
 
         if (ko.isObservable(self.params.statsVisible)) {
           self.analysisStats.subscribe(function (newValue) {