Differential D20219 Diff 48280 src/applications/harbormaster/controller/HarbormasterPlanViewController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/harbormaster/controller/HarbormasterPlanViewController.php
| Show All 12 Lines | public function handleRequest(AphrontRequest $request) { | ||||
| $plan = id(new HarbormasterBuildPlanQuery()) | $plan = id(new HarbormasterBuildPlanQuery()) | ||||
| ->setViewer($viewer) | ->setViewer($viewer) | ||||
| ->withIDs(array($id)) | ->withIDs(array($id)) | ||||
| ->executeOne(); | ->executeOne(); | ||||
| if (!$plan) { | if (!$plan) { | ||||
| return new Aphront404Response(); | return new Aphront404Response(); | ||||
| } | } | ||||
| $timeline = $this->buildTransactionTimeline( | |||||
| $plan, | |||||
| new HarbormasterBuildPlanTransactionQuery()); | |||||
| $timeline->setShouldTerminate(true); | |||||
| $title = $plan->getName(); | $title = $plan->getName(); | ||||
| $header = id(new PHUIHeaderView()) | $header = id(new PHUIHeaderView()) | ||||
| ->setHeader($plan->getName()) | ->setHeader($plan->getName()) | ||||
| ->setUser($viewer) | ->setUser($viewer) | ||||
| ->setPolicyObject($plan) | ->setPolicyObject($plan) | ||||
| ->setHeaderIcon('fa-ship'); | ->setHeaderIcon('fa-ship'); | ||||
| $curtain = $this->buildCurtainView($plan); | $curtain = $this->buildCurtainView($plan); | ||||
| $crumbs = $this->buildApplicationCrumbs(); | $crumbs = $this->buildApplicationCrumbs() | ||||
| $crumbs->addTextCrumb(pht('Plan %d', $id)); | ->addTextCrumb($plan->getObjectName()) | ||||
| $crumbs->setBorder(true); | ->setBorder(true); | ||||
| list($step_list, $has_any_conflicts, $would_deadlock) = | list($step_list, $has_any_conflicts, $would_deadlock, $steps) = | ||||
| $this->buildStepList($plan); | $this->buildStepList($plan); | ||||
| $error = null; | $error = null; | ||||
| if ($would_deadlock) { | if (!$steps) { | ||||
| $error = pht('This build plan will deadlock when executed, due to '. | $error = pht( | ||||
| 'circular dependencies present in the build plan. '. | 'This build plan does not have any build steps yet, so it will '. | ||||
| 'Examine the step list and resolve the deadlock.'); | 'not do anything when run.'); | ||||
| } else if ($would_deadlock) { | |||||
| $error = pht( | |||||
| 'This build plan will deadlock when executed, due to circular '. | |||||
| 'dependencies present in the build plan. Examine the step list '. | |||||
| 'and resolve the deadlock.'); | |||||
| } else if ($has_any_conflicts) { | } else if ($has_any_conflicts) { | ||||
| // A deadlocking build will also cause all the artifacts to be | // A deadlocking build will also cause all the artifacts to be | ||||
| // invalid, so we just skip showing this message if that's the | // invalid, so we just skip showing this message if that's the | ||||
| // case. | // case. | ||||
| $error = pht('This build plan has conflicts in one or more build steps. '. | $error = pht( | ||||
| 'This build plan has conflicts in one or more build steps. '. | |||||
| 'Examine the step list and resolve the listed errors.'); | 'Examine the step list and resolve the listed errors.'); | ||||
| } | } | ||||
| if ($error) { | if ($error) { | ||||
| $error = id(new PHUIInfoView()) | $error = id(new PHUIInfoView()) | ||||
| ->setSeverity(PHUIInfoView::SEVERITY_WARNING) | ->setSeverity(PHUIInfoView::SEVERITY_WARNING) | ||||
| ->appendChild($error); | ->appendChild($error); | ||||
| } | } | ||||
| $builds_view = $this->newBuildsView($plan); | |||||
| $timeline = $this->buildTransactionTimeline( | |||||
| $plan, | |||||
| new HarbormasterBuildPlanTransactionQuery()); | |||||
| $timeline->setShouldTerminate(true); | |||||
| $view = id(new PHUITwoColumnView()) | $view = id(new PHUITwoColumnView()) | ||||
| ->setHeader($header) | ->setHeader($header) | ||||
| ->setCurtain($curtain) | ->setCurtain($curtain) | ||||
| ->setMainColumn(array( | ->setMainColumn( | ||||
| array( | |||||
| $error, | $error, | ||||
| $step_list, | $step_list, | ||||
| $builds_view, | |||||
| $timeline, | $timeline, | ||||
| )); | )); | ||||
| return $this->newPage() | return $this->newPage() | ||||
| ->setTitle($title) | ->setTitle($title) | ||||
| ->setCrumbs($crumbs) | ->setCrumbs($crumbs) | ||||
| ->setPageObjectPHIDs(array($plan->getPHID())) | |||||
| ->appendChild($view); | ->appendChild($view); | ||||
| } | } | ||||
| private function buildStepList(HarbormasterBuildPlan $plan) { | private function buildStepList(HarbormasterBuildPlan $plan) { | ||||
| $viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
| $run_order = HarbormasterBuildGraph::determineDependencyExecution($plan); | $run_order = HarbormasterBuildGraph::determineDependencyExecution($plan); | ||||
| ▲ Show 20 Lines • Show All 126 Lines • ▼ Show 20 Lines | $header = id(new PHUIHeaderView()) | ||||
| ->setDisabled(!$can_edit) | ->setDisabled(!$can_edit) | ||||
| ->setWorkflow(!$can_edit)); | ->setWorkflow(!$can_edit)); | ||||
| $step_box = id(new PHUIObjectBoxView()) | $step_box = id(new PHUIObjectBoxView()) | ||||
| ->setHeader($header) | ->setHeader($header) | ||||
| ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) | ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) | ||||
| ->appendChild($step_list); | ->appendChild($step_list); | ||||
| return array($step_box, $has_any_conflicts, $is_deadlocking); | return array($step_box, $has_any_conflicts, $is_deadlocking, $steps); | ||||
| } | } | ||||
| private function buildCurtainView(HarbormasterBuildPlan $plan) { | private function buildCurtainView(HarbormasterBuildPlan $plan) { | ||||
| $viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
| $id = $plan->getID(); | $id = $plan->getID(); | ||||
| $curtain = $this->newCurtainView($plan); | $curtain = $this->newCurtainView($plan); | ||||
| ▲ Show 20 Lines • Show All 146 Lines • ▼ Show 20 Lines | final class HarbormasterPlanViewController extends HarbormasterPlanController { | ||||
| } | } | ||||
| private function buildDependsOnList( | private function buildDependsOnList( | ||||
| array $step_phids, | array $step_phids, | ||||
| $name, | $name, | ||||
| array $steps) { | array $steps) { | ||||
| $has_conflicts = false; | $has_conflicts = false; | ||||
| if (count($step_phids) === 0) { | if (!$step_phids) { | ||||
| return null; | return null; | ||||
| } | } | ||||
| $this->requireResource('harbormaster-css'); | $this->requireResource('harbormaster-css'); | ||||
| $steps = mpull($steps, null, 'getPHID'); | $steps = mpull($steps, null, 'getPHID'); | ||||
| $header = phutil_tag( | $header = phutil_tag( | ||||
| ▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | private function buildDependsOnList( | ||||
| $ui = array( | $ui = array( | ||||
| $header, | $header, | ||||
| $list, | $list, | ||||
| ); | ); | ||||
| return array($ui, $has_conflicts); | return array($ui, $has_conflicts); | ||||
| } | } | ||||
| private function newBuildsView(HarbormasterBuildPlan $plan) { | |||||
| $viewer = $this->getViewer(); | |||||
| $builds = id(new HarbormasterBuildQuery()) | |||||
| ->setViewer($viewer) | |||||
| ->withBuildPlanPHIDs(array($plan->getPHID())) | |||||
| ->setLimit(10) | |||||
| ->execute(); | |||||
| $list = id(new HarbormasterBuildView()) | |||||
| ->setViewer($viewer) | |||||
| ->setBuilds($builds) | |||||
| ->newObjectList(); | |||||
| $list->setNoDataString(pht('No recent builds.')); | |||||
| $more_href = new PhutilURI( | |||||
| $this->getApplicationURI('/build/'), | |||||
| array('plan' => $plan->getPHID())); | |||||
| $more_link = id(new PHUIButtonView()) | |||||
| ->setTag('a') | |||||
| ->setIcon('fa-list-ul') | |||||
| ->setText(pht('View All Builds')) | |||||
| ->setHref($more_href); | |||||
| $header = id(new PHUIHeaderView()) | |||||
| ->setHeader(pht('Recent Builds')) | |||||
| ->addActionLink($more_link); | |||||
| return id(new PHUIObjectBoxView()) | |||||
| ->setHeader($header) | |||||
| ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) | |||||
| ->appendChild($list); | |||||
| } | |||||
| } | } | ||||