2014-03-26 22:40:47 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorProjectBoardViewController
|
|
|
|
extends PhabricatorProjectBoardController {
|
|
|
|
|
|
|
|
private $id;
|
2014-06-13 23:09:21 +02:00
|
|
|
private $slug;
|
2014-03-26 22:40:47 +01:00
|
|
|
private $handles;
|
2014-05-20 20:42:05 +02:00
|
|
|
private $queryKey;
|
|
|
|
private $filter;
|
2014-03-26 22:40:47 +01:00
|
|
|
|
|
|
|
public function shouldAllowPublic() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function willProcessRequest(array $data) {
|
2014-06-13 23:09:21 +02:00
|
|
|
$this->id = idx($data, 'id');
|
|
|
|
$this->slug = idx($data, 'slug');
|
2014-05-20 20:42:05 +02:00
|
|
|
$this->queryKey = idx($data, 'queryKey');
|
|
|
|
$this->filter = (bool)idx($data, 'filter');
|
2014-03-26 22:40:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$viewer = $request->getUser();
|
|
|
|
|
2014-06-25 21:30:20 +02:00
|
|
|
$show_hidden = $request->getBool('hidden');
|
|
|
|
|
2014-03-26 22:40:47 +01:00
|
|
|
$project = id(new PhabricatorProjectQuery())
|
|
|
|
->setViewer($viewer)
|
2014-06-13 23:09:21 +02:00
|
|
|
->needImages(true);
|
|
|
|
if ($this->slug) {
|
|
|
|
$project->withSlugs(array($this->slug));
|
|
|
|
} else {
|
|
|
|
$project->withIDs(array($this->id));
|
|
|
|
}
|
|
|
|
$project = $project->executeOne();
|
2014-03-26 22:40:47 +01:00
|
|
|
if (!$project) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
2014-06-13 23:09:21 +02:00
|
|
|
|
2014-03-26 22:40:47 +01:00
|
|
|
$this->setProject($project);
|
|
|
|
|
2014-06-25 21:30:20 +02:00
|
|
|
$column_query = id(new PhabricatorProjectColumnQuery())
|
2014-03-26 22:40:47 +01:00
|
|
|
->setViewer($viewer)
|
2014-06-25 21:30:20 +02:00
|
|
|
->withProjectPHIDs(array($project->getPHID()));
|
|
|
|
|
|
|
|
if (!$show_hidden) {
|
|
|
|
$column_query->withStatuses(
|
|
|
|
array(PhabricatorProjectColumn::STATUS_ACTIVE));
|
|
|
|
}
|
2014-03-26 22:40:47 +01:00
|
|
|
|
2014-06-25 21:30:20 +02:00
|
|
|
$columns = $column_query->execute();
|
2014-03-26 22:40:47 +01:00
|
|
|
$columns = mpull($columns, null, 'getSequence');
|
|
|
|
|
|
|
|
// If there's no default column, create one now.
|
|
|
|
if (empty($columns[0])) {
|
|
|
|
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
|
|
|
|
$column = PhabricatorProjectColumn::initializeNewColumn($viewer)
|
|
|
|
->setSequence(0)
|
|
|
|
->setProjectPHID($project->getPHID())
|
|
|
|
->save();
|
|
|
|
$column->attachProject($project);
|
|
|
|
$columns[0] = $column;
|
|
|
|
unset($unguarded);
|
|
|
|
}
|
|
|
|
|
|
|
|
ksort($columns);
|
|
|
|
|
2014-05-20 20:42:05 +02:00
|
|
|
$board_uri = $this->getApplicationURI('board/'.$project->getID().'/');
|
|
|
|
|
|
|
|
$engine = id(new ManiphestTaskSearchEngine())
|
2014-03-26 22:40:47 +01:00
|
|
|
->setViewer($viewer)
|
2014-05-20 20:42:05 +02:00
|
|
|
->setBaseURI($board_uri)
|
|
|
|
->setIsBoardView(true);
|
|
|
|
|
|
|
|
if ($request->isFormPost()) {
|
|
|
|
$saved = $engine->buildSavedQueryFromRequest($request);
|
|
|
|
$engine->saveQuery($saved);
|
|
|
|
return id(new AphrontRedirectResponse())->setURI(
|
|
|
|
$engine->getQueryResultsPageURI($saved->getQueryKey()));
|
|
|
|
}
|
|
|
|
|
|
|
|
$query_key = $this->queryKey;
|
|
|
|
if (!$query_key) {
|
|
|
|
$query_key = 'open';
|
|
|
|
}
|
|
|
|
|
|
|
|
$custom_query = null;
|
|
|
|
if ($engine->isBuiltinQuery($query_key)) {
|
|
|
|
$saved = $engine->buildSavedQueryFromBuiltin($query_key);
|
|
|
|
} else {
|
|
|
|
$saved = id(new PhabricatorSavedQueryQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withQueryKeys(array($query_key))
|
|
|
|
->executeOne();
|
|
|
|
|
|
|
|
if (!$saved) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
$custom_query = $saved;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->filter) {
|
|
|
|
$filter_form = id(new AphrontFormView())
|
|
|
|
->setUser($viewer);
|
|
|
|
$engine->buildSearchForm($filter_form, $saved);
|
|
|
|
|
|
|
|
return $this->newDialog()
|
|
|
|
->setWidth(AphrontDialogView::WIDTH_FULL)
|
|
|
|
->setTitle(pht('Advanced Filter'))
|
|
|
|
->appendChild($filter_form->buildLayoutView())
|
|
|
|
->setSubmitURI($board_uri)
|
|
|
|
->addSubmitButton(pht('Apply Filter'))
|
|
|
|
->addCancelButton($board_uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
$task_query = $engine->buildQueryFromSavedQuery($saved);
|
|
|
|
|
|
|
|
$tasks = $task_query
|
|
|
|
->addWithAllProjects(array($project->getPHID()))
|
2014-03-26 22:40:47 +01:00
|
|
|
->setOrderBy(ManiphestTaskQuery::ORDER_PRIORITY)
|
2014-05-20 20:42:05 +02:00
|
|
|
->setViewer($viewer)
|
2014-03-26 22:40:47 +01:00
|
|
|
->execute();
|
2014-05-20 20:42:05 +02:00
|
|
|
|
2014-03-26 22:40:47 +01:00
|
|
|
$tasks = mpull($tasks, null, 'getPHID');
|
|
|
|
$task_phids = array_keys($tasks);
|
|
|
|
|
|
|
|
if ($task_phids) {
|
|
|
|
$edge_type = PhabricatorEdgeConfig::TYPE_OBJECT_HAS_COLUMN;
|
|
|
|
$edge_query = id(new PhabricatorEdgeQuery())
|
|
|
|
->withSourcePHIDs($task_phids)
|
|
|
|
->withEdgeTypes(array($edge_type))
|
|
|
|
->withDestinationPHIDs(mpull($columns, 'getPHID'));
|
|
|
|
$edge_query->execute();
|
|
|
|
}
|
|
|
|
|
|
|
|
$task_map = array();
|
|
|
|
$default_phid = $columns[0]->getPHID();
|
|
|
|
foreach ($tasks as $task) {
|
|
|
|
$task_phid = $task->getPHID();
|
|
|
|
$column_phids = $edge_query->getDestinationPHIDs(array($task_phid));
|
|
|
|
|
|
|
|
$column_phid = head($column_phids);
|
|
|
|
$column_phid = nonempty($column_phid, $default_phid);
|
|
|
|
|
|
|
|
$task_map[$column_phid][] = $task_phid;
|
|
|
|
}
|
|
|
|
|
|
|
|
$task_can_edit_map = id(new PhabricatorPolicyFilter())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->requireCapabilities(array(PhabricatorPolicyCapability::CAN_EDIT))
|
|
|
|
->apply($tasks);
|
|
|
|
|
|
|
|
$board_id = celerity_generate_unique_node_id();
|
|
|
|
|
|
|
|
$board = id(new PHUIWorkboardView())
|
|
|
|
->setUser($viewer)
|
|
|
|
->setID($board_id);
|
|
|
|
|
|
|
|
$this->initBehavior(
|
|
|
|
'project-boards',
|
|
|
|
array(
|
|
|
|
'boardID' => $board_id,
|
|
|
|
'projectPHID' => $project->getPHID(),
|
|
|
|
'moveURI' => $this->getApplicationURI('move/'.$project->getID().'/'),
|
|
|
|
'createURI' => '/maniphest/task/create/',
|
|
|
|
));
|
|
|
|
|
|
|
|
$this->handles = ManiphestTaskListView::loadTaskHandles($viewer, $tasks);
|
|
|
|
|
|
|
|
foreach ($columns as $column) {
|
|
|
|
$panel = id(new PHUIWorkpanelView())
|
|
|
|
->setHeader($column->getDisplayName())
|
|
|
|
->setHeaderColor($column->getHeaderColor());
|
2014-06-25 21:30:20 +02:00
|
|
|
|
2014-06-25 21:30:43 +02:00
|
|
|
$panel->setEditURI($board_uri.'column/'.$column->getID().'/');
|
2014-06-25 21:30:20 +02:00
|
|
|
|
2014-03-26 22:40:47 +01:00
|
|
|
$panel->setHeaderAction(id(new PHUIIconView())
|
2014-05-21 19:18:43 +02:00
|
|
|
->setIconFont('fa-plus')
|
2014-03-26 22:40:47 +01:00
|
|
|
->setHref('/maniphest/task/create/')
|
|
|
|
->addSigil('column-add-task')
|
|
|
|
->setMetadata(
|
|
|
|
array('columnPHID' => $column->getPHID())));
|
|
|
|
|
|
|
|
$cards = id(new PHUIObjectItemListView())
|
|
|
|
->setUser($viewer)
|
|
|
|
->setFlush(true)
|
|
|
|
->setAllowEmptyList(true)
|
|
|
|
->addSigil('project-column')
|
|
|
|
->setMetadata(
|
|
|
|
array(
|
|
|
|
'columnPHID' => $column->getPHID(),
|
|
|
|
));
|
2014-06-25 21:30:20 +02:00
|
|
|
|
2014-03-26 22:40:47 +01:00
|
|
|
$task_phids = idx($task_map, $column->getPHID(), array());
|
|
|
|
foreach (array_select_keys($tasks, $task_phids) as $task) {
|
|
|
|
$owner = null;
|
|
|
|
if ($task->getOwnerPHID()) {
|
|
|
|
$owner = $this->handles[$task->getOwnerPHID()];
|
|
|
|
}
|
|
|
|
$can_edit = idx($task_can_edit_map, $task->getPHID(), false);
|
|
|
|
$cards->addItem(id(new ProjectBoardTaskCard())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->setTask($task)
|
|
|
|
->setOwner($owner)
|
|
|
|
->setCanEdit($can_edit)
|
|
|
|
->getItem());
|
|
|
|
}
|
|
|
|
$panel->setCards($cards);
|
|
|
|
|
|
|
|
if (!$task_phids) {
|
|
|
|
$cards->addClass('project-column-empty');
|
|
|
|
}
|
|
|
|
|
|
|
|
$board->addPanel($panel);
|
|
|
|
}
|
|
|
|
|
|
|
|
$can_edit = PhabricatorPolicyFilter::hasCapability(
|
|
|
|
$viewer,
|
|
|
|
$project,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT);
|
|
|
|
|
2014-05-08 23:21:32 +02:00
|
|
|
$add_icon = id(new PHUIIconView())
|
|
|
|
->setIconFont('fa-plus bluegrey');
|
|
|
|
|
|
|
|
$add_button = id(new PHUIButtonView())
|
|
|
|
->setText(pht('Add Column'))
|
|
|
|
->setIcon($add_icon)
|
|
|
|
->setTag('a')
|
|
|
|
->setHref($this->getApplicationURI('board/'.$this->id.'/edit/'))
|
|
|
|
->setDisabled(!$can_edit)
|
|
|
|
->setWorkflow(!$can_edit);
|
|
|
|
|
2014-05-20 20:42:05 +02:00
|
|
|
Javelin::initBehavior(
|
|
|
|
'boards-filter',
|
|
|
|
array(
|
|
|
|
));
|
|
|
|
|
|
|
|
$filter_icon = id(new PHUIIconView())
|
|
|
|
->setIconFont('fa-search-plus bluegrey');
|
|
|
|
|
|
|
|
$named = array(
|
|
|
|
'open' => pht('Open Tasks'),
|
|
|
|
'all' => pht('All Tasks'),
|
|
|
|
);
|
|
|
|
|
|
|
|
if ($viewer->isLoggedIn()) {
|
|
|
|
$named['assigned'] = pht('Assigned to Me');
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($custom_query) {
|
|
|
|
$named[$custom_query->getQueryKey()] = pht('Custom Filter');
|
|
|
|
}
|
|
|
|
|
|
|
|
$items = array();
|
|
|
|
foreach ($named as $key => $name) {
|
|
|
|
$is_selected = ($key == $query_key);
|
|
|
|
if ($is_selected) {
|
|
|
|
$active_filter = $name;
|
|
|
|
}
|
|
|
|
|
|
|
|
$is_custom = false;
|
|
|
|
if ($custom_query) {
|
|
|
|
$is_custom = ($key == $custom_query->getQueryKey());
|
|
|
|
}
|
|
|
|
|
|
|
|
$item = id(new PhabricatorActionView())
|
|
|
|
->setIcon('fa-search')
|
|
|
|
->setSelected($is_selected)
|
|
|
|
->setName($name);
|
|
|
|
|
|
|
|
if ($is_custom) {
|
|
|
|
$item->setHref(
|
|
|
|
$this->getApplicationURI(
|
|
|
|
'board/'.$this->id.'/filter/query/'.$key.'/'));
|
|
|
|
$item->setWorkflow(true);
|
|
|
|
} else {
|
|
|
|
$item->setHref($engine->getQueryResultsPageURI($key));
|
|
|
|
}
|
|
|
|
|
|
|
|
$items[] = $item;
|
|
|
|
}
|
|
|
|
|
|
|
|
$items[] = id(new PhabricatorActionView())
|
|
|
|
->setIcon('fa-cog')
|
|
|
|
->setHref($this->getApplicationURI('board/'.$this->id.'/filter/'))
|
|
|
|
->setWorkflow(true)
|
|
|
|
->setName(pht('Advanced Filter...'));
|
|
|
|
|
|
|
|
$filter_menu = id(new PhabricatorActionListView())
|
|
|
|
->setUser($viewer);
|
|
|
|
foreach ($items as $item) {
|
|
|
|
$filter_menu->addAction($item);
|
|
|
|
}
|
|
|
|
|
|
|
|
$filter_button = id(new PHUIButtonView())
|
|
|
|
->setText(pht('Filter: %s', $active_filter))
|
|
|
|
->setIcon($filter_icon)
|
|
|
|
->setTag('a')
|
|
|
|
->setHref('#')
|
|
|
|
->addSigil('boards-filter-menu')
|
|
|
|
->setMetadata(
|
|
|
|
array(
|
|
|
|
'items' => hsprintf('%s', $filter_menu),
|
|
|
|
));
|
|
|
|
|
2014-05-08 23:21:32 +02:00
|
|
|
$header_link = phutil_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => $this->getApplicationURI('view/'.$project->getID().'/')
|
|
|
|
),
|
|
|
|
$project->getName());
|
2014-03-26 22:40:47 +01:00
|
|
|
|
2014-06-25 21:30:20 +02:00
|
|
|
if ($show_hidden) {
|
|
|
|
$hidden_uri = $request->getRequestURI()
|
|
|
|
->setQueryParam('hidden', null);
|
|
|
|
$hidden_icon = id(new PHUIIconView())
|
|
|
|
->setIconFont('fa-eye-slash bluegrey');
|
|
|
|
$hidden_text = pht('Hide Hidden Columns');
|
|
|
|
} else {
|
|
|
|
$hidden_uri = $request->getRequestURI()
|
|
|
|
->setQueryParam('hidden', 'true');
|
|
|
|
$hidden_icon = id(new PHUIIconView())
|
|
|
|
->setIconFont('fa-eye bluegrey');
|
|
|
|
$hidden_text = pht('Show Hidden Columns');
|
|
|
|
}
|
|
|
|
|
|
|
|
$hidden_button = id(new PHUIButtonView())
|
|
|
|
->setText($hidden_text)
|
|
|
|
->setIcon($hidden_icon)
|
|
|
|
->setTag('a')
|
|
|
|
->setHref($hidden_uri);
|
|
|
|
|
2014-03-26 22:40:47 +01:00
|
|
|
$header = id(new PHUIHeaderView())
|
2014-05-08 23:21:32 +02:00
|
|
|
->setHeader($header_link)
|
2014-03-26 22:40:47 +01:00
|
|
|
->setUser($viewer)
|
2014-05-08 23:21:32 +02:00
|
|
|
->setNoBackground(true)
|
2014-03-26 22:40:47 +01:00
|
|
|
->setImage($project->getProfileImageURI())
|
2014-05-08 23:21:32 +02:00
|
|
|
->setImageURL($this->getApplicationURI('view/'.$project->getID().'/'))
|
2014-06-25 21:30:20 +02:00
|
|
|
->addActionLink($hidden_button)
|
2014-05-20 20:42:05 +02:00
|
|
|
->addActionLink($filter_button)
|
2014-05-08 23:21:32 +02:00
|
|
|
->addActionLink($add_button)
|
2014-03-26 22:40:47 +01:00
|
|
|
->setPolicyObject($project);
|
|
|
|
|
|
|
|
$board_box = id(new PHUIBoxView())
|
|
|
|
->appendChild($board)
|
2014-05-08 23:21:32 +02:00
|
|
|
->addClass('project-board-wrapper');
|
2014-03-26 22:40:47 +01:00
|
|
|
|
|
|
|
return $this->buildApplicationPage(
|
|
|
|
array(
|
2014-05-08 23:21:32 +02:00
|
|
|
$header,
|
2014-03-26 22:40:47 +01:00
|
|
|
$board_box,
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'title' => pht('%s Board', $project->getName()),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|