diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 7f5b6db0d4..9cb07a0259 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -3312,6 +3312,7 @@ phutil_register_library_map(array( 'PhameController' => 'applications/phame/controller/PhameController.php', 'PhameCreatePostConduitAPIMethod' => 'applications/phame/conduit/PhameCreatePostConduitAPIMethod.php', 'PhameDAO' => 'applications/phame/storage/PhameDAO.php', + 'PhameHomeController' => 'applications/phame/controller/PhameHomeController.php', 'PhamePost' => 'applications/phame/storage/PhamePost.php', 'PhamePostCommentController' => 'applications/phame/controller/post/PhamePostCommentController.php', 'PhamePostController' => 'applications/phame/controller/post/PhamePostController.php', @@ -3319,6 +3320,7 @@ phutil_register_library_map(array( 'PhamePostEditor' => 'applications/phame/editor/PhamePostEditor.php', 'PhamePostFramedController' => 'applications/phame/controller/post/PhamePostFramedController.php', 'PhamePostListController' => 'applications/phame/controller/post/PhamePostListController.php', + 'PhamePostListView' => 'applications/phame/view/PhamePostListView.php', 'PhamePostMailReceiver' => 'applications/phame/mail/PhamePostMailReceiver.php', 'PhamePostNewController' => 'applications/phame/controller/post/PhamePostNewController.php', 'PhamePostNotLiveController' => 'applications/phame/controller/post/PhamePostNotLiveController.php', @@ -7632,6 +7634,7 @@ phutil_register_library_map(array( 'PhameController' => 'PhabricatorController', 'PhameCreatePostConduitAPIMethod' => 'PhameConduitAPIMethod', 'PhameDAO' => 'PhabricatorLiskDAO', + 'PhameHomeController' => 'PhamePostController', 'PhamePost' => array( 'PhameDAO', 'PhabricatorPolicyInterface', @@ -7649,6 +7652,7 @@ phutil_register_library_map(array( 'PhamePostEditor' => 'PhabricatorApplicationTransactionEditor', 'PhamePostFramedController' => 'PhamePostController', 'PhamePostListController' => 'PhamePostController', + 'PhamePostListView' => 'AphrontTagView', 'PhamePostMailReceiver' => 'PhabricatorObjectMailReceiver', 'PhamePostNewController' => 'PhamePostController', 'PhamePostNotLiveController' => 'PhamePostController', diff --git a/src/applications/phame/application/PhabricatorPhameApplication.php b/src/applications/phame/application/PhabricatorPhameApplication.php index b2f4fd3a3a..771babd7bc 100644 --- a/src/applications/phame/application/PhabricatorPhameApplication.php +++ b/src/applications/phame/application/PhabricatorPhameApplication.php @@ -38,7 +38,7 @@ final class PhabricatorPhameApplication extends PhabricatorApplication { public function getRoutes() { return array( '/phame/' => array( - '' => 'PhamePostListController', + '' => 'PhameHomeController', 'live/(?P[^/]+)/(?P.*)' => 'PhameBlogLiveController', 'post/' => array( '(?:(?Pdraft|all)/)?' => 'PhamePostListController', diff --git a/src/applications/phame/controller/PhameHomeController.php b/src/applications/phame/controller/PhameHomeController.php new file mode 100644 index 0000000000..fd3ab41cf7 --- /dev/null +++ b/src/applications/phame/controller/PhameHomeController.php @@ -0,0 +1,98 @@ +getViewer(); + + $pager = id(new AphrontCursorPagerView()) + ->readFromRequest($request); + + $posts = id(new PhamePostQuery()) + ->setViewer($viewer) + ->withVisibility(PhameConstants::VISIBILITY_PUBLISHED) + ->executeWithCursorPager($pager); + + $actions = $this->renderActions($viewer); + $action_button = id(new PHUIButtonView()) + ->setTag('a') + ->setText(pht('Search')) + ->setHref('#') + ->setIconFont('fa-search') + ->addClass('phui-mobile-menu') + ->setDropdownMenu($actions); + + $title = pht('Recent Posts'); + + $header = id(new PHUIHeaderView()) + ->setHeader($title) + ->addActionLink($action_button); + + $post_list = id(new PhamePostListView()) + ->setPosts($posts) + ->setViewer($viewer) + ->showBlog(true) + ->setNodata(pht('No Recent Visible Posts.')); + + $crumbs = $this->buildApplicationCrumbs(); + $crumbs->setBorder(true); + $crumbs->addTextCrumb( + pht('Recent Posts'), + $this->getApplicationURI('post/')); + + $page = id(new PHUIDocumentViewPro()) + ->setHeader($header) + ->appendChild($post_list); + + return $this->newPage() + ->setTitle($title) + ->setCrumbs($crumbs) + ->appendChild( + array( + $page, + )); + + + } + + private function renderActions($viewer) { + $actions = id(new PhabricatorActionListView()) + ->setUser($viewer); + + $actions->addAction( + id(new PhabricatorActionView()) + ->setIcon('fa-pencil-square-o') + ->setHref($this->getApplicationURI('post/')) + ->setName(pht('Find Posts'))); + + $actions->addAction( + id(new PhabricatorActionView()) + ->setIcon('fa-star') + ->setHref($this->getApplicationURI('blog/')) + ->setName(pht('Find Blogs'))); + + return $actions; + } + + protected function buildApplicationCrumbs() { + $crumbs = parent::buildApplicationCrumbs(); + + $can_create = $this->hasApplicationCapability( + PhameBlogCreateCapability::CAPABILITY); + + $crumbs->addAction( + id(new PHUIListItemView()) + ->setName(pht('New Blog')) + ->setHref($this->getApplicationURI('/blog/new/')) + ->setIcon('fa-plus-square') + ->setDisabled(!$can_create) + ->setWorkflow(!$can_create)); + + return $crumbs; + } + +} diff --git a/src/applications/phame/controller/blog/PhameBlogViewController.php b/src/applications/phame/controller/blog/PhameBlogViewController.php index 0e12ec1aa8..631c86e27b 100644 --- a/src/applications/phame/controller/blog/PhameBlogViewController.php +++ b/src/applications/phame/controller/blog/PhameBlogViewController.php @@ -52,10 +52,10 @@ final class PhameBlogViewController extends PhameBlogController { ->setStatus($header_icon, $header_color, $header_name) ->addActionLink($action_button); - $post_list = $this->renderPostList( - $posts, - $viewer, - pht('This blog has no visible posts.')); + $post_list = id(new PhamePostListView()) + ->setPosts($posts) + ->setViewer($viewer) + ->setNodata(pht('This blog has no visible posts.')); $crumbs = $this->buildApplicationCrumbs(); $crumbs->setBorder(true); @@ -128,63 +128,6 @@ final class PhameBlogViewController extends PhameBlogController { return $view; } - protected function renderPostList( - array $posts, - PhabricatorUser $viewer, - $nodata) { - assert_instances_of($posts, 'PhamePost'); - - $handle_phids = array(); - foreach ($posts as $post) { - $handle_phids[] = $post->getBloggerPHID(); - if ($post->getBlog()) { - $handle_phids[] = $post->getBlog()->getPHID(); - } - } - $handles = $viewer->loadHandles($handle_phids); - - $list = array(); - foreach ($posts as $post) { - $blogger = $handles[$post->getBloggerPHID()]->renderLink(); - $blogger_uri = $handles[$post->getBloggerPHID()]->getURI(); - $blogger_image = $handles[$post->getBloggerPHID()]->getImageURI(); - - $phame_post = null; - if ($post->getBody()) { - $phame_post = PhabricatorMarkupEngine::summarize($post->getBody()); - $phame_post = new PHUIRemarkupView($viewer, $phame_post); - } else { - $phame_post = phutil_tag('em', array(), pht('Empty Post')); - } - - $blogger = phutil_tag('strong', array(), $blogger); - $date = phabricator_datetime($post->getDatePublished(), $viewer); - if ($post->isDraft()) { - $subtitle = pht('Unpublished draft by %s.', $blogger); - } else { - $subtitle = pht('Written by %s on %s.', $blogger, $date); - } - - $item = id(new PHUIDocumentSummaryView()) - ->setTitle($post->getTitle()) - ->setHref($this->getApplicationURI('/post/view/'.$post->getID().'/')) - ->setSubtitle($subtitle) - ->setImage($blogger_image) - ->setImageHref($blogger_uri) - ->setSummary($phame_post) - ->setDraft($post->isDraft()); - - $list[] = $item; - } - - if (empty($list)) { - $list = id(new PHUIInfoView()) - ->appendChild($nodata); - } - - return $list; - } - private function renderActions(PhameBlog $blog, PhabricatorUser $viewer) { $actions = id(new PhabricatorActionListView()) ->setObject($blog) diff --git a/src/applications/phame/view/PhamePostListView.php b/src/applications/phame/view/PhamePostListView.php new file mode 100644 index 0000000000..b493dcc3e6 --- /dev/null +++ b/src/applications/phame/view/PhamePostListView.php @@ -0,0 +1,110 @@ +posts = $posts; + return $this; + } + + public function setNodata($nodata) { + $this->nodata = $nodata; + return $this; + } + + public function showBlog($show) { + $this->showBlog = $show; + return $this; + } + + public function setViewer($viewer) { + $this->viewer = $viewer; + return $this; + } + + protected function getTagAttributes() { + return array(); + } + + protected function getTagContent() { + $viewer = $this->viewer; + $posts = $this->posts; + $nodata = $this->nodata; + + $handle_phids = array(); + foreach ($posts as $post) { + $handle_phids[] = $post->getBloggerPHID(); + if ($post->getBlog()) { + $handle_phids[] = $post->getBlog()->getPHID(); + } + } + $handles = $viewer->loadHandles($handle_phids); + + $list = array(); + foreach ($posts as $post) { + $blogger = $handles[$post->getBloggerPHID()]->renderLink(); + $blogger_uri = $handles[$post->getBloggerPHID()]->getURI(); + $blogger_image = $handles[$post->getBloggerPHID()]->getImageURI(); + + $phame_post = null; + if ($post->getBody()) { + $phame_post = PhabricatorMarkupEngine::summarize($post->getBody()); + $phame_post = new PHUIRemarkupView($viewer, $phame_post); + } else { + $phame_post = phutil_tag('em', array(), pht('Empty Post')); + } + + $blogger = phutil_tag('strong', array(), $blogger); + $date = phabricator_datetime($post->getDatePublished(), $viewer); + + $blog = null; + if ($post->getBlog()) { + $blog = phutil_tag( + 'a', + array( + 'href' => '/phame/blog/view/'.$post->getBlog()->getID().'/', + ), + $post->getBlog()->getName()); + } + + if ($this->showBlog && $blog) { + if ($post->isDraft()) { + $subtitle = pht('Unpublished draft by %s in %s.', $blogger, $blog); + } else { + $subtitle = pht('By %s on %s in %s.', $blogger, $date, $blog); + } + } else { + if ($post->isDraft()) { + $subtitle = pht('Unpublished draft by %s.', $blogger); + } else { + $subtitle = pht('Written by %s on %s.', $blogger, $date); + } + } + + $item = id(new PHUIDocumentSummaryView()) + ->setTitle($post->getTitle()) + ->setHref('/phame/post/view/'.$post->getID().'/') + ->setSubtitle($subtitle) + ->setImage($blogger_image) + ->setImageHref($blogger_uri) + ->setSummary($phame_post) + ->setDraft($post->isDraft()); + + $list[] = $item; + } + + if (empty($list)) { + $list = id(new PHUIInfoView()) + ->appendChild($nodata); + } + + return $list; + } + +}