WIP timesheet timers: fix overwrite and display overwritten time and time of recording

This commit is contained in:
ralf 2022-10-06 09:03:51 +02:00
parent 0a745299ce
commit ccee240055
6 changed files with 30 additions and 18 deletions

View File

@ -74,13 +74,14 @@ egw.extend('timer', egw.MODULE_GLOBAL, function()
/** /**
* Get state of timer * Get state of timer
* @param string _action last action * @param string _action last action
* @param string|Date|undefined _time time to report
* @returns {{action: string, overall: {}, specific: {}, ts: Date}} * @returns {{action: string, overall: {}, specific: {}, ts: Date}}
*/ */
function getState(_action) function getState(_action, _time)
{ {
return { return {
action: _action, action: _action,
ts: new Date(), ts: new Date(_time || new Date),
overall: overall, overall: overall,
specific: specific specific: specific
} }
@ -124,7 +125,7 @@ egw.extend('timer', egw.MODULE_GLOBAL, function()
break; break;
} }
// persist state // persist state
egw.request('timesheet.EGroupware\\Timesheet\\Events.ajax_event', [getState(_action)]).then(() => { egw.request('timesheet.EGroupware\\Timesheet\\Events.ajax_event', [getState(_action, _time)]).then(() => {
if (_action === 'specific-stop') if (_action === 'specific-stop')
{ {
egw.open(null, 'timesheet', 'add', {events: 'specific'}); egw.open(null, 'timesheet', 'add', {events: 'specific'});
@ -336,6 +337,7 @@ egw.extend('timer', egw.MODULE_GLOBAL, function()
timerAction(button_id.replace(/_([a-z]+)\[([a-z]+)\]/, '$1-$2'), timerAction(button_id.replace(/_([a-z]+)\[([a-z]+)\]/, '$1-$2'),
// eT2 operates in user-time, while timers here always operate in UTC // eT2 operates in user-time, while timers here always operate in UTC
value.time ? new Date((new Date(value.time)).valueOf() + egw.getTimezoneOffset() * 60000) : undefined); value.time ? new Date((new Date(value.time)).valueOf() + egw.getTimezoneOffset() * 60000) : undefined);
dialog._overlayContentNode.querySelector('et2-date-time').value = '';
setButtonState(); setButtonState();
return false; return false;
} }
@ -360,9 +362,6 @@ egw.extend('timer', egw.MODULE_GLOBAL, function()
setButtonState(); setButtonState();
// update timers in dialog // update timers in dialog
update(); update();
// set current time for overwrite time input (eT2 operates in user-time!)
//let now = new Date((new Date).valueOf() - egw.getTimezoneOffset() * 60000);
//dialog._overlayContentNode.querySelector('et2-date-time').value = now;
}); });
}); });
} }

View File

@ -97,7 +97,7 @@ only admin admin de nur Administratoren
only admin can edit this status admin de nur Administratoren dürfen Stundenzettel mit diesen Status bearbeiten only admin can edit this status admin de nur Administratoren dürfen Stundenzettel mit diesen Status bearbeiten
or endtime timesheet de oder Endzeit or endtime timesheet de oder Endzeit
order timesheet de Reihenfolge order timesheet de Reihenfolge
overwrite common de Überschreiben overwrite time common de Zeit überschreiben
overwriting start or stop time timesheet de Überschreiben der Start- oder Stop-Zeit overwriting start or stop time timesheet de Überschreiben der Start- oder Stop-Zeit
parent admin de Übergeordnet parent admin de Übergeordnet
pause common de Pause pause common de Pause
@ -108,6 +108,7 @@ price timesheet de Preis
project fields timesheet de Felder Projektmanager project fields timesheet de Felder Projektmanager
projectmanager integration admin de Integration des Projektmanagers projectmanager integration admin de Integration des Projektmanagers
quantity timesheet de Menge quantity timesheet de Menge
recorded timesheet de Aufgenommen
recovered timesheet de wiederhergestellt recovered timesheet de wiederhergestellt
replacements for inserting entries into documents timesheet de Platzhalter für das Einfügen in Dokumente replacements for inserting entries into documents timesheet de Platzhalter für das Einfügen in Dokumente
restore this entry timesheet de Diesen Eintrag wiederherstellen restore this entry timesheet de Diesen Eintrag wiederherstellen
@ -134,6 +135,7 @@ status deleted. timesheet de Status gelöscht
status of created timesheets timesheet de Status für neue Stundenzettel status of created timesheets timesheet de Status für neue Stundenzettel
status updated. timesheet de Status geändert status updated. timesheet de Status geändert
stop common de Stop stop common de Stop
sum timesheet de Summe
sum %1: timesheet de Summe %1: sum %1: timesheet de Summe %1:
tag to mark positions for address labels timesheet de Platzhalter, um die Position der Adresslabels festzulegen tag to mark positions for address labels timesheet de Platzhalter, um die Position der Adresslabels festzulegen
the document can contain placeholder like {{%3}}, to be replaced with the data (%1full list of placeholder names%2). timesheet de Das Dokument kann Platzhalter wie {{%3}} beinhalten, die mit den entsprechenden Inhalten ersetzt werden (%1Liste der Platzhalter%2). the document can contain placeholder like {{%3}}, to be replaced with the data (%1full list of placeholder names%2). timesheet de Das Dokument kann Platzhalter wie {{%3}} beinhalten, die mit den entsprechenden Inhalten ersetzt werden (%1Liste der Platzhalter%2).

