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

Allow Nuance items to put commands actions into the work UI

Summary:
Ref T12738. This doesn't actually do anything yet, but allows items to define commands that show up in the UI.

Adds a "Throw in Trash" item for complaints.

This construction will allow future changes to add an `EngineExtension` which can provide generic/default commands across item types.

Test Plan: {F4975086}

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T12738

Differential Revision: https://secure.phabricator.com/D18009
This commit is contained in:
epriestley 2017-05-24 07:36:46 -07:00
parent cbf9008d15
commit e1b8532e24
5 changed files with 113 additions and 3 deletions

View file

@ -1622,6 +1622,7 @@ phutil_register_library_map(array(
'NuanceItemActionController' => 'applications/nuance/controller/NuanceItemActionController.php',
'NuanceItemCommand' => 'applications/nuance/storage/NuanceItemCommand.php',
'NuanceItemCommandQuery' => 'applications/nuance/query/NuanceItemCommandQuery.php',
'NuanceItemCommandSpec' => 'applications/nuance/command/NuanceItemCommandSpec.php',
'NuanceItemCommandTransaction' => 'applications/nuance/xaction/NuanceItemCommandTransaction.php',
'NuanceItemController' => 'applications/nuance/controller/NuanceItemController.php',
'NuanceItemEditor' => 'applications/nuance/editor/NuanceItemEditor.php',
@ -6744,6 +6745,7 @@ phutil_register_library_map(array(
'PhabricatorPolicyInterface',
),
'NuanceItemCommandQuery' => 'NuanceQuery',
'NuanceItemCommandSpec' => 'Phobject',
'NuanceItemCommandTransaction' => 'NuanceItemTransactionType',
'NuanceItemController' => 'NuanceController',
'NuanceItemEditor' => 'PhabricatorApplicationTransactionEditor',

View file

@ -0,0 +1,37 @@
<?php
final class NuanceItemCommandSpec
extends Phobject {
private $commandKey;
private $name;
private $icon;
public function setCommandKey($command_key) {
$this->commandKey = $command_key;
return $this;
}
public function getCommandKey() {
return $this->commandKey;
}
public function setName($name) {
$this->name = $name;
return $this;
}
public function getName() {
return $this->name;
}
public function setIcon($icon) {
$this->icon = $icon;
return $this;
}
public function getIcon() {
return $this->icon;
}
}

View file

@ -54,16 +54,25 @@ final class NuanceQueueWorkController
$item = head($items);
$curtain = $this->buildCurtain($queue);
$curtain = $this->buildCurtain($queue, $item);
$timeline = $this->buildTransactionTimeline(
$item,
new NuanceItemTransactionQuery());
$timeline->setShouldTerminate(true);
$impl = $item->getImplementation()
->setViewer($viewer);
$work_content = $impl->buildItemWorkView($item);
$view = id(new PHUITwoColumnView())
->setCurtain($curtain)
->setMainColumn($timeline);
->setMainColumn(
array(
$work_content,
$timeline,
));
return $this->newPage()
->setTitle($title)
@ -71,12 +80,28 @@ final class NuanceQueueWorkController
->appendChild($view);
}
private function buildCurtain(NuanceQueue $queue) {
private function buildCurtain(NuanceQueue $queue, NuanceItem $item) {
$viewer = $this->getViewer();
$id = $queue->getID();
$curtain = $this->newCurtainView();
$impl = $item->getImplementation();
$commands = $impl->buildWorkCommands($item);
foreach ($commands as $command) {
$command_key = $command->getCommandKey();
$item_id = $item->getID();
$curtain->addAction(
id(new PhabricatorActionView())
->setName($command->getName())
->setIcon($command->getIcon())
->setHref("queue/command/{$id}/{$command_key}/{$item_id}/"))
->setWorkflow(true);
}
$curtain->addAction(
id(new PhabricatorActionView())
->setType(PhabricatorActionView::TYPE_DIVIDER));

View file

@ -13,4 +13,38 @@ final class NuanceFormItemType
return pht('Complaint');
}
protected function newWorkCommands(NuanceItem $item) {
return array(
$this->newCommand('trash')
->setIcon('fa-trash')
->setName(pht('Throw In Trash')),
);
}
protected function newItemView(NuanceItem $item) {
$viewer = $this->getViewer();
$content = $item->getItemProperty('complaint');
$content_view = id(new PHUIRemarkupView($viewer, $content))
->setContextObject($item);
$content_section = id(new PHUIPropertyListView())
->addTextContent(
phutil_tag(
'div',
array(
'class' => 'phabricator-remarkup',
),
$content_view));
$content_box = id(new PHUIObjectBoxView())
->setHeaderText(pht('Complaint'))
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
->appendChild($content_section);
return array(
$content_box,
);
}
}

View file

@ -32,6 +32,10 @@ abstract class NuanceItemType
return $this->newItemView($item);
}
final public function buildItemWorkView(NuanceItem $item) {
return $this->newItemView($item);
}
protected function newItemView(NuanceItem $item) {
return null;
}
@ -104,6 +108,10 @@ abstract class NuanceItemType
return null;
}
final public function buildWorkCommands(NuanceItem $item) {
return $this->newWorkCommands($item);
}
final public function applyCommand(
NuanceItem $item,
NuanceItemCommand $command) {
@ -159,4 +167,8 @@ abstract class NuanceItemType
return id(new PhabricatorNuanceApplication())->getPHID();
}
protected function newCommand($command_key) {
return id(new NuanceItemCommandSpec())
->setCommandKey($command_key);
}
}