1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-23 07:12:41 +01:00

Give Nuance items some basic descriptive text

Summary: Ref T10537. Ref T10538.

Test Plan: {F1164858}

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10537, T10538

Differential Revision: https://secure.phabricator.com/D15445
This commit is contained in:
epriestley 2016-03-09 04:42:25 -08:00
parent ee155ce8d2
commit 1e83aef880
9 changed files with 90 additions and 45 deletions

View file

@ -15,6 +15,7 @@ final class NuanceItemViewController extends NuanceController {
}
$title = pht('Item %d', $item->getID());
$name = $item->getDisplayName();
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb(
@ -23,16 +24,16 @@ final class NuanceItemViewController extends NuanceController {
$crumbs->addTextCrumb($title);
$crumbs->setBorder(true);
$properties = $this->buildPropertyView($item);
$curtain = $this->buildCurtain($item);
$content = $this->buildContent($item);
$header = id(new PHUIHeaderView())
->setHeader($title);
->setHeader($name);
$view = id(new PHUITwoColumnView())
->setHeader($header)
->setCurtain($curtain)
->addPropertySection(pht('DETAILS'), $properties);
->setMainColumn($content);
return $this->newPage()
->setTitle($title)
@ -40,27 +41,6 @@ final class NuanceItemViewController extends NuanceController {
->appendChild($view);
}
private function buildPropertyView(NuanceItem $item) {
$viewer = $this->getViewer();
$properties = id(new PHUIPropertyListView())
->setUser($viewer);
$properties->addProperty(
pht('Date Created'),
phabricator_datetime($item->getDateCreated(), $viewer));
$source = $item->getSource();
$definition = $source->getDefinition();
$definition->renderItemViewProperties(
$viewer,
$item,
$properties);
return $properties;
}
private function buildCurtain(NuanceItem $item) {
$viewer = $this->getViewer();
$id = $item->getID();
@ -81,5 +61,12 @@ final class NuanceItemViewController extends NuanceController {
return $curtain;
}
private function buildContent(NuanceItem $item) {
$viewer = $this->getViewer();
$impl = $item->getImplementation();
$impl->setViewer($viewer);
return $impl->buildItemView($item);
}
}

View file

@ -158,6 +158,9 @@ final class NuanceGitHubRepositoryImportCursor
$this->updatePolling($response, $now, true);
// Reverse the new items so we insert them in chronological order.
$new_items = array_reverse($new_items);
$source->openTransaction();
foreach ($new_items as $new_item) {
$new_item->save();

View file

@ -5,6 +5,49 @@ final class NuanceGitHubEventItemType
const ITEMTYPE = 'github.event';
public function getItemTypeDisplayName() {
return pht('GitHub Event');
}
public function getItemTypeDisplayIcon() {
return 'fa-github';
}
public function getItemDisplayName(NuanceItem $item) {
$raw = $item->getItemProperty('api.raw', array());
$repo = idxv($raw, array('repo', 'name'), pht('<unknown/unknown>'));
$type = idx($raw, 'type');
switch ($type) {
case 'PushEvent':
$head = idxv($raw, array('payload', 'head'));
$head = substr($head, 0, 8);
$name = pht('Push %s', $head);
break;
case 'IssuesEvent':
$action = idxv($raw, array('payload', 'action'));
$number = idxv($raw, array('payload', 'issue', 'number'));
$name = pht('Issue #%d (%s)', $number, $action);
break;
case 'IssueCommentEvent':
$action = idxv($raw, array('payload', 'action'));
$number = idxv($raw, array('payload', 'issue', 'number'));
$name = pht('Issue #%d (Comment, %s)', $number, $action);
break;
case 'PullRequestEvent':
$action = idxv($raw, array('payload', 'action'));
$number = idxv($raw, array('payload', 'pull_request', 'number'));
$name = pht('Pull Request #%d (%s)', $number, $action);
break;
default:
$name = pht('Unknown Event ("%s")', $type);
break;
}
return pht('GitHub %s %s', $repo, $name);
}
public function canUpdateItems() {
return true;
}

View file

@ -3,10 +3,36 @@
abstract class NuanceItemType
extends Phobject {
private $viewer;
public function setViewer(PhabricatorUser $viewer) {
$this->viewer = $viewer;
return $this;
}
public function getViewer() {
return $this->viewer;
}
public function canUpdateItems() {
return false;
}
final public function buildItemView(NuanceItem $item) {
return $this->newItemView($item);
}
protected function newItemView() {
return null;
}
public function getItemTypeDisplayIcon() {
return null;
}
abstract public function getItemTypeDisplayName();
abstract public function getItemDisplayName(NuanceItem $item);
final public function updateItem(NuanceItem $item) {
if (!$this->canUpdateItems()) {
throw new Exception(

View file

@ -33,7 +33,7 @@ final class NuanceItemPHIDType extends PhabricatorPHIDType {
foreach ($handles as $phid => $handle) {
$item = $objects[$phid];
$handle->setName($item->getLabel($viewer));
$handle->setName($item->getItemDisplayName());
$handle->setURI($item->getURI());
}
}

View file

@ -61,12 +61,16 @@ final class NuanceItemSearchEngine
$list = new PHUIObjectItemListView();
$list->setUser($viewer);
foreach ($items as $item) {
$impl = $item->getImplementation();
$view = id(new PHUIObjectItemView())
->setObjectName(pht('Item %d', $item->getID()))
->setHeader($item->getDisplayName())
->setHref($item->getURI());
$view->addIcon('none', $item->getItemType());
$view->addIcon(
$impl->getItemTypeDisplayIcon(),
$impl->getItemTypeDisplayName());
$list->addItem($view);
}

View file

@ -72,13 +72,6 @@ final class NuancePhabricatorFormSourceDefinition
return $box;
}
public function renderItemViewProperties(
PhabricatorUser $viewer,
NuanceItem $item,
PHUIPropertyListView $view) {
$this->renderItemCommonProperties($viewer, $item, $view);
}
public function renderItemEditProperties(
PhabricatorUser $viewer,
NuanceItem $item,

View file

@ -193,13 +193,6 @@ abstract class NuanceSourceDefinition extends Phobject {
return $item;
}
public function renderItemViewProperties(
PhabricatorUser $viewer,
NuanceItem $item,
PHUIPropertyListView $view) {
return;
}
public function renderItemEditProperties(
PhabricatorUser $viewer,
NuanceItem $item,

View file

@ -87,10 +87,6 @@ final class NuanceItem
return '/nuance/item/view/'.$this->getID().'/';
}
public function getLabel(PhabricatorUser $viewer) {
return pht('TODO: An Item');
}
public function getRequestor() {
return $this->assertAttached($this->requestor);
}
@ -144,7 +140,7 @@ final class NuanceItem
}
public function getDisplayName() {
return pht('An Item');
return $this->getImplementation()->getItemDisplayName($this);
}
public function scheduleUpdate() {