diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 5e9a0c23be..c8b3f97726 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -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', diff --git a/src/applications/badges/application/PhabricatorBadgesApplication.php b/src/applications/badges/application/PhabricatorBadgesApplication.php index ce52eff99a..6eab0c55f8 100644 --- a/src/applications/badges/application/PhabricatorBadgesApplication.php +++ b/src/applications/badges/application/PhabricatorBadgesApplication.php @@ -47,11 +47,14 @@ final class PhabricatorBadgesApplication extends PhabricatorApplication { => 'PhabricatorBadgesArchiveController', 'view/(?:(?P\d+)/)?' => 'PhabricatorBadgesViewController', - 'recipients/(?P[1-9]\d*)/' - => 'PhabricatorBadgesEditRecipientsController', - 'recipients/(?P[1-9]\d*)/remove/' - => 'PhabricatorBadgesRemoveRecipientsController', - + 'recipients/' => array( + '(?P[1-9]\d*)/' + => 'PhabricatorBadgesRecipientsController', + '(?P[1-9]\d*)/add/' + => 'PhabricatorBadgesEditRecipientsController', + '(?P[1-9]\d*)/remove/' + => 'PhabricatorBadgesRemoveRecipientsController', + ), ), ); } diff --git a/src/applications/badges/controller/PhabricatorBadgesEditRecipientsController.php b/src/applications/badges/controller/PhabricatorBadgesEditRecipientsController.php index a73c6777af..2f794e4470 100644 --- a/src/applications/badges/controller/PhabricatorBadgesEditRecipientsController.php +++ b/src/applications/badges/controller/PhabricatorBadgesEditRecipientsController.php @@ -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')); diff --git a/src/applications/badges/controller/PhabricatorBadgesProfileController.php b/src/applications/badges/controller/PhabricatorBadgesProfileController.php new file mode 100644 index 0000000000..97d4b11b93 --- /dev/null +++ b/src/applications/badges/controller/PhabricatorBadgesProfileController.php @@ -0,0 +1,88 @@ +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; + } + +} diff --git a/src/applications/badges/controller/PhabricatorBadgesRecipientsController.php b/src/applications/badges/controller/PhabricatorBadgesRecipientsController.php new file mode 100644 index 0000000000..2b6bb6b10a --- /dev/null +++ b/src/applications/badges/controller/PhabricatorBadgesRecipientsController.php @@ -0,0 +1,58 @@ +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); + } + +} diff --git a/src/applications/badges/controller/PhabricatorBadgesViewController.php b/src/applications/badges/controller/PhabricatorBadgesViewController.php index 05f6286020..3c434ff1d5 100644 --- a/src/applications/badges/controller/PhabricatorBadgesViewController.php +++ b/src/applications/badges/controller/PhabricatorBadgesViewController.php @@ -1,7 +1,7 @@ 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); diff --git a/src/applications/badges/storage/PhabricatorBadgesBadge.php b/src/applications/badges/storage/PhabricatorBadgesBadge.php index d14d49a57c..4cdc4edf61 100644 --- a/src/applications/badges/storage/PhabricatorBadgesBadge.php +++ b/src/applications/badges/storage/PhabricatorBadgesBadge.php @@ -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 )----------------------------------- */ diff --git a/src/applications/badges/storage/PhabricatorBadgesTransaction.php b/src/applications/badges/storage/PhabricatorBadgesTransaction.php index 22505b247e..24509f94bb 100644 --- a/src/applications/badges/storage/PhabricatorBadgesTransaction.php +++ b/src/applications/badges/storage/PhabricatorBadgesTransaction.php @@ -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( diff --git a/src/applications/badges/view/PhabricatorBadgesRecipientsListView.php b/src/applications/badges/view/PhabricatorBadgesRecipientsListView.php index c5d3a56cda..f221487ed2 100644 --- a/src/applications/badges/view/PhabricatorBadgesRecipientsListView.php +++ b/src/applications/badges/view/PhabricatorBadgesRecipientsListView.php @@ -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);