From f0b695239186ed3e4f3f5124e2726e0897df829d Mon Sep 17 00:00:00 2001 From: Chad Little Date: Fri, 9 Dec 2016 13:04:57 -0800 Subject: [PATCH] Add an ApplicationProfilePanel Summary: Allows applications to be added as profile menu items Test Plan: Add an application to a project, see menu item, click on menu. Uninstall application, see menu without application. Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin Differential Revision: https://secure.phabricator.com/D17016 --- src/__phutil_library_map__.php | 2 + .../PhabricatorApplicationProfilePanel.php | 79 +++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 src/applications/search/profilepanel/PhabricatorApplicationProfilePanel.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index a956ee6f4c..97799da03e 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1787,6 +1787,7 @@ phutil_register_library_map(array( 'PhabricatorApplicationEmailCommandsController' => 'applications/meta/controller/PhabricatorApplicationEmailCommandsController.php', 'PhabricatorApplicationLaunchView' => 'applications/meta/view/PhabricatorApplicationLaunchView.php', 'PhabricatorApplicationPanelController' => 'applications/meta/controller/PhabricatorApplicationPanelController.php', + 'PhabricatorApplicationProfilePanel' => 'applications/search/profilepanel/PhabricatorApplicationProfilePanel.php', 'PhabricatorApplicationQuery' => 'applications/meta/query/PhabricatorApplicationQuery.php', 'PhabricatorApplicationSearchController' => 'applications/search/controller/PhabricatorApplicationSearchController.php', 'PhabricatorApplicationSearchEngine' => 'applications/search/engine/PhabricatorApplicationSearchEngine.php', @@ -6609,6 +6610,7 @@ phutil_register_library_map(array( 'PhabricatorApplicationEmailCommandsController' => 'PhabricatorApplicationsController', 'PhabricatorApplicationLaunchView' => 'AphrontTagView', 'PhabricatorApplicationPanelController' => 'PhabricatorApplicationsController', + 'PhabricatorApplicationProfilePanel' => 'PhabricatorProfilePanel', 'PhabricatorApplicationQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhabricatorApplicationSearchController' => 'PhabricatorSearchBaseController', 'PhabricatorApplicationSearchEngine' => 'Phobject', diff --git a/src/applications/search/profilepanel/PhabricatorApplicationProfilePanel.php b/src/applications/search/profilepanel/PhabricatorApplicationProfilePanel.php new file mode 100644 index 0000000000..f2d53f936d --- /dev/null +++ b/src/applications/search/profilepanel/PhabricatorApplicationProfilePanel.php @@ -0,0 +1,79 @@ +getApplication($config); + if ($app) { + return $app->getName(); + } else { + return pht('(Uninstalled Application)'); + } + return $app->getName(); + } + + public function buildEditEngineFields( + PhabricatorProfilePanelConfiguration $config) { + return array( + id(new PhabricatorDatasourceEditField()) + ->setKey('application') + ->setLabel(pht('Application')) + ->setDatasource(new PhabricatorApplicationDatasource()) + ->setSingleValue($config->getPanelProperty('application')), + ); + } + + private function getApplication( + PhabricatorProfilePanelConfiguration $config) { + $viewer = $this->getViewer(); + $phid = $config->getPanelProperty('application'); + $app = id(new PhabricatorApplicationQuery()) + ->setViewer($viewer) + ->withPHIDs(array($phid)) + ->executeOne(); + + return $app; + } + + protected function newNavigationMenuItems( + PhabricatorProfilePanelConfiguration $config) { + $viewer = $this->getViewer(); + $app = $this->getApplication($config); + if (!$app) { + return array(); + } + + $is_installed = PhabricatorApplication::isClassInstalledForViewer( + get_class($app), + $viewer); + if (!$is_installed) { + return array(); + } + + $item = $this->newItem() + ->setHref($app->getApplicationURI()) + ->setName($app->getName()) + ->setIcon($app->getIcon()); + + return array( + $item, + ); + } + +}