2011-02-21 03:41:23 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
abstract class PhabricatorProjectController extends PhabricatorController {
|
|
|
|
|
2015-02-23 20:27:19 +01:00
|
|
|
private $project;
|
|
|
|
|
|
|
|
protected function setProject(PhabricatorProject $project) {
|
|
|
|
$this->project = $project;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getProject() {
|
|
|
|
return $this->project;
|
|
|
|
}
|
|
|
|
|
2015-12-27 11:04:37 +01:00
|
|
|
protected function loadProject() {
|
|
|
|
$viewer = $this->getViewer();
|
|
|
|
$request = $this->getRequest();
|
|
|
|
|
|
|
|
$id = $request->getURIData('id');
|
|
|
|
$slug = $request->getURIData('slug');
|
|
|
|
|
|
|
|
if ($slug) {
|
|
|
|
$normal_slug = PhabricatorSlug::normalizeProjectSlug($slug);
|
|
|
|
$is_abnormal = ($slug !== $normal_slug);
|
|
|
|
$normal_uri = "/tag/{$normal_slug}/";
|
|
|
|
} else {
|
|
|
|
$is_abnormal = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$query = id(new PhabricatorProjectQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->needMembers(true)
|
|
|
|
->needWatchers(true)
|
|
|
|
->needImages(true)
|
|
|
|
->needSlugs(true);
|
|
|
|
|
|
|
|
if ($slug) {
|
|
|
|
$query->withSlugs(array($slug));
|
|
|
|
} else {
|
|
|
|
$query->withIDs(array($id));
|
|
|
|
}
|
|
|
|
|
|
|
|
$policy_exception = null;
|
|
|
|
try {
|
|
|
|
$project = $query->executeOne();
|
|
|
|
} catch (PhabricatorPolicyException $ex) {
|
|
|
|
$policy_exception = $ex;
|
|
|
|
$project = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$project) {
|
|
|
|
// This project legitimately does not exist, so just 404 the user.
|
|
|
|
if (!$policy_exception) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Here, the project exists but the user can't see it. If they are
|
|
|
|
// using a non-canonical slug to view the project, redirect to the
|
|
|
|
// canonical slug. If they're already using the canonical slug, rethrow
|
|
|
|
// the exception to give them the policy error.
|
|
|
|
if ($is_abnormal) {
|
|
|
|
return id(new AphrontRedirectResponse())->setURI($normal_uri);
|
|
|
|
} else {
|
|
|
|
throw $policy_exception;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// The user can view the project, but is using a noncanonical slug.
|
|
|
|
// Redirect to the canonical slug.
|
|
|
|
$primary_slug = $project->getPrimarySlug();
|
|
|
|
if ($slug && ($slug !== $primary_slug)) {
|
|
|
|
$primary_uri = "/tag/{$primary_slug}/";
|
|
|
|
return id(new AphrontRedirectResponse())->setURI($primary_uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->setProject($project);
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2015-01-12 19:04:01 +01:00
|
|
|
public function buildApplicationMenu() {
|
|
|
|
return $this->buildSideNavView(true)->getMenu();
|
|
|
|
}
|
|
|
|
|
2013-07-22 17:34:35 +02:00
|
|
|
public function buildSideNavView($for_app = false) {
|
2015-02-23 20:27:19 +01:00
|
|
|
$project = $this->getProject();
|
2013-02-13 18:22:14 +01:00
|
|
|
|
|
|
|
$nav = new AphrontSideNavFilterView();
|
2013-07-22 17:34:35 +02:00
|
|
|
$nav->setBaseURI(new PhutilURI($this->getApplicationURI()));
|
2013-02-13 18:22:14 +01:00
|
|
|
|
2015-02-23 20:27:19 +01:00
|
|
|
$viewer = $this->getViewer();
|
|
|
|
|
2015-02-23 21:45:59 +01:00
|
|
|
$id = null;
|
2013-02-13 18:22:14 +01:00
|
|
|
if ($for_app) {
|
2015-02-23 20:27:19 +01:00
|
|
|
if ($project) {
|
|
|
|
$id = $project->getID();
|
2015-01-12 19:04:01 +01:00
|
|
|
$nav->addFilter("profile/{$id}/", pht('Profile'));
|
|
|
|
$nav->addFilter("board/{$id}/", pht('Workboard'));
|
|
|
|
$nav->addFilter("members/{$id}/", pht('Members'));
|
|
|
|
$nav->addFilter("feed/{$id}/", pht('Feed'));
|
|
|
|
}
|
2013-07-22 17:34:35 +02:00
|
|
|
$nav->addFilter('create', pht('Create Project'));
|
2013-02-13 18:22:14 +01:00
|
|
|
}
|
|
|
|
|
2015-01-12 19:04:01 +01:00
|
|
|
if (!$id) {
|
|
|
|
id(new PhabricatorProjectSearchEngine())
|
2015-01-19 19:14:27 +01:00
|
|
|
->setViewer($viewer)
|
2015-01-12 19:04:01 +01:00
|
|
|
->addNavigationItems($nav->getMenu());
|
|
|
|
}
|
2013-07-22 17:34:35 +02:00
|
|
|
|
|
|
|
$nav->selectFilter(null);
|
|
|
|
|
2013-02-13 18:22:14 +01:00
|
|
|
return $nav;
|
|
|
|
}
|
|
|
|
|
2015-01-12 19:04:01 +01:00
|
|
|
public function buildIconNavView(PhabricatorProject $project) {
|
2015-02-23 20:27:19 +01:00
|
|
|
$this->setProject($project);
|
2015-01-19 19:14:27 +01:00
|
|
|
$viewer = $this->getViewer();
|
2015-01-12 19:04:01 +01:00
|
|
|
$id = $project->getID();
|
|
|
|
$picture = $project->getProfileImageURI();
|
|
|
|
$name = $project->getName();
|
|
|
|
|
2015-01-13 18:53:24 +01:00
|
|
|
$columns = id(new PhabricatorProjectColumnQuery())
|
2015-01-19 19:14:27 +01:00
|
|
|
->setViewer($viewer)
|
2015-01-13 18:53:24 +01:00
|
|
|
->withProjectPHIDs(array($project->getPHID()))
|
|
|
|
->execute();
|
|
|
|
if ($columns) {
|
|
|
|
$board_icon = 'fa-columns';
|
|
|
|
} else {
|
|
|
|
$board_icon = 'fa-columns grey';
|
|
|
|
}
|
|
|
|
|
2015-01-12 19:04:01 +01:00
|
|
|
$nav = new AphrontSideNavFilterView();
|
|
|
|
$nav->setIconNav(true);
|
|
|
|
$nav->setBaseURI(new PhutilURI($this->getApplicationURI()));
|
|
|
|
$nav->addIcon("profile/{$id}/", $name, null, $picture);
|
2015-01-19 19:14:27 +01:00
|
|
|
|
|
|
|
$class = 'PhabricatorManiphestApplication';
|
|
|
|
if (PhabricatorApplication::isClassInstalledForViewer($class, $viewer)) {
|
|
|
|
$phid = $project->getPHID();
|
2015-11-08 04:25:21 +01:00
|
|
|
$nav->addIcon("board/{$id}/", pht('Workboard'), $board_icon);
|
2015-01-19 19:14:27 +01:00
|
|
|
$query_uri = urisprintf(
|
2015-04-26 16:15:25 +02:00
|
|
|
'/maniphest/?statuses=open()&projects=%s#R',
|
|
|
|
$phid);
|
2015-01-19 19:14:27 +01:00
|
|
|
$nav->addIcon(null, pht('Open Tasks'), 'fa-anchor', null, $query_uri);
|
|
|
|
}
|
|
|
|
|
2015-01-12 19:04:01 +01:00
|
|
|
$nav->addIcon("feed/{$id}/", pht('Feed'), 'fa-newspaper-o');
|
|
|
|
$nav->addIcon("members/{$id}/", pht('Members'), 'fa-group');
|
|
|
|
|
2016-01-11 23:31:12 +01:00
|
|
|
if (false && PhabricatorEnv::getEnvConfig('phabricator.show-prototypes')) {
|
2015-12-27 14:16:36 +01:00
|
|
|
if ($project->supportsSubprojects()) {
|
|
|
|
$subprojects_icon = 'fa-sitemap';
|
|
|
|
} else {
|
|
|
|
$subprojects_icon = 'fa-sitemap grey';
|
|
|
|
}
|
|
|
|
|
Allow installs to customize project icons
Summary:
Ref T10010. Ref T5819. General alignment of the stars:
- There were some hacks in Conduit around stripping `fa-...` off icons when reading and writing that I wanted to get rid of.
- We probably have room for a subtitle in the new heavy nav, and using the icon name is a good starting point (and maybe good enough on its own?)
- The project list was real bad looking with redundant tag/names, now it is very slightly less bad looking with non-redundant types?
- Some installs will want to call Milestones something else, and this gets us a big part of the way there.
- This may slightly help to reinforce "tag" vs "policy" vs "group" stuff?
---
I'm letting installs have enough rope to shoot themselves in the foot (e.g., define 100 icons). It isn't the end of the world if they reuse icons, and is clearly their fault.
I think the cases where 100 icons will break down are:
- Icon selector dialog may get very unwieldy.
- Query UI will be pretty iffy/huge with 100 icons.
We could improve these fairly easily if an install comes up with a reasonable use case for having 100 icons.
---
The UI on the icon itself in the list views is a little iffy -- mostly, it's too saturated/bold.
I'd ideally like to try either:
- rendering a "shade" version (i.e. lighter, less-saturated color); or
- rendering a "shade" tag with just the icon in it.
However, there didn't seem to be a way to do the first one right now (`fa-example sh-blue` doesn't work) and the second one had weird margins/padding, so I left it like this for now. I figure we can clean it up once we build the thick nav, since that will probably also want an identical element.
(I don't want to render a full tag with the icon + name since I think that's confusing -- it looks like a project/object tag, but is not.)
Test Plan:
{F1049905}
{F1049906}
Reviewers: chad
Reviewed By: chad
Subscribers: 20after4, Luke081515.2
Maniphest Tasks: T5819, T10010
Differential Revision: https://secure.phabricator.com/D14918
2015-12-30 13:36:48 +01:00
|
|
|
$key = PhabricatorProjectIconSet::getMilestoneIconKey();
|
|
|
|
$milestones_icon = PhabricatorProjectIconSet::getIconIcon($key);
|
|
|
|
if (!$project->supportsMilestones()) {
|
|
|
|
$milestones_icon = "{$milestones_icon} grey";
|
2015-12-27 14:16:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$nav->addIcon(
|
|
|
|
"subprojects/{$id}/",
|
|
|
|
pht('Subprojects'),
|
|
|
|
$subprojects_icon);
|
|
|
|
|
|
|
|
$nav->addIcon(
|
|
|
|
"milestones/{$id}/",
|
|
|
|
pht('Milestones'),
|
|
|
|
$milestones_icon);
|
2015-12-27 13:47:08 +01:00
|
|
|
}
|
|
|
|
|
2015-01-12 19:04:01 +01:00
|
|
|
return $nav;
|
|
|
|
}
|
|
|
|
|
2015-12-27 13:10:59 +01:00
|
|
|
protected function buildApplicationCrumbs() {
|
|
|
|
$crumbs = parent::buildApplicationCrumbs();
|
|
|
|
|
|
|
|
$project = $this->getProject();
|
|
|
|
if ($project) {
|
|
|
|
$ancestors = $project->getAncestorProjects();
|
|
|
|
$ancestors = array_reverse($ancestors);
|
|
|
|
$ancestors[] = $project;
|
|
|
|
foreach ($ancestors as $ancestor) {
|
|
|
|
$crumbs->addTextCrumb(
|
2015-12-27 14:16:36 +01:00
|
|
|
$ancestor->getName(),
|
|
|
|
$ancestor->getURI());
|
2015-12-27 13:10:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $crumbs;
|
|
|
|
}
|
|
|
|
|
2011-02-21 03:41:23 +01:00
|
|
|
}
|