From 300a8964839c19149a3b0f97a43e91f20b891448 Mon Sep 17 00:00:00 2001 From: Kyrylo Gliebov Date: Mon, 1 Oct 2018 17:42:22 +0200 Subject: [PATCH] Datetimepicker refactoring --- src/recordings.jsx | 89 +++++++++++++++++----------------------------- 1 file changed, 32 insertions(+), 57 deletions(-) diff --git a/src/recordings.jsx b/src/recordings.jsx index a7622ed..654758d 100644 --- a/src/recordings.jsx +++ b/src/recordings.jsx @@ -198,6 +198,8 @@ class Datetimepicker extends React.Component { } } +console.log(Datetimepicker); + function LogElement(props) { const entry = props.entry; const start = props.start; @@ -654,8 +656,6 @@ class View extends React.Component { super(props); this.onLocationChanged = this.onLocationChanged.bind(this); this.journalctlIngest = this.journalctlIngest.bind(this); - this.handleDateSinceChange = this.handleDateSinceChange.bind(this); - this.handleDateUntilChange = this.handleDateUntilChange.bind(this); this.handleInputChange = this.handleInputChange.bind(this); this.handleTsChange = this.handleTsChange.bind(this); this.handleLogTsChange = this.handleLogTsChange.bind(this); @@ -672,13 +672,12 @@ class View extends React.Component { recordingList: [], /* ID of the recording to display, or null for all */ recordingID: cockpit.location.path[0] || null, - dateSince: cockpit.location.options.dateSince || null, - dateSinceLastValid: null, - dateUntil: cockpit.location.options.dateUntil || null, - dateUntilLastValid: null, - /* value to filter recordings by username */ + /* filter values start */ + date_since: cockpit.location.options.date_since || "", + date_until: cockpit.location.options.date_until || "", username: cockpit.location.options.username || "", hostname: cockpit.location.options.hostname || "", + /* filter values end */ error_tlog_uid: false, diff_hosts: false, curTs: null, @@ -700,10 +699,10 @@ class View extends React.Component { onLocationChanged() { this.setState({ recordingID: cockpit.location.path[0] || null, - dateSince: cockpit.location.options.dateSince || null, - dateUntil: cockpit.location.options.dateUntil || null, - username: cockpit.location.options.username || null, - hostname: cockpit.location.options.hostname || null, + date_since: cockpit.location.options.date_since || "", + date_until: cockpit.location.options.date_until || "", + username: cockpit.location.options.username || "", + hostname: cockpit.location.options.hostname || "", }); } @@ -739,7 +738,7 @@ class View extends React.Component { /* If no recording found */ if (r === undefined) { /* Create new recording */ - if (hostname != e["_HOSTNAME"]) { + if (hostname !== e["_HOSTNAME"]) { this.setState({diff_hosts: true}); } @@ -797,22 +796,21 @@ class View extends React.Component { */ journalctlStart() { let matches = ["_UID=" + this.uid]; - if (this.state.username) { + if (this.state.username && this.state.username !== "") { matches.push("TLOG_USER=" + this.state.username); } - if (this.state.hostname && this.state.hostname != null && - this.state.hostname != "") { + if (this.state.hostname && this.state.hostname !== "") { matches.push("_HOSTNAME=" + this.state.hostname); } let options = {follow: true, count: "all"}; - if (this.state.dateSinceLastValid) { - options['since'] = this.state.dateSinceLastValid; + if (this.state.date_since && this.state.date_since !== "") { + options['since'] = this.state.date_since; } - if (this.state.dateUntil) { - options['until'] = this.state.dateUntilLastValid; + if (this.state.date_until && this.state.date_until !== "") { + options['until'] = this.state.date_until; } if (this.state.recordingID !== null) { @@ -861,16 +859,6 @@ class View extends React.Component { this.setState({recordingList: []}); } - handleDateSinceChange(date, last_valid) { - this.setState({dateSinceLastValid: last_valid}); - cockpit.location.go([], $.extend(cockpit.location.options, { dateSince: date })); - } - - handleDateUntilChange(date, last_valid) { - this.setState({dateUntilLastValid: last_valid}); - cockpit.location.go([], $.extend(cockpit.location.options, { dateUntil: date })); - } - handleInputChange(event) { const name = event.target.name; const value = event.target.value; @@ -901,18 +889,6 @@ class View extends React.Component { this.setState({error_tlog_uid: true}); }); - let dateSince = parseDate(this.state.dateSince); - - if (dateSince && dateSince != true) { - this.setState({dateSinceLastValid: dateSince}); - } - - let dateUntil = parseDate(this.state.dateUntil); - - if (dateUntil && dateUntil != true) { - this.setState({dateUntilLastValid: dateUntil}); - } - cockpit.addEventListener("locationchanged", this.onLocationChanged); } @@ -929,16 +905,16 @@ class View extends React.Component { * and recording ID has changed */ if (this.journalctlRecordingID !== null && - this.state.recordingID != prevState.recordingID) { + this.state.recordingID !== prevState.recordingID) { if (this.journalctlIsRunning()) { this.journalctlStop(); } this.journalctlStart(); } - if (this.state.dateSinceLastValid != prevState.dateSinceLastValid || - this.state.dateUntilLastValid != prevState.dateUntilLastValid || - this.state.username != prevState.username || - this.state.hostname != prevState.hostname + if (this.state.date_since !== prevState.date_since || + this.state.date_until !== prevState.date_until || + this.state.username !== prevState.username || + this.state.hostname !== prevState.hostname ) { this.clearRecordings(); this.journalctlRestart(); @@ -961,18 +937,16 @@ class View extends React.Component { - + - + - + - + @@ -1004,11 +978,12 @@ class View extends React.Component { + date_since={this.state.date_since} + date_until={this.state.date_until} + username={this.state.username} + hostname={this.state.hostname} + list={this.state.recordingList} + diff_hosts={this.state.diff_hosts} /> ); } else {