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

Allow Nuance item types to provide actions for items

Summary:
Ref T10537. This allows item types to expose item actions. Eventually these actions might be things like "promote to task", "tweet reply", "ban user forever", etc.

For now, provide a simple action which shows a raw item in a dialog.

Test Plan: {F1185573}

Reviewers: chad

Reviewed By: chad

Subscribers: Luke081515.2

Maniphest Tasks: T10537

Differential Revision: https://secure.phabricator.com/D15504
This commit is contained in:
epriestley 2016-03-21 17:38:22 -07:00
parent 47dedfb152
commit e523585811
6 changed files with 115 additions and 0 deletions

View file

@ -1439,6 +1439,7 @@ phutil_register_library_map(array(
'NuanceImportCursorDataQuery' => 'applications/nuance/query/NuanceImportCursorDataQuery.php', 'NuanceImportCursorDataQuery' => 'applications/nuance/query/NuanceImportCursorDataQuery.php',
'NuanceImportCursorPHIDType' => 'applications/nuance/phid/NuanceImportCursorPHIDType.php', 'NuanceImportCursorPHIDType' => 'applications/nuance/phid/NuanceImportCursorPHIDType.php',
'NuanceItem' => 'applications/nuance/storage/NuanceItem.php', 'NuanceItem' => 'applications/nuance/storage/NuanceItem.php',
'NuanceItemActionController' => 'applications/nuance/controller/NuanceItemActionController.php',
'NuanceItemController' => 'applications/nuance/controller/NuanceItemController.php', 'NuanceItemController' => 'applications/nuance/controller/NuanceItemController.php',
'NuanceItemEditor' => 'applications/nuance/editor/NuanceItemEditor.php', 'NuanceItemEditor' => 'applications/nuance/editor/NuanceItemEditor.php',
'NuanceItemListController' => 'applications/nuance/controller/NuanceItemListController.php', 'NuanceItemListController' => 'applications/nuance/controller/NuanceItemListController.php',
@ -5726,6 +5727,7 @@ phutil_register_library_map(array(
'PhabricatorPolicyInterface', 'PhabricatorPolicyInterface',
'PhabricatorApplicationTransactionInterface', 'PhabricatorApplicationTransactionInterface',
), ),
'NuanceItemActionController' => 'NuanceController',
'NuanceItemController' => 'NuanceController', 'NuanceItemController' => 'NuanceController',
'NuanceItemEditor' => 'PhabricatorApplicationTransactionEditor', 'NuanceItemEditor' => 'PhabricatorApplicationTransactionEditor',
'NuanceItemListController' => 'NuanceItemController', 'NuanceItemListController' => 'NuanceItemController',

View file

@ -43,6 +43,8 @@ final class PhabricatorNuanceApplication extends PhabricatorApplication {
$this->getQueryRoutePattern() => 'NuanceItemListController', $this->getQueryRoutePattern() => 'NuanceItemListController',
'view/(?P<id>[1-9]\d*)/' => 'NuanceItemViewController', 'view/(?P<id>[1-9]\d*)/' => 'NuanceItemViewController',
'manage/(?P<id>[1-9]\d*)/' => 'NuanceItemManageController', 'manage/(?P<id>[1-9]\d*)/' => 'NuanceItemManageController',
'action/(?P<id>[1-9]\d*)/(?P<action>[^/]+)/'
=> 'NuanceItemActionController',
), ),
'source/' => array( 'source/' => array(
$this->getQueryRoutePattern() => 'NuanceSourceListController', $this->getQueryRoutePattern() => 'NuanceSourceListController',

View file

@ -0,0 +1,26 @@
<?php
final class NuanceItemActionController extends NuanceController {
public function handleRequest(AphrontRequest $request) {
$viewer = $this->getViewer();
$id = $request->getURIData('id');
$item = id(new NuanceItemQuery())
->setViewer($viewer)
->withIDs(array($id))
->executeOne();
if (!$item) {
return new Aphront404Response();
}
$action = $request->getURIData('action');
$impl = $item->getImplementation();
$impl->setViewer($viewer);
$impl->setController($this);
return $impl->buildActionResponse($item, $action);
}
}

View file

@ -58,6 +58,13 @@ final class NuanceItemViewController extends NuanceController {
->setIcon('fa-cogs') ->setIcon('fa-cogs')
->setHref($this->getApplicationURI("item/manage/{$id}/"))); ->setHref($this->getApplicationURI("item/manage/{$id}/")));
$impl = $item->getImplementation();
$impl->setViewer($viewer);
foreach ($impl->getItemActions($item) as $action) {
$curtain->addAction($action);
}
return $curtain; return $curtain;
} }

View file

@ -144,4 +144,46 @@ final class NuanceGitHubEventItemType
return NuanceGitHubRawEvent::newEvent($type, $raw); return NuanceGitHubRawEvent::newEvent($type, $raw);
} }
public function getItemActions(NuanceItem $item) {
$actions = array();
$actions[] = $this->newItemAction($item, 'raw')
->setName(pht('View Raw Event'))
->setWorkflow(true)
->setIcon('fa-code');
return $actions;
}
protected function handleAction(NuanceItem $item, $action) {
$controller = $this->getController();
switch ($action) {
case 'raw':
$raw = array(
'api.type' => $item->getItemProperty('api.type'),
'api.raw' => $item->getItemProperty('api.raw'),
);
$raw_output = id(new PhutilJSON())->encodeFormatted($raw);
$raw_box = id(new AphrontFormTextAreaControl())
->setCustomClass('PhabricatorMonospaced')
->setLabel(pht('Raw Event'))
->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL)
->setValue($raw_output);
$form = id(new AphrontFormView())
->appendChild($raw_box);
return $controller->newDialog()
->setWidth(AphrontDialogView::WIDTH_FULL)
->setTitle(pht('GitHub Raw Event'))
->appendForm($form)
->addCancelButton($item->getURI(), pht('Done'));
}
return null;
}
} }

View file

@ -4,6 +4,7 @@ abstract class NuanceItemType
extends Phobject { extends Phobject {
private $viewer; private $viewer;
private $controller;
public function setViewer(PhabricatorUser $viewer) { public function setViewer(PhabricatorUser $viewer) {
$this->viewer = $viewer; $this->viewer = $viewer;
@ -14,6 +15,15 @@ abstract class NuanceItemType
return $this->viewer; return $this->viewer;
} }
public function setController(PhabricatorController $controller) {
$this->controller = $controller;
return $this;
}
public function getController() {
return $this->controller;
}
public function canUpdateItems() { public function canUpdateItems() {
return false; return false;
} }
@ -30,6 +40,10 @@ abstract class NuanceItemType
return null; return null;
} }
public function getItemActions(NuanceItem $item) {
return array();
}
abstract public function getItemTypeDisplayName(); abstract public function getItemTypeDisplayName();
abstract public function getItemDisplayName(NuanceItem $item); abstract public function getItemDisplayName(NuanceItem $item);
@ -60,4 +74,26 @@ abstract class NuanceItemType
->execute(); ->execute();
} }
final protected function newItemAction(NuanceItem $item, $key) {
$id = $item->getID();
$action_uri = "/nuance/item/action/{$id}/{$key}/";
return id(new PhabricatorActionView())
->setHref($action_uri);
}
final public function buildActionResponse(NuanceItem $item, $action) {
$response = $this->handleAction($item, $action);
if ($response === null) {
return new Aphront404Response();
}
return $response;
}
protected function handleAction(NuanceItem $item, $action) {
return null;
}
} }