mirror of https://github.com/MISP/MISP
chg: [decaying] Improved UI and limit number of digit in parameters
parent
5e54a9c311
commit
d21e33c91c
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
|
@ -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 == '') {
|
||||
|
|
Loading…
Reference in New Issue