Browse Source

HUE-5685 [editor] Indicate primary keys with an icon in assist and the autocomplete dropdown

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

+ 12 - 17
desktop/core/src/desktop/static/desktop/js/assist/assistDbEntry.js

@@ -293,15 +293,12 @@ var AssistDbEntry = (function () {
       var index = 0;
       if (typeof data.tables_meta !== "undefined") {
         newEntries = $.map(data.tables_meta, function(table) {
-          return self.createEntry({
-            name: table.name,
-            index: index++,
-            displayName: table.name,
-            title: table.name + (table.comment ? ' - ' + table.comment : ''),
-            type: table.type,
-            isTable: /table/i.test(table.type),
-            isView: /view/i.test(table.type)
-          });
+          table.index = index++;
+          table.title = table.name + (table.comment ? ' - ' + table.comment : '');
+          table.displayName = table.name;
+          table.isTable = /table/i.test(table.type);
+          table.isView = /view/i.test(table.type);
+          return self.createEntry(table);
         });
       } else if (typeof data.extended_columns !== "undefined" && data.extended_columns !== null) {
         newEntries = $.map(data.extended_columns, function (columnDef) {
@@ -317,14 +314,12 @@ var AssistDbEntry = (function () {
           if (typeof columnDef.type !== "undefined" && columnDef.type !== null) {
             shortType = columnDef.type.match(/^[^<]*/g)[0]; // everything before '<'
           }
-          return self.createEntry({
-            name: columnDef.name,
-            index: index++,
-            displayName: displayName,
-            title: title,
-            isColumn: true,
-            type: shortType
-          });
+          columnDef.index = index++;
+          columnDef.displayName = displayName;
+          columnDef.title = title;
+          columnDef.isColumn = true;
+          columnDef.type = shortType;
+          return self.createEntry(columnDef);
         });
       } else if (typeof data.columns !== "undefined" && data.columns !== null) {
         newEntries = $.map(data.columns, function(columnName) {

+ 2 - 2
desktop/core/src/desktop/templates/assist.mako

@@ -148,12 +148,12 @@ from notebook.conf import ENABLE_QUERY_BUILDER
       </div>
       <!-- ko if: expandable -->
       <a class="assist-entry assist-field-link" href="javascript:void(0)" data-bind="click: toggleOpen, attr: {'title': definition.title }">
-        <span class="highlightable" data-bind="css: { 'highlight': highlight}, attr: {'column': columnName, 'table': tableName, 'database': databaseName }, text: definition.displayName, draggableText: { text: editorText, meta: {'type': 'sql', 'column': columnName, 'table': tableName, 'database': databaseName } }"></span>
+        <span class="highlightable" data-bind="css: { 'highlight': highlight}, attr: {'column': columnName, 'table': tableName, 'database': databaseName }, text: definition.displayName, draggableText: { text: editorText, meta: {'type': 'sql', 'column': columnName, 'table': tableName, 'database': databaseName } }"></span><!-- ko if: definition.primary_key --> <i class="fa fa-key"></i><!-- /ko -->
       </a>
       <!-- /ko -->
       <!-- ko ifnot: expandable -->
       <div style="cursor: default;" class="assist-entry assist-field-link" href="javascript:void(0)" data-bind="event: { dblClick: dblClick }, attr: {'title': definition.title }">
-        <span class="highlightable" data-bind="css: { 'highlight': highlight}, attr: {'column': columnName, 'table': tableName, 'database': databaseName}, text: definition.displayName, draggableText: { text: editorText, meta: {'type': 'sql', 'column': columnName, 'table': tableName, 'database': databaseName} }"></span>
+        <span class="highlightable" data-bind="css: { 'highlight': highlight}, attr: {'column': columnName, 'table': tableName, 'database': databaseName}, text: definition.displayName, draggableText: { text: editorText, meta: {'type': 'sql', 'column': columnName, 'table': tableName, 'database': databaseName} }"></span><!-- ko if: definition.primary_key --> <i class="fa fa-key"></i><!-- /ko -->
       </div>
       <!-- /ko -->
       <div class="center" data-bind="visible: loading"><i class="fa fa-spinner fa-spin assist-spinner"></i></div>

+ 4 - 1
desktop/libs/notebook/src/notebook/templates/hue_ace_autocompleter.mako

@@ -40,7 +40,7 @@ from desktop.views import _ko
                 css: { 'selected': $index() === $parent.selectedIndex() },
                 event: { 'mouseover': function () { $parent.hoveredIndex($index()); }, 'mouseout': function () { $parent.hoveredIndex(null); } }">
               <div class="autocompleter-suggestion-value">
-                <div class="autocompleter-dot" data-bind="style: { 'background-color': category.color }"></div> <span data-bind="matchedText: { suggestion: $data, filter: $parent.suggestions.filter }"></span>
+                <div class="autocompleter-dot" data-bind="style: { 'background-color': category.color }"></div> <span data-bind="matchedText: { suggestion: $data, filter: $parent.suggestions.filter }"></span> <!-- ko if: details && details.primary_key --><i class="fa fa-key"></i><!-- /ko -->
               </div>
               <div class="autocompleter-suggestion-meta"><!-- ko if: popular --><i class="fa fa-star-o popular-icon"></i> <!-- /ko --><span data-bind="text: meta"></span></div>
             </div>
@@ -101,6 +101,9 @@ from desktop.views import _ko
       <div class="autocompleter-details-contents">
         <div class="details-attribute" ><i class="fa fa-database fa-fw"></i> <span data-bind="text: details.database"></span></div>
         <div class="details-attribute" ><i class="fa fa-table fa-fw"></i> <span data-bind="text: details.table"></span></div>
+        <!-- ko if: typeof details.primary_key !== 'undefined' && details.primary_key -->
+        <div class="details-attribute" ><i class="fa fa-key fa-fw"></i> ${ _('Primary key') }</div>
+        <!-- /ko -->
         <!-- ko if: typeof details.popularity !== 'undefined' -->
         <br/>
         <div class="details-popularity margin-top-10" data-bind="tooltip: { title: '${ _ko('Popularity') } ' + details.popularity.relativePopularity + '%', placement: 'bottom' }"><i class="fa fa-fw fa-star-o popular-icon"></i>