1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 00:42:41 +01:00

Calendar events should now have a 'Name' field.

Summary: Closes T7953, Calendar events should now have a 'Name' field.

Test Plan: Create or edit event with no title, save event, should get error requiring name, event detail view timeline should reflect name changes.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: Korvin, epriestley

Maniphest Tasks: T7953

Differential Revision: https://secure.phabricator.com/D12591
This commit is contained in:
lkassianik 2015-04-28 08:34:26 -07:00
parent d961a15d07
commit 43ab0e879f
6 changed files with 128 additions and 58 deletions

View file

@ -0,0 +1,2 @@
ALTER TABLE {$NAMESPACE}_calendar.calendar_event
ADD name LONGTEXT COLLATE {$COLLATE_TEXT} NOT NULL;

View file

@ -14,8 +14,11 @@ final class PhabricatorCalendarEventEditController
} }
public function processRequest() { public function processRequest() {
$request = $this->getRequest(); $request = $this->getRequest();
$user = $request->getUser(); $user = $request->getUser();
$error_name = true;
$validation_exception = null;
$start_time = id(new AphrontFormDateControl()) $start_time = id(new AphrontFormDateControl())
->setUser($user) ->setUser($user)
@ -30,15 +33,15 @@ final class PhabricatorCalendarEventEditController
->setInitialTime(AphrontFormDateControl::TIME_END_OF_DAY); ->setInitialTime(AphrontFormDateControl::TIME_END_OF_DAY);
if ($this->isCreate()) { if ($this->isCreate()) {
$status = PhabricatorCalendarEvent::initializeNewCalendarEvent($user); $event = PhabricatorCalendarEvent::initializeNewCalendarEvent($user);
$end_value = $end_time->readValueFromRequest($request); $end_value = $end_time->readValueFromRequest($request);
$start_value = $start_time->readValueFromRequest($request); $start_value = $start_time->readValueFromRequest($request);
$submit_label = pht('Create'); $submit_label = pht('Create');
$filter = 'status/create/'; $filter = 'event/create/';
$page_title = pht('Create Event'); $page_title = pht('Create Event');
$redirect = 'created'; $redirect = 'created';
} else { } else {
$status = id(new PhabricatorCalendarEventQuery()) $event = id(new PhabricatorCalendarEventQuery())
->setViewer($user) ->setViewer($user)
->withIDs(array($this->id)) ->withIDs(array($this->id))
->requireCapabilities( ->requireCapabilities(
@ -47,24 +50,25 @@ final class PhabricatorCalendarEventEditController
PhabricatorPolicyCapability::CAN_EDIT, PhabricatorPolicyCapability::CAN_EDIT,
)) ))
->executeOne(); ->executeOne();
if (!$status) { if (!$event) {
return new Aphront404Response(); return new Aphront404Response();
} }
$end_time->setValue($status->getDateTo()); $end_time->setValue($event->getDateTo());
$start_time->setValue($status->getDateFrom()); $start_time->setValue($event->getDateFrom());
$submit_label = pht('Update'); $submit_label = pht('Update');
$filter = 'event/edit/'.$status->getID().'/'; $filter = 'event/edit/'.$event->getID().'/';
$page_title = pht('Update Event'); $page_title = pht('Update Event');
$redirect = 'updated'; $redirect = 'updated';
} }
$errors = array(); $errors = array();
if ($request->isFormPost()) { if ($request->isFormPost()) {
$xactions = array(); $xactions = array();
$type = $request->getInt('status'); $name = $request->getStr('name');
$type = $request->getInt('status');
$start_value = $start_time->readValueFromRequest($request); $start_value = $start_time->readValueFromRequest($request);
$end_value = $end_time->readValueFromRequest($request); $end_value = $end_time->readValueFromRequest($request);
$description = $request->getStr('description'); $description = $request->getStr('description');
if ($start_time->getError()) { if ($start_time->getError()) {
@ -74,6 +78,11 @@ final class PhabricatorCalendarEventEditController
$errors[] = pht('Invalid end time; reset to default.'); $errors[] = pht('Invalid end time; reset to default.');
} }
if (!$errors) { if (!$errors) {
$xactions[] = id(new PhabricatorCalendarEventTransaction())
->setTransactionType(
PhabricatorCalendarEventTransaction::TYPE_NAME)
->setNewValue($name);
$xactions[] = id(new PhabricatorCalendarEventTransaction()) $xactions[] = id(new PhabricatorCalendarEventTransaction())
->setTransactionType( ->setTransactionType(
PhabricatorCalendarEventTransaction::TYPE_START_DATE) PhabricatorCalendarEventTransaction::TYPE_START_DATE)
@ -99,8 +108,15 @@ final class PhabricatorCalendarEventEditController
->setContentSourceFromRequest($request) ->setContentSourceFromRequest($request)
->setContinueOnNoEffect(true); ->setContinueOnNoEffect(true);
$xactions = $editor->applyTransactions($status, $xactions); try {
return id(new AphrontRedirectResponse())->setURI('/E'.$status->getID()); $xactions = $editor->applyTransactions($event, $xactions);
$response = id(new AphrontRedirectResponse());
return $response->setURI('/E'.$event->getID());
} catch (PhabricatorApplicationTransactionValidationException $ex) {
$validation_exception = $ex;
$error_name = $ex
->getShortMessage(PhabricatorCalendarEventTransaction::TYPE_NAME);
}
} }
} }
@ -111,85 +127,66 @@ final class PhabricatorCalendarEventEditController
->setErrors($errors); ->setErrors($errors);
} }
$name = id(new AphrontFormTextControl())
->setLabel(pht('Name'))
->setName('name')
->setValue($event->getName())
->setError($error_name);
$status_select = id(new AphrontFormSelectControl()) $status_select = id(new AphrontFormSelectControl())
->setLabel(pht('Status')) ->setLabel(pht('Status'))
->setName('status') ->setName('status')
->setValue($status->getStatus()) ->setValue($event->getStatus())
->setOptions($status->getStatusOptions()); ->setOptions($event->getStatusOptions());
$description = id(new AphrontFormTextAreaControl()) $description = id(new AphrontFormTextAreaControl())
->setLabel(pht('Description')) ->setLabel(pht('Description'))
->setName('description') ->setName('description')
->setValue($status->getDescription()); ->setValue($event->getDescription());
if ($request->isAjax()) { $form = id(new AphrontFormView())
$dialog = id(new AphrontDialogView()) ->setUser($user)
->setUser($user) ->appendChild($name)
->setTitle($page_title)
->setWidth(AphrontDialogView::WIDTH_FORM);
if ($this->isCreate()) {
$dialog->setSubmitURI($this->getApplicationURI('event/create/'));
} else {
$dialog->setSubmitURI(
$this->getApplicationURI('event/edit/'.$status->getID().'/'));
}
$form = new PHUIFormLayoutView();
if ($error_view) {
$form->appendChild($error_view);
}
} else {
$form = id(new AphrontFormView())
->setUser($user);
}
$form
->appendChild($status_select) ->appendChild($status_select)
->appendChild($start_time) ->appendChild($start_time)
->appendChild($end_time) ->appendChild($end_time)
->appendChild($description); ->appendChild($description);
if ($request->isAjax()) { $submit = id(new AphrontFormSubmitControl())
$dialog->addSubmitButton($submit_label); ->setValue($submit_label);
$submit = $dialog;
} else {
$submit = id(new AphrontFormSubmitControl())
->setValue($submit_label);
}
if ($this->isCreate()) { if ($this->isCreate()) {
$submit->addCancelButton($this->getApplicationURI()); $submit->addCancelButton($this->getApplicationURI());
} else { } else {
$submit->addCancelButton('/E'.$status->getID()); $submit->addCancelButton('/E'.$event->getID());
} }
if ($request->isAjax()) {
$dialog->appendChild($form);
return id(new AphrontDialogResponse())
->setDialog($dialog);
}
$form->appendChild($submit); $form->appendChild($submit);
$form_box = id(new PHUIObjectBoxView()) $form_box = id(new PHUIObjectBoxView())
->setHeaderText($page_title) ->setHeaderText($page_title)
->setFormErrors($errors) ->setFormErrors($errors)
->setForm($form); ->setForm($form);
$nav = $this->buildSideNavView($status); $nav = $this->buildSideNavView($event);
$nav->selectFilter($filter); $nav->selectFilter($filter);
$crumbs = $this->buildApplicationCrumbs(); $crumbs = $this->buildApplicationCrumbs();
if (!$this->isCreate()) { if (!$this->isCreate()) {
$crumbs->addTextCrumb('E'.$status->getId(), '/E'.$status->getId()); $crumbs->addTextCrumb('E'.$event->getId(), '/E'.$event->getId());
} }
$crumbs->addTextCrumb($page_title); $crumbs->addTextCrumb($page_title);
$object_box = id(new PHUIObjectBoxView())
->setHeaderText($page_title)
->setValidationException($validation_exception)
->appendChild($form);
$nav->appendChild( $nav->appendChild(
array( array(
$crumbs, $crumbs,
$form_box, $object_box,
)); ));
return $this->buildApplicationPage( return $this->buildApplicationPage(

View file

@ -26,6 +26,7 @@ final class PhabricatorCalendarEventViewController
} }
$title = 'E'.$event->getID(); $title = 'E'.$event->getID();
$page_title = $title.' '.$event->getName();
$crumbs = $this->buildApplicationCrumbs(); $crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb($title, '/E'.$event->getID()); $crumbs->addTextCrumb($title, '/E'.$event->getID());
@ -49,7 +50,7 @@ final class PhabricatorCalendarEventViewController
$timeline, $timeline,
), ),
array( array(
'title' => $title, 'title' => $page_title,
)); ));
} }
@ -58,7 +59,7 @@ final class PhabricatorCalendarEventViewController
return id(new PHUIHeaderView()) return id(new PHUIHeaderView())
->setUser($viewer) ->setUser($viewer)
->setHeader($event->getTerseSummary($viewer)) ->setHeader($event->getName())
->setPolicyObject($event); ->setPolicyObject($event);
} }
@ -101,6 +102,10 @@ final class PhabricatorCalendarEventViewController
->setUser($viewer) ->setUser($viewer)
->setObject($event); ->setObject($event);
// $properties->addProperty(
// pht('Name'),
// $event->getName());
$properties->addProperty( $properties->addProperty(
pht('Starts'), pht('Starts'),
phabricator_datetime($event->getDateFrom(), $viewer)); phabricator_datetime($event->getDateFrom(), $viewer));

