1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 08:52:39 +01:00

Update Phortune Merchant UI

Summary: Builds out Phortune Merchant pages to have a sidenav and sub-pages for further expansion. For now this links Orders and Subscriptions to the query engine pages, but could be split out to be more informative (unpaid, upcoming, etc).

Test Plan:
Create a new merchant, edit some information, add a manager in new UI, edit logo, click through to subscriptions, orders.

{F4883013}

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Differential Revision: https://secure.phabricator.com/D17655
This commit is contained in:
Chad Little 2017-04-11 10:57:40 -07:00
parent 5dd18a7ec1
commit 58a127f2f9
8 changed files with 292 additions and 37 deletions

View file

@ -4369,6 +4369,7 @@ phutil_register_library_map(array(
'PhortuneMemberHasAccountEdgeType' => 'applications/phortune/edge/PhortuneMemberHasAccountEdgeType.php',
'PhortuneMemberHasMerchantEdgeType' => 'applications/phortune/edge/PhortuneMemberHasMerchantEdgeType.php',
'PhortuneMerchant' => 'applications/phortune/storage/PhortuneMerchant.php',
'PhortuneMerchantAddManagerController' => 'applications/phortune/controller/merchant/PhortuneMerchantAddManagerController.php',
'PhortuneMerchantCapability' => 'applications/phortune/capability/PhortuneMerchantCapability.php',
'PhortuneMerchantContactInfoTransaction' => 'applications/phortune/xaction/PhortuneMerchantContactInfoTransaction.php',
'PhortuneMerchantController' => 'applications/phortune/controller/merchant/PhortuneMerchantController.php',
@ -4381,10 +4382,12 @@ phutil_register_library_map(array(
'PhortuneMerchantInvoiceEmailTransaction' => 'applications/phortune/xaction/PhortuneMerchantInvoiceEmailTransaction.php',
'PhortuneMerchantInvoiceFooterTransaction' => 'applications/phortune/xaction/PhortuneMerchantInvoiceFooterTransaction.php',
'PhortuneMerchantListController' => 'applications/phortune/controller/merchant/PhortuneMerchantListController.php',
'PhortuneMerchantManagerController' => 'applications/phortune/controller/merchant/PhortuneMerchantManagerController.php',
'PhortuneMerchantNameTransaction' => 'applications/phortune/xaction/PhortuneMerchantNameTransaction.php',
'PhortuneMerchantPHIDType' => 'applications/phortune/phid/PhortuneMerchantPHIDType.php',
'PhortuneMerchantPictureController' => 'applications/phortune/controller/merchant/PhortuneMerchantPictureController.php',
'PhortuneMerchantPictureTransaction' => 'applications/phortune/xaction/PhortuneMerchantPictureTransaction.php',
'PhortuneMerchantProfileController' => 'applications/phortune/controller/merchant/PhortuneMerchantProfileController.php',
'PhortuneMerchantQuery' => 'applications/phortune/query/PhortuneMerchantQuery.php',
'PhortuneMerchantSearchEngine' => 'applications/phortune/query/PhortuneMerchantSearchEngine.php',
'PhortuneMerchantTransaction' => 'applications/phortune/storage/PhortuneMerchantTransaction.php',
@ -9832,6 +9835,7 @@ phutil_register_library_map(array(
'PhabricatorApplicationTransactionInterface',
'PhabricatorPolicyInterface',
),
'PhortuneMerchantAddManagerController' => 'PhortuneController',
'PhortuneMerchantCapability' => 'PhabricatorPolicyCapability',
'PhortuneMerchantContactInfoTransaction' => 'PhortuneMerchantTransactionType',
'PhortuneMerchantController' => 'PhortuneController',
@ -9840,20 +9844,22 @@ phutil_register_library_map(array(
'PhortuneMerchantEditEngine' => 'PhabricatorEditEngine',
'PhortuneMerchantEditor' => 'PhabricatorApplicationTransactionEditor',
'PhortuneMerchantHasMemberEdgeType' => 'PhabricatorEdgeType',
'PhortuneMerchantInvoiceCreateController' => 'PhortuneMerchantController',
'PhortuneMerchantInvoiceCreateController' => 'PhortuneMerchantProfileController',
'PhortuneMerchantInvoiceEmailTransaction' => 'PhortuneMerchantTransactionType',
'PhortuneMerchantInvoiceFooterTransaction' => 'PhortuneMerchantTransactionType',
'PhortuneMerchantListController' => 'PhortuneMerchantController',
'PhortuneMerchantManagerController' => 'PhortuneMerchantProfileController',
'PhortuneMerchantNameTransaction' => 'PhortuneMerchantTransactionType',
'PhortuneMerchantPHIDType' => 'PhabricatorPHIDType',
'PhortuneMerchantPictureController' => 'PhortuneMerchantController',
'PhortuneMerchantPictureController' => 'PhortuneMerchantProfileController',
'PhortuneMerchantPictureTransaction' => 'PhortuneMerchantTransactionType',
'PhortuneMerchantProfileController' => 'PhortuneController',
'PhortuneMerchantQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhortuneMerchantSearchEngine' => 'PhabricatorApplicationSearchEngine',
'PhortuneMerchantTransaction' => 'PhabricatorModularTransaction',
'PhortuneMerchantTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
'PhortuneMerchantTransactionType' => 'PhabricatorModularTransactionType',
'PhortuneMerchantViewController' => 'PhortuneMerchantController',
'PhortuneMerchantViewController' => 'PhortuneMerchantProfileController',
'PhortuneMonthYearExpiryControl' => 'AphrontFormControl',
'PhortuneOrderTableView' => 'AphrontView',
'PhortunePayPalPaymentProvider' => 'PhortunePaymentProvider',

View file

@ -88,6 +88,10 @@ final class PhabricatorPhortuneApplication extends PhabricatorApplication {
=> 'PhortuneMerchantEditController',
'orders/(?P<merchantID>\d+)/(?:query/(?P<queryKey>[^/]+)/)?'
=> 'PhortuneCartListController',
'manager/' => array(
'(?:(?P<id>\d+)/)?' => 'PhortuneMerchantManagerController',
'add/(?:(?P<id>\d+)/)?' => 'PhortuneMerchantAddManagerController',
),
'(?P<merchantID>\d+)/' => array(
'cart/(?P<id>\d+)/' => array(
'' => 'PhortuneCartViewController',

View file

@ -0,0 +1,76 @@
<?php
final class PhortuneMerchantAddManagerController extends PhortuneController {
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$id = $request->getURIData('id');
$merchant = id(new PhortuneMerchantQuery())
->setViewer($viewer)
->withIDs(array($id))
->needProfileImage(true)
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->executeOne();
if (!$merchant) {
return new Aphront404Response();
}
$v_members = array();
$e_members = null;
$merchant_uri = $this->getApplicationURI("/merchant/manager/{$id}/");
if ($request->isFormPost()) {
$xactions = array();
$v_members = $request->getArr('memberPHIDs');
$type_edge = PhabricatorTransactions::TYPE_EDGE;
$xactions[] = id(new PhortuneMerchantTransaction())
->setTransactionType($type_edge)
->setMetadataValue(
'edge:type',
PhortuneMerchantHasMemberEdgeType::EDGECONST)
->setNewValue(
array(
'+' => array_fuse($v_members),
));
$editor = id(new PhortuneMerchantEditor())
->setActor($viewer)
->setContentSourceFromRequest($request)
->setContinueOnNoEffect(true);
try {
$editor->applyTransactions($merchant, $xactions);
return id(new AphrontRedirectResponse())->setURI($merchant_uri);
} catch (PhabricatorApplicationTransactionValidationException $ex) {
$validation_exception = $ex;
$e_members = $ex->getShortMessage($type_edge);
}
}
$form = id(new AphrontFormView())
->setUser($viewer)
->appendControl(
id(new AphrontFormTokenizerControl())
->setDatasource(new PhabricatorPeopleDatasource())
->setLabel(pht('Members'))
->setName('memberPHIDs')
->setValue($v_members)
->setError($e_members));
return $this->newDialog()
->setTitle(pht('Add New Manager'))
->appendForm($form)
->setWidth(AphrontDialogView::WIDTH_FORM)
->addCancelButton($merchant_uri)
->addSubmitButton(pht('Add Manager'));
}
}

View file

@ -1,7 +1,7 @@
<?php
final class PhortuneMerchantInvoiceCreateController
extends PhortuneMerchantController {
extends PhortuneMerchantProfileController {
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getUser();
@ -11,6 +11,7 @@ final class PhortuneMerchantInvoiceCreateController
return new Aphront404Response();
}
$this->setMerchant($merchant);
$merchant_id = $merchant->getID();
$cancel_uri = $this->getApplicationURI("/merchant/{$merchant_id}/");
@ -88,8 +89,7 @@ final class PhortuneMerchantInvoiceCreateController
$title = pht('New Invoice');
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb($merchant->getName());
$crumbs->setBorder(true);
$crumbs->addTextCrumb($title);
$v_title = $request->getStr('title');
$e_title = true;
@ -245,9 +245,12 @@ final class PhortuneMerchantInvoiceCreateController
$box,
));
$navigation = $this->buildSideNavView('orders');
return $this->newPage()
->setTitle($title)
->setCrumbs($crumbs)
->setNavigation($navigation)
->appendChild($view);
}

View file

@ -0,0 +1,91 @@
<?php
final class PhortuneMerchantManagerController
extends PhortuneMerchantProfileController {
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$id = $request->getURIData('id');
$merchant = id(new PhortuneMerchantQuery())
->setViewer($viewer)
->withIDs(array($id))
->needProfileImage(true)
->executeOne();
if (!$merchant) {
return new Aphront404Response();
}
$this->setMerchant($merchant);
$header = $this->buildHeaderView();
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb(pht('Managers'));
$header = $this->buildHeaderView();
$members = $this->buildMembersSection($merchant);
$view = id(new PHUITwoColumnView())
->setHeader($header)
->setFooter(array(
$members,
));
$navigation = $this->buildSideNavView('managers');
return $this->newPage()
->setTitle(pht('Managers'))
->setCrumbs($crumbs)
->setNavigation($navigation)
->appendChild($view);
}
private function buildMembersSection(PhortuneMerchant $merchant) {
$viewer = $this->getViewer();
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$merchant,
PhabricatorPolicyCapability::CAN_EDIT);
$id = $merchant->getID();
$add = id(new PHUIButtonView())
->setTag('a')
->setText(pht('New Manager'))
->setIcon('fa-plus')
->setWorkflow(true)
->setHref("/phortune/merchant/manager/add/{$id}/");
$header = id(new PHUIHeaderView())
->setHeader(pht('Merchant Account Managers'))
->addActionLink($add);
$list = id(new PHUIObjectItemListView())
->setUser($viewer);
$member_phids = $merchant->getMemberPHIDs();
$handles = $viewer->loadHandles($member_phids);
foreach ($member_phids as $member_phid) {
$image_uri = $handles[$member_phid]->getImageURI();
$image_href = $handles[$member_phid]->getURI();
$person = $handles[$member_phid];
$member = id(new PHUIObjectItemView())
->setImageURI($image_uri)
->setHref($image_href)
->setHeader($person->getFullName())
->addAttribute(pht('Merchant Manager'));
$list->addItem($member);
}
return id(new PHUIObjectBoxView())
->setHeader($header)
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
->setObjectList($list);
}
}

View file

@ -1,7 +1,7 @@
<?php
final class PhortuneMerchantPictureController
extends PhortuneMerchantController {
extends PhortuneMerchantProfileController {
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
@ -21,6 +21,7 @@ final class PhortuneMerchantPictureController
return new Aphront404Response();
}
$this->setMerchant($merchant);
$uri = $merchant->getURI();
$supported_formats = PhabricatorFile::getTransformableImageFormats();
@ -92,7 +93,7 @@ final class PhortuneMerchantPictureController
}
}
$title = pht('Edit Merchant Picture');
$title = pht('Edit Logo');
$form = id(new PHUIFormLayoutView())
->setUser($viewer);
@ -208,12 +209,10 @@ final class PhortuneMerchantPictureController
->setForm($upload_form);
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb($merchant->getName(), $uri);
$crumbs->addTextCrumb(pht('Merchant Logo'));
$crumbs->setBorder(true);
$crumbs->addTextCrumb(pht('Edit Logo'));
$header = id(new PHUIHeaderView())
->setHeader(pht('Edit Merchant Logo'))
->setHeader(pht('Edit Logo'))
->setHeaderIcon('fa-camera');
$view = id(new PHUITwoColumnView())
@ -223,9 +222,12 @@ final class PhortuneMerchantPictureController
$upload_box,
));
$navigation = $this->buildSideNavView();
return $this->newPage()
->setTitle($title)
->setCrumbs($crumbs)
->setNavigation($navigation)
->appendChild(
array(
$view,

View file

@ -0,0 +1,92 @@
<?php
abstract class PhortuneMerchantProfileController
extends PhortuneController {
private $merchant;
public function setMerchant(PhortuneMerchant $merchant) {
$this->merchant = $merchant;
return $this;
}
public function getMerchant() {
return $this->merchant;
}
public function buildApplicationMenu() {
return $this->buildSideNavView()->getMenu();
}
protected function buildHeaderView() {
$viewer = $this->getViewer();
$merchant = $this->getMerchant();
$title = $merchant->getName();
$header = id(new PHUIHeaderView())
->setHeader($title)
->setUser($viewer)
->setPolicyObject($merchant)
->setImage($merchant->getProfileImageURI());
return $header;
}
protected function buildApplicationCrumbs() {
$merchant = $this->getMerchant();
$id = $merchant->getID();
$merchant_uri = $this->getApplicationURI("/merchant/{$id}/");
$crumbs = parent::buildApplicationCrumbs();
$crumbs->addTextCrumb($merchant->getName(), $merchant_uri);
$crumbs->setBorder(true);
return $crumbs;
}
protected function buildSideNavView($filter = null) {
$viewer = $this->getViewer();
$merchant = $this->getMerchant();
$id = $merchant->getID();
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$merchant,
PhabricatorPolicyCapability::CAN_EDIT);
$nav = id(new AphrontSideNavFilterView())
->setBaseURI(new PhutilURI($this->getApplicationURI()));
$nav->addLabel(pht('Merchant'));
$nav->addFilter(
'overview',
pht('Overview'),
$this->getApplicationURI("/merchant/{$id}/"),
'fa-building-o');
if ($can_edit) {
$nav->addFilter(
'orders',
pht('Orders'),
$this->getApplicationURI("merchant/orders/{$id}/"),
'fa-retweet');
$nav->addFilter(
'subscriptions',
pht('Subscriptions'),
$this->getApplicationURI("merchant/{$id}/subscription/"),
'fa-shopping-cart');
$nav->addFilter(
'managers',
pht('Managers'),
$this->getApplicationURI("/merchant/manager/{$id}/"),
'fa-group');
}
$nav->selectFilter($filter);
return $nav;
}
}

View file

@ -1,7 +1,7 @@
<?php
final class PhortuneMerchantViewController
extends PhortuneMerchantController {
extends PhortuneMerchantProfileController {
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
@ -16,21 +16,15 @@ final class PhortuneMerchantViewController
return new Aphront404Response();
}
$this->setMerchant($merchant);
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb($merchant->getName());
$crumbs->setBorder(true);
$header = $this->buildHeaderView();
$title = pht(
'Merchant %d %s',
$merchant->getID(),
$merchant->getName());
$header = id(new PHUIHeaderView())
->setHeader($merchant->getName())
->setUser($viewer)
->setPolicyObject($merchant)
->setImage($merchant->getProfileImageURI());
$providers = id(new PhortunePaymentProviderConfigQuery())
->setViewer($viewer)
->withMerchantPHIDs(array($merchant->getPHID()))
@ -48,6 +42,8 @@ final class PhortuneMerchantViewController
new PhortuneMerchantTransactionQuery());
$timeline->setShouldTerminate(true);
$navigation = $this->buildSideNavView('overview');
$view = id(new PHUITwoColumnView())
->setHeader($header)
->setCurtain($curtain)
@ -60,6 +56,7 @@ final class PhortuneMerchantViewController
return $this->newPage()
->setTitle($title)
->setCrumbs($crumbs)
->setNavigation($navigation)
->appendChild($view);
}
@ -196,22 +193,6 @@ final class PhortuneMerchantViewController
->setWorkflow(!$can_edit)
->setHref($this->getApplicationURI("merchant/picture/{$id}/")));
$curtain->addAction(
id(new PhabricatorActionView())
->setName(pht('View Orders'))
->setIcon('fa-shopping-cart')
->setHref($this->getApplicationURI("merchant/orders/{$id}/"))
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit));
$curtain->addAction(
id(new PhabricatorActionView())
->setName(pht('View Subscriptions'))
->setIcon('fa-moon-o')
->setHref($this->getApplicationURI("merchant/{$id}/subscription/"))
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit));
$curtain->addAction(
id(new PhabricatorActionView())
->setName(pht('New Invoice'))