Skip to content

Commit 1e4d8dd

Browse files
committed
replace deprecated downloadDataFormatter with downloadAccessors
fixes mtierltd#140
1 parent fdfccc2 commit 1e4d8dd

File tree

2 files changed

+37
-41
lines changed

2 files changed

+37
-41
lines changed

js/src/reports.js

Lines changed: 36 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -174,49 +174,47 @@ var dtf = require("./dateformat.js");
174174
n = n + '';
175175
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
176176
}
177+
var endedAccessor = function(value, data, type, params, column){
178+
if (group1 != '' || group2 != '' || group3 != ''){
179+
return '*';
180+
}
181+
return moment(data.time, dtf.dtformat()).add(moment.duration(data.totalDuration)).format(dtf.dtformat());
182+
}
183+
var totalDurationAccessor = function(value, data, type, params, column){
184+
var s = Math.floor( (data.totalDuration) % 60 );
185+
var m = Math.floor( (data.totalDuration/60) % 60 );
186+
var h = Math.floor( (data.totalDuration/(60*60)));
187+
return pad(h,2) + ':' + pad(m,2) + ':' + pad(s,2);
188+
}
189+
var whenAccessor = function(value, data, type, params, column){
190+
switch(group3) {
191+
case 'day':
192+
return moment.unix(value).format(dtf.dformat());
193+
case 'month':
194+
return moment.unix(value).format(dtf.mformat());
195+
case 'week':
196+
return moment.unix(value).format('YYYY[W]W');
197+
case 'year':
198+
return moment.unix(value).format('YYYY');
199+
default:
200+
return moment.unix(value).format(dtf.dtformat());
201+
}
202+
}
203+
var nullCheckAccessor = function(value, data, type, params, column){
204+
return value ? value : '';
205+
}
177206
var table = new Tabulator("#report", {
178207
ajaxURL:baseUrl,
179208
layout:"fitColumns",
180-
downloadDataFormatter:function(data){
181-
//data - active table data array
182-
data.forEach(function(row){
183-
184-
var time = row.time;
185-
var duration = row.totalDuration;
186-
if (group1 != '' || group2 != '' || group3 != ''){
187-
row.ended = '*';
188-
} else {
189-
var ended = moment(time, dtf.dtformat()).add(duration,"seconds").format(dtf.dtformat());
190-
row.ended = ended;
191-
192-
}
193-
194-
var s = Math.floor( (duration) % 60 );
195-
var m = Math.floor( (duration/60) % 60 );
196-
var h = Math.floor( (duration/(60*60)));
197-
198-
row.totalDuration = pad(h,2) + ':' + pad(m,2) + ':' + pad(s,2);
199-
200-
if (row.project == null){
201-
row.project = '';
202-
}
203-
if (row.client == null){
204-
row.client = '';
205-
}
206-
207-
});
208-
209-
return data;
210-
},
211209
columns:[
212210
//{title:"Id", field:"id", width:100}, //column has a fixed width of 100px;
213-
{title:"#", field:"", formatter:"rownum"},
211+
{title:"#", field:"id", formatter:"rownum"},
214212
{title:"Name", field:"name", widthGrow:1}, //column will be allocated 1/5 of the remaining space
215213
{title:"Details", field:"details", widthGrow:1}, //column will be allocated 1/5 of the remaining space
216214
{title:"User", field:"userUid", widthGrow:1}, //column will be allocated 1/5 of the remaining space
217-
{title:"Project", field:"project", widthGrow:1}, //column will be allocated 1/5 of the remaining space
218-
{title:"Client", field:"client", widthGrow:1}, //column will be allocated 1/5 of the remaining space
219-
{title:"When", field:"time", widthGrow:1, formatter:function(cell, formatterParams, onRendered){
215+
{title:"Project", field:"project",accessorDownload:nullCheckAccessor, widthGrow:1}, //column will be allocated 1/5 of the remaining space
216+
{title:"Client", field:"client",accessorDownload:nullCheckAccessor, widthGrow:1}, //column will be allocated 1/5 of the remaining space
217+
{title:"When", field:"time", widthGrow:1,accessorDownload:whenAccessor,formatter:function(cell, formatterParams, onRendered){
220218
var t = cell.getValue();
221219
switch(group3) {
222220
case 'day':
@@ -231,15 +229,14 @@ var dtf = require("./dateformat.js");
231229
return moment.unix(t).format(dtf.dtformat());
232230
}
233231
}},
234-
{title:"Total Duration", field:"totalDuration",formatter:function(cell, formatterParams, onRendered){
232+
{title:"Total Duration", field:"totalDuration",accessorDownload:totalDurationAccessor,formatter:function(cell, formatterParams, onRendered){
235233
//cell - the cell component
236234
//formatterParams - parameters set for the column
237235
//onRendered - function to call when the formatter has been rendered
238236
var duration = cell.getValue();
239237
var s = Math.floor( (duration) % 60 );
240238
var m = Math.floor( (duration/60) % 60 );
241239
var h = Math.floor( (duration/(60*60)));
242-
243240
return pad(h,2) + ':' + pad(m,2) + ':' + pad(s,2);
244241

245242
},bottomCalc:"sum", bottomCalcParams:{
@@ -256,7 +253,7 @@ var dtf = require("./dateformat.js");
256253
return pad(h,2) + ':' + pad(m,2) + ':' + pad(s,2);
257254

258255
}}, //column will be allocated 1/5 of the remaining space
259-
{title:"Ended", field:"ended",visible:false, formatter:function(cell, formatterParams, onRendered){
256+
{title:"Ended", field:"ended",visible:false,accessorDownload:endedAccessor,formatter:function(cell, formatterParams, onRendered){
260257
//cell - the cell component
261258
//formatterParams - parameters set for the column
262259
//onRendered - function to call when the formatter has been rendered
@@ -265,8 +262,7 @@ var dtf = require("./dateformat.js");
265262
}
266263
var time = cell.getRow().getData().time;
267264
var duration = cell.getRow().getData().totalDuration;
268-
var ended = moment(time, dtf.dtformat()).add(duration,"seconds").format(dtf.dtformat());
269-
return ended;
265+
return moment.unix(parseInt(time) + parseInt(duration)).format(dtf.dtformat());
270266

271267
}},
272268
],

templates/content/reports.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
<select id="group2" style="width: 200px;">
4343
<option value="">None</option>
4444
<option value="name">Time Entry</option>
45-
<option value="userUid" selected >User</option>
45+
<option value="userUid" selected>User</option>
4646
<option value="project">Project</option>
4747
</select>
4848
</label>

0 commit comments

Comments
 (0)