View File

@ -97,7 +97,7 @@ only admin admin en Only admin
only admin can edit this status admin en Only admins can edit timesheets with this status only admin can edit this status admin en Only admins can edit timesheets with this status
or endtime timesheet en or end time or endtime timesheet en or end time
order timesheet en Order order timesheet en Order
overwrite common en Overwrite overwrite time common en Overwrite time
overwriting start or stop time timesheet en Overwriting start or stop time overwriting start or stop time timesheet en Overwriting start or stop time
parent admin en Parent parent admin en Parent
pause common en Pause pause common en Pause
@ -108,6 +108,7 @@ price timesheet en Price
project fields timesheet en Project fields project fields timesheet en Project fields
projectmanager integration admin en Project Manager integration projectmanager integration admin en Project Manager integration
quantity timesheet en Quantity quantity timesheet en Quantity
recorded timesheet en Recorded
recovered timesheet en recovered recovered timesheet en recovered
replacements for inserting entries into documents timesheet en Replacements for inserting entries into documents replacements for inserting entries into documents timesheet en Replacements for inserting entries into documents
restore this entry timesheet en Restore this entry restore this entry timesheet en Restore this entry
@ -134,6 +135,7 @@ status deleted. timesheet en Status deleted.
status of created timesheets timesheet en Status of created timesheets status of created timesheets timesheet en Status of created timesheets
status updated. timesheet en Status updated. status updated. timesheet en Status updated.
stop common en Stop stop common en Stop
sum timesheet en Sum
sum %1: timesheet en Sum %1: sum %1: timesheet en Sum %1:
tag to mark positions for address labels timesheet en Tag to mark positions for address labels tag to mark positions for address labels timesheet en Tag to mark positions for address labels
the document can contain placeholder like {{%3}}, to be replaced with the data (%1full list of placeholder names%2). timesheet en The document can contain placeholder like {{%3}}, to be replaced with the data (%1full list of placeholder names%2). the document can contain placeholder like {{%3}}, to be replaced with the data (%1full list of placeholder names%2). timesheet en The document can contain placeholder like {{%3}}, to be replaced with the data (%1full list of placeholder names%2).

View File

