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

Owners -- kill tabs

Summary:
pretty standard MO, but a little tricky in that we dynamically pre-pend
filters for "new", "edit", "search results" and "details" use cases.

Test Plan:
clicked around owners a bunch and verified proper filters showed up
and that when clicked they worked as expected

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, epriestley

Maniphest Tasks: T631

Differential Revision: https://secure.phabricator.com/D1516
This commit is contained in:
Bob Trahan 2012-01-10 11:21:49 -08:00
parent deed4ffed0
commit 2c3a08b37b
9 changed files with 149 additions and 101 deletions

View file

@ -1,7 +1,7 @@
<?php <?php
/* /*
* Copyright 2011 Facebook, Inc. * Copyright 2012 Facebook, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -18,6 +18,15 @@
abstract class PhabricatorOwnersController extends PhabricatorController { abstract class PhabricatorOwnersController extends PhabricatorController {
private $filter;
private function getSideNavFilter() {
return $this->filter;
}
protected function setSideNavFilter($filter) {
$this->filter = $filter;
return $this;
}
public function buildStandardPageResponse($view, array $data) { public function buildStandardPageResponse($view, array $data) {
$page = $this->buildStandardPageView(); $page = $this->buildStandardPageView();
@ -25,22 +34,65 @@ abstract class PhabricatorOwnersController extends PhabricatorController {
$page->setApplicationName('Owners'); $page->setApplicationName('Owners');
$page->setBaseURI('/owners/'); $page->setBaseURI('/owners/');
$page->setTitle(idx($data, 'title')); $page->setTitle(idx($data, 'title'));
$page->setTabs(
array(
'index' => array(
'href' => '/owners/',
'name' => 'Package Index',
),
'related' => array(
'href' => '/owners/related/',
'name' => 'Related Commits',
),
),
idx($data, 'tab'));
$page->setGlyph("\xE2\x98\x81"); $page->setGlyph("\xE2\x98\x81");
$page->appendChild($view); $nav = $this->renderSideNav();
$nav->appendChild($view);
$page->appendChild($nav);
$response = new AphrontWebpageResponse(); $response = new AphrontWebpageResponse();
return $response->setContent($page->render()); return $response->setContent($page->render());
} }
public function renderSideNav() {
$package_views = array(
array('name' => 'Owned',
'key' => 'view/owned'),
array('name' => 'All',
'key' => 'view/all'),
);
$package_views =
array_merge($this->getExtraPackageViews(),
$package_views);
$base_uri = new PhutilURI('/owners/');
$nav = new AphrontSideNavFilterView();
$nav->setBaseUri($base_uri);
$nav->addLabel('Packages');
foreach ($package_views as $view) {
$nav->addFilter($view['key'], $view['name']);
}
$nav->addSpacer();
$nav->addLabel('Related Commits');
$related_views = $this->getRelatedViews();
foreach ($related_views as $view) {
$href = clone $base_uri;
$href->setPath($href->getPath().$view['key']);
$href = (string)$href;
$nav->addFilter($view['key'],
$view['name'],
$href);
}
$filter = $this->getSideNavFilter();
$nav->selectFilter($filter, 'view/owned');
return $nav;
}
protected function getExtraPackageViews() {
return array();
}
protected function getRelatedViews() {
$related_views = array(
array('name' => 'Related to Package',
'key' => 'related/view/all'),
array('name' => 'Needs Attention',
'key' => 'related/view/audit')
);
return $related_views;
}
} }

View file

@ -8,7 +8,9 @@
phutil_require_module('phabricator', 'aphront/response/webpage'); phutil_require_module('phabricator', 'aphront/response/webpage');
phutil_require_module('phabricator', 'applications/base/controller/base'); phutil_require_module('phabricator', 'applications/base/controller/base');
phutil_require_module('phabricator', 'view/layout/sidenavfilter');
phutil_require_module('phutil', 'parser/uri');
phutil_require_module('phutil', 'utils'); phutil_require_module('phutil', 'utils');

View file

@ -1,7 +1,7 @@
<?php <?php
/* /*
* Copyright 2011 Facebook, Inc. * Copyright 2012 Facebook, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -19,6 +19,7 @@
class PhabricatorOwnersDetailController extends PhabricatorOwnersController { class PhabricatorOwnersDetailController extends PhabricatorOwnersController {
private $id; private $id;
private $package;
public function willProcessRequest(array $data) { public function willProcessRequest(array $data) {
$this->id = $data['id']; $this->id = $data['id'];
@ -32,6 +33,7 @@ class PhabricatorOwnersDetailController extends PhabricatorOwnersController {
if (!$package) { if (!$package) {
return new Aphront404Response(); return new Aphront404Response();
} }
$this->package = $package;
$paths = $package->loadPaths(); $paths = $package->loadPaths();
$owners = $package->loadOwners(); $owners = $package->loadOwners();
@ -138,22 +140,22 @@ class PhabricatorOwnersDetailController extends PhabricatorOwnersController {
'Edit Package')); 'Edit Package'));
$panel->appendChild($table); $panel->appendChild($table);
$nav = new AphrontSideNavView(); $key = 'package/'.$package->getID();
$nav->appendChild($panel); $this->setSideNavFilter($key);
$nav->addNavItem(
phutil_render_tag(
'a',
array(
'href' => '/owners/package/'.$package->getID().'/',
'class' => 'aphront-side-nav-selected',
),
'Package Details'));
return $this->buildStandardPageResponse( return $this->buildStandardPageResponse(
$nav, $panel,
array( array(
'title' => "Package '".$package->getName()."'", 'title' => "Package '".$package->getName()."'",
)); ));
} }
protected function getExtraPackageViews() {
$package = $this->package;
return array(
array('name' => 'Details',
'key' => 'package/'.$package->getID(),
));
}
} }

View file

@ -13,7 +13,6 @@ phutil_require_module('phabricator', 'applications/phid/handle/data');
phutil_require_module('phabricator', 'infrastructure/javelin/markup'); phutil_require_module('phabricator', 'infrastructure/javelin/markup');
phutil_require_module('phabricator', 'view/control/table'); phutil_require_module('phabricator', 'view/control/table');
phutil_require_module('phabricator', 'view/layout/panel'); phutil_require_module('phabricator', 'view/layout/panel');
phutil_require_module('phabricator', 'view/layout/sidenav');
phutil_require_module('phutil', 'markup'); phutil_require_module('phutil', 'markup');
phutil_require_module('phutil', 'utils'); phutil_require_module('phutil', 'utils');

View file

@ -1,7 +1,7 @@
<?php <?php
/* /*
* Copyright 2011 Facebook, Inc. * Copyright 2012 Facebook, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -146,7 +146,14 @@ class PhabricatorOwnersEditController extends PhabricatorOwnersController {
$token_all_owners = array_select_keys($handles, $owners); $token_all_owners = array_select_keys($handles, $owners);
$token_all_owners = mpull($token_all_owners, 'getFullName'); $token_all_owners = mpull($token_all_owners, 'getFullName');
$title = $package->getID() ? 'Edit Package' : 'New Package'; if ($package->getID()) {
$title = 'Edit Package';
$side_nav_filter = 'edit/'.$this->id;
} else {
$title = 'New Package';
$side_nav_filter = 'new';
}
$this->setSideNavFilter($side_nav_filter);
$repos = id(new PhabricatorRepository())->loadAll(); $repos = id(new PhabricatorRepository())->loadAll();
@ -268,4 +275,15 @@ class PhabricatorOwnersEditController extends PhabricatorOwnersController {
)); ));
} }
protected function getExtraPackageViews() {
if ($this->id) {
$extra = array(array('name' => 'Edit',
'key' => 'edit/'.$this->id));
} else {
$extra = array(array('name' => 'New',
'key' => 'new'));
}
return $extra;
}
} }

View file

@ -1,7 +1,7 @@
<?php <?php
/* /*
* Copyright 2011 Facebook, Inc. * Copyright 2012 Facebook, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -18,10 +18,11 @@
class PhabricatorOwnersListController extends PhabricatorOwnersController { class PhabricatorOwnersListController extends PhabricatorOwnersController {
private $view; protected $view;
public function willProcessRequest(array $data) { public function willProcessRequest(array $data) {
$this->view = idx($data, 'view'); $this->view = idx($data, 'view', 'owned');
$this->setSideNavFilter('view/'.$this->view);
} }
public function processRequest() { public function processRequest() {
@ -29,35 +30,6 @@ class PhabricatorOwnersListController extends PhabricatorOwnersController {
$request = $this->getRequest(); $request = $this->getRequest();
$user = $request->getUser(); $user = $request->getUser();
$views = array(
'owned' => 'Owned Packages',
'all' => 'All Packages',
'search' => 'Search Results',
);
if (empty($views[$this->view])) {
reset($views);
$this->view = key($views);
}
if ($this->view != 'search') {
unset($views['search']);
}
$nav = new AphrontSideNavView();
foreach ($views as $key => $name) {
$nav->addNavItem(
phutil_render_tag(
'a',
array(
'href' => '/owners/view/'.$key.'/',
'class' => ($this->view == $key)
? 'aphront-side-nav-selected'
: null,
),
phutil_escape_html($name)));
}
$package = new PhabricatorOwnersPackage(); $package = new PhabricatorOwnersPackage();
$owner = new PhabricatorOwnersOwner(); $owner = new PhabricatorOwnersOwner();
$path = new PhabricatorOwnersPath(); $path = new PhabricatorOwnersPath();
@ -184,14 +156,13 @@ class PhabricatorOwnersListController extends PhabricatorOwnersController {
$filter->appendChild($form); $filter->appendChild($form);
$nav->appendChild($filter);
$nav->appendChild($content);
return $this->buildStandardPageResponse( return $this->buildStandardPageResponse(
$nav, array(
$filter,
$content,
),
array( array(
'title' => 'Package Index', 'title' => 'Package Index',
'tab' => 'index',
)); ));
} }
@ -289,4 +260,17 @@ class PhabricatorOwnersListController extends PhabricatorOwnersController {
return $panel; return $panel;
} }
protected function getExtraPackageViews() {
switch ($this->view) {
case 'search':
$extra = array(array('name' => 'Search Results',
'key' => 'view/search'));
break;
default:
$extra = array();
break;
}
return $extra;
}
} }

View file

@ -20,7 +20,6 @@ phutil_require_module('phabricator', 'view/form/control/text');
phutil_require_module('phabricator', 'view/form/control/tokenizer'); phutil_require_module('phabricator', 'view/form/control/tokenizer');
phutil_require_module('phabricator', 'view/layout/listfilter'); phutil_require_module('phabricator', 'view/layout/listfilter');
phutil_require_module('phabricator', 'view/layout/panel'); phutil_require_module('phabricator', 'view/layout/panel');
phutil_require_module('phabricator', 'view/layout/sidenav');
phutil_require_module('phutil', 'markup'); phutil_require_module('phutil', 'markup');
phutil_require_module('phutil', 'utils'); phutil_require_module('phutil', 'utils');

View file

@ -1,7 +1,7 @@
<?php <?php
/* /*
* Copyright 2011 Facebook, Inc. * Copyright 2012 Facebook, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -50,19 +50,39 @@ class PhabricatorOwnerRelatedListController
$search_view = $this->renderSearchView(); $search_view = $this->renderSearchView();
$list_panel = $this->renderListPanel(); $list_panel = $this->renderListPanel();
$nav = $this->renderSideNav();
$nav->appendChild($search_view); $side_nav_filter = 'related/view/'.$this->view.$this->getQueryString();
$nav->appendChild($list_panel); $this->setSideNavFilter($side_nav_filter);
return $this->buildStandardPageResponse( return $this->buildStandardPageResponse(
$nav, array(
$search_view,
$list_panel
),
array( array(
'title' => 'Related Commits', 'title' => 'Related Commits',
'tab' => 'related',
)); ));
} }
protected function getRelatedViews() {
$related_views = parent::getRelatedViews();
if ($this->packagePHID) {
$query = $this->getQueryString();
foreach ($related_views as &$view) {
$view['key'] = $view['key'].$query;
}
}
return $related_views;
}
private function getQueryString() {
$query = null;
if ($this->packagePHID) {
$query = '/?phid=' . $this->packagePHID;
}
return $query;
}
private function renderListPanel() { private function renderListPanel() {
if (!$this->packagePHID) { if (!$this->packagePHID) {
return id(new AphrontErrorView()) return id(new AphrontErrorView())
@ -151,33 +171,6 @@ class PhabricatorOwnerRelatedListController
return $status_arr; return $status_arr;
} }
private function renderSideNav() {
$views = array(
'all' => 'Related to Package',
'audit' => 'Needs Attention',
);
$query = null;
if ($this->packagePHID) {
$query = '?phid=' . $this->packagePHID;
}
$nav = new AphrontSideNavView();
foreach ($views as $key => $name) {
$nav->addNavItem(
phutil_render_tag(
'a',
array(
'href' => '/owners/related/view/'.$key.'/'.$query,
'class' => ($this->view === $key
? 'aphront-side-nav-selected'
: null),
),
phutil_escape_html($name)));
}
return $nav;
}
private function renderSearchView() { private function renderSearchView() {
if ($this->packagePHID) { if ($this->packagePHID) {
$loader = new PhabricatorObjectHandleData(array($this->packagePHID)); $loader = new PhabricatorObjectHandleData(array($this->packagePHID));

View file

@ -23,7 +23,6 @@ phutil_require_module('phabricator', 'view/form/control/tokenizer');
phutil_require_module('phabricator', 'view/form/error'); phutil_require_module('phabricator', 'view/form/error');
phutil_require_module('phabricator', 'view/layout/listfilter'); phutil_require_module('phabricator', 'view/layout/listfilter');
phutil_require_module('phabricator', 'view/layout/panel'); phutil_require_module('phabricator', 'view/layout/panel');
phutil_require_module('phabricator', 'view/layout/sidenav');
phutil_require_module('phabricator', 'view/utils'); phutil_require_module('phabricator', 'view/utils');
phutil_require_module('phutil', 'markup'); phutil_require_module('phutil', 'markup');