Skip to content

Commit 10be376

Browse files
authored
Merge pull request #3 from Hawiak/feature/use-enter-for-new-work-item
Feature/use enter for new work item
2 parents 5d436f0 + bce60c2 commit 10be376

File tree

7 files changed

+40
-22
lines changed

7 files changed

+40
-22
lines changed

appinfo/info.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Mit dem integrierten Dashboard lässt sich anhand eines Kuchen-/Donut-Diagramms
3535

3636
Diese App wird aktuell noch weiterentwickelt, also: Augen offen halten für neue Features! Und falls Dir irgendwelche Verbesserungsvorschläge, Probleme oder neue Features einfallen, schau mal auf unserem [GitHub Projekt](https://github.com/mtierltd/timetracker) vorbei, vielleicht wird Dein Thema bereits diskutiert! Und falls nicht, starte gerne eine neue Diskussion, wir freuen uns auf Dein Feedback!
3737
</description>
38-
<version>0.0.74</version>
38+
<version>0.0.75</version>
3939
<licence>agpl</licence>
4040
<author mail="[email protected]" >MTier Ltd.</author>
4141
<namespace>TimeTracker</namespace>

js/src/timer.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ function() {
2525

2626

2727
$( function() {
28+
$('#work-input-form').on('submit', function(e) {
29+
e.preventDefault();
30+
createWorkItem();
31+
});
2832
var days='30';
2933
var start = moment().startOf('day').subtract(29, 'days');
3034
var end = moment().endOf('day');
@@ -382,9 +386,7 @@ function() {
382386
})
383387
$('.wi-play').click(function(e) {
384388
e.preventDefault();
385-
$('#work-input').val($(this).data('work-name'));
386-
startTimer($(this).data('projectid'), $(this).data('tagids'));
387-
return false;
389+
createWorkItem();
388390
})
389391
$('.wi-trash').click(function(e) {
390392
$("#dialog-confirm").dialog({
@@ -577,6 +579,12 @@ function() {
577579
});
578580
}
579581

582+
function createWorkItem() {
583+
$('#work-input').val($(this).data('work-name'));
584+
startTimer($(this).data('projectid'), $(this).data('tagids'));
585+
return false;
586+
}
587+
580588
function startTimer(projectId = null, tags = ""){
581589
if(localStorage.getItem('isTimerStarted') === 'true'){
582590
stopTimer(startTimer, [projectId, tags]);

lib/Controller/AjaxController.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,14 @@ public function index() {
152152

153153
}
154154

155+
/**
156+
* @NoAdminRequired
157+
*/
155158
public function addCost($id)
156159
{
157160
$wi = $this->workIntervalMapper->find($id);
158161
$cost = $this->request->cost;
162+
$cost = str_replace(',', '.', $cost);
159163

160164
if (!is_numeric($cost)) {
161165
return new JSONResponse(['error' => 'Non numeric value'], Http::STATUS_BAD_REQUEST);
@@ -481,6 +485,8 @@ public function addWorkInterval() {
481485

482486
$this->workIntervalMapper->insert($wi);
483487

488+
$running = $this->workIntervalMapper->findAllRunning($this->userId);
489+
484490
return new JSONResponse(["WorkIntervals" => json_decode(json_encode($running), true)]);
485491
}
486492

@@ -561,12 +567,16 @@ public function deleteClient($id) {
561567
* @NoCSRFRequired
562568
*/
563569
public function getClients(){
564-
$clients = $this->clientMapper->findAll($this->userId);
565-
return new JSONResponse(["Clients" => json_decode(json_encode($clients), true)]);
566-
}
567-
570+
$clientName = $this->request->term ?? null;
568571

572+
if ($clientName) {
573+
$clients = $this->clientMapper->searchByName($this->userId, $clientName);
574+
} else {
575+
$clients = $this->clientMapper->findAll($this->userId);
576+
}
569577

578+
return new JSONResponse(["Clients" => json_decode(json_encode($clients), true)]);
579+
}
570580

571581
/**
572582
*

lib/Db/ClientMapper.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ public function __construct(IDBConnection $db) {
1616
public function findByName($name) {
1717
$sql = 'SELECT * FROM `*PREFIX*timetracker_client` ' .
1818
'WHERE upper(`name`) = ?';
19-
19+
2020
try {
2121
$e = $this->findEntity($sql, [strtoupper($name)]);
2222
return $e;
2323
} catch (\OCP\AppFramework\Db\DoesNotExistException $e){
2424
return null;
2525
}
26-
26+
2727
}
2828

2929
/**
@@ -36,11 +36,14 @@ public function find($id) {
3636
return $this->findEntity($sql, [$id]);
3737
}
3838

39-
4039
public function findAll($user){
4140
$sql = 'SELECT tc.* FROM `*PREFIX*timetracker_client` tc left join `*PREFIX*timetracker_user_to_client` uc on uc.client_id = tc.id where uc.user_uid = ? order by tc.name asc';
4241
return $this->findEntities($sql, [$user]);
4342
}
4443

45-
46-
}
44+
public function searchByName($user, $name){
45+
$name = strtoupper($name);
46+
$sql = 'SELECT tc.* FROM `*PREFIX*timetracker_client` tc left join `*PREFIX*timetracker_user_to_client` uc on uc.client_id = tc.id where uc.user_uid = ? and upper(tc.name) LIKE ? order by tc.name asc';
47+
return $this->findEntities($sql, [$user, "%" . $name . "%"]);
48+
}
49+
}

lib/Db/ProjectMapper.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ public function searchByName($user, string $name) {
3030
$name = strtoupper($name);
3131
$sql = 'SELECT tp.* FROM `*PREFIX*timetracker_project` tp LEFT JOIN `*PREFIX*timetracker_user_to_project` up ON up.project_id = tp.id WHERE up.`user_uid` = ? AND upper(tp.`name`) LIKE ? ORDER BY tp.`name`';
3232

33-
return $this->findEntities($sql, [$user, $name ."%"]);
33+
return $this->findEntities($sql, [$user,"%" . $name ."%"]);
34+
3435
}
3536

3637
/**
@@ -75,8 +76,4 @@ public function delete($project_id) {
7576
}
7677

7778
}
78-
79-
80-
81-
8279
}

lib/Migration/Version000020Date20220528101009.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
declare(strict_types=1);
44

55
/**
6-
* @copyright Copyright (c) 2022 Your name <your@email.com>
6+
* @copyright Copyright (c) 2022 Harm Akkerman <harmakkerman94@gmail.com>
77
*
8-
* @author Your name <your@email.com>
8+
* @author Harm Akkerman <harmakkerman94@gmail.com>
99
*
1010
* @license GNU AGPL version 3 or any later version
1111
*

templates/content/index.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div id="timetracker-content">
22
<div id="top-work-bar">
33
<div id="work-input-container">
4-
<form>
4+
<form id="work-input-form">
55
<input tabindex="1" type="text" spellcheck="false" autocomplete="off" class="" value="" placeholder="What have you done?" id="work-input">
66
</form>
77
</div>
@@ -66,4 +66,4 @@
6666
<div class="clearfix"> </div>
6767
<div id="work-intervals">
6868
</div>
69-
</div>
69+
</div>

0 commit comments

Comments
 (0)