@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at recaptime-dev/main 205 lines 5.8 kB view raw
1<?php 2 3final class DrydockLeaseViewController extends DrydockLeaseController { 4 5 public function handleRequest(AphrontRequest $request) { 6 $viewer = $request->getViewer(); 7 $id = $request->getURIData('id'); 8 9 $lease = id(new DrydockLeaseQuery()) 10 ->setViewer($viewer) 11 ->withIDs(array($id)) 12 ->needUnconsumedCommands(true) 13 ->executeOne(); 14 if (!$lease) { 15 return new Aphront404Response(); 16 } 17 18 $id = $lease->getID(); 19 $lease_uri = $this->getApplicationURI("lease/{$id}/"); 20 21 $title = pht('Lease %d', $lease->getID()); 22 23 $header = id(new PHUIHeaderView()) 24 ->setHeader($title) 25 ->setHeaderIcon('fa-link') 26 ->setStatus( 27 $lease->getStatusIcon(), 28 $lease->getStatusColor(), 29 $lease->getStatusDisplayName()); 30 31 if ($lease->isReleasing()) { 32 $header->addTag( 33 id(new PHUITagView()) 34 ->setType(PHUITagView::TYPE_SHADE) 35 ->setIcon('fa-exclamation-triangle') 36 ->setColor('red') 37 ->setName('Releasing')); 38 } 39 40 $curtain = $this->buildCurtain($lease); 41 $properties = $this->buildPropertyListView($lease); 42 43 $log_query = id(new DrydockLogQuery()) 44 ->withLeasePHIDs(array($lease->getPHID())); 45 46 $log_table = $this->buildLogTable($log_query) 47 ->setHideLeases(true); 48 49 $logs = $this->buildLogBox( 50 $log_table, 51 $this->getApplicationURI("lease/{$id}/logs/query/all/")); 52 53 $crumbs = $this->buildApplicationCrumbs(); 54 $crumbs->addTextCrumb($title, $lease_uri); 55 $crumbs->setBorder(true); 56 57 $locks = $this->buildLocksTab($lease->getPHID()); 58 $commands = $this->buildCommandsTab($lease->getPHID()); 59 60 $tab_group = id(new PHUITabGroupView()) 61 ->addTab( 62 id(new PHUITabView()) 63 ->setName(pht('Properties')) 64 ->setKey('properties') 65 ->appendChild($properties)) 66 ->addTab( 67 id(new PHUITabView()) 68 ->setName(pht('Slot Locks')) 69 ->setKey('locks') 70 ->appendChild($locks)) 71 ->addTab( 72 id(new PHUITabView()) 73 ->setName(pht('Commands')) 74 ->setKey('commands') 75 ->appendChild($commands)); 76 77 $object_box = id(new PHUIObjectBoxView()) 78 ->setHeaderText(pht('Properties')) 79 ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) 80 ->addTabGroup($tab_group); 81 82 $view = id(new PHUITwoColumnView()) 83 ->setHeader($header) 84 ->setCurtain($curtain) 85 ->setMainColumn(array( 86 $object_box, 87 $logs, 88 )); 89 90 return $this->newPage() 91 ->setTitle($title) 92 ->setCrumbs($crumbs) 93 ->appendChild( 94 array( 95 $view, 96 )); 97 98 } 99 100 private function buildCurtain(DrydockLease $lease) { 101 $viewer = $this->getViewer(); 102 103 $curtain = $this->newCurtainView($lease); 104 $id = $lease->getID(); 105 106 $can_release = $lease->canRelease(); 107 if ($lease->isReleasing()) { 108 $can_release = false; 109 } 110 111 $can_edit = PhabricatorPolicyFilter::hasCapability( 112 $viewer, 113 $lease, 114 PhabricatorPolicyCapability::CAN_EDIT); 115 116 $curtain->addAction( 117 id(new PhabricatorActionView()) 118 ->setName(pht('Release Lease')) 119 ->setIcon('fa-times') 120 ->setHref($this->getApplicationURI("/lease/{$id}/release/")) 121 ->setWorkflow(true) 122 ->setDisabled(!$can_release || !$can_edit)); 123 124 return $curtain; 125 } 126 127 private function buildPropertyListView( 128 DrydockLease $lease) { 129 $viewer = $this->getViewer(); 130 131 $view = new PHUIPropertyListView(); 132 133 $view->addProperty( 134 pht('Resource Type'), 135 $lease->getResourceType()); 136 137 $owner_phid = $lease->getOwnerPHID(); 138 if ($owner_phid) { 139 $owner_display = $viewer->renderHandle($owner_phid); 140 } else { 141 $owner_display = phutil_tag('em', array(), pht('No Owner')); 142 } 143 $view->addProperty(pht('Owner'), $owner_display); 144 145 $authorizing_phid = $lease->getAuthorizingPHID(); 146 if ($authorizing_phid) { 147 $authorizing_display = $viewer->renderHandle($authorizing_phid); 148 } else { 149 $authorizing_display = phutil_tag('em', array(), pht('None')); 150 } 151 $view->addProperty(pht('Authorized By'), $authorizing_display); 152 153 $resource_phid = $lease->getResourcePHID(); 154 if ($resource_phid) { 155 $resource_display = $viewer->renderHandle($resource_phid); 156 } else { 157 $resource_display = phutil_tag('em', array(), pht('No Resource')); 158 } 159 $view->addProperty(pht('Resource'), $resource_display); 160 161 $until = $lease->getUntil(); 162 if ($until) { 163 $until_display = phabricator_datetime($until, $viewer); 164 } else { 165 $until_display = phutil_tag('em', array(), pht('Never')); 166 } 167 $view->addProperty(pht('Expires'), $until_display); 168 169 $acquired_epoch = $lease->getAcquiredEpoch(); 170 $activated_epoch = $lease->getActivatedEpoch(); 171 172 if ($acquired_epoch) { 173 $acquired_display = phabricator_datetime($acquired_epoch, $viewer); 174 } else { 175 if ($activated_epoch) { 176 $acquired_display = phutil_tag( 177 'em', 178 array(), 179 pht('Activated on Acquisition')); 180 } else { 181 $acquired_display = phutil_tag('em', array(), pht('Not Acquired')); 182 } 183 } 184 $view->addProperty(pht('Acquired'), $acquired_display); 185 186 if ($activated_epoch) { 187 $activated_display = phabricator_datetime($activated_epoch, $viewer); 188 } else { 189 $activated_display = phutil_tag('em', array(), pht('Not Activated')); 190 } 191 $view->addProperty(pht('Activated'), $activated_display); 192 193 $attributes = $lease->getAttributes(); 194 if ($attributes) { 195 $view->addSectionHeader( 196 pht('Attributes'), 'fa-list-ul'); 197 foreach ($attributes as $key => $value) { 198 $view->addProperty($key, $value); 199 } 200 } 201 202 return $view; 203 } 204 205}