Skip to content

Commit 5e8ebe9

Browse files
committed
make all the sorting in js; fixes mtierltd#131
1 parent 8af8bc2 commit 5e8ebe9

File tree

3 files changed

+19
-43
lines changed

3 files changed

+19
-43
lines changed

js/src/reports.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,19 +216,21 @@ var dtf = require("./dateformat.js");
216216
{title:"User", field:"userUid", widthGrow:1}, //column will be allocated 1/5 of the remaining space
217217
{title:"Project", field:"project", widthGrow:1}, //column will be allocated 1/5 of the remaining space
218218
{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){
219+
{title:"When", field:"time", widthGrow:1, formatter:function(cell, formatterParams, onRendered){
220220
var t = cell.getValue();
221221
switch(group3) {
222222
case 'day':
223223
return moment.unix(t).format(dtf.dformat());
224224
case 'month':
225-
return moment(t).format(dtf.mformat());
226-
case '':
227-
return moment.unix(t).format(dtf.dtformat());
225+
return moment.unix(t).format(dtf.mformat());
226+
case 'week':
227+
return moment.unix(t).format('YYYY[W]W');
228+
case 'year':
229+
return moment.unix(t).format('YYYY');
228230
default:
229-
return t;
231+
return moment.unix(t).format(dtf.dtformat());
230232
}
231-
}},
233+
}},
232234
{title:"Total Duration", field:"totalDuration",formatter:function(cell, formatterParams, onRendered){
233235
//cell - the cell component
234236
//formatterParams - parameters set for the column

js/src/timelines.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,17 +197,19 @@ var dtf = require("./dateformat.js");
197197
{title:"User", field:"userUid", widthGrow:1}, //column will be allocated 1/5 of the remaining space
198198
{title:"Project", field:"project", widthGrow:1}, //column will be allocated 1/5 of the remaining space
199199
{title:"Client", field:"client", widthGrow:1}, //column will be allocated 1/5 of the remaining space
200-
{title:"When", field:"time", widthGrow:1,formatter:function(cell, formatterParams, onRendered){
200+
{title:"When", field:"time", widthGrow:1, formatter:function(cell, formatterParams, onRendered){
201201
var t = cell.getValue();
202202
switch(group3) {
203203
case 'day':
204204
return moment.unix(t).format(dtf.dformat());
205205
case 'month':
206-
return moment(t).format(dtf.mformat());
207-
case '':
208-
return moment.unix(t).format(dtf.dtformat());
206+
return moment.unix(t).format(dtf.mformat());
207+
case 'week':
208+
return moment.unix(t).format('YYYY[W]W');
209+
case 'year':
210+
return moment.unix(t).format('YYYY');
209211
default:
210-
return t;
212+
return moment.unix(t).format(dtf.dtformat());
211213
}
212214
}},
213215
{title:"Total Duration", field:"totalDuration",formatter:function(cell, formatterParams, onRendered){

lib/Db/ReportItemMapper.php

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ public function report($user, $from, $to, $filterProjectId, $filterClientId, $fi
3737

3838
$selectFields = ['min(wi.id) as id', 'sum(duration) as "totalDuration"'];
3939

40-
$pg = 0;
4140
$aggregation = true;
4241
if(empty($groupOn1) && empty($groupOn2) && empty($timegroup)) {
4342
$selectFields[] = 'min(wi.details) as "details"';
@@ -60,37 +59,10 @@ public function report($user, $from, $to, $filterProjectId, $filterClientId, $fi
6059
} else {
6160
$selectFields[]= "min(start) as time";
6261
}
63-
} elseif ($timegroup == 'day') {
62+
} else {
6463
$selectFields[]= "start as time";
6564
}
6665

67-
if ($this->dbengine == 'POSTGRES') {
68-
$pg = 1;
69-
if ($timegroup == 'week') {
70-
$selectFields[]= "concat(date_part('year', to_timestamp(start)), 'W', to_char(to_timestamp(start), 'IW')) as time";
71-
}elseif ($timegroup == 'year') {
72-
$selectFields[]= "date_part('year', to_timestamp(start)) as time";
73-
}elseif ($timegroup == 'month') {
74-
$selectFields[]= "to_char(to_timestamp(start), 'YYYY-MM') as time";
75-
}
76-
} else if ($this->dbengine == 'SQLITE') {
77-
if ($timegroup == 'week') {
78-
$selectFields[]= "strftime('%YW%W', datetime(start, 'unixepoch')) as time";
79-
}elseif ($timegroup == 'year') {
80-
$selectFields[]= "strftime('%Y', datetime(start, 'unixepoch')) as time";
81-
}elseif ($timegroup == 'month') {
82-
$selectFields[]= "strftime('%Y-%m', datetime(start, 'unixepoch')) as time";
83-
}
84-
} else {
85-
if ($timegroup == 'week') {
86-
$selectFields[]= "CONCAT(YEAR(FROM_UNIXTIME(start)), 'W', WEEK(FROM_UNIXTIME(start))) as time";
87-
}elseif ($timegroup == 'year') {
88-
$selectFields[]= "YEAR(FROM_UNIXTIME(start)) as time";
89-
}elseif ($timegroup == 'month') {
90-
$selectFields[]= "DATE_FORMAT(FROM_UNIXTIME(start),'%Y-%m') as time";
91-
}
92-
93-
}
9466
if ($aggregation){
9567
if($groupOn1 != 'name'){
9668
if ($this->dbengine != 'MYSQL') {
@@ -213,7 +185,7 @@ public function report($user, $from, $to, $filterProjectId, $filterClientId, $fi
213185
if ($groupOn1 == 'name'){
214186
$groups[] = 'wi.name';
215187
} else {
216-
if($pg) { // postgres needs quotes on names
188+
if ($this->dbengine == 'POSTGRES') { // postgres needs quotes on names
217189
$groups[] = '"'.$groupOn1.'"';
218190
} else {
219191
$groups[] = $groupOn1;
@@ -225,8 +197,8 @@ public function report($user, $from, $to, $filterProjectId, $filterClientId, $fi
225197
if ($groupOn2 == 'name'){
226198
$groups[] = 'wi.name';
227199
} else {
228-
if($pg) {
229-
$groups[] = '"'.$groupOn2.'"';// postgres needs quotes on names
200+
if ($this->dbengine == 'POSTGRES') { // postgres needs quotes on names
201+
$groups[] = '"'.$groupOn2.'"';
230202
} else {
231203
$groups[] = $groupOn2;
232204
}

0 commit comments

Comments
 (0)