From 049fb2018bde80d807105f8313ab577035849ddd Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 28 Jan 2014 20:18:01 -0800 Subject: [PATCH] Add very basic "quick create" menu Summary: Ref T3623. This is like a pre-v0, in that it doesn't have a dropdown yet. Clicking the button takes you to a page which can serve as a right click / mobile / edit target in the long run, but is obviously not great for desktop use. I'll add the dropdown in the next iteration. Test Plan: {F105631} Reviewers: chad, btrahan Reviewed By: chad CC: aran Maniphest Tasks: T3623 Differential Revision: https://secure.phabricator.com/D8088 --- src/__phutil_library_map__.php | 2 + .../PhabricatorApplicationAuth.php | 6 ++- .../base/PhabricatorApplication.php | 13 ++++- .../PhabricatorApplicationConpherence.php | 14 ++++++ .../PhabricatorApplicationDiviner.php | 11 +++-- .../PhabricatorApplicationHome.php | 26 ++++++++++ .../PhabricatorHomeQuickCreateController.php | 47 +++++++++++++++++++ .../PhabricatorApplicationManiphest.php | 12 +++++ .../PhabricatorApplicationPaste.php | 12 +++++ .../PhabricatorApplicationPeople.php | 9 ++-- .../PhabricatorApplicationSettings.php | 13 ++--- .../page/menu/PhabricatorMainMenuView.php | 2 + src/view/phui/PHUIListItemView.php | 10 ++++ 13 files changed, 159 insertions(+), 18 deletions(-) create mode 100644 src/applications/home/controller/PhabricatorHomeQuickCreateController.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 16b5a48d4d..784fa675c0 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1530,6 +1530,7 @@ phutil_register_library_map(array( 'PhabricatorHelpKeyboardShortcutController' => 'applications/help/controller/PhabricatorHelpKeyboardShortcutController.php', 'PhabricatorHomeController' => 'applications/home/controller/PhabricatorHomeController.php', 'PhabricatorHomeMainController' => 'applications/home/controller/PhabricatorHomeMainController.php', + 'PhabricatorHomeQuickCreateController' => 'applications/home/controller/PhabricatorHomeQuickCreateController.php', 'PhabricatorHovercardExample' => 'applications/uiexample/examples/PhabricatorHovercardExample.php', 'PhabricatorHovercardView' => 'view/widget/hovercard/PhabricatorHovercardView.php', 'PhabricatorIRCBot' => 'infrastructure/daemon/bot/PhabricatorIRCBot.php', @@ -4177,6 +4178,7 @@ phutil_register_library_map(array( 'PhabricatorHelpKeyboardShortcutController' => 'PhabricatorHelpController', 'PhabricatorHomeController' => 'PhabricatorController', 'PhabricatorHomeMainController' => 'PhabricatorHomeController', + 'PhabricatorHomeQuickCreateController' => 'PhabricatorHomeController', 'PhabricatorHovercardExample' => 'PhabricatorUIExample', 'PhabricatorHovercardView' => 'AphrontView', 'PhabricatorIRCBot' => 'PhabricatorDaemon', diff --git a/src/applications/auth/application/PhabricatorApplicationAuth.php b/src/applications/auth/application/PhabricatorApplicationAuth.php index afb2c313df..1e9228b01c 100644 --- a/src/applications/auth/application/PhabricatorApplicationAuth.php +++ b/src/applications/auth/application/PhabricatorApplicationAuth.php @@ -39,7 +39,8 @@ final class PhabricatorApplicationAuth extends PhabricatorApplication { ->setIcon('power') ->setWorkflow(true) ->setHref('/logout/') - ->setSelected(($controller instanceof PhabricatorLogoutController)); + ->setSelected(($controller instanceof PhabricatorLogoutController)) + ->setOrder(900); $items[] = $item; } else { if ($controller instanceof PhabricatorAuthController) { @@ -51,7 +52,8 @@ final class PhabricatorApplicationAuth extends PhabricatorApplication { ->setName(pht('Log In')) // TODO: Login icon? ->setIcon('power') - ->setHref('/auth/start/'); + ->setHref('/auth/start/') + ->setOrder(900); $items[] = $item; } } diff --git a/src/applications/base/PhabricatorApplication.php b/src/applications/base/PhabricatorApplication.php index 49c7241e8a..b0febb168b 100644 --- a/src/applications/base/PhabricatorApplication.php +++ b/src/applications/base/PhabricatorApplication.php @@ -248,7 +248,7 @@ abstract class PhabricatorApplication * @param PhabricatorUser The viewing user. * @param AphrontController The current controller. May be null for special * pages like 404, exception handlers, etc. - * @return list List of menu items. + * @return list List of menu items. * @task ui */ public function buildMainMenuItems( @@ -270,6 +270,17 @@ abstract class PhabricatorApplication } + /** + * Build items for the "quick create" menu. + * + * @param PhabricatorUser The viewing user. + * @return list List of menu items. + */ + public function getQuickCreateItems(PhabricatorUser $viewer) { + return array(); + } + + /* -( Application Management )--------------------------------------------- */ public static function getByClass($class_name) { diff --git a/src/applications/conpherence/application/PhabricatorApplicationConpherence.php b/src/applications/conpherence/application/PhabricatorApplicationConpherence.php index 04ce42b584..7d670cfc19 100644 --- a/src/applications/conpherence/application/PhabricatorApplicationConpherence.php +++ b/src/applications/conpherence/application/PhabricatorApplicationConpherence.php @@ -50,4 +50,18 @@ final class PhabricatorApplicationConpherence extends PhabricatorApplication { ); } + public function getQuickCreateItems(PhabricatorUser $viewer) { + $items = array(); + + $item = id(new PHUIListItemView()) + ->setName(pht('New Conpherence Thread')) + ->setIcon('new') + ->setWorkflow(true) + ->setHref($this->getBaseURI().'new/'); + $items[] = $item; + + return $items; + } + + } diff --git a/src/applications/diviner/application/PhabricatorApplicationDiviner.php b/src/applications/diviner/application/PhabricatorApplicationDiviner.php index d4dbed044a..b4db1281ca 100644 --- a/src/applications/diviner/application/PhabricatorApplicationDiviner.php +++ b/src/applications/diviner/application/PhabricatorApplicationDiviner.php @@ -58,11 +58,12 @@ final class PhabricatorApplicationDiviner extends PhabricatorApplication { } if ($application && $application->getHelpURI()) { - $item = new PHUIListItemView(); - $item->setName(pht('%s Help', $application->getName())); - $item->addClass('core-menu-item'); - $item->setIcon('help'); - $item->setHref($application->getHelpURI()); + $item = id(new PHUIListItemView()) + ->setName(pht('%s Help', $application->getName())) + ->addClass('core-menu-item') + ->setIcon('help') + ->setOrder(100) + ->setHref($application->getHelpURI()); $items[] = $item; } diff --git a/src/applications/home/application/PhabricatorApplicationHome.php b/src/applications/home/application/PhabricatorApplicationHome.php index 628bf9c3d9..9393d24333 100644 --- a/src/applications/home/application/PhabricatorApplicationHome.php +++ b/src/applications/home/application/PhabricatorApplicationHome.php @@ -17,6 +17,9 @@ final class PhabricatorApplicationHome extends PhabricatorApplication { public function getRoutes() { return array( '/(?:(?P(?:jump))/)?' => 'PhabricatorHomeMainController', + '/home/' => array( + 'create/' => 'PhabricatorHomeQuickCreateController', + ), ); } @@ -28,4 +31,27 @@ final class PhabricatorApplicationHome extends PhabricatorApplication { return false; } + public function getApplicationOrder() { + return 9; + } + + public function buildMainMenuItems( + PhabricatorUser $user, + PhabricatorController $controller = null) { + + $items = array(); + + if ($user->isLoggedIn() && $user->isUserActivated()) { + $item = id(new PHUIListItemView()) + ->setName(pht('Create New...')) + ->setIcon('new') + ->addClass('core-menu-item') + ->setHref('/home/create/') + ->setOrder(300); + $items[] = $item; + } + + return $items; + } + } diff --git a/src/applications/home/controller/PhabricatorHomeQuickCreateController.php b/src/applications/home/controller/PhabricatorHomeQuickCreateController.php new file mode 100644 index 0000000000..a93b7f1c06 --- /dev/null +++ b/src/applications/home/controller/PhabricatorHomeQuickCreateController.php @@ -0,0 +1,47 @@ +getRequest()->getUser(); + + $applications = id(new PhabricatorApplicationQuery()) + ->setViewer($viewer) + ->withInstalled(true) + ->execute(); + + $items = array(); + foreach ($applications as $application) { + $app_items = $application->getQuickCreateItems($viewer); + foreach ($app_items as $app_item) { + $items[] = $app_item; + } + } + + $list = id(new PHUIObjectItemListView()) + ->setUser($viewer); + + foreach ($items as $item) { + $list->addItem( + id(new PHUIObjectItemView()) + ->setHeader($item->getName()) + ->setWorkflow($item->getWorkflow()) + ->setHref($item->getHref())); + } + + $crumbs = $this->buildApplicationCrumbs(); + $crumbs->addTextCrumb(pht('Quick Create')); + + return $this->buildApplicationPage( + array( + $crumbs, + $list, + ), + array( + 'title' => pht('Quick Create'), + )); + } + + +} diff --git a/src/applications/maniphest/application/PhabricatorApplicationManiphest.php b/src/applications/maniphest/application/PhabricatorApplicationManiphest.php index 234f1e2a3b..1637216271 100644 --- a/src/applications/maniphest/application/PhabricatorApplicationManiphest.php +++ b/src/applications/maniphest/application/PhabricatorApplicationManiphest.php @@ -90,6 +90,18 @@ final class PhabricatorApplicationManiphest extends PhabricatorApplication { return $status; } + public function getQuickCreateItems(PhabricatorUser $viewer) { + $items = array(); + + $item = id(new PHUIListItemView()) + ->setName(pht('New Maniphest Task')) + ->setIcon('new') + ->setHref($this->getBaseURI().'task/create/'); + $items[] = $item; + + return $items; + } + protected function getCustomCapabilities() { return array( ManiphestCapabilityDefaultView::CAPABILITY => array( diff --git a/src/applications/paste/application/PhabricatorApplicationPaste.php b/src/applications/paste/application/PhabricatorApplicationPaste.php index 846dc86cae..9f13e15313 100644 --- a/src/applications/paste/application/PhabricatorApplicationPaste.php +++ b/src/applications/paste/application/PhabricatorApplicationPaste.php @@ -50,4 +50,16 @@ final class PhabricatorApplicationPaste extends PhabricatorApplication { ); } + public function getQuickCreateItems(PhabricatorUser $viewer) { + $items = array(); + + $item = id(new PHUIListItemView()) + ->setName(pht('New Paste')) + ->setIcon('new') + ->setHref($this->getBaseURI().'create/'); + $items[] = $item; + + return $items; + } + } diff --git a/src/applications/people/application/PhabricatorApplicationPeople.php b/src/applications/people/application/PhabricatorApplicationPeople.php index c1485b95fa..ff3692dc68 100644 --- a/src/applications/people/application/PhabricatorApplicationPeople.php +++ b/src/applications/people/application/PhabricatorApplicationPeople.php @@ -97,10 +97,11 @@ final class PhabricatorApplicationPeople extends PhabricatorApplication { if ($user->isLoggedIn() && $user->isUserActivated()) { $image = $user->loadProfileImageURI(); - $item = new PHUIListItemView(); - $item->setName($user->getUsername()); - $item->setHref('/p/'.$user->getUsername().'/'); - $item->addClass('core-menu-item'); + $item = id(new PHUIListItemView()) + ->setName($user->getUsername()) + ->setHref('/p/'.$user->getUsername().'/') + ->addClass('core-menu-item') + ->setOrder(200); $classes = array( 'phabricator-core-menu-icon', diff --git a/src/applications/settings/application/PhabricatorApplicationSettings.php b/src/applications/settings/application/PhabricatorApplicationSettings.php index e42ba50229..7f0f32ef1a 100644 --- a/src/applications/settings/application/PhabricatorApplicationSettings.php +++ b/src/applications/settings/application/PhabricatorApplicationSettings.php @@ -39,12 +39,13 @@ final class PhabricatorApplicationSettings extends PhabricatorApplication { if ($user->isLoggedIn() && $user->isUserActivated()) { $selected = ($controller instanceof PhabricatorSettingsMainController); - $item = new PHUIListItemView(); - $item->setName(pht('Settings')); - $item->setIcon('settings'); - $item->addClass('core-menu-item'); - $item->setSelected($selected); - $item->setHref('/settings/'); + $item = id(new PHUIListItemView()) + ->setName(pht('Settings')) + ->setIcon('settings') + ->addClass('core-menu-item') + ->setSelected($selected) + ->setHref('/settings/') + ->setOrder(400); $items[] = $item; } diff --git a/src/view/page/menu/PhabricatorMainMenuView.php b/src/view/page/menu/PhabricatorMainMenuView.php index 62f68f2a25..94430e8ed4 100644 --- a/src/view/page/menu/PhabricatorMainMenuView.php +++ b/src/view/page/menu/PhabricatorMainMenuView.php @@ -163,6 +163,8 @@ final class PhabricatorMainMenuView extends AphrontView { } } + $actions = msort($actions, 'getOrder'); + $view = $this->getApplicationMenu(); if (!$view) { diff --git a/src/view/phui/PHUIListItemView.php b/src/view/phui/PHUIListItemView.php index 9af36ab589..374adfaae7 100644 --- a/src/view/phui/PHUIListItemView.php +++ b/src/view/phui/PHUIListItemView.php @@ -23,6 +23,16 @@ final class PHUIListItemView extends AphrontTagView { private $disabled; private $renderNameAsTooltip; private $statusColor; + private $order; + + public function setOrder($order) { + $this->order = $order; + return $this; + } + + public function getOrder() { + return $this->order; + } public function setRenderNameAsTooltip($render_name_as_tooltip) { $this->renderNameAsTooltip = $render_name_as_tooltip;