Skip to content

Commit 38e55de

Browse files
committed
added manual entry for work intervals
1 parent 9c050fc commit 38e55de

File tree

6 files changed

+169
-3
lines changed

6 files changed

+169
-3
lines changed

appinfo/info.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<name>Time Tracker</name>
66
<summary>Time Tracker App</summary>
77
<description><![CDATA[Time Tracker App]]></description>
8-
<version>0.0.26</version>
8+
<version>0.0.27</version>
99
<licence>agpl</licence>
1010
<author mail="[email protected]" >MTier Ltd.</author>
1111
<namespace>TimeTracker</namespace>

appinfo/routes.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
['name' => 'ajax#index', 'url' => '/ajax/', 'verb' => 'GET'],
2525
['name' => 'ajax#work_intervals', 'url' => '/ajax/work-intervals', 'verb' => 'GET'],
2626
['name' => 'ajax#update_work_interval', 'url' => '/ajax/update-work-interval/{id}', 'verb' => 'POST'],
27+
['name' => 'ajax#add_work_interval', 'url' => '/ajax/add-work-interval/{name}', 'verb' => 'POST'],
2728
['name' => 'ajax#delete_work_interval', 'url' => '/ajax/delete-work-interval/{id}', 'verb' => 'POST'],
2829

2930
['name' => 'ajax#get_clients', 'url' => '/ajax/clients', 'verb' => 'GET'],

css/style.css

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,4 +382,13 @@ td.ε_row {
382382
}
383383
#clients {
384384
margin-top: 30px;
385-
}
385+
}
386+
#manual-entry-button {
387+
float:right;
388+
}
389+
390+
391+
#form-manual-entry label {display: block;}
392+
#hours-manual-entry{
393+
width: 240px;
394+
}

