nci/static/js/app/components/terminal/terminal.js

54 lines
1.3 KiB
JavaScript
Raw Normal View History

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-06-14 15:24:03 +00:00
scrollOnData: true,
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-06-14 15:24:03 +00:00
ensureScrollPosition: function() {
if (this.scrollOnData) {
var codeNode = this.refs.code.getDOMNode();
this.ignoreScrollEvent = true;
codeNode.scrollTop = codeNode.scrollHeight - codeNode.offsetHeight;
}
},
onScroll: function() {
if (!this.ignoreScrollEvent) {
var codeNode = this.refs.code.getDOMNode();
if (codeNode.offsetHeight + codeNode.scrollTop >= codeNode.scrollHeight) {
this.scrollOnData = true;
} else {
this.scrollOnData = false;
}
}
this.ignoreScrollEvent = false;
},
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) {
this.setState({data: ansiUp.ansi_to_html(build.data)});
_.defer(this.ensureScrollPosition);
this.ensureScrollPosition();
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 {
data: ''
};
}
});
return Component;
});