Changeset View
Changeset View
Standalone View
Standalone View
src/applications/search/engine/PhabricatorProfileMenuEngine.php
| <?php | <?php | ||||
| abstract class PhabricatorProfileMenuEngine extends Phobject { | abstract class PhabricatorProfileMenuEngine extends Phobject { | ||||
| private $viewer; | private $viewer; | ||||
| private $profileObject; | private $profileObject; | ||||
| private $customPHID; | private $customPHID; | ||||
| private $items; | private $items; | ||||
| private $menuType; | |||||
| private $defaultItem; | private $defaultItem; | ||||
| private $controller; | private $controller; | ||||
| private $navigation; | private $navigation; | ||||
| private $showNavigation = true; | |||||
| const MENU_GLOBAL = 'global'; | |||||
| const MENU_PERSONAL = 'personal'; | |||||
| const MENU_COMBINED = 'menu'; | |||||
| public function setViewer(PhabricatorUser $viewer) { | public function setViewer(PhabricatorUser $viewer) { | ||||
| $this->viewer = $viewer; | $this->viewer = $viewer; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getViewer() { | public function getViewer() { | ||||
| return $this->viewer; | return $this->viewer; | ||||
| Show All 32 Lines | private function setDefaultItem( | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getDefaultItem() { | public function getDefaultItem() { | ||||
| $this->loadItems(); | $this->loadItems(); | ||||
| return $this->defaultItem; | return $this->defaultItem; | ||||
| } | } | ||||
| public function setMenuType($type) { | |||||
| $this->menuType = $type; | |||||
| return $this; | |||||
| } | |||||
| private function getMenuType() { | |||||
| return $this->menuType; | |||||
| } | |||||
| public function setShowNavigation($show) { | |||||
| $this->showNavigation = $show; | |||||
| return $this; | |||||
| } | |||||
| public function getShowNavigation() { | |||||
| return $this->showNavigation; | |||||
| } | |||||
| abstract protected function getItemURI($path); | abstract protected function getItemURI($path); | ||||
| abstract protected function isMenuEngineConfigurable(); | abstract protected function isMenuEngineConfigurable(); | ||||
| public function buildResponse() { | public function buildResponse() { | ||||
| $controller = $this->getController(); | $controller = $this->getController(); | ||||
| $viewer = $controller->getViewer(); | $viewer = $controller->getViewer(); | ||||
| ▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | switch ($item_action) { | ||||
| } | } | ||||
| break; | break; | ||||
| } | } | ||||
| $navigation = $this->buildNavigation(); | $navigation = $this->buildNavigation(); | ||||
| $navigation->selectFilter('item.configure'); | $navigation->selectFilter('item.configure'); | ||||
| $crumbs = $controller->buildApplicationCrumbsForEditEngine(); | $crumbs = $controller->buildApplicationCrumbsForEditEngine(); | ||||
| switch ($this->getMenuType()) { | |||||
| case 'personal': | |||||
| $crumbs->addTextCrumb(pht('Personal')); | |||||
| break; | |||||
| case 'global': | |||||
| $crumbs->addTextCrumb(pht('Global')); | |||||
| break; | |||||
| } | |||||
| switch ($item_action) { | switch ($item_action) { | ||||
| case 'view': | case 'view': | ||||
| $content = $this->buildItemViewContent($selected_item); | $content = $this->buildItemViewContent($selected_item); | ||||
| break; | break; | ||||
| case 'configure': | case 'configure': | ||||
| $content = $this->buildItemConfigureContent($item_list); | $content = $this->buildItemConfigureContent($item_list); | ||||
| $crumbs->addTextCrumb(pht('Configure Menu')); | $crumbs->addTextCrumb(pht('Configure Menu')); | ||||
| Show All 31 Lines | public function buildResponse() { | ||||
| } | } | ||||
| if ($content instanceof AphrontResponseProducerInterface) { | if ($content instanceof AphrontResponseProducerInterface) { | ||||
| return $content; | return $content; | ||||
| } | } | ||||
| $crumbs->setBorder(true); | $crumbs->setBorder(true); | ||||
| return $controller->newPage() | $page = $controller->newPage() | ||||
| ->setTitle(pht('Configure Menu')) | ->setTitle(pht('Configure Menu')) | ||||
| ->setNavigation($navigation) | |||||
| ->setCrumbs($crumbs) | ->setCrumbs($crumbs) | ||||
| ->appendChild($content); | ->appendChild($content); | ||||
| if ($this->getShowNavigation()) { | |||||
| $page->setNavigation($navigation); | |||||
| } | |||||
| return $page; | |||||
| } | } | ||||
| public function buildNavigation() { | public function buildNavigation() { | ||||
| if ($this->navigation) { | if ($this->navigation) { | ||||
| return $this->navigation; | return $this->navigation; | ||||
| } | } | ||||
| $nav = id(new AphrontSideNavFilterView()) | $nav = id(new AphrontSideNavFilterView()) | ||||
| ▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | private function getItems() { | ||||
| return $this->items; | return $this->items; | ||||
| } | } | ||||
| private function loadItems() { | private function loadItems() { | ||||
| $viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
| $object = $this->getProfileObject(); | $object = $this->getProfileObject(); | ||||
| $items = $this->loadBuiltinProfileItems(); | $items = $this->loadBuiltinProfileItems(); | ||||
| $menu = $this->getMenuType(); | |||||
| if ($this->getCustomPHID()) { | if ($this->getCustomPHID()) { | ||||
| $stored_items = id(new PhabricatorProfileMenuItemConfigurationQuery()) | $stored_items = id(new PhabricatorProfileMenuItemConfigurationQuery()) | ||||
| ->setViewer($viewer) | ->setViewer($viewer) | ||||
| ->withProfilePHIDs(array($object->getPHID())) | ->withProfilePHIDs(array($object->getPHID())) | ||||
| ->withCustomPHIDs(array($this->getCustomPHID())) | ->withCustomPHIDs(array($this->getCustomPHID())) | ||||
| ->setMenuType($menu) | |||||
| ->execute(); | ->execute(); | ||||
| } else { | } else { | ||||
| $stored_items = id(new PhabricatorProfileMenuItemConfigurationQuery()) | $stored_items = id(new PhabricatorProfileMenuItemConfigurationQuery()) | ||||
| ->setViewer($viewer) | ->setViewer($viewer) | ||||
| ->withProfilePHIDs(array($object->getPHID())) | ->withProfilePHIDs(array($object->getPHID())) | ||||
| ->setMenuType($menu) | |||||
| ->execute(); | ->execute(); | ||||
| } | } | ||||
| foreach ($stored_items as $stored_item) { | foreach ($stored_items as $stored_item) { | ||||
| $impl = $stored_item->getMenuItem(); | $impl = $stored_item->getMenuItem(); | ||||
| $impl->setViewer($viewer); | $impl->setViewer($viewer); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 216 Lines • ▼ Show 20 Lines | private function buildItemConfigureContent(array $items) { | ||||
| Javelin::initBehavior( | Javelin::initBehavior( | ||||
| 'reorder-profile-menu-items', | 'reorder-profile-menu-items', | ||||
| array( | array( | ||||
| 'listID' => $list_id, | 'listID' => $list_id, | ||||
| 'orderURI' => $this->getItemURI('reorder/'), | 'orderURI' => $this->getItemURI('reorder/'), | ||||
| )); | )); | ||||
| $list = id(new PHUIObjectItemListView()) | $list = id(new PHUIObjectItemListView()) | ||||
| ->setID($list_id); | ->setID($list_id) | ||||
| ->setNoDataString(pht('This menu currently has no items.')); | |||||
| foreach ($items as $item) { | foreach ($items as $item) { | ||||
| $id = $item->getID(); | $id = $item->getID(); | ||||
| $builtin_key = $item->getBuiltinKey(); | $builtin_key = $item->getBuiltinKey(); | ||||
| $can_edit = PhabricatorPolicyFilter::hasCapability( | $can_edit = PhabricatorPolicyFilter::hasCapability( | ||||
| $viewer, | $viewer, | ||||
| $item, | $item, | ||||
| ▲ Show 20 Lines • Show All 120 Lines • ▼ Show 20 Lines | private function buildItemConfigureContent(array $items) { | ||||
| $action_list->addAction( | $action_list->addAction( | ||||
| id(new PhabricatorActionView()) | id(new PhabricatorActionView()) | ||||
| ->setIcon('fa-book') | ->setIcon('fa-book') | ||||
| ->setHref($doc_link) | ->setHref($doc_link) | ||||
| ->setName($doc_name)); | ->setName($doc_name)); | ||||
| $header = id(new PHUIHeaderView()) | $header = id(new PHUIHeaderView()) | ||||
| ->setHeader(pht('Profile Menu Items')) | ->setHeader(pht('Menu Items')) | ||||
| ->setHeaderIcon('fa-list'); | ->setHeaderIcon('fa-list'); | ||||
| $box = id(new PHUIObjectBoxView()) | $box = id(new PHUIObjectBoxView()) | ||||
| ->setHeaderText(pht('Navigation')) | ->setHeaderText(pht('Current Menu Items')) | ||||
| ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) | ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) | ||||
| ->setObjectList($list); | ->setObjectList($list); | ||||
| $panel = id(new PHUICurtainPanelView()) | $panel = id(new PHUICurtainPanelView()) | ||||
| ->appendChild($action_view); | ->appendChild($action_view); | ||||
| $curtain = id(new PHUICurtainView()) | $curtain = id(new PHUICurtainView()) | ||||
| ->setViewer($viewer) | ->setViewer($viewer) | ||||
| ▲ Show 20 Lines • Show All 300 Lines • Show Last 20 Lines | |||||