1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-19 12:00:55 +01:00

Add an ApplicationProfilePanel

Summary: Allows applications to be added as profile menu items

Test Plan: Add an application to a project, see menu item, click on menu. Uninstall application, see menu without application.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Differential Revision: https://secure.phabricator.com/D17016
This commit is contained in:
Chad Little 2016-12-09 13:04:57 -08:00
parent 9c72c1b1da
commit f0b6952391
2 changed files with 81 additions and 0 deletions

View file

@ -1787,6 +1787,7 @@ phutil_register_library_map(array(
'PhabricatorApplicationEmailCommandsController' => 'applications/meta/controller/PhabricatorApplicationEmailCommandsController.php', 'PhabricatorApplicationEmailCommandsController' => 'applications/meta/controller/PhabricatorApplicationEmailCommandsController.php',
'PhabricatorApplicationLaunchView' => 'applications/meta/view/PhabricatorApplicationLaunchView.php', 'PhabricatorApplicationLaunchView' => 'applications/meta/view/PhabricatorApplicationLaunchView.php',
'PhabricatorApplicationPanelController' => 'applications/meta/controller/PhabricatorApplicationPanelController.php', 'PhabricatorApplicationPanelController' => 'applications/meta/controller/PhabricatorApplicationPanelController.php',
'PhabricatorApplicationProfilePanel' => 'applications/search/profilepanel/PhabricatorApplicationProfilePanel.php',
'PhabricatorApplicationQuery' => 'applications/meta/query/PhabricatorApplicationQuery.php', 'PhabricatorApplicationQuery' => 'applications/meta/query/PhabricatorApplicationQuery.php',
'PhabricatorApplicationSearchController' => 'applications/search/controller/PhabricatorApplicationSearchController.php', 'PhabricatorApplicationSearchController' => 'applications/search/controller/PhabricatorApplicationSearchController.php',
'PhabricatorApplicationSearchEngine' => 'applications/search/engine/PhabricatorApplicationSearchEngine.php', 'PhabricatorApplicationSearchEngine' => 'applications/search/engine/PhabricatorApplicationSearchEngine.php',
@ -6609,6 +6610,7 @@ phutil_register_library_map(array(
'PhabricatorApplicationEmailCommandsController' => 'PhabricatorApplicationsController', 'PhabricatorApplicationEmailCommandsController' => 'PhabricatorApplicationsController',
'PhabricatorApplicationLaunchView' => 'AphrontTagView', 'PhabricatorApplicationLaunchView' => 'AphrontTagView',
'PhabricatorApplicationPanelController' => 'PhabricatorApplicationsController', 'PhabricatorApplicationPanelController' => 'PhabricatorApplicationsController',
'PhabricatorApplicationProfilePanel' => 'PhabricatorProfilePanel',
'PhabricatorApplicationQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhabricatorApplicationQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhabricatorApplicationSearchController' => 'PhabricatorSearchBaseController', 'PhabricatorApplicationSearchController' => 'PhabricatorSearchBaseController',
'PhabricatorApplicationSearchEngine' => 'Phobject', 'PhabricatorApplicationSearchEngine' => 'Phobject',

View file

@ -0,0 +1,79 @@
<?php
final class PhabricatorApplicationProfilePanel
extends PhabricatorProfilePanel {
const PANELKEY = 'application';
public function getPanelTypeIcon() {
return 'fa-globe';
}
public function getPanelTypeName() {
return pht('Application');
}
public function canAddToObject($object) {
return true;
}
public function getDisplayName(
PhabricatorProfilePanelConfiguration $config) {
$app = $this->getApplication($config);
if ($app) {
return $app->getName();
} else {
return pht('(Uninstalled Application)');
}
return $app->getName();
}
public function buildEditEngineFields(
PhabricatorProfilePanelConfiguration $config) {
return array(
id(new PhabricatorDatasourceEditField())
->setKey('application')
->setLabel(pht('Application'))
->setDatasource(new PhabricatorApplicationDatasource())
->setSingleValue($config->getPanelProperty('application')),
);
}
private function getApplication(
PhabricatorProfilePanelConfiguration $config) {
$viewer = $this->getViewer();
$phid = $config->getPanelProperty('application');
$app = id(new PhabricatorApplicationQuery())
->setViewer($viewer)
->withPHIDs(array($phid))
->executeOne();
return $app;
}
protected function newNavigationMenuItems(
PhabricatorProfilePanelConfiguration $config) {
$viewer = $this->getViewer();
$app = $this->getApplication($config);
if (!$app) {
return array();
}
$is_installed = PhabricatorApplication::isClassInstalledForViewer(
get_class($app),
$viewer);
if (!$is_installed) {
return array();
}
$item = $this->newItem()
->setHref($app->getApplicationURI())
->setName($app->getName())
->setIcon($app->getIcon());
return array(
$item,
);
}
}