nci/static/js/app/components/common/progress/index.js
2015-07-26 16:05:54 +03:00

32 lines
721 B
JavaScript

'use strict';
define([
'underscore',
'react',
'templates/app/components/common/progress/index'
], function(_, React, template) {
return React.createClass({
render: template,
_computePercent: function() {
var build = this.props.build;
return Math.round((Date.now() - build.startDate) /
build.project.avgBuildDuration * 100);
},
componentDidMount: function() {
var self = this,
updateCallback = function() {
if (self.props.build.status === 'in-progress') {
self.setState({percent: self._computePercent()});
_.delay(updateCallback, 100);
}
}
updateCallback();
},
getInitialState: function() {
return {
percent: this._computePercent()
}
}
});
});