accumulo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From milleruntime <...@git.apache.org>
Subject [GitHub] accumulo pull request #242: ACCUMULO-2181/3005 REST API and new Monitor UI
Date Fri, 07 Apr 2017 20:21:32 GMT
Github user milleruntime commented on a diff in the pull request:

    https://github.com/apache/accumulo/pull/242#discussion_r110474249
  
    --- Diff: server/monitor/src/main/resources/resources/tables.js ---
    @@ -0,0 +1,348 @@
    +/*
    +* 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.
    +*/
    +
    +/**
    + * Makes the REST calls, generates the tables with the new information
    + */
    +function refreshTables() {
    +  $.ajaxSetup({
    +    async: false
    +  });
    +  getNamespaces();
    +  $.ajaxSetup({
    +    async: true
    +  });
    +  createNamespacesDropdown();
    +  // If the namespaces in sessionStorage is undefined, select all namespaces
    +  if (sessionStorage.namespaces === undefined) {
    +    sessionStorage.namespaces = '[]';
    +    populateTable('*');
    +  }
    +  populateTable(undefined);
    +  sortTable(sessionStorage.tableColumnSort === undefined ?
    +      0 : sessionStorage.tableColumnSort);
    +}
    +
    +/**
    + * Used to redraw the page
    + */
    +function refresh() {
    +  // If tables are in master page, refresh master and tables
    +  if (!hasMaster) {
    +    refreshTables();
    +  } else {
    +    refreshMaster();
    +    refreshTables();
    +  }
    +}
    +
    +var hasMaster = false;
    +function toggleMaster(master) {
    +  hasMaster = master
    +}
    +
    +/**
    + * Creates listeners for when the namespaces are selected or unselected
    + */
    +function namespaceChanged() {
    +  var $namespaceSelect = $('#namespaces');
    +
    +  $namespaceSelect.off();
    +
    +  $namespaceSelect.on('select2:select', function(e) {
    +    var id = e.params === null ? undefined : e.params['data']['id'];
    +    populateTable(id);
    +  });
    +
    +  $namespaceSelect.on('select2:unselect', function(e) {
    +    var id = e.params === null ? undefined : e.params['data']['id'];
    +    populateTable(id);
    +  });
    +}
    +
    +/**
    + * Creates the namespaces dropdown menu
    + */
    +function createNamespacesDropdown() {
    +  var data = JSON.parse(NAMESPACES).namespaces;
    +  var caption = [];
    +
    +  caption.push('<span class="table-caption">Table&nbsp;List</span><br
/>');
    +
    +  $('<caption/>', {
    +    html: caption.join('')
    +  }).appendTo('#filters');
    +
    +  var data2 = [{ id: '*', text: '* (All Tables)'}];
    +  $.each(data, function(key, val) {
    +    var namespace = val === '' ? '- (DEFAULT)' : val;
    +    data2.push({id: val === '' ? '-' : val, text: namespace});
    +  });
    +
    +  $('#namespaces').select2({
    +    data: data2,
    +    allowClear: true
    +  });
    +  namespaceChanged();
    +}
    +
    +/**
    + * Creates the tables table with the selected namespace
    + *
    + * @param {string} ns Selected namespace
    + */
    +function populateTable(ns) {
    +  var tmpArr = sessionStorage.namespaces === undefined ?
    +      [] : JSON.parse(sessionStorage.namespaces);
    +  sessionStorage.namespaceChanged = true;
    +  var namespaces = JSON.parse(NAMESPACES).namespaces;
    +
    +  // If there is a selected namespace, change the displayed tables
    +  if (ns !== undefined) {
    +    /*
    +     * If the namespace has not been selected,
    +     * add it to the namespace array, otherwise remove it
    +     */
    +    if (tmpArr.indexOf(ns) == -1) {
    +      /* If the namespace is *, add all namespaces to the array,
    +       * otherwise just add the selected namespace
    +       */
    +      if (ns === '*') {
    +        tmpArr = [];
    +
    +        tmpArr.push('*');
    +        $.each(namespaces, function(key, val) {
    +          tmpArr.push(val === '' ? '-' : val);
    +        });
    +      } else {
    +        tmpArr.push(ns);
    +        /*
    +         * If the namespace array is the same size
    +         * as the total number of namespaces, add *
    +         */
    +        if (tmpArr.length == namespaces.length) {
    +          tmpArr.push('*');
    +        }
    +      }
    +    } else {
    +      /*
    +       * If * is in the array, and the selected
    +       * namespace is not *, remove * from array
    +       */
    +      if (tmpArr.indexOf('*') !== -1 && ns !== '*') {
    +        tmpArr.splice(tmpArr.indexOf('*'), 1);
    +      }
    +      /*
    +       * If the selected namespace is not *,
    +       * remove it from array, otherwise, remove all
    +       */
    +      if (ns !== '*') {
    +        tmpArr.splice(tmpArr.indexOf(ns), 1);
    +      } else {
    +        tmpArr = [];
    +      }
    +    }
    +  }
    +
    +  $('#namespaces').select2().val(tmpArr).trigger('change'); // TODO Fix this, causes
null dataAdapter
    +
    +  sessionStorage.namespaces = JSON.stringify(tmpArr);
    +
    +  $.ajaxSetup({
    +    async: false
    +  });
    +  getNamespaceTables(tmpArr);
    +  $.ajaxSetup({
    +    async: true
    +  });
    +
    +  var data = sessionStorage.tables === undefined ?
    +      [] : JSON.parse(sessionStorage.tables);
    +  clearTable('tableList');
    +
    +  var numTables = 0;
    +
    +  $.each(data.tables, function(keyT, tab) {
    +    // Only add tables that are part of the array, or all if * is in the array
    +    if (tmpArr.indexOf(tab.namespace === '' ? '-' : tab.namespace) !== -1 ||
    +        tmpArr.indexOf('*') !== -1) {
    +      $.each(tab.table, function(key, val) {
    +
    +        var row = [];
    +        row.push('<td class="firstcell left" data-value="' + val.tablename +
    +            '"><a href="/tables/' + val.tableId +
    +            '">' + val.tablename + '</a></td>');
    +        row.push('<td class="center" data-value="' + val.tableState +
    +            '"><span>' + val.tableState + '</span></td>');
    +
    +        if (val.tableState === 'ONLINE') {
    +          row.push('<td class="right" data-value="' + val.tablets +
    +              '">' + bigNumberForQuantity(val.tablets) + '</td>');
    +
    +          row.push('<td class="right" data-value="' + val.offlineTablets +
    +              '">' + bigNumberForQuantity(val.offlineTablets) + '</td>');
    +
    +          row.push('<td class="right" data-value="' + val.recs + '">' +
    +              bigNumberForQuantity(val.recs) + '</td>');
    +
    +          row.push('<td class="right" data-value="' + val.recsInMemory +
    +              '">' + bigNumberForQuantity(val.recsInMemory) + '</td>');
    +
    +          row.push('<td class="right" data-value="' + val.ingest +
    +              '">' + bigNumberForQuantity(Math.floor(val.ingest)) + '</td>');
    +
    +          row.push('<td class="right" data-value="' + val.entriesRead +
    +              '">' + bigNumberForQuantity(Math.floor(val.entriesRead)) +
    +              '</td>');
    +
    +          row.push('<td class="right" data-value="' + val.entriesReturned +
    +              '">' + bigNumberForQuantity(Math.floor(val.entriesReturned)) +
    +              '</td>');
    +
    +          row.push('<td class="right" data-value="' + val.holdTime + '">' +
    --- End diff --
    
    Another simple function would be nice here.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message