Skip to content

Commit 65db2de

Browse files
committed
add support for changing the timeline in the Timer main view
closes #51
1 parent 22556a9 commit 65db2de

File tree

4 files changed

+48
-6
lines changed

4 files changed

+48
-6
lines changed

js/timer.js

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,39 @@
44

55

66
$( function() {
7+
var days='31';
8+
var start = moment().subtract(29, 'days');
9+
var end = moment();
10+
11+
function cb(start, end) {
12+
$('#report-range span').html(start.format('DD/MM/YY') + ' - ' + end.format('DD/MM/YY'));
13+
}
14+
$("#report-range").daterangepicker({
15+
timePicker: false,
16+
startDate: start,
17+
endDate: end,
18+
ranges: {
19+
'Today': [moment(), moment()],
20+
'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
21+
'Last 7 Days': [moment().subtract(6, 'days'), moment()],
22+
'Last 30 Days': [moment().subtract(29, 'days'), moment()],
23+
'Last 90 Days': [moment().subtract(89, 'days'), moment()],
24+
'Last 365 Days': [moment().subtract(364, 'days'), moment()],
25+
'This Month': [moment().startOf('month'), moment().endOf('month')],
26+
'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')],
27+
'The Month Before Last': [moment().subtract(2, 'month').startOf('month'), moment().subtract(2, 'month').endOf('month')],
28+
'This Year': [moment().startOf('year'), moment().endOf('year')],
29+
'Last Year': [moment().subtract(1, 'year').startOf('year'), moment().subtract(1, 'year').endOf('year')],
30+
},
31+
locale: {
32+
format: 'DD/MM/YY'
33+
}
34+
},cb);
35+
$("#report-range").on('apply.daterangepicker', function(ev, picker) {
36+
days = (picker.endDate.unix()-picker.startDate.unix()) / 86400;
37+
getWorkItems();
38+
});
39+
cb(start, end);
740

841
var entityMap = {
942
'&': '&',
@@ -180,7 +213,7 @@
180213
return formattedTime;
181214
}
182215
function getWorkItems(){
183-
var baseUrl = OC.generateUrl('/apps/timetracker/ajax/work-intervals');
216+
var baseUrl = OC.generateUrl('/apps/timetracker/ajax/work-intervals?days='+days);
184217
$.ajaxSetup({
185218
scriptCharset: "utf-8",
186219
//contentType: "application/json; charset=utf-8"
@@ -527,4 +560,4 @@
527560
});
528561
} );
529562

530-
}());
563+
}());

lib/Controller/AjaxController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ public function __construct($AppName, IRequest $request, IUserSession $userSessi
7373
*
7474
* @NoAdminRequired
7575
*/
76-
public function workIntervals() {
76+
public function workIntervals($days) {
7777
$i = 0;
78-
$tryIntervals=[90,180,365,365*5];
78+
$tryIntervals=[$days,90,180,365,365*5];
7979
do {
8080
$l = $this->workIntervalMapper->findLatestDays($this->userId,$tryIntervals[$i],0);
8181
$i++;

lib/Db/WorkIntervalMapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,4 @@ public function deleteAllForProject($project_id) {
105105

106106
}
107107

108-
}
108+
}

templates/content/index.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,16 @@
5656
</div>
5757
5858
<div class="clearfix"> </div>
59+
<br/>
60+
<div class="time-controls">
61+
<div id="report-range" style="background: #fff; cursor: pointer; padding: 5px 10px; border: 1px solid #ccc; width: 100%">
62+
<i class="fa fa-calendar"></i>&nbsp;
63+
<span></span> <i class="fa fa-caret-down"></i>
64+
</div>
65+
</div>
66+
<br/>
67+
5968
<div class="clearfix"> </div>
6069
<div id="work-intervals">
6170
</div>
62-
</div>
71+
</div>

0 commit comments

Comments
 (0)