Skip to content

Commit 59419c7

Browse files
authored
Codacy js fixes (netdata#5337)
* Ignore main.js which will be deprecated and fix some warnings in dashboard * Minor fixes to resolve codacy issues in dashboard.js.
1 parent ad6fdf8 commit 59419c7

File tree

5 files changed

+111
-102
lines changed

5 files changed

+111
-102
lines changed

.codacy.yml

+1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ exclude_paths:
1111
- web/gui/lib/**
1212
- web/gui/old/**
1313
- web/gui/src/**
14+
- web/gui/main.js
1415
- tests/**

web/gui/dashboard.js

+55-51
Original file line numberDiff line numberDiff line change
@@ -2930,6 +2930,9 @@ NETDATA.sparklineChartCreate = function (state, data) {
29302930
};
29312931
// google charts
29322932

2933+
// Codacy declarations
2934+
/* global google */
2935+
29332936
NETDATA.googleInitialize = function (callback) {
29342937
if (typeof netdataNoGoogleCharts === 'undefined' || !netdataNoGoogleCharts) {
29352938
$.ajax({
@@ -4988,6 +4991,7 @@ NETDATA.commonColors = {
49884991

49894992
// Codacy declarations
49904993
/* global clipboard */
4994+
/* global Ps */
49914995

49924996
if (NETDATA.options.debug.main_loop) {
49934997
console.log('welcome to NETDATA');
@@ -6256,6 +6260,55 @@ let chartState = function (element) {
62566260
this.tm.last_dom_created = 0;
62576261
};
62586262

6263+
const maxMessageFontSize = () => {
6264+
let screenHeight = screen.height;
6265+
let el = this.element;
6266+
6267+
// normally we want a font size, as tall as the element
6268+
let h = el.clientHeight;
6269+
6270+
// but give it some air, 20% let's say, or 5 pixels min
6271+
let lost = Math.max(h * 0.2, 5);
6272+
h -= lost;
6273+
6274+
// center the text, vertically
6275+
let paddingTop = (lost - 5) / 2;
6276+
6277+
// but check the width too
6278+
// it should fit 10 characters in it
6279+
let w = el.clientWidth / 10;
6280+
if (h > w) {
6281+
paddingTop += (h - w) / 2;
6282+
h = w;
6283+
}
6284+
6285+
// and don't make it too huge
6286+
// 5% of the screen size is good
6287+
if (h > screenHeight / 20) {
6288+
paddingTop += (h - (screenHeight / 20)) / 2;
6289+
h = screenHeight / 20;
6290+
}
6291+
6292+
// set it
6293+
this.element_message.style.fontSize = h.toString() + 'px';
6294+
this.element_message.style.paddingTop = paddingTop.toString() + 'px';
6295+
};
6296+
6297+
const showMessageIcon = (icon) => {
6298+
this.element_message.innerHTML = icon;
6299+
maxMessageFontSize();
6300+
$(this.element_message).removeClass('hidden');
6301+
this.tmp.___messageHidden___ = undefined;
6302+
};
6303+
6304+
const showLoading = () => {
6305+
if (!this.chart_created) {
6306+
showMessageIcon(NETDATA.icons.loading + ' netdata');
6307+
return true;
6308+
}
6309+
return false;
6310+
};
6311+
62596312
let createDOM = () => {
62606313
if (!this.enabled) {
62616314
return;
@@ -6329,47 +6382,6 @@ let chartState = function (element) {
63296382
}
63306383
};
63316384

6332-
const maxMessageFontSize = () => {
6333-
let screenHeight = screen.height;
6334-
let el = this.element;
6335-
6336-
// normally we want a font size, as tall as the element
6337-
let h = el.clientHeight;
6338-
6339-
// but give it some air, 20% let's say, or 5 pixels min
6340-
let lost = Math.max(h * 0.2, 5);
6341-
h -= lost;
6342-
6343-
// center the text, vertically
6344-
let paddingTop = (lost - 5) / 2;
6345-
6346-
// but check the width too
6347-
// it should fit 10 characters in it
6348-
let w = el.clientWidth / 10;
6349-
if (h > w) {
6350-
paddingTop += (h - w) / 2;
6351-
h = w;
6352-
}
6353-
6354-
// and don't make it too huge
6355-
// 5% of the screen size is good
6356-
if (h > screenHeight / 20) {
6357-
paddingTop += (h - (screenHeight / 20)) / 2;
6358-
h = screenHeight / 20;
6359-
}
6360-
6361-
// set it
6362-
this.element_message.style.fontSize = h.toString() + 'px';
6363-
this.element_message.style.paddingTop = paddingTop.toString() + 'px';
6364-
};
6365-
6366-
const showMessageIcon = (icon) => {
6367-
this.element_message.innerHTML = icon;
6368-
maxMessageFontSize();
6369-
$(this.element_message).removeClass('hidden');
6370-
this.tmp.___messageHidden___ = undefined;
6371-
};
6372-
63736385
const hideMessage = () => {
63746386
if (typeof this.tmp.___messageHidden___ === 'undefined') {
63756387
this.tmp.___messageHidden___ = true;
@@ -6393,14 +6405,6 @@ let chartState = function (element) {
63936405
showMessageIcon(icon + ' netdata' + invisibleSearchableText());
63946406
};
63956407

6396-
const showLoading = () => {
6397-
if (!this.chart_created) {
6398-
showMessageIcon(NETDATA.icons.loading + ' netdata');
6399-
return true;
6400-
}
6401-
return false;
6402-
};
6403-
64046408
const isHidden = () => {
64056409
return (typeof this.tmp.___chartIsHidden___ !== 'undefined');
64066410
};
@@ -8828,7 +8832,7 @@ NETDATA.resetAllCharts = function (state) {
88288832
// if (NETDATA.globalPanAndZoom.isMaster(state) === false) {
88298833
// master = false;
88308834
// }
8831-
const master = NETDATA.globalPanAndZoom.isMaster(state)
8835+
const master = NETDATA.globalPanAndZoom.isMaster(state);
88328836

88338837
// clear the global Pan and Zoom
88348838
// this will also refresh the master
@@ -9758,7 +9762,7 @@ NETDATA.registry = {
97589762
NETDATA.registry.hello(NETDATA.serverDefault, function (data) {
97599763
if (data) {
97609764
NETDATA.registry.server = data.registry;
9761-
if (data.cloud_base_url != "") {
9765+
if (data.cloud_base_url !== "") {
97629766
NETDATA.registry.isCloudEnabled = true;
97639767
NETDATA.registry.cloudBaseURL = data.cloud_base_url;
97649768
} else {

web/gui/src/dashboard.js/charting/google-charts.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// google charts
22

3+
// Codacy declarations
4+
/* global google */
5+
36
NETDATA.googleInitialize = function (callback) {
47
if (typeof netdataNoGoogleCharts === 'undefined' || !netdataNoGoogleCharts) {
58
$.ajax({

web/gui/src/dashboard.js/main.js

+51-50
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
// Codacy declarations
55
/* global clipboard */
6+
/* global Ps */
67

78
if (NETDATA.options.debug.main_loop) {
89
console.log('welcome to NETDATA');
@@ -1271,6 +1272,55 @@ let chartState = function (element) {
12711272
this.tm.last_dom_created = 0;
12721273
};
12731274

1275+
const maxMessageFontSize = () => {
1276+
let screenHeight = screen.height;
1277+
let el = this.element;
1278+
1279+
// normally we want a font size, as tall as the element
1280+
let h = el.clientHeight;
1281+
1282+
// but give it some air, 20% let's say, or 5 pixels min
1283+
let lost = Math.max(h * 0.2, 5);
1284+
h -= lost;
1285+
1286+
// center the text, vertically
1287+
let paddingTop = (lost - 5) / 2;
1288+
1289+
// but check the width too
1290+
// it should fit 10 characters in it
1291+
let w = el.clientWidth / 10;
1292+
if (h > w) {
1293+
paddingTop += (h - w) / 2;
1294+
h = w;
1295+
}
1296+
1297+
// and don't make it too huge
1298+
// 5% of the screen size is good
1299+
if (h > screenHeight / 20) {
1300+
paddingTop += (h - (screenHeight / 20)) / 2;
1301+
h = screenHeight / 20;
1302+
}
1303+
1304+
// set it
1305+
this.element_message.style.fontSize = h.toString() + 'px';
1306+
this.element_message.style.paddingTop = paddingTop.toString() + 'px';
1307+
};
1308+
1309+
const showMessageIcon = (icon) => {
1310+
this.element_message.innerHTML = icon;
1311+
maxMessageFontSize();
1312+
$(this.element_message).removeClass('hidden');
1313+
this.tmp.___messageHidden___ = undefined;
1314+
};
1315+
1316+
const showLoading = () => {
1317+
if (!this.chart_created) {
1318+
showMessageIcon(NETDATA.icons.loading + ' netdata');
1319+
return true;
1320+
}
1321+
return false;
1322+
};
1323+
12741324
let createDOM = () => {
12751325
if (!this.enabled) {
12761326
return;
@@ -1344,47 +1394,6 @@ let chartState = function (element) {
13441394
}
13451395
};
13461396

1347-
const maxMessageFontSize = () => {
1348-
let screenHeight = screen.height;
1349-
let el = this.element;
1350-
1351-
// normally we want a font size, as tall as the element
1352-
let h = el.clientHeight;
1353-
1354-
// but give it some air, 20% let's say, or 5 pixels min
1355-
let lost = Math.max(h * 0.2, 5);
1356-
h -= lost;
1357-
1358-
// center the text, vertically
1359-
let paddingTop = (lost - 5) / 2;
1360-
1361-
// but check the width too
1362-
// it should fit 10 characters in it
1363-
let w = el.clientWidth / 10;
1364-
if (h > w) {
1365-
paddingTop += (h - w) / 2;
1366-
h = w;
1367-
}
1368-
1369-
// and don't make it too huge
1370-
// 5% of the screen size is good
1371-
if (h > screenHeight / 20) {
1372-
paddingTop += (h - (screenHeight / 20)) / 2;
1373-
h = screenHeight / 20;
1374-
}
1375-
1376-
// set it
1377-
this.element_message.style.fontSize = h.toString() + 'px';
1378-
this.element_message.style.paddingTop = paddingTop.toString() + 'px';
1379-
};
1380-
1381-
const showMessageIcon = (icon) => {
1382-
this.element_message.innerHTML = icon;
1383-
maxMessageFontSize();
1384-
$(this.element_message).removeClass('hidden');
1385-
this.tmp.___messageHidden___ = undefined;
1386-
};
1387-
13881397
const hideMessage = () => {
13891398
if (typeof this.tmp.___messageHidden___ === 'undefined') {
13901399
this.tmp.___messageHidden___ = true;
@@ -1408,14 +1417,6 @@ let chartState = function (element) {
14081417
showMessageIcon(icon + ' netdata' + invisibleSearchableText());
14091418
};
14101419

1411-
const showLoading = () => {
1412-
if (!this.chart_created) {
1413-
showMessageIcon(NETDATA.icons.loading + ' netdata');
1414-
return true;
1415-
}
1416-
return false;
1417-
};
1418-
14191420
const isHidden = () => {
14201421
return (typeof this.tmp.___chartIsHidden___ !== 'undefined');
14211422
};
@@ -3843,7 +3844,7 @@ NETDATA.resetAllCharts = function (state) {
38433844
// if (NETDATA.globalPanAndZoom.isMaster(state) === false) {
38443845
// master = false;
38453846
// }
3846-
const master = NETDATA.globalPanAndZoom.isMaster(state)
3847+
const master = NETDATA.globalPanAndZoom.isMaster(state);
38473848

38483849
// clear the global Pan and Zoom
38493850
// this will also refresh the master

web/gui/src/dashboard.js/registry.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ NETDATA.registry = {
7575
NETDATA.registry.hello(NETDATA.serverDefault, function (data) {
7676
if (data) {
7777
NETDATA.registry.server = data.registry;
78-
if (data.cloud_base_url != "") {
78+
if (data.cloud_base_url !== "") {
7979
NETDATA.registry.isCloudEnabled = true;
8080
NETDATA.registry.cloudBaseURL = data.cloud_base_url;
8181
} else {

0 commit comments

Comments
 (0)