Jelajahi Sumber

HUE-7969 [metastore] Enable editing of database descriptions in the table browser

Johan Ahlen 7 tahun lalu
induk
melakukan
16f85a3

File diff ditekan karena terlalu besar
+ 0 - 0
apps/metastore/src/metastore/static/metastore/css/metastore.css


+ 17 - 1
apps/metastore/src/metastore/static/metastore/js/metastore.model.js

@@ -32,6 +32,16 @@ var MetastoreDatabase = (function () {
 
     self.comment = ko.observable();
 
+    self.comment.subscribe(function (newValue) {
+      self.catalogEntry.getComment().done(function (comment) {
+        if (comment !== newValue) {
+          self.catalogEntry.setComment(newValue).done(self.comment).fail(function () {
+            self.comment(comment);
+          })
+        }
+      });
+    });
+
     self.stats = ko.observable();
     self.navigatorMeta = ko.observable();
 
@@ -390,8 +400,12 @@ var MetastoreTable = (function () {
 
     self.comment = ko.observable();
 
+    if (self.catalogEntry.hasResolvedComment()) {
+      self.comment(self.catalogEntry.getResolvedComment());
+    }
+
     self.commentWithoutNewLines = ko.pureComputed(function(){
-      return self.comment() ? hueUtils.deXSS(self.comment().replace(/<br\s*[\/]?>/gi, ' ')) : '';
+      return self.comment() ? hueUtils.deXSS(self.comment().replace(/[\n\r]+/gi, ' ')) : '';
     });
 
     self.comment.subscribe(function (newValue) {
@@ -617,6 +631,8 @@ var MetastoreColumn = (function () {
         }
       });
     });
+
+    self.catalogEntry.getComment().done(self.comment);
   }
 
   MetastoreColumn.prototype.showContextPopover = function (entry, event) {

+ 6 - 1
apps/metastore/src/metastore/static/metastore/less/metastore.less

@@ -92,7 +92,12 @@
 
   .tile {
     margin-bottom: 20px;
-    min-height: 124px;
+  }
+
+  .table-description {
+    margin-bottom: 10px;
+    margin-left: 30px;
+    white-space: pre;
   }
 
   .properties-table {

+ 29 - 23
apps/metastore/src/metastore/templates/metastore.mako

@@ -160,10 +160,10 @@ ${ components.menubar(is_embeddable) }
               </div>
               <!-- /ko -->
               <!-- ko if: table.isView() -->
-                <span data-bind="text: comment"></span>
+                <span style="white-space: pre;" data-bind="text: comment"></span>
               <!-- /ko -->
             % else:
-              <span data-bind="text: comment"></span>
+              <span style="white-space: pre;" data-bind="text: comment"></span>
             % endif
           </td>
         </tr>
@@ -431,28 +431,34 @@ ${ components.menubar(is_embeddable) }
 
 <script type="text/html" id="metastore-tables">
     <div class="row-fluid">
+      % if has_write_access:
+        <div style="position: relative;" class="show-inactive-on-hover margin-bottom-20">
+          <div style="position:absolute; left: 10px; top: 2px;"><a class="inactive-action pointer toggle-editable" title="${ _('Edit the description') }"><i class="fa fa-pencil vertical-align-top"></i></a></div>
+          <div style="margin-left: 25px;" data-bind="toggleOverflow: { height: 24 }">
+            <div style="height: inherit" data-bind="editable: comment, editableOptions: { escape: true, enabled: true, type: 'textarea', toggle: 'manual', toggleElement: '.toggle-editable', placement: 'bottom', forcePlacement: true, placeholder: '${ _ko('Add a description...') }', emptytext: '${ _ko('No description available') }', inputclass:'input-xlarge', rows: 10 }" class="inline-block">
+              ${ _('Add a description...') }
+            </div>
+          </div>
+        </div>
+      % else:
+        <div data-bind="text: comment, attr:{ title: comment }" class="table-description"></div>
+      %endif
+
       <!-- ko with: stats  -->
       <div class="span12 tile">
           <div class="span6 tile">
             <h4>${ _('Properties') }</h4>
-            <div title="${ _('Description') }"><i class="fa fa-fw fa-comment muted"></i>
-              <!-- ko if: $parent.comment -->
-              <span data-bind="text: comment"></span>
-              <!-- /ko -->
-              <!-- ko ifnot: $parent.comment -->
-              <i>${_('No description.')}</i>
-              <!-- /ko -->
-              <div title="${ _('Owner') }">
-                <i class="fa fa-fw fa-user muted"></i>
-                <span data-bind="text: owner_name ? owner_name : '${ _ko('None') }'"></span> <span data-bind="visible: owner_type">(<span data-bind="text: owner_type"></span>)</span>
-                <br/>
-                <i class="fa fa-fw fa-hdd-o muted"></i>
-                % if IS_EMBEDDED.get():
-                  <span data-bind="attr: { 'title': location }"> ${_('Location')}</span>
-                % else:
-                  <a data-bind="attr: { 'href': hdfs_link, 'rel': location }"> ${_('Location')}</a>
-                % endif
-              </div>
+            <div title="${ _('Owner') }">
+              <i class="fa fa-fw fa-user muted"></i>
+              <span data-bind="text: owner_name ? owner_name : '${ _ko('None') }'"></span> <span data-bind="visible: owner_type">(<span data-bind="text: owner_type"></span>)</span>
+            </div>
+            <div title="${ _('Location') }">
+              <i class="fa fa-fw fa-hdd-o muted"></i>
+              % if IS_EMBEDDED.get():
+                <span data-bind="attr: { 'title': location }"> ${_('Location')}</span>
+              % else:
+                <a data-bind="attr: { 'href': hdfs_link, 'rel': location }"> ${_('Location')}</a>
+              % endif
             </div>
           </div>
           <div class="span6 tile">
@@ -496,7 +502,7 @@ ${ components.menubar(is_embeddable) }
             <th width="1%" style="text-align: center" class="vertical-align-middle"><div class="hueCheckbox fa" data-bind="hueCheckAll: { allValues: filteredTables, selectedValues: selectedTables }"></div></th>
             <th>&nbsp;</th>
             <th width="30%">${ _('Table Name') }</th>
-            <th width="48%">${ _('Comment') }</th>
+            <th width="48%">${ _('Description') }</th>
             <!-- ko if: $root.optimizerEnabled  -->
             <th width="10%">${ _('Popularity') }</th>
             <th width="10%">${ _('Columns') }</th>
@@ -513,7 +519,7 @@ ${ components.menubar(is_embeddable) }
               <td>
                 <a class="tableLink" href="javascript:void(0);" data-bind="text: catalogEntry.name, click: function() { $parent.setTable($data, function() { huePubSub.publish('metastore.url.change'); }) }"></a>
               </td>
-              <td style="text-overflow: ellipsis; overflow: hidden; max-width: 0" data-bind="html: commentWithoutNewLines, attr: { title: hueUtils.html2text(commentWithoutNewLines()) }"></td>
+              <td style="text-overflow: ellipsis; overflow: hidden; max-width: 0" data-bind="text: commentWithoutNewLines, attr: { title: hueUtils.html2text(commentWithoutNewLines()) }"></td>
               <!-- ko if: $root.optimizerEnabled -->
                 <!-- ko if: optimizerStats() -->
                 <td>
@@ -901,7 +907,7 @@ ${ components.menubar(is_embeddable) }
     </div>
   </div>
   % else:
-    <div data-bind="html: comment, attr:{ title: comment }" class="table-description"></div>
+    <div data-bind="text: comment, attr:{ title: comment }" class="table-description"></div>
   %endif
 
   <ul class="nav nav-tabs nav-tabs-border margin-top-30">

File diff ditekan karena terlalu besar
+ 0 - 0
desktop/core/src/desktop/static/desktop/css/hue-embedded.css


File diff ditekan karena terlalu besar
+ 0 - 0
desktop/core/src/desktop/static/desktop/css/hue.css


File diff ditekan karena terlalu besar
+ 0 - 0
desktop/core/src/desktop/static/desktop/css/hue3-extra.css


+ 1 - 0
desktop/core/src/desktop/static/desktop/less/hue-autocomplete.less

@@ -199,6 +199,7 @@
 .autocompleter-details-contents .details-comment * {
   font-size: 13px !important;
   line-height: 14px !important;
+  white-space: pre;
 }
 
 .autocompleter-details-contents .details-code {

+ 1 - 1
desktop/core/src/desktop/templates/hue_ace_autocompleter.mako

@@ -673,7 +673,7 @@ from desktop.views import _ko
     <!-- /ko -->
     <!-- ko ifnot: loading -->
     <!-- ko if: comment() -->
-    <div class="details-comment" data-bind="html: comment"></div>
+    <div class="details-comment" data-bind="text: comment"></div>
     <!-- /ko -->
     <!-- ko ifnot: comment() -->
     <div class="details-no-comment">

+ 4 - 4
desktop/core/src/desktop/templates/ko_components/ko_context_popover.mako

@@ -93,7 +93,7 @@ from metadata.conf import has_navigator
       <!-- /ko -->
       <!-- ko if: typeof $parent.comment !== 'undefined' && $parent.comment() -->
       <div class="context-popover-header">${ _("Description") }</div>
-      <div class="context-popover-section" style="font-style: italic;" data-bind="text: $parent.comment()"></div>
+      <div class="context-popover-section" style="font-style: italic; white-space: pre;" data-bind="text: $parent.comment()"></div>
       <!-- /ko -->
       %if has_navigator(user):
         <!-- ko if: ($parent.sourceType === 'hive' || $parent.sourceType === 'impala') && $parent.catalogEntry() -->
@@ -118,7 +118,7 @@ from metadata.conf import has_navigator
         <div style="margin: 0 0 5px 10px;"><a class="pointer" data-bind="text: name, attr: { title: name }, click: function() { huePubSub.publish('context.popover.scroll.to.column', name); }"></a> <!-- ko if: typeof type !== 'undefined' -->(<span data-bind="text: type.indexOf('<') !== -1 ? type.substring(0, type.indexOf('<')) : type, attr: { title: type }"></span>)<!-- /ko --></div>
         <!-- ko if: typeof $parent.comment !== 'undefined' && $parent.comment() -->
         <div class="context-popover-header">${ _("Description") }</div>
-        <div class="context-popover-section" style="font-style: italic;" data-bind="text: $parent.comment()"></div>
+        <div class="context-popover-section" style="font-style: italic; white-space: pre;" data-bind="text: $parent.comment()"></div>
         <!-- /ko -->
         %if has_navigator(user):
           <!-- ko if: ($parent.sourceType === 'hive' || $parent.sourceType === 'impala') && $parent.catalogEntry() -->
@@ -203,8 +203,8 @@ from metadata.conf import has_navigator
     <div class="context-popover-flex-fill">
       <div class="context-popover-flex">
         <div data-bind="if: $parent.comment">
-          <div class="context-popover-header">${ _("Comment") }</div>
-          <div class="context-popover-section" style="font-style: italic;" data-bind="text: $parent.comment"></div>
+          <div class="context-popover-header">${ _("Description") }</div>
+          <div class="context-popover-section" style="font-style: italic; white-space: pre;" data-bind="text: $parent.comment"></div>
         </div>
         <!-- ko if: catalogEntry() -->
         <div class="context-popover-header">${_('Tags')}</div>

Beberapa file tidak ditampilkan karena terlalu banyak file yang berubah dalam diff ini