/* The MIT License (MIT) Copyright (C) 2012-2013 Anton Simonov Copyright (C) 2014-2017 Vsevolod Stakhov Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ define(['jquery', 'd3pie', 'visibility', 'app/stats', 'app/graph', 'app/config', 'app/symbols', 'app/history', 'app/upload'], function ($, d3pie, visibility, tab_stat, tab_graph, tab_config, tab_symbols, tab_history, tab_upload) { // begin var graphs = {}; var tables = {}; var neighbours = []; //list of clusters var checked_server = "All SERVERS"; var interface = { read_only: false, }; var timer_id = []; var selData; // Graph's dataset selector state function stopTimers() { for (var key in timer_id) { Visibility.stop(timer_id[key]); } } function disconnect() { if (graphs.chart) { graphs.chart.destroy(); graphs.chart = undefined; } if (graphs.rrd_pie) { graphs.rrd_pie.destroy(); graphs.rrd_pie = undefined; } if (graphs.graph) { graphs.graph.destroy(); graphs.graph = undefined; } if (tables.history) { tables.history.destroy(); tables.history = undefined; } if (tables.errors) { tables.errors.destroy(); tables.errors = undefined; } if (tables.symbols) { tables.symbols.destroy(); tables.symbols = undefined; } stopTimers(); cleanCredentials(); interface.connect(); } function tabClick(tab_id) { if ($(tab_id).attr('disabled')) return; $(tab_id).attr('disabled', true); stopTimers(); if (tab_id === "#refresh") { tab_id = "#" + $('.navbar-nav .active > a' ).attr('id'); } switch (tab_id) { case "#status_nav": tab_stat.statWidgets(interface, graphs, checked_server); timer_id.status = Visibility.every(10000, function () { tab_stat.statWidgets(interface, graphs, checked_server); }); break; case "#throughput_nav": tab_graph.draw(interface, graphs, checked_server, selData); var autoRefresh = { hourly: 60000, daily: 300000 }; timer_id.throughput = Visibility.every(autoRefresh[selData] || 3600000, function () { tab_graph.draw(interface, graphs, checked_server, selData); }); break; case "#configuration_nav": tab_config.getActions(interface); tab_config.getMaps(interface); break; case "#symbols_nav": tab_symbols.getSymbols(interface, tables, checked_server); break; case "#history_nav": tab_history.getHistory(interface, tables, checked_server); tab_history.getErrors(interface, tables, checked_server); break; case "#disconnect": disconnect(); break; } setTimeout(function () { $(tab_id).removeAttr('disabled'); $('#refresh').removeAttr('disabled'); }, 1000); } // @return password function getPassword() { return sessionStorage.getItem('Password'); } // @save credentials function saveCredentials(password) { sessionStorage.setItem('Password', password); } // @clean credentials function cleanCredentials() { sessionStorage.clear(); $('#statWidgets').empty(); $('#listMaps').empty(); $('#modalBody').empty(); $('#historyLog tbody').remove(); $('#errorsLog tbody').remove(); $('#symbolsTable tbody').remove(); password = ''; } function isLogged() { if (sessionStorage.getItem('Credentials') !== null) { return true; } return false; } function displayUI() { // @toggle auth and main var disconnect = $('#navBar .pull-right'); $('#mainUI').show(); $('#progress').show(); $(disconnect).show(); tabClick("#refresh"); $('#progress').hide(); } // Public functions interface.setup = function() { // Bind event handlers to selectors $("#selData").change(function () { selData = this.value; tabClick("#throughput_nav"); }); $.ajaxSetup({ timeout: 2000, jsonp: false }); $(document).ajaxStart(function () { $('#navBar').addClass('loading'); }); $(document).ajaxComplete(function () { setTimeout(function () { $('#navBar').removeClass('loading'); }, 1000); }); $('a[data-toggle="tab"]').on('click', function (e) { var tab_id = "#" + $(e.target).attr("id"); tabClick(tab_id); }); // Radio buttons $(document).on('click', 'input:radio[name="clusterName"]', function () { if (!this.disabled) { checked_server = this.value; tabClick("#status_nav"); } }); tab_config.setup(interface); tab_symbols.setup(interface, tables); tab_history.setup(interface, tables); tab_upload.setup(interface) }; interface.alertMessage = function (alertState, alertText) { if ($('.alert').is(':visible')) { $(alert).hide().remove(); } var alert = $('