2011-06-12 23:06:17 +00:00
|
|
|
<?php
|
|
|
|
|
2012-03-09 15:46:25 -08:00
|
|
|
final class PhabricatorCountdownViewController
|
2011-06-12 23:06:17 +00:00
|
|
|
extends PhabricatorCountdownController {
|
|
|
|
|
2014-05-17 13:40:20 -07:00
|
|
|
public function shouldAllowPublic() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-07-22 13:35:34 -07:00
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
|
|
$viewer = $request->getViewer();
|
|
|
|
$id = $request->getURIData('id');
|
2013-05-23 06:47:54 -07:00
|
|
|
|
2013-07-22 14:42:25 -07:00
|
|
|
$countdown = id(new PhabricatorCountdownQuery())
|
2015-07-22 13:35:34 -07:00
|
|
|
->setViewer($viewer)
|
|
|
|
->withIDs(array($id))
|
2013-05-23 06:47:54 -07:00
|
|
|
->executeOne();
|
|
|
|
if (!$countdown) {
|
2011-06-12 23:06:17 +00:00
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
2013-07-23 06:16:19 -07:00
|
|
|
$countdown_view = id(new PhabricatorCountdownView())
|
2015-07-22 13:35:34 -07:00
|
|
|
->setUser($viewer)
|
2016-02-26 14:34:51 -08:00
|
|
|
->setCountdown($countdown);
|
2011-06-12 23:06:17 +00:00
|
|
|
|
2013-07-23 06:16:19 -07:00
|
|
|
$id = $countdown->getID();
|
|
|
|
$title = $countdown->getTitle();
|
2011-06-12 23:06:17 +00:00
|
|
|
|
2013-02-25 12:48:55 -08:00
|
|
|
$crumbs = $this
|
|
|
|
->buildApplicationCrumbs()
|
2016-02-26 14:34:51 -08:00
|
|
|
->addTextCrumb("C{$id}")
|
|
|
|
->setBorder(true);
|
2013-07-23 06:16:19 -07:00
|
|
|
|
2015-07-22 13:35:34 -07:00
|
|
|
$epoch = $countdown->getEpoch();
|
|
|
|
if ($epoch >= PhabricatorTime::getNow()) {
|
|
|
|
$icon = 'fa-clock-o';
|
|
|
|
$color = '';
|
|
|
|
$status = pht('Running');
|
|
|
|
} else {
|
|
|
|
$icon = 'fa-check-square-o';
|
|
|
|
$color = 'dark';
|
|
|
|
$status = pht('Launched');
|
|
|
|
}
|
|
|
|
|
2013-09-17 09:12:37 -07:00
|
|
|
$header = id(new PHUIHeaderView())
|
2013-10-16 10:36:08 -07:00
|
|
|
->setHeader($title)
|
2015-07-22 13:35:34 -07:00
|
|
|
->setUser($viewer)
|
|
|
|
->setPolicyObject($countdown)
|
2016-03-03 22:08:00 +00:00
|
|
|
->setStatus($icon, $color, $status)
|
|
|
|
->setHeaderIcon('fa-rocket');
|
2013-07-23 06:16:19 -07:00
|
|
|
|
|
|
|
$actions = $this->buildActionListView($countdown);
|
2016-02-26 14:34:51 -08:00
|
|
|
$properties = $this->buildPropertyListView($countdown);
|
|
|
|
$subheader = $this->buildSubheaderView($countdown);
|
2013-09-28 15:55:38 -07:00
|
|
|
|
2015-07-22 13:35:34 -07:00
|
|
|
$timeline = $this->buildTransactionTimeline(
|
|
|
|
$countdown,
|
|
|
|
new PhabricatorCountdownTransactionQuery());
|
2015-07-24 15:40:55 -07:00
|
|
|
$add_comment = $this->buildCommentForm($countdown);
|
2015-07-22 13:35:34 -07:00
|
|
|
|
2016-02-26 14:34:51 -08:00
|
|
|
$content = array(
|
|
|
|
$countdown_view,
|
|
|
|
$timeline,
|
|
|
|
$add_comment,
|
|
|
|
);
|
2015-11-28 15:41:29 -08:00
|
|
|
|
2016-02-26 14:34:51 -08:00
|
|
|
$view = id(new PHUITwoColumnView())
|
|
|
|
->setHeader($header)
|
|
|
|
->setSubheader($subheader)
|
|
|
|
->setMainColumn($content)
|
|
|
|
->setPropertyList($properties)
|
|
|
|
->setActionList($actions);
|
2015-11-28 15:41:29 -08:00
|
|
|
|
|
|
|
return $this->newPage()
|
|
|
|
->setTitle($title)
|
|
|
|
->setCrumbs($crumbs)
|
|
|
|
->setPageObjectPHIDs(
|
|
|
|
array(
|
|
|
|
$countdown->getPHID(),
|
|
|
|
))
|
|
|
|
->appendChild(
|
|
|
|
array(
|
2016-02-26 14:34:51 -08:00
|
|
|
$view,
|
2015-11-28 15:41:29 -08:00
|
|
|
));
|
2011-06-12 23:06:17 +00:00
|
|
|
}
|
|
|
|
|
2013-07-23 06:16:19 -07:00
|
|
|
private function buildActionListView(PhabricatorCountdown $countdown) {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$viewer = $request->getUser();
|
|
|
|
|
|
|
|
$id = $countdown->getID();
|
|
|
|
|
|
|
|
$view = id(new PhabricatorActionListView())
|
2015-07-18 12:19:32 -07:00
|
|
|
->setObject($countdown)
|
2013-07-23 06:16:19 -07:00
|
|
|
->setUser($viewer);
|
|
|
|
|
|
|
|
$can_edit = PhabricatorPolicyFilter::hasCapability(
|
|
|
|
$viewer,
|
|
|
|
$countdown,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT);
|
|
|
|
|
|
|
|
$view->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
2014-05-12 10:08:32 -07:00
|
|
|
->setIcon('fa-pencil')
|
2013-07-23 06:16:19 -07:00
|
|
|
->setName(pht('Edit Countdown'))
|
|
|
|
->setHref($this->getApplicationURI("edit/{$id}/"))
|
|
|
|
->setDisabled(!$can_edit)
|
|
|
|
->setWorkflow(!$can_edit));
|
|
|
|
|
|
|
|
$view->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
2014-05-12 10:08:32 -07:00
|
|
|
->setIcon('fa-times')
|
2013-07-23 06:16:19 -07:00
|
|
|
->setName(pht('Delete Countdown'))
|
|
|
|
->setHref($this->getApplicationURI("delete/{$id}/"))
|
|
|
|
->setDisabled(!$can_edit)
|
|
|
|
->setWorkflow(true));
|
|
|
|
|
|
|
|
return $view;
|
|
|
|
}
|
|
|
|
|
2013-10-11 07:53:56 -07:00
|
|
|
private function buildPropertyListView(
|
2016-02-26 14:34:51 -08:00
|
|
|
PhabricatorCountdown $countdown) {
|
2015-03-29 18:22:27 -07:00
|
|
|
$viewer = $this->getViewer();
|
2013-10-11 07:53:56 -07:00
|
|
|
$view = id(new PHUIPropertyListView())
|
|
|
|
->setUser($viewer)
|
2016-02-26 14:34:51 -08:00
|
|
|
->setObject($countdown);
|
|
|
|
$view->invokeWillRenderEvent();
|
|
|
|
return $view;
|
|
|
|
}
|
2013-07-23 06:16:19 -07:00
|
|
|
|
2016-02-26 14:34:51 -08:00
|
|
|
private function buildSubheaderView(
|
|
|
|
PhabricatorCountdown $countdown) {
|
|
|
|
$viewer = $this->getViewer();
|
2013-07-23 06:16:19 -07:00
|
|
|
|
2016-02-26 14:34:51 -08:00
|
|
|
$author = $viewer->renderHandle($countdown->getAuthorPHID())->render();
|
|
|
|
$date = phabricator_datetime($countdown->getDateCreated(), $viewer);
|
|
|
|
$author = phutil_tag('strong', array(), $author);
|
2015-07-23 10:56:18 -07:00
|
|
|
|
2016-02-26 14:34:51 -08:00
|
|
|
$person = id(new PhabricatorPeopleQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withPHIDs(array($countdown->getAuthorPHID()))
|
|
|
|
->needProfileImage(true)
|
|
|
|
->executeOne();
|
2015-07-23 10:56:18 -07:00
|
|
|
|
2016-02-26 14:34:51 -08:00
|
|
|
$image_uri = $person->getProfileImageURI();
|
|
|
|
$image_href = '/p/'.$person->getUsername();
|
|
|
|
|
|
|
|
$content = pht('Authored by %s on %s.', $author, $date);
|
|
|
|
|
|
|
|
return id(new PHUIHeadThingView())
|
|
|
|
->setImage($image_uri)
|
|
|
|
->setImageHref($image_href)
|
|
|
|
->setContent($content);
|
2013-07-23 06:16:19 -07:00
|
|
|
}
|
|
|
|
|
2015-07-24 15:40:55 -07:00
|
|
|
private function buildCommentForm(PhabricatorCountdown $countdown) {
|
|
|
|
$viewer = $this->getViewer();
|
|
|
|
|
|
|
|
$is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business');
|
|
|
|
|
|
|
|
$add_comment_header = $is_serious
|
|
|
|
? pht('Add Comment')
|
|
|
|
: pht('Last Words');
|
|
|
|
|
|
|
|
$draft = PhabricatorDraft::newFromUserAndKey(
|
|
|
|
$viewer, $countdown->getPHID());
|
|
|
|
|
|
|
|
return id(new PhabricatorApplicationTransactionCommentView())
|
|
|
|
->setUser($viewer)
|
|
|
|
->setObjectPHID($countdown->getPHID())
|
|
|
|
->setDraft($draft)
|
|
|
|
->setHeaderText($add_comment_header)
|
|
|
|
->setAction($this->getApplicationURI('/comment/'.$countdown->getID().'/'))
|
|
|
|
->setSubmitButtonName(pht('Add Comment'));
|
|
|
|
}
|
|
|
|
|
2011-06-12 23:06:17 +00:00
|
|
|
}
|