Author: smaisonneuve Date: 2015-04-29 16:48:57 +0000 (Wed, 29 Apr 2015) New Revision: 1303 Url: http://forge.nuiton.org/projects/sandbox/repository/revisions/1303 Log: [Wit] - Rapport : add timeline Modified: wit/js/components/FilterBar.js wit/js/components/Timeline.js wit/js/pages/Rapport.js Modified: wit/js/components/FilterBar.js =================================================================== --- wit/js/components/FilterBar.js 2015-04-29 15:16:24 UTC (rev 1302) +++ wit/js/components/FilterBar.js 2015-04-29 16:48:57 UTC (rev 1303) @@ -20,10 +20,10 @@ var moment = require('moment'); var db = require("./js/services/database.js"); - var beginDate = moment(React.findDOMNode(this.refs.beginDate).value); - var endDate = moment(React.findDOMNode(this.refs.endDate).value); + this.startDate = moment(React.findDOMNode(this.refs.beginDate).value); + this.endDate = moment(React.findDOMNode(this.refs.endDate).value); - return db.searchLogs(null, beginDate, endDate, true); + return db.searchLogs(null, this.startDate, this.endDate, true); }, onSearch: function() { @@ -31,7 +31,7 @@ this.search() .then(function(result) { - self.props.onSearchResult(result); + self.props.onSearchResult(result, self.startDate, self.endDate); // console.log(result); }); }, Modified: wit/js/components/Timeline.js =================================================================== --- wit/js/components/Timeline.js 2015-04-29 15:16:24 UTC (rev 1302) +++ wit/js/components/Timeline.js 2015-04-29 16:48:57 UTC (rev 1303) @@ -14,11 +14,23 @@ }, componentDidMount: function () { - var self = this; // Retrieve window focus activity - user.getSessions(this.startDate, this.endDate, true) + this.refresh(this.startDate, this.endDate); + }, + + componentWillReceiveProps: function(nextProps) { + this.refresh(nextProps.data.startDate, nextProps.data.endDate); + }, + + refresh: function (startDate, endDate) { + this.startDate = startDate; + this.endDate = endDate; + + var self = this; + + user.getSessions(startDate, endDate, true) .then(function (sessions) { self.setState({ sessions: sessions @@ -34,7 +46,7 @@ // Create a wrapper for each window session var self = this, - timeRange = this.endDate.diff(this.startDate); + timeRange = this.endDate && this.endDate.diff(this.startDate); items = items.concat( sessions.map(function(session) { Modified: wit/js/pages/Rapport.js =================================================================== --- wit/js/pages/Rapport.js 2015-04-29 15:16:24 UTC (rev 1302) +++ wit/js/pages/Rapport.js 2015-04-29 16:48:57 UTC (rev 1303) @@ -1,13 +1,22 @@ /** @jsx React.DOM */ +var moment = require("moment"); var Rapport = React.createClass({ getInitialState : function() { - return {result: []}; + return { + startDate: moment().subtract(1, "h"), + endDate: moment(), + result: [] + }; }, - handleSearchResult: function(result) { - this.setState({result: result}); + handleSearchResult: function(result, startDate, endDate) { + this.setState({ + startDate: startDate, + endDate: endDate, + result: result + }); }, render: function() { @@ -15,6 +24,7 @@ <div> <FilterBar onSearchResult={this.handleSearchResult}/> <FilterLogs data={this.state.result}/> + <Timeline data={this.state}/> </div> ); }