mirror of
https://gitlab.silvrtree.co.uk/martind2000/nci.git
synced 2025-01-10 23:45:07 +00:00
separate new lines on server
This commit is contained in:
parent
46e9b64f59
commit
5c527b75fc
@ -1,7 +1,7 @@
|
||||
|
||||
scm:
|
||||
type: git
|
||||
repository: ./
|
||||
repository: ../../nci
|
||||
rev: master
|
||||
|
||||
# catchRev:
|
||||
|
@ -61,11 +61,7 @@ exports.init = function(app, callback) {
|
||||
}, this.slot());
|
||||
},
|
||||
function(err, lines) {
|
||||
var fullText = _(lines).reduce(function(memo, line) {
|
||||
return memo + line.text;
|
||||
}, '')
|
||||
|
||||
client.emit('sync', 'data', {text: fullText});
|
||||
client.emit('sync', 'data', {lines: lines});
|
||||
this.pass(true);
|
||||
},
|
||||
function(err) {
|
||||
@ -107,23 +103,59 @@ exports.init = function(app, callback) {
|
||||
buildsResource.clientEmitSync('cancel', {buildId: build.id});
|
||||
});
|
||||
|
||||
var buildLogLineNumbersHash = {};
|
||||
var buildLogLineNumbersHash = {},
|
||||
lastLinesHash = {};
|
||||
|
||||
distributor.on('buildData', function(build, data) {
|
||||
var logLineNumber = buildLogLineNumbersHash[build.id] || 0;
|
||||
var cleanupText = function(text) {
|
||||
return text.replace('\r', '');
|
||||
};
|
||||
|
||||
buildLogLineNumbersHash[build.id] = ++logLineNumber
|
||||
var splittedData = data.split('\n'),
|
||||
logLineNumber = buildLogLineNumbersHash[build.id] || 0;
|
||||
|
||||
lastLinesHash[build.id] = lastLinesHash[build.id] || '';
|
||||
|
||||
// if we don't have last line, so we start new line
|
||||
if (!lastLinesHash[build.id]) {
|
||||
logLineNumber++;
|
||||
}
|
||||
lastLinesHash[build.id] += _(splittedData).first();
|
||||
|
||||
var lines = [{
|
||||
text: cleanupText(lastLinesHash[build.id]),
|
||||
buildId: build.id,
|
||||
number: logLineNumber
|
||||
}];
|
||||
|
||||
if (splittedData.length > 1) {
|
||||
// if we have last '' we have to take all except last
|
||||
// this shown that string ends with eol
|
||||
if (_(splittedData).last() === '') {
|
||||
lastLinesHash[build.id] = '';
|
||||
splittedData = _(splittedData.slice(1)).initial();
|
||||
} else {
|
||||
lastLinesHash[build.id] = _(splittedData).last();
|
||||
splittedData = _(splittedData).tail();
|
||||
}
|
||||
|
||||
lines = lines.concat(_(splittedData).map(function(line) {
|
||||
return {
|
||||
text: cleanupText(line),
|
||||
buildId: build.id,
|
||||
number: ++logLineNumber
|
||||
};
|
||||
}));
|
||||
}
|
||||
|
||||
buildLogLineNumbersHash[build.id] = logLineNumber;
|
||||
app.dataio.resource('build' + build.id).clientEmitSync(
|
||||
'data',
|
||||
{text: data}
|
||||
{lines: lines}
|
||||
);
|
||||
|
||||
// write build logs to db
|
||||
db.logLines.put({
|
||||
text: data,
|
||||
number: logLineNumber,
|
||||
buildId: build.id
|
||||
}, function(err) {
|
||||
db.logLines.put(lines, function(err) {
|
||||
if (err) {
|
||||
logger.error(
|
||||
'Error during write log line "' + logLineNumber +
|
||||
|
@ -1,3 +1,3 @@
|
||||
.terminal(ref="code")
|
||||
.terminal
|
||||
pre.terminal_code
|
||||
.terminal_footer(style={height: '30px'})
|
||||
|
@ -22,15 +22,20 @@ define([
|
||||
|
||||
var Component = React.createClass({
|
||||
mixins: [Reflux.ListenerMixin],
|
||||
|
||||
shouldScrollBottom: true,
|
||||
ignoreScrollEvent: false,
|
||||
data: [],
|
||||
linesCount: 0,
|
||||
|
||||
componentDidMount: function() {
|
||||
this.listenTo(terminalStore, this.updateItems);
|
||||
var node = this.refs.code.getDOMNode();
|
||||
var node = document.getElementsByClassName('terminal')[0];
|
||||
this.initialScrollPosition = node.getBoundingClientRect().top;
|
||||
|
||||
$(window).scroll(this.onScroll);
|
||||
$(window).on('scroll', this.onScroll);
|
||||
},
|
||||
componentWillUnmount: function() {
|
||||
$(window).off('scroll', this.onScroll);
|
||||
},
|
||||
prepareRow: function(row) {
|
||||
return ansiUp.ansi_to_html(row.replace('\r', ''));
|
||||
@ -42,14 +47,14 @@ define([
|
||||
});
|
||||
},
|
||||
onScroll: function() {
|
||||
var node = this.refs.code.getDOMNode(),
|
||||
var node = document.getElementsByClassName('terminal')[0],
|
||||
body = document.getElementsByTagName('body')[0];
|
||||
this.shouldScrollBottom = window.innerHeight + body.scrollTop >=
|
||||
node.offsetHeight + this.initialScrollPosition;
|
||||
},
|
||||
ensureScrollPosition: function() {
|
||||
if (this.shouldScrollBottom) {
|
||||
var node = this.refs.code.getDOMNode(),
|
||||
var node = document.getElementsByClassName('terminal')[0],
|
||||
body = document.getElementsByTagName('body')[0];
|
||||
body.scrollTop = this.initialScrollPosition + node.offsetHeight;
|
||||
}
|
||||
@ -84,7 +89,6 @@ define([
|
||||
this.linesCount = currentLinesCount;
|
||||
this.ensureScrollPosition();
|
||||
}, 100),
|
||||
data: [],
|
||||
updateItems: function(build) {
|
||||
// listen just our console update
|
||||
if (build.buildId === this.props.build) {
|
||||
|
@ -14,30 +14,6 @@ define([
|
||||
this.connectedResourcesHash = {};
|
||||
},
|
||||
|
||||
transformData: function(data) {
|
||||
var splittedData = data.text.split('\n');
|
||||
|
||||
if (this.currentLine) {
|
||||
this.lines.pop();
|
||||
}
|
||||
|
||||
this.currentLine += _(splittedData).first();
|
||||
this.lines.push(this.currentLine);
|
||||
|
||||
if (splittedData.length > 1) {
|
||||
if (_(splittedData).last() === '') {
|
||||
this.currentLine = '';
|
||||
splittedData = _(splittedData.slice(1)).initial();
|
||||
} else {
|
||||
this.currentLine = _(splittedData).last();
|
||||
splittedData = _(splittedData).tail();
|
||||
}
|
||||
this.lines = this.lines.concat(splittedData);
|
||||
}
|
||||
|
||||
return this.lines;
|
||||
},
|
||||
|
||||
onReadTerminalOutput: function(build) {
|
||||
var self = this,
|
||||
output = [],
|
||||
@ -53,10 +29,15 @@ define([
|
||||
}
|
||||
|
||||
connect.resource(resourceName).subscribe('data', function(data) {
|
||||
var lastLine = _(self.lines).last();
|
||||
if (lastLine && (_(data.lines).first().number === lastLine.number)) {
|
||||
self.lines = _(self.lines).initial();
|
||||
}
|
||||
self.lines = self.lines.concat(data.lines);
|
||||
self.trigger({
|
||||
buildId: build.id,
|
||||
name: 'Console for build #' + build.id,
|
||||
data: self.transformData(data)
|
||||
data: _(self.lines).pluck('text')
|
||||
});
|
||||
});
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user