Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#6371 get rid of the OK button #6487

Merged
merged 17 commits into from
Jan 5, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 33 additions & 22 deletions beakerx/beakerx/static/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,28 +74,21 @@ define(function(require) {
var errors = [];

var val = $('#heap_GB').val().trim();
var parsedVal = parseFloat(val);

if (val !== '') {
if (false === isNaN(parsedVal) && parsedVal > 0) {
if (val % 1 === 0) {
result += '-Xmx' + parsedVal + 'g ';
} else {
result += '-Xmx' + parseInt(parsedVal * 1024) + 'm ';
}
} else {
errors.push('Heap Size must be a positive decimal number.');
try {
if (val !== '') {
var parsedVal = settings.normaliseHeapSize(val);
result += '-Xmx' + parsedVal + ' ';
}
} catch (e) {
errors.push(e.message);
}

var other_property = $('#other_property').find('input');
other_property.each(function() {
$('#other_property').find('input').each(function() {
var value = $(this).val().trim();
result += value + ' ';
});

var java_property = $('#properties_property').find('div');
java_property.each(function() {
$('#properties_property').find('div').each(function() {
var children = $($(this).children());
var value = $(children.get(1)).val().trim();
var name = $(children.get(0)).val().trim();
Expand Down Expand Up @@ -221,6 +214,22 @@ define(function(require) {
}).val(value).keyup(InputChanged);
},

normaliseHeapSize: function(val) {
if (val === '') {
return '';
}

var parsedVal = parseFloat(val);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is broken, please do not change how valid numbers are identified, it's actually quite tricky.
parseFloat("5a") = 5

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not change the way it was identified

see:

var val = $("#heap_GB").val().trim();
if (val.length > 0) {
if (!isNaN(val)) {
if (val % 1 === 0) {
result += '-Xmx' + val + 'g '
} else {
result += '-Xmx' + parseInt(val * 1024) + 'm '
}
}
}

if (val.length > 0 && isNaN(val)) {
$('#errors').append($('<span>').text("Heap Size must be a decimal number."));
enable_button = false;
}

All i did with it was a little extraction refactor, because i needed that logic in two different places.

I added additional check

  • isFinite(val) will catch "5a"


if (isNaN(parsedVal) || parsedVal <= 0) {
throw new Error('Heap Size must be a positive decimal number.');
}

return (val % 1 === 0) ?
parsedVal + 'g' :
parseInt(parsedVal * 1024) + 'm';
},

load: function(payload) {
if (payload === undefined) {
payload = {
Expand Down Expand Up @@ -375,6 +384,7 @@ define(function(require) {
function _submitOptions() {
var payload = {
version: 2,
heap_GB: '',
jvm_options: {
other: [],
properties: [],
Expand Down Expand Up @@ -403,13 +413,14 @@ define(function(require) {
}

});
var default_property = $('#default_options').find('input');
default_property.each(function() {
var value = $(this).val().trim();
if (value.length > 0) {
payload.jvm_options.heap_GB = value;
}
});

try {
var val = $('#heap_GB').val().trim();
settings.normaliseHeapSize(val);
payload.jvm_options.heap_GB = val;
} catch (e) {
}

settings.setVariables(JSON.stringify({
'beakerx': payload
}));
Expand Down