js/timer.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,63 @@
2424
form[ 0 ].reset();
2525
}
2626
});
27+
var picker = $("#hours-manual-entry").daterangepicker({
28+
timePicker: true,
29+
//startDate:tsToDate($(this).data('start-date')),
30+
//endDate:tsToDate($(this).data('end-date')),
31+
timePicker24Hour: true,
32+
locale: {
33+
format: 'DD/MM/YY hh:mm:ss'
34+
}
35+
});
36+
function validateManualEntryFields(){
37+
if($('#name-manual-entry').val() == ''){
38+
$("#confirm-button").button("option", "disabled", true);
39+
} else {
40+
$("#confirm-button").button("option", "disabled", false);
41+
}
42+
}
43+
$('#name-manual-entry').on('input',function() {
44+
45+
validateManualEntryFields();
46+
});
47+
48+
$("#dialog-manual-entry").dialog({
49+
autoOpen: false,
50+
buttons :
51+
[ {
52+
id: 'confirm-button',
53+
text: "Confirm",
54+
click: function() {
55+
var baseUrl = OC.generateUrl('/apps/timetracker/ajax/add-work-interval/'+$('#name-manual-entry').val());
56+
57+
var jqxhr = $.post( baseUrl,{start:picker.data('daterangepicker').startDate.format('DD/MM/YY HH:mm'), end:picker.data('daterangepicker').endDate.format('DD/MM/YY HH:mm'), tzoffset: new Date().getTimezoneOffset()} ,function() {
58+
getWorkItems();
59+
$("#dialog-manual-entry").dialog("close");
60+
})
61+
.done(function() {
62+
63+
})
64+
.fail(function() {
65+
alert( "error" );
66+
})
67+
},
68+
},
69+
{
70+
id: 'cancel-button',
71+
text: "Cancel",
72+
click: function() {
73+
$(this).dialog("close");
74+
},
75+
},]
76+
});
77+
78+
$('#manual-entry-button').click(function(e) {
79+
$("#dialog-manual-entry").dialog("open");
80+
return false;
81+
});
82+
validateManualEntryFields();
83+
2784
function editWorkIntem(dialogWorkItemEditForm){
2885
target = dialogWorkItemEditForm.target;
2986
form = dialogWorkItemEditForm.find( "form" );

lib/Controller/AjaxController.php

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function __construct($AppName, IRequest $request, IUserSession $userSessi
6565
*/
6666
public function workIntervals() {
6767
$i = 0;
68-
$tryIntervals=[7,14,31,365,365*5];
68+
$tryIntervals=[90,180,365,365*5];
6969
do {
7070
$l = $this->workIntervalMapper->findLatestDays($this->userId,$tryIntervals[$i],0);
7171
$i++;
@@ -279,6 +279,87 @@ public function updateWorkInterval($id) {
279279
}
280280

281281

282+
/**
283+
*
284+
* @NoAdminRequired
285+
*/
286+
287+
public function addWorkInterval() {
288+
289+
$wi = new WorkInterval();
290+
$wi->setUserUid($this->userId);
291+
$wi->setRunning(0);
292+
293+
if (isset($this->request->name)) {
294+
$wi->setName($this->request->name);
295+
}
296+
if (isset($this->request->projectId)) {
297+
$wi->setProjectId($this->request->projectId);
298+
if ($wi->projectId != null){
299+
$project = $this->projectMapper->find($wi->projectId);
300+
$locked = $project->locked;
301+
if($locked){
302+
$allowedTags = $this->tagMapper->findAllAlowedForProject($project->id);
303+
$allowedTagsIds = array_map(function($tag) { return $tag->id;}, $allowedTags);
304+
$currentTags = $this->workIntervalToTagMapper->findAllForWorkInterval($id);
305+
$currentTagsIds = array_map(function($witag) { return $witag->tagId;}, $currentTags);
306+
$newTags = array_intersect($allowedTagsIds,$currentTagsIds);
307+
308+
$this->workIntervalToTagMapper->deleteAllForWorkInterval($id);
309+
foreach($newTags as $tag){
310+
if (empty($tag))
311+
continue;
312+
$newWiToTag = new WorkIntervalToTag();
313+
$newWiToTag->setWorkIntervalId($id);
314+
$newWiToTag->setTagId($tag);
315+
$newWiToTag->setCreatedAt(time());
316+
$this->workIntervalToTagMapper->insert($newWiToTag);
317+
318+
}
319+
320+
}
321+
322+
}
323+
}
324+
if (isset($this->request->tagId)) {
325+
$tags = \explode(",", $this->request->tagId);
326+
$this->workIntervalToTagMapper->deleteAllForWorkInterval($id);
327+
$project = null;
328+
$locked = 0;
329+
330+
331+
foreach($tags as $tag){
332+
if (empty($tag))
333+
continue;
334+
$newWiToTag = new WorkIntervalToTag();
335+
$newWiToTag->setWorkIntervalId($id);
336+
$newWiToTag->setTagId($tag);
337+
$newWiToTag->setCreatedAt(time());
338+
//var_dump($newWiToTag);
339+
$this->workIntervalToTagMapper->insert($newWiToTag);
340+
341+
}
342+
}
343+
if (isset($this->request->start)) {
344+
$tzoffset = 0;
345+
if (isset($this->request->tzoffset)) {
346+
$tzoffset = $this->request->tzoffset;
347+
}
348+
349+
date_default_timezone_set('UTC');
350+
$dt = \DateTime::createFromFormat ( "d/m/y H:i",$this->request->start);
351+
$dt->setTimeZone(new \DateTimeZone('UTC'));
352+
$wi->setStart($dt->getTimestamp()+$tzoffset*60);
353+
$de = \DateTime::createFromFormat ( "d/m/y H:i",$this->request->end);
354+
$de->setTimeZone(new \DateTimeZone('UTC'));
355+
$wi->setDuration($de->getTimestamp() - $dt->getTimestamp());
356+
}
357+
358+
$this->workIntervalMapper->insert($wi);
359+
360+
return new JSONResponse(["WorkIntervals" => json_decode(json_encode($running), true)]);
361+
}
362+
282363

283364
/**
284365
*

templates/content/index.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
</div>
1616
1717
</div>
18+
<div class="ui-button ui-widget ui-corner-all" id="manual-entry-button">Manual entry</div>
1819
<div id="dialog-confirm" title="Confirmation Required" class='hidden'>
1920
Are you sure you want to delete this work item?
2021
</div>
@@ -31,6 +32,23 @@
3132
</fieldset>
3233
</form>
3334
</div>
35+
36+
<div id="dialog-manual-entry" title="Edit work item" class='hidden'>
37+
<p class="validateTips">All form fields are required.</p>
38+
39+
<form id='form-manual-entry'>
40+
<fieldset>
41+
<label for="name">Name</label>
42+
<input type="text" name="name" id="name-manual-entry" value="" class="text ui-widget-content ui-corner-all">
43+
<!-- <div id='hours-manual-entry'>&nbsp;</div> -->
44+
<label for="hours">Interval</label>
45+
<input type="text" name="hours" id="hours-manual-entry" value="" class="text ui-widget-content ui-corner-all">
46+
<!-- Allow form submission with keyboard without duplicating the dialog button -->
47+
<input type="submit" tabindex="-1" style="position:absolute; top:-1000px">
48+
</fieldset>
49+
</form>
50+
</div>
51+
3452
<div class="clearfix"> </div>
3553
<div class="clearfix"> </div>
3654
<div id="work-intervals">

0 commit comments

Comments
 (0)