public function handleRequest(AphrontRequest $request)
 {
     $viewer = $this->getViewer();
     $message_id = $request->getURIData('id');
     $message = id(new HarbormasterBuildUnitMessage())->load($message_id);
     if (!$message) {
         return new Aphront404Response();
     }
     $build_target = id(new HarbormasterBuildTargetQuery())->setViewer($viewer)->withPHIDs(array($message->getBuildTargetPHID()))->executeOne();
     if (!$build_target) {
         return new Aphront404Response();
     }
     $build = $build_target->getBuild();
     $buildable = $build->getBuildable();
     $buildable_id = $buildable->getID();
     $id = $message->getID();
     $display_name = $message->getUnitMessageDisplayName();
     $status = $message->getResult();
     $status_icon = HarbormasterUnitStatus::getUnitStatusIcon($status);
     $status_color = HarbormasterUnitStatus::getUnitStatusColor($status);
     $status_label = HarbormasterUnitStatus::getUnitStatusLabel($status);
     $header = id(new PHUIHeaderView())->setHeader($display_name)->setStatus($status_icon, $status_color, $status_label);
     $properties = $this->buildPropertyListView($message);
     $curtain = $this->buildCurtainView($message, $build);
     $unit = id(new PHUIObjectBoxView())->setHeaderText(pht('TEST RESULT'))->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)->addPropertyList($properties);
     $crumbs = $this->buildApplicationCrumbs();
     $this->addBuildableCrumb($crumbs, $buildable);
     $crumbs->addTextCrumb(pht('Unit Tests'), "/harbormaster/unit/{$buildable_id}/");
     $crumbs->addTextCrumb(pht('Unit %d', $id));
     $crumbs->setBorder(true);
     $title = array($display_name, $buildable->getMonogram());
     $view = id(new PHUITwoColumnView())->setHeader($header)->setCurtain($curtain)->setMainColumn(array($unit));
     return $this->newPage()->setTitle($title)->setCrumbs($crumbs)->appendChild($view);
 }
 public function render()
 {
     require_celerity_resource('harbormaster-css');
     $messages = $this->unitMessages;
     $messages = msort($messages, 'getSortKey');
     $limit = $this->limit;
     if ($this->limit) {
         $display_messages = array_slice($messages, 0, $limit);
     } else {
         $display_messages = $messages;
     }
     $rows = array();
     $any_duration = false;
     foreach ($display_messages as $message) {
         $status = $message->getResult();
         $icon_icon = HarbormasterUnitStatus::getUnitStatusIcon($status);
         $icon_color = HarbormasterUnitStatus::getUnitStatusColor($status);
         $icon_label = HarbormasterUnitStatus::getUnitStatusLabel($status);
         $result_icon = id(new PHUIIconView())->setIcon("{$icon_icon} {$icon_color}")->addSigil('has-tooltip')->setMetadata(array('tip' => $icon_label));
         $duration = $message->getDuration();
         if ($duration !== null) {
             $any_duration = true;
             $duration = pht('%s ms', new PhutilNumber((int) (1000 * $duration)));
         }
         $name = $message->getUnitMessageDisplayName();
         $id = $message->getID();
         if ($id) {
             $name = phutil_tag('a', array('href' => "/harbormaster/unit/view/{$id}/"), $name);
         }
         $details = $message->getUnitMessageDetails();
         if (strlen($details)) {
             $name = array($name, $this->renderUnitTestDetails($details));
         }
         $rows[] = array($result_icon, $duration, $name);
     }
     $full_uri = $this->fullResultsURI;
     if ($full_uri && count($messages) > $limit) {
         $counts = array();
         $groups = mgroup($messages, 'getResult');
         foreach ($groups as $status => $group) {
             $counts[] = HarbormasterUnitStatus::getUnitStatusCountLabel($status, count($group));
         }
         $link_text = pht('View Full Test Results (%s)', implode(" ยท ", $counts));
         $full_link = phutil_tag('a', array('href' => $full_uri), $link_text);
         $link_icon = id(new PHUIIconView())->setIcon('fa-ellipsis-h lightgreytext');
         $rows[] = array($link_icon, null, $full_link);
     }
     $table = id(new AphrontTableView($rows))->setHeaders(array(null, pht('Time'), pht('Test')))->setColumnClasses(array('top center', 'top right', 'top wide'))->setColumnWidths(array('32px', '64px'))->setColumnVisibility(array(true, $any_duration));
     if ($this->notice) {
         $table->setNotice($this->notice);
     }
     return $table;
 }
 public function render()
 {
     $messages = $this->messages;
     $buildable = $this->buildable;
     $id = $buildable->getID();
     $full_uri = "/harbormaster/unit/{$id}/";
     $messages = msort($messages, 'getSortKey');
     $head_unit = head($messages);
     if ($head_unit) {
         $status = $head_unit->getResult();
         $tag_text = HarbormasterUnitStatus::getUnitStatusLabel($status);
         $tag_color = HarbormasterUnitStatus::getUnitStatusColor($status);
         $tag_icon = HarbormasterUnitStatus::getUnitStatusIcon($status);
     } else {
         $tag_text = pht('No Unit Tests');
         $tag_color = 'grey';
         $tag_icon = 'fa-ban';
     }
     $tag = id(new PHUITagView())->setType(PHUITagView::TYPE_SHADE)->setShade($tag_color)->setIcon($tag_icon)->setName($tag_text);
     $header = id(new PHUIHeaderView())->setHeader(array(pht('Unit Tests'), $tag));
     if ($this->showViewAll) {
         $view_all = id(new PHUIButtonView())->setTag('a')->setHref($full_uri)->setIcon('fa-list-ul')->setText('View All');
         $header->addActionLink($view_all);
     }
     $box = id(new PHUIObjectBoxView())->setHeader($header)->setBackground(PHUIObjectBoxView::BLUE_PROPERTY);
     $table = id(new HarbormasterUnitPropertyView())->setUnitMessages($messages);
     if ($this->showViewAll) {
         $table->setFullResultsURI($full_uri);
     }
     if ($this->limit) {
         $table->setLimit($this->limit);
     }
     $excuse = $this->excuse;
     if (strlen($excuse)) {
         $excuse_icon = id(new PHUIIconView())->setIcon('fa-commenting-o red');
         $table->setNotice(array($excuse_icon, ' ', phutil_tag('strong', array(), pht('Excuse:')), ' ', $excuse));
     }
     $box->setTable($table);
     return $box;
 }
 public function getSortKey()
 {
     $status = $this->getResult();
     $sort = HarbormasterUnitStatus::getUnitStatusSort($status);
     $parts = array($sort, $this->getEngine(), $this->getNamespace(), $this->getName(), $this->getID());
     return implode("", $parts);
 }