Differential D21628 Diff 51485 src/applications/diffusion/management/DiffusionRepositoryStorageManagementPanel.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/management/DiffusionRepositoryStorageManagementPanel.php
Show First 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | private function buildClusterStatusPanel() { | ||||
if ($service_phid) { | if ($service_phid) { | ||||
$service = id(new AlmanacServiceQuery()) | $service = id(new AlmanacServiceQuery()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->withServiceTypes( | ->withServiceTypes( | ||||
array( | array( | ||||
AlmanacClusterRepositoryServiceType::SERVICETYPE, | AlmanacClusterRepositoryServiceType::SERVICETYPE, | ||||
)) | )) | ||||
->withPHIDs(array($service_phid)) | ->withPHIDs(array($service_phid)) | ||||
->needBindings(true) | ->needActiveBindings(true) | ||||
->executeOne(); | ->executeOne(); | ||||
if (!$service) { | if (!$service) { | ||||
// TODO: Viewer may not have permission to see the service, or it may | // TODO: Viewer may not have permission to see the service, or it may | ||||
// be invalid? Raise some more useful error here? | // be invalid? Raise some more useful error here? | ||||
throw new Exception(pht('Unable to load cluster service.')); | throw new Exception(pht('Unable to load cluster service.')); | ||||
} | } | ||||
} else { | } else { | ||||
$service = null; | $service = null; | ||||
} | } | ||||
Javelin::initBehavior('phabricator-tooltips'); | Javelin::initBehavior('phabricator-tooltips'); | ||||
$rows = array(); | $rows = array(); | ||||
if ($service) { | if ($service) { | ||||
$bindings = $service->getBindings(); | $bindings = $service->getActiveBindings(); | ||||
$bindings = mgroup($bindings, 'getDevicePHID'); | $bindings = mgroup($bindings, 'getDevicePHID'); | ||||
// This is an unusual read which always comes from the master. | // This is an unusual read which always comes from the master. | ||||
if (PhabricatorEnv::isReadOnly()) { | if (PhabricatorEnv::isReadOnly()) { | ||||
$versions = array(); | $versions = array(); | ||||
} else { | } else { | ||||
$versions = PhabricatorRepositoryWorkingCopyVersion::loadVersions( | $versions = PhabricatorRepositoryWorkingCopyVersion::loadVersions( | ||||
$repository->getPHID()); | $repository->getPHID()); | ||||
} | } | ||||
$versions = mpull($versions, null, 'getDevicePHID'); | $versions = mpull($versions, null, 'getDevicePHID'); | ||||
// List enabled devices first, then sort devices in each group by name. | |||||
$sort = array(); | $sort = array(); | ||||
foreach ($bindings as $key => $binding_group) { | foreach ($bindings as $key => $binding_group) { | ||||
$all_disabled = $this->isDisabledGroup($binding_group); | |||||
$sort[$key] = id(new PhutilSortVector()) | $sort[$key] = id(new PhutilSortVector()) | ||||
->addInt($all_disabled ? 1 : 0) | |||||
->addString(head($binding_group)->getDevice()->getName()); | ->addString(head($binding_group)->getDevice()->getName()); | ||||
} | } | ||||
$sort = msortv($sort, 'getSelf'); | $sort = msortv($sort, 'getSelf'); | ||||
$bindings = array_select_keys($bindings, array_keys($sort)) + $bindings; | $bindings = array_select_keys($bindings, array_keys($sort)) + $bindings; | ||||
foreach ($bindings as $binding_group) { | foreach ($bindings as $binding_group) { | ||||
$all_disabled = $this->isDisabledGroup($binding_group); | |||||
$any_binding = head($binding_group); | $any_binding = head($binding_group); | ||||
if ($all_disabled) { | |||||
$binding_icon = 'fa-times grey'; | |||||
$binding_tip = pht('Disabled'); | |||||
} else { | |||||
$binding_icon = 'fa-folder-open green'; | $binding_icon = 'fa-folder-open green'; | ||||
$binding_tip = pht('Active'); | $binding_tip = pht('Active'); | ||||
} | |||||
$binding_icon = id(new PHUIIconView()) | $binding_icon = id(new PHUIIconView()) | ||||
->setIcon($binding_icon) | ->setIcon($binding_icon) | ||||
->addSigil('has-tooltip') | ->addSigil('has-tooltip') | ||||
->setMetadata( | ->setMetadata( | ||||
array( | array( | ||||
'tip' => $binding_tip, | 'tip' => $binding_tip, | ||||
)); | )); | ||||
▲ Show 20 Lines • Show All 220 Lines • ▼ Show 20 Lines | private function buildRefsStatusPanel( | ||||
if ($info_view) { | if ($info_view) { | ||||
$box_view->setInfoView($info_view); | $box_view->setInfoView($info_view); | ||||
} | } | ||||
return $box_view; | return $box_view; | ||||
} | } | ||||
private function isDisabledGroup(array $binding_group) { | |||||
assert_instances_of($binding_group, 'AlmanacBinding'); | |||||
foreach ($binding_group as $binding) { | |||||
if (!$binding->getIsDisabled()) { | |||||
return false; | |||||
} | |||||
} | |||||
return true; | |||||
} | |||||
} | } |