From 12d8520059622e13ba257c83a3f581411c8bc75f Mon Sep 17 00:00:00 2001 From: Chad Little Date: Wed, 17 Feb 2016 12:43:38 -0800 Subject: [PATCH] Convert PHUIObjectBoxView to AphrontTagView Summary: Attempting to clean PHUIObjectBoxView up a little as well as finally being able to `addClass` on the sucker. I'm running into some issue with `addTabs` though, which on Files isn't firing. Test Plan: Bounce around tons of screens. Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin Differential Revision: https://secure.phabricator.com/D15291 --- src/__phutil_library_map__.php | 2 +- ...PhabricatorPeopleProfileViewController.php | 4 +- .../PhabricatorProjectProfileController.php | 8 +- src/view/phui/PHUIObjectBoxView.php | 260 +++++++++--------- 4 files changed, 133 insertions(+), 141 deletions(-) diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 538ea56772..d277b62547 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -5711,7 +5711,7 @@ phutil_register_library_map(array( 'PHUIListView' => 'AphrontTagView', 'PHUIListViewTestCase' => 'PhabricatorTestCase', 'PHUIMainMenuView' => 'AphrontView', - 'PHUIObjectBoxView' => 'AphrontView', + 'PHUIObjectBoxView' => 'AphrontTagView', 'PHUIObjectItemListExample' => 'PhabricatorUIExample', 'PHUIObjectItemListView' => 'AphrontTagView', 'PHUIObjectItemView' => 'AphrontTagView', diff --git a/src/applications/people/controller/PhabricatorPeopleProfileViewController.php b/src/applications/people/controller/PhabricatorPeopleProfileViewController.php index 9978c6198e..9c85a5b7b3 100644 --- a/src/applications/people/controller/PhabricatorPeopleProfileViewController.php +++ b/src/applications/people/controller/PhabricatorPeopleProfileViewController.php @@ -174,7 +174,7 @@ final class PhabricatorPeopleProfileViewController $box = id(new PHUIObjectBoxView()) ->setHeader($header) ->appendChild($list) - ->setBackground(PHUIBoxView::GREY); + ->setBackground(PHUIObjectBoxView::GREY); return $box; } @@ -218,7 +218,7 @@ final class PhabricatorPeopleProfileViewController $box = id(new PHUIObjectBoxView()) ->setHeaderText(pht('Badges')) ->appendChild($flex) - ->setBackground(PHUIBoxView::GREY); + ->setBackground(PHUIObjectBoxView::GREY); return $box; } diff --git a/src/applications/project/controller/PhabricatorProjectProfileController.php b/src/applications/project/controller/PhabricatorProjectProfileController.php index 81a172ae42..f944bf5128 100644 --- a/src/applications/project/controller/PhabricatorProjectProfileController.php +++ b/src/applications/project/controller/PhabricatorProjectProfileController.php @@ -59,14 +59,14 @@ final class PhabricatorProjectProfileController ->setUser($viewer) ->setProject($project) ->setLimit(5) - ->setBackground(PHUIBoxView::GREY) + ->setBackground(PHUIObjectBoxView::GREY) ->setUserPHIDs($project->getMemberPHIDs()); $watcher_list = id(new PhabricatorProjectWatcherListView()) ->setUser($viewer) ->setProject($project) ->setLimit(5) - ->setBackground(PHUIBoxView::GREY) + ->setBackground(PHUIObjectBoxView::GREY) ->setUserPHIDs($project->getWatcherPHIDs()); $nav = $this->getProfileMenu(); @@ -244,7 +244,7 @@ final class PhabricatorProjectProfileController return id(new PHUIObjectBoxView()) ->setHeader($header) - ->setBackground(PHUIBoxView::GREY) + ->setBackground(PHUIObjectBoxView::GREY) ->setObjectList($milestone_list); } @@ -292,7 +292,7 @@ final class PhabricatorProjectProfileController return id(new PHUIObjectBoxView()) ->setHeader($header) - ->setBackground(PHUIBoxView::GREY) + ->setBackground(PHUIObjectBoxView::GREY) ->setObjectList($subproject_list); } diff --git a/src/view/phui/PHUIObjectBoxView.php b/src/view/phui/PHUIObjectBoxView.php index 32440a09cf..5cbb3a58b6 100644 --- a/src/view/phui/PHUIObjectBoxView.php +++ b/src/view/phui/PHUIObjectBoxView.php @@ -1,6 +1,6 @@ sigils[] = $sigil; - return $this; - } - - public function setMetadata(array $metadata) { - $this->metadata = $metadata; - return $this; - } + const BLUE = 'phui-box-blue'; + const GREY = 'phui-box-grey'; public function addPropertyList( PHUIPropertyListView $property_list, @@ -144,11 +137,6 @@ final class PHUIObjectBoxView extends AphrontView { return $this; } - public function setID($id) { - $this->id = $id; - return $this; - } - public function setHeader($header) { $this->header = $header; return $this; @@ -195,7 +183,109 @@ final class PHUIObjectBoxView extends AphrontView { return $this; } - public function render() { + public function willRender() { + $tab_lists = array(); + $property_lists = array(); + $tab_map = array(); + + $default_key = 'tab.default'; + + // Find the selected tab, or select the first tab if none are selected. + if ($this->tabs) { + $selected_tab = null; + foreach ($this->tabs as $key => $tab) { + if ($tab->getSelected()) { + $selected_tab = $key; + break; + } + } + if ($selected_tab === null) { + head($this->tabs)->setSelected(true); + $selected_tab = head_key($this->tabs); + } + } + + foreach ($this->propertyLists as $key => $list) { + $group = new PHUIPropertyGroupView(); + $i = 0; + foreach ($list as $item) { + $group->addPropertyList($item); + if ($i > 0) { + $item->addClass('phui-property-list-section-noninitial'); + } + $i++; + } + + if ($this->tabs && $key != $default_key) { + $tab_id = celerity_generate_unique_node_id(); + $tab_map[$key] = $tab_id; + + if ($key === $selected_tab) { + $style = null; + } else { + $style = 'display: none'; + } + + $tab_lists[] = phutil_tag( + 'div', + array( + 'style' => $style, + 'id' => $tab_id, + ), + $group); + } else { + if ($this->tabs) { + $group->addClass('phui-property-group-noninitial'); + } + $property_lists[] = $group; + } + $this->propertyList = $property_lists; + $this->tabMap = $tab_map; + $this->tabLists = $tab_lists; + } + } + + protected function getTagAttributes() { + $classes = array(); + $classes[] = 'phui-box'; + $classes[] = 'phui-box-border'; + $classes[] = 'phui-object-box'; + $classes[] = 'mlt mll mlr'; + + if ($this->color) { + $classes[] = 'phui-object-box-'.$this->color; + } + + if ($this->collapsed) { + $classes[] = 'phui-object-box-collapsed'; + } + + if ($this->flush) { + $classes[] = 'phui-object-box-flush'; + } + + if ($this->background) { + $classes[] = $this->background; + } + + $sigil = null; + $metadata = null; + if ($this->tabs) { + $sigil = 'phui-object-box'; + $metadata = array( + 'tabMap' => $this->tabMap, + ); + } + + return array( + 'class' => implode(' ', $classes), + 'sigil' => $sigil, + 'meta' => $metadata, + ); + } + + protected function getTagContent() { + require_celerity_resource('phui-box-css'); require_celerity_resource('phui-object-box-css'); $header = $this->header; @@ -296,63 +386,6 @@ final class PHUIObjectBoxView extends AphrontView { } } - $tab_lists = array(); - $property_lists = array(); - $tab_map = array(); - - $default_key = 'tab.default'; - - // Find the selected tab, or select the first tab if none are selected. - if ($this->tabs) { - $selected_tab = null; - foreach ($this->tabs as $key => $tab) { - if ($tab->getSelected()) { - $selected_tab = $key; - break; - } - } - if ($selected_tab === null) { - head($this->tabs)->setSelected(true); - $selected_tab = head_key($this->tabs); - } - } - - foreach ($this->propertyLists as $key => $list) { - $group = new PHUIPropertyGroupView(); - $i = 0; - foreach ($list as $item) { - $group->addPropertyList($item); - if ($i > 0) { - $item->addClass('phui-property-list-section-noninitial'); - } - $i++; - } - - if ($this->tabs && $key != $default_key) { - $tab_id = celerity_generate_unique_node_id(); - $tab_map[$key] = $tab_id; - - if ($key === $selected_tab) { - $style = null; - } else { - $style = 'display: none'; - } - - $tab_lists[] = phutil_tag( - 'div', - array( - 'style' => $style, - 'id' => $tab_id, - ), - $group); - } else { - if ($this->tabs) { - $group->addClass('phui-property-group-noninitial'); - } - $property_lists[] = $group; - } - } - $tabs = null; if ($this->tabs) { $tabs = id(new PHUIListView()) @@ -360,69 +393,28 @@ final class PHUIObjectBoxView extends AphrontView { foreach ($this->tabs as $tab) { $tabs->addMenuItem($tab); } - Javelin::initBehavior('phui-object-box-tabs'); } - $content = id(new PHUIBoxView()) - ->appendChild( - array( - ($this->showHideOpen == false ? $this->anchor : null), - $header, - $this->infoView, - $this->formErrors, - $this->formSaved, - $exception_errors, - $this->form, - $tabs, - $tab_lists, - $showhide, - ($this->showHideOpen == true ? $this->anchor : null), - $property_lists, - $this->table, - $this->renderChildren(), - )) - ->setBorder(true) - ->setID($this->id) - ->addMargin(PHUI::MARGIN_LARGE_TOP) - ->addMargin(PHUI::MARGIN_LARGE_LEFT) - ->addMargin(PHUI::MARGIN_LARGE_RIGHT) - ->addClass('phui-object-box'); - - if ($this->color) { - $content->addClass('phui-object-box-'.$this->color); - } - - if ($this->background) { - $content->setColor($this->background); - } - - if ($this->collapsed) { - $content->addClass('phui-object-box-collapsed'); - } - - if ($this->tabs) { - $content->addSigil('phui-object-box'); - $content->setMetadata( - array( - 'tabMap' => $tab_map, - )); - } - - if ($this->flush) { - $content->addClass('phui-object-box-flush'); - } - - foreach ($this->sigils as $sigil) { - $content->addSigil($sigil); - } - - if ($this->metadata !== null) { - $content->setMetadata($this->metadata); - } + $content = array( + ($this->showHideOpen == false ? $this->anchor : null), + $header, + $this->infoView, + $this->formErrors, + $this->formSaved, + $exception_errors, + $this->form, + $tabs, + $this->tabLists, + $showhide, + ($this->showHideOpen == true ? $this->anchor : null), + $this->propertyList, + $this->table, + $this->renderChildren(), + ); if ($this->objectList) { - $content->appendChild($this->objectList); + $content[] = $this->objectList; } return $content;