mirror of https://github.com/portainer/portainer
fix(general): fix the size display using the filesize library (#246)
* fix(general): fix the size display using the filesize library * refactor(humansize): use default value for filterpull/248/head
parent
59e65222eb
commit
739a5ec299
|
@ -53,7 +53,7 @@
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Total memory</td>
|
<td>Total memory</td>
|
||||||
<td>{{ infoData.MemTotal|humansize }}</td>
|
<td>{{ infoData.MemTotal|humansize: 2 }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
|
@ -87,7 +87,7 @@ function (Settings, $scope, Messages, $timeout, Container, ContainerTop, $stateP
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
scaleLabel: function (valueObj) {
|
scaleLabel: function (valueObj) {
|
||||||
return humansizeFilter(parseInt(valueObj.value, 10));
|
return humansizeFilter(parseInt(valueObj.value, 10), 2);
|
||||||
},
|
},
|
||||||
responsive: true
|
responsive: true
|
||||||
//scaleOverride: true,
|
//scaleOverride: true,
|
||||||
|
@ -100,7 +100,7 @@ function (Settings, $scope, Messages, $timeout, Container, ContainerTop, $stateP
|
||||||
datasets: [networkRxDataset, networkTxDataset]
|
datasets: [networkRxDataset, networkTxDataset]
|
||||||
}, {
|
}, {
|
||||||
scaleLabel: function (valueObj) {
|
scaleLabel: function (valueObj) {
|
||||||
return humansizeFilter(parseInt(valueObj.value, 10));
|
return humansizeFilter(parseInt(valueObj.value, 10), 2);
|
||||||
},
|
},
|
||||||
responsive: true
|
responsive: true
|
||||||
});
|
});
|
||||||
|
|
|
@ -42,8 +42,8 @@
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Total memory</td>
|
<td>Total memory</td>
|
||||||
<td ng-if="!swarm_mode">{{ info.MemTotal|humansize }}</td>
|
<td ng-if="!swarm_mode">{{ info.MemTotal|humansize: 2 }}</td>
|
||||||
<td ng-if="swarm_mode">{{ totalMemory|humansize }}</td>
|
<td ng-if="swarm_mode">{{ totalMemory|humansize: 2 }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr ng-if="!swarm_mode">
|
<tr ng-if="!swarm_mode">
|
||||||
<td>Operating system</td>
|
<td>Operating system</td>
|
||||||
|
|
|
@ -123,15 +123,13 @@ angular.module('portainer.filters', [])
|
||||||
})
|
})
|
||||||
.filter('humansize', function () {
|
.filter('humansize', function () {
|
||||||
'use strict';
|
'use strict';
|
||||||
return function (bytes) {
|
return function (bytes, round) {
|
||||||
var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
|
if (!round) {
|
||||||
if (bytes === 0) {
|
round = 1;
|
||||||
return 'n/a';
|
}
|
||||||
|
if (bytes || bytes === 0) {
|
||||||
|
return filesize(bytes, {base: 10, round: round});
|
||||||
}
|
}
|
||||||
var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)), 10);
|
|
||||||
var value = bytes / Math.pow(1024, i);
|
|
||||||
var decimalPlaces = (i < 1) ? 0 : (i - 1);
|
|
||||||
return value.toFixed(decimalPlaces) + ' ' + sizes[[i]];
|
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
.filter('containername', function () {
|
.filter('containername', function () {
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
"angular-ui-select": "~0.17.1",
|
"angular-ui-select": "~0.17.1",
|
||||||
"bootstrap": "~3.3.6",
|
"bootstrap": "~3.3.6",
|
||||||
"font-awesome": "~4.6.3",
|
"font-awesome": "~4.6.3",
|
||||||
|
"filesize": "~3.3.0",
|
||||||
"Hover": "2.0.2",
|
"Hover": "2.0.2",
|
||||||
"jquery": "1.11.1",
|
"jquery": "1.11.1",
|
||||||
"jquery.gritter": "1.7.4",
|
"jquery.gritter": "1.7.4",
|
||||||
|
|
|
@ -71,6 +71,7 @@ module.exports = function (grunt) {
|
||||||
'bower_components/bootstrap/dist/js/bootstrap.min.js',
|
'bower_components/bootstrap/dist/js/bootstrap.min.js',
|
||||||
'bower_components/Chart.js/Chart.min.js',
|
'bower_components/Chart.js/Chart.min.js',
|
||||||
'bower_components/lodash/dist/lodash.min.js',
|
'bower_components/lodash/dist/lodash.min.js',
|
||||||
|
'bower_components/filesize/lib/filesize.min.js',
|
||||||
'bower_components/moment/min/moment.min.js',
|
'bower_components/moment/min/moment.min.js',
|
||||||
'bower_components/xterm.js/src/xterm.js',
|
'bower_components/xterm.js/src/xterm.js',
|
||||||
'assets/js/jquery.gritter.js', // Using custom version to fix error in minified build due to "use strict"
|
'assets/js/jquery.gritter.js', // Using custom version to fix error in minified build due to "use strict"
|
||||||
|
|
|
@ -82,32 +82,6 @@ describe('filters', function () {
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('humansize', function () {
|
|
||||||
it('should return n/a when size is zero', inject(function (humansizeFilter) {
|
|
||||||
expect(humansizeFilter(0)).toBe('n/a');
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should handle Bytes values', inject(function (humansizeFilter) {
|
|
||||||
expect(humansizeFilter(512)).toBe('512 Bytes');
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should handle KB values', inject(function (humansizeFilter) {
|
|
||||||
expect(humansizeFilter(5 * 1024)).toBe('5 KB');
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should handle MB values', inject(function (humansizeFilter) {
|
|
||||||
expect(humansizeFilter(5 * 1024 * 1024)).toBe('5.0 MB');
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should handle GB values', inject(function (humansizeFilter) {
|
|
||||||
expect(humansizeFilter(5 * 1024 * 1024 * 1024)).toBe('5.00 GB');
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should handle TB values', inject(function (humansizeFilter) {
|
|
||||||
expect(humansizeFilter(5 * 1024 * 1024 * 1024 * 1024)).toBe('5.000 TB');
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('containername', function () {
|
describe('containername', function () {
|
||||||
it('should strip the leading slash from container name', inject(function (containernameFilter) {
|
it('should strip the leading slash from container name', inject(function (containernameFilter) {
|
||||||
var container = {
|
var container = {
|
||||||
|
|
Loading…
Reference in New Issue