mirror of
https://gitlab.silvrtree.co.uk/martind2000/nci.git
synced 2025-01-11 05:55:07 +00:00
separate new lines on server
This commit is contained in:
parent
46e9b64f59
commit
5c527b75fc
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
scm:
|
scm:
|
||||||
type: git
|
type: git
|
||||||
repository: ./
|
repository: ../../nci
|
||||||
rev: master
|
rev: master
|
||||||
|
|
||||||
# catchRev:
|
# catchRev:
|
||||||
|
@ -61,11 +61,7 @@ exports.init = function(app, callback) {
|
|||||||
}, this.slot());
|
}, this.slot());
|
||||||
},
|
},
|
||||||
function(err, lines) {
|
function(err, lines) {
|
||||||
var fullText = _(lines).reduce(function(memo, line) {
|
client.emit('sync', 'data', {lines: lines});
|
||||||
return memo + line.text;
|
|
||||||
}, '')
|
|
||||||
|
|
||||||
client.emit('sync', 'data', {text: fullText});
|
|
||||||
this.pass(true);
|
this.pass(true);
|
||||||
},
|
},
|
||||||
function(err) {
|
function(err) {
|
||||||
@ -107,23 +103,59 @@ exports.init = function(app, callback) {
|
|||||||
buildsResource.clientEmitSync('cancel', {buildId: build.id});
|
buildsResource.clientEmitSync('cancel', {buildId: build.id});
|
||||||
});
|
});
|
||||||
|
|
||||||
var buildLogLineNumbersHash = {};
|
var buildLogLineNumbersHash = {},
|
||||||
|
lastLinesHash = {};
|
||||||
|
|
||||||
distributor.on('buildData', function(build, data) {
|
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(
|
app.dataio.resource('build' + build.id).clientEmitSync(
|
||||||
'data',
|
'data',
|
||||||
{text: data}
|
{lines: lines}
|
||||||
);
|
);
|
||||||
|
|
||||||
// write build logs to db
|
// write build logs to db
|
||||||
db.logLines.put({
|
db.logLines.put(lines, function(err) {
|
||||||
text: data,
|
|
||||||
number: logLineNumber,
|
|
||||||
buildId: build.id
|
|
||||||
}, function(err) {
|
|
||||||
if (err) {
|
if (err) {
|
||||||
logger.error(
|
logger.error(
|
||||||
'Error during write log line "' + logLineNumber +
|
'Error during write log line "' + logLineNumber +
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
.terminal(ref="code")
|
.terminal
|
||||||
pre.terminal_code
|
pre.terminal_code
|
||||||
.terminal_footer(style={height: '30px'})
|
.terminal_footer(style={height: '30px'})
|
||||||
|
@ -22,15 +22,20 @@ define([
|
|||||||
|
|
||||||
var Component = React.createClass({
|
var Component = React.createClass({
|
||||||
mixins: [Reflux.ListenerMixin],
|
mixins: [Reflux.ListenerMixin],
|
||||||
|
|
||||||
shouldScrollBottom: true,
|
shouldScrollBottom: true,
|
||||||
ignoreScrollEvent: false,
|
data: [],
|
||||||
linesCount: 0,
|
linesCount: 0,
|
||||||
|
|
||||||
componentDidMount: function() {
|
componentDidMount: function() {
|
||||||
this.listenTo(terminalStore, this.updateItems);
|
this.listenTo(terminalStore, this.updateItems);
|
||||||
var node = this.refs.code.getDOMNode();
|
var node = document.getElementsByClassName('terminal')[0];
|
||||||
this.initialScrollPosition = node.getBoundingClientRect().top;
|
this.initialScrollPosition = node.getBoundingClientRect().top;
|
||||||
|
|
||||||
$(window).scroll(this.onScroll);
|
$(window).on('scroll', this.onScroll);
|
||||||
|
},
|
||||||
|
componentWillUnmount: function() {
|
||||||
|
$(window).off('scroll', this.onScroll);
|
||||||
},
|
},
|
||||||
prepareRow: function(row) {
|
prepareRow: function(row) {
|
||||||
return ansiUp.ansi_to_html(row.replace('\r', ''));
|
return ansiUp.ansi_to_html(row.replace('\r', ''));
|
||||||
@ -42,14 +47,14 @@ define([
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
onScroll: function() {
|
onScroll: function() {
|
||||||
var node = this.refs.code.getDOMNode(),
|
var node = document.getElementsByClassName('terminal')[0],
|
||||||
body = document.getElementsByTagName('body')[0];
|
body = document.getElementsByTagName('body')[0];
|
||||||
this.shouldScrollBottom = window.innerHeight + body.scrollTop >=
|
this.shouldScrollBottom = window.innerHeight + body.scrollTop >=
|
||||||
node.offsetHeight + this.initialScrollPosition;
|
node.offsetHeight + this.initialScrollPosition;
|
||||||
},
|
},
|
||||||
ensureScrollPosition: function() {
|
ensureScrollPosition: function() {
|
||||||
if (this.shouldScrollBottom) {
|
if (this.shouldScrollBottom) {
|
||||||
var node = this.refs.code.getDOMNode(),
|
var node = document.getElementsByClassName('terminal')[0],
|
||||||
body = document.getElementsByTagName('body')[0];
|
body = document.getElementsByTagName('body')[0];
|
||||||
body.scrollTop = this.initialScrollPosition + node.offsetHeight;
|
body.scrollTop = this.initialScrollPosition + node.offsetHeight;
|
||||||
}
|
}
|
||||||
@ -84,7 +89,6 @@ define([
|
|||||||
this.linesCount = currentLinesCount;
|
this.linesCount = currentLinesCount;
|
||||||
this.ensureScrollPosition();
|
this.ensureScrollPosition();
|
||||||
}, 100),
|
}, 100),
|
||||||
data: [],
|
|
||||||
updateItems: function(build) {
|
updateItems: function(build) {
|
||||||
// listen just our console update
|
// listen just our console update
|
||||||
if (build.buildId === this.props.build) {
|
if (build.buildId === this.props.build) {
|
||||||
|
@ -14,30 +14,6 @@ define([
|
|||||||
this.connectedResourcesHash = {};
|
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) {
|
onReadTerminalOutput: function(build) {
|
||||||
var self = this,
|
var self = this,
|
||||||
output = [],
|
output = [],
|
||||||
@ -53,10 +29,15 @@ define([
|
|||||||
}
|
}
|
||||||
|
|
||||||
connect.resource(resourceName).subscribe('data', function(data) {
|
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({
|
self.trigger({
|
||||||
buildId: build.id,
|
buildId: build.id,
|
||||||
name: 'Console for build #' + 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