diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 0a5debf55c..d0c6c0d9cb 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -2514,8 +2514,9 @@ phutil_register_library_map(array( 'ReleephPHIDTypeBranch' => 'applications/releeph/phid/ReleephPHIDTypeBranch.php', 'ReleephPHIDTypeProject' => 'applications/releeph/phid/ReleephPHIDTypeProject.php', 'ReleephPHIDTypeRequest' => 'applications/releeph/phid/ReleephPHIDTypeRequest.php', + 'ReleephProductActionController' => 'applications/releeph/controller/project/ReleephProductActionController.php', + 'ReleephProductController' => 'applications/releeph/controller/project/ReleephProductController.php', 'ReleephProject' => 'applications/releeph/storage/ReleephProject.php', - 'ReleephProjectActionController' => 'applications/releeph/controller/project/ReleephProjectActionController.php', 'ReleephProjectController' => 'applications/releeph/controller/ReleephProjectController.php', 'ReleephProjectCreateController' => 'applications/releeph/controller/project/ReleephProjectCreateController.php', 'ReleephProjectEditController' => 'applications/releeph/controller/project/ReleephProjectEditController.php', @@ -5487,12 +5488,13 @@ phutil_register_library_map(array( 'ReleephPHIDTypeBranch' => 'PhabricatorPHIDType', 'ReleephPHIDTypeProject' => 'PhabricatorPHIDType', 'ReleephPHIDTypeRequest' => 'PhabricatorPHIDType', + 'ReleephProductActionController' => 'ReleephProductController', + 'ReleephProductController' => 'ReleephController', 'ReleephProject' => array( 0 => 'ReleephDAO', 1 => 'PhabricatorPolicyInterface', ), - 'ReleephProjectActionController' => 'ReleephProjectController', 'ReleephProjectController' => 'ReleephController', 'ReleephProjectCreateController' => 'ReleephProjectController', 'ReleephProjectEditController' => 'ReleephProjectController', diff --git a/src/applications/releeph/application/PhabricatorApplicationReleeph.php b/src/applications/releeph/application/PhabricatorApplicationReleeph.php index 46fcd86f37..66f1345d73 100644 --- a/src/applications/releeph/application/PhabricatorApplicationReleeph.php +++ b/src/applications/releeph/application/PhabricatorApplicationReleeph.php @@ -41,7 +41,7 @@ final class PhabricatorApplicationReleeph extends PhabricatorApplication { '(?:query/(?P[^/]+)/)?' => 'ReleephProjectViewController', 'edit/' => 'ReleephProjectEditController', 'cutbranch/' => 'ReleephBranchCreateController', - 'action/(?P.+)/' => 'ReleephProjectActionController', + 'action/(?P.+)/' => 'ReleephProductActionController', 'history/' => 'ReleephProjectHistoryController', ), ), diff --git a/src/applications/releeph/controller/project/ReleephProductActionController.php b/src/applications/releeph/controller/project/ReleephProductActionController.php new file mode 100644 index 0000000000..3761c808c6 --- /dev/null +++ b/src/applications/releeph/controller/project/ReleephProductActionController.php @@ -0,0 +1,78 @@ +id = $data['projectID']; + $this->action = $data['action']; + } + + public function processRequest() { + $request = $this->getRequest(); + $viewer = $request->getUser(); + + $product = id(new ReleephProjectQuery()) + ->withIDs(array($this->id)) + ->requireCapabilities( + array( + PhabricatorPolicyCapability::CAN_VIEW, + PhabricatorPolicyCapability::CAN_EDIT, + )) + ->setViewer($viewer) + ->executeOne(); + if (!$product) { + return new Aphront404Response(); + } + + $this->setProduct($product); + + $product_id = $product->getID(); + $product_uri = $this->getProductViewURI($product); + + $action = $this->action; + switch ($action) { + case 'deactivate': + case 'activate': + break; + default: + throw new Aphront404Response(); + } + + if ($request->isFormPost()) { + if ($action == 'activate') { + $product->setIsActive(1)->save(); + } else { + $product->deactivate($viewer)->save(); + } + + return id(new AphrontRedirectResponse())->setURI($product_uri); + } + + if ($action == 'activate') { + $title = pht('Activate Product?'); + $body = pht( + 'Reactivate the product %s?', + phutil_tag('strong', array(), $product->getName())); + $submit = pht('Reactivate Product'); + $short = pht('Deactivate'); + } else { + $title = pht('Really Deactivate Product?'); + $body = pht( + 'Really deactivate the product %s?', + phutil_tag('strong', array(), $product->getName())); + $submit = pht('Deactivate Product'); + $short = pht('Activate'); + } + + return $this->newDialog() + ->setTitle($title) + ->setShortTitle($short) + ->appendParagraph($body) + ->addSubmitButton($submit) + ->addCancelButton($product_uri); + } + +} diff --git a/src/applications/releeph/controller/project/ReleephProductController.php b/src/applications/releeph/controller/project/ReleephProductController.php new file mode 100644 index 0000000000..e14b98e80c --- /dev/null +++ b/src/applications/releeph/controller/project/ReleephProductController.php @@ -0,0 +1,30 @@ +product = $product; + return $this; + } + + protected function getProductViewURI(ReleephProject $product) { + return $this->getApplicationURI('project/'.$product->getID().'/'); + } + + protected function buildApplicationCrumbs() { + $crumbs = parent::buildApplicationCrumbs(); + + $product = $this->product; + if ($product) { + $crumbs->addTextCrumb( + $product->getName(), + $this->getProductViewURI($product)); + } + + return $crumbs; + } + + +} diff --git a/src/applications/releeph/controller/project/ReleephProjectActionController.php b/src/applications/releeph/controller/project/ReleephProjectActionController.php deleted file mode 100644 index 40e47f4b4b..0000000000 --- a/src/applications/releeph/controller/project/ReleephProjectActionController.php +++ /dev/null @@ -1,58 +0,0 @@ -action = $data['action']; - } - - public function processRequest() { - $request = $this->getRequest(); - $viewer = $request->getUser(); - - $action = $this->action; - - $project = id(new ReleephProjectQuery()) - ->withIDs(array($this->getReleephProject()->getID())) - ->requireCapabilities( - array( - PhabricatorPolicyCapability::CAN_VIEW, - PhabricatorPolicyCapability::CAN_EDIT, - )) - ->setViewer($viewer) - ->executeOne(); - if (!$project) { - return new Aphront404Response(); - } - - $project_id = $project->getID(); - $project_uri = $this->getApplicationURI("project/{$project_id}/"); - - switch ($action) { - case 'deactivate': - if ($request->isDialogFormPost()) { - $project->deactivate($viewer)->save(); - return id(new AphrontRedirectResponse())->setURI($project_uri); - } - - $dialog = id(new AphrontDialogView()) - ->setUser($request->getUser()) - ->setTitle(pht('Really deactivate Releeph Project?')) - ->appendChild(phutil_tag( - 'p', - array(), - pht('Really deactivate the Releeph project: %s?', - $project->getName()))) - ->addSubmitButton(pht('Deactivate Project')) - ->addCancelButton($project_uri); - - return id(new AphrontDialogResponse())->setDialog($dialog); - case 'activate': - $project->setIsActive(1)->save(); - return id(new AphrontRedirectResponse())->setURI($project_uri); - } - } -} diff --git a/src/applications/releeph/controller/project/ReleephProjectViewController.php b/src/applications/releeph/controller/project/ReleephProjectViewController.php index bd58a01f27..acee8f207e 100644 --- a/src/applications/releeph/controller/project/ReleephProjectViewController.php +++ b/src/applications/releeph/controller/project/ReleephProjectViewController.php @@ -177,13 +177,6 @@ final class ReleephProjectViewController extends ReleephProjectController PhabricatorPolicyCapability::CAN_EDIT); $edit_uri = $this->getApplicationURI("project/{$id}/edit/"); - - $deactivate_uri = "project/{$id}/action/deactivate/"; - $deactivate_uri = $this->getApplicationURI($deactivate_uri); - - $reactivate_uri = "project/{$id}/action/activate/"; - $reactivate_uri = $this->getApplicationURI($reactivate_uri); - $history_uri = $this->getApplicationURI("project/{$id}/history/"); $actions->addAction( @@ -195,25 +188,23 @@ final class ReleephProjectViewController extends ReleephProjectController ->setWorkflow(!$can_edit)); if ($project->getIsActive()) { - $actions->addAction( - id(new PhabricatorActionView()) - ->setName(pht('Deactivate Project')) - ->setHref($deactivate_uri) - ->setIcon('delete') - ->setDisabled(!$can_edit) - ->setWorkflow(true)); + $status_name = pht('Deactivate Product'); + $status_href = "project/{$id}/action/deactivate/"; + $status_icon = 'delete'; } else { - $actions->addAction( - id(new PhabricatorActionView()) - ->setName(pht('Reactivate Project')) - ->setHref($reactivate_uri) - ->setIcon('new') - ->setUser($viewer) - ->setRenderAsForm(true) - ->setDisabled(!$can_edit) - ->setWorkflow(true)); + $status_name = pht('Reactivate Product'); + $status_href = "project/{$id}/action/activate/"; + $status_icon = 'new'; } + $actions->addAction( + id(new PhabricatorActionView()) + ->setName($status_name) + ->setHref($this->getApplicationURI($status_href)) + ->setIcon($status_icon) + ->setDisabled(!$can_edit) + ->setWorkflow(true)); + $actions->addAction( id(new PhabricatorActionView()) ->setName(pht('View History'))