1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-18 19:40:55 +01:00

Allow form configurations to retitle and reorder forms and add preambles

Summary:
Ref T9132. This just makes edited forms do //something//, albeit not anything very useful yet.

You can now edit a form and:

  - Retitle it;
  - add a preamble (instructions on top of the form); and
  - reorder the form's fields.

Test Plan:
{F974632}

{F974633}

{F974634}

{F974635}

{F974636}

Reviewers: chad

Reviewed By: chad

Subscribers: hach-que

Maniphest Tasks: T9132

Differential Revision: https://secure.phabricator.com/D14503
This commit is contained in:
epriestley 2015-11-17 09:33:06 -08:00
parent d7212d855e
commit 9aee90f8c1
17 changed files with 408 additions and 34 deletions

View file

@ -419,6 +419,7 @@ return array(
'rsrc/js/application/repository/repository-crossreference.js' => 'e5339c43', 'rsrc/js/application/repository/repository-crossreference.js' => 'e5339c43',
'rsrc/js/application/search/behavior-reorder-queries.js' => 'e9581f08', 'rsrc/js/application/search/behavior-reorder-queries.js' => 'e9581f08',
'rsrc/js/application/slowvote/behavior-slowvote-embed.js' => '887ad43f', 'rsrc/js/application/slowvote/behavior-slowvote-embed.js' => '887ad43f',
'rsrc/js/application/transactions/behavior-reorder-fields.js' => 'b59e1e96',
'rsrc/js/application/transactions/behavior-show-older-transactions.js' => 'dbbf48b6', 'rsrc/js/application/transactions/behavior-show-older-transactions.js' => 'dbbf48b6',
'rsrc/js/application/transactions/behavior-transaction-comment-form.js' => 'b23b49e6', 'rsrc/js/application/transactions/behavior-transaction-comment-form.js' => 'b23b49e6',
'rsrc/js/application/transactions/behavior-transaction-list.js' => '13c739ea', 'rsrc/js/application/transactions/behavior-transaction-list.js' => '13c739ea',
@ -591,6 +592,7 @@ return array(
'javelin-behavior-doorkeeper-tag' => 'e5822781', 'javelin-behavior-doorkeeper-tag' => 'e5822781',
'javelin-behavior-drydock-live-operation-status' => '901935ef', 'javelin-behavior-drydock-live-operation-status' => '901935ef',
'javelin-behavior-durable-column' => 'c72aa091', 'javelin-behavior-durable-column' => 'c72aa091',
'javelin-behavior-editengine-reorder-fields' => 'b59e1e96',
'javelin-behavior-error-log' => '6882e80a', 'javelin-behavior-error-log' => '6882e80a',
'javelin-behavior-event-all-day' => '38dcf3c8', 'javelin-behavior-event-all-day' => '38dcf3c8',
'javelin-behavior-fancy-datepicker' => '8ae55229', 'javelin-behavior-fancy-datepicker' => '8ae55229',
@ -1714,6 +1716,13 @@ return array(
'javelin-typeahead-preloaded-source', 'javelin-typeahead-preloaded-source',
'javelin-util', 'javelin-util',
), ),
'b59e1e96' => array(
'javelin-behavior',
'javelin-stratcom',
'javelin-workflow',
'javelin-dom',
'phabricator-draggable-list',
),
'b5c256b8' => array( 'b5c256b8' => array(
'javelin-install', 'javelin-install',
'javelin-dom', 'javelin-dom',

View file

@ -2118,6 +2118,7 @@ phutil_register_library_map(array(
'PhabricatorEditEngineConfigurationListController' => 'applications/transactions/controller/PhabricatorEditEngineConfigurationListController.php', 'PhabricatorEditEngineConfigurationListController' => 'applications/transactions/controller/PhabricatorEditEngineConfigurationListController.php',
'PhabricatorEditEngineConfigurationPHIDType' => 'applications/transactions/phid/PhabricatorEditEngineConfigurationPHIDType.php', 'PhabricatorEditEngineConfigurationPHIDType' => 'applications/transactions/phid/PhabricatorEditEngineConfigurationPHIDType.php',
'PhabricatorEditEngineConfigurationQuery' => 'applications/transactions/query/PhabricatorEditEngineConfigurationQuery.php', 'PhabricatorEditEngineConfigurationQuery' => 'applications/transactions/query/PhabricatorEditEngineConfigurationQuery.php',
'PhabricatorEditEngineConfigurationReorderController' => 'applications/transactions/controller/PhabricatorEditEngineConfigurationReorderController.php',
'PhabricatorEditEngineConfigurationSaveController' => 'applications/transactions/controller/PhabricatorEditEngineConfigurationSaveController.php', 'PhabricatorEditEngineConfigurationSaveController' => 'applications/transactions/controller/PhabricatorEditEngineConfigurationSaveController.php',
'PhabricatorEditEngineConfigurationSearchEngine' => 'applications/transactions/query/PhabricatorEditEngineConfigurationSearchEngine.php', 'PhabricatorEditEngineConfigurationSearchEngine' => 'applications/transactions/query/PhabricatorEditEngineConfigurationSearchEngine.php',
'PhabricatorEditEngineConfigurationTransaction' => 'applications/transactions/storage/PhabricatorEditEngineConfigurationTransaction.php', 'PhabricatorEditEngineConfigurationTransaction' => 'applications/transactions/storage/PhabricatorEditEngineConfigurationTransaction.php',
@ -2810,6 +2811,7 @@ phutil_register_library_map(array(
'PhabricatorRemarkupCowsayBlockInterpreter' => 'infrastructure/markup/interpreter/PhabricatorRemarkupCowsayBlockInterpreter.php', 'PhabricatorRemarkupCowsayBlockInterpreter' => 'infrastructure/markup/interpreter/PhabricatorRemarkupCowsayBlockInterpreter.php',
'PhabricatorRemarkupCustomBlockRule' => 'infrastructure/markup/rule/PhabricatorRemarkupCustomBlockRule.php', 'PhabricatorRemarkupCustomBlockRule' => 'infrastructure/markup/rule/PhabricatorRemarkupCustomBlockRule.php',
'PhabricatorRemarkupCustomInlineRule' => 'infrastructure/markup/rule/PhabricatorRemarkupCustomInlineRule.php', 'PhabricatorRemarkupCustomInlineRule' => 'infrastructure/markup/rule/PhabricatorRemarkupCustomInlineRule.php',
'PhabricatorRemarkupEditField' => 'applications/transactions/editfield/PhabricatorRemarkupEditField.php',
'PhabricatorRemarkupFigletBlockInterpreter' => 'infrastructure/markup/interpreter/PhabricatorRemarkupFigletBlockInterpreter.php', 'PhabricatorRemarkupFigletBlockInterpreter' => 'infrastructure/markup/interpreter/PhabricatorRemarkupFigletBlockInterpreter.php',
'PhabricatorRemarkupUIExample' => 'applications/uiexample/examples/PhabricatorRemarkupUIExample.php', 'PhabricatorRemarkupUIExample' => 'applications/uiexample/examples/PhabricatorRemarkupUIExample.php',
'PhabricatorRepositoriesSetupCheck' => 'applications/config/check/PhabricatorRepositoriesSetupCheck.php', 'PhabricatorRepositoriesSetupCheck' => 'applications/config/check/PhabricatorRepositoriesSetupCheck.php',
@ -6209,6 +6211,7 @@ phutil_register_library_map(array(
'PhabricatorEditEngineConfigurationListController' => 'PhabricatorEditEngineController', 'PhabricatorEditEngineConfigurationListController' => 'PhabricatorEditEngineController',
'PhabricatorEditEngineConfigurationPHIDType' => 'PhabricatorPHIDType', 'PhabricatorEditEngineConfigurationPHIDType' => 'PhabricatorPHIDType',
'PhabricatorEditEngineConfigurationQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhabricatorEditEngineConfigurationQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhabricatorEditEngineConfigurationReorderController' => 'PhabricatorEditEngineController',
'PhabricatorEditEngineConfigurationSaveController' => 'PhabricatorEditEngineController', 'PhabricatorEditEngineConfigurationSaveController' => 'PhabricatorEditEngineController',
'PhabricatorEditEngineConfigurationSearchEngine' => 'PhabricatorApplicationSearchEngine', 'PhabricatorEditEngineConfigurationSearchEngine' => 'PhabricatorApplicationSearchEngine',
'PhabricatorEditEngineConfigurationTransaction' => 'PhabricatorApplicationTransaction', 'PhabricatorEditEngineConfigurationTransaction' => 'PhabricatorApplicationTransaction',
@ -7021,6 +7024,7 @@ phutil_register_library_map(array(
'PhabricatorRemarkupCowsayBlockInterpreter' => 'PhutilRemarkupBlockInterpreter', 'PhabricatorRemarkupCowsayBlockInterpreter' => 'PhutilRemarkupBlockInterpreter',
'PhabricatorRemarkupCustomBlockRule' => 'PhutilRemarkupBlockRule', 'PhabricatorRemarkupCustomBlockRule' => 'PhutilRemarkupBlockRule',
'PhabricatorRemarkupCustomInlineRule' => 'PhutilRemarkupRule', 'PhabricatorRemarkupCustomInlineRule' => 'PhutilRemarkupRule',
'PhabricatorRemarkupEditField' => 'PhabricatorEditField',
'PhabricatorRemarkupFigletBlockInterpreter' => 'PhutilRemarkupBlockInterpreter', 'PhabricatorRemarkupFigletBlockInterpreter' => 'PhutilRemarkupBlockInterpreter',
'PhabricatorRemarkupUIExample' => 'PhabricatorUIExample', 'PhabricatorRemarkupUIExample' => 'PhabricatorUIExample',
'PhabricatorRepositoriesSetupCheck' => 'PhabricatorSetupCheck', 'PhabricatorRepositoriesSetupCheck' => 'PhabricatorSetupCheck',

View file

@ -636,7 +636,15 @@ abstract class PhabricatorApplication
} }
protected function getEditRoutePattern($base = null) { protected function getEditRoutePattern($base = null) {
return $base.'(?:(?P<id>[0-9]\d*)/)?(?:(?P<editAction>parameters)/)?'; return $base.'(?:'.
'(?P<id>[0-9]\d*)/)?'.
'(?:'.
'(?:'.
'(?P<editAction>parameters)'.
'|'.
'(?:form/(?P<formKey>[^/]+))'.
')'.
'/)?';
} }
protected function getQueryRoutePattern($base = null) { protected function getQueryRoutePattern($base = null) {

View file

@ -45,6 +45,8 @@ final class PhabricatorTransactionsApplication extends PhabricatorApplication {
'PhabricatorEditEngineConfigurationViewController', 'PhabricatorEditEngineConfigurationViewController',
'save/(?P<key>[^/]+)/' => 'save/(?P<key>[^/]+)/' =>
'PhabricatorEditEngineConfigurationSaveController', 'PhabricatorEditEngineConfigurationSaveController',
'reorder/(?P<key>[^/]+)/' =>
'PhabricatorEditEngineConfigurationReorderController',
), ),
), ),
), ),

View file

@ -0,0 +1,123 @@
<?php
final class PhabricatorEditEngineConfigurationReorderController
extends PhabricatorEditEngineController {
public function handleRequest(AphrontRequest $request) {
$engine_key = $request->getURIData('engineKey');
$this->setEngineKey($engine_key);
$key = $request->getURIData('key');
$viewer = $this->getViewer();
$config = id(new PhabricatorEditEngineConfigurationQuery())
->setViewer($viewer)
->withEngineKeys(array($engine_key))
->withIdentifiers(array($key))
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->executeOne();
if (!$config) {
return id(new Aphront404Response());
}
$cancel_uri = "/transactions/editengine/{$engine_key}/view/{$key}/";
$reorder_uri = "/transactions/editengine/{$engine_key}/reorder/{$key}/";
if ($request->isFormPost()) {
$xactions = array();
$key_order = $request->getStrList('keyOrder');
$type_order = PhabricatorEditEngineConfigurationTransaction::TYPE_ORDER;
$xactions[] = id(new PhabricatorEditEngineConfigurationTransaction())
->setTransactionType($type_order)
->setNewValue($key_order);
$editor = id(new PhabricatorEditEngineConfigurationEditor())
->setActor($viewer)
->setContentSourceFromRequest($request)
->setContinueOnMissingFields(true)
->setContinueOnNoEffect(true);
$editor->applyTransactions($config, $xactions);
return id(new AphrontRedirectResponse())
->setURI($cancel_uri);
}
$engine = $config->getEngine();
$fields = $engine->getFieldsForConfig($config);
$list_id = celerity_generate_unique_node_id();
$input_id = celerity_generate_unique_node_id();
$list = id(new PHUIObjectItemListView())
->setUser($viewer)
->setID($list_id)
->setFlush(true);
$key_order = array();
foreach ($fields as $field) {
if (!$field->getIsReorderable()) {
continue;
}
$label = $field->getLabel();
$key = $field->getKey();
if ($label !== null) {
$header = $label;
} else {
$header = $key;
}
$item = id(new PHUIObjectItemView())
->setHeader($header)
->setGrippable(true)
->addSigil('editengine-form-field')
->setMetadata(
array(
'fieldKey' => $key,
));
$list->addItem($item);
$key_order[] = $key;
}
Javelin::initBehavior(
'editengine-reorder-fields',
array(
'listID' => $list_id,
'inputID' => $input_id,
'reorderURI' => $reorder_uri,
));
$note = id(new PHUIInfoView())
->appendChild(pht('Drag and drop fields to reorder them.'))
->setSeverity(PHUIInfoView::SEVERITY_NOTICE);
$input = phutil_tag(
'input',
array(
'type' => 'hidden',
'name' => 'keyOrder',
'value' => implode(', ', $key_order),
'id' => $input_id,
));
return $this->newDialog()
->setTitle(pht('Reorder Fields'))
->setWidth(AphrontDialogView::WIDTH_FORM)
->appendChild($note)
->appendChild($list)
->appendChild($input)
->addSubmitButton(pht('Save Changes'))
->addCancelButton($cancel_uri);
}
}

View file

@ -39,6 +39,8 @@ final class PhabricatorEditEngineConfigurationViewController
->setHeader($header) ->setHeader($header)
->addPropertyList($properties); ->addPropertyList($properties);
$field_list = $this->buildFieldList($config);
$crumbs = $this->buildApplicationCrumbs(); $crumbs = $this->buildApplicationCrumbs();
if ($is_concrete) { if ($is_concrete) {
@ -62,6 +64,7 @@ final class PhabricatorEditEngineConfigurationViewController
->appendChild( ->appendChild(
array( array(
$box, $box,
$field_list,
$timeline, $timeline,
)); ));
} }
@ -69,7 +72,8 @@ final class PhabricatorEditEngineConfigurationViewController
private function buildActionView( private function buildActionView(
PhabricatorEditEngineConfiguration $config) { PhabricatorEditEngineConfiguration $config) {
$viewer = $this->getViewer(); $viewer = $this->getViewer();
$engine_key = $this->getEngineKey(); $engine = $config->getEngine();
$engine_key = $engine->getEngineKey();
$can_edit = PhabricatorPolicyFilter::hasCapability( $can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer, $viewer,
@ -79,13 +83,13 @@ final class PhabricatorEditEngineConfigurationViewController
$view = id(new PhabricatorActionListView()) $view = id(new PhabricatorActionListView())
->setUser($viewer); ->setUser($viewer);
$key = $config->getIdentifier(); $form_key = $config->getIdentifier();
$base_uri = "/transactions/editengine/{$engine_key}"; $base_uri = "/transactions/editengine/{$engine_key}";
$is_concrete = (bool)$config->getID(); $is_concrete = (bool)$config->getID();
if (!$is_concrete) { if (!$is_concrete) {
$save_uri = "{$base_uri}/save/{$key}/"; $save_uri = "{$base_uri}/save/{$form_key}/";
$view->addAction( $view->addAction(
id(new PhabricatorActionView()) id(new PhabricatorActionView())
@ -97,7 +101,7 @@ final class PhabricatorEditEngineConfigurationViewController
$can_edit = false; $can_edit = false;
} else { } else {
$edit_uri = "{$base_uri}/edit/{$key}/"; $edit_uri = "{$base_uri}/edit/{$form_key}/";
$view->addAction( $view->addAction(
id(new PhabricatorActionView()) id(new PhabricatorActionView())
->setName(pht('Edit Form Configuration')) ->setName(pht('Edit Form Configuration'))
@ -107,6 +111,24 @@ final class PhabricatorEditEngineConfigurationViewController
->setHref($edit_uri)); ->setHref($edit_uri));
} }
$use_uri = $engine->getEditURI(null, "form/{$form_key}/");
$view->addAction(
id(new PhabricatorActionView())
->setName(pht('Use Form'))
->setIcon('fa-th-list')
->setHref($use_uri));
$reorder_uri = "{$base_uri}/reorder/{$form_key}/";
$view->addAction(
id(new PhabricatorActionView())
->setName(pht('Reorder Fields'))
->setIcon('fa-sort-alpha-asc')
->setHref($reorder_uri)
->setWorkflow(true)
->setDisabled(!$can_edit));
return $view; return $view;
} }
@ -121,5 +143,35 @@ final class PhabricatorEditEngineConfigurationViewController
return $properties; return $properties;
} }
private function buildFieldList(PhabricatorEditEngineConfiguration $config) {
$viewer = $this->getViewer();
$engine = $config->getEngine();
$fields = $engine->getFieldsForConfig($config);
$form = id(new AphrontFormView())
->setUser($viewer)
->setAction(null);
foreach ($fields as $field) {
$field->setIsPreview(true);
$field->appendToForm($form);
}
$info = id(new PHUIInfoView())
->setSeverity(PHUIInfoView::SEVERITY_NOTICE)
->setErrors(
array(
pht('This is a preview of the current form configuration.'),
));
$box = id(new PHUIObjectBoxView())
->setHeaderText(pht('Form Preview'))
->setInfoView($info)
->setForm($form);
return $box;
}
} }

View file

@ -46,6 +46,11 @@ abstract class PhabricatorEditEngine
return $this->getPhobjectClassConstant('ENGINECONST', 64); return $this->getPhobjectClassConstant('ENGINECONST', 64);
} }
final public function getApplication() {
$app_class = $this->getEngineApplicationClass();
return PhabricatorApplication::getByClass($app_class);
}
/* -( Managing Fields )---------------------------------------------------- */ /* -( Managing Fields )---------------------------------------------------- */
@ -53,6 +58,15 @@ abstract class PhabricatorEditEngine
abstract public function getEngineApplicationClass(); abstract public function getEngineApplicationClass();
abstract protected function buildCustomEditFields($object); abstract protected function buildCustomEditFields($object);
public function getFieldsForConfig(
PhabricatorEditEngineConfiguration $config) {
$object = $this->newEditableObject();
$this->editEngineConfiguration = $config;
return $this->buildEditFields($object);
}
final protected function buildEditFields($object) { final protected function buildEditFields($object) {
$viewer = $this->getViewer(); $viewer = $this->getViewer();
$editor = $object->getApplicationTransactionEditor(); $editor = $object->getApplicationTransactionEditor();
@ -129,6 +143,7 @@ abstract class PhabricatorEditEngine
->setEditTypeKey('space') ->setEditTypeKey('space')
->setDescription( ->setDescription(
pht('Shifts the object in the Spaces application.')) pht('Shifts the object in the Spaces application.'))
->setIsReorderable(false)
->setAliases(array('space', 'policy.space')) ->setAliases(array('space', 'policy.space'))
->setTransactionType($type_space) ->setTransactionType($type_space)
->setValue($object->getSpacePHID()); ->setValue($object->getSpacePHID());
@ -222,6 +237,13 @@ abstract class PhabricatorEditEngine
*/ */
abstract protected function getObjectCreateTitleText($object); abstract protected function getObjectCreateTitleText($object);
/**
* @task text
*/
protected function getFormHeaderText($object) {
$config = $this->getEditEngineConfiguration();
return $config->getName();
}
/** /**
* @task text * @task text
@ -384,16 +406,16 @@ abstract class PhabricatorEditEngine
/** /**
* @task uri * @task uri
*/ */
protected function getObjectEditURI($object) { protected function getObjectCreateCancelURI($object) {
return $this->getController()->getApplicationURI('edit/'); return $this->getApplication()->getApplicationURI();
} }
/** /**
* @task uri * @task uri
*/ */
protected function getObjectCreateCancelURI($object) { protected function getEditorURI() {
return $this->getController()->getApplicationURI(); return $this->getApplication()->getApplicationURI('edit/');
} }
@ -408,12 +430,12 @@ abstract class PhabricatorEditEngine
/** /**
* @task uri * @task uri
*/ */
protected function getEditURI($object, $path = null) { public function getEditURI($object = null, $path = null) {
$parts = array( $parts = array();
$this->getObjectEditURI($object),
);
if (!$this->getIsCreate()) { $parts[] = $this->getEditorURI();
if ($object && $object->getID()) {
$parts[] = $object->getID().'/'; $parts[] = $object->getID().'/';
} }
@ -563,7 +585,8 @@ abstract class PhabricatorEditEngine
$controller = $this->getController(); $controller = $this->getController();
$request = $controller->getRequest(); $request = $controller->getRequest();
$config = $this->loadEditEngineConfiguration($request->getURIData('form')); $form_key = $request->getURIData('formKey');
$config = $this->loadEditEngineConfiguration($form_key);
if (!$config) { if (!$config) {
return new Aphront404Response(); return new Aphront404Response();
} }
@ -668,7 +691,7 @@ abstract class PhabricatorEditEngine
$action_button = $this->buildEditFormActionButton($object); $action_button = $this->buildEditFormActionButton($object);
if ($this->getIsCreate()) { if ($this->getIsCreate()) {
$header_text = $this->getObjectCreateTitleText($object); $header_text = $this->getFormHeaderText($object);
} else { } else {
$header_text = $this->getObjectEditTitleText($object); $header_text = $this->getObjectEditTitleText($object);
} }

View file

@ -39,7 +39,7 @@ abstract class PhabricatorEditEngineAPIMethod
final public function getMethodDescription() { final public function getMethodDescription() {
// TODO: We don't currently have a real viewer in this method. // TODO: We don't currently have a real viewer in this method.
$viewer = new PhabricatorUser(); $viewer = PhabricatorUser::getOmnipotentUser();
$engine = $this->newEditEngine() $engine = $this->newEditEngine()
->setViewer($viewer); ->setViewer($viewer);

View file

@ -14,6 +14,8 @@ abstract class PhabricatorEditField extends Phobject {
private $description; private $description;
private $editTypeKey; private $editTypeKey;
private $isLocked; private $isLocked;
private $isPreview;
private $isReorderable = true;
public function setKey($key) { public function setKey($key) {
$this->key = $key; $this->key = $key;
@ -78,6 +80,24 @@ abstract class PhabricatorEditField extends Phobject {
return $this->isLocked; return $this->isLocked;
} }
public function setIsPreview($preview) {
$this->isPreview = $preview;
return $this;
}
public function getIsPreview() {
return $this->isPreview;
}
public function setIsReorderable($is_reorderable) {
$this->isReorderable = $is_reorderable;
return $this;
}
public function getIsReorderable() {
return $this->isReorderable;
}
protected function newControl() { protected function newControl() {
throw new PhutilMethodNotImplementedException(); throw new PhutilMethodNotImplementedException();
} }
@ -96,7 +116,7 @@ abstract class PhabricatorEditField extends Phobject {
$control->setLabel($this->getLabel()); $control->setLabel($this->getLabel());
} }
if ($this->getIsLocked()) { if ($this->getIsLocked() || $this->getIsPreview()) {
$control->setDisabled(true); $control->setDisabled(true);
} }
@ -149,9 +169,6 @@ abstract class PhabricatorEditField extends Phobject {
} }
public function getTransactionType() { public function getTransactionType() {
if (!$this->transactionType) {
throw new PhutilInvalidStateException('setTransactionType');
}
return $this->transactionType; return $this->transactionType;
} }
@ -257,6 +274,10 @@ abstract class PhabricatorEditField extends Phobject {
public function getEditTransactionTypes() { public function getEditTransactionTypes() {
$transaction_type = $this->getTransactionType(); $transaction_type = $this->getTransactionType();
if ($transaction_type === null) {
return array();
}
$type_key = $this->getEditTypeKey(); $type_key = $this->getEditTypeKey();
// TODO: This is a pretty big pile of hard-coded hacks for now. // TODO: This is a pretty big pile of hard-coded hacks for now.

View file

@ -0,0 +1,10 @@
<?php
final class PhabricatorRemarkupEditField
extends PhabricatorEditField {
protected function newControl() {
return new PhabricatorRemarkupControl();
}
}

View file

@ -51,20 +51,21 @@ final class PhabricatorEditEngineConfigurationEditEngine
} }
protected function getObjectViewURI($object) { protected function getObjectViewURI($object) {
$engine_key = $this->getTargetEngine()->getEngineKey();
$id = $object->getID(); $id = $object->getID();
return "/transactions/editengine/{$engine_key}/view/{$id}/"; return $this->getURI("view/{$id}/");
} }
protected function getObjectEditURI($object) { protected function getEditorURI() {
$engine_key = $this->getTargetEngine()->getEngineKey(); return $this->getURI('edit/');
$id = $object->getID();
return "/transactions/editengine/{$engine_key}/edit/{$id}/";
} }
protected function getObjectCreateCancelURI($object) { protected function getObjectCreateCancelURI($object) {
return $this->getURI();
}
private function getURI($path = null) {
$engine_key = $this->getTargetEngine()->getEngineKey(); $engine_key = $this->getTargetEngine()->getEngineKey();
return "/transactions/editengine/{$engine_key}/"; return "/transactions/editengine/{$engine_key}/{$path}";
} }
protected function buildCustomEditFields($object) { protected function buildCustomEditFields($object) {
@ -76,6 +77,13 @@ final class PhabricatorEditEngineConfigurationEditEngine
->setTransactionType( ->setTransactionType(
PhabricatorEditEngineConfigurationTransaction::TYPE_NAME) PhabricatorEditEngineConfigurationTransaction::TYPE_NAME)
->setValue($object->getName()), ->setValue($object->getName()),
id(new PhabricatorRemarkupEditField())
->setKey('preamble')
->setLabel(pht('Preamble'))
->setDescription(pht('Optional instructions, shown above the form.'))
->setTransactionType(
PhabricatorEditEngineConfigurationTransaction::TYPE_PREAMBLE)
->setValue($object->getPreamble()),
); );
} }

View file

@ -18,6 +18,8 @@ final class PhabricatorEditEngineConfigurationEditor
$types[] = PhabricatorTransactions::TYPE_EDIT_POLICY; $types[] = PhabricatorTransactions::TYPE_EDIT_POLICY;
$types[] = PhabricatorEditEngineConfigurationTransaction::TYPE_NAME; $types[] = PhabricatorEditEngineConfigurationTransaction::TYPE_NAME;
$types[] = PhabricatorEditEngineConfigurationTransaction::TYPE_PREAMBLE;
$types[] = PhabricatorEditEngineConfigurationTransaction::TYPE_ORDER;
return $types; return $types;
} }
@ -57,6 +59,10 @@ final class PhabricatorEditEngineConfigurationEditor
switch ($xaction->getTransactionType()) { switch ($xaction->getTransactionType()) {
case PhabricatorEditEngineConfigurationTransaction::TYPE_NAME: case PhabricatorEditEngineConfigurationTransaction::TYPE_NAME:
return $object->getName(); return $object->getName();
case PhabricatorEditEngineConfigurationTransaction::TYPE_PREAMBLE;
return $object->getPreamble();
case PhabricatorEditEngineConfigurationTransaction::TYPE_ORDER:
return $object->getFieldOrder();
} }
} }
@ -66,6 +72,8 @@ final class PhabricatorEditEngineConfigurationEditor
switch ($xaction->getTransactionType()) { switch ($xaction->getTransactionType()) {
case PhabricatorEditEngineConfigurationTransaction::TYPE_NAME: case PhabricatorEditEngineConfigurationTransaction::TYPE_NAME:
case PhabricatorEditEngineConfigurationTransaction::TYPE_PREAMBLE;
case PhabricatorEditEngineConfigurationTransaction::TYPE_ORDER:
return $xaction->getNewValue(); return $xaction->getNewValue();
} }
} }
@ -78,6 +86,12 @@ final class PhabricatorEditEngineConfigurationEditor
case PhabricatorEditEngineConfigurationTransaction::TYPE_NAME: case PhabricatorEditEngineConfigurationTransaction::TYPE_NAME:
$object->setName($xaction->getNewValue()); $object->setName($xaction->getNewValue());
return; return;
case PhabricatorEditEngineConfigurationTransaction::TYPE_PREAMBLE;
$object->setPreamble($xaction->getNewValue());
return;
case PhabricatorEditEngineConfigurationTransaction::TYPE_ORDER:
$object->setFieldOrder($xaction->getNewValue());
return;
} }
return parent::applyCustomInternalTransaction($object, $xaction); return parent::applyCustomInternalTransaction($object, $xaction);
@ -89,6 +103,8 @@ final class PhabricatorEditEngineConfigurationEditor
switch ($xaction->getTransactionType()) { switch ($xaction->getTransactionType()) {
case PhabricatorEditEngineConfigurationTransaction::TYPE_NAME: case PhabricatorEditEngineConfigurationTransaction::TYPE_NAME:
case PhabricatorEditEngineConfigurationTransaction::TYPE_PREAMBLE;
case PhabricatorEditEngineConfigurationTransaction::TYPE_ORDER;
return; return;
} }

View file

@ -134,6 +134,31 @@ final class PhabricatorEditEngineConfigurationQuery
return $page; return $page;
} }
protected function willFilterPage(array $configs) {
$engine_keys = mpull($configs, 'getEngineKey');
$engines = id(new PhabricatorEditEngineQuery())
->setParentQuery($this)
->setViewer($this->getViewer())
->withEngineKeys($engine_keys)
->execute();
$engines = mpull($engines, null, 'getEngineKey');
foreach ($configs as $key => $config) {
$engine = idx($engines, $config->getEngineKey());
if (!$engine) {
$this->didRejectResult($config);
unset($configs[$key]);
continue;
}
$config->attachEngine($engine);
}
return $configs;
}
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
$where = parent::buildWhereClauseParts($conn); $where = parent::buildWhereClauseParts($conn);

View file

@ -20,6 +20,28 @@ final class PhabricatorEditEngineQuery
return $engines; return $engines;
} }
protected function willFilterPage(array $engines) {
$viewer = $this->getViewer();
foreach ($engines as $key => $engine) {
$app_class = $engine->getEngineApplicationClass();
if ($app_class === null) {
continue;
}
$can_see = PhabricatorApplication::isClassInstalledForViewer(
$app_class,
$viewer);
if (!$can_see) {
$this->didRejectResult($engine);
unset($engines[$key]);
continue;
}
}
return $engines;
}
public function getQueryApplicationClass() { public function getQueryApplicationClass() {
return 'PhabricatorTransactionsApplication'; return 'PhabricatorTransactionsApplication';
} }

View file

@ -99,12 +99,13 @@ final class PhabricatorEditEngineConfiguration
$fields = $this->reorderFields($fields); $fields = $this->reorderFields($fields);
$head_instructions = $this->getProperty('instructions.head'); $preamble = $this->getPreamble();
if (strlen($head_instructions)) { if (strlen($preamble)) {
$fields = array( $fields = array(
'config.instructions.head' => id(new PhabricatorInstructionsEditField()) 'config.preamble' => id(new PhabricatorInstructionsEditField())
->setKey('config.instructions.head') ->setKey('config.preamble')
->setValue($head_instructions), ->setIsReorderable(false)
->setValue($preamble),
) + $fields; ) + $fields;
} }
@ -112,7 +113,7 @@ final class PhabricatorEditEngineConfiguration
} }
private function reorderFields(array $fields) { private function reorderFields(array $fields) {
$keys = array(); $keys = $this->getFieldOrder();
$fields = array_select_keys($fields, $keys) + $fields; $fields = array_select_keys($fields, $keys) + $fields;
// Now, move locked fields to the bottom. // Now, move locked fields to the bottom.
@ -158,6 +159,22 @@ final class PhabricatorEditEngineConfiguration
return pht('Untitled Form'); return pht('Untitled Form');
} }
public function getPreamble() {
return $this->getProperty('preamble');
}
public function setPreamble($preamble) {
return $this->setProperty('preamble', $preamble);
}
public function setFieldOrder(array $field_order) {
return $this->setProperty('order', $field_order);
}
public function getFieldOrder() {
return $this->getProperty('order', array());
}
/* -( PhabricatorPolicyInterface )----------------------------------------- */ /* -( PhabricatorPolicyInterface )----------------------------------------- */

View file

@ -4,6 +4,8 @@ final class PhabricatorEditEngineConfigurationTransaction
extends PhabricatorApplicationTransaction { extends PhabricatorApplicationTransaction {
const TYPE_NAME = 'editengine.config.name'; const TYPE_NAME = 'editengine.config.name';
const TYPE_PREAMBLE = 'editengine.config.preamble';
const TYPE_ORDER = 'editengine.config.order';
public function getApplicationName() { public function getApplicationName() {
return 'search'; return 'search';

View file

@ -0,0 +1,32 @@
/**
* @provides javelin-behavior-editengine-reorder-fields
* @requires javelin-behavior
* javelin-stratcom
* javelin-workflow
* javelin-dom
* phabricator-draggable-list
*/
JX.behavior('editengine-reorder-fields', function(config) {
var root = JX.$(config.listID);
var list = new JX.DraggableList('editengine-form-field', root)
.setFindItemsHandler(function() {
return JX.DOM.scry(root, 'li', 'editengine-form-field');
});
list.listen('didDrop', function() {
var nodes = list.findItems();
var data;
var keys = [];
for (var ii = 0; ii < nodes.length; ii++) {
data = JX.Stratcom.getData(nodes[ii]);
keys.push(data.fieldKey);
}
JX.$(config.inputID).value = keys.join(',');
});
});