Skip to content

Commit 9160e27

Browse files
committed
1 parent a5ca66e commit 9160e27

File tree

2 files changed

+39
-8
lines changed

2 files changed

+39
-8
lines changed

js/timer.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@
260260
((child.running == 1)?'':tsToHour(child.start+child.duration))+
261261
"</div>"+
262262
"<div class='wi-child-duration'>"+((child.running == 1)?'running...':secondsToTimer(child.duration))+"</div>"+
263-
"<div class='wi-play-space'><span class='fas clickable fa-play wi-play' id="+child.id+" data-work-name='"+child.name+"'></span><div>"+"</div></li></div>");
263+
"<div class='wi-play-space'><span class='fas clickable fa-play wi-play' id="+child.id+" data-work-name='"+child.name+"' data-projectid="+child.projectId+" data-tagids='"+child.tags.map(function(tag) {return tag.id}).join(',')+"' ></span><div>"+"</div></li></div>");
264264
});
265265

266266

@@ -324,7 +324,7 @@
324324
$('.wi-play').click(function(e) {
325325
e.preventDefault();
326326
$('#work-input').val($(this).data('work-name'));
327-
startTimer();
327+
startTimer($(this).data('projectid'), $(this).data('tagids'));
328328
return false;
329329
})
330330
$('.wi-trash').click(function(e) {
@@ -497,7 +497,7 @@
497497
});
498498
}
499499

500-
function startTimer(){
500+
function startTimer(projectId = null, tags = ""){
501501
if(localStorage.getItem('isTimerStarted') === 'true'){
502502
stopTimer();
503503
}
@@ -506,7 +506,7 @@
506506
if (workName == ''){
507507
workName = 'no description';
508508
}
509-
var jqxhr = $.post( "ajax/start-timer/"+workName, function() {
509+
var jqxhr = $.post( "ajax/start-timer/"+workName, { projectId: projectId, tags: tags}, function() {
510510
localStorage.setItem('isTimerStarted', true);
511511
$('#start-tracking > span').addClass("stop-button").removeClass("play-button");
512512
getWorkItems();

lib/Controller/AjaxController.php

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,16 @@ public function index() {
146146

147147
public function startTimer($name) {
148148
//$this->endTimer();
149+
$projectId = null;
150+
if (isset($this->request->projectId) && (!empty($this->request->projectId))){
151+
$projectId = $this->request->projectId;
152+
}
153+
154+
$tags = null;
155+
if (isset($this->request->tags) && (!empty($this->request->tags))){
156+
$tags = $this->request->tags;
157+
}
158+
149159
if (strlen($name) > 255){
150160
return new JSONResponse(["Error" => "Name too long"]);
151161
}
@@ -154,15 +164,22 @@ public function startTimer($name) {
154164
$winterval->setRunning(1);
155165
$winterval->setName($name);
156166
$winterval->setUserUid($this->userId);
167+
168+
// first get tags and project ids from the last work item with the same name
157169
$lwinterval = $this->workIntervalMapper->findLatestByName($this->userId, $name);
158-
if ($lwinterval != null){
170+
if ($projectId == null && $lwinterval != null){
159171

160172
$winterval->setProjectId($lwinterval->projectId);
161173
}
174+
175+
if($projectId != null){
176+
$winterval->setProjectId($projectId);
177+
}
178+
162179
$this->workIntervalMapper->insert($winterval);
163-
if ($lwinterval != null){
164-
$tags = $this->workIntervalToTagMapper->findAllForWorkInterval($lwinterval->id);
165-
foreach($tags as $t){
180+
if ($tags == null && $lwinterval != null){
181+
$lastTags = $this->workIntervalToTagMapper->findAllForWorkInterval($lwinterval->id);
182+
foreach($lastTags as $t){
166183
$wtot = new WorkIntervalToTag();
167184
$wtot->setWorkIntervalId($winterval->id);
168185
$wtot->setTagId($t->tagId);
@@ -172,6 +189,20 @@ public function startTimer($name) {
172189

173190
}
174191

192+
if ($tags != null){
193+
$tagsArray = explode(",", $tags);
194+
foreach($tagsArray as $t){
195+
$wtot = new WorkIntervalToTag();
196+
$wtot->setWorkIntervalId($winterval->id);
197+
$wtot->setTagId($t);
198+
$wtot->setCreatedAt(time());
199+
$this->workIntervalToTagMapper->insert($wtot);
200+
}
201+
202+
}
203+
204+
205+
175206

176207
//echo json_encode((array)$winterval);
177208
return new JSONResponse(["WorkIntervals" => $winterval, "running" => 1]);

0 commit comments

Comments
 (0)