You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@atlas.apache.org by kb...@apache.org on 2020/10/13 13:23:31 UTC
[atlas] 02/02: ATLAS-3991: UI: Handlebar helper number format issue
This is an automated email from the ASF dual-hosted git repository.
kbhatt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/atlas.git
commit 74c9394148d175950615f82455dc1e302000c01b
Author: kevalbhatt <kb...@apache.org>
AuthorDate: Tue Oct 13 18:44:07 2020 +0530
ATLAS-3991: UI: Handlebar helper number format issue
---
dashboardv2/public/js/modules/Helpers.js | 24 ++++++++++++++--------
dashboardv2/public/js/utils/CommonViewFunction.js | 2 +-
dashboardv2/public/js/utils/Helper.js | 4 ++--
.../public/js/views/search/SearchLayoutView.js | 4 ++--
dashboardv2/public/js/views/site/Statistics.js | 18 ++++++++--------
dashboardv3/public/js/modules/Helpers.js | 24 ++++++++++++++--------
dashboardv3/public/js/utils/CommonViewFunction.js | 2 +-
dashboardv3/public/js/utils/Helper.js | 4 ++--
.../public/js/views/search/SearchLayoutView.js | 4 ++--
.../search/tree/ClassificationTreeLayoutView.js | 4 ++--
.../js/views/search/tree/EntityTreeLayoutView.js | 4 ++--
dashboardv3/public/js/views/site/Favorite.js | 14 ++++++-------
dashboardv3/public/js/views/site/Statistics.js | 18 ++++++++--------
13 files changed, 69 insertions(+), 57 deletions(-)
diff --git a/dashboardv2/public/js/modules/Helpers.js b/dashboardv2/public/js/modules/Helpers.js
index 7ef5f25..cd1ccee 100644
--- a/dashboardv2/public/js/modules/Helpers.js
+++ b/dashboardv2/public/js/modules/Helpers.js
@@ -102,29 +102,35 @@ define(['require',
//return options.inverse(this);
});
- Handlebars.registerHelper('arithmetic', function(val1, operator, val2, options) {
- var v1 = parseInt(val1) || 0,
- v2 = parseInt(val2) || 0;
+ Handlebars.registerHelper('arithmetic', function(val1, operator, val2, commaFormat, options) {
+ var v1 = (val1 && parseInt(val1.toString().replace(/\,/g, ''))) || 0,
+ v2 = (val2 && parseInt(val2.toString().replace(/\,/g, ''))) || 0,
+ val = null;
switch (operator) {
case '+':
- return (v1 + v2);
+ val = v1 + v2;
break;
case '-':
- return (v1 - v2);
+ val = v1 - v2;
break;
case '/':
- return (v1 / v2);
+ val = v1 / v2;
break;
case '*':
- return (v1 * v2);
+ val = v1 * v2;
break;
case '%':
- return (v1 % v2);
+ val = v1 % v2;
break;
default:
- return 0;
+ val = 0;
break;
}
+ if (commaFormat === false) {
+ return val;
+ }
+ return _.numberFormatWithComma(val);;
+
});
Handlebars.registerHelper('lookup', function(obj, field, defaulValue) {
diff --git a/dashboardv2/public/js/utils/CommonViewFunction.js b/dashboardv2/public/js/utils/CommonViewFunction.js
index 4fcb0fc..f766204 100644
--- a/dashboardv2/public/js/utils/CommonViewFunction.js
+++ b/dashboardv2/public/js/utils/CommonViewFunction.js
@@ -87,7 +87,7 @@ define(['require', 'utils/Utils', 'modules/Modal', 'utils/Messages', 'utils/Enum
showListCount = options.showListCount || true,
highlightString = options.highlightString,
formatStringVal = options.formatStringVal,
- numberFormat = options.numberFormat || _.numberFormatWithComa;
+ numberFormat = options.numberFormat || _.numberFormatWithComma;
var table = "",
getHighlightedString = function(resultStr) {
diff --git a/dashboardv2/public/js/utils/Helper.js b/dashboardv2/public/js/utils/Helper.js
index ead6e2f..8b9f4c5 100644
--- a/dashboardv2/public/js/utils/Helper.js
+++ b/dashboardv2/public/js/utils/Helper.js
@@ -23,7 +23,7 @@ define(['require',
], function(require, Utils, d3) {
'use strict';
_.mixin({
- numberFormatWithComa: function(number) {
+ numberFormatWithComma: function(number) {
return d3.format(',')(number);
},
numberFormatWithBytes: function(number) {
@@ -33,7 +33,7 @@ define(['require',
}
var i = number == 0 ? 0 : Math.floor(Math.log(number) / Math.log(1024));
if (i > 8) {
- return _.numberFormatWithComa(number);
+ return _.numberFormatWithComma(number);
}
return Number((number / Math.pow(1024, i)).toFixed(2)) + " " + ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"][i];
} else {
diff --git a/dashboardv2/public/js/views/search/SearchLayoutView.js b/dashboardv2/public/js/views/search/SearchLayoutView.js
index b828d29..4b643bb 100644
--- a/dashboardv2/public/js/views/search/SearchLayoutView.js
+++ b/dashboardv2/public/js/views/search/SearchLayoutView.js
@@ -545,7 +545,7 @@ define(['require',
var name = Utils.getName(model.toJSON(), 'name');
if (model.get('category') == 'ENTITY' && (serviceTypeToBefiltered && serviceTypeToBefiltered.length ? _.contains(serviceTypeToBefiltered, model.get('serviceType')) : true)) {
var entityCount = (that.entityCountObj.entity.entityActive[name] || 0) + (that.entityCountObj.entity.entityDeleted[name] || 0);
- typeStr += '<option value="' + (name) + '" data-name="' + (name) + '">' + (name) + ' ' + (entityCount ? "(" + _.numberFormatWithComa(entityCount) + ")" : '') + '</option>';
+ typeStr += '<option value="' + (name) + '" data-name="' + (name) + '">' + (name) + ' ' + (entityCount ? "(" + _.numberFormatWithComma(entityCount) + ")" : '') + '</option>';
}
if (isTypeOnly == undefined && model.get('category') == 'CLASSIFICATION') {
var tagEntityCount = that.entityCountObj.tag.tagEntities[name];
@@ -554,7 +554,7 @@ define(['require',
foundNewClassification = true;
}
}
- tagStr += '<option value="' + (name) + '" data-name="' + (name) + '">' + (name) + ' ' + (tagEntityCount ? "(" + _.numberFormatWithComa(tagEntityCount) + ")" : '') + '</option>';
+ tagStr += '<option value="' + (name) + '" data-name="' + (name) + '">' + (name) + ' ' + (tagEntityCount ? "(" + _.numberFormatWithComma(tagEntityCount) + ")" : '') + '</option>';
}
});
diff --git a/dashboardv2/public/js/views/site/Statistics.js b/dashboardv2/public/js/views/site/Statistics.js
index d469fe8..8284129 100644
--- a/dashboardv2/public/js/views/site/Statistics.js
+++ b/dashboardv2/public/js/views/site/Statistics.js
@@ -277,7 +277,7 @@ define(['require',
"type": "classification"
})
);
- this.ui.classification.find(".count").html(" (" + _.numberFormatWithComa(tagsCount) + ")");
+ this.ui.classification.find(".count").html(" (" + _.numberFormatWithComma(tagsCount) + ")");
if (tagEntitiesKeys.length > this.DATA_MAX_LENGTH) {
this.closePanel({
el: this.ui.classification
@@ -310,7 +310,7 @@ define(['require',
if (type == "shell") {
shellEntityCount += intVal
}
- intVal = _.numberFormatWithComa(intVal)
+ intVal = _.numberFormatWithComma(intVal)
if (stats[key]) {
stats[key][type] = intVal;
} else {
@@ -341,10 +341,10 @@ define(['require',
})),
})
);
- this.$('[data-id="activeEntity"]').html(" (" + _.numberFormatWithComa(activeEntityCount) + ")");
- this.$('[data-id="deletedEntity"]').html(" (" + _.numberFormatWithComa(deletedEntityCount) + ")");
- this.$('[data-id="shellEntity"]').html(" (" + _.numberFormatWithComa(shellEntityCount) + ")");
- this.ui.entity.find(".count").html(" (" + _.numberFormatWithComa(data.general.entityCount) + ")");
+ this.$('[data-id="activeEntity"]').html(" (" + _.numberFormatWithComma(activeEntityCount) + ")");
+ this.$('[data-id="deletedEntity"]').html(" (" + _.numberFormatWithComma(deletedEntityCount) + ")");
+ this.$('[data-id="shellEntity"]').html(" (" + _.numberFormatWithComma(shellEntityCount) + ")");
+ this.ui.entity.find(".count").html(" (" + _.numberFormatWithComma(data.general.entityCount) + ")");
if (statsKeys.length > this.DATA_MAX_LENGTH) {
this.closePanel({
el: this.ui.entity
@@ -412,7 +412,7 @@ define(['require',
pickValueFrom = argument.key;
}
var returnVal = data.Notification[pickValueFrom];
- return returnVal ? _.numberFormatWithComa(returnVal) : 0;
+ return returnVal ? _.numberFormatWithComma(returnVal) : 0;
}
})
);
@@ -493,9 +493,9 @@ define(['require',
} else if (type == 'day') {
return Utils.formatDate({ date: value, dateFormat: Globals.meridiemFormat })
} else if (type == 'number') {
- return _.numberFormatWithComa(value);
+ return _.numberFormatWithComma(value);
} else if (type == 'millisecond') {
- return _.numberFormatWithComa(value) + " millisecond/s";
+ return _.numberFormatWithComma(value) + " millisecond/s";
} else if (type == "status-html") {
return '<span class="connection-status ' + value + '"></span>';
} else {
diff --git a/dashboardv3/public/js/modules/Helpers.js b/dashboardv3/public/js/modules/Helpers.js
index 7ef5f25..cd1ccee 100644
--- a/dashboardv3/public/js/modules/Helpers.js
+++ b/dashboardv3/public/js/modules/Helpers.js
@@ -102,29 +102,35 @@ define(['require',
//return options.inverse(this);
});
- Handlebars.registerHelper('arithmetic', function(val1, operator, val2, options) {
- var v1 = parseInt(val1) || 0,
- v2 = parseInt(val2) || 0;
+ Handlebars.registerHelper('arithmetic', function(val1, operator, val2, commaFormat, options) {
+ var v1 = (val1 && parseInt(val1.toString().replace(/\,/g, ''))) || 0,
+ v2 = (val2 && parseInt(val2.toString().replace(/\,/g, ''))) || 0,
+ val = null;
switch (operator) {
case '+':
- return (v1 + v2);
+ val = v1 + v2;
break;
case '-':
- return (v1 - v2);
+ val = v1 - v2;
break;
case '/':
- return (v1 / v2);
+ val = v1 / v2;
break;
case '*':
- return (v1 * v2);
+ val = v1 * v2;
break;
case '%':
- return (v1 % v2);
+ val = v1 % v2;
break;
default:
- return 0;
+ val = 0;
break;
}
+ if (commaFormat === false) {
+ return val;
+ }
+ return _.numberFormatWithComma(val);;
+
});
Handlebars.registerHelper('lookup', function(obj, field, defaulValue) {
diff --git a/dashboardv3/public/js/utils/CommonViewFunction.js b/dashboardv3/public/js/utils/CommonViewFunction.js
index 2573a60..394d62f 100644
--- a/dashboardv3/public/js/utils/CommonViewFunction.js
+++ b/dashboardv3/public/js/utils/CommonViewFunction.js
@@ -87,7 +87,7 @@ define(['require', 'utils/Utils', 'modules/Modal', 'utils/Messages', 'utils/Enum
showListCount = options.showListCount || true,
highlightString = options.highlightString,
formatStringVal = options.formatStringVal,
- numberFormat = options.numberFormat || _.numberFormatWithComa;
+ numberFormat = options.numberFormat || _.numberFormatWithComma;
var table = "",
getHighlightedString = function(resultStr) {
diff --git a/dashboardv3/public/js/utils/Helper.js b/dashboardv3/public/js/utils/Helper.js
index d21556e..b3af004 100644
--- a/dashboardv3/public/js/utils/Helper.js
+++ b/dashboardv3/public/js/utils/Helper.js
@@ -24,7 +24,7 @@ define(['require',
], function(require, Utils, d3) {
'use strict';
_.mixin({
- numberFormatWithComa: function(number) {
+ numberFormatWithComma: function(number) {
return d3.format(',')(number);
},
numberFormatWithBytes: function(number) {
@@ -34,7 +34,7 @@ define(['require',
}
var i = number == 0 ? 0 : Math.floor(Math.log(number) / Math.log(1024));
if (i > 8) {
- return _.numberFormatWithComa(number);
+ return _.numberFormatWithComma(number);
}
return Number((number / Math.pow(1024, i)).toFixed(2)) + " " + ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"][i];
} else {
diff --git a/dashboardv3/public/js/views/search/SearchLayoutView.js b/dashboardv3/public/js/views/search/SearchLayoutView.js
index 0c4eb40..c604d13 100644
--- a/dashboardv3/public/js/views/search/SearchLayoutView.js
+++ b/dashboardv3/public/js/views/search/SearchLayoutView.js
@@ -464,11 +464,11 @@ define(['require',
var name = Utils.getName(model.toJSON(), 'name');
if (model.get('category') == 'ENTITY' && (serviceTypeToBefiltered && serviceTypeToBefiltered.length ? _.contains(serviceTypeToBefiltered, model.get('serviceType')) : true)) {
var entityCount = (that.entityCountObj.entity.entityActive[name] + (that.entityCountObj.entity.entityDeleted[name] ? that.entityCountObj.entity.entityDeleted[name] : 0));
- typeStr += '<option value="' + (name) + '" data-name="' + (name) + '">' + (name) + ' ' + (entityCount ? "(" + _.numberFormatWithComa(entityCount) + ")" : '') + '</option>';
+ typeStr += '<option value="' + (name) + '" data-name="' + (name) + '">' + (name) + ' ' + (entityCount ? "(" + _.numberFormatWithComma(entityCount) + ")" : '') + '</option>';
}
if (isTypeOnly == undefined && model.get('category') == 'CLASSIFICATION') {
var tagEntityCount = that.entityCountObj.tag.tagEntities[name];
- tagStr += '<option value="' + (name) + '" data-name="' + (name) + '">' + (name) + ' ' + (tagEntityCount ? "(" + _.numberFormatWithComa(tagEntityCount) + ")" : '') + '</option>';
+ tagStr += '<option value="' + (name) + '" data-name="' + (name) + '">' + (name) + ' ' + (tagEntityCount ? "(" + _.numberFormatWithComma(tagEntityCount) + ")" : '') + '</option>';
}
});
if (_.isUndefined(isTypeOnly)) {
diff --git a/dashboardv3/public/js/views/search/tree/ClassificationTreeLayoutView.js b/dashboardv3/public/js/views/search/tree/ClassificationTreeLayoutView.js
index 08c6538..43ca358 100644
--- a/dashboardv3/public/js/views/search/tree/ClassificationTreeLayoutView.js
+++ b/dashboardv3/public/js/views/search/tree/ClassificationTreeLayoutView.js
@@ -443,7 +443,7 @@ define([
name: name
});
var tagEntityCount = that.entityCountObj.tag.tagEntities[name];
- var tagname = tagEntityCount ? name + " (" + _.numberFormatWithComa(tagEntityCount) + ")" : name;
+ var tagname = tagEntityCount ? name + " (" + _.numberFormatWithComma(tagEntityCount) + ")" : name;
if (that.options.value) {
isSelectedChild = that.options.value.tag ? that.options.value.tag == name : false;
@@ -486,7 +486,7 @@ define([
var modelJSON = model.toJSON();
var name = modelJSON.name;
var tagEntityCount = that.entityCountObj.tag.tagEntities[name];
- var tagname = tagEntityCount ? name + " (" + _.numberFormatWithComa(tagEntityCount) + ")" : name,
+ var tagname = tagEntityCount ? name + " (" + _.numberFormatWithComma(tagEntityCount) + ")" : name,
isSelected = false;
if (that.options.value) {
diff --git a/dashboardv3/public/js/views/search/tree/EntityTreeLayoutView.js b/dashboardv3/public/js/views/search/tree/EntityTreeLayoutView.js
index a859ea0..ba1c7f5 100644
--- a/dashboardv3/public/js/views/search/tree/EntityTreeLayoutView.js
+++ b/dashboardv3/public/js/views/search/tree/EntityTreeLayoutView.js
@@ -320,7 +320,7 @@ define([
var entityCount =
(that.entityCountObj.entity.entityActive[model.get("name")] || 0) +
(that.entityCountObj.entity.entityDeleted[model.get("name")] || 0),
- modelname = entityCount ? model.get("name") + " (" + _.numberFormatWithComa(entityCount) + ")" : model.get("name");
+ modelname = entityCount ? model.get("name") + " (" + _.numberFormatWithComma(entityCount) + ")" : model.get("name");
if (that.options.value) {
isSelected = that.options.value.type ? that.options.value.type == model.get("name") : false;
if (!that.typeId) {
@@ -416,7 +416,7 @@ define([
var checkEmptyServiceType = false,
getParrent = data[parents[i]],
totalCounter = getParrent.totalCounter,
- textName = getParrent.totalCounter ? parents[i] + " (" + _.numberFormatWithComa(totalCounter) + ")" : parents[i],
+ textName = getParrent.totalCounter ? parents[i] + " (" + _.numberFormatWithComma(totalCounter) + ")" : parents[i],
parent = {
icon: "fa fa-folder-o",
type: type,
diff --git a/dashboardv3/public/js/views/site/Favorite.js b/dashboardv3/public/js/views/site/Favorite.js
index c10791d..cea53e4 100644
--- a/dashboardv3/public/js/views/site/Favorite.js
+++ b/dashboardv3/public/js/views/site/Favorite.js
@@ -126,7 +126,7 @@ define(['require',
} else {
deletedEntityCount += intVal;
}
- intVal = _.numberFormatWithComa(intVal)
+ intVal = _.numberFormatWithComma(intVal)
if (stats[key]) {
stats[key][type] = intVal;
} else {
@@ -149,9 +149,9 @@ define(['require',
"data": _.pick(stats, (_.keys(stats).sort())),
})
);
- that.$('[data-id="activeEntity"]').html(" (" + _.numberFormatWithComa(activeEntityCount) + ")");
- that.$('[data-id="deletedEntity"]').html(" (" + _.numberFormatWithComa(deletedEntityCount) + ")");
- that.ui.entityHeader.html(" (" + _.numberFormatWithComa(data.general.entityCount) + ")");
+ that.$('[data-id="activeEntity"]').html(" (" + _.numberFormatWithComma(activeEntityCount) + ")");
+ that.$('[data-id="deletedEntity"]').html(" (" + _.numberFormatWithComma(deletedEntityCount) + ")");
+ that.ui.entityHeader.html(" (" + _.numberFormatWithComma(data.general.entityCount) + ")");
}
},
renderStats: function(options) {
@@ -214,7 +214,7 @@ define(['require',
pickValueFrom = argument.key;
}
var returnVal = data.Notification[pickValueFrom];
- return returnVal ? _.numberFormatWithComa(returnVal) : 0;
+ return returnVal ? _.numberFormatWithComma(returnVal) : 0;
}
})
);
@@ -246,9 +246,9 @@ define(['require',
} else if (type == 'day') {
return moment.tz(value, moment.tz.guess()).format("MM/DD/YYYY h:mm A z");
} else if (type == 'number') {
- return _.numberFormatWithComa(value);
+ return _.numberFormatWithComma(value);
} else if (type == 'millisecond') {
- return _.numberFormatWithComa(value) + " millisecond/s";
+ return _.numberFormatWithComma(value) + " millisecond/s";
} else if (type == "status-html") {
return '<span class="connection-status ' + value + '"></span>';
} else {
diff --git a/dashboardv3/public/js/views/site/Statistics.js b/dashboardv3/public/js/views/site/Statistics.js
index 52c2a53..cb2a655 100644
--- a/dashboardv3/public/js/views/site/Statistics.js
+++ b/dashboardv3/public/js/views/site/Statistics.js
@@ -185,7 +185,7 @@ define(['require',
"type": "classification"
})
);
- this.ui.classification.find(".count").html(" (" + _.numberFormatWithComa(tagsCount) + ")");
+ this.ui.classification.find(".count").html(" (" + _.numberFormatWithComma(tagsCount) + ")");
if (tagEntitiesKeys.length > this.DATA_MAX_LENGTH) {
this.closePanel({
el: this.ui.classification
@@ -218,7 +218,7 @@ define(['require',
if (type == "shell") {
shellEntityCount += intVal
}
- intVal = _.numberFormatWithComa(intVal)
+ intVal = _.numberFormatWithComma(intVal)
if (stats[key]) {
stats[key][type] = intVal;
} else {
@@ -249,10 +249,10 @@ define(['require',
})),
})
);
- this.$('[data-id="activeEntity"]').html(" (" + _.numberFormatWithComa(activeEntityCount) + ")");
- this.$('[data-id="deletedEntity"]').html(" (" + _.numberFormatWithComa(deletedEntityCount) + ")");
- this.$('[data-id="shellEntity"]').html(" (" + _.numberFormatWithComa(shellEntityCount) + ")");
- this.ui.entity.find(".count").html(" (" + _.numberFormatWithComa(data.general.entityCount) + ")");
+ this.$('[data-id="activeEntity"]').html(" (" + _.numberFormatWithComma(activeEntityCount) + ")");
+ this.$('[data-id="deletedEntity"]').html(" (" + _.numberFormatWithComma(deletedEntityCount) + ")");
+ this.$('[data-id="shellEntity"]').html(" (" + _.numberFormatWithComma(shellEntityCount) + ")");
+ this.ui.entity.find(".count").html(" (" + _.numberFormatWithComma(data.general.entityCount) + ")");
if (statsKeys.length > this.DATA_MAX_LENGTH) {
this.closePanel({
el: this.ui.entity
@@ -320,7 +320,7 @@ define(['require',
pickValueFrom = argument.key;
}
var returnVal = data.Notification[pickValueFrom];
- return returnVal ? _.numberFormatWithComa(returnVal) : 0;
+ return returnVal ? _.numberFormatWithComma(returnVal) : 0;
}
})
);
@@ -400,9 +400,9 @@ define(['require',
} else if (type == 'day') {
return Utils.formatDate({ date: value, dateFormat: Globals.meridiemFormat })
} else if (type == 'number') {
- return _.numberFormatWithComa(value);
+ return _.numberFormatWithComma(value);
} else if (type == 'millisecond') {
- return _.numberFormatWithComa(value) + " millisecond/s";
+ return _.numberFormatWithComma(value) + " millisecond/s";
} else if (type == "status-html") {
return '<span class="connection-status ' + value + '"></span>';
} else {