Path: blob/master/src/applications/drydock/view/DrydockRepositoryOperationStatusView.php
12256 views
<?php12final class DrydockRepositoryOperationStatusView3extends AphrontView {45private $operation;6private $boxView;78public function setOperation(DrydockRepositoryOperation $operation) {9$this->operation = $operation;10return $this;11}1213public function getOperation() {14return $this->operation;15}1617public function setBoxView(PHUIObjectBoxView $box_view) {18$this->boxView = $box_view;19return $this;20}2122public function getBoxView() {23return $this->boxView;24}2526public function render() {27$viewer = $this->getUser();28$operation = $this->getOperation();2930$list = $this->renderUnderwayState();3132// If the operation is currently underway, refresh the status view.33if ($operation->isUnderway()) {34$status_id = celerity_generate_unique_node_id();35$id = $operation->getID();3637$list->setID($status_id);3839Javelin::initBehavior(40'drydock-live-operation-status',41array(42'statusID' => $status_id,43'updateURI' => "/drydock/operation/{$id}/status/",44));45}4647$box_view = $this->getBoxView();48if (!$box_view) {49$box_view = id(new PHUIObjectBoxView())50->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)51->setHeaderText(pht('Operation Status'));52}53$box_view->setObjectList($list);5455return $box_view;56}5758public function renderUnderwayState() {59$viewer = $this->getUser();60$operation = $this->getOperation();6162$id = $operation->getID();6364$state = $operation->getOperationState();65$icon = DrydockRepositoryOperation::getOperationStateIcon($state);66$name = DrydockRepositoryOperation::getOperationStateName($state);6768$item = id(new PHUIObjectItemView())69->setHref("/drydock/operation/{$id}/")70->setObjectName(pht('Operation %d', $id))71->setHeader($operation->getOperationDescription($viewer))72->setStatusIcon($icon, $name);7374if ($state != DrydockRepositoryOperation::STATE_FAIL) {75$item->addAttribute($operation->getOperationCurrentStatus($viewer));76} else {77$vcs_error = $operation->getCommandError();78if ($vcs_error) {79switch ($vcs_error['phase']) {80case DrydockWorkingCopyBlueprintImplementation::PHASE_SQUASHMERGE:81$message = pht(82'This change did not merge cleanly. This usually indicates '.83'that the change is out of date and needs to be updated.');84break;85case DrydockWorkingCopyBlueprintImplementation::PHASE_REMOTEFETCH:86$message = pht(87'This change could not be fetched from the remote.');88break;89case DrydockWorkingCopyBlueprintImplementation::PHASE_MERGEFETCH:90$message = pht(91'This change could not be fetched from the remote staging '.92'area. It may not have been pushed, or may have been removed.');93break;94case DrydockLandRepositoryOperation::PHASE_COMMIT:95$message = pht(96'Committing this change failed. It may already have been '.97'merged.');98break;99case DrydockLandRepositoryOperation::PHASE_PUSH:100$message = pht(101'The push failed. This usually indicates '.102'that the change is breaking some rules or '.103'some custom commit hook has failed.');104break;105default:106$message = pht(107'Operation encountered an error while performing repository '.108'operations.');109break;110}111112$item->addAttribute($message);113114$table = $this->renderVCSErrorTable($vcs_error);115list($links, $info) = $this->renderDetailToggles($table);116117$item->addAttribute($links);118$item->appendChild($info);119} else {120$item->addAttribute(pht('Operation encountered an error.'));121}122123$is_dismissed = $operation->getIsDismissed();124125$item->addAction(126id(new PHUIListItemView())127->setName('Dismiss')128->setIcon('fa-times')129->setDisabled($is_dismissed)130->setWorkflow(true)131->setHref("/drydock/operation/{$id}/dismiss/"));132}133134return id(new PHUIObjectItemListView())135->addItem($item);136}137138private function renderVCSErrorTable(array $vcs_error) {139$rows = array();140141$rows[] = array(142pht('Command'),143phutil_censor_credentials($vcs_error['command']),144);145146$rows[] = array(pht('Error'), $vcs_error['err']);147148$rows[] = array(149pht('Stdout'),150phutil_censor_credentials($vcs_error['stdout']),151);152153$rows[] = array(154pht('Stderr'),155phutil_censor_credentials($vcs_error['stderr']),156);157158$table = id(new AphrontTableView($rows))159->setColumnClasses(160array(161'header',162'wide prewrap',163));164165return $table;166}167168private function renderDetailToggles(AphrontTableView $table) {169$show_id = celerity_generate_unique_node_id();170$hide_id = celerity_generate_unique_node_id();171$info_id = celerity_generate_unique_node_id();172173Javelin::initBehavior('phabricator-reveal-content');174175$show_details = javelin_tag(176'a',177array(178'id' => $show_id,179'href' => '#',180'sigil' => 'reveal-content',181'mustcapture' => true,182'meta' => array(183'hideIDs' => array($show_id),184'showIDs' => array($hide_id, $info_id),185),186),187pht('Show Details'));188189$hide_details = javelin_tag(190'a',191array(192'id' => $hide_id,193'href' => '#',194'sigil' => 'reveal-content',195'mustcapture' => true,196'style' => 'display: none',197'meta' => array(198'hideIDs' => array($hide_id, $info_id),199'showIDs' => array($show_id),200),201),202pht('Hide Details'));203204$info = javelin_tag(205'div',206array(207'id' => $info_id,208'style' => 'display: none',209),210$table);211212$links = array(213$show_details,214$hide_details,215);216217return array($links, $info);218}219220}221222223