Differential D9332 Diff 22234 src/applications/settings/panel/PhabricatorSettingsPanelHomePreferences.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/settings/panel/PhabricatorSettingsPanelHomePreferences.php
Show All 13 Lines | final class PhabricatorSettingsPanelHomePreferences | ||||
public function getPanelGroup() { | public function getPanelGroup() { | ||||
return pht('Application Settings'); | return pht('Application Settings'); | ||||
} | } | ||||
public function processRequest(AphrontRequest $request) { | public function processRequest(AphrontRequest $request) { | ||||
$user = $request->getUser(); | $user = $request->getUser(); | ||||
$preferences = $user->loadPreferences(); | $preferences = $user->loadPreferences(); | ||||
require_celerity_resource('phabricator-settings-css'); | |||||
$apps = id(new PhabricatorApplicationQuery()) | $apps = id(new PhabricatorApplicationQuery()) | ||||
->setViewer($user) | ->setViewer($user) | ||||
->withInstalled(true) | ->withInstalled(true) | ||||
->withUnlisted(false) | ->withUnlisted(false) | ||||
->withLaunchable(true) | |||||
->execute(); | ->execute(); | ||||
$pref_tiles = PhabricatorUserPreferences::PREFERENCE_APP_TILES; | $pinned = $preferences->getPinnedApplications($apps, $user); | ||||
$tiles = $preferences->getPreference($pref_tiles, array()); | |||||
if ($request->isFormPost()) { | $app_list = array(); | ||||
$values = $request->getArr('tile'); | foreach ($pinned as $app) { | ||||
foreach ($apps as $app) { | if (isset($apps[$app])) { | ||||
$key = get_class($app); | $app_list[$app] = $apps[$app]; | ||||
$value = idx($values, $key); | |||||
switch ($value) { | |||||
case PhabricatorApplication::TILE_FULL: | |||||
case PhabricatorApplication::TILE_SHOW: | |||||
case PhabricatorApplication::TILE_HIDE: | |||||
$tiles[$key] = $value; | |||||
break; | |||||
default: | |||||
unset($tiles[$key]); | |||||
break; | |||||
} | } | ||||
} | } | ||||
$preferences->setPreference($pref_tiles, $tiles); | |||||
$preferences->save(); | |||||
return id(new AphrontRedirectResponse()) | if ($request->getBool('add')) { | ||||
->setURI($this->getPanelURI('?saved=true')); | $options = array(); | ||||
foreach ($apps as $app) { | |||||
$options[get_class($app)] = $app->getName(); | |||||
} | } | ||||
asort($options); | |||||
$form = id(new AphrontFormView()) | unset($options['PhabricatorApplicationApplications']); | ||||
->setUser($user); | |||||
$group_map = PhabricatorApplication::getApplicationGroups(); | |||||
$output = array(); | |||||
$app_groups = mgroup($apps, 'getApplicationGroup'); | |||||
$app_groups = array_select_keys($app_groups, array_keys($group_map)); | |||||
foreach ($app_groups as $group => $apps) { | if ($request->isFormPost()) { | ||||
$group_name = $group_map[$group]; | $pin = $request->getStr('pin'); | ||||
$rows = array(); | if (isset($options[$pin]) && !in_array($pin, $pinned)) { | ||||
$pinned[] = $pin; | |||||
$preferences->setPreference( | |||||
PhabricatorUserPreferences::PREFERENCE_APP_PINNED, | |||||
$pinned); | |||||
$preferences->save(); | |||||
foreach ($apps as $app) { | return id(new AphrontRedirectResponse()) | ||||
if (!$app->shouldAppearInLaunchView()) { | ->setURI($this->getPanelURI()); | ||||
continue; | |||||
} | } | ||||
$default = $app->getDefaultTileDisplay($user); | |||||
if ($default == PhabricatorApplication::TILE_INVISIBLE) { | |||||
continue; | |||||
} | } | ||||
$default_name = PhabricatorApplication::getTileDisplayName($default); | $options_control = id(new AphrontFormSelectControl()) | ||||
->setName('pin') | |||||
$hide = PhabricatorApplication::TILE_HIDE; | ->setLabel(pht('Application')) | ||||
$show = PhabricatorApplication::TILE_SHOW; | ->setOptions($options) | ||||
$full = PhabricatorApplication::TILE_FULL; | ->setDisabledOptions(array_keys($app_list)); | ||||
$key = get_class($app); | $form = id(new AphrontFormView()) | ||||
->setUser($user) | |||||
$default_radio_button_status = | ->addHiddenInput('add', 'true') | ||||
(idx($tiles, $key, 'default') == 'default') ? 'checked' : null; | ->appendRemarkupInstructions( | ||||
pht('Choose an application to pin to your home page.')) | |||||
->appendChild($options_control); | |||||
$dialog = id(new AphrontDialogView()) | |||||
->setUser($user) | |||||
->setWidth(AphrontDialogView::WIDTH_FORM) | |||||
->setTitle(pht('Pin Application')) | |||||
->appendChild($form->buildLayoutView()) | |||||
->addSubmitButton(pht('Pin Application')) | |||||
->addCancelButton($this->getPanelURI()); | |||||
return id(new AphrontDialogResponse())->setDialog($dialog); | |||||
} | |||||
$unpin = $request->getStr('unpin'); | |||||
if ($unpin) { | |||||
$app = idx($apps, $unpin); | |||||
if ($app) { | |||||
if ($request->isFormPost()) { | |||||
$pinned = array_diff($pinned, array($unpin)); | |||||
$preferences->setPreference( | |||||
PhabricatorUserPreferences::PREFERENCE_APP_PINNED, | |||||
$pinned); | |||||
$preferences->save(); | |||||
$hide_radio_button_status = | return id(new AphrontRedirectResponse()) | ||||
(idx($tiles, $key, 'default') == $hide) ? 'checked' : null; | ->setURI($this->getPanelURI()); | ||||
} | |||||
$show_radio_button_status = | $dialog = id(new AphrontDialogView()) | ||||
(idx($tiles, $key, 'default') == $show) ? 'checked' : null; | ->setUser($user) | ||||
->setTitle(pht('Unpin Application')) | |||||
->appendParagraph( | |||||
pht( | |||||
'Unpin the %s application from your home page?', | |||||
phutil_tag('strong', array(), $app->getName()))) | |||||
->addSubmitButton(pht('Unpin Application')) | |||||
->addCanceLButton($this->getPanelURI()); | |||||
$full_radio_button_status = | return id(new AphrontDialogResponse())->setDialog($dialog); | ||||
(idx($tiles, $key, 'default') == $full) ? 'checked' : null; | } | ||||
} | |||||
$order = $request->getStrList('order'); | |||||
if ($order && $request->validateCSRF()) { | |||||
$preferences->setPreference( | |||||
PhabricatorUserPreferences::PREFERENCE_APP_PINNED, | |||||
$order); | |||||
$preferences->save(); | |||||
$default_radio_button = phutil_tag( | return id(new AphrontRedirectResponse()) | ||||
'input', | ->setURI($this->getPanelURI()); | ||||
array( | } | ||||
'type' => 'radio', | |||||
'name' => 'tile['.$key.']', | |||||
'value' => 'default', | |||||
'checked' => $default_radio_button_status, | |||||
)); | |||||
$hide_radio_button = phutil_tag( | $list_id = celerity_generate_unique_node_id(); | ||||
'input', | |||||
array( | |||||
'type' => 'radio', | |||||
'name' => 'tile['.$key.']', | |||||
'value' => $hide, | |||||
'checked' => $hide_radio_button_status, | |||||
)); | |||||
$show_radio_button = phutil_tag( | $list = id(new PHUIObjectItemListView()) | ||||
'input', | ->setUser($user) | ||||
array( | ->setID($list_id) | ||||
'type' => 'radio', | ->setFlush(true); | ||||
'name' => 'tile['.$key.']', | |||||
'value' => $show, | |||||
'checked' => $show_radio_button_status, | |||||
)); | |||||
$full_radio_button = phutil_tag( | Javelin::initBehavior( | ||||
'input', | 'reorder-applications', | ||||
array( | array( | ||||
'type' => 'radio', | 'listID' => $list_id, | ||||
'name' => 'tile['.$key.']', | 'panelURI' => $this->getPanelURI(), | ||||
'value' => $full, | |||||
'checked' => $full_radio_button_status, | |||||
)); | )); | ||||
$desc = $app->getShortDescription(); | foreach ($app_list as $key => $application) { | ||||
$app_column = hsprintf( | if ($key == 'PhabricatorApplicationApplications') { | ||||
"<strong>%s</strong><br/ >%s, <em>Default: %s</em>", | |||||
$app->getName(), $desc, $default_name); | |||||
$rows[] = array( | |||||
$app_column, | |||||
$default_radio_button, | |||||
$hide_radio_button, | |||||
$show_radio_button, | |||||
$full_radio_button, | |||||
); | |||||
} | |||||
if (empty($rows)) { | |||||
continue; | continue; | ||||
} | } | ||||
$table = new AphrontTableView($rows); | $icon = $application->getIconName(); | ||||
if (!$icon) { | |||||
$icon = 'application'; | |||||
} | |||||
$icon_view = javelin_tag( | |||||
'span', | |||||
array( | |||||
'class' => 'phui-icon-view '. | |||||
'sprite-apps-large apps-'.$icon.'-dark-large', | |||||
'aural' => false, | |||||
), | |||||
''); | |||||
$item = id(new PHUIObjectItemView()) | |||||
->setHeader($application->getName()) | |||||
->setImageIcon($icon_view) | |||||
->addAttribute($application->getShortDescription()) | |||||
->setGrippable(true); | |||||
$item->addAction( | |||||
id(new PHUIListItemView()) | |||||
->setIcon('fa-times') | |||||
->setHref($this->getPanelURI().'?unpin='.$key) | |||||
->setWorkflow(true)); | |||||
$table | $item->addSigil('pinned-application'); | ||||
->setClassName('phabricator-settings-homepagetable') | $item->setMetadata( | ||||
->setHeaders( | |||||
array( | |||||
pht('Applications'), | |||||
pht('Default'), | |||||
pht('Hidden'), | |||||
pht('Small'), | |||||
pht('Large'), | |||||
)) | |||||
->setColumnClasses( | |||||
array( | array( | ||||
'', | 'applicationClass' => $key, | ||||
'fixed', | |||||
'fixed', | |||||
'fixed', | |||||
'fixed', | |||||
)); | )); | ||||
$list->addItem($item); | |||||
$panel = id(new PHUIObjectBoxView()) | |||||
->setHeaderText($group_name) | |||||
->appendChild($table); | |||||
$output[] = $panel; | |||||
} | |||||
$save_button = | |||||
id(new AphrontFormSubmitControl()) | |||||
->setValue(pht('Save Preferences')); | |||||
$output[] = id(new PHUIBoxView()) | |||||
->addPadding(PHUI::PADDING_LARGE) | |||||
->addClass('phabricator-settings-homepagetable-button') | |||||
->appendChild($save_button); | |||||
$form->appendChild($output); | |||||
$error_view = null; | |||||
if ($request->getStr('saved') === 'true') { | |||||
$error_view = id(new AphrontErrorView()) | |||||
->setTitle(pht('Preferences Saved')) | |||||
->setSeverity(AphrontErrorView::SEVERITY_NOTICE) | |||||
->setErrors(array(pht('Your preferences have been saved.'))); | |||||
} | } | ||||
$header = id(new PHUIHeaderView()) | $header = id(new PHUIHeaderView()) | ||||
->setHeader(pht('Home Page Preferences')); | ->setHeader(pht('Pinned Applications')) | ||||
->addActionLink( | |||||
$form = id(new PHUIBoxView()) | id(new PHUIButtonView()) | ||||
->addClass('phabricator-settings-homepagetable-wrap') | ->setTag('a') | ||||
->appendChild($form); | ->setText(pht('Pin Application')) | ||||
->setHref($this->getPanelURI().'?add=true') | |||||
->setWorkflow(true) | |||||
->setIcon( | |||||
id(new PHUIIconView()) | |||||
->setIconFont('fa-thumb-tack'))); | |||||
$box = id(new PHUIObjectBoxView()) | |||||
->setHeader($header) | |||||
->appendChild($list); | |||||
return array($header, $error_view, $form); | return $box; | ||||
} | } | ||||
} | } |