Differential D16028 Diff 38580 src/applications/settings/panel/PhabricatorHomePreferencesSettingsPanel.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/settings/panel/PhabricatorHomePreferencesSettingsPanel.php
Show All 10 Lines | public function getPanelName() { | ||||
return pht('Home Page'); | return pht('Home Page'); | ||||
} | } | ||||
public function getPanelGroupKey() { | public function getPanelGroupKey() { | ||||
return PhabricatorSettingsApplicationsPanelGroup::PANELGROUPKEY; | return PhabricatorSettingsApplicationsPanelGroup::PANELGROUPKEY; | ||||
} | } | ||||
public function processRequest(AphrontRequest $request) { | public function processRequest(AphrontRequest $request) { | ||||
$user = $request->getUser(); | $viewer = $this->getViewer(); | ||||
$preferences = $user->loadPreferences(); | $preferences = $this->loadTargetPreferences(); | ||||
$pinned_key = PhabricatorPinnedApplicationsSetting::SETTINGKEY; | |||||
$pinned = $preferences->getSettingValue($pinned_key); | |||||
$apps = id(new PhabricatorApplicationQuery()) | $apps = id(new PhabricatorApplicationQuery()) | ||||
->setViewer($user) | ->setViewer($viewer) | ||||
->withInstalled(true) | ->withInstalled(true) | ||||
->withUnlisted(false) | ->withUnlisted(false) | ||||
->withLaunchable(true) | ->withLaunchable(true) | ||||
->execute(); | ->execute(); | ||||
$pinned = $preferences->getPinnedApplications($apps, $user); | |||||
$app_list = array(); | $app_list = array(); | ||||
foreach ($pinned as $app) { | foreach ($pinned as $app) { | ||||
if (isset($apps[$app])) { | if (isset($apps[$app])) { | ||||
$app_list[$app] = $apps[$app]; | $app_list[$app] = $apps[$app]; | ||||
} | } | ||||
} | } | ||||
if ($request->getBool('reset')) { | |||||
if ($request->isFormPost()) { | |||||
$this->writePinnedApplications($preferences, null); | |||||
return id(new AphrontRedirectResponse()) | |||||
->setURI($this->getPanelURI()); | |||||
} | |||||
return $this->newDialog() | |||||
->setTitle(pht('Reset Applications')) | |||||
->addHiddenInput('reset', 'true') | |||||
->appendParagraph( | |||||
pht('Reset pinned applications to their defaults?')) | |||||
->addSubmitButton(pht('Reset Applications')) | |||||
->addCancelButton($this->getPanelURI()); | |||||
} | |||||
if ($request->getBool('add')) { | if ($request->getBool('add')) { | ||||
$options = array(); | $options = array(); | ||||
foreach ($apps as $app) { | foreach ($apps as $app) { | ||||
$options[get_class($app)] = $app->getName(); | $options[get_class($app)] = $app->getName(); | ||||
} | } | ||||
asort($options); | asort($options); | ||||
unset($options['PhabricatorApplicationsApplication']); | unset($options['PhabricatorApplicationsApplication']); | ||||
if ($request->isFormPost()) { | if ($request->isFormPost()) { | ||||
$pin = $request->getStr('pin'); | $pin = $request->getStr('pin'); | ||||
if (isset($options[$pin]) && !in_array($pin, $pinned)) { | if (isset($options[$pin]) && !in_array($pin, $pinned)) { | ||||
$pinned[] = $pin; | $pinned[] = $pin; | ||||
$preferences->setPreference( | |||||
PhabricatorUserPreferences::PREFERENCE_APP_PINNED, | $this->writePinnedApplications($preferences, $pinned); | ||||
$pinned); | |||||
$preferences->save(); | |||||
return id(new AphrontRedirectResponse()) | return id(new AphrontRedirectResponse()) | ||||
->setURI($this->getPanelURI()); | ->setURI($this->getPanelURI()); | ||||
} | } | ||||
} | } | ||||
$options_control = id(new AphrontFormSelectControl()) | $options_control = id(new AphrontFormSelectControl()) | ||||
->setName('pin') | ->setName('pin') | ||||
->setLabel(pht('Application')) | ->setLabel(pht('Application')) | ||||
->setOptions($options) | ->setOptions($options) | ||||
->setDisabledOptions(array_keys($app_list)); | ->setDisabledOptions(array_keys($app_list)); | ||||
$form = id(new AphrontFormView()) | $form = id(new AphrontFormView()) | ||||
->setUser($user) | ->setViewer($viewer) | ||||
->addHiddenInput('add', 'true') | ->addHiddenInput('add', 'true') | ||||
->appendRemarkupInstructions( | ->appendRemarkupInstructions( | ||||
pht('Choose an application to pin to your home page.')) | pht('Choose an application to pin to your home page.')) | ||||
->appendChild($options_control); | ->appendChild($options_control); | ||||
$dialog = id(new AphrontDialogView()) | return $this->newDialog() | ||||
->setUser($user) | |||||
->setWidth(AphrontDialogView::WIDTH_FORM) | ->setWidth(AphrontDialogView::WIDTH_FORM) | ||||
->setTitle(pht('Pin Application')) | ->setTitle(pht('Pin Application')) | ||||
->appendChild($form->buildLayoutView()) | ->appendChild($form->buildLayoutView()) | ||||
->addSubmitButton(pht('Pin Application')) | ->addSubmitButton(pht('Pin Application')) | ||||
->addCancelButton($this->getPanelURI()); | ->addCancelButton($this->getPanelURI()); | ||||
return id(new AphrontDialogResponse())->setDialog($dialog); | |||||
} | } | ||||
$unpin = $request->getStr('unpin'); | $unpin = $request->getStr('unpin'); | ||||
if ($unpin) { | if ($unpin) { | ||||
$app = idx($apps, $unpin); | $app = idx($apps, $unpin); | ||||
if ($app) { | if ($app) { | ||||
if ($request->isFormPost()) { | if ($request->isFormPost()) { | ||||
$pinned = array_diff($pinned, array($unpin)); | $pinned = array_diff($pinned, array($unpin)); | ||||
$preferences->setPreference( | |||||
PhabricatorUserPreferences::PREFERENCE_APP_PINNED, | $this->writePinnedApplications($preferences, $pinned); | ||||
$pinned); | |||||
$preferences->save(); | |||||
return id(new AphrontRedirectResponse()) | return id(new AphrontRedirectResponse()) | ||||
->setURI($this->getPanelURI()); | ->setURI($this->getPanelURI()); | ||||
} | } | ||||
$dialog = id(new AphrontDialogView()) | return $this->newDialog() | ||||
->setUser($user) | |||||
->setTitle(pht('Unpin Application')) | ->setTitle(pht('Unpin Application')) | ||||
->addHiddenInput('unpin', $unpin) | |||||
->appendParagraph( | ->appendParagraph( | ||||
pht( | pht( | ||||
'Unpin the %s application from your home page?', | 'Unpin the %s application from your home page?', | ||||
phutil_tag('strong', array(), $app->getName()))) | phutil_tag('strong', array(), $app->getName()))) | ||||
->addSubmitButton(pht('Unpin Application')) | ->addSubmitButton(pht('Unpin Application')) | ||||
->addCanceLButton($this->getPanelURI()); | ->addCancelButton($this->getPanelURI()); | ||||
return id(new AphrontDialogResponse())->setDialog($dialog); | |||||
} | } | ||||
} | } | ||||
$order = $request->getStrList('order'); | $order = $request->getStrList('order'); | ||||
if ($order && $request->validateCSRF()) { | if ($order && $request->validateCSRF()) { | ||||
$preferences->setPreference( | $this->writePinnedApplications($preferences, $order); | ||||
PhabricatorUserPreferences::PREFERENCE_APP_PINNED, | |||||
$order); | |||||
$preferences->save(); | |||||
return id(new AphrontRedirectResponse()) | return id(new AphrontRedirectResponse()) | ||||
->setURI($this->getPanelURI()); | ->setURI($this->getPanelURI()); | ||||
} | } | ||||
$list_id = celerity_generate_unique_node_id(); | $list_id = celerity_generate_unique_node_id(); | ||||
$list = id(new PHUIObjectItemListView()) | $list = id(new PHUIObjectItemListView()) | ||||
->setUser($user) | ->setViewer($viewer) | ||||
->setID($list_id); | ->setID($list_id); | ||||
Javelin::initBehavior( | Javelin::initBehavior( | ||||
'reorder-applications', | 'reorder-applications', | ||||
array( | array( | ||||
'listID' => $list_id, | 'listID' => $list_id, | ||||
'panelURI' => $this->getPanelURI(), | 'panelURI' => $this->getPanelURI(), | ||||
)); | )); | ||||
Show All 40 Lines | public function processRequest(AphrontRequest $request) { | ||||
$header = id(new PHUIHeaderView()) | $header = id(new PHUIHeaderView()) | ||||
->setHeader(pht('Pinned Applications')) | ->setHeader(pht('Pinned Applications')) | ||||
->addActionLink( | ->addActionLink( | ||||
id(new PHUIButtonView()) | id(new PHUIButtonView()) | ||||
->setTag('a') | ->setTag('a') | ||||
->setText(pht('Pin Application')) | ->setText(pht('Pin Application')) | ||||
->setHref($this->getPanelURI().'?add=true') | ->setHref($this->getPanelURI().'?add=true') | ||||
->setWorkflow(true) | ->setWorkflow(true) | ||||
->setIcon('fa-thumb-tack')); | ->setIcon('fa-thumb-tack')) | ||||
->addActionLink( | |||||
id(new PHUIButtonView()) | |||||
->setTag('a') | |||||
->setText(pht('Reset to Defaults')) | |||||
->setHref($this->getPanelURI().'?reset=true') | |||||
->setWorkflow(true) | |||||
->setIcon('fa-recycle')); | |||||
$box = id(new PHUIObjectBoxView()) | $box = id(new PHUIObjectBoxView()) | ||||
->setHeader($header) | ->setHeader($header) | ||||
->setObjectList($list); | ->setObjectList($list); | ||||
return $box; | return $box; | ||||
} | } | ||||
private function writePinnedApplications( | |||||
PhabricatorUserPreferences $preferences, | |||||
$pinned) { | |||||
$viewer = $this->getViewer(); | |||||
$request = $this->getController()->getRequest(); | |||||
$pinned_key = PhabricatorPinnedApplicationsSetting::SETTINGKEY; | |||||
$editor = id(new PhabricatorUserPreferencesEditor()) | |||||
->setActor($viewer) | |||||
->setContentSourceFromRequest($request) | |||||
->setContinueOnNoEffect(true) | |||||
->setContinueOnMissingFields(true); | |||||
$xactions = array(); | |||||
$xactions[] = $preferences->newTransaction($pinned_key, $pinned); | |||||
$editor->applyTransactions($preferences, $xactions); | |||||
} | |||||
} | } |