Github user lstav commented on a diff in the pull request:

    https://github.com/apache/accumulo/pull/242#discussion_r110215947
  
    --- Diff: server/monitor/src/main/resources/resources/functions.js ---
    @@ -0,0 +1,686 @@
    +/*
    +* Licensed to the Apache Software Foundation (ASF) under one or more
    +* contributor license agreements.  See the NOTICE file distributed with
    +* this work for additional information regarding copyright ownership.
    +* The ASF licenses this file to You under the Apache License, Version 2.0
    +* (the "License"); you may not use this file except in compliance with
    +* the License.  You may obtain a copy of the License at
    +*
    +*     http://www.apache.org/licenses/LICENSE-2.0
    +*
    +* Unless required by applicable law or agreed to in writing, software
    +* distributed under the License is distributed on an "AS IS" BASIS,
    +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +* See the License for the specific language governing permissions and
    +* limitations under the License.
    +*/
    +
    +// Suffixes for quantity
    +var QUANTITY_SUFFIX = ['', 'K', 'M', 'B', 'T', 'e15', 'e18', 'e21'];
    +// Suffixes for size
    +var SIZE_SUFFIX = ['', 'K', 'M', 'G', 'T', 'P', 'E', 'Z'];
    +
    +/**
    + * Initializes Auto Refresh to false if it is not set,
    + * and creates listeners for auto refresh
    + */
    +function setupAutoRefresh() {
    +  // Sets auto refresh to true or false
    +  if (!sessionStorage.autoRefresh) {
    +    sessionStorage.autoRefresh = 'false';
    +  }
    +  // Need this to set the initial value for the autorefresh on page load
    +  if (sessionStorage.autoRefresh == 'false') {
    +    $('.auto-refresh').parent().removeClass('active');
    +  } else {
    +    $('.auto-refresh').parent().addClass('active');
    +  }
    +  // Initializes the auto refresh on click listener
    +  $('.auto-refresh').click(function(e) {
    +    if ($(this).parent().attr('class') == 'active') {
    +      $(this).parent().removeClass('active');
    +      sessionStorage.autoRefresh = 'false';
    +    } else {
    +      $(this).parent().addClass('active');
    +      sessionStorage.autoRefresh = 'true';
    +    }
    +  });
    +}
    +
    +/**
    + * Global timer that checks for auto refresh status every 5 seconds
    + */
    +TIMER = setInterval(function() {
    +  if (sessionStorage.autoRefresh == 'true') {
    +    $('.auto-refresh').parent().addClass('active');
    +    refresh();
    +    refreshNavBar();
    +  } else {
    +    $('.auto-refresh').parent().removeClass('active');
    +  }
    +}, 5000);
    +
    +/**
    + * Empty function in case there is no refresh implementation
    + */
    +function refresh() {
    +}
    +
    +/**
    + * Converts a number to a size with suffix
    + *
    + * @param {number} size Number to convert
    + * @return {string} Number with suffix added
    + */
    +function bigNumberForSize(size) {
    +  if (size === null)
    +    size = 0;
    +  return bigNumber(size, SIZE_SUFFIX, 1024);
    +}
    +
    +/**
    + * Converts a number to a quantity with suffix
    + *
    + * @param {number} quantity Number to convert
    + * @return {string} Number with suffix added
    + */
    +function bigNumberForQuantity(quantity) {
    +  if (quantity === null)
    +    quantity = 0;
    +  return bigNumber(quantity, QUANTITY_SUFFIX, 1000);
    +}
    +
    +/**
    + * Adds the suffix to the number, converts the number to one close to the 
base
    + *
    + * @param {number} big Number to convert
    + * @param {array} suffixes Suffixes to use for convertion
    + * @param {number} base Base to use for convertion
    + * @return {string} The new value with the suffix
    + */
    +function bigNumber(big, suffixes, base) {
    +  // If the number is smaller than the base, return thee number with no 
suffix
    +  if (big < base) {
    +    return big + suffixes[0];
    +  }
    +  // Finds which suffix to use
    +  var exp = Math.floor(Math.log(big) / Math.log(base));
    +  // Divides the bumber by the equivalent suffix number
    +  var val = big / Math.pow(base, exp);
    +  // Keeps the number to 2 decimal places and adds the suffix
    +  return val.toFixed(2) + suffixes[exp];
    +}
    +
    +/**
    + * Converts the time to short number and adds unit
    + *
    + * @param {number} time Time in microseconds
    + * @return {string} The time with units
    + */
    +function timeDuration(time) {
    +  var ms, sec, min, hr, day, yr;
    +  ms = sec = min = hr = day = yr = -1;
    +
    +  time = Math.floor(time);
    +
    +  // If time is 0 return a dash
    +  if (time == 0) {
    +    return '&mdash;';
    +  }
    +
    +  // Obtains the milliseconds, if time is 0, return milliseconds, and units
    +  ms = time % 1000;
    +  time = Math.floor(time / 1000);
    +  if (time == 0) {
    +    return ms + 'ms';
    +  }
    +
    +  // Obtains the seconds, if time is 0, return seconds, milliseconds, and 
units
    +  sec = time % 60;
    +  time = Math.floor(time / 60);
    +  if (time == 0) {
    +    return sec + 's' + '&nbsp;' + ms + 'ms';
    +  }
    +
    +  // Obtains the minutes, if time is 0, return minutes, seconds, and units
    +  min = time % 60;
    +  time = Math.floor(time / 60);
    +  if (time == 0) {
    +    return min + 'm' + '&nbsp;' + sec + 's';
    --- End diff --
    
    Ah gotcha, I'll try to check it out and see if I can reduce it.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to