diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -2820,9 +2820,14 @@ 'PhabricatorHeraldContentSource' => 'applications/herald/contentsource/PhabricatorHeraldContentSource.php', 'PhabricatorHighSecurityRequestExceptionHandler' => 'aphront/handler/PhabricatorHighSecurityRequestExceptionHandler.php', 'PhabricatorHomeApplication' => 'applications/home/application/PhabricatorHomeApplication.php', + 'PhabricatorHomeConstants' => 'applications/home/constants/PhabricatorHomeConstants.php', 'PhabricatorHomeController' => 'applications/home/controller/PhabricatorHomeController.php', 'PhabricatorHomeMainController' => 'applications/home/controller/PhabricatorHomeMainController.php', + 'PhabricatorHomeManageProfileMenuItem' => 'applications/home/menuitem/PhabricatorHomeManageProfileMenuItem.php', + 'PhabricatorHomeMenuController' => 'applications/home/controller/PhabricatorHomeMenuController.php', + 'PhabricatorHomeMenuItemController' => 'applications/home/controller/PhabricatorHomeMenuItemController.php', 'PhabricatorHomePreferencesSettingsPanel' => 'applications/settings/panel/PhabricatorHomePreferencesSettingsPanel.php', + 'PhabricatorHomeProfileMenuEngine' => 'applications/home/engine/PhabricatorHomeProfileMenuEngine.php', 'PhabricatorHomeQuickCreateController' => 'applications/home/controller/PhabricatorHomeQuickCreateController.php', 'PhabricatorHovercardEngineExtension' => 'applications/search/engineextension/PhabricatorHovercardEngineExtension.php', 'PhabricatorHovercardEngineExtensionModule' => 'applications/search/engineextension/PhabricatorHovercardEngineExtensionModule.php', @@ -7861,9 +7866,14 @@ 'PhabricatorHeraldContentSource' => 'PhabricatorContentSource', 'PhabricatorHighSecurityRequestExceptionHandler' => 'PhabricatorRequestExceptionHandler', 'PhabricatorHomeApplication' => 'PhabricatorApplication', + 'PhabricatorHomeConstants' => 'PhabricatorHomeController', 'PhabricatorHomeController' => 'PhabricatorController', 'PhabricatorHomeMainController' => 'PhabricatorHomeController', + 'PhabricatorHomeManageProfileMenuItem' => 'PhabricatorProfileMenuItem', + 'PhabricatorHomeMenuController' => 'PhabricatorHomeController', + 'PhabricatorHomeMenuItemController' => 'PhabricatorHomeController', 'PhabricatorHomePreferencesSettingsPanel' => 'PhabricatorSettingsPanel', + 'PhabricatorHomeProfileMenuEngine' => 'PhabricatorProfileMenuEngine', 'PhabricatorHomeQuickCreateController' => 'PhabricatorHomeController', 'PhabricatorHovercardEngineExtension' => 'Phobject', 'PhabricatorHovercardEngineExtensionModule' => 'PhabricatorConfigModule', diff --git a/src/applications/home/application/PhabricatorHomeApplication.php b/src/applications/home/application/PhabricatorHomeApplication.php --- a/src/applications/home/application/PhabricatorHomeApplication.php +++ b/src/applications/home/application/PhabricatorHomeApplication.php @@ -27,6 +27,11 @@ '/(?Phome)/' => 'PhabricatorHomeMainController', '/home/' => array( 'create/' => 'PhabricatorHomeQuickCreateController', + 'menu/' => array( + '' => 'PhabricatorHomeMenuController', + '(?Pglobal|personal)/item/' => $this->getProfileMenuRouting( + 'PhabricatorHomeMenuItemController'), + ), ), ); } diff --git a/src/applications/home/constants/PhabricatorHomeConstants.php b/src/applications/home/constants/PhabricatorHomeConstants.php new file mode 100644 --- /dev/null +++ b/src/applications/home/constants/PhabricatorHomeConstants.php @@ -0,0 +1,9 @@ +getViewer(); + + $menu = id(new PHUIObjectItemListView()) + ->setUser($viewer); + + $menu->addItem( + id(new PHUIObjectItemView()) + ->setHeader(pht('Personal Menu Items')) + ->setHref($this->getApplicationURI('menu/personal/item/configure/')) + ->setImageURI($viewer->getProfileImageURI()) + ->addAttribute(pht('Edit the menu for your personal account.'))); + + $icon = id(new PHUIIconView()) + ->setIcon('fa-globe') + ->setBackground('bg-blue'); + + $menu->addItem( + id(new PHUIObjectItemView()) + ->setHeader(pht('Global Menu Items')) + ->setHref($this->getApplicationURI('menu/global/item/configure/')) + ->setImageIcon($icon) + ->addAttribute(pht('Edit the global default menu for all users.'))); + + $crumbs = $this->buildApplicationCrumbs(); + $crumbs->addTextCrumb(pht('Manage')); + $crumbs->setBorder(true); + + $box = id(new PHUIObjectBoxView()) + ->setObjectList($menu); + + $header = id(new PHUIHeaderView()) + ->setHeader(pht('Manage Home Menu')) + ->setHeaderIcon('fa-home'); + + $view = id(new PHUITwoColumnView()) + ->setHeader($header) + ->setFooter(array( + $box, + )); + + return $this->newPage() + ->setTitle(pht('Manage Home Menu')) + ->setCrumbs($crumbs) + ->appendChild($view); + + } + +} diff --git a/src/applications/home/controller/PhabricatorHomeMenuItemController.php b/src/applications/home/controller/PhabricatorHomeMenuItemController.php new file mode 100644 --- /dev/null +++ b/src/applications/home/controller/PhabricatorHomeMenuItemController.php @@ -0,0 +1,29 @@ +getViewer(); + $type = $request->getURIData('type'); + $custom_phid = null; + if ($type == 'personal') { + $custom_phid = $viewer->getPHID(); + } + + $application = 'PhabricatorHomeApplication'; + $home_app = id(new PhabricatorApplicationQuery()) + ->setViewer($viewer) + ->withClasses(array($application)) + ->withInstalled(true) + ->executeOne(); + + $engine = id(new PhabricatorHomeProfileMenuEngine()) + ->setProfileObject($home_app) + ->setCustomPHID($custom_phid) + ->setController($this); + + return $engine->buildResponse(); + } + +} diff --git a/src/applications/home/engine/PhabricatorHomeProfileMenuEngine.php b/src/applications/home/engine/PhabricatorHomeProfileMenuEngine.php new file mode 100644 --- /dev/null +++ b/src/applications/home/engine/PhabricatorHomeProfileMenuEngine.php @@ -0,0 +1,58 @@ +getProfileObject(); + $custom = $this->getCustomPHID(); + + if ($custom) { + return "/home/menu/personal/item/{$path}"; + } else { + return "/home/menu/global/item/{$path}"; + } + } + + protected function getBuiltinProfileItems($object) { + $viewer = $this->getViewer(); + $items = array(); + $custom_phid = $this->getCustomPHID(); + + $applications = id(new PhabricatorApplicationQuery()) + ->setViewer($viewer) + ->withInstalled(true) + ->withUnlisted(false) + ->withLaunchable(true) + ->execute(); + + foreach ($applications as $application) { + if (!$application->isPinnedByDefault($viewer)) { + continue; + } + + $properties = array( + 'name' => $application->getName(), + 'application' => $application->getPHID(), + ); + + $items[] = $this->newItem() + ->setBuiltinKey($application->getPHID()) + ->setMenuItemKey(PhabricatorApplicationProfileMenuItem::MENUITEMKEY) + ->setMenuItemProperties($properties); + } + + // Single Manage Item, switches URI based on admin/user + $items[] = $this->newItem() + ->setBuiltinKey(PhabricatorHomeConstants::ITEM_MANAGE) + ->setMenuItemKey( + PhabricatorHomeManageProfileMenuItem::MENUITEMKEY); + + return $items; + } + +} diff --git a/src/applications/home/menuitem/PhabricatorHomeManageProfileMenuItem.php b/src/applications/home/menuitem/PhabricatorHomeManageProfileMenuItem.php new file mode 100644 --- /dev/null +++ b/src/applications/home/menuitem/PhabricatorHomeManageProfileMenuItem.php @@ -0,0 +1,72 @@ +getMenuItemProperty('name'); + + if (strlen($name)) { + return $name; + } + + return $this->getDefaultName(); + } + + public function buildEditEngineFields( + PhabricatorProfileMenuItemConfiguration $config) { + return array( + id(new PhabricatorTextEditField()) + ->setKey('name') + ->setLabel(pht('Name')) + ->setPlaceholder($this->getDefaultName()) + ->setValue($config->getMenuItemProperty('name')), + ); + } + + protected function newNavigationMenuItems( + PhabricatorProfileMenuItemConfiguration $config) { + $viewer = $this->getViewer(); + + if ($viewer->isLoggedIn()) { + $admin = $viewer->getIsAdmin(); + $name = $this->getDisplayName($config); + $icon = 'fa-pencil'; + $href = '/home/menu/personal/item/configure/'; + if ($admin) { + $href = '/home/menu/'; + } + + $item = $this->newItem() + ->setHref($href) + ->setName($name) + ->setIcon($icon); + } + + return array( + $item, + ); + } + +}