Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 0355E200C5E for ; Fri, 7 Apr 2017 22:21:36 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 021F1160B84; Fri, 7 Apr 2017 20:21:36 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 2BE36160BA9 for ; Fri, 7 Apr 2017 22:21:35 +0200 (CEST) Received: (qmail 86213 invoked by uid 500); 7 Apr 2017 20:21:33 -0000 Mailing-List: contact dev-help@accumulo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@accumulo.apache.org Delivered-To: mailing list dev@accumulo.apache.org Received: (qmail 85674 invoked by uid 99); 7 Apr 2017 20:21:32 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 07 Apr 2017 20:21:32 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 0FCAEF21A2; Fri, 7 Apr 2017 20:21:32 +0000 (UTC) From: milleruntime To: dev@accumulo.apache.org Reply-To: dev@accumulo.apache.org References: In-Reply-To: Subject: [GitHub] accumulo pull request #242: ACCUMULO-2181/3005 REST API and new Monitor UI Content-Type: text/plain Message-Id: <20170407202132.0FCAEF21A2@git1-us-west.apache.org> Date: Fri, 7 Apr 2017 20:21:32 +0000 (UTC) archived-at: Fri, 07 Apr 2017 20:21:36 -0000 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('Table List
'); + + $('', { + 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('' + val.tablename + ''); + row.push('' + val.tableState + ''); + + if (val.tableState === 'ONLINE') { + row.push('' + bigNumberForQuantity(val.tablets) + ''); + + row.push('' + bigNumberForQuantity(val.offlineTablets) + ''); + + row.push('' + + bigNumberForQuantity(val.recs) + ''); + + row.push('' + bigNumberForQuantity(val.recsInMemory) + ''); + + row.push('' + bigNumberForQuantity(Math.floor(val.ingest)) + ''); + + row.push('' + bigNumberForQuantity(Math.floor(val.entriesRead)) + + ''); + + row.push('' + bigNumberForQuantity(Math.floor(val.entriesReturned)) + + ''); + + row.push('' + --- 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. ---