Changeset View
Changeset View
Standalone View
Standalone View
src/applications/harbormaster/event/HarbormasterUIEventListener.php
- This file was added.
<?php | |||||
final class HarbormasterUIEventListener | |||||
extends PhabricatorEventListener { | |||||
public function register() { | |||||
$this->listen(PhabricatorEventType::TYPE_UI_WILLRENDERPROPERTIES); | |||||
} | |||||
public function handleEvent(PhutilEvent $event) { | |||||
switch ($event->getType()) { | |||||
case PhabricatorEventType::TYPE_UI_WILLRENDERPROPERTIES: | |||||
$this->handlePropertyEvent($event); | |||||
break; | |||||
} | |||||
} | |||||
private function handlePropertyEvent($ui_event) { | |||||
$user = $ui_event->getUser(); | |||||
$object = $ui_event->getValue('object'); | |||||
if (!$object || !$object->getPHID()) { | |||||
// No object, or the object has no PHID yet.. | |||||
return; | |||||
} | |||||
$target = null; | |||||
if ($object instanceof PhabricatorRepositoryCommit) { | |||||
$target = $object; | |||||
} elseif ($object instanceof DifferentialRevision) { | |||||
$target = $object->loadActiveDiff(); | |||||
} else { | |||||
return; | |||||
} | |||||
epriestley: At some point, maybe we should add `HarbormasterBuildableInterface`, although I'm not sure it's… | |||||
if (!$this->canUseApplication($ui_event->getUser())) { | |||||
return; | |||||
} | |||||
$buildables = id(new HarbormasterBuildableQuery()) | |||||
->setViewer($user) | |||||
->withBuildablePHIDs(array($target->getPHID())) | |||||
->execute(); | |||||
if (!$buildables) { | |||||
return; | |||||
} | |||||
$builds = id(new HarbormasterBuildQuery()) | |||||
->setViewer($user) | |||||
->withBuildablePHIDs(mpull($buildables, 'getPHID')) | |||||
Not Done Inline ActionsIsn't this a reasonable case where we don't need to load the BuildPlans? I don't think it's a huge deal to always load them, but they make handles and integrations like this way heavier. If every object loaded related objects that it usually needs, rather than just objects it absolutely needs, I think handle queries would be out of control huge. epriestley: Isn't this a reasonable case where we //don't// need to load the BuildPlans? I don't think it's… | |||||
->execute(); | |||||
Not Done Inline ActionsIf there are no builds, maybe we should just return? This will render an empty "Build Status:", I think? epriestley: If there are no builds, maybe we should just return? This will render an empty "Build Status:"… | |||||
if (!$builds) { | |||||
return; | |||||
} | |||||
$build_handles = id(new PhabricatorHandleQuery()) | |||||
->setViewer($user) | |||||
->withPHIDs(mpull($builds, 'getPHID')) | |||||
->execute(); | |||||
$status_view = new PHUIStatusListView(); | |||||
foreach ($builds as $build) { | |||||
$item = new PHUIStatusItemView(); | |||||
$item->setTarget( | |||||
$build_handles[$build->getPHID()]->renderLink()); | |||||
switch ($build->getBuildStatus()) { | |||||
case HarbormasterBuild::STATUS_INACTIVE: | |||||
$item->setIcon('open-dark', pht('Inactive')); | |||||
break; | |||||
case HarbormasterBuild::STATUS_PENDING: | |||||
$item->setIcon('open-blue', pht('Pending')); | |||||
break; | |||||
case HarbormasterBuild::STATUS_WAITING: | |||||
$item->setIcon('up-blue', pht('Waiting on Resource')); | |||||
break; | |||||
case HarbormasterBuild::STATUS_BUILDING: | |||||
$item->setIcon('right-blue', pht('Building')); | |||||
break; | |||||
case HarbormasterBuild::STATUS_PASSED: | |||||
$item->setIcon('accept-green', pht('Passed')); | |||||
break; | |||||
case HarbormasterBuild::STATUS_FAILED: | |||||
$item->setIcon('reject-red', pht('Failed')); | |||||
break; | |||||
case HarbormasterBuild::STATUS_ERROR: | |||||
$item->setIcon('minus-red', pht('Unexpected Error')); | |||||
break; | |||||
case HarbormasterBuild::STATUS_CANCELLED: | |||||
$item->setIcon('minus-dark', pht('Cancelled')); | |||||
break; | |||||
default: | |||||
$item->setIcon('question', pht('Unknown')); | |||||
break; | |||||
} | |||||
$status_view->addItem($item); | |||||
} | |||||
$view = $ui_event->getValue('view'); | |||||
$view->addProperty(pht('Build Status'), $status_view); | |||||
} | |||||
} |
At some point, maybe we should add HarbormasterBuildableInterface, although I'm not sure it's practical to imagine that third parties could really extend it with new buildables -- at a minimum, the objects would need some kind of "createThisBuildableFromScratch()" method, which is probably hard. Maybe this is more realistic than I think, though. This is easy to circle back to later, though.