1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 06:42:42 +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',
'PhabricatorApplicationApplications' => 'applications/meta/application/PhabricatorApplicationApplications.php',
'PhabricatorApplicationAudit' => 'applications/audit/application/PhabricatorApplicationAudit.php',
'PhabricatorApplicationAuth' => 'applications/auth/application/PhabricatorApplicationAuth.php',
'PhabricatorApplicationDifferential' => 'applications/differential/application/PhabricatorApplicationDifferential.php',
'PhabricatorApplicationDiffusion' => 'applications/diffusion/application/PhabricatorApplicationDiffusion.php',
'PhabricatorApplicationFact' => 'applications/fact/application/PhabricatorApplicationFact.php',
'PhabricatorApplicationFlags' => 'applications/flag/application/PhabricatorApplicationFlags.php',
'PhabricatorApplicationLaunchView' => 'applications/meta/view/PhabricatorApplicationLaunchView.php',
'PhabricatorApplicationManiphest' => 'applications/maniphest/application/PhabricatorApplicationManiphest.php',
'PhabricatorApplicationPeople' => 'applications/people/application/PhabricatorApplicationPeople.php',
'PhabricatorApplicationPhriction' => 'applications/phriction/application/PhabricatorApplicationPhriction.php',
'PhabricatorApplicationSettings' => 'applications/people/application/PhabricatorApplicationSettings.php',
'PhabricatorApplicationStatusView' => 'applications/meta/view/PhabricatorApplicationStatusView.php',
'PhabricatorApplicationsController' => 'applications/meta/controller/PhabricatorApplicationsController.php',
'PhabricatorApplicationsListController' => 'applications/meta/controller/PhabricatorApplicationsListController.php',
@ -1617,13 +1620,16 @@ phutil_register_library_map(array(
'Phabricator404Controller' => 'PhabricatorController',
'PhabricatorApplicationApplications' => 'PhabricatorApplication',
'PhabricatorApplicationAudit' => 'PhabricatorApplication',
'PhabricatorApplicationAuth' => 'PhabricatorApplication',
'PhabricatorApplicationDifferential' => 'PhabricatorApplication',
'PhabricatorApplicationDiffusion' => 'PhabricatorApplication',
'PhabricatorApplicationFact' => 'PhabricatorApplication',
'PhabricatorApplicationFlags' => 'PhabricatorApplication',
'PhabricatorApplicationLaunchView' => 'AphrontView',
'PhabricatorApplicationManiphest' => 'PhabricatorApplication',
'PhabricatorApplicationPeople' => 'PhabricatorApplication',
'PhabricatorApplicationPhriction' => 'PhabricatorApplication',
'PhabricatorApplicationSettings' => 'PhabricatorApplication',
'PhabricatorApplicationStatusView' => 'AphrontView',
'PhabricatorApplicationsController' => 'PhabricatorController',
'PhabricatorApplicationsListController' => 'PhabricatorApplicationsController',

View file

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

View file

@ -67,15 +67,6 @@ class AphrontDefaultApplicationConfiguration
'/phid/' => array(
'' => '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(
'' => 'PhabricatorConduitListController',
'method/(?P<method>[^/]+)/' => 'PhabricatorConduitConsoleController',
@ -152,10 +143,6 @@ class AphrontDefaultApplicationConfiguration
'/~/' => 'DarkConsoleController',
'/settings/' => array(
'(?:page/(?P<page>[^/]+)/)?' => 'PhabricatorUserSettingsController',
),
'/repository/' => array(
'' => 'PhabricatorRepositoryListController',
'create/' => 'PhabricatorRepositoryCreateController',
@ -486,35 +473,6 @@ class AphrontDefaultApplicationConfiguration
}
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;
}

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();
}
public function buildMainMenuItems(
PhabricatorUser $user,
PhabricatorController $controller) {
return array();
}
/* -( Application Management )--------------------------------------------- */

View file

@ -111,6 +111,7 @@ abstract class PhabricatorController extends AphrontController {
public function buildStandardPageView() {
$view = new PhabricatorStandardPageView();
$view->setRequest($this->getRequest());
$view->setController($this);
if ($this->shouldRequireAdmin()) {
$view->setIsAdminInterface(true);
@ -127,4 +128,37 @@ abstract class PhabricatorController extends AphrontController {
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 $searchDefaultScope;
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) {
$this->isAdminInterface = $is_admin_interface;
@ -505,27 +515,17 @@ final class PhabricatorStandardPageView extends AphrontPageView {
Javelin::initBehavior('phabricator-keyboard-shortcuts', $keyboard_config);
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().'/');
$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);
$applications = PhabricatorApplication::getAllInstalledApplications();
$icon_views = array();
foreach ($applications as $application) {
$icon_views[] = $application->buildMainMenuItems(
$this->getRequest()->getUser(),
$this->getController());
}
$icon_views = array_mergev($icon_views);
$icon_views = msort($icon_views, 'getSortOrder');
$menu->appendChild($icon_views);
return $menu->render();
}

View file

@ -21,6 +21,7 @@ final class PhabricatorMainMenuIconView extends AphrontView {
private $classes = array();
private $href;
private $name;
private $sortOrder = 0.5;
public function setName($name) {
$this->name = $name;
@ -45,6 +46,21 @@ final class PhabricatorMainMenuIconView extends AphrontView {
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() {
$name = $this->getName();

View file

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 496 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 204 B