public function render()
 {
     $leases = $this->leases;
     $viewer = $this->getUser();
     $view = new PHUIObjectItemListView();
     foreach ($leases as $lease) {
         $item = id(new PHUIObjectItemView())->setUser($viewer)->setHeader($lease->getLeaseName())->setHref('/drydock/lease/' . $lease->getID() . '/');
         if ($lease->hasAttachedResource()) {
             $resource = $lease->getResource();
             $resource_href = '/drydock/resource/' . $resource->getID() . '/';
             $resource_name = $resource->getName();
             $item->addAttribute(phutil_tag('a', array('href' => $resource_href), $resource_name));
         }
         $status = DrydockLeaseStatus::getNameForStatus($lease->getStatus());
         $item->addAttribute($status);
         $item->setEpoch($lease->getDateCreated());
         // TODO: Tailor this for clarity.
         if ($lease->isActivating()) {
             $item->setStatusIcon('fa-dot-circle-o yellow');
         } else {
             if ($lease->isActive()) {
                 $item->setStatusIcon('fa-dot-circle-o green');
             } else {
                 $item->setStatusIcon('fa-dot-circle-o red');
             }
         }
         $view->addItem($item);
     }
     return $view;
 }
 private function buildPropertyListView(DrydockLease $lease, PhabricatorActionListView $actions)
 {
     $viewer = $this->getViewer();
     $view = new PHUIPropertyListView();
     $view->setActionList($actions);
     $view->addProperty(pht('Status'), DrydockLeaseStatus::getNameForStatus($lease->getStatus()));
     $view->addProperty(pht('Resource Type'), $lease->getResourceType());
     $resource_phid = $lease->getResourcePHID();
     if ($resource_phid) {
         $resource_display = $viewer->renderHandle($resource_phid);
     } else {
         $resource_display = phutil_tag('em', array(), pht('No Resource'));
     }
     $view->addProperty(pht('Resource'), $resource_display);
     $until = $lease->getUntil();
     if ($until) {
         $until_display = phabricator_datetime($until, $viewer);
     } else {
         $until_display = phutil_tag('em', array(), pht('Never'));
     }
     $view->addProperty(pht('Expires'), $until_display);
     $attributes = $lease->getAttributes();
     if ($attributes) {
         $view->addSectionHeader(pht('Attributes'), 'fa-list-ul');
         foreach ($attributes as $key => $value) {
             $view->addProperty($key, $value);
         }
     }
     return $view;
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $nav = $this->buildSideNav('lease');
     $pager = new AphrontPagerView();
     $pager->setURI(new PhutilURI('/drydock/lease/'), 'page');
     $data = id(new DrydockLease())->loadAllWhere('1 = 1 ORDER BY id DESC LIMIT %d, %d', $pager->getOffset(), $pager->getPageSize() + 1);
     $data = $pager->sliceResults($data);
     $phids = mpull($data, 'getOwnerPHID');
     $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
     $resource_ids = mpull($data, 'getResourceID');
     $resources = array();
     if ($resource_ids) {
         $resources = id(new DrydockResource())->loadAllWhere('id IN (%Ld)', $resource_ids);
     }
     $rows = array();
     foreach ($data as $lease) {
         $resource = idx($resources, $lease->getResourceID());
         $rows[] = array($lease->getID(), DrydockLeaseStatus::getNameForStatus($lease->getStatus()), $lease->getOwnerPHID() ? $handles[$lease->getOwnerPHID()]->renderLink() : null, $lease->getResourceID(), $resource ? phutil_escape_html($resource->getName()) : null, phabricator_datetime($lease->getDateCreated(), $user));
     }
     $table = new AphrontTableView($rows);
     $table->setHeaders(array('ID', 'Status', 'Owner', 'Resource ID', 'Resource', 'Created'));
     $table->setColumnClasses(array('', '', '', '', 'wide pri', 'right'));
     $panel = new AphrontPanelView();
     $panel->setHeader('Drydock Leases');
     $panel->appendChild($table);
     $panel->appendChild($pager);
     $nav->appendChild($panel);
     return $this->buildStandardPageResponse($nav, array('title' => 'Leases'));
 }
 public function buildSearchForm(AphrontFormView $form, PhabricatorSavedQuery $saved)
 {
     $statuses = $saved->getParameter('statuses', array());
     $status_control = id(new AphrontFormCheckboxControl())->setLabel(pht('Status'));
     foreach (DrydockLeaseStatus::getAllStatuses() as $status) {
         $status_control->addCheckbox('statuses[]', $status, DrydockLeaseStatus::getNameForStatus($status), in_array($status, $statuses));
     }
     $form->appendChild($status_control);
 }
 protected function buildCustomSearchFields()
 {
     return array(id(new PhabricatorSearchCheckboxesField())->setLabel(pht('Statuses'))->setKey('statuses')->setOptions(DrydockLeaseStatus::getStatusMap()));
 }