Fix v1 progress

This commit is contained in:
Jeffrey Morgan
2015-04-20 12:07:52 -04:00
parent e7b2cabf5c
commit f97deb9f7c
2 changed files with 22 additions and 16 deletions

View File

@@ -82,7 +82,8 @@ var ContainerHome = React.createClass({
</div>
);
} else if (this.props.container && this.props.container.State.Downloading) {
if (this.state.progress) {
if (this.state.progress !== undefined) {
console.log(this.state.progress);
body = (
<div className="details-progress">
<h2>Downloading Image</h2>

View File

@@ -32,7 +32,7 @@ var ContainerStore = assign(Object.create(EventEmitter.prototype), {
return image.Id.slice(0, 12);
}));
var layersToDownload = layerSizes.filter(function (layerSize) {
return !existingIds.has(layerSize.Id);
return !existingIds.has(layerSize.Id) && !isNaN(layerSize.size);
});
var totalBytes = layersToDownload.map(function (s) { return s.size; }).reduce(function (pv, sv) { return pv + sv; }, 0);
@@ -54,7 +54,6 @@ var ContainerStore = assign(Object.create(EventEmitter.prototype), {
stream.on('data', str => {
var data = JSON.parse(str);
console.log(data);
if (data.error) {
_error = data.error;
@@ -72,20 +71,26 @@ var ContainerStore = assign(Object.create(EventEmitter.prototype), {
} else if (data.status === 'Downloading') {
var current = data.progressDetail.current;
var total = data.progressDetail.total;
var layerFraction = current / total;
layerProgress[data.id] = layerFraction;
if (total <= 0) {
layerProgress[data.id] = 0;
} else {
layerProgress[data.id] = current / total;
}
var chunks = layersToDownload.map(function (s) {
var progress = layerProgress[s.Id] || 0;
return progress * s.size;
});
var totalReceived = chunks.reduce(function (pv, sv) {
return pv + sv;
}, 0);
console.log(totalReceived, totalBytes);
var totalProgress = totalReceived / totalBytes;
progressCallback(totalProgress);
}
var chunks = layersToDownload.map(function (s) {
return layerProgress[s.Id] * s.size;
});
var totalReceived = chunks.reduce(function (pv, sv) {
return pv + sv;
}, 0);
var totalProgress = totalReceived / totalBytes;
progressCallback(totalProgress);
});
stream.on('end', function () {
callback(_error);