From a8220ab2d293bb7f4b014b79d16b2fb05090fa93 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Feb 2021 12:45:55 +0100 Subject: Adding upstream version 1.29.0. Signed-off-by: Daniel Baumann --- web/gui/main.js | 100 +++++++++++++++++++------------------------------------- 1 file changed, 34 insertions(+), 66 deletions(-) (limited to 'web/gui/main.js') diff --git a/web/gui/main.js b/web/gui/main.js index 0635b07a7..5bf11e5f7 100644 --- a/web/gui/main.js +++ b/web/gui/main.js @@ -499,10 +499,26 @@ function toggleAgentItem(e, guid) { // When you stream metrics from netdata to netdata, the recieving netdata now // has multiple host databases. It's own, and multiple mirrored. Mirrored databases // can be accessed with +const OLD_DASHBOARD_SUFFIX = "old" +let isOldSuffix = true +try { + const currentScriptMainJs = document.currentScript; + const mainJsSrc = currentScriptMainJs.getAttribute("src") + isOldSuffix = mainJsSrc.startsWith("../main.js") +} catch { + console.warn("current script not detecting, assuming the dashboard is running with /old suffix") +} + +function transformWithOldSuffix(url) { + return isOldSuffix ? `../${url}` : url +} + function renderStreamedHosts(options) { let html = `
Databases streamed to this agent
`; - var base = document.location.origin.toString() + document.location.pathname.toString(); + var base = document.location.origin.toString() + + document.location.pathname.toString() + .replace(isOldSuffix ? `/${OLD_DASHBOARD_SUFFIX}` : "", ""); if (base.endsWith("/host/" + options.hostname + "/")) { base = base.substring(0, base.length - ("/host/" + options.hostname + "/").toString().length); } @@ -536,10 +552,10 @@ function renderStreamedHosts(options) { displayedDatabases = true; if (hostname === master) { - url = `${base}/`; + url = isOldSuffix ? `${base}/${OLD_DASHBOARD_SUFFIX}/` : `${base}/`; icon = 'home'; } else { - url = `${base}/host/${hostname}/`; + url = isOldSuffix ? `${base}/host/${hostname}/${OLD_DASHBOARD_SUFFIX}/` : `${base}/host/${hostname}/`; icon = 'window-restore'; } @@ -707,10 +723,9 @@ function clearMyNetdataMenu() { } function errorMyNetdataMenu() { - setMyNetdataMenu(`
+ setMyNetdataMenu(`
- Cannot load known netdata agents from netdata.cloud! -
+ Cannot load known Netdata agents from Netdata Cloud! Please make sure you have the latest version of Netdata.
`); } @@ -791,11 +806,6 @@ function renderMyNetdataMenu(machinesArray) { if (!isSignedIn()) { html += ( `
- - Nodes beta -
-
-
Switch Identity
@@ -965,7 +975,7 @@ function gotoServerModalHandler(guid) { if (!isSignedIn()) { // When the registry is enabled, if the user's known URLs are not working - // we consult the registry to get additional URLs. + // we consult the registry to get additional URLs. setTimeout(function () { if (gotoServerStop === false) { document.getElementById('gotoServerResponse').innerHTML = 'Added all the known URLs for this machine.'; @@ -1805,8 +1815,8 @@ function renderPage(menus, data) { const isMemoryModeDbEngine = data.memory_mode === "dbengine"; - sidebar += '
  • add more charts
  • '; - sidebar += '
  • add more alarms
  • '; + sidebar += '
  • Add more charts
  • '; + sidebar += '
  • Add more alarms
  • '; sidebar += '
  • Every ' + ((data.update_every === 1) ? 'second' : data.update_every.toString() + ' seconds') + ', ' + 'Netdata collects ' + data.dimensions_count.toLocaleString() + ' metrics on ' + @@ -1818,7 +1828,7 @@ function renderPage(menus, data) { if (!isMemoryModeDbEngine) { sidebar += '
     
    Get more history by ' + - 'configuring Netdata\'s history or using the DB engine.' + 'configuring Netdata\'s history or using the DB engine.'; } sidebar += '
     
    netdata
    ' + data.version.toString() + '
  • '; @@ -1933,7 +1943,7 @@ function renderChartsAndMenu(data) { function loadJs(url, callback) { $.ajax({ - url: url, + url: url.startsWith("http") ? url : transformWithOldSuffix(url), cache: true, dataType: "script", xhrFields: { withCredentials: true } // required for the cookie @@ -1980,7 +1990,7 @@ function loadBootstrapSlider(callback) { if (bootstrapSliderLoaded === false) { bootstrapSliderLoaded = true; loadJs('lib/bootstrap-slider-10.0.0.min.js', function () { - NETDATA._loadCSS('css/bootstrap-slider-10.0.0.min.css'); + NETDATA._loadCSS(transformWithOldSuffix("css/bootstrap-slider-10.0.0.min.css")); callback(); }); } else { @@ -4806,11 +4816,7 @@ function signInDidClick(e) { } function shouldShowSignInBanner() { - if (isSignedIn()) { - return false; - } - - return localStorage.getItem("signInBannerClosed") != "true"; + return false; } function closeSignInBanner() { @@ -4894,43 +4900,6 @@ function signOut() { cloudSSOSignOut(); } -function renderAccountUI() { - if (!NETDATA.registry.isCloudEnabled) { - return - } - - const container = document.getElementById("account-menu-container"); - if (isSignedIn()) { - container.removeAttribute("title"); - container.removeAttribute("data-original-title"); - container.removeAttribute("data-placement"); - container.innerHTML = ( - ` - ` - ) - document.getElementById("amc-account-name").textContent = cloudAccountName; // Anti-XSS - } else { - container.setAttribute("data-original-title", "sign in"); - container.setAttribute("data-placement", "bottom"); - container.innerHTML = ( - `` - ) - } -} - function handleMessage(e) { switch (e.data.type) { case "sign-in": @@ -4956,13 +4925,13 @@ function handleSignInMessage(e) { netdataRegistryCallback(registryAgents); if (e.data.redirectURI && !window.location.href.includes(e.data.redirectURI)) { - window.location.replace(e.data.redirectURI); + // lgtm false-positive - redirectURI does not come from user input, but from iframe callback + window.location.replace(e.data.redirectURI); // lgtm[js/client-side-unvalidated-url-redirection] } } function handleSignOutMessage(e) { clearCloudVariables(); - renderAccountUI(); renderMyNetdataMenu(registryAgents); } @@ -5116,7 +5085,6 @@ function initCloud() { } touchAgent(); - renderAccountUI(); } // This callback is called after NETDATA.registry is initialized. @@ -5128,7 +5096,7 @@ function netdataRegistryCallback(machinesArray) { registryAgents = machinesArray; if (isSignedIn()) { - // We call getCloudAccountAgents() here because it requires that + // We call getCloudAccountAgents() here because it requires that // NETDATA.registry is initialized. clearMyNetdataMenu(); getCloudAccountAgents().then((agents) => { @@ -5154,8 +5122,8 @@ function netdataRegistryCallback(machinesArray) { } }; -// If we know the cloudBaseURL and agentID from local storage render (eagerly) -// the account ui before receiving the definitive response from the web server. +// If we know the cloudBaseURL and agentID from local storage render (eagerly) +// the account ui before receiving the definitive response from the web server. // This improves the perceived performance. function tryFastInitCloud() { const baseURL = localStorage.getItem("cloud.baseURL"); @@ -5183,5 +5151,5 @@ if (document.readyState === "complete") { if (document.readyState === "complete") { initializeApp(); } - }) + }); } -- cgit v1.2.3