View file

@ -14,6 +14,7 @@ final class PhabricatorCalendarEventEditor
public function getTransactionTypes() { public function getTransactionTypes() {
$types = parent::getTransactionTypes(); $types = parent::getTransactionTypes();
$types[] = PhabricatorCalendarEventTransaction::TYPE_NAME;
$types[] = PhabricatorCalendarEventTransaction::TYPE_START_DATE; $types[] = PhabricatorCalendarEventTransaction::TYPE_START_DATE;
$types[] = PhabricatorCalendarEventTransaction::TYPE_END_DATE; $types[] = PhabricatorCalendarEventTransaction::TYPE_END_DATE;
$types[] = PhabricatorCalendarEventTransaction::TYPE_STATUS; $types[] = PhabricatorCalendarEventTransaction::TYPE_STATUS;
@ -29,6 +30,8 @@ final class PhabricatorCalendarEventEditor
PhabricatorLiskDAO $object, PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) { PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) { switch ($xaction->getTransactionType()) {
case PhabricatorCalendarEventTransaction::TYPE_NAME:
return $object->getName();
case PhabricatorCalendarEventTransaction::TYPE_START_DATE: case PhabricatorCalendarEventTransaction::TYPE_START_DATE:
return $object->getDateFrom(); return $object->getDateFrom();
case PhabricatorCalendarEventTransaction::TYPE_END_DATE: case PhabricatorCalendarEventTransaction::TYPE_END_DATE:
@ -51,6 +54,7 @@ final class PhabricatorCalendarEventEditor
PhabricatorApplicationTransaction $xaction) { PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) { switch ($xaction->getTransactionType()) {
case PhabricatorCalendarEventTransaction::TYPE_NAME:
case PhabricatorCalendarEventTransaction::TYPE_START_DATE: case PhabricatorCalendarEventTransaction::TYPE_START_DATE:
case PhabricatorCalendarEventTransaction::TYPE_END_DATE: case PhabricatorCalendarEventTransaction::TYPE_END_DATE:
case PhabricatorCalendarEventTransaction::TYPE_DESCRIPTION: case PhabricatorCalendarEventTransaction::TYPE_DESCRIPTION:
@ -67,6 +71,9 @@ final class PhabricatorCalendarEventEditor
PhabricatorApplicationTransaction $xaction) { PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) { switch ($xaction->getTransactionType()) {
case PhabricatorCalendarEventTransaction::TYPE_NAME:
$object->setName($xaction->getNewValue());
return;
case PhabricatorCalendarEventTransaction::TYPE_START_DATE: case PhabricatorCalendarEventTransaction::TYPE_START_DATE:
$object->setDateFrom($xaction->getNewValue()); $object->setDateFrom($xaction->getNewValue());
return; return;
@ -93,6 +100,7 @@ final class PhabricatorCalendarEventEditor
PhabricatorApplicationTransaction $xaction) { PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) { switch ($xaction->getTransactionType()) {
case PhabricatorCalendarEventTransaction::TYPE_NAME:
case PhabricatorCalendarEventTransaction::TYPE_START_DATE: case PhabricatorCalendarEventTransaction::TYPE_START_DATE:
case PhabricatorCalendarEventTransaction::TYPE_END_DATE: case PhabricatorCalendarEventTransaction::TYPE_END_DATE:
case PhabricatorCalendarEventTransaction::TYPE_STATUS: case PhabricatorCalendarEventTransaction::TYPE_STATUS:
@ -105,4 +113,33 @@ final class PhabricatorCalendarEventEditor
return parent::applyCustomExternalTransaction($object, $xaction); return parent::applyCustomExternalTransaction($object, $xaction);
} }
protected function validateTransaction(
PhabricatorLiskDAO $object,
$type,
array $xactions) {
$errors = parent::validateTransaction($object, $type, $xactions);
switch ($type) {
case PhabricatorCalendarEventTransaction::TYPE_NAME:
$missing = $this->validateIsEmptyTextField(
$object->getName(),
$xactions);
if ($missing) {
$error = new PhabricatorApplicationTransactionValidationError(
$type,
pht('Required'),
pht('Event name is required.'),
nonempty(last($xactions), null));
$error->setIsMissingFieldError(true);
$errors[] = $error;
}
break;
}
return $errors;
}
} }

View file

@ -5,6 +5,7 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
PhabricatorMarkupInterface, PhabricatorMarkupInterface,
PhabricatorApplicationTransactionInterface { PhabricatorApplicationTransactionInterface {
protected $name;
protected $userPHID; protected $userPHID;
protected $dateFrom; protected $dateFrom;
protected $dateTo; protected $dateTo;
@ -49,6 +50,7 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
return array( return array(
self::CONFIG_AUX_PHID => true, self::CONFIG_AUX_PHID => true,
self::CONFIG_COLUMN_SCHEMA => array( self::CONFIG_COLUMN_SCHEMA => array(
'name' => 'text',
'dateFrom' => 'epoch', 'dateFrom' => 'epoch',
'dateTo' => 'epoch', 'dateTo' => 'epoch',
'status' => 'uint32', 'status' => 'uint32',

View file

@ -3,6 +3,7 @@
final class PhabricatorCalendarEventTransaction final class PhabricatorCalendarEventTransaction
extends PhabricatorApplicationTransaction { extends PhabricatorApplicationTransaction {
const TYPE_NAME = 'calendar.name';
const TYPE_START_DATE = 'calendar.startdate'; const TYPE_START_DATE = 'calendar.startdate';
const TYPE_END_DATE = 'calendar.enddate'; const TYPE_END_DATE = 'calendar.enddate';
const TYPE_STATUS = 'calendar.status'; const TYPE_STATUS = 'calendar.status';
@ -27,6 +28,7 @@ final class PhabricatorCalendarEventTransaction
$phids = parent::getRequiredHandlePHIDs(); $phids = parent::getRequiredHandlePHIDs();
switch ($this->getTransactionType()) { switch ($this->getTransactionType()) {
case self::TYPE_NAME:
case self::TYPE_START_DATE: case self::TYPE_START_DATE:
case self::TYPE_END_DATE: case self::TYPE_END_DATE:
case self::TYPE_STATUS: case self::TYPE_STATUS:
@ -41,6 +43,7 @@ final class PhabricatorCalendarEventTransaction
public function shouldHide() { public function shouldHide() {
$old = $this->getOldValue(); $old = $this->getOldValue();
switch ($this->getTransactionType()) { switch ($this->getTransactionType()) {
case self::TYPE_NAME:
case self::TYPE_START_DATE: case self::TYPE_START_DATE:
case self::TYPE_END_DATE: case self::TYPE_END_DATE:
case self::TYPE_STATUS: case self::TYPE_STATUS:
@ -52,6 +55,7 @@ final class PhabricatorCalendarEventTransaction
public function getIcon() { public function getIcon() {
switch ($this->getTransactionType()) { switch ($this->getTransactionType()) {
case self::TYPE_NAME:
case self::TYPE_START_DATE: case self::TYPE_START_DATE:
case self::TYPE_END_DATE: case self::TYPE_END_DATE:
case self::TYPE_STATUS: case self::TYPE_STATUS:
@ -71,6 +75,15 @@ final class PhabricatorCalendarEventTransaction
$type = $this->getTransactionType(); $type = $this->getTransactionType();
switch ($type) { switch ($type) {
case self::TYPE_NAME:
if ($old) {
return pht(
'%s changed the name of this event from %s to %s.',
$this->renderHandleLink($author_phid),
$old,
$new);
}
break;
case self::TYPE_START_DATE: case self::TYPE_START_DATE:
if ($old) { if ($old) {
return pht( return pht(
@ -113,6 +126,16 @@ final class PhabricatorCalendarEventTransaction
$type = $this->getTransactionType(); $type = $this->getTransactionType();
switch ($type) { switch ($type) {
case self::TYPE_NAME:
if ($old) {
return pht(
'%s changed the name of %s from %s to %s.',
$this->renderHandleLink($author_phid),
$this->renderHandleLink($object_phid),
$old,
$new);
}
break;
case self::TYPE_START_DATE: case self::TYPE_START_DATE:
if ($old) { if ($old) {
return pht( return pht(
@ -153,6 +176,7 @@ final class PhabricatorCalendarEventTransaction
$new = $this->getNewValue(); $new = $this->getNewValue();
switch ($this->getTransactionType()) { switch ($this->getTransactionType()) {
case self::TYPE_NAME:
case self::TYPE_START_DATE: case self::TYPE_START_DATE:
case self::TYPE_END_DATE: case self::TYPE_END_DATE:
case self::TYPE_STATUS: case self::TYPE_STATUS:
@ -191,6 +215,9 @@ final class PhabricatorCalendarEventTransaction
public function getMailTags() { public function getMailTags() {
$tags = array(); $tags = array();
switch ($this->getTransactionType()) { switch ($this->getTransactionType()) {
case self::TYPE_NAME:
$tags[] = self::MAILTAG_CONTENT;
break;
case self::TYPE_START_DATE: case self::TYPE_START_DATE:
$tags[] = self::MAILTAG_CONTENT; $tags[] = self::MAILTAG_CONTENT;
break; break;