@ -210,7 +210,7 @@ class Events extends Api\Storage\Base
* *
* @param array& $timer array with keys 'start', 'offset' and 'paused' * @param array& $timer array with keys 'start', 'offset' and 'paused'
* @param array $row * @param array $row
* @return void * @return int? time in ms for stop or pause events, null for start
*/ */
protected static function evaluate(array &$timer, array $row) protected static function evaluate(array &$timer, array $row)
{ {
@ -221,7 +221,7 @@ class Events extends Api\Storage\Base
} }
elseif ($timer['start']) elseif ($timer['start'])
{ {
$timer['offset'] += 1000 * ($row['tse_time']->getTimestamp() - $timer['start']->getTimestamp()); $timer['offset'] += $time = 1000 * ($row['tse_time']->getTimestamp() - $timer['start']->getTimestamp());
$timer['start'] = null; $timer['start'] = null;
$timer['paused'] = ($row['tse_type'] & self::PAUSE) === self::PAUSE; $timer['paused'] = ($row['tse_type'] & self::PAUSE) === self::PAUSE;
} }
@ -229,6 +229,7 @@ class Events extends Api\Storage\Base
{ {
$timer['paused'] = ($row['tse_type'] & self::PAUSE) === self::PAUSE; $timer['paused'] = ($row['tse_type'] & self::PAUSE) === self::PAUSE;
} }
return $time ?? null;
} }
/** /**
@ -237,10 +238,10 @@ class Events extends Api\Storage\Base
* Not stopped events-sequences are NOT returned (stopped sequences end with a stop event). * Not stopped events-sequences are NOT returned (stopped sequences end with a stop event).
* *
* @param int|array $filter * @param int|array $filter
* @param int &$time=null on return time in seconds * @param int &$total=null on return time in seconds
* @return array[] tse_id => array pairs plus extra key sum (time-sum in seconds) * @return array[] tse_id => array pairs plus extra key sum (time-sum in seconds)
*/ */
public static function get($filter, int &$time=null) public static function get($filter, int &$total=null)
{ {
if (!is_array($filter)) if (!is_array($filter))
{ {
@ -251,24 +252,25 @@ class Events extends Api\Storage\Base
'offset' => 0, 'offset' => 0,
'paused' => false, 'paused' => false,
]; ];
$time = $open = 0; $total = $open = 0;
$events = []; $events = [];
foreach(self::getInstance()->search('', false, 'tse_id', '', '', foreach(self::getInstance()->search('', false, 'tse_id', '', '',
false, 'AND', false, $filter) as $row) false, 'AND', false, $filter) as $row)
{ {
self::evaluate($timer, $row); $time = self::evaluate($timer, $row);
++$open; ++$open;
if ($row['tse_type'] & self::STOP) if ($row['tse_type'] & self::STOP)
{ {
$row['total'] = $time += $timer['offset'] / 1000; $row['total'] = $total += $timer['offset'] / 1000;
$timer = $init_timer; $timer = $init_timer;
$open = 0; $open = 0;
} }
elseif ($row['tse_type'] & self::PAUSE) elseif ($row['tse_type'] & self::PAUSE)
{ {
$row['total'] = $time + $timer['offset'] / 1000; $row['total'] = $total + $timer['offset'] / 1000;
} }
$row['time'] = $time / 1000;
$events[$row['tse_id']] = $row; $events[$row['tse_id']] = $row;
} }
// remove open / unstopped timer events // remove open / unstopped timer events

View File

@ -88,16 +88,22 @@
<column/> <column/>
<column/> <column/>
<column/> <column/>
<column/>
<column/>
</columns> </columns>
<rows> <rows>
<row class="th"> <row class="th">
<description value="Time"/> <description value="Time"/>
<description value="Recorded"/>
<description value="Type"/> <description value="Type"/>
<description value="Duration"/> <description value="Duration"/>
<description value="Sum"/>
</row> </row>
<row> <row>
<date-time id="${row}[tse_time]" readonly="true"/> <date-time id="${row}[tse_time]" readonly="true"/>
<date-time id="${row}[tse_timestamp]" readonly="true"/>
<select id="${row}[tse_type]" readonly="true"/> <select id="${row}[tse_type]" readonly="true"/>
<date-timeonly id="${row}[time]" readonly="true"/>
<date-timeonly id="${row}[total]" readonly="true"/> <date-timeonly id="${row}[total]" readonly="true"/>
</row> </row>
</rows> </rows>

View File

@ -12,8 +12,9 @@
</columns> </columns>
<rows> <rows>
<row disabled="@disable=/overwrite/"> <row disabled="@disable=/overwrite/">
<description value="Overwrite" span="2"/> <description value="Overwrite time" span="2"/>
<et2-date-time id="time" span="all"/> <et2-date-time id="time" span="all" placeholder="now"
onclick="if (!this.value) this.value = new Date((new Date).valueOf() - egw.getTimezoneOffset() * 60000)"/>
</row> </row>
<row disabled="@disable=/specific/"> <row disabled="@disable=/specific/">
<description value="Timer"/> <description value="Timer"/>