1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 14:00:56 +01:00

Build Badges View page into more of a profile

Summary: Ref T10798. Cleans up the UI a little and adds a sidenav.

Test Plan: Review badge and recipients in sandbox.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Maniphest Tasks: T10798

Differential Revision: https://secure.phabricator.com/D17358
This commit is contained in:
Chad Little 2017-02-15 11:32:08 -08:00
parent 2f69cb5fe7
commit 9716e83d60
9 changed files with 187 additions and 54 deletions

View file

@ -2027,8 +2027,10 @@ phutil_register_library_map(array(
'PhabricatorBadgesListController' => 'applications/badges/controller/PhabricatorBadgesListController.php',
'PhabricatorBadgesMailReceiver' => 'applications/badges/mail/PhabricatorBadgesMailReceiver.php',
'PhabricatorBadgesPHIDType' => 'applications/badges/phid/PhabricatorBadgesPHIDType.php',
'PhabricatorBadgesProfileController' => 'applications/badges/controller/PhabricatorBadgesProfileController.php',
'PhabricatorBadgesQuality' => 'applications/badges/constants/PhabricatorBadgesQuality.php',
'PhabricatorBadgesQuery' => 'applications/badges/query/PhabricatorBadgesQuery.php',
'PhabricatorBadgesRecipientsController' => 'applications/badges/controller/PhabricatorBadgesRecipientsController.php',
'PhabricatorBadgesRecipientsListView' => 'applications/badges/view/PhabricatorBadgesRecipientsListView.php',
'PhabricatorBadgesRemoveRecipientsController' => 'applications/badges/controller/PhabricatorBadgesRemoveRecipientsController.php',
'PhabricatorBadgesReplyHandler' => 'applications/badges/mail/PhabricatorBadgesReplyHandler.php',
@ -6942,7 +6944,6 @@ phutil_register_library_map(array(
'PhabricatorPolicyInterface',
'PhabricatorApplicationTransactionInterface',
'PhabricatorSubscribableInterface',
'PhabricatorTokenReceiverInterface',
'PhabricatorFlaggableInterface',
'PhabricatorDestructibleInterface',
'PhabricatorConduitResultInterface',
@ -6964,8 +6965,10 @@ phutil_register_library_map(array(
'PhabricatorBadgesListController' => 'PhabricatorBadgesController',
'PhabricatorBadgesMailReceiver' => 'PhabricatorObjectMailReceiver',
'PhabricatorBadgesPHIDType' => 'PhabricatorPHIDType',
'PhabricatorBadgesProfileController' => 'PhabricatorController',
'PhabricatorBadgesQuality' => 'Phobject',
'PhabricatorBadgesQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhabricatorBadgesRecipientsController' => 'PhabricatorBadgesProfileController',
'PhabricatorBadgesRecipientsListView' => 'AphrontView',
'PhabricatorBadgesRemoveRecipientsController' => 'PhabricatorBadgesController',
'PhabricatorBadgesReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler',
@ -6975,7 +6978,7 @@ phutil_register_library_map(array(
'PhabricatorBadgesTransaction' => 'PhabricatorApplicationTransaction',
'PhabricatorBadgesTransactionComment' => 'PhabricatorApplicationTransactionComment',
'PhabricatorBadgesTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
'PhabricatorBadgesViewController' => 'PhabricatorBadgesController',
'PhabricatorBadgesViewController' => 'PhabricatorBadgesProfileController',
'PhabricatorBarePageUIExample' => 'PhabricatorUIExample',
'PhabricatorBarePageView' => 'AphrontPageView',
'PhabricatorBaseURISetupCheck' => 'PhabricatorSetupCheck',

View file

@ -47,11 +47,14 @@ final class PhabricatorBadgesApplication extends PhabricatorApplication {
=> 'PhabricatorBadgesArchiveController',
'view/(?:(?P<id>\d+)/)?'
=> 'PhabricatorBadgesViewController',
'recipients/(?P<id>[1-9]\d*)/'
=> 'PhabricatorBadgesEditRecipientsController',
'recipients/(?P<id>[1-9]\d*)/remove/'
=> 'PhabricatorBadgesRemoveRecipientsController',
'recipients/' => array(
'(?P<id>[1-9]\d*)/'
=> 'PhabricatorBadgesRecipientsController',
'(?P<id>[1-9]\d*)/add/'
=> 'PhabricatorBadgesEditRecipientsController',
'(?P<id>[1-9]\d*)/remove/'
=> 'PhabricatorBadgesRemoveRecipientsController',
),
),
);
}

View file

@ -22,7 +22,7 @@ final class PhabricatorBadgesEditRecipientsController
return new Aphront404Response();
}
$view_uri = $this->getApplicationURI('view/'.$badge->getID().'/');
$view_uri = $this->getApplicationURI('recipients/'.$badge->getID().'/');
$awards = $badge->getAwards();
$recipient_phids = mpull($awards, 'getRecipientPHID');
@ -79,13 +79,13 @@ final class PhabricatorBadgesEditRecipientsController
->appendControl(
id(new AphrontFormTokenizerControl())
->setName('phids')
->setLabel(pht('Add Recipients'))
->setLabel(pht('Recipients'))
->setDatasource(new PhabricatorPeopleDatasource()));
}
$dialog = id(new AphrontDialogView())
->setUser($viewer)
->setTitle(pht('Award Badges'))
->setTitle(pht('Add Recipients'))
->appendForm($form)
->addCancelButton($view_uri)
->addSubmitButton(pht('Add Recipients'));

View file

@ -0,0 +1,88 @@
<?php
abstract class PhabricatorBadgesProfileController
extends PhabricatorController {
private $badge;
public function setBadge(PhabricatorBadgesBadge $badge) {
$this->badge = $badge;
return $this;
}
public function getBadge() {
return $this->badge;
}
public function buildApplicationMenu() {
return $this->buildSideNavView()->getMenu();
}
protected function buildHeaderView() {
$viewer = $this->getViewer();
$badge = $this->getBadge();
$id = $badge->getID();
if ($badge->isArchived()) {
$status_icon = 'fa-ban';
$status_color = 'dark';
} else {
$status_icon = 'fa-check';
$status_color = 'bluegrey';
}
$status_name = idx(
PhabricatorBadgesBadge::getStatusNameMap(),
$badge->getStatus());
return id(new PHUIHeaderView())
->setHeader($badge->getName())
->setUser($viewer)
->setPolicyObject($badge)
->setStatus($status_icon, $status_color, $status_name)
->setHeaderIcon('fa-trophy');
}
protected function buildApplicationCrumbs() {
$badge = $this->getBadge();
$id = $badge->getID();
$badge_uri = $this->getApplicationURI("/view/{$id}/");
$crumbs = parent::buildApplicationCrumbs();
$crumbs->addTextCrumb($badge->getName(), $badge_uri);
$crumbs->setBorder(true);
return $crumbs;
}
protected function buildSideNavView($filter = null) {
$viewer = $this->getViewer();
$badge = $this->getBadge();
$id = $badge->getID();
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$badge,
PhabricatorPolicyCapability::CAN_EDIT);
$nav = id(new AphrontSideNavFilterView())
->setBaseURI(new PhutilURI($this->getApplicationURI()));
$nav->addLabel(pht('Badge'));
$nav->addFilter(
'view',
pht('View Badge'),
$this->getApplicationURI("/view/{$id}/"),
'fa-trophy');
$nav->addFilter(
'recipients',
pht('View Recipients'),
$this->getApplicationURI("/recipients/{$id}/"),
'fa-group');
$nav->selectFilter($filter);
return $nav;
}
}

View file

@ -0,0 +1,58 @@
<?php
final class PhabricatorBadgesRecipientsController
extends PhabricatorBadgesProfileController {
public function shouldAllowPublic() {
return true;
}
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$id = $request->getURIData('id');
$badge = id(new PhabricatorBadgesQuery())
->setViewer($viewer)
->withIDs(array($id))
->needRecipients(true)
->executeOne();
if (!$badge) {
return new Aphront404Response();
}
$this->setBadge($badge);
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb(pht('Recipients'));
$crumbs->setBorder(true);
$title = $badge->getName();
$header = $this->buildHeaderView();
$awards = $badge->getAwards();
$recipient_phids = mpull($awards, 'getRecipientPHID');
$recipient_phids = array_reverse($recipient_phids);
$handles = $this->loadViewerHandles($recipient_phids);
$recipient_list = id(new PhabricatorBadgesRecipientsListView())
->setBadge($badge)
->setHandles($handles)
->setUser($viewer);
$view = id(new PHUITwoColumnView())
->setHeader($header)
->setFooter(array(
$recipient_list,
));
$navigation = $this->buildSideNavView('recipients');
return $this->newPage()
->setTitle($title)
->setCrumbs($crumbs)
->setPageObjectPHIDs(array($badge->getPHID()))
->setNavigation($navigation)
->appendChild($view);
}
}

View file

@ -1,7 +1,7 @@
<?php
final class PhabricatorBadgesViewController
extends PhabricatorBadgesController {
extends PhabricatorBadgesProfileController {
public function shouldAllowPublic() {
return true;
@ -14,35 +14,17 @@ final class PhabricatorBadgesViewController
$badge = id(new PhabricatorBadgesQuery())
->setViewer($viewer)
->withIDs(array($id))
->needRecipients(true)
->executeOne();
if (!$badge) {
return new Aphront404Response();
}
$this->setBadge($badge);
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb($badge->getName());
$crumbs->setBorder(true);
$title = $badge->getName();
if ($badge->isArchived()) {
$status_icon = 'fa-ban';
$status_color = 'dark';
} else {
$status_icon = 'fa-check';
$status_color = 'bluegrey';
}
$status_name = idx(
PhabricatorBadgesBadge::getStatusNameMap(),
$badge->getStatus());
$header = id(new PHUIHeaderView())
->setHeader($badge->getName())
->setUser($viewer)
->setPolicyObject($badge)
->setStatus($status_icon, $status_color, $status_name)
->setHeaderIcon('fa-trophy');
$header = $this->buildHeaderView();
$curtain = $this->buildCurtain($badge);
$details = $this->buildDetailsView($badge);
@ -50,16 +32,6 @@ final class PhabricatorBadgesViewController
$badge,
new PhabricatorBadgesTransactionQuery());
$awards = $badge->getAwards();
$recipient_phids = mpull($awards, 'getRecipientPHID');
$recipient_phids = array_reverse($recipient_phids);
$handles = $this->loadViewerHandles($recipient_phids);
$recipient_list = id(new PhabricatorBadgesRecipientsListView())
->setBadge($badge)
->setHandles($handles)
->setUser($viewer);
$comment_view = id(new PhabricatorBadgesEditEngine())
->setViewer($viewer)
->buildEditEngineCommentView($badge);
@ -68,16 +40,18 @@ final class PhabricatorBadgesViewController
->setHeader($header)
->setCurtain($curtain)
->setMainColumn(array(
$recipient_list,
$timeline,
$comment_view,
))
->addPropertySection(pht('Description'), $details);
$navigation = $this->buildSideNavView('view');
return $this->newPage()
->setTitle($title)
->setCrumbs($crumbs)
->setPageObjectPHIDs(array($badge->getPHID()))
->setNavigation($navigation)
->appendChild($view);
}
@ -116,7 +90,7 @@ final class PhabricatorBadgesViewController
$id = $badge->getID();
$edit_uri = $this->getApplicationURI("/edit/{$id}/");
$archive_uri = $this->getApplicationURI("/archive/{$id}/");
$award_uri = $this->getApplicationURI("/recipients/{$id}/");
$award_uri = $this->getApplicationURI("/recipients/{$id}/add/");
$curtain = $this->newCurtainView($badge);

View file

@ -5,7 +5,6 @@ final class PhabricatorBadgesBadge extends PhabricatorBadgesDAO
PhabricatorPolicyInterface,
PhabricatorApplicationTransactionInterface,
PhabricatorSubscribableInterface,
PhabricatorTokenReceiverInterface,
PhabricatorFlaggableInterface,
PhabricatorDestructibleInterface,
PhabricatorConduitResultInterface,
@ -161,14 +160,6 @@ final class PhabricatorBadgesBadge extends PhabricatorBadgesDAO
}
/* -( PhabricatorTokenReceiverInterface )---------------------------------- */
public function getUsersToNotifyOfTokenGiven() {
return array($this->getCreatorPHID());
}
/* -( PhabricatorDestructibleInterface )----------------------------------- */

View file

@ -38,6 +38,10 @@ final class PhabricatorBadgesTransaction
$type = $this->getTransactionType();
switch ($type) {
case PhabricatorTransactions::TYPE_CREATE:
return pht(
'%s created this badge.',
$this->renderHandleLink($author_phid));
case self::TYPE_NAME:
if ($old === null) {
return pht(

View file

@ -27,6 +27,18 @@ final class PhabricatorBadgesRecipientsListView extends AphrontView {
$badge,
PhabricatorPolicyCapability::CAN_EDIT);
$award_button = id(new PHUIButtonView())
->setTag('a')
->setIcon('fa-plus')
->setText(pht('Add Recipents'))
->setWorkflow(true)
->setDisabled(!$can_edit)
->setHref('/badges/recipients/'.$badge->getID().'/add/');
$header = id(new PHUIHeaderView())
->setHeader(pht('Recipients'))
->addActionLink($award_button);
$list = id(new PHUIObjectItemListView())
->setNoDataString(pht('This badge does not have any recipients.'))
->setFlush(true);
@ -62,7 +74,7 @@ final class PhabricatorBadgesRecipientsListView extends AphrontView {
}
$box = id(new PHUIObjectBoxView())
->setHeaderText(pht('Recipients'))
->setHeader($header)
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
->setObjectList($list);