Codacy js fixes (#5337)
* Ignore main.js which will be deprecated and fix some warnings in dashboard * Minor fixes to resolve codacy issues in dashboard.js.
Chris Akritidis committed
Feb 6, 2019 at 15:52 UTC
59419c71f7064b0270ea249280122f97d47fe33d
5 files changed
+111
-102
.codacy.yml
+1
@@ -11,4 +11,5 @@ exclude_paths:
11
- web/gui/lib/**
12
- web/gui/old/**
13
- web/gui/src/**
14
+ - web/gui/main.js
15
- tests/**
web/gui/dashboard.js
+55
-51
@@ -2930,6 +2930,9 @@ NETDATA.sparklineChartCreate = function (state, data) {
2930
};
2931
// google charts
2932
2933
+// Codacy declarations
2934
+/* global google */
2935
+
2936
NETDATA.googleInitialize = function (callback) {
2937
if (typeof netdataNoGoogleCharts === 'undefined' || !netdataNoGoogleCharts) {
2938
$.ajax({
@@ -4988,6 +4991,7 @@ NETDATA.commonColors = {
4991
4992
// Codacy declarations
4993
/* global clipboard */
4994
+/* global Ps */
4995
4996
if (NETDATA.options.debug.main_loop) {
4997
console.log('welcome to NETDATA');
@@ -6256,6 +6260,55 @@ let chartState = function (element) {
6260
this.tm.last_dom_created = 0;
6261
};
6262
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
+
6312
let createDOM = () => {
6313
if (!this.enabled) {
6314
return;
@@ -6329,47 +6382,6 @@ let chartState = function (element) {
6382
}
6383
};
6384
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
-
6385
const hideMessage = () => {
6386
if (typeof this.tmp.___messageHidden___ === 'undefined') {
6387
this.tmp.___messageHidden___ = true;
@@ -6393,14 +6405,6 @@ let chartState = function (element) {
6405
showMessageIcon(icon + ' netdata' + invisibleSearchableText());
6406
};
6407
6396
- const showLoading = () => {
6397
- if (!this.chart_created) {
6398
- showMessageIcon(NETDATA.icons.loading + ' netdata');
6399
- return true;
6400
- }
6401
- return false;
6402
- };
6403
-
6408
const isHidden = () => {
6409
return (typeof this.tmp.___chartIsHidden___ !== 'undefined');
6410
};
@@ -8828,7 +8832,7 @@ NETDATA.resetAllCharts = function (state) {
8832
// if (NETDATA.globalPanAndZoom.isMaster(state) === false) {
8833
// master = false;
8834
// }
8831
- const master = NETDATA.globalPanAndZoom.isMaster(state)
8835
+ const master = NETDATA.globalPanAndZoom.isMaster(state);
8836
8837
// clear the global Pan and Zoom
8838
// this will also refresh the master
@@ -9758,7 +9762,7 @@ NETDATA.registry = {
9762
NETDATA.registry.hello(NETDATA.serverDefault, function (data) {
9763
if (data) {
9764
NETDATA.registry.server = data.registry;
9761
- if (data.cloud_base_url != "") {
9765
+ if (data.cloud_base_url !== "") {
9766
NETDATA.registry.isCloudEnabled = true;
9767
NETDATA.registry.cloudBaseURL = data.cloud_base_url;
9768
} else {
web/gui/src/dashboard.js/charting/google-charts.js
+3
@@ -1,5 +1,8 @@
1
// google charts
2
3
+// Codacy declarations
4
+/* global google */
5
+
6
NETDATA.googleInitialize = function (callback) {
7
if (typeof netdataNoGoogleCharts === 'undefined' || !netdataNoGoogleCharts) {
8
$.ajax({
web/gui/src/dashboard.js/main.js
+51
-50
@@ -3,6 +3,7 @@
3
4
// Codacy declarations
5
/* global clipboard */
6
+/* global Ps */
7
8
if (NETDATA.options.debug.main_loop) {
9
console.log('welcome to NETDATA');
@@ -1271,6 +1272,55 @@ let chartState = function (element) {
1272
this.tm.last_dom_created = 0;
1273
};
1274
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
+
1324
let createDOM = () => {
1325
if (!this.enabled) {
1326
return;
@@ -1344,47 +1394,6 @@ let chartState = function (element) {
1394
}
1395
};
1396
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
-
1397
const hideMessage = () => {
1398
if (typeof this.tmp.___messageHidden___ === 'undefined') {
1399
this.tmp.___messageHidden___ = true;
@@ -1408,14 +1417,6 @@ let chartState = function (element) {
1417
showMessageIcon(icon + ' netdata' + invisibleSearchableText());
1418
};
1419
1411
- const showLoading = () => {
1412
- if (!this.chart_created) {
1413
- showMessageIcon(NETDATA.icons.loading + ' netdata');
1414
- return true;
1415
- }
1416
- return false;
1417
- };
1418
-
1420
const isHidden = () => {
1421
return (typeof this.tmp.___chartIsHidden___ !== 'undefined');
1422
};
@@ -3843,7 +3844,7 @@ NETDATA.resetAllCharts = function (state) {
3844
// if (NETDATA.globalPanAndZoom.isMaster(state) === false) {
3845
// master = false;
3846
// }
3846
- const master = NETDATA.globalPanAndZoom.isMaster(state)
3847
+ const master = NETDATA.globalPanAndZoom.isMaster(state);
3848
3849
// clear the global Pan and Zoom
3850
// this will also refresh the master
web/gui/src/dashboard.js/registry.js
+1
-1
@@ -75,7 +75,7 @@ NETDATA.registry = {
75
NETDATA.registry.hello(NETDATA.serverDefault, function (data) {
76
if (data) {
77
NETDATA.registry.server = data.registry;
78
- if (data.cloud_base_url != "") {
78
+ if (data.cloud_base_url !== "") {
79
NETDATA.registry.isCloudEnabled = true;
80
NETDATA.registry.cloudBaseURL = data.cloud_base_url;
81
} else {