Render Drydock logs in text from "bin/drydock lease"; in HTML in web views

Summary: Ref T13073. The new log output from `bin/drydock lease` currently uses HTML handle rendering, but should render to text.

Test Plan: Ran `bin/drydock lease` and saw normal text in log output. Viewed the same logs from the web UI and saw HTML.

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T13073

Differential Revision: https://secure.phabricator.com/D19101
This commit is contained in:
epriestley
2018-02-15 15:35:20 -08:00
parent 2b0f98900b
commit 463dda98ed
7 changed files with 41 additions and 14 deletions

View File

@@ -13,14 +13,13 @@ final class DrydockLeaseNoAuthorizationsLogType extends DrydockLogType {
} }
public function renderLog(array $data) { public function renderLog(array $data) {
$viewer = $this->getViewer();
$authorizing_phid = idx($data, 'authorizingPHID'); $authorizing_phid = idx($data, 'authorizingPHID');
return pht( return pht(
'The object which authorized this lease (%s) is not authorized to use '. 'The object which authorized this lease (%s) is not authorized to use '.
'any of the blueprints the lease lists. Approve the authorizations '. 'any of the blueprints the lease lists. Approve the authorizations '.
'before using the lease.', 'before using the lease.',
$viewer->renderHandle($authorizing_phid)->render()); $this->renderHandle($authorizing_phid));
} }
} }

View File

@@ -13,13 +13,11 @@ final class DrydockLeaseReclaimLogType extends DrydockLogType {
} }
public function renderLog(array $data) { public function renderLog(array $data) {
$viewer = $this->getViewer();
$resource_phids = idx($data, 'resourcePHIDs', array()); $resource_phids = idx($data, 'resourcePHIDs', array());
return pht( return pht(
'Reclaimed resource %s.', 'Reclaimed resource %s.',
$viewer->renderHandleList($resource_phids)->render()); $this->renderHandleList($resource_phids));
} }
} }

View File

@@ -13,13 +13,11 @@ final class DrydockLeaseWaitingForResourcesLogType extends DrydockLogType {
} }
public function renderLog(array $data) { public function renderLog(array $data) {
$viewer = $this->getViewer();
$blueprint_phids = idx($data, 'blueprintPHIDs', array()); $blueprint_phids = idx($data, 'blueprintPHIDs', array());
return pht( return pht(
'Waiting for available resources from: %s.', 'Waiting for available resources from: %s.',
$viewer->renderHandleList($blueprint_phids)->render()); $this->renderHandleList($blueprint_phids));
} }
} }

View File

@@ -4,17 +4,18 @@ abstract class DrydockLogType extends Phobject {
private $viewer; private $viewer;
private $log; private $log;
private $renderingMode = 'text';
abstract public function getLogTypeName(); abstract public function getLogTypeName();
abstract public function getLogTypeIcon(array $data); abstract public function getLogTypeIcon(array $data);
abstract public function renderLog(array $data); abstract public function renderLog(array $data);
public function setViewer(PhabricatorUser $viewer) { final public function setViewer(PhabricatorUser $viewer) {
$this->viewer = $viewer; $this->viewer = $viewer;
return $this; return $this;
} }
public function getViewer() { final public function getViewer() {
return $this->viewer; return $this->viewer;
} }
@@ -38,4 +39,36 @@ abstract class DrydockLogType extends Phobject {
->execute(); ->execute();
} }
final public function renderLogForText($data) {
$this->renderingMode = 'text';
return $this->renderLog($data);
}
final public function renderLogForHTML($data) {
$this->renderingMode = 'html';
return $this->renderLog($data);
}
final protected function renderHandle($phid) {
$viewer = $this->getViewer();
$handle = $viewer->renderHandle($phid);
if ($this->renderingMode == 'html') {
return $handle->render();
} else {
return $handle->setAsText(true)->render();
}
}
final protected function renderHandleList(array $phids) {
$viewer = $this->getViewer();
$handle_list = $viewer->renderHandleList($phids);
if ($this->renderingMode == 'html') {
return $handle_list->render();
} else {
return $handle_list->setAsText(true)->render();
}
}
} }

View File

@@ -13,12 +13,11 @@ final class DrydockResourceReclaimLogType extends DrydockLogType {
} }
public function renderLog(array $data) { public function renderLog(array $data) {
$viewer = $this->getViewer();
$reclaimer_phid = idx($data, 'reclaimerPHID'); $reclaimer_phid = idx($data, 'reclaimerPHID');
return pht( return pht(
'Resource reclaimed by %s.', 'Resource reclaimed by %s.',
$viewer->renderHandle($reclaimer_phid)->render()); $this->renderHandle($reclaimer_phid));
} }
} }

View File

@@ -163,7 +163,7 @@ final class DrydockManagementLeaseWorkflow
$log_data = $log->getData(); $log_data = $log->getData();
$type = $type_object->getLogTypeName(); $type = $type_object->getLogTypeName();
$data = $type_object->renderLog($log_data); $data = $type_object->renderLogForText($log_data);
} else { } else {
$type = pht('Unknown ("%s")', $type_key); $type = pht('Unknown ("%s")', $type_key);
$data = null; $data = null;

View File

@@ -52,7 +52,7 @@ final class DrydockLogListView extends AphrontView {
$type = $type_object->getLogTypeName(); $type = $type_object->getLogTypeName();
$icon = $type_object->getLogTypeIcon($log_data); $icon = $type_object->getLogTypeIcon($log_data);
$data = $type_object->renderLog($log_data); $data = $type_object->renderLogForHTML($log_data);
$data = phutil_escape_html_newlines($data); $data = phutil_escape_html_newlines($data);
} else { } else {
$type = pht('<Unknown: %s>', $type_key); $type = pht('<Unknown: %s>', $type_key);