Skip to content

Commit a5ca66e

Browse files
committed
fix for #52
1 parent 93762fc commit a5ca66e

File tree

1 file changed

+59
-11
lines changed

1 file changed

+59
-11
lines changed

js/reports.js

Lines changed: 59 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,37 @@
166166
var table = new Tabulator("#report", {
167167
ajaxURL:baseUrl,
168168
layout:"fitColumns",
169+
downloadDataFormatter:function(data){
170+
//data - active table data array
171+
data.forEach(function(row){
172+
173+
var time = row.time;
174+
var duration = row.totalDuration;
175+
if (group1 != '' || group2 != '' || group3 != ''){
176+
row.ended = '*';
177+
} else {
178+
var ended = moment(time, 'YYYY-MM-DD hh:mm:ss').add(duration,"seconds").format('YYYY-MM-DD HH:mm');
179+
row.ended = ended;
180+
181+
}
182+
183+
var s = Math.floor( (duration) % 60 );
184+
var m = Math.floor( (duration/60) % 60 );
185+
var h = Math.floor( (duration/(60*60)));
186+
187+
row.totalDuration = pad(h,2) + ':' + pad(m,2) + ':' + pad(s,2);
188+
189+
if (row.project == null){
190+
row.project = '';
191+
}
192+
if (row.client == null){
193+
row.client = '';
194+
}
195+
196+
});
197+
198+
return data;
199+
},
169200
columns:[
170201
//{title:"Id", field:"id", width:100}, //column has a fixed width of 100px;
171202
{title:"#", field:"", formatter:"rownum"},
@@ -187,31 +218,48 @@
187218
return pad(h,2) + ':' + pad(m,2) + ':' + pad(s,2);
188219

189220
},bottomCalc:"sum", bottomCalcParams:{
190-
precision:1,
191-
},bottomCalcFormatter:function(cell, formatterParams, onRendered){
192-
//cell - the cell component
193-
//formatterParams - parameters set for the column
194-
//onRendered - function to call when the formatter has been rendered
195-
var duration = cell.getValue();
196-
var s = Math.floor( (duration) % 60 );
197-
var m = Math.floor( (duration/60) % 60 );
198-
var h = Math.floor( (duration/(60*60)));
221+
precision:1,
222+
},bottomCalcFormatter:function(cell, formatterParams, onRendered){
223+
//cell - the cell component
224+
//formatterParams - parameters set for the column
225+
//onRendered - function to call when the formatter has been rendered
226+
var duration = cell.getValue();
227+
var s = Math.floor( (duration) % 60 );
228+
var m = Math.floor( (duration/60) % 60 );
229+
var h = Math.floor( (duration/(60*60)));
199230

200-
return pad(h,2) + ':' + pad(m,2) + ':' + pad(s,2);
231+
return pad(h,2) + ':' + pad(m,2) + ':' + pad(s,2);
201232

202-
}}, //column will be allocated 1/5 of the remaining space
233+
}}, //column will be allocated 1/5 of the remaining space
234+
{title:"Ended", field:"ended",visible:false, formatter:function(cell, formatterParams, onRendered){
235+
//cell - the cell component
236+
//formatterParams - parameters set for the column
237+
//onRendered - function to call when the formatter has been rendered
238+
if (group1 != '' || group2 != '' || group3 != ''){
239+
return '*';
240+
}
241+
var time = cell.getRow().getData().time;
242+
var duration = cell.getRow().getData().totalDuration;
243+
var ended = moment(time, 'YYYY-MM-DD hh:mm:ss').add(duration,"seconds").format('YYYY-MM-DD HH:mm');
244+
return ended;
245+
246+
}},
203247
],
204248
ajaxResponse:function(url, params, response){
205249

206250
return response.items; //return the tableData property of a response json object
207251
},
208252
});
209253
$("#download-csv").off().click(function(){
254+
table.showColumn("ended");
210255
table.download("csv", "data.csv");
256+
table.hideColumn("ended");
211257
return false;
212258
});
213259
$("#download-json").off().click(function(){
260+
table.showColumn("ended");
214261
table.download("json", "data.json");
262+
table.hideColumn("ended");
215263
return false;
216264
});
217265
}

0 commit comments

Comments
 (0)