1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-19 13:22:42 +01:00

Add Drafts to PhameHome

Summary: Adds a list of your drafts. Fixes T9927y

Test Plan:
Load up home, see my drafts. Fake 0 drafts, see fallback message.

{F1023139}

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Differential Revision: https://secure.phabricator.com/D14756
This commit is contained in:
Chad Little 2015-12-12 13:19:21 -08:00
parent 30255fe420
commit 32a7674c22
5 changed files with 122 additions and 5 deletions

View file

@ -3341,6 +3341,7 @@ phutil_register_library_map(array(
'PhameCreatePostConduitAPIMethod' => 'applications/phame/conduit/PhameCreatePostConduitAPIMethod.php',
'PhameDAO' => 'applications/phame/storage/PhameDAO.php',
'PhameDescriptionView' => 'applications/phame/view/PhameDescriptionView.php',
'PhameDraftListView' => 'applications/phame/view/PhameDraftListView.php',
'PhameHomeController' => 'applications/phame/controller/PhameHomeController.php',
'PhameLiveController' => 'applications/phame/controller/PhameLiveController.php',
'PhamePost' => 'applications/phame/storage/PhamePost.php',
@ -7691,6 +7692,7 @@ phutil_register_library_map(array(
'PhameCreatePostConduitAPIMethod' => 'PhameConduitAPIMethod',
'PhameDAO' => 'PhabricatorLiskDAO',
'PhameDescriptionView' => 'AphrontTagView',
'PhameDraftListView' => 'AphrontTagView',
'PhameHomeController' => 'PhamePostController',
'PhameLiveController' => 'PhameController',
'PhamePost' => array(

View file

@ -57,15 +57,34 @@ final class PhameHomeController extends PhamePostController {
->setHeader($header)
->appendChild($post_list);
$sidebar = id(new PhameBlogListView())
$blog_list = id(new PhameBlogListView())
->setBlogs($blogs)
->setViewer($viewer);
$draft_list = null;
if ($viewer->isLoggedIn()) {
$drafts = id(new PhamePostQuery())
->setViewer($viewer)
->withBloggerPHIDs(array($viewer->getPHID()))
->withBlogPHIDs(mpull($blogs, 'getPHID'))
->withVisibility(PhameConstants::VISIBILITY_DRAFT)
->setLimit(5)
->execute();
$draft_list = id(new PhameDraftListView())
->setPosts($drafts)
->setBlogs($blogs)
->setViewer($viewer);
}
$phame_view = id(new PHUITwoColumnView())
->setMainColumn(array(
$page,
))
->setSideColumn($sidebar)
->setSideColumn(array(
$blog_list,
$draft_list,
))
->setDisplay(PHUITwoColumnView::DISPLAY_LEFT)
->addClass('phame-home-view');

View file

@ -68,6 +68,7 @@ final class PhamePostQuery extends PhabricatorCursorPagedPolicyAwareQuery {
$blog_phids = mpull($posts, 'getBlogPHID');
$blogs = id(new PhameBlogQuery())
->setViewer($this->getViewer())
->needProfileImage(true)
->withPHIDs($blog_phids)
->execute();
$blogs = mpull($blogs, null, 'getPHID');

View file

@ -24,7 +24,6 @@ final class PhameBlogListView extends AphrontTagView {
protected function getTagContent() {
require_celerity_resource('phame-css');
Javelin::initBehavior('phabricator-tooltips');
$list = array();
foreach ($this->blogs as $blog) {
@ -54,8 +53,6 @@ final class PhameBlogListView extends AphrontTagView {
array(
'href' => '/phame/post/edit/?blog='.$blog->getID(),
'class' => 'phame-blog-list-new-post',
'sigil' => 'has-tooltip',
'meta' => array('tip' => pht('New Post')),
),
$icon);

View file

@ -0,0 +1,98 @@
<?php
final class PhameDraftListView extends AphrontTagView {
private $posts;
private $blogs;
private $viewer;
public function setPosts($posts) {
assert_instances_of($posts, 'PhamePost');
$this->posts = $posts;
return $this;
}
public function setBlogs($blogs) {
assert_instances_of($blogs, 'PhameBlog');
$this->blogs = $blogs;
return $this;
}
public function setViewer($viewer) {
$this->viewer = $viewer;
return $this;
}
protected function getTagAttributes() {
$classes = array();
$classes[] = 'phame-blog-list';
return array('class' => implode(' ', $classes));
}
protected function getTagContent() {
require_celerity_resource('phame-css');
$list = array();
foreach ($this->posts as $post) {
$blog = $post->getBlog();
$image_uri = $blog->getProfileImageURI();
$image = phutil_tag(
'a',
array(
'class' => 'phame-blog-list-image',
'style' => 'background-image: url('.$image_uri.');',
'href' => $blog->getViewURI(),
));
$title = phutil_tag(
'a',
array(
'class' => 'phame-blog-list-title',
'href' => $post->getViewURI(),
),
$post->getTitle());
$icon = id(new PHUIIconView())
->setIconFont('fa-pencil-square-o')
->addClass('phame-blog-list-icon');
$edit = phutil_tag(
'a',
array(
'href' => '/phame/post/edit/'.$post->getID().'/',
'class' => 'phame-blog-list-new-post',
),
$icon);
$list[] = phutil_tag(
'div',
array(
'class' => 'phame-blog-list-item',
),
array(
$image,
$title,
$edit,
));
}
if (empty($list)) {
$list = pht('You have no draft posts.');
}
$header = phutil_tag(
'h4',
array(
'class' => 'phame-blog-list-header',
),
phutil_tag(
'a',
array(
'href' => '/phame/post/query/draft/',
),
pht('Drafts')));
return array($header, $list);
}
}