Author: jruchaud Date: 2015-04-29 14:29:57 +0000 (Wed, 29 Apr 2015) New Revision: 1298 Url: http://forge.nuiton.org/projects/sandbox/repository/revisions/1298 Log: Continue export CSV and TXT Modified: wit/js/components/FilterLogs.js Modified: wit/js/components/FilterLogs.js =================================================================== --- wit/js/components/FilterLogs.js 2015-04-29 14:00:13 UTC (rev 1297) +++ wit/js/components/FilterLogs.js 2015-04-29 14:29:57 UTC (rev 1298) @@ -2,7 +2,7 @@ var FilterLogs = React.createClass({ - getCSV: function(sepRow, sepCol) { + getCSV: function() { var result = ""; var nodes = document.querySelectorAll("tr"); @@ -11,24 +11,72 @@ for (var c = 0, lc = row.length; c < lc; c++) { var col = row[c]; - result += col.textContent + (sepCol || ";"); + result += col.textContent + ";"; } - result += sepRow || "\n"; + result += "\n"; }; return result; }, - onCopy: function() { - var result = this.getCSV(); + getTXT: function() { + var result = ""; + + var dates = Object.keys(this.state.data); + for (var date of dates) { + result += date + "\n--------\n" + result += "\n" + this.getTXTRow(date, [], this.state.data[date]) + "\n"; + } + + return result; + }, + + getTXTRow: function(date, tags, tagObject) { + var r = ""; + + if (tagObject.duration) { + r += tagObject.duration + " - " + tags.join(', ') + "\n"; + } + + var keys = Object.keys(tagObject); + for (var k of keys) { + if (k != "diff" && k != "duration") { + r += this.getTXTRow(date, tags.concat(k), tagObject[k]); + } + } + + return r; + }, + + onClipboardCSV: function() { + var content = this.getCSV(); + this.clipboard(content); + }, + + onClipboardTXT: function() { + var content = this.getTXT(); + this.clipboard(content); + }, + + clipboard: function(content) { var gui = require('nw.gui'); var clipboard = gui.Clipboard.get(); - clipboard.set(result, 'text'); + clipboard.set(content, 'text'); }, - onMail: function() { - var result = this.getCSV("%0A", "%3B"); - var link = "mailto:?body=" + result; + onMailCSV: function(content) { + var content = this.getCSV(); + this.mail(content); + }, + + onMailTXT: function(content) { + var content = this.getTXT(); + this.mail(content); + }, + + mail: function(content) { + content = content.replace(/\n/g, "%0A").replace(/;/g, "%3B").replace(/-/g, "%2D"); + var link = "mailto:?body=" + content; window.location.href = link; }, @@ -98,17 +146,17 @@ <h1>Result</h1> <div ref="actions" className="btn-group" role="group"> - <button type="button" className="btn btn-primary" onClick={this.onCopy}> + <button type="button" className="btn btn-primary" onClick={this.onClipboardCSV}> CSV <span className="glyphicon glyphicon-copy" aria-hidden="true"></span> </button> - <button type="button" className="btn btn-primary" onClick={this.onCopy}> + <button type="button" className="btn btn-primary" onClick={this.onClipboardTXT}> TXT <span className="glyphicon glyphicon-copy" aria-hidden="true"></span> </button> - <button type="button" className="btn btn-primary" onClick={this.onMail}> + <button type="button" className="btn btn-primary" onClick={this.onMailCSV}> CSV <span className="glyphicon glyphicon-envelope" aria-hidden="true"></span> </button> - <button type="button" className="btn btn-primary" onClick={this.onMail}> + <button type="button" className="btn btn-primary" onClick={this.onMailTXT}> TXT <span className="glyphicon glyphicon-envelope" aria-hidden="true"></span> </button> </div>