This is an automated email from the ASF dual-hosted git repository.

mmiller pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/accumulo.git


The following commit(s) were added to refs/heads/main by this push:
     new c5ca1713d1 Clean up bulkImport js (#2675)
c5ca1713d1 is described below

commit c5ca1713d1f70b71effbfb1451a881590590437a
Author: Mike Miller <mmil...@apache.org>
AuthorDate: Fri May 6 06:33:34 2022 -0400

    Clean up bulkImport js (#2675)
    
    * Refactor bulkImport.js to be formatted properly and use concise jquery
    
    Co-authored-by: Dom G. <domgargu...@apache.org>
---
 .../accumulo/monitor/resources/js/bulkImport.js    | 139 ++++++++++-----------
 .../accumulo/monitor/resources/js/functions.js     |   8 +-
 .../apache/accumulo/monitor/resources/js/global.js |   3 +
 .../apache/accumulo/monitor/resources/js/server.js |   3 +-
 .../accumulo/monitor/templates/bulkImport.ftl      |   4 +-
 5 files changed, 75 insertions(+), 82 deletions(-)

diff --git 
a/server/monitor/src/main/resources/org/apache/accumulo/monitor/resources/js/bulkImport.js
 
b/server/monitor/src/main/resources/org/apache/accumulo/monitor/resources/js/bulkImport.js
index bac1c7d581..5ef20d568c 100644
--- 
a/server/monitor/src/main/resources/org/apache/accumulo/monitor/resources/js/bulkImport.js
+++ 
b/server/monitor/src/main/resources/org/apache/accumulo/monitor/resources/js/bulkImport.js
@@ -16,99 +16,88 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+/* JSLint global definitions */
+/*global
+    $, document, sessionStorage, clearTableBody, EMPTY_ROW_THREE_CELLS, 
EMPTY_CELL, getBulkImports
+*/
 "use strict";
 
-/**
- * Creates bulk import initial table
- */
-$(document).ready(function() {
-  refreshBulkImport();
-});
-
-/**
- * Makes the REST calls, generates the tables with the new information
- */
-function refreshBulkImport() {
-  getBulkImports().then(function() {
-    refreshBulkImportTable();
-    refreshServerBulkTable();
-  });
-}
-
-/**
- * Used to redraw the page
- */
-function refresh() {
-  refreshBulkImport();
-}
-
 /**
  * Generates the manager bulk import status table
  */
 function refreshBulkImportTable() {
+    $("#bulkListTable tbody").html(EMPTY_ROW_THREE_CELLS);
 
-  clearTableBody('managerBulkImportStatus');
-
-  /*
-   * Get the bulk import value obtained earlier, if it doesn't exists,
-   * create an empty array
-   */
-  var data = sessionStorage.bulkImports === undefined ?
-      [] : JSON.parse(sessionStorage.bulkImports);
+    // Get the bulk import data from the session
+    var data = sessionStorage.bulkImports === undefined ?
+                [] : JSON.parse(sessionStorage.bulkImports);
 
-  /* If the data is empty, create an empty row, otherwise,
-   * create the rows for the table
-   */
-  if (data.length === 0 || data.bulkImport.length === 0) {
-    $('<tr/>', {
-      html: createEmptyRow(3, 'Empty')
-    }).appendTo('#managerBulkImportStatus tbody');
-  } else {
-    $.each(data.bulkImport, function(key, val) {
-      var items = [];
-      items.push(createFirstCell(val.filename, val.filename));
-      items.push(createRightCell(val.age, new Date(val.age)));
-      items.push(createRightCell(val.state, val.state));
-      $('<tr/>', {
-        html: items.join('')
-      }).appendTo('#managerBulkImportStatus tbody');
+    // If the data is empty, clear table, otherwise populate
+    if (data.length === 0 || data.bulkImport.length === 0) {
+        return;
+    }
+    console.log("Populate bulkListTable with " + sessionStorage.bulkImports);
+    var tableBodyHtml = "";
+    $.each(data.bulkImport, function (key, val) {
+        console.log("Append row " + key + " " + JSON.stringify(val) + " to 
bulkListTable");
+        tableBodyHtml += "<tr><td class='firstcell'>" + val.filename + "</td>";
+        tableBodyHtml += "<td class='center'>" + new Date(val.age) + "</td>";
+        tableBodyHtml += "<td class='center'>" + val.state + "</td></tr>";
     });
-  }
 
+    $("#bulkListTable tbody").html(tableBodyHtml);
 }
 
 /**
- * Generates the bulk import status table
+ * Generates the bulkPerServerTable table
  */
 function refreshServerBulkTable() {
+    $("#bulkPerServerTable tbody").html(EMPTY_ROW_THREE_CELLS);
 
-  clearTableBody('bulkImportStatus');
+    // get the bulkImport data from sessionStorage
+    var data = sessionStorage.bulkImports === undefined ?
+                [] : JSON.parse(sessionStorage.bulkImports);
 
-  /* Get the bulk import value obtained earlier, if it doesn't exists,
-   * create an empty array
-   */
-  var data = sessionStorage.bulkImports === undefined ?
-   [] : JSON.parse(sessionStorage.bulkImports);
+    // if data is empty, log an error because that means no tablet servers 
were found
+    if (data.length === 0 || data.tabletServerBulkImport.length === 0) {
+        console.error("No tablet servers.");
+        return;
+    }
+    var tableBodyHtml = "";
+    $.each(data.tabletServerBulkImport, function (key, val) {
+        console.log("Append " + key + " " + JSON.stringify(val) + " to 
bulkPerServerTable");
+        var ageCell = EMPTY_CELL;
+        if (val.oldestAge > 0) {
+            ageCell = "<td>" + new Date(val.oldestAge) + "</td>";
+        }
+        tableBodyHtml += "<tr><td><a href='/tservers?s=" + val.server + "'>" + 
val.server + "</a></td>";
+        tableBodyHtml += "<td>" + val.importSize + "</td>";
+        tableBodyHtml += ageCell + "</tr>";
+    });
 
-  /* If the data is empty, create an empty row, otherwise
-   * create the rows for the table
-   */
-  if (data.length === 0 || data.tabletServerBulkImport.length === 0) {
-    $('<tr/>', {
-      html: createEmptyRow(3, 'Empty')
-    }).appendTo('#bulkImportStatus tbody');
-  } else {
-    $.each(data.tabletServerBulkImport, function(key, val) {
-      var items = [];
-      items.push(createFirstCell(val.server, '<a href="/tservers?s=' +
-          val.server + '">' + val.server + '</a>'));
-      items.push(createRightCell(val.importSize, val.importSize));
-      items.push(createRightCell(val.oldestAge, (val.oldestAge > 0 ?
-          new Date(val.oldestAge) : '&mdash;')));
-      $('<tr/>', {
-        html: items.join('')
-      }).appendTo('#bulkImportStatus tbody');
+    $("#bulkPerServerTable tbody").html(tableBodyHtml);
+}
+
+/**
+* Makes the REST calls, generates the tables with the new information
+*/
+function refreshBulkImport() {
+    getBulkImports().then(function () {
+        refreshBulkImportTable();
+        refreshServerBulkTable();
     });
-  }
+}
+
+/**
+* Creates bulk import initial table
+*/
+$(document).ready(function () {
+    refreshBulkImport();
+});
 
+/**
+* Used to redraw the page
+*/
+function refresh() {
+    refreshBulkImport();
 }
diff --git 
a/server/monitor/src/main/resources/org/apache/accumulo/monitor/resources/js/functions.js
 
b/server/monitor/src/main/resources/org/apache/accumulo/monitor/resources/js/functions.js
index 0c2fb7a0aa..88cd734ef5 100644
--- 
a/server/monitor/src/main/resources/org/apache/accumulo/monitor/resources/js/functions.js
+++ 
b/server/monitor/src/main/resources/org/apache/accumulo/monitor/resources/js/functions.js
@@ -358,9 +358,11 @@ function getScans() {
  * REST GET call for the bulk imports, stores it on a sessionStorage variable
  */
 function getBulkImports() {
-  return $.getJSON('/rest/bulkImports', function(data) {
-    sessionStorage.bulkImports = JSON.stringify(data);
-  });
+    return $.getJSON('/rest/bulkImports', function(data) {
+        var str = JSON.stringify(data);
+        console.log("REST getBulkImports() = " + str)
+        sessionStorage.bulkImports = str;
+    });
 }
 
 /**
diff --git 
a/server/monitor/src/main/resources/org/apache/accumulo/monitor/resources/js/global.js
 
b/server/monitor/src/main/resources/org/apache/accumulo/monitor/resources/js/global.js
index 875845d3aa..aa516fc287 100644
--- 
a/server/monitor/src/main/resources/org/apache/accumulo/monitor/resources/js/global.js
+++ 
b/server/monitor/src/main/resources/org/apache/accumulo/monitor/resources/js/global.js
@@ -27,3 +27,6 @@ var NAMESPACES = '';
  * Timer object
  */
 var TIMER;
+
+const EMPTY_CELL = "<td>-</td>";
+const EMPTY_ROW_THREE_CELLS = "<tr>" + EMPTY_CELL + EMPTY_CELL + EMPTY_CELL + 
"</tr>";
diff --git 
a/server/monitor/src/main/resources/org/apache/accumulo/monitor/resources/js/server.js
 
b/server/monitor/src/main/resources/org/apache/accumulo/monitor/resources/js/server.js
index ff9adc2ed2..708a423dce 100644
--- 
a/server/monitor/src/main/resources/org/apache/accumulo/monitor/resources/js/server.js
+++ 
b/server/monitor/src/main/resources/org/apache/accumulo/monitor/resources/js/server.js
@@ -18,7 +18,6 @@
  */
 "use strict";
 
-var dashCell = "<td>&mdash;</td>";
 var serv;
 var tabletResults;
 /**
@@ -126,7 +125,7 @@ function refreshResultsTable() {
  * Appends a table cell containing value to the rowId, if value is not null
  */
 function appendDurationToRow(rowId, value) {
-  let v = dashCell;
+  let v = EMPTY_CELL;
   if (value != null) {
     v = "<td>" + timeDuration(value * 1000.0) + "</td>";
   }
diff --git 
a/server/monitor/src/main/resources/org/apache/accumulo/monitor/templates/bulkImport.ftl
 
b/server/monitor/src/main/resources/org/apache/accumulo/monitor/templates/bulkImport.ftl
index 80b0022db5..c891266b2f 100644
--- 
a/server/monitor/src/main/resources/org/apache/accumulo/monitor/templates/bulkImport.ftl
+++ 
b/server/monitor/src/main/resources/org/apache/accumulo/monitor/templates/bulkImport.ftl
@@ -25,7 +25,7 @@
       </div>
       <div class="row">
         <div class="col-xs-12">
-          <table id="managerBulkImportStatus" class="table table-bordered 
table-striped table-condensed">
+          <table id="bulkListTable" class="table table-bordered table-striped 
table-condensed">
             <caption><span class="table-caption">Bulk 
Imports</span><br/></caption>
             <thead>
               <tr>
@@ -41,7 +41,7 @@
 
       <div class="row">
         <div class="col-xs-12">
-          <table id="bulkImportStatus" class="table table-bordered 
table-striped table-condensed">
+          <table id="bulkPerServerTable" class="table table-bordered 
table-striped table-condensed">
             <caption><span class="table-caption">Per 
TabletServer</span><br/></caption>
             <thead>
               <tr>

Reply via email to