[fix-image-history] Move byteToSize in app.tag and use it in image history. Better render for created_by

This commit is contained in:
Joxit
2018-12-14 21:57:42 +01:00
parent cb50dd42d8
commit ffd0a7c628
3 changed files with 20 additions and 12 deletions

View File

@@ -222,6 +222,17 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
oReq.setRequestHeader('Accept', 'application/vnd.docker.distribution.manifest.v2+json');
oReq.send();
};
registryUI.bytesToSize = function (bytes) {
var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
if (bytes == undefined || isNaN(bytes)) {
return '?';
} else if (bytes == 0) {
return '0 Byte';
}
var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
return Math.ceil(bytes / Math.pow(1024, i)) + ' ' + sizes[i];
};
route.start(true);
</script>
</app>

View File

@@ -15,19 +15,9 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<image-size>
<div title="Compressed size of your image.">{ this.bytesToSize(this.size) }</div>
<div title="Compressed size of your image.">{ registryUI.bytesToSize(this.size) }</div>
<script type="text/javascript">
var self = this;
this.bytesToSize = function (bytes) {
var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
if (bytes == undefined || isNaN(bytes)) {
return '?';
} else if (bytes == 0) {
return '0 Byte';
}
var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
return Math.ceil(bytes / Math.pow(1024, i)) + ' ' + sizes[i];
};
opts.image.on('size', function(size) {
self.size = size;
self.update();

View File

@@ -55,9 +55,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
default: return 10;
}
};
registryUI.taghistory.eltSort = function(e1, e2) {
return registryUI.taghistory.eltIdx(e1.key) - registryUI.taghistory.eltIdx(e2.key);
};
registryUI.taghistory.display = function() {
registryUI.taghistory.elements = []
let oReq = new Http();
@@ -68,6 +70,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
switch (attribute) {
case "created":
return new Date(value).toLocaleString();
case "created_by":
const cmd = value.match(/\/bin\/sh *-c *#\(nop\) *([A-Z]+)/);
return (cmd && cmd [1]) || 'RUN'
case 'size':
return registryUI.bytesToSize(value);
case "container_config":
case "config":
return "";
@@ -90,7 +97,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
registryUI.taghistory.elements.push(guiElements);
}
exec(blobs)
blobs.history.forEach(function(elt) { exec(elt) });
blobs.history.reverse().forEach(function(elt) { exec(elt) });
registryUI.taghistory.loadend = true;
registryUI.taghistory.instance.update();
});