Commit accedc82 authored by Franco Fichtner's avatar Franco Fichtner

firmware: merge packages lists for single sorted list

parent 6c87cd42
......@@ -92,20 +92,66 @@ class FirmwareController extends ApiControllerBase
);
}
}
} else {
$response = array('status' => 'unknown', 'status_msg' => gettext('Current status is unknown.'));
}
/* XXX array isn't flat, need to refactor this */
if (isset($response['upgrade_packages'])) {
$sorted = array();
foreach ($response['upgrade_packages'] as $key => $value) {
$sorted[$value['name']] = $value;
/*
* new_packages: array with { name: <package_name>, version: <package_version> }
* reinstall_packages: array with { name: <package_name>, version: <package_version> }
* delete_packages: array with { name: <package_name>, version: <package_version> }
* upgrade_packages: array with { name: <package_name>, current_version: <current_version>, new_version: <new_version> }
*/
foreach (array('new_packages', 'reinstall_packages', 'delete_packages', 'upgrade_packages') as $pkg_type) {
if (isset($response[$pkg_type])) {
foreach ($response[$pkg_type] as $value) {
switch ($pkg_type) {
case 'new_packages':
$sorted[$value['name']] = array(
'new' => $value['version'],
'reason' => gettext('new'),
'name' => $value['name'],
'old' => gettext('N/A'),
);
break;
case 'reinstall_packages':
$sorted[$value['name']] = array(
'reason' => gettext('reinstall'),
'new' => $value['version'],
'old' => $value['version'],
'name' => $value['name'],
);
break;
case 'delete_packages':
$sorted[$value['name']] = array(
'reason' => gettext('delete'),
'old' => $value['version'],
'name' => $value['name'],
'new' => gettext('N/A'),
);
break;
case 'upgrade_packages':
$sorted[$value['name']] = array(
'reason' => gettext('update'),
'old' => $value['current_version'],
'new' => $value['new_version'],
'name' => $value['name'],
);
break;
default:
/* undefined */
break;
}
}
}
}
uksort($sorted, function ($a, $b) {
return strnatcmp($a, $b);
});
$response['upgrade_packages'] = $sorted;
$response['all_packages'] = $sorted;
} else {
$response = array('status' => 'unknown', 'status_msg' => gettext('Firmware status check was aborted internally. Please try again.'));
}
return $response;
......
......@@ -63,22 +63,12 @@ POSSIBILITY OF SUCH DAMAGE.
// show upgrade list
$('#updatetab > a').tab('show');
$("#updatelist").html("<tr><th>{{ lang._('Package Name') }}</th>" +
"<th>{{ lang._('Current Version') }}</th><th>{{ lang._('New Version') }}</th></tr>");
$.each(['new_packages', 'upgrade_packages', 'reinstall_packages'], function(type_idx,type_name){
if ( data[type_name] != undefined ) {
$.each(data[type_name],function(index,row){
if (type_name == "new_packages") {
"<th>{{ lang._('Current Version') }}</th><th>{{ lang._('New Version') }}</th>" +
"<th>{{ lang._('Required Action') }}</th></tr>");
$.each(data['all_packages'], function (index, row) {
$('#updatelist').append('<tr><td>'+row['name']+'</td>' +
"<td><strong>{{ lang._('NEW') }}</strong></td><td>"+row['version']+"</td></tr>");
} else if (type_name == "reinstall_packages") {
$('#updatelist').append('<tr><td>'+row['name']+'</td>' +
"<td>"+row['version']+"</td><td><strong>{{ lang._('REINSTALL') }}</strong></td></tr>");
} else {
$('#updatelist').append('<tr><td>'+row['name']+'</td>' +
'<td>'+row['current_version']+'</td><td>'+row['new_version']+'</td></tr>');
}
});
}
'<td>'+row['old']+'</td><td>'+row['new']+'</td><td>' +
row['reason'] + '</td></tr>');
});
}
......
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