Fix Logs view

This commit is contained in:
Kyrylo Gliebov 2018-10-09 18:55:01 +02:00
parent 2fe77ec1da
commit 0f37e525d7

View file

@ -233,14 +233,12 @@ class Logs extends React.Component {
this.journalctlPrepend = this.journalctlPrepend.bind(this); this.journalctlPrepend = this.journalctlPrepend.bind(this);
this.getLogs = this.getLogs.bind(this); this.getLogs = this.getLogs.bind(this);
this.loadLater = this.loadLater.bind(this); this.loadLater = this.loadLater.bind(this);
this.loadEarlier = this.loadEarlier.bind(this);
this.loadForTs = this.loadForTs.bind(this); this.loadForTs = this.loadForTs.bind(this);
this.journalCtl = null; this.journalCtl = null;
this.entries = []; this.entries = [];
this.start = null; this.start = null;
this.end = null; this.end = null;
this.earlier_than = null; this.earlier_than = null;
this.load_earlier = false;
this.state = { this.state = {
cursor: null, cursor: null,
after: null, after: null,
@ -263,19 +261,11 @@ class Logs extends React.Component {
} }
journalctlIngest(entryList) { journalctlIngest(entryList) {
if (this.load_earlier === true) { if (entryList.length > 0) {
entryList.push(...this.entries); this.entries.push(...entryList);
this.entries = entryList; const after = this.entries[this.entries.length - 1].__CURSOR;
this.setState({entries: this.entries}); this.setState({entries: this.entries, after: after});
this.load_earlier = false; this.scrollToBottom();
this.scrollToTop();
} else {
if (entryList.length > 0) {
this.entries.push(...entryList);
const after = this.entries[this.entries.length - 1].__CURSOR;
this.setState({entries: this.entries, after: after});
this.scrollToBottom();
}
} }
} }
@ -300,9 +290,7 @@ class Logs extends React.Component {
count: "all", count: "all",
}; };
if (this.load_earlier === true) { if (this.state.after != null) {
options["until"] = formatDateTime(this.earlier_than);
} else if (this.state.after != null) {
options["after"] = this.state.after; options["after"] = this.state.after;
delete options.since; delete options.since;
} }
@ -316,12 +304,6 @@ class Logs extends React.Component {
} }
} }
loadEarlier() {
this.load_earlier = true;
this.start = this.start - 3600;
this.getLogs();
}
loadLater() { loadLater() {
this.start = this.end; this.start = this.end;
this.end = this.end + 3600; this.end = this.end + 3600;
@ -368,13 +350,11 @@ class Logs extends React.Component {
<div className="panel panel-default"> <div className="panel panel-default">
<div className="panel-heading"> <div className="panel-heading">
<span>Logs</span> <span>Logs</span>
<button className="btn btn-default" style={{"float":"right"}} onClick={this.loadEarlier}>Load earlier entries</button> <button className="btn btn-default" style={{"float":"right"}} onClick={this.loadLater}>Load later entries</button>
</div> </div>
<LogsView entries={this.state.entries} start={this.props.recording.start} <LogsView entries={this.state.entries} start={this.props.recording.start}
end={this.props.recording.end} jumpToTs={this.props.jumpToTs} /> end={this.props.recording.end} jumpToTs={this.props.jumpToTs} />
<div className="panel-heading"> <div className="panel-heading" />
<button className="btn btn-default" onClick={this.loadLater}>Load later entries</button>
</div>
</div> </div>
); );
} }