2011-01-25 22:26:09 +01:00
|
|
|
<?php
|
|
|
|
|
2012-03-10 00:46:25 +01:00
|
|
|
final class DifferentialRevisionEditController extends DifferentialController {
|
2011-01-25 22:26:09 +01:00
|
|
|
|
|
|
|
private $id;
|
|
|
|
|
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
$this->id = idx($data, 'id');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
2011-02-04 00:41:58 +01:00
|
|
|
$request = $this->getRequest();
|
2013-07-01 21:38:42 +02:00
|
|
|
$viewer = $request->getUser();
|
2011-02-04 00:41:58 +01:00
|
|
|
|
|
|
|
if (!$this->id) {
|
|
|
|
$this->id = $request->getInt('revisionID');
|
|
|
|
}
|
|
|
|
|
2011-01-25 22:26:09 +01:00
|
|
|
if ($this->id) {
|
2013-07-01 21:38:42 +02:00
|
|
|
$revision = id(new DifferentialRevisionQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withIDs(array($this->id))
|
2013-07-16 01:01:31 +02:00
|
|
|
->needRelationships(true)
|
|
|
|
->needReviewerStatus(true)
|
2013-07-01 21:38:42 +02:00
|
|
|
->executeOne();
|
2011-01-25 22:26:09 +01:00
|
|
|
if (!$revision) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$revision = new DifferentialRevision();
|
2013-07-16 01:01:31 +02:00
|
|
|
$revision->attachRelationships(array());
|
2011-01-25 22:26:09 +01:00
|
|
|
}
|
|
|
|
|
2011-08-10 22:46:01 +02:00
|
|
|
$aux_fields = $this->loadAuxiliaryFields($revision);
|
|
|
|
|
2011-01-26 02:17:19 +01:00
|
|
|
$diff_id = $request->getInt('diffID');
|
|
|
|
if ($diff_id) {
|
2013-07-01 21:38:42 +02:00
|
|
|
$diff = id(new DifferentialDiffQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withIDs(array($diff_id))
|
|
|
|
->executeOne();
|
2011-01-26 02:17:19 +01:00
|
|
|
if (!$diff) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
if ($diff->getRevisionID()) {
|
|
|
|
// TODO: Redirect?
|
|
|
|
throw new Exception("This diff is already attached to a revision!");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$diff = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$errors = array();
|
2011-02-03 04:38:43 +01:00
|
|
|
|
2011-01-25 22:26:09 +01:00
|
|
|
|
2011-02-03 04:38:43 +01:00
|
|
|
if ($request->isFormPost() && !$request->getStr('viaDiffView')) {
|
2011-08-10 22:46:01 +02:00
|
|
|
foreach ($aux_fields as $aux_field) {
|
|
|
|
$aux_field->setValueFromRequest($request);
|
|
|
|
try {
|
|
|
|
$aux_field->validateField();
|
|
|
|
} catch (DifferentialFieldValidationException $ex) {
|
|
|
|
$errors[] = $ex->getMessage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-25 22:26:09 +01:00
|
|
|
if (!$errors) {
|
2013-05-24 15:38:54 +02:00
|
|
|
$is_new = !$revision->getID();
|
|
|
|
$user = $request->getUser();
|
|
|
|
|
2012-10-10 19:18:23 +02:00
|
|
|
$editor = new DifferentialRevisionEditor($revision);
|
|
|
|
$editor->setActor($request->getUser());
|
2011-01-26 02:17:19 +01:00
|
|
|
if ($diff) {
|
|
|
|
$editor->addDiff($diff, $request->getStr('comments'));
|
|
|
|
}
|
2011-08-10 22:46:01 +02:00
|
|
|
$editor->setAuxiliaryFields($aux_fields);
|
2013-09-16 17:04:14 +02:00
|
|
|
$editor->setAphrontRequestForEventDispatch($request);
|
2011-01-26 02:17:19 +01:00
|
|
|
$editor->save();
|
|
|
|
|
2011-01-30 22:20:56 +01:00
|
|
|
return id(new AphrontRedirectResponse())
|
2011-01-26 02:17:19 +01:00
|
|
|
->setURI('/D'.$revision->getID());
|
2011-01-25 22:26:09 +01:00
|
|
|
}
|
|
|
|
}
|
2011-02-03 04:38:43 +01:00
|
|
|
|
2011-08-14 23:28:08 +02:00
|
|
|
$aux_phids = array();
|
|
|
|
foreach ($aux_fields as $key => $aux_field) {
|
|
|
|
$aux_phids[$key] = $aux_field->getRequiredHandlePHIDsForRevisionEdit();
|
|
|
|
}
|
|
|
|
$phids = array_mergev($aux_phids);
|
2011-02-03 02:38:03 +01:00
|
|
|
$phids = array_unique($phids);
|
2012-09-05 04:02:56 +02:00
|
|
|
$handles = $this->loadViewerHandles($phids);
|
2011-08-14 23:28:08 +02:00
|
|
|
foreach ($aux_fields as $key => $aux_field) {
|
|
|
|
$aux_field->setHandles(array_select_keys($handles, $aux_phids[$key]));
|
|
|
|
}
|
2011-01-25 22:26:09 +01:00
|
|
|
|
|
|
|
$form = new AphrontFormView();
|
2011-01-31 03:52:29 +01:00
|
|
|
$form->setUser($request->getUser());
|
2011-01-26 02:17:19 +01:00
|
|
|
if ($diff) {
|
|
|
|
$form->addHiddenInput('diffID', $diff->getID());
|
|
|
|
}
|
|
|
|
|
2011-01-25 22:26:09 +01:00
|
|
|
if ($revision->getID()) {
|
2011-01-25 22:48:05 +01:00
|
|
|
$form->setAction('/differential/revision/edit/'.$revision->getID().'/');
|
2011-01-25 22:26:09 +01:00
|
|
|
} else {
|
|
|
|
$form->setAction('/differential/revision/edit/');
|
|
|
|
}
|
|
|
|
|
2011-01-26 02:17:19 +01:00
|
|
|
$error_view = null;
|
|
|
|
if ($errors) {
|
|
|
|
$error_view = id(new AphrontErrorView())
|
2013-01-24 19:46:47 +01:00
|
|
|
->setTitle(pht('Form Errors'))
|
2011-01-26 02:17:19 +01:00
|
|
|
->setErrors($errors);
|
|
|
|
}
|
2011-01-25 22:48:05 +01:00
|
|
|
|
2011-02-05 02:53:14 +01:00
|
|
|
if ($diff && $revision->getID()) {
|
|
|
|
$form
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextAreaControl())
|
2013-01-24 19:46:47 +01:00
|
|
|
->setLabel(pht('Comments'))
|
2011-02-05 02:53:14 +01:00
|
|
|
->setName('comments')
|
2013-01-24 19:46:47 +01:00
|
|
|
->setCaption(pht("Explain what's new in this diff."))
|
2011-02-05 02:53:14 +01:00
|
|
|
->setValue($request->getStr('comments')))
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormSubmitControl())
|
2013-01-24 19:46:47 +01:00
|
|
|
->setValue(pht('Save')))
|
2011-02-05 02:53:14 +01:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormDividerControl()));
|
|
|
|
}
|
|
|
|
|
2013-08-05 19:46:39 +02:00
|
|
|
$preview = array();
|
2011-08-10 22:46:01 +02:00
|
|
|
foreach ($aux_fields as $aux_field) {
|
|
|
|
$control = $aux_field->renderEditControl();
|
|
|
|
if ($control) {
|
|
|
|
$form->appendChild($control);
|
|
|
|
}
|
2013-08-05 19:46:39 +02:00
|
|
|
$preview[] = $aux_field->renderEditPreview();
|
2011-08-10 22:46:01 +02:00
|
|
|
}
|
2011-01-26 02:17:19 +01:00
|
|
|
|
|
|
|
$submit = id(new AphrontFormSubmitControl())
|
|
|
|
->setValue('Save');
|
|
|
|
if ($diff) {
|
|
|
|
$submit->addCancelButton('/differential/diff/'.$diff->getID().'/');
|
|
|
|
} else {
|
|
|
|
$submit->addCancelButton('/D'.$revision->getID());
|
|
|
|
}
|
|
|
|
|
|
|
|
$form->appendChild($submit);
|
2011-01-25 22:26:09 +01:00
|
|
|
|
Update form styles, implement in many places
Summary:
This creates a common form look and feel across the site. I spent a bit of time working out a number of kinks in our various renderings. Some things:
- Font Styles are correctly applied for form elements now.
- Everything lines up!
- Selects are larger, easier to read, interact.
- Inputs have been squared.
- Consistant CSS applied glow (try it!)
- Improved Mobile Responsiveness
- CSS applied to all form elements, not just Aphront
- Many other minor tweaks.
I tried to hit as many high profile forms as possible in an effort to increase consistency. Stopped for now and will follow up after this lands. I know Evan is not a super fan of the glow, but after working with it for a week, it's way cleaner and responsive than the OS controls. Give it a try.
Test Plan: Tested many applications, forms, mobile and tablet.
Reviewers: epriestley, btrahan
Reviewed By: epriestley
CC: aran, Korvin
Differential Revision: https://secure.phabricator.com/D5860
2013-05-07 23:07:06 +02:00
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
2011-01-25 22:26:09 +01:00
|
|
|
if ($revision->getID()) {
|
2011-02-05 02:53:14 +01:00
|
|
|
if ($diff) {
|
Update form styles, implement in many places
Summary:
This creates a common form look and feel across the site. I spent a bit of time working out a number of kinks in our various renderings. Some things:
- Font Styles are correctly applied for form elements now.
- Everything lines up!
- Selects are larger, easier to read, interact.
- Inputs have been squared.
- Consistant CSS applied glow (try it!)
- Improved Mobile Responsiveness
- CSS applied to all form elements, not just Aphront
- Many other minor tweaks.
I tried to hit as many high profile forms as possible in an effort to increase consistency. Stopped for now and will follow up after this lands. I know Evan is not a super fan of the glow, but after working with it for a week, it's way cleaner and responsive than the OS controls. Give it a try.
Test Plan: Tested many applications, forms, mobile and tablet.
Reviewers: epriestley, btrahan
Reviewed By: epriestley
CC: aran, Korvin
Differential Revision: https://secure.phabricator.com/D5860
2013-05-07 23:07:06 +02:00
|
|
|
$title = pht('Update Differential Revision');
|
|
|
|
$crumbs->addCrumb(
|
|
|
|
id(new PhabricatorCrumbView())
|
|
|
|
->setName('D'.$revision->getID())
|
|
|
|
->setHref('/differential/diff/'.$diff->getID().'/'));
|
2011-02-05 02:53:14 +01:00
|
|
|
} else {
|
Update form styles, implement in many places
Summary:
This creates a common form look and feel across the site. I spent a bit of time working out a number of kinks in our various renderings. Some things:
- Font Styles are correctly applied for form elements now.
- Everything lines up!
- Selects are larger, easier to read, interact.
- Inputs have been squared.
- Consistant CSS applied glow (try it!)
- Improved Mobile Responsiveness
- CSS applied to all form elements, not just Aphront
- Many other minor tweaks.
I tried to hit as many high profile forms as possible in an effort to increase consistency. Stopped for now and will follow up after this lands. I know Evan is not a super fan of the glow, but after working with it for a week, it's way cleaner and responsive than the OS controls. Give it a try.
Test Plan: Tested many applications, forms, mobile and tablet.
Reviewers: epriestley, btrahan
Reviewed By: epriestley
CC: aran, Korvin
Differential Revision: https://secure.phabricator.com/D5860
2013-05-07 23:07:06 +02:00
|
|
|
$title = pht('Edit Differential Revision');
|
|
|
|
$crumbs->addCrumb(
|
|
|
|
id(new PhabricatorCrumbView())
|
|
|
|
->setName('D'.$revision->getID())
|
|
|
|
->setHref('/D'.$revision->getID()));
|
2011-02-05 02:53:14 +01:00
|
|
|
}
|
2011-01-25 22:26:09 +01:00
|
|
|
} else {
|
Update form styles, implement in many places
Summary:
This creates a common form look and feel across the site. I spent a bit of time working out a number of kinks in our various renderings. Some things:
- Font Styles are correctly applied for form elements now.
- Everything lines up!
- Selects are larger, easier to read, interact.
- Inputs have been squared.
- Consistant CSS applied glow (try it!)
- Improved Mobile Responsiveness
- CSS applied to all form elements, not just Aphront
- Many other minor tweaks.
I tried to hit as many high profile forms as possible in an effort to increase consistency. Stopped for now and will follow up after this lands. I know Evan is not a super fan of the glow, but after working with it for a week, it's way cleaner and responsive than the OS controls. Give it a try.
Test Plan: Tested many applications, forms, mobile and tablet.
Reviewers: epriestley, btrahan
Reviewed By: epriestley
CC: aran, Korvin
Differential Revision: https://secure.phabricator.com/D5860
2013-05-07 23:07:06 +02:00
|
|
|
$title = pht('Create New Differential Revision');
|
2011-01-25 22:26:09 +01:00
|
|
|
}
|
|
|
|
|
2013-09-25 20:23:29 +02:00
|
|
|
$form_box = id(new PHUIObjectBoxView())
|
2013-08-27 00:45:58 +02:00
|
|
|
->setHeaderText($title)
|
|
|
|
->setFormError($error_view)
|
|
|
|
->setForm($form);
|
|
|
|
|
Update form styles, implement in many places
Summary:
This creates a common form look and feel across the site. I spent a bit of time working out a number of kinks in our various renderings. Some things:
- Font Styles are correctly applied for form elements now.
- Everything lines up!
- Selects are larger, easier to read, interact.
- Inputs have been squared.
- Consistant CSS applied glow (try it!)
- Improved Mobile Responsiveness
- CSS applied to all form elements, not just Aphront
- Many other minor tweaks.
I tried to hit as many high profile forms as possible in an effort to increase consistency. Stopped for now and will follow up after this lands. I know Evan is not a super fan of the glow, but after working with it for a week, it's way cleaner and responsive than the OS controls. Give it a try.
Test Plan: Tested many applications, forms, mobile and tablet.
Reviewers: epriestley, btrahan
Reviewed By: epriestley
CC: aran, Korvin
Differential Revision: https://secure.phabricator.com/D5860
2013-05-07 23:07:06 +02:00
|
|
|
$crumbs->addCrumb(
|
|
|
|
id(new PhabricatorCrumbView())
|
2013-08-05 19:46:39 +02:00
|
|
|
->setName($title));
|
2011-01-25 22:26:09 +01:00
|
|
|
|
Update form styles, implement in many places
Summary:
This creates a common form look and feel across the site. I spent a bit of time working out a number of kinks in our various renderings. Some things:
- Font Styles are correctly applied for form elements now.
- Everything lines up!
- Selects are larger, easier to read, interact.
- Inputs have been squared.
- Consistant CSS applied glow (try it!)
- Improved Mobile Responsiveness
- CSS applied to all form elements, not just Aphront
- Many other minor tweaks.
I tried to hit as many high profile forms as possible in an effort to increase consistency. Stopped for now and will follow up after this lands. I know Evan is not a super fan of the glow, but after working with it for a week, it's way cleaner and responsive than the OS controls. Give it a try.
Test Plan: Tested many applications, forms, mobile and tablet.
Reviewers: epriestley, btrahan
Reviewed By: epriestley
CC: aran, Korvin
Differential Revision: https://secure.phabricator.com/D5860
2013-05-07 23:07:06 +02:00
|
|
|
return $this->buildApplicationPage(
|
2011-01-25 22:26:09 +01:00
|
|
|
array(
|
Update form styles, implement in many places
Summary:
This creates a common form look and feel across the site. I spent a bit of time working out a number of kinks in our various renderings. Some things:
- Font Styles are correctly applied for form elements now.
- Everything lines up!
- Selects are larger, easier to read, interact.
- Inputs have been squared.
- Consistant CSS applied glow (try it!)
- Improved Mobile Responsiveness
- CSS applied to all form elements, not just Aphront
- Many other minor tweaks.
I tried to hit as many high profile forms as possible in an effort to increase consistency. Stopped for now and will follow up after this lands. I know Evan is not a super fan of the glow, but after working with it for a week, it's way cleaner and responsive than the OS controls. Give it a try.
Test Plan: Tested many applications, forms, mobile and tablet.
Reviewers: epriestley, btrahan
Reviewed By: epriestley
CC: aran, Korvin
Differential Revision: https://secure.phabricator.com/D5860
2013-05-07 23:07:06 +02:00
|
|
|
$crumbs,
|
2013-08-27 00:45:58 +02:00
|
|
|
$form_box,
|
2013-08-05 19:46:39 +02:00
|
|
|
$preview),
|
Update form styles, implement in many places
Summary:
This creates a common form look and feel across the site. I spent a bit of time working out a number of kinks in our various renderings. Some things:
- Font Styles are correctly applied for form elements now.
- Everything lines up!
- Selects are larger, easier to read, interact.
- Inputs have been squared.
- Consistant CSS applied glow (try it!)
- Improved Mobile Responsiveness
- CSS applied to all form elements, not just Aphront
- Many other minor tweaks.
I tried to hit as many high profile forms as possible in an effort to increase consistency. Stopped for now and will follow up after this lands. I know Evan is not a super fan of the glow, but after working with it for a week, it's way cleaner and responsive than the OS controls. Give it a try.
Test Plan: Tested many applications, forms, mobile and tablet.
Reviewers: epriestley, btrahan
Reviewed By: epriestley
CC: aran, Korvin
Differential Revision: https://secure.phabricator.com/D5860
2013-05-07 23:07:06 +02:00
|
|
|
array(
|
|
|
|
'title' => $title,
|
|
|
|
'device' => true,
|
2011-01-25 22:26:09 +01:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2011-08-10 22:46:01 +02:00
|
|
|
private function loadAuxiliaryFields(DifferentialRevision $revision) {
|
|
|
|
|
2011-08-14 23:28:08 +02:00
|
|
|
$user = $this->getRequest()->getUser();
|
|
|
|
|
2011-08-10 22:46:01 +02:00
|
|
|
$aux_fields = DifferentialFieldSelector::newSelector()
|
|
|
|
->getFieldSpecifications();
|
|
|
|
foreach ($aux_fields as $key => $aux_field) {
|
2011-08-14 23:28:08 +02:00
|
|
|
$aux_field->setRevision($revision);
|
2011-08-10 22:46:01 +02:00
|
|
|
if (!$aux_field->shouldAppearOnEdit()) {
|
|
|
|
unset($aux_fields[$key]);
|
2011-08-14 23:28:08 +02:00
|
|
|
} else {
|
|
|
|
$aux_field->setUser($user);
|
2011-08-10 22:46:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return DifferentialAuxiliaryField::loadFromStorage(
|
|
|
|
$revision,
|
|
|
|
$aux_fields);
|
|
|
|
}
|
|
|
|
|
2011-01-25 22:26:09 +01:00
|
|
|
}
|