Differential D17355 Diff 41736 src/applications/dashboard/customfield/PhabricatorDashboardPanelTabsCustomField.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/dashboard/customfield/PhabricatorDashboardPanelTabsCustomField.php
Show All 9 Lines | final class PhabricatorDashboardPanelTabsCustomField | ||||
public function shouldAppearInApplicationSearch() { | public function shouldAppearInApplicationSearch() { | ||||
return false; | return false; | ||||
} | } | ||||
public function readValueFromRequest(AphrontRequest $request) { | public function readValueFromRequest(AphrontRequest $request) { | ||||
$value = array(); | $value = array(); | ||||
$names = $request->getArr($this->getFieldKey().'_name'); | $names = $request->getArr($this->getFieldKey().'_name'); | ||||
$panels = $request->getArr($this->getFieldKey().'_panelID'); | $panel_ids = $request->getArr($this->getFieldKey().'_panelID'); | ||||
$panels = array(); | |||||
foreach ($panel_ids as $panel_id) { | |||||
$panels[] = $panel_id[0]; | |||||
} | |||||
foreach ($names as $idx => $name) { | foreach ($names as $idx => $name) { | ||||
$panel_id = idx($panels, $idx); | $panel_id = idx($panels, $idx); | ||||
if (strlen($name) && $panel_id) { | if (strlen($name) && $panel_id) { | ||||
$value[] = array( | $value[] = array( | ||||
'name' => $name, | 'name' => $name, | ||||
'panelID' => $panel_id, | 'panelID' => $panel_id, | ||||
); | ); | ||||
} | } | ||||
} | } | ||||
$this->setFieldValue($value); | $this->setFieldValue($value); | ||||
} | } | ||||
public function renderEditControl(array $handles) { | public function renderEditControl(array $handles) { | ||||
// NOTE: This includes archived panels so we don't mutate the tabs | // NOTE: This includes archived panels so we don't mutate the tabs | ||||
// when saving a tab panel that includes archied panels. This whole UI is | // when saving a tab panel that includes archied panels. This whole UI is | ||||
// hopefully temporary anyway. | // hopefully temporary anyway. | ||||
epriestley: LUL | |||||
$panels = id(new PhabricatorDashboardPanelQuery()) | |||||
->setViewer($this->getViewer()) | |||||
->execute(); | |||||
$panel_map = array(); | |||||
foreach ($panels as $panel) { | |||||
$panel_map[$panel->getID()] = pht( | |||||
'%s %s', | |||||
$panel->getMonogram(), | |||||
$panel->getName()); | |||||
} | |||||
$panel_map = array( | |||||
'' => pht('(None)'), | |||||
) + $panel_map; | |||||
$value = $this->getFieldValue(); | $value = $this->getFieldValue(); | ||||
if (!is_array($value)) { | if (!is_array($value)) { | ||||
$value = array(); | $value = array(); | ||||
} | } | ||||
$out = array(); | $out = array(); | ||||
for ($ii = 1; $ii <= 6; $ii++) { | for ($ii = 1; $ii <= 6; $ii++) { | ||||
$tab = idx($value, ($ii - 1), array()); | $tab = idx($value, ($ii - 1), array()); | ||||
$panel = idx($tab, 'panelID', null); | |||||
$panel_id = array(); | |||||
if ($panel) { | |||||
$panel_id[] = $panel; | |||||
} | |||||
$out[] = id(new AphrontFormTextControl()) | $out[] = id(new AphrontFormTextControl()) | ||||
->setName($this->getFieldKey().'_name[]') | ->setName($this->getFieldKey().'_name[]') | ||||
->setValue(idx($tab, 'name')) | ->setValue(idx($tab, 'name')) | ||||
->setLabel(pht('Tab %d Name', $ii)); | ->setLabel(pht('Tab %d Name', $ii)); | ||||
$out[] = id(new AphrontFormSelectControl()) | $out[] = id(new AphrontFormTokenizerControl()) | ||||
->setUser($this->getViewer()) | |||||
->setDatasource(new PhabricatorDashboardPanelDatasource()) | |||||
->setName($this->getFieldKey().'_panelID[]') | ->setName($this->getFieldKey().'_panelID[]') | ||||
->setValue(idx($tab, 'panelID')) | ->setValue($panel_id) | ||||
->setOptions($panel_map) | ->setLimit(1) | ||||
->setLabel(pht('Tab %d Panel', $ii)); | ->setLabel(pht('Tab %d Panel', $ii)); | ||||
} | } | ||||
return $out; | return $out; | ||||
} | } | ||||
} | } |
LUL