Skip to content

Commit 23d53f9

Browse files
author
mtierltd
committed
use intervals for the timer display instead of days in the past
fixes mtierltd#98
1 parent 0631e44 commit 23d53f9

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

js/src/timer.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ function() {
3535
timePicker: false,
3636
startDate: start,
3737
endDate: end,
38-
showCustomRangeLabel: false,
3938
ranges: {
4039
'Today': [moment().startOf('day'), moment().endOf('day')],
4140
'Last 7 Days': [moment().startOf('day').subtract(6, 'days'), moment().endOf('day')],
@@ -53,7 +52,8 @@ function() {
5352
}
5453
},cb);
5554
$("#report-range").on('apply.daterangepicker', function(ev, picker) {
56-
days = Math.round((picker.endDate.unix()-picker.startDate.unix()) / 86400);
55+
start = picker.startDate;
56+
end = picker.endDate;
5757
getWorkItems();
5858
});
5959
cb(start, end);
@@ -243,7 +243,7 @@ function() {
243243
return formattedTime;
244244
}
245245
function getWorkItems() {
246-
var baseUrl = OC.generateUrl('/apps/timetracker/ajax/work-intervals?days='+days);
246+
var baseUrl = OC.generateUrl('/apps/timetracker/ajax/work-intervals?from='+start.unix()+'&to='+end.unix());
247247
$.ajaxSetup({
248248
scriptCharset: "utf-8",
249249
//contentType: "application/json; charset=utf-8"

lib/Controller/AjaxController.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,9 @@ public function __construct($AppName, IRequest $request, IUserSession $userSessi
7878
* @NoAdminRequired
7979
*/
8080
public function workIntervals() {
81-
$ndays = 30;
82-
if (isset($this->request->days)){
83-
$ndays = $this->request->days;
84-
}
85-
86-
$l = $this->workIntervalMapper->findLatestDays($this->userId, $ndays, 0);
81+
$from = $this->request->from;
82+
$to = $this->request->to;
83+
$l = $this->workIntervalMapper->findLatestInterval($this->userId, $from, $to);
8784
$days = [];
8885
foreach ($l as $wi){
8986
//$dt = date("d/m/Y", $wi->start);

lib/Db/WorkIntervalMapper.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,27 @@ public function findLatestByName($user, $name){
6060
}
6161
}
6262

63+
public function findLatestInterval($user, $from, $to, $limit = 5000, $offset = 0){
64+
$filters[] = "(user_uid = ?)";
65+
$params[] = $user;
66+
67+
if (!empty($from)){
68+
$filters[] = "(start > ?)";
69+
$params[] = $from;
70+
71+
}
72+
if (!empty($to)){
73+
$filters[] = "(start < ?)";
74+
$params[] = $to;
75+
76+
}
77+
78+
if ($this->dbengine == 'MYSQL'){
79+
$sql = 'SELECT * FROM `*PREFIX*timetracker_work_interval` where '.implode(" and ",$filters).' order by start desc';
80+
return $this->findEntities($sql, $params, $limit, $offset);
81+
}
82+
}
83+
6384
public function findLatestDays($user, $limitDays = 10, $startDay = 0, $limit = 5000, $offset = 0){
6485
if ($this->dbengine == 'MYSQL'){
6586
$sql = 'SELECT * FROM `*PREFIX*timetracker_work_interval` where user_uid = ? and
@@ -74,7 +95,6 @@ public function findLatestDays($user, $limitDays = 10, $startDay = 0, $limit = 5
7495
order by start desc';
7596
return $this->findEntities($sql, [$user],$limit, $offset);
7697
}
77-
7898
}
7999

80100
public function findAllRunning($user, $limit = 100, $offset = 0){

0 commit comments

Comments
 (0)