Commit 74c93941 by kevalbhatt

ATLAS-3991: UI: Handlebar helper number format issue

parent 3c0b2746
......@@ -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) {
......
......@@ -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) {
......
......@@ -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 {
......
......@@ -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>';
}
});
......
......@@ -277,7 +277,7 @@ define(['require',
"type": "classification"
})
);
this.ui.classification.find(".count").html("&nbsp;(" + _.numberFormatWithComa(tagsCount) + ")");
this.ui.classification.find(".count").html("&nbsp;(" + _.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("&nbsp;(" + _.numberFormatWithComa(activeEntityCount) + ")");
this.$('[data-id="deletedEntity"]').html("&nbsp;(" + _.numberFormatWithComa(deletedEntityCount) + ")");
this.$('[data-id="shellEntity"]').html("&nbsp;(" + _.numberFormatWithComa(shellEntityCount) + ")");
this.ui.entity.find(".count").html("&nbsp;(" + _.numberFormatWithComa(data.general.entityCount) + ")");
this.$('[data-id="activeEntity"]').html("&nbsp;(" + _.numberFormatWithComma(activeEntityCount) + ")");
this.$('[data-id="deletedEntity"]').html("&nbsp;(" + _.numberFormatWithComma(deletedEntityCount) + ")");
this.$('[data-id="shellEntity"]').html("&nbsp;(" + _.numberFormatWithComma(shellEntityCount) + ")");
this.ui.entity.find(".count").html("&nbsp;(" + _.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 {
......
......@@ -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) {
......
......@@ -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) {
......
......@@ -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 {
......
......@@ -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)) {
......
......@@ -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) {
......
......@@ -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,
......
......@@ -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("&nbsp;(" + _.numberFormatWithComa(activeEntityCount) + ")");
that.$('[data-id="deletedEntity"]').html("&nbsp;(" + _.numberFormatWithComa(deletedEntityCount) + ")");
that.ui.entityHeader.html("&nbsp;(" + _.numberFormatWithComa(data.general.entityCount) + ")");
that.$('[data-id="activeEntity"]').html("&nbsp;(" + _.numberFormatWithComma(activeEntityCount) + ")");
that.$('[data-id="deletedEntity"]').html("&nbsp;(" + _.numberFormatWithComma(deletedEntityCount) + ")");
that.ui.entityHeader.html("&nbsp;(" + _.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 {
......
......@@ -185,7 +185,7 @@ define(['require',
"type": "classification"
})
);
this.ui.classification.find(".count").html("&nbsp;(" + _.numberFormatWithComa(tagsCount) + ")");
this.ui.classification.find(".count").html("&nbsp;(" + _.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("&nbsp;(" + _.numberFormatWithComa(activeEntityCount) + ")");
this.$('[data-id="deletedEntity"]').html("&nbsp;(" + _.numberFormatWithComa(deletedEntityCount) + ")");
this.$('[data-id="shellEntity"]').html("&nbsp;(" + _.numberFormatWithComa(shellEntityCount) + ")");
this.ui.entity.find(".count").html("&nbsp;(" + _.numberFormatWithComa(data.general.entityCount) + ")");
this.$('[data-id="activeEntity"]').html("&nbsp;(" + _.numberFormatWithComma(activeEntityCount) + ")");
this.$('[data-id="deletedEntity"]').html("&nbsp;(" + _.numberFormatWithComma(deletedEntityCount) + ")");
this.$('[data-id="shellEntity"]').html("&nbsp;(" + _.numberFormatWithComma(shellEntityCount) + ")");
this.ui.entity.find(".count").html("&nbsp;(" + _.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 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment