mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-18 19:40:55 +01:00
Allow EditEngine to build NUX buttons that point at the right place
Summary: Fixes T11812. - Pull the logic for building the "Create Whatever" dropdown out. - Use it to generate NUX buttons, too. - Use the new logic in Paste and Maniphest. Test Plan: - Viewed Paste NUX, button worked. - Viewed Maniphest NUX with multiple create forms, button worked. Reviewers: chad, avivey Reviewed By: avivey Subscribers: avivey Maniphest Tasks: T11812 Differential Revision: https://secure.phabricator.com/D16797
This commit is contained in:
parent
e4c6ae5345
commit
0f1785c0aa
3 changed files with 103 additions and 54 deletions
|
@ -405,11 +405,11 @@ final class ManiphestTaskSearchEngine
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getNewUserBody() {
|
protected function getNewUserBody() {
|
||||||
$create_button = id(new PHUIButtonView())
|
$viewer = $this->requireViewer();
|
||||||
->setTag('a')
|
|
||||||
->setText(pht('Create a Task'))
|
$create_button = id(new ManiphestEditEngine())
|
||||||
->setHref('/maniphest/task/edit/')
|
->setViewer($viewer)
|
||||||
->setColor(PHUIButtonView::GREEN);
|
->newNUXBUtton(pht('Create a Task'));
|
||||||
|
|
||||||
$icon = $this->getApplication()->getIcon();
|
$icon = $this->getApplication()->getIcon();
|
||||||
$app_name = $this->getApplication()->getName();
|
$app_name = $this->getApplication()->getName();
|
||||||
|
|
|
@ -204,11 +204,11 @@ final class PhabricatorPasteSearchEngine
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getNewUserBody() {
|
protected function getNewUserBody() {
|
||||||
$create_button = id(new PHUIButtonView())
|
$viewer = $this->requireViewer();
|
||||||
->setTag('a')
|
|
||||||
->setText(pht('Create a Paste'))
|
$create_button = id(new PhabricatorPasteEditEngine())
|
||||||
->setHref('/paste/create/')
|
->setViewer($viewer)
|
||||||
->setColor(PHUIButtonView::GREEN);
|
->newNUXButton(pht('Create a Paste'));
|
||||||
|
|
||||||
$icon = $this->getApplication()->getIcon();
|
$icon = $this->getApplication()->getIcon();
|
||||||
$app_name = $this->getApplication()->getName();
|
$app_name = $this->getApplication()->getName();
|
||||||
|
|
|
@ -1352,11 +1352,80 @@ abstract class PhabricatorEditEngine
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function newNUXButton($text) {
|
||||||
|
$specs = $this->newCreateActionSpecifications(array());
|
||||||
|
$head = head($specs);
|
||||||
|
|
||||||
|
return id(new PHUIButtonView())
|
||||||
|
->setTag('a')
|
||||||
|
->setText($text)
|
||||||
|
->setHref($head['uri'])
|
||||||
|
->setDisabled($head['disabled'])
|
||||||
|
->setWorkflow($head['workflow'])
|
||||||
|
->setColor(PHUIButtonView::GREEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
final public function addActionToCrumbs(
|
final public function addActionToCrumbs(
|
||||||
PHUICrumbsView $crumbs,
|
PHUICrumbsView $crumbs,
|
||||||
array $parameters = array()) {
|
array $parameters = array()) {
|
||||||
$viewer = $this->getViewer();
|
$viewer = $this->getViewer();
|
||||||
|
|
||||||
|
$specs = $this->newCreateActionSpecifications($parameters);
|
||||||
|
|
||||||
|
$head = head($specs);
|
||||||
|
$menu_uri = $head['uri'];
|
||||||
|
|
||||||
|
$dropdown = null;
|
||||||
|
if (count($specs) > 1) {
|
||||||
|
$menu_icon = 'fa-caret-square-o-down';
|
||||||
|
$menu_name = $this->getObjectCreateShortText();
|
||||||
|
$workflow = false;
|
||||||
|
$disabled = false;
|
||||||
|
|
||||||
|
$dropdown = id(new PhabricatorActionListView())
|
||||||
|
->setUser($viewer);
|
||||||
|
|
||||||
|
foreach ($specs as $spec) {
|
||||||
|
$dropdown->addAction(
|
||||||
|
id(new PhabricatorActionView())
|
||||||
|
->setName($spec['name'])
|
||||||
|
->setIcon($spec['icon'])
|
||||||
|
->setHref($spec['uri']))
|
||||||
|
->setDisabled($head['disabled'])
|
||||||
|
->setWorkflow($head['workflow']);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$menu_icon = $head['icon'];
|
||||||
|
$menu_name = $head['name'];
|
||||||
|
|
||||||
|
$workflow = $head['workflow'];
|
||||||
|
$disabled = $head['disabled'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$action = id(new PHUIListItemView())
|
||||||
|
->setName($menu_name)
|
||||||
|
->setHref($menu_uri)
|
||||||
|
->setIcon($menu_icon)
|
||||||
|
->setWorkflow($workflow)
|
||||||
|
->setDisabled($disabled);
|
||||||
|
|
||||||
|
if ($dropdown) {
|
||||||
|
$action->setDropdownMenu($dropdown);
|
||||||
|
}
|
||||||
|
|
||||||
|
$crumbs->addAction($action);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build a raw description of available "Create New Object" UI options so
|
||||||
|
* other methods can build menus or buttons.
|
||||||
|
*/
|
||||||
|
private function newCreateActionSpecifications(array $parameters) {
|
||||||
|
$viewer = $this->getViewer();
|
||||||
|
|
||||||
$can_create = $this->hasCreateCapability();
|
$can_create = $this->hasCreateCapability();
|
||||||
if ($can_create) {
|
if ($can_create) {
|
||||||
$configs = $this->loadUsableConfigurationsForCreate();
|
$configs = $this->loadUsableConfigurationsForCreate();
|
||||||
|
@ -1364,12 +1433,11 @@ abstract class PhabricatorEditEngine
|
||||||
$configs = array();
|
$configs = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
$dropdown = null;
|
|
||||||
$disabled = false;
|
$disabled = false;
|
||||||
$workflow = false;
|
$workflow = false;
|
||||||
|
|
||||||
$menu_icon = 'fa-plus-square';
|
$menu_icon = 'fa-plus-square';
|
||||||
|
$specs = array();
|
||||||
if (!$configs) {
|
if (!$configs) {
|
||||||
if ($viewer->isLoggedIn()) {
|
if ($viewer->isLoggedIn()) {
|
||||||
$disabled = true;
|
$disabled = true;
|
||||||
|
@ -1385,54 +1453,35 @@ abstract class PhabricatorEditEngine
|
||||||
} else {
|
} else {
|
||||||
$create_uri = $this->getEditURI(null, 'nocreate/');
|
$create_uri = $this->getEditURI(null, 'nocreate/');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$specs[] = array(
|
||||||
|
'name' => $this->getObjectCreateShortText(),
|
||||||
|
'uri' => $create_uri,
|
||||||
|
'icon' => $menu_icon,
|
||||||
|
'disabled' => $disabled,
|
||||||
|
'workflow' => $workflow,
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
$config = head($configs);
|
foreach ($configs as $config) {
|
||||||
$form_key = $config->getIdentifier();
|
$form_key = $config->getIdentifier();
|
||||||
$create_uri = $this->getEditURI(null, "form/{$form_key}/");
|
$config_uri = $this->getEditURI(null, "form/{$form_key}/");
|
||||||
|
|
||||||
if ($parameters) {
|
if ($parameters) {
|
||||||
$create_uri = (string)id(new PhutilURI($create_uri))
|
$config_uri = (string)id(new PhutilURI($config_uri))
|
||||||
->setQueryParams($parameters);
|
->setQueryParams($parameters);
|
||||||
}
|
|
||||||
|
|
||||||
if (count($configs) > 1) {
|
|
||||||
$menu_icon = 'fa-caret-square-o-down';
|
|
||||||
|
|
||||||
$dropdown = id(new PhabricatorActionListView())
|
|
||||||
->setUser($viewer);
|
|
||||||
|
|
||||||
foreach ($configs as $config) {
|
|
||||||
$form_key = $config->getIdentifier();
|
|
||||||
$config_uri = $this->getEditURI(null, "form/{$form_key}/");
|
|
||||||
|
|
||||||
if ($parameters) {
|
|
||||||
$config_uri = (string)id(new PhutilURI($config_uri))
|
|
||||||
->setQueryParams($parameters);
|
|
||||||
}
|
|
||||||
|
|
||||||
$item_icon = 'fa-plus';
|
|
||||||
|
|
||||||
$dropdown->addAction(
|
|
||||||
id(new PhabricatorActionView())
|
|
||||||
->setName($config->getDisplayName())
|
|
||||||
->setIcon($item_icon)
|
|
||||||
->setHref($config_uri));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$specs[] = array(
|
||||||
|
'name' => $config->getDisplayName(),
|
||||||
|
'uri' => $config_uri,
|
||||||
|
'icon' => 'fa-plus',
|
||||||
|
'disabled' => false,
|
||||||
|
'workflow' => false,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$action = id(new PHUIListItemView())
|
return $specs;
|
||||||
->setName($this->getObjectCreateShortText())
|
|
||||||
->setHref($create_uri)
|
|
||||||
->setIcon($menu_icon)
|
|
||||||
->setWorkflow($workflow)
|
|
||||||
->setDisabled($disabled);
|
|
||||||
|
|
||||||
if ($dropdown) {
|
|
||||||
$action->setDropdownMenu($dropdown);
|
|
||||||
}
|
|
||||||
|
|
||||||
$crumbs->addAction($action);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final public function buildEditEngineCommentView($object) {
|
final public function buildEditEngineCommentView($object) {
|
||||||
|
|
Loading…
Reference in a new issue