mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-20 12:30:56 +01:00
Added a popup to both start and end times with Phrequent allowing the user to edit their start/end times. Also added a field for notes on the stop time
Summary: I have added a dialog box which pops up when a user starts or stops tracking time on an issue with Phrequent. These dialogs allow the user to modify the time if it so happens that they forgot to either clock in or out. I have also added a Note field in the dialog when a user stops tracking time. This allows them to enter a note about the time, and is entered into the database, but is currently (as far as I know) not visible anywhere in Phabricator. I have made these changes according to the suggestions found in T3568 Also, upon clocking in or out, if the time entered is a future time, an error is returned and the user is asked to enter a valid time. Test Plan: Start tracking time and edit the start date/time, then end the time and edit that timestamp as well. Also, try entering future dates/times and ensure that the dialog reports an error and asks for the time again. Ensure that these edited times are recorded properly. Reviewers: epriestley, #blessed_reviewers Subscribers: epriestley, Korvin Maniphest Tasks: T3568 Differential Revision: https://secure.phabricator.com/D9147
This commit is contained in:
parent
3e9a988cd7
commit
715bf1fd55
1 changed files with 84 additions and 9 deletions
|
@ -15,18 +15,90 @@ final class PhrequentTrackController
|
|||
$request = $this->getRequest();
|
||||
$user = $request->getUser();
|
||||
|
||||
$phid = $this->phid;
|
||||
$handle = id(new PhabricatorHandleQuery())
|
||||
->setViewer($user)
|
||||
->withPHIDs(array($phid))
|
||||
->executeOne();
|
||||
|
||||
if (!$this->isStartingTracking() &&
|
||||
!$this->isStoppingTracking()) {
|
||||
throw new Exception('Unrecognized verb: ' . $this->verb);
|
||||
}
|
||||
|
||||
if ($this->isStartingTracking()) {
|
||||
$this->startTracking($user, $this->phid);
|
||||
} else if ($this->isStoppingTracking()) {
|
||||
$this->stopTracking($user, $this->phid);
|
||||
switch ($this->verb) {
|
||||
case 'start':
|
||||
$button_text = pht('Start Tracking');
|
||||
$title_text = pht('Start Tracking Time');
|
||||
$inner_text = pht('What time did you start working?');
|
||||
$action_text = pht('Start Timer');
|
||||
$label_text = pht('Start Time');
|
||||
break;
|
||||
case 'stop':
|
||||
$button_text = pht('Stop Tracking');
|
||||
$title_text = pht('Stop Tracking Time');
|
||||
$inner_text = pht('What time did you stop working?');
|
||||
$action_text = pht('Stop Timer');
|
||||
$label_text = pht('Stop Time');
|
||||
break;
|
||||
}
|
||||
|
||||
return id(new AphrontRedirectResponse());
|
||||
$epoch_control = id(new AphrontFormDateControl())
|
||||
->setUser($user)
|
||||
->setName('epoch')
|
||||
->setLabel($action_text)
|
||||
->setValue(time());
|
||||
|
||||
$err = array();
|
||||
|
||||
if ($request->isDialogFormPost()) {
|
||||
$timestamp = $epoch_control->readValueFromRequest($request);
|
||||
$note = $request->getStr('note');
|
||||
|
||||
if (!$epoch_control->isValid() || $timestamp > time()) {
|
||||
$err[] = pht('Invalid date, please enter a valid non-future date');
|
||||
}
|
||||
|
||||
if (!$err) {
|
||||
if ($this->isStartingTracking()) {
|
||||
$this->startTracking($user, $this->phid, $timestamp);
|
||||
} else if ($this->isStoppingTracking()) {
|
||||
$this->stopTracking($user, $this->phid, $timestamp, $note);
|
||||
}
|
||||
return id(new AphrontRedirectResponse());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$dialog = $this->newDialog()
|
||||
->setTitle($title_text)
|
||||
->setWidth(AphrontDialogView::WIDTH_FORM);
|
||||
|
||||
if ($err) {
|
||||
$dialog->setErrors($err);
|
||||
}
|
||||
|
||||
$form = new PHUIFormLayoutView();
|
||||
$form
|
||||
->appendChild(hsprintf(
|
||||
"<p>%s</p><br />", $inner_text));
|
||||
|
||||
$form->appendChild($epoch_control);
|
||||
|
||||
if ($this->isStoppingTracking()) {
|
||||
$form
|
||||
->appendChild(
|
||||
id(new AphrontFormTextControl())
|
||||
->setLabel(pht('Note'))
|
||||
->setName('note'));
|
||||
}
|
||||
|
||||
$dialog->appendChild($form);
|
||||
|
||||
$dialog->addCancelButton($handle->getURI());
|
||||
$dialog->addSubmitButton($action_text);
|
||||
|
||||
return $dialog;
|
||||
}
|
||||
|
||||
private function isStartingTracking() {
|
||||
|
@ -37,15 +109,15 @@ final class PhrequentTrackController
|
|||
return $this->verb === 'stop';
|
||||
}
|
||||
|
||||
private function startTracking($user, $phid) {
|
||||
private function startTracking($user, $phid, $timestamp) {
|
||||
$usertime = new PhrequentUserTime();
|
||||
$usertime->setDateStarted(time());
|
||||
$usertime->setDateStarted($timestamp);
|
||||
$usertime->setUserPHID($user->getPHID());
|
||||
$usertime->setObjectPHID($phid);
|
||||
$usertime->save();
|
||||
}
|
||||
|
||||
private function stopTracking($user, $phid) {
|
||||
private function stopTracking($user, $phid, $timestamp, $note) {
|
||||
if (!PhrequentUserTimeQuery::isUserTrackingObject($user, $phid)) {
|
||||
// Don't do anything, it's not being tracked.
|
||||
return;
|
||||
|
@ -57,13 +129,16 @@ final class PhrequentTrackController
|
|||
queryfx(
|
||||
$conn,
|
||||
'UPDATE %T usertime '.
|
||||
'SET usertime.dateEnded = UNIX_TIMESTAMP() '.
|
||||
'SET usertime.dateEnded = %d, '.
|
||||
'usertime.note = %s '.
|
||||
'WHERE usertime.userPHID = %s '.
|
||||
'AND usertime.objectPHID = %s '.
|
||||
'AND usertime.dateEnded IS NULL '.
|
||||
'ORDER BY usertime.dateStarted, usertime.id DESC '.
|
||||
'LIMIT 1',
|
||||
$usertime_dao->getTableName(),
|
||||
$timestamp,
|
||||
$note,
|
||||
$user->getPHID(),
|
||||
$phid);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue