Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Mit dem integrierten Dashboard lässt sich anhand eines Kuchen-/Donut-Diagramms

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!
</description>
<version>0.0.92</version>
<version>0.0.93</version>
<licence>agpl</licence>
<author mail="info@mtier.org" >MTier Ltd.</author>
<namespace>TimeTracker</namespace>
Expand Down
75 changes: 73 additions & 2 deletions js/src/app/views/TimerView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,23 @@

<form class="top-bar" @submit.prevent="onSubmitWorkInput">
<NcTextField v-model="workInput" style="width: 320px;" label="What have you done?" placeholder="What have you done?" />
<NcSelect v-model="startProject"
:options="projects"
label="name"
placeholder="Project"
aria-label-combobox="Project for the new timer"
:disabled="isRunning"
style="min-width: 180px;"
@update:model-value="startSelectionTouched = true" />
<NcSelect v-model="startTags"
:options="tags"
label="name"
multiple
placeholder="Tags"
aria-label-combobox="Tags for the new timer"
:disabled="isRunning"
style="min-width: 180px;"
@update:model-value="startSelectionTouched = true" />
<NcButton type="primary" native-type="submit">{{ isRunning ? 'Stop' : 'Start' }}</NcButton>
<span v-if="isRunning" class="live-timer">{{ liveTimerText }}</span>
<NcButton type="secondary" @click="openManualEntry">Manual entry</NcButton>
Expand Down Expand Up @@ -164,6 +181,11 @@ export default {
from.setDate(from.getDate() - 30)
return {
workInput: '',
// Project and tags for the next timer. Pre-filled by
// suggestStartSelection() until the user changes them.
startProject: null,
startTags: [],
startSelectionTouched: false,
days: {},
running: [],
projects: [],
Expand Down Expand Up @@ -202,9 +224,21 @@ export default {
}
return result
},
// All loaded entries, newest first
recentEntries() {
return Object.values(this.flattenedDays)
.flatMap((day) => day.children)
.sort((a, b) => b.start - a.start)
},
},
watch: {
workInput() {
this.suggestStartSelection()
},
},
async mounted() {
await Promise.all([this.loadWorkIntervals(), this.loadProjects(), this.loadTags()])
this.suggestStartSelection()
},
beforeUnmount() {
clearInterval(this.liveTimerInterval)
Expand All @@ -230,14 +264,41 @@ export default {
this.loadWorkIntervals()
},
async loadWorkIntervals() {
// The end date picker gives a moment on that day (page load time, or
// midnight when picked), so include the whole day: otherwise entries
// started later that day, like a timer started just now, are missing.
const to = new Date(this.rangeTo)
to.setHours(23, 59, 59, 999)
const data = await apiGet('/work-intervals', {
from: Math.floor(this.rangeFrom.getTime() / 1000),
to: Math.floor(this.rangeTo.getTime() / 1000),
to: Math.floor(to.getTime() / 1000),
tzoffset: new Date().getTimezoneOffset(),
})
this.days = data.days || {}
this.running = data.running || []
this.setupLiveTimer(data.now)
this.suggestStartSelection()
},
/**
* Pre-fill project and tags for the next timer, unless the user
* already changed them:
* - an earlier entry with the same name: its project and tags, which
* is what the server would copy anyway
* - otherwise: the project of the latest entry that has one
*/
suggestStartSelection() {
if (this.startSelectionTouched) return
const name = this.workInput.trim()
const sameName = name ? this.recentEntries.find((e) => e.name === name) : null
if (sameName) {
this.startProject = this.projectFor(sameName)
const tagIds = (sameName.tags || []).map((t) => t.id)
this.startTags = this.tags.filter((t) => tagIds.includes(t.id))
return
}
const lastWithProject = this.recentEntries.find((e) => e.projectId)
this.startProject = lastWithProject ? this.projectFor(lastWithProject) : null
this.startTags = []
},
setupLiveTimer(serverNow) {
clearInterval(this.liveTimerInterval)
Expand All @@ -255,7 +316,15 @@ export default {
if (this.isRunning) {
await this.stopTimer()
} else {
await this.startTimer(this.workInput.trim() || 'no description')
const started = await this.startTimer(
this.workInput.trim() || 'no description',
this.startProject?.id,
this.startTags.map((t) => t.id).join(','),
)
if (started) {
this.startSelectionTouched = false
this.suggestStartSelection()
}
}
},
async startTimer(name, projectId, tagIds) {
Expand All @@ -266,8 +335,10 @@ export default {
})
this.workInput = ''
await this.loadWorkIntervals()
return true
} catch (e) {
showError(e.message)
return false
}
},
async stopTimer() {
Expand Down
67 changes: 46 additions & 21 deletions lib/Controller/AjaxController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Controller;
use OCP\IDBConnection;
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IUserSession;
Expand Down Expand Up @@ -53,12 +54,13 @@ class AjaxController extends Controller {
protected $l10n;
protected $groupManager;
protected $mailer;
protected $db;

public function __construct($AppName, IRequest $request, IUserSession $userSession, IL10N $l10n,
WorkIntervalMapper $workIntervalMapper, ClientMapper $clientMapper, UserToClientMapper $userToClientMapper,
ProjectMapper $projectMapper, UserToProjectMapper $userToProjectMapper, TagMapper $tagMapper, WorkIntervalToTagMapper $workIntervalToTagMapper, ReportItemMapper $reportItemMapper,
TimelineMapper $timelineMapper, TimelineEntryMapper $timelineEntryMapper, GoalMapper $goalMapper,
IGroupManager $groupManager, IMailer $mailer, $userId){
IGroupManager $groupManager, IMailer $mailer, IDBConnection $db, $userId){
parent::__construct($AppName, $request);
$this->userId = $userId;
$this->userSession = $userSession;
Expand All @@ -82,6 +84,7 @@ public function __construct($AppName, IRequest $request, IUserSession $userSessi
$this->l10n = $l10n;
$this->groupManager = $groupManager;
$this->mailer = $mailer;
$this->db = $db;
}

/**
Expand Down Expand Up @@ -1012,20 +1015,28 @@ public function postTimeline(){
$timeline->setTotalDuration($totalDuration);
$timeline->setCreatedAt(time());
$timeline->setStatus('pending');
$this->timelineMapper->insert($timeline);
foreach($items as $i){
$te = new TimelineEntry();
$te->setTimelineId($timeline->id);
$te->setUserUid($timeline->userUid);
$te->setName($i->name);
$te->setProjectName($i->project ? $i->project : "");
$te->setClientName($i->client ? $i->client : "");
$te->setTimeInterval($i->time);
$te->setTotalDuration($i->totalDuration);
$te->setCreatedAt(time());
$te->setCost($i->cost);
$this->timelineEntryMapper->insert($te);

// Create the timeline and all its entries together, so a failing entry
// doesn't leave an empty timeline behind.
$this->db->beginTransaction();
try {
$this->timelineMapper->insert($timeline);
foreach($items as $i){
$te = new TimelineEntry();
$te->setTimelineId($timeline->id);
$te->setUserUid($timeline->userUid);
$te->setName($i->name);
$te->setProjectName($i->project ? $i->project : "");
$te->setClientName($i->client ? $i->client : "");
$te->setTimeInterval($i->time);
$te->setTotalDuration($i->totalDuration);
$te->setCreatedAt(time());
$te->setCost($i->cost);
$this->timelineEntryMapper->insert($te);
}
$this->db->commit();
} catch (\Throwable $e) {
$this->db->rollBack();
throw $e;
}
return new JSONResponse(["Timeline" => json_decode(json_encode($timeline), true)]);
}
Expand Down Expand Up @@ -1064,6 +1075,16 @@ public function secondsToTime($seconds){
return $timeFormat;
}

/**
* Costs are stored in cents; empty when an entry has no cost.
*/
private function formatCost($cents){
if ($cents === null || $cents === '') {
return '';
}
return number_format(((int)$cents) / 100, 2, '.', '');
}

/**
*
* @NoAdminRequired
Expand All @@ -1085,14 +1106,16 @@ public function downloadTimeline($id){
$output = fopen('php://output', 'w');

// output the column headings
fputcsv($output, array('id', 'User Uid', 'Name', 'Project Name', 'Client Name', 'Time Interval', 'Total Duration'));
fputcsv($output, array('id', 'User Uid', 'Name', 'Project Name', 'Client Name', 'Time Interval', 'Total Duration', 'Cost'));
$totalDuration = 0;
$totalCost = 0;
foreach($te as $t){

fputcsv($output, [$t->id, $t->userUid, $t->name, $t->projectName, $t->clientName, $t->timeInterval, $this->secondsToTime($t->totalDuration)]);
fputcsv($output, [$t->id, $t->userUid, $t->name, $t->projectName, $t->clientName, $t->timeInterval, $this->secondsToTime($t->totalDuration), $this->formatCost($t->cost)]);
$totalDuration += $t->totalDuration;
$totalCost += (int)$t->cost;
}
fputcsv($output, ['TOTAL', '', '', '', '', '', $this->secondsToTime($totalDuration)]);
fputcsv($output, ['TOTAL', '', '', '', '', '', $this->secondsToTime($totalDuration), $this->formatCost($totalCost)]);
fclose($output);
exit(0);
}
Expand Down Expand Up @@ -1151,14 +1174,16 @@ public function emailTimeline($id) {
$output = fopen($path, "w");
//$path = stream_get_meta_data($output)['uri'];
// output the column headings
fputcsv($output, array('id', 'User Uid', 'Name', 'Project Name', 'Client Name', 'Time Interval', 'Total Duration'));
fputcsv($output, array('id', 'User Uid', 'Name', 'Project Name', 'Client Name', 'Time Interval', 'Total Duration', 'Cost'));
$totalDuration = 0;
$totalCost = 0;
foreach($te as $t){

fputcsv($output, [$t->id, $t->userUid, $t->name, $t->projectName, $t->clientName, $t->timeInterval, $this->secondsToTime($t->totalDuration)]);
fputcsv($output, [$t->id, $t->userUid, $t->name, $t->projectName, $t->clientName, $t->timeInterval, $this->secondsToTime($t->totalDuration), $this->formatCost($t->cost)]);
$totalDuration += $t->totalDuration;
$totalCost += (int)$t->cost;
}
fputcsv($output, ['TOTAL', '', '', '', '', '', $this->secondsToTime($totalDuration)]);
fputcsv($output, ['TOTAL', '', '', '', '', '', $this->secondsToTime($totalDuration), $this->formatCost($totalCost)]);



Expand Down
2 changes: 2 additions & 0 deletions lib/Db/TimelineEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class TimelineEntry extends Entity {
public $timeInterval;
public $totalDuration;
public $createdAt;
public $cost;


public function __construct() {
Expand All @@ -29,5 +30,6 @@ public function __construct() {
$this->addType('timeInterval', 'string');
$this->addType('totalDuration', 'string');
$this->addType('createdAt', 'integer');
$this->addType('cost', 'integer');
}
}
56 changes: 56 additions & 0 deletions lib/Migration/Version000093Date20261024000000.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

declare(strict_types=1);

/**
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

namespace OCA\TimeTracker\Migration;

use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\DB\Types;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

/**
* Stores the cost of each timeline entry, like work intervals do since
* Version000020Date20220528101009 (in cents, nullable).
*/
class Version000093Date20261024000000 extends SimpleMigrationStep {

public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();

if (!$schema->hasTable('timetracker_timeline_entry')) {
return null;
}

$table = $schema->getTable('timetracker_timeline_entry');
if ($table->hasColumn('cost')) {
return null;
}

$table->addColumn('cost', Types::INTEGER, [
'notnull' => false,
'length' => 10,
]);

return $schema;
}
}
10 changes: 10 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -409,3 +409,13 @@ parameters:
message: "#^Call to method setPrimaryKey\\(\\) on an unknown class Doctrine\\\\DBAL\\\\Schema\\\\Table\\.$#"
count: 2
path: lib/Migration/Version000001Date20210719192031.php

-
message: "#^Call to method addColumn\\(\\) on an unknown class Doctrine\\\\DBAL\\\\Schema\\\\Table\\.$#"
count: 1
path: lib/Migration/Version000093Date20261024000000.php

-
message: "#^Call to method hasColumn\\(\\) on an unknown class Doctrine\\\\DBAL\\\\Schema\\\\Table\\.$#"
count: 1
path: lib/Migration/Version000093Date20261024000000.php
Loading