chg: [decaying] Improved UI and limit number of digit in parameters

pull/5032/head
mokaddem 2019-07-09 09:49:08 +02:00
parent 5e54a9c311
commit d21e33c91c
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
4 changed files with 47 additions and 7 deletions

View File

@ -48,7 +48,11 @@ class DecayingModel extends AppModel
if (!empty($this->data['DecayingModel']['parameters']) && !is_array($this->data['DecayingModel']['parameters'])) {
$encoded = json_decode($this->data['DecayingModel']['parameters'], true);
if ($encoded !== null) {
return $this->__validateParameters($encoded);
$validation = $this->__validateParameters($encoded);
if ($validation !== false) {
$this->data['DecayingModel']['parameters'] = json_encode($encoded);
return true;
}
}
return false;
}
@ -81,10 +85,20 @@ class DecayingModel extends AppModel
return true;
}
private function __validateParameters($parameters)
/*
* may be done at some point but we still want to be generic
* so enforcing hardcoded tests here may not be the best solution
* For now, limit the number of digits for the parameters
*/
private function __validateParameters(&$parameters)
{
// may be done at some point but we still want to be generic
// so enforcing hardcoded tests here may not be the best solution
foreach ($parameters as $name => $value) {
if (is_array($value)) {
$this->__validateParameters($parameters[$name]);
} else if (is_numeric($value)) {
$parameters[$name] = round($value, 4);
}
}
return true;
}

View File

@ -184,7 +184,7 @@ $(document).ready(function() {
var text = $(this).text().trim();
var parsedJson = ''
if (text !== '') {
parsedJson = syntaxHighlightJson(text);
parsedJson = jsonToNestedTable(text, [], ['table', 'table-condensed', 'table-bordered']);
}
$(this).html(parsedJson);
});

View File

@ -437,7 +437,7 @@
var data = this.retreiveData();
delete data['name'];
delete data['description'];
var $rows = $('#modelTableBody').find('tr');
var $rows = $('#modelTableBody > tr');
$rows.removeClass('success');
$('div.input-prepend > span.param-name, #summary_base_score_config').removeClass('success');
$rows.each(function(i) {
@ -484,7 +484,7 @@
var text = $(this).text().trim();
var parsedJson = '';
if (text !== '') {
parsedJson = syntaxHighlightJson(text);
parsedJson = jsonToNestedTable(text, [], ['table', 'table-condensed', 'table-bordered']);
}
$(this).html(parsedJson);
});

View File

@ -4249,6 +4249,32 @@ function syntaxHighlightJson(json, indent) {
});
}
function jsonToNestedTable(json, header, table_classes) {
if (typeof json == 'string') {
json = JSON.parse(json);
}
header = header === undefined ? [] : header;
table_classes = table_classes === undefined ? [] : table_classes;
$table = $('<table></table>');
table_classes.forEach(function(classname) {
$table.addClass(classname);
});
if (header.length > 0) {
$header = $('<thead><tr></tr></thead>');
header.forEach(function(col) {
$header.child().append($('<td>' + col + '</td>'));
});
$table.append($header);
}
$body = $('<tbody></tbody>');
Object.keys(json).forEach(function(k) {
var value = json[k];
$body.append($('<tr><td>' + k + '</td><td>' + value + '</td></tr>'))
});
$table.append($body);
return $table[0].outerHTML;
}
function liveFilter() {
var lookupString = $('#liveFilterField').val();
if (lookupString == '') {