2015-05-07 21:55:40 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
define([
|
2015-06-14 15:24:03 +00:00
|
|
|
'underscore',
|
2015-05-07 21:55:40 +00:00
|
|
|
'react',
|
|
|
|
'reflux',
|
2015-05-10 16:53:33 +00:00
|
|
|
'app/stores/terminal',
|
2015-06-14 15:24:03 +00:00
|
|
|
'ansi_up',
|
2015-05-10 16:53:33 +00:00
|
|
|
'templates/app/components/terminal/terminal'
|
2015-06-14 15:24:03 +00:00
|
|
|
], function(_, React, Reflux, terminalStore, ansiUp, template) {
|
2015-05-07 21:55:40 +00:00
|
|
|
var Component = React.createClass({
|
|
|
|
mixins: [Reflux.ListenerMixin],
|
2015-11-18 20:14:46 +00:00
|
|
|
shouldScrollBottom: true,
|
2015-06-14 15:24:03 +00:00
|
|
|
ignoreScrollEvent: false,
|
2015-05-07 21:55:40 +00:00
|
|
|
componentDidMount: function() {
|
2015-05-10 16:53:33 +00:00
|
|
|
this.listenTo(terminalStore, this.updateItems);
|
2015-05-07 21:55:40 +00:00
|
|
|
},
|
2015-11-18 20:14:46 +00:00
|
|
|
prepareOutput: function(output) {
|
|
|
|
return output.map(function(row) {
|
|
|
|
return ansiUp.ansi_to_html(row.text);
|
|
|
|
});
|
2015-06-14 15:24:03 +00:00
|
|
|
},
|
2015-11-18 20:14:46 +00:00
|
|
|
componentWillUpdate: function() {
|
|
|
|
var node = this.refs.code.getDOMNode();
|
|
|
|
this.shouldScrollBottom = node.scrollTop + node.offsetHeight >= node.scrollHeight;
|
2015-06-14 15:24:03 +00:00
|
|
|
},
|
2015-11-18 20:14:46 +00:00
|
|
|
componentDidUpdate: function() {
|
|
|
|
if (this.shouldScrollBottom) {
|
|
|
|
var node = this.refs.code.getDOMNode();
|
|
|
|
node.scrollTop = node.scrollHeight;
|
|
|
|
}
|
2015-07-08 20:37:31 +00:00
|
|
|
},
|
2015-06-14 15:24:03 +00:00
|
|
|
updateItems: function(build) {
|
2015-05-10 16:53:33 +00:00
|
|
|
// listen just our console update
|
2015-06-14 15:24:03 +00:00
|
|
|
if (build.buildId === this.props.build) {
|
2015-07-08 20:37:31 +00:00
|
|
|
this.setState({data: this.prepareOutput(build.data)});
|
2015-05-10 16:53:33 +00:00
|
|
|
}
|
2015-05-07 21:55:40 +00:00
|
|
|
},
|
2015-05-17 13:48:16 +00:00
|
|
|
render: template,
|
2015-05-07 21:55:40 +00:00
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
2015-11-18 20:14:46 +00:00
|
|
|
data: []
|
2015-05-07 21:55:40 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return Component;
|
|
|
|
});
|