mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +01:00
Basic Favorites application
Summary: Ref T5867. Rough in a Favorites application, not wired to anything. Test Plan: tbd. currently 404s so... I messed up something. Tossing up to read. Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin Maniphest Tasks: T5867 Differential Revision: https://secure.phabricator.com/D17160
This commit is contained in:
parent
7ea1bd5a5a
commit
6816974d57
10 changed files with 262 additions and 3 deletions
|
@ -2654,6 +2654,13 @@ phutil_register_library_map(array(
|
|||
'PhabricatorFactSimpleSpec' => 'applications/fact/spec/PhabricatorFactSimpleSpec.php',
|
||||
'PhabricatorFactSpec' => 'applications/fact/spec/PhabricatorFactSpec.php',
|
||||
'PhabricatorFactUpdateIterator' => 'applications/fact/extract/PhabricatorFactUpdateIterator.php',
|
||||
'PhabricatorFavoritesApplication' => 'applications/favorites/application/PhabricatorFavoritesApplication.php',
|
||||
'PhabricatorFavoritesConstants' => 'applications/favorites/constants/PhabricatorFavoritesConstants.php',
|
||||
'PhabricatorFavoritesController' => 'applications/favorites/controller/PhabricatorFavoritesController.php',
|
||||
'PhabricatorFavoritesMainController' => 'applications/favorites/controller/PhabricatorFavoritesMainController.php',
|
||||
'PhabricatorFavoritesManageProfileMenuItem' => 'applications/favorites/menuitem/PhabricatorFavoritesManageProfileMenuItem.php',
|
||||
'PhabricatorFavoritesMenuItemController' => 'applications/favorites/controller/PhabricatorFavoritesMenuItemController.php',
|
||||
'PhabricatorFavoritesProfileMenuEngine' => 'applications/favorites/engine/PhabricatorFavoritesProfileMenuEngine.php',
|
||||
'PhabricatorFaxContentSource' => 'infrastructure/contentsource/PhabricatorFaxContentSource.php',
|
||||
'PhabricatorFeedApplication' => 'applications/feed/application/PhabricatorFeedApplication.php',
|
||||
'PhabricatorFeedBuilder' => 'applications/feed/builder/PhabricatorFeedBuilder.php',
|
||||
|
@ -7650,6 +7657,13 @@ phutil_register_library_map(array(
|
|||
'PhabricatorFactSimpleSpec' => 'PhabricatorFactSpec',
|
||||
'PhabricatorFactSpec' => 'Phobject',
|
||||
'PhabricatorFactUpdateIterator' => 'PhutilBufferedIterator',
|
||||
'PhabricatorFavoritesApplication' => 'PhabricatorApplication',
|
||||
'PhabricatorFavoritesConstants' => 'PhabricatorFavoritesController',
|
||||
'PhabricatorFavoritesController' => 'PhabricatorController',
|
||||
'PhabricatorFavoritesMainController' => 'PhabricatorFavoritesController',
|
||||
'PhabricatorFavoritesManageProfileMenuItem' => 'PhabricatorProfileMenuItem',
|
||||
'PhabricatorFavoritesMenuItemController' => 'PhabricatorFavoritesController',
|
||||
'PhabricatorFavoritesProfileMenuEngine' => 'PhabricatorProfileMenuEngine',
|
||||
'PhabricatorFaxContentSource' => 'PhabricatorContentSource',
|
||||
'PhabricatorFeedApplication' => 'PhabricatorApplication',
|
||||
'PhabricatorFeedBuilder' => 'Phobject',
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorFavoritesApplication extends PhabricatorApplication {
|
||||
|
||||
public function getBaseURI() {
|
||||
return '/favorites/';
|
||||
}
|
||||
|
||||
public function getName() {
|
||||
return pht('Favorites');
|
||||
}
|
||||
|
||||
public function getShortDescription() {
|
||||
return pht('Favorite Items');
|
||||
}
|
||||
|
||||
public function getIcon() {
|
||||
return 'fa-star-o';
|
||||
}
|
||||
|
||||
public function getRoutes() {
|
||||
return array(
|
||||
'/favorites/' => array(
|
||||
'' => 'PhabricatorFavoritesMainController',
|
||||
'(?P<type>global|personal)/item/' => $this->getProfileMenuRouting(
|
||||
'PhabricatorFavoritesMenuItemController'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public function isLaunchable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getApplicationOrder() {
|
||||
return 9;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorFavoritesConstants
|
||||
extends PhabricatorFavoritesController {
|
||||
|
||||
const ITEM_MANAGE = 'favorites.manage';
|
||||
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
<?php
|
||||
|
||||
abstract class PhabricatorFavoritesController extends PhabricatorController {}
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorFavoritesMainController
|
||||
extends PhabricatorFavoritesController {
|
||||
|
||||
public function shouldAllowPublic() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
$viewer = $request->getViewer();
|
||||
|
||||
$menu = id(new PHUIObjectItemListView())
|
||||
->setUser($viewer);
|
||||
|
||||
$menu->addItem(
|
||||
id(new PHUIObjectItemView())
|
||||
->setHeader(pht('Personal Menu Items'))
|
||||
->setHref($this->getApplicationURI('personal/item/configure/'))
|
||||
->setImageURI($viewer->getProfileImageURI())
|
||||
->addAttribute(pht('Edit favorites for your personal account.')));
|
||||
|
||||
$icon = id(new PHUIIconView())
|
||||
->setIcon('fa-globe')
|
||||
->setBackground('bg-blue');
|
||||
|
||||
$menu->addItem(
|
||||
id(new PHUIObjectItemView())
|
||||
->setHeader(pht('Global Menu Items'))
|
||||
->setHref($this->getApplicationURI('global/item/configure/'))
|
||||
->setImageIcon($icon)
|
||||
->addAttribute(pht('Edit global default favorites for all users.')));
|
||||
|
||||
$crumbs = $this->buildApplicationCrumbs();
|
||||
$crumbs->addTextCrumb(pht('Manage'));
|
||||
$crumbs->setBorder(true);
|
||||
|
||||
$box = id(new PHUIObjectBoxView())
|
||||
->setObjectList($menu);
|
||||
|
||||
$header = id(new PHUIHeaderView())
|
||||
->setHeader(pht('Manage Favorites'))
|
||||
->setHeaderIcon('fa-star-o');
|
||||
|
||||
$view = id(new PHUITwoColumnView())
|
||||
->setHeader($header)
|
||||
->setFooter(array(
|
||||
$box,
|
||||
));
|
||||
|
||||
return $this->newPage()
|
||||
->setTitle(pht('Manage'))
|
||||
->setCrumbs($crumbs)
|
||||
->appendChild($view);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorFavoritesMenuItemController
|
||||
extends PhabricatorFavoritesController {
|
||||
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
$viewer = $this->getViewer();
|
||||
$type = $request->getURIData('type');
|
||||
$custom_phid = null;
|
||||
if ($type == 'personal') {
|
||||
$custom_phid = $viewer->getPHID();
|
||||
}
|
||||
|
||||
$application = 'PhabricatorFavoritesApplication';
|
||||
$favorites = id(new PhabricatorApplicationQuery())
|
||||
->setViewer($viewer)
|
||||
->withClasses(array($application))
|
||||
->withInstalled(true)
|
||||
->executeOne();
|
||||
|
||||
$engine = id(new PhabricatorFavoritesProfileMenuEngine())
|
||||
->setProfileObject($favorites)
|
||||
->setCustomPHID($custom_phid)
|
||||
->setController($this);
|
||||
|
||||
return $engine->buildResponse();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorFavoritesProfileMenuEngine
|
||||
extends PhabricatorProfileMenuEngine {
|
||||
|
||||
protected function isMenuEngineConfigurable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function getItemURI($path) {
|
||||
$object = $this->getProfileObject();
|
||||
$custom = $this->getCustomPHID();
|
||||
|
||||
if ($custom) {
|
||||
return "/favorites/personal/item/{$path}";
|
||||
} else {
|
||||
return "/favorites/global/item/{$path}";
|
||||
}
|
||||
}
|
||||
|
||||
protected function getBuiltinProfileItems($object) {
|
||||
$items = array();
|
||||
|
||||
$custom = $this->getCustomPHID();
|
||||
|
||||
if ($custom) {
|
||||
$items[] = $this->newItem()
|
||||
->setBuiltinKey(PhabricatorFavoritesConstants::ITEM_MANAGE)
|
||||
->setMenuItemKey(
|
||||
PhabricatorFavoritesManageProfileMenuItem::MENUITEMKEY);
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorFavoritesManageProfileMenuItem
|
||||
extends PhabricatorProfileMenuItem {
|
||||
|
||||
const MENUITEMKEY = 'favorites.manage';
|
||||
|
||||
public function getMenuItemTypeName() {
|
||||
return pht('Manage Favorites');
|
||||
}
|
||||
|
||||
private function getDefaultName() {
|
||||
return pht('Manage');
|
||||
}
|
||||
|
||||
public function canHideMenuItem(
|
||||
PhabricatorProfileMenuItemConfiguration $config) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function canMakeDefault(
|
||||
PhabricatorProfileMenuItemConfiguration $config) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getDisplayName(
|
||||
PhabricatorProfileMenuItemConfiguration $config) {
|
||||
$name = $config->getMenuItemProperty('name');
|
||||
|
||||
if (strlen($name)) {
|
||||
return $name;
|
||||
}
|
||||
|
||||
return $this->getDefaultName();
|
||||
}
|
||||
|
||||
public function buildEditEngineFields(
|
||||
PhabricatorProfileMenuItemConfiguration $config) {
|
||||
return array(
|
||||
id(new PhabricatorTextEditField())
|
||||
->setKey('name')
|
||||
->setLabel(pht('Name'))
|
||||
->setPlaceholder($this->getDefaultName())
|
||||
->setValue($config->getMenuItemProperty('name')),
|
||||
);
|
||||
}
|
||||
|
||||
protected function newNavigationMenuItems(
|
||||
PhabricatorProfileMenuItemConfiguration $config) {
|
||||
|
||||
$name = $this->getDisplayName($config);
|
||||
$icon = 'fa-pencil';
|
||||
$href = '/favorites/personal/item/configure/';
|
||||
|
||||
$item = $this->newItem()
|
||||
->setHref($href)
|
||||
->setName($name)
|
||||
->setIcon($icon);
|
||||
|
||||
return array(
|
||||
$item,
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -748,9 +748,11 @@ abstract class PhabricatorProfileMenuEngine extends Phobject {
|
|||
return new Aphront404Response();
|
||||
}
|
||||
|
||||
$custom_phid = $this->getCustomPHID();
|
||||
$configuration = PhabricatorProfileMenuItemConfiguration::initializeNewItem(
|
||||
$object,
|
||||
$item_type);
|
||||
$item_type,
|
||||
$custom_phid);
|
||||
|
||||
$viewer = $this->getViewer();
|
||||
|
||||
|
@ -765,6 +767,7 @@ abstract class PhabricatorProfileMenuEngine extends Phobject {
|
|||
->setMenuEngine($this)
|
||||
->setProfileObject($object)
|
||||
->setNewMenuItemConfiguration($configuration)
|
||||
->setCustomPHID($custom_phid)
|
||||
->setController($controller)
|
||||
->buildResponse();
|
||||
}
|
||||
|
@ -778,6 +781,7 @@ abstract class PhabricatorProfileMenuEngine extends Phobject {
|
|||
->setMenuEngine($this)
|
||||
->setProfileObject($object)
|
||||
->setController($controller)
|
||||
->setCustomPHID($this->getCustomPHID())
|
||||
->buildResponse();
|
||||
}
|
||||
|
||||
|
@ -810,6 +814,7 @@ abstract class PhabricatorProfileMenuEngine extends Phobject {
|
|||
->setProfileObject($object)
|
||||
->setNewMenuItemConfiguration($configuration)
|
||||
->setController($controller)
|
||||
->setCustomPHID($this->getCustomPHID())
|
||||
->buildResponse();
|
||||
}
|
||||
|
||||
|
|
|
@ -34,13 +34,15 @@ final class PhabricatorProfileMenuItemConfiguration
|
|||
|
||||
public static function initializeNewItem(
|
||||
$profile_object,
|
||||
PhabricatorProfileMenuItem $item) {
|
||||
PhabricatorProfileMenuItem $item,
|
||||
$custom_phid) {
|
||||
|
||||
return self::initializeNewBuiltin()
|
||||
->setProfilePHID($profile_object->getPHID())
|
||||
->setMenuItemKey($item->getMenuItemKey())
|
||||
->attachMenuItem($item)
|
||||
->attachProfileObject($profile_object);
|
||||
->attachProfileObject($profile_object)
|
||||
->setCustomPHID($custom_phid);
|
||||
}
|
||||
|
||||
protected function getConfiguration() {
|
||||
|
|
Loading…
Reference in a new issue