1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-26 08:42:41 +01:00

Drive menu icons from Applications

Summary:
This makes no changes, it just moves the menu icons to the applications instead of hard-coded on the page.

I'm going to try to address some of the angst in T1593 next...

Test Plan: Loaded logged-in / logged out pages. Clicked menu items. Looked at /applications/.

Reviewers: vrana, btrahan

Reviewed By: vrana

CC: aran

Maniphest Tasks: T1593, T1569

Differential Revision: https://secure.phabricator.com/D3146
This commit is contained in:
epriestley 2012-08-05 14:12:43 -07:00
parent 643653dc61
commit 314c25365d
13 changed files with 260 additions and 63 deletions

View file

@ -540,13 +540,16 @@ phutil_register_library_map(array(
'PhabricatorApplication' => 'applications/base/PhabricatorApplication.php', 'PhabricatorApplication' => 'applications/base/PhabricatorApplication.php',
'PhabricatorApplicationApplications' => 'applications/meta/application/PhabricatorApplicationApplications.php', 'PhabricatorApplicationApplications' => 'applications/meta/application/PhabricatorApplicationApplications.php',
'PhabricatorApplicationAudit' => 'applications/audit/application/PhabricatorApplicationAudit.php', 'PhabricatorApplicationAudit' => 'applications/audit/application/PhabricatorApplicationAudit.php',
'PhabricatorApplicationAuth' => 'applications/auth/application/PhabricatorApplicationAuth.php',
'PhabricatorApplicationDifferential' => 'applications/differential/application/PhabricatorApplicationDifferential.php', 'PhabricatorApplicationDifferential' => 'applications/differential/application/PhabricatorApplicationDifferential.php',
'PhabricatorApplicationDiffusion' => 'applications/diffusion/application/PhabricatorApplicationDiffusion.php', 'PhabricatorApplicationDiffusion' => 'applications/diffusion/application/PhabricatorApplicationDiffusion.php',
'PhabricatorApplicationFact' => 'applications/fact/application/PhabricatorApplicationFact.php', 'PhabricatorApplicationFact' => 'applications/fact/application/PhabricatorApplicationFact.php',
'PhabricatorApplicationFlags' => 'applications/flag/application/PhabricatorApplicationFlags.php', 'PhabricatorApplicationFlags' => 'applications/flag/application/PhabricatorApplicationFlags.php',
'PhabricatorApplicationLaunchView' => 'applications/meta/view/PhabricatorApplicationLaunchView.php', 'PhabricatorApplicationLaunchView' => 'applications/meta/view/PhabricatorApplicationLaunchView.php',
'PhabricatorApplicationManiphest' => 'applications/maniphest/application/PhabricatorApplicationManiphest.php', 'PhabricatorApplicationManiphest' => 'applications/maniphest/application/PhabricatorApplicationManiphest.php',
'PhabricatorApplicationPeople' => 'applications/people/application/PhabricatorApplicationPeople.php',
'PhabricatorApplicationPhriction' => 'applications/phriction/application/PhabricatorApplicationPhriction.php', 'PhabricatorApplicationPhriction' => 'applications/phriction/application/PhabricatorApplicationPhriction.php',
'PhabricatorApplicationSettings' => 'applications/people/application/PhabricatorApplicationSettings.php',
'PhabricatorApplicationStatusView' => 'applications/meta/view/PhabricatorApplicationStatusView.php', 'PhabricatorApplicationStatusView' => 'applications/meta/view/PhabricatorApplicationStatusView.php',
'PhabricatorApplicationsController' => 'applications/meta/controller/PhabricatorApplicationsController.php', 'PhabricatorApplicationsController' => 'applications/meta/controller/PhabricatorApplicationsController.php',
'PhabricatorApplicationsListController' => 'applications/meta/controller/PhabricatorApplicationsListController.php', 'PhabricatorApplicationsListController' => 'applications/meta/controller/PhabricatorApplicationsListController.php',
@ -1617,13 +1620,16 @@ phutil_register_library_map(array(
'Phabricator404Controller' => 'PhabricatorController', 'Phabricator404Controller' => 'PhabricatorController',
'PhabricatorApplicationApplications' => 'PhabricatorApplication', 'PhabricatorApplicationApplications' => 'PhabricatorApplication',
'PhabricatorApplicationAudit' => 'PhabricatorApplication', 'PhabricatorApplicationAudit' => 'PhabricatorApplication',
'PhabricatorApplicationAuth' => 'PhabricatorApplication',
'PhabricatorApplicationDifferential' => 'PhabricatorApplication', 'PhabricatorApplicationDifferential' => 'PhabricatorApplication',
'PhabricatorApplicationDiffusion' => 'PhabricatorApplication', 'PhabricatorApplicationDiffusion' => 'PhabricatorApplication',
'PhabricatorApplicationFact' => 'PhabricatorApplication', 'PhabricatorApplicationFact' => 'PhabricatorApplication',
'PhabricatorApplicationFlags' => 'PhabricatorApplication', 'PhabricatorApplicationFlags' => 'PhabricatorApplication',
'PhabricatorApplicationLaunchView' => 'AphrontView', 'PhabricatorApplicationLaunchView' => 'AphrontView',
'PhabricatorApplicationManiphest' => 'PhabricatorApplication', 'PhabricatorApplicationManiphest' => 'PhabricatorApplication',
'PhabricatorApplicationPeople' => 'PhabricatorApplication',
'PhabricatorApplicationPhriction' => 'PhabricatorApplication', 'PhabricatorApplicationPhriction' => 'PhabricatorApplication',
'PhabricatorApplicationSettings' => 'PhabricatorApplication',
'PhabricatorApplicationStatusView' => 'AphrontView', 'PhabricatorApplicationStatusView' => 'AphrontView',
'PhabricatorApplicationsController' => 'PhabricatorController', 'PhabricatorApplicationsController' => 'PhabricatorController',
'PhabricatorApplicationsListController' => 'PhabricatorApplicationsController', 'PhabricatorApplicationsListController' => 'PhabricatorApplicationsController',

View file

@ -32,6 +32,10 @@ abstract class AphrontController {
return; return;
} }
public function didProcessRequest($response) {
return $response;
}
abstract public function processRequest(); abstract public function processRequest();
final public function __construct(AphrontRequest $request) { final public function __construct(AphrontRequest $request) {

View file

@ -67,15 +67,6 @@ class AphrontDefaultApplicationConfiguration
'/phid/' => array( '/phid/' => array(
'' => 'PhabricatorPHIDLookupController', '' => 'PhabricatorPHIDLookupController',
), ),
'/people/' => array(
'' => 'PhabricatorPeopleListController',
'logs/' => 'PhabricatorPeopleLogsController',
'edit/(?:(?P<id>\d+)/(?:(?P<view>\w+)/)?)?'
=> 'PhabricatorPeopleEditController',
'ldap/' => 'PhabricatorPeopleLdapController',
),
'/p/(?P<username>[\w._-]+)/(?:(?P<page>\w+)/)?'
=> 'PhabricatorPeopleProfileController',
'/conduit/' => array( '/conduit/' => array(
'' => 'PhabricatorConduitListController', '' => 'PhabricatorConduitListController',
'method/(?P<method>[^/]+)/' => 'PhabricatorConduitConsoleController', 'method/(?P<method>[^/]+)/' => 'PhabricatorConduitConsoleController',
@ -152,10 +143,6 @@ class AphrontDefaultApplicationConfiguration
'/~/' => 'DarkConsoleController', '/~/' => 'DarkConsoleController',
'/settings/' => array(
'(?:page/(?P<page>[^/]+)/)?' => 'PhabricatorUserSettingsController',
),
'/repository/' => array( '/repository/' => array(
'' => 'PhabricatorRepositoryListController', '' => 'PhabricatorRepositoryListController',
'create/' => 'PhabricatorRepositoryCreateController', 'create/' => 'PhabricatorRepositoryCreateController',
@ -486,35 +473,6 @@ class AphrontDefaultApplicationConfiguration
} }
public function willSendResponse(AphrontResponse $response) { public function willSendResponse(AphrontResponse $response) {
$request = $this->getRequest();
$response->setRequest($request);
if ($response instanceof AphrontDialogResponse) {
if (!$request->isAjax()) {
$view = new PhabricatorStandardPageView();
$view->setRequest($request);
$view->appendChild(
'<div style="padding: 2em 0;">'.
$response->buildResponseString().
'</div>');
$response = new AphrontWebpageResponse();
$response->setContent($view->render());
return $response;
} else {
return id(new AphrontAjaxResponse())
->setContent(array(
'dialog' => $response->buildResponseString(),
));
}
} else if ($response instanceof AphrontRedirectResponse) {
if ($request->isAjax()) {
return id(new AphrontAjaxResponse())
->setContent(
array(
'redirect' => $response->getURI(),
));
}
}
return $response; return $response;
} }

View file

@ -0,0 +1,45 @@
<?php
/*
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
final class PhabricatorApplicationAuth extends PhabricatorApplication {
public function shouldAppearInLaunchView() {
return false;
}
public function buildMainMenuItems(
PhabricatorUser $user,
PhabricatorController $controller) {
$items = array();
if ($user->isLoggedIn()) {
require_celerity_resource('phabricator-glyph-css');
$item = new PhabricatorMainMenuIconView();
$item->setName(pht('Log Out'));
$item->addClass('glyph glyph-logout');
$item->setHref('/logout/');
$item->setSortOrder(1.0);
$items[] = $item;
}
return $items;
}
}

View file

@ -85,6 +85,12 @@ abstract class PhabricatorApplication {
return array(); return array();
} }
public function buildMainMenuItems(
PhabricatorUser $user,
PhabricatorController $controller) {
return array();
}
/* -( Application Management )--------------------------------------------- */ /* -( Application Management )--------------------------------------------- */

View file

@ -111,6 +111,7 @@ abstract class PhabricatorController extends AphrontController {
public function buildStandardPageView() { public function buildStandardPageView() {
$view = new PhabricatorStandardPageView(); $view = new PhabricatorStandardPageView();
$view->setRequest($this->getRequest()); $view->setRequest($this->getRequest());
$view->setController($this);
if ($this->shouldRequireAdmin()) { if ($this->shouldRequireAdmin()) {
$view->setIsAdminInterface(true); $view->setIsAdminInterface(true);
@ -127,4 +128,37 @@ abstract class PhabricatorController extends AphrontController {
return $response; return $response;
} }
public function didProcessRequest($response) {
$request = $this->getRequest();
$response->setRequest($request);
if ($response instanceof AphrontDialogResponse) {
if (!$request->isAjax()) {
$view = new PhabricatorStandardPageView();
$view->setRequest($request);
$view->setController($this);
$view->appendChild(
'<div style="padding: 2em 0;">'.
$response->buildResponseString().
'</div>');
$response = new AphrontWebpageResponse();
$response->setContent($view->render());
return $response;
} else {
return id(new AphrontAjaxResponse())
->setContent(array(
'dialog' => $response->buildResponseString(),
));
}
} else if ($response instanceof AphrontRedirectResponse) {
if ($request->isAjax()) {
return id(new AphrontAjaxResponse())
->setContent(
array(
'redirect' => $response->getURI(),
));
}
}
return $response;
}
} }

View file

@ -0,0 +1,66 @@
<?php
/*
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
final class PhabricatorApplicationPeople extends PhabricatorApplication {
public function getShortDescription() {
return 'User Accounts';
}
public function getBaseURI() {
return '/people/';
}
public function getIconURI() {
return celerity_get_resource_uri('/rsrc/image/app/app_people.png');
}
public function getRoutes() {
return array(
'/people/' => array(
'' => 'PhabricatorPeopleListController',
'logs/' => 'PhabricatorPeopleLogsController',
'edit/(?:(?P<id>\d+)/(?:(?P<view>\w+)/)?)?'
=> 'PhabricatorPeopleEditController',
'ldap/' => 'PhabricatorPeopleLdapController',
),
'/p/(?P<username>[\w._-]+)/(?:(?P<page>\w+)/)?'
=> 'PhabricatorPeopleProfileController',
);
}
public function buildMainMenuItems(
PhabricatorUser $user,
PhabricatorController $controller) {
$items = array();
if ($user->isLoggedIn()) {
require_celerity_resource('phabricator-glyph-css');
$item = new PhabricatorMainMenuIconView();
$item->setName($user->getUsername());
$item->addClass('glyph glyph-profile');
$item->setHref('/p/'.$user->getUsername().'/');
$item->setSortOrder(0.0);
$items[] = $item;
}
return $items;
}
}

View file

@ -0,0 +1,61 @@
<?php
/*
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
final class PhabricatorApplicationSettings extends PhabricatorApplication {
public function getBaseURI() {
return '/settings/';
}
public function getShortDescription() {
return 'User Preferences';
}
public function getIconURI() {
return celerity_get_resource_uri('/rsrc/image/app/app_settings.png');
}
public function getRoutes() {
return array(
'/settings/' => array(
'(?:page/(?P<page>[^/]+)/)?' => 'PhabricatorUserSettingsController',
),
);
}
public function buildMainMenuItems(
PhabricatorUser $user,
PhabricatorController $controller) {
$items = array();
if ($user->isLoggedIn()) {
require_celerity_resource('phabricator-glyph-css');
$item = new PhabricatorMainMenuIconView();
$item->setName(pht('Settings'));
$item->addClass('glyph glyph-settings');
$item->setHref('/settings/');
$item->setSortOrder(0.90);
$items[] = $item;
}
return $items;
}
}

View file

@ -32,6 +32,16 @@ final class PhabricatorStandardPageView extends AphrontPageView {
private $disableConsole; private $disableConsole;
private $searchDefaultScope; private $searchDefaultScope;
private $pageObjects = array(); private $pageObjects = array();
private $controller;
public function setController(AphrontController $controller) {
$this->controller = $controller;
return $this;
}
public function getController() {
return $this->controller;
}
public function setIsAdminInterface($is_admin_interface) { public function setIsAdminInterface($is_admin_interface) {
$this->isAdminInterface = $is_admin_interface; $this->isAdminInterface = $is_admin_interface;
@ -505,27 +515,17 @@ final class PhabricatorStandardPageView extends AphrontPageView {
Javelin::initBehavior('phabricator-keyboard-shortcuts', $keyboard_config); Javelin::initBehavior('phabricator-keyboard-shortcuts', $keyboard_config);
if ($user->isLoggedIn()) { $applications = PhabricatorApplication::getAllInstalledApplications();
require_celerity_resource('phabricator-glyph-css'); $icon_views = array();
foreach ($applications as $application) {
$item = new PhabricatorMainMenuIconView(); $icon_views[] = $application->buildMainMenuItems(
$item->setName($user->getUsername()); $this->getRequest()->getUser(),
$item->addClass('glyph glyph-profile'); $this->getController());
$item->setHref('/p/'.$user->getUsername().'/');
$menu->appendChild($item);
$item = new PhabricatorMainMenuIconView();
$item->setName(pht('Settings'));
$item->addClass('glyph glyph-settings');
$item->setHref('/settings/');
$menu->appendChild($item);
$item = new PhabricatorMainMenuIconView();
$item->setName(pht('Log Out'));
$item->addClass('glyph glyph-logout');
$item->setHref('/logout/');
$menu->appendChild($item);
} }
$icon_views = array_mergev($icon_views);
$icon_views = msort($icon_views, 'getSortOrder');
$menu->appendChild($icon_views);
return $menu->render(); return $menu->render();
} }

View file

@ -21,6 +21,7 @@ final class PhabricatorMainMenuIconView extends AphrontView {
private $classes = array(); private $classes = array();
private $href; private $href;
private $name; private $name;
private $sortOrder = 0.5;
public function setName($name) { public function setName($name) {
$this->name = $name; $this->name = $name;
@ -45,6 +46,21 @@ final class PhabricatorMainMenuIconView extends AphrontView {
return $this; return $this;
} }
/**
* Provide a float, where 0.0 is the profile item and 1.0 is the logout
* item. Normally you should pick something between the two.
*
* @param float Sort order.
* @return this
*/
public function setSortOrder($sort_order) {
$this->sortOrder = $sort_order;
return $this;
}
public function getSortOrder() {
return $this->sortOrder;
}
public function render() { public function render() {
$name = $this->getName(); $name = $this->getName();

View file

@ -192,6 +192,7 @@ try {
if (!$response) { if (!$response) {
$controller->willProcessRequest($uri_data); $controller->willProcessRequest($uri_data);
$response = $controller->processRequest(); $response = $controller->processRequest();
$response = $controller->didProcessRequest($response);
} }
} catch (AphrontRedirectException $ex) { } catch (AphrontRedirectException $ex) {
$response = id(new AphrontRedirectResponse()) $response = id(new AphrontRedirectResponse())
@ -202,7 +203,7 @@ try {
} }
try { try {
$response = $application->willSendResponse($response); $response = $application->willSendResponse($response, $controller);
$response->setRequest($request); $response->setRequest($request);
$response_string = $response->buildResponseString(); $response_string = $response->buildResponseString();
} catch (Exception $ex) { } catch (Exception $ex) {

Binary file not shown.

After

Width:  |  Height:  |  Size: 496 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 204 B