r1295 - wit/js/components
Author: jruchaud Date: 2015-04-29 12:41:19 +0000 (Wed, 29 Apr 2015) New Revision: 1295 Url: http://forge.nuiton.org/projects/sandbox/repository/revisions/1295 Log: Prepare export Modified: wit/js/components/FilterBar.js wit/js/components/FilterLogs.js Modified: wit/js/components/FilterBar.js =================================================================== --- wit/js/components/FilterBar.js 2015-04-29 12:16:59 UTC (rev 1294) +++ wit/js/components/FilterBar.js 2015-04-29 12:41:19 UTC (rev 1295) @@ -16,15 +16,20 @@ React.findDOMNode(this.refs.endDate).value = endDefaultDate; }, - onSearch: function() { - var self = this; + search: function() { var moment = require('moment'); var db = require("./js/services/database.js"); var beginDate = moment(React.findDOMNode(this.refs.beginDate).value).toDate(); var endDate = moment(React.findDOMNode(this.refs.endDate).value).toDate(); - db.searchLogs(null, beginDate) + return db.searchLogs(null, beginDate); + }, + + onSearch: function() { + var self = this; + + this.search() .then(function(result) { self.props.onSearchResult(result); // console.log(result); Modified: wit/js/components/FilterLogs.js =================================================================== --- wit/js/components/FilterLogs.js 2015-04-29 12:16:59 UTC (rev 1294) +++ wit/js/components/FilterLogs.js 2015-04-29 12:41:19 UTC (rev 1295) @@ -2,6 +2,36 @@ var FilterLogs = React.createClass({ + getCSV: function(sepRow, sepCol) { + var result = ""; + + var nodes = document.querySelectorAll("tr"); + for (var r = 0, lr = nodes.length; r < lr; r++) { + var row = nodes[r].children; + + for (var c = 0, lc = row.length; c < lc; c++) { + var col = row[c]; + result += col.textContent + (sepCol || ";"); + } + result += sepRow || "\n"; + }; + + return result; + }, + + onCopy: function() { + var result = this.getCSV(); + var gui = require('nw.gui'); + var clipboard = gui.Clipboard.get(); + clipboard.set(result, 'text'); + }, + + onMail: function() { + var result = this.getCSV("%0A", "%3B"); + var link = "mailto:?body=" + result; + window.location.href = link; + }, + render: function() { var moment = require('moment'); @@ -18,19 +48,32 @@ ); }); +// if (!this.props.data || !this.props.data.length) { +// return null; +// } + return ( - <table className="table"> - <thead> - <tr> - <th>Date</th> - <th>Duration</th> - <th>Tags</th> - </tr> - </thead> - <tbody> - {items} - </tbody> - </table> + <div> + <h1>Result</h1> + + <div ref="actions" className="btn-group" role="group"> + <button onClick={this.onCopy} className="btn btn-primary">Copy</button> + <button onClick={this.onMail} className="btn btn-primary">Mail</button> + </div> + + <table className="table"> + <thead> + <tr> + <th>Date</th> + <th>Duration</th> + <th>Tags</th> + </tr> + </thead> + <tbody> + {items} + </tbody> + </table> + </div> ); } });
participants (1)
-
jruchaud@users.nuiton.org