1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-29 18:22:41 +01:00

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) {
$viewer = $this->getViewer();
$authorizing_phid = idx($data, 'authorizingPHID');
return pht(
'The object which authorized this lease (%s) is not authorized to use '.
'any of the blueprints the lease lists. Approve the authorizations '.
'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) {
$viewer = $this->getViewer();
$resource_phids = idx($data, 'resourcePHIDs', array());
return pht(
'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) {
$viewer = $this->getViewer();
$blueprint_phids = idx($data, 'blueprintPHIDs', array());
return pht(
'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 $log;
private $renderingMode = 'text';
abstract public function getLogTypeName();
abstract public function getLogTypeIcon(array $data);
abstract public function renderLog(array $data);
public function setViewer(PhabricatorUser $viewer) {
final public function setViewer(PhabricatorUser $viewer) {
$this->viewer = $viewer;
return $this;
}
public function getViewer() {
final public function getViewer() {
return $this->viewer;
}
@ -38,4 +39,36 @@ abstract class DrydockLogType extends Phobject {
->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) {
$viewer = $this->getViewer();
$reclaimer_phid = idx($data, 'reclaimerPHID');
return pht(
'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();
$type = $type_object->getLogTypeName();
$data = $type_object->renderLog($log_data);
$data = $type_object->renderLogForText($log_data);
} else {
$type = pht('Unknown ("%s")', $type_key);
$data = null;

View file

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