2014-11-13 15:14:41 +01:00
|
|
|
var React = require('react');
|
2015-02-04 18:47:37 +01:00
|
|
|
var moment = require('moment');
|
2014-11-13 15:14:41 +01:00
|
|
|
|
2015-01-26 16:54:50 +01:00
|
|
|
var DIFF_PREFIXES = {
|
|
|
|
A: ' ',
|
|
|
|
E: ' ',
|
|
|
|
D: '-',
|
|
|
|
N: '+'
|
|
|
|
}
|
|
|
|
|
|
|
|
var SPADEN_CLASS = {
|
|
|
|
A: 'blue', // array edited
|
|
|
|
E: 'blue', // edited
|
|
|
|
D: 'negative', // deleted
|
|
|
|
N: 'positive', // added
|
|
|
|
}
|
|
|
|
|
2014-11-14 07:29:55 +01:00
|
|
|
var LogEntry = React.createClass({
|
2014-11-13 15:14:41 +01:00
|
|
|
propTypes: {
|
|
|
|
event: React.PropTypes.object.isRequired
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
2015-02-04 18:47:37 +01:00
|
|
|
var date = moment(this.props.event.createdAt);
|
2015-01-26 16:54:50 +01:00
|
|
|
|
2014-11-13 15:14:41 +01:00
|
|
|
return (
|
|
|
|
<tr>
|
2015-01-26 16:54:50 +01:00
|
|
|
<td>
|
2015-02-04 18:47:37 +01:00
|
|
|
{date.format('ll')}<br />
|
|
|
|
{date.format('HH:mm')}
|
2015-01-26 16:54:50 +01:00
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
<strong>{this.props.event.data.name}</strong><em>[{this.props.event.type}]</em>
|
|
|
|
</td>
|
|
|
|
<td style={{maxWidth: 300}}>
|
|
|
|
{this.renderEventDiff()}
|
|
|
|
</td>
|
|
|
|
<td>{this.props.event.createdBy}</td>
|
2014-11-13 15:14:41 +01:00
|
|
|
</tr>
|
|
|
|
);
|
2015-01-26 16:54:50 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
renderFullEventData: function() {
|
|
|
|
var localEventData = JSON.parse(JSON.stringify(this.props.event.data));
|
|
|
|
delete localEventData.description;
|
|
|
|
delete localEventData.name;
|
|
|
|
|
|
|
|
var prettyPrinted = JSON.stringify(localEventData, null, 2);
|
|
|
|
|
|
|
|
return (<code className='JSON smalltext man'>{prettyPrinted}</code>)
|
|
|
|
},
|
|
|
|
|
|
|
|
renderEventDiff: function() {
|
|
|
|
if (!this.props.showFullEvents && this.props.event.diffs) {
|
|
|
|
var changes = this.props.event.diffs.map(this.buildDiff);
|
|
|
|
return (<code className='smalltext man'>{changes.length === 0 ? '(no changes)' : changes}</code>)
|
|
|
|
} else {
|
|
|
|
return this.renderFullEventData();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
buildDiff: function(diff, idx) {
|
|
|
|
var change;
|
|
|
|
var key = diff.path.join('.');
|
|
|
|
|
|
|
|
if (diff.lhs !== undefined && diff.rhs !== undefined) {
|
|
|
|
change = (
|
|
|
|
<div>
|
|
|
|
<div className={SPADEN_CLASS.D}>- {key}: {JSON.stringify(diff.lhs)}</div>
|
|
|
|
<div className={SPADEN_CLASS.N}>+ {key}: {JSON.stringify(diff.rhs)}</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
var spadenClass = SPADEN_CLASS[diff.kind]
|
|
|
|
var prefix = DIFF_PREFIXES[diff.kind];
|
|
|
|
|
|
|
|
change = (<div className={spadenClass}>{prefix} {key}: {JSON.stringify(diff.rhs)}</div>)
|
|
|
|
}
|
|
|
|
|
|
|
|
return (<div key={idx}>{change}</div>)
|
2014-11-13 15:14:41 +01:00
|
|
|
}
|
2015-01-26 16:54:50 +01:00
|
|
|
|
2014-11-13 15:14:41 +01:00
|
|
|
});
|
|
|
|
|
2014-11-14 07:29:55 +01:00
|
|
|
module.exports = LogEntry;
|