mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-19 03:50:54 +01:00
Add Form MenuItem, Fix EditEngine Typeahead
Summary: Adds a FormEditEngine MenuItem for adding forms to Projects, Home, QuickCreate. Also adds an EditEngine typeahead that has token rendering issues currently. Test Plan: Set a normal form as a menu item, edit it, set the name. Set a custom form as a menu item, edit it, set a name. Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin Differential Revision: https://secure.phabricator.com/D17098
This commit is contained in:
parent
aa9708c5d3
commit
e9243f22b9
5 changed files with 166 additions and 5 deletions
|
@ -2582,6 +2582,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorEditEngineExtensionModule' => 'applications/transactions/engineextension/PhabricatorEditEngineExtensionModule.php',
|
||||
'PhabricatorEditEngineListController' => 'applications/transactions/controller/PhabricatorEditEngineListController.php',
|
||||
'PhabricatorEditEnginePointsCommentAction' => 'applications/transactions/commentaction/PhabricatorEditEnginePointsCommentAction.php',
|
||||
'PhabricatorEditEngineProfileMenuItem' => 'applications/search/menuitem/PhabricatorEditEngineProfileMenuItem.php',
|
||||
'PhabricatorEditEngineQuery' => 'applications/transactions/query/PhabricatorEditEngineQuery.php',
|
||||
'PhabricatorEditEngineSearchEngine' => 'applications/transactions/query/PhabricatorEditEngineSearchEngine.php',
|
||||
'PhabricatorEditEngineSelectCommentAction' => 'applications/transactions/commentaction/PhabricatorEditEngineSelectCommentAction.php',
|
||||
|
@ -7571,6 +7572,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorEditEngineExtensionModule' => 'PhabricatorConfigModule',
|
||||
'PhabricatorEditEngineListController' => 'PhabricatorEditEngineController',
|
||||
'PhabricatorEditEnginePointsCommentAction' => 'PhabricatorEditEngineCommentAction',
|
||||
'PhabricatorEditEngineProfileMenuItem' => 'PhabricatorProfileMenuItem',
|
||||
'PhabricatorEditEngineQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
'PhabricatorEditEngineSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||
'PhabricatorEditEngineSelectCommentAction' => 'PhabricatorEditEngineCommentAction',
|
||||
|
|
|
@ -0,0 +1,122 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorEditEngineProfileMenuItem
|
||||
extends PhabricatorProfileMenuItem {
|
||||
|
||||
const MENUITEMKEY = 'editengine';
|
||||
|
||||
private $form;
|
||||
|
||||
public function getMenuItemTypeIcon() {
|
||||
return 'fa-plus';
|
||||
}
|
||||
|
||||
public function getMenuItemTypeName() {
|
||||
return pht('Forms');
|
||||
}
|
||||
|
||||
public function canAddToObject($object) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function attachForm($form) {
|
||||
$this->form = $form;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getForm() {
|
||||
$form = $this->form;
|
||||
if (!$form) {
|
||||
return null;
|
||||
}
|
||||
return $form;
|
||||
}
|
||||
|
||||
public function willBuildNavigationItems(array $items) {
|
||||
$viewer = $this->getViewer();
|
||||
$engines = PhabricatorEditEngine::getAllEditEngines();
|
||||
$engine_keys = array_keys($engines);
|
||||
$forms = id(new PhabricatorEditEngineConfigurationQuery())
|
||||
->setViewer($viewer)
|
||||
->withEngineKeys($engine_keys)
|
||||
->withIsDisabled(false)
|
||||
->execute();
|
||||
$form_engines = mgroup($forms, 'getEngineKey');
|
||||
$form_ids = $forms;
|
||||
|
||||
$builtin_map = array();
|
||||
foreach ($form_engines as $engine_key => $form_engine) {
|
||||
$builtin_map[$engine_key] = mpull($form_engine, null, 'getBuiltinKey');
|
||||
}
|
||||
|
||||
foreach ($items as $item) {
|
||||
$key = $item->getMenuItemProperty('formKey');
|
||||
list($engine_key, $form_key) = explode('/', $key);
|
||||
if (is_numeric($form_key)) {
|
||||
$form = idx($form_ids, $form_key, null);
|
||||
$item->getMenuItem()->attachForm($form);
|
||||
} else if (isset($builtin_map[$engine_key][$form_key])) {
|
||||
$form = $builtin_map[$engine_key][$form_key];
|
||||
$item->getMenuItem()->attachForm($form);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getDisplayName(
|
||||
PhabricatorProfileMenuItemConfiguration $config) {
|
||||
$form = $this->getForm();
|
||||
if (!$form) {
|
||||
return pht('(Restricted/Invalid Form)');
|
||||
}
|
||||
if (strlen($this->getName($config))) {
|
||||
return $this->getName($config);
|
||||
} else {
|
||||
return $form->getName();
|
||||
}
|
||||
}
|
||||
|
||||
public function buildEditEngineFields(
|
||||
PhabricatorProfileMenuItemConfiguration $config) {
|
||||
return array(
|
||||
id(new PhabricatorTextEditField())
|
||||
->setKey('name')
|
||||
->setLabel(pht('Name'))
|
||||
->setValue($this->getName($config)),
|
||||
id(new PhabricatorDatasourceEditField())
|
||||
->setKey('formKey')
|
||||
->setLabel(pht('Form'))
|
||||
->setDatasource(new PhabricatorEditEngineDatasource())
|
||||
->setSingleValue($config->getMenuItemProperty('formKey')),
|
||||
);
|
||||
}
|
||||
|
||||
private function getName(
|
||||
PhabricatorProfileMenuItemConfiguration $config) {
|
||||
return $config->getMenuItemProperty('name');
|
||||
}
|
||||
|
||||
protected function newNavigationMenuItems(
|
||||
PhabricatorProfileMenuItemConfiguration $config) {
|
||||
|
||||
$form = $this->getForm();
|
||||
if (!$form) {
|
||||
return array();
|
||||
}
|
||||
$engine = $form->getEngine();
|
||||
$form_key = $form->getIdentifier();
|
||||
|
||||
$icon = $form->getIcon();
|
||||
$name = $this->getDisplayName($config);
|
||||
$href = $engine->getEditURI(null, "form/{$form_key}/");
|
||||
|
||||
$item = $this->newItem()
|
||||
->setHref($href)
|
||||
->setName($name)
|
||||
->setIcon($icon);
|
||||
|
||||
return array(
|
||||
$item,
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -49,7 +49,14 @@ abstract class PhabricatorEditEngine
|
|||
}
|
||||
|
||||
final public function getEngineKey() {
|
||||
return $this->getPhobjectClassConstant('ENGINECONST', 64);
|
||||
$key = $this->getPhobjectClassConstant('ENGINECONST', 64);
|
||||
if (strpos($key, '/') !== false) {
|
||||
throw new Exception(
|
||||
pht(
|
||||
'EditEngine ("%s") contains an invalid key character "/".',
|
||||
get_class($this)));
|
||||
}
|
||||
return $key;
|
||||
}
|
||||
|
||||
final public function getApplication() {
|
||||
|
|
|
@ -109,6 +109,14 @@ final class PhabricatorEditEngineConfiguration
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function setBuiltinKey($key) {
|
||||
if (strpos($key, '/') !== false) {
|
||||
throw new Exception(
|
||||
pht('EditEngine BuiltinKey contains an invalid key character "/".'));
|
||||
}
|
||||
return parent::setBuiltinKey($key);
|
||||
}
|
||||
|
||||
public function attachEngine(PhabricatorEditEngine $engine) {
|
||||
$this->engine = $engine;
|
||||
return $this;
|
||||
|
|
|
@ -15,25 +15,47 @@ final class PhabricatorEditEngineDatasource
|
|||
return 'PhabricatorTransactionsApplication';
|
||||
}
|
||||
|
||||
protected function renderSpecialTokens(array $values) {
|
||||
return $this->renderTokensFromResults($this->buildResults(), $values);
|
||||
}
|
||||
|
||||
public function loadResults() {
|
||||
$results = $this->buildResults();
|
||||
return $this->filterResultsAgainstTokens($results);
|
||||
}
|
||||
|
||||
private function buildResults() {
|
||||
$query = id(new PhabricatorEditEngineConfigurationQuery());
|
||||
|
||||
$forms = $this->executeQuery($query);
|
||||
$results = array();
|
||||
foreach ($forms as $form) {
|
||||
|
||||
if ($form->getID()) {
|
||||
$key = $form->getEngineKey().'/'.$form->getID();
|
||||
} else {
|
||||
$key = $form->getEngineKey().'/'.$form->getBuiltinKey();
|
||||
}
|
||||
$result = id(new PhabricatorTypeaheadResult())
|
||||
->setName($form->getName())
|
||||
->setPHID($form->getPHID());
|
||||
->setPHID($key)
|
||||
->setIcon($form->getIcon());
|
||||
|
||||
if ($form->getIsDisabled()) {
|
||||
$result->setClosed(pht('Archived'));
|
||||
}
|
||||
|
||||
$results[] = $result;
|
||||
if ($form->getIsDefault()) {
|
||||
$result->addAttribute(pht('Create Form'));
|
||||
}
|
||||
|
||||
if ($form->getIsEdit()) {
|
||||
$result->addAttribute(pht('Edit Form'));
|
||||
}
|
||||
|
||||
$results[$key] = $result;
|
||||
}
|
||||
|
||||
return $this->filterResultsAgainstTokens($results);
|
||||
return $results;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue