Skip to content
This repository was archived by the owner on Mar 30, 2024. It is now read-only.

Commit 397b859

Browse files
committed
Get additional time for last task (don't give name in dialog and write e.g. +5m as time)
1 parent a4ceeff commit 397b859

File tree

8 files changed

+40
-12
lines changed

8 files changed

+40
-12
lines changed

core/InputParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
class InputParser {
33

4-
private const TIME_INPUT_PREG = '/^(((\d+h)?(\d+m)?)|(\d+:\d+))$/';
4+
private const TIME_INPUT_PREG = '/^((\+?(\d+h)?(\d+m)?)|(\d+:\d+))$/';
55

66
private const CATEGORY_INPUT_PREG = '/^[A-Za-z\-]+$/';
77

core/Recorder.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ private function saveTaskTime(JSONReader $r) : void {
7575
"name" => $r->getValue(['name']),
7676
"category" => $r->getValue(['category'])
7777
));
78+
$this->dialog->setLastTask(
79+
$r->getValue(['name']),
80+
in_array($r->getValue(['category']), StatsData::getAllCategories()) ?
81+
array_search($r->getValue(['category']), StatsData::getAllCategories()) : null
82+
);
7883
}
7984

8085
private function recordNew(JSONReader $r) : void {

core/Utilities.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55
class Utilities {
66

7-
const VERSION = 'v0.8.5 alpha';
7+
const VERSION = 'v0.8.6 alpha';
88

99
/**
1010
* OS Consts

core/platform/Dialog.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ abstract class Dialog {
2121
protected ?string $chTime = null;
2222
protected bool $shortBreak = false;
2323

24+
/**
25+
* Set the last tasks name and category
26+
* User can enter +5m to get five minutes more
27+
* for last task.
28+
*/
29+
public function setLastTask(?string $name, ?int $category){
30+
$this->chName = $name;
31+
$this->chCategory = $category;
32+
}
33+
2434
/**
2535
* Set an array of available categories [ID => CatName, ...]
2636
* No short break now, will be set in open().

core/platform/InTerminalDialog.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ public function open() : void {
3030
echo "Give a name for the task:" . PHP_EOL;
3131
do {
3232
$name = readline("Name: ");
33-
} while( empty($name) );
33+
} while( !InputParser::checkNameInput($name) );
3434
$this->chName = $name;
3535

3636
echo "-----------------------------------" . PHP_EOL;
3737
echo "Give a time limit for the task:" . PHP_EOL;
3838
do {
3939
$time = readline("Time: ");
40-
} while( !InputParser::checkTimeInput($time) );
40+
} while( !InputParser::checkTimeInput($time) || strpos($time, '+') !== false );
4141
$this->chTime = $time;
4242

4343
echo "===================================" . PHP_EOL;

core/platform/LinuxDialog.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,20 @@ public function open() : void {
3535
$this->open();
3636
return;
3737
}
38-
39-
$this->chCategory = in_array($stdout[0], $this->categories) ? array_search($stdout[0], $this->categories) : null; // category id
40-
$this->chName = InputParser::checkNameInput($stdout[1]) ? $stdout[1] : null;
41-
$this->chTime = InputParser::checkTimeInput($stdout[2]) ? $stdout[2] : null;
4238

39+
// additional time?
40+
$timelist = array_values(array_filter($stdout, function ($v){
41+
return InputParser::checkTimeInput($v);
42+
}));
43+
if( count($timelist) === 1 && strpos($timelist[0], '+' ) !== false ){
44+
$this->chTime = $timelist[0];
45+
}
46+
else{
47+
$this->chCategory = in_array($stdout[0], $this->categories) ? array_search($stdout[0], $this->categories) : null; // category id
48+
$this->chName = InputParser::checkNameInput($stdout[1]) ? $stdout[1] : null;
49+
$this->chTime = InputParser::checkTimeInput($stdout[2]) ? $stdout[2] : null;
50+
}
51+
4352
if( is_null($this->chCategory) || is_null( $this->chTime ) || is_null($this->chName)){
4453
$this->open();
4554
return;

core/platform/MacDialog.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ public function open() : void {
2121
$this->shortBreak = true;
2222
}
2323
else{
24-
$this->chCategory = in_array($stdout['cat'], $this->categories) ? array_search($stdout['cat'], $this->categories) : null; // category id
25-
$this->chName = InputParser::checkNameInput($stdout['name']) ? $stdout['name'] : null;
24+
if( strpos($stdout['time'], '+' ) === false ){ // not additional time for last task/ else values are set
25+
$this->chCategory = in_array($stdout['cat'], $this->categories) ? array_search($stdout['cat'], $this->categories) : null; // category id
26+
$this->chName = InputParser::checkNameInput($stdout['name']) ? $stdout['name'] : null;
27+
}
2628
$this->chTime = InputParser::checkTimeInput($stdout['time']) ? $stdout['time'] : null;
2729

2830
if( is_null($this->chCategory) || is_null( $this->chTime ) || is_null($this->chName)){

core/platform/WindowsDialog.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ public function open() : void {
2424
$this->shortBreak = true;
2525
}
2626
else{
27-
$this->chCategory = in_array($stdout['cat'], $this->categories) ? array_search($stdout['cat'], $this->categories) : null; // category id
28-
$this->chName = InputParser::checkNameInput($stdout['name']) ? $stdout['name'] : null;
27+
if( strpos($stdout['time'], '+' ) === false ){ // not additional time for last task/ else values are set
28+
$this->chCategory = in_array($stdout['cat'], $this->categories) ? array_search($stdout['cat'], $this->categories) : null; // category id
29+
$this->chName = InputParser::checkNameInput($stdout['name']) ? $stdout['name'] : null;
30+
}
2931
$this->chTime = InputParser::checkTimeInput($stdout['time']) ? $stdout['time'] : null;
3032

3133
if( is_null($this->chCategory) || is_null( $this->chTime ) || is_null($this->chName)){

0 commit comments

Comments
 (0)