浏览代码

HUE-2808 [dbquery] Add row numbers to support default order by

Fixed also HTTP 500 with null doc_id for the Share functionality
Enrico Berti 10 年之前
父节点
当前提交
abeb2e5

+ 4 - 1
apps/rdbms/src/rdbms/static/rdbms/js/rdbms.vm.js

@@ -79,7 +79,10 @@ function RdbmsViewModel() {
   self.updateResults = function(results) {
     var rows = [];
     self.columns.removeAll();  // Needed for datatables to refresh properly.
-    self.columns(results.columns);
+    if (results.columns != null) {
+      results.columns.unshift("");
+    }
+    self.columns(results.columns ? results.columns : []);
     self.rows.removeAll();
     self.rows(results.rows);
   };

+ 8 - 3
apps/rdbms/src/rdbms/templates/execute.mako

@@ -817,10 +817,15 @@ ${ commonshare() | n,unicode }
   }
 
   function addResults(viewModel, dataTable, index, pageSize) {
-    $.each(viewModel.rows.slice(index, index+pageSize), function(row_index, row) {
+    $.each(viewModel.rows.slice(index, index + pageSize), function (row_index, row) {
       var ordered_row = [];
-      $.each(viewModel.columns(), function(col_index, col) {
-        ordered_row.push(row[col]);
+      $.each(viewModel.columns(), function (col_index, col) {
+        if (col_index == 0) {
+          ordered_row.push(index + row_index);
+        }
+        else {
+          ordered_row.push(row[col]);
+        }
       });
       dataTable.fnAddData(ordered_row);
     });

+ 1 - 1
apps/rdbms/src/rdbms/views.py

@@ -72,7 +72,7 @@ def execute_query(request, design_id=None, query_history_id=None):
 
   return render('execute.mako', request, {
     'action': action,
-    'doc_id': json.dumps(design.id and design.doc.get().id),
+    'doc_id': json.dumps(design.id and design.doc.get().id or -1),
     'design': design,
     'autocomplete_base_url': reverse('rdbms:api_autocomplete_databases', kwargs={}),
     'can_edit_name': design.id and not design.is_auto,