public function processRequest() { $this->requireApplicationCapability(ManiphestBulkEditCapability::CAPABILITY); $request = $this->getRequest(); $user = $request->getUser(); $task_ids = $request->getArr('batch'); $tasks = id(new ManiphestTaskQuery())->setViewer($user)->withIDs($task_ids)->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->execute(); $actions = $request->getStr('actions'); if ($actions) { $actions = json_decode($actions, true); } if ($request->isFormPost() && is_array($actions)) { foreach ($tasks as $task) { $field_list = PhabricatorCustomField::getObjectFields($task, PhabricatorCustomField::ROLE_EDIT); $field_list->readFieldsFromStorage($task); $xactions = $this->buildTransactions($actions, $task); if ($xactions) { // TODO: Set content source to "batch edit". $editor = id(new ManiphestTransactionEditor())->setActor($user)->setContentSourceFromRequest($request)->setContinueOnNoEffect(true)->setContinueOnMissingFields(true)->applyTransactions($task, $xactions); } } $task_ids = implode(',', mpull($tasks, 'getID')); return id(new AphrontRedirectResponse())->setURI('/maniphest/?ids=' . $task_ids); } $handles = ManiphestTaskListView::loadTaskHandles($user, $tasks); $list = new ManiphestTaskListView(); $list->setTasks($tasks); $list->setUser($user); $list->setHandles($handles); $template = new AphrontTokenizerTemplateView(); $template = $template->render(); $projects_source = new PhabricatorProjectDatasource(); $mailable_source = new PhabricatorMetaMTAMailableDatasource(); $owner_source = new PhabricatorTypeaheadOwnerDatasource(); require_celerity_resource('maniphest-batch-editor'); Javelin::initBehavior('maniphest-batch-editor', array('root' => 'maniphest-batch-edit-form', 'tokenizerTemplate' => $template, 'sources' => array('project' => array('src' => $projects_source->getDatasourceURI(), 'placeholder' => $projects_source->getPlaceholderText()), 'owner' => array('src' => $owner_source->getDatasourceURI(), 'placeholder' => $owner_source->getPlaceholderText(), 'limit' => 1), 'cc' => array('src' => $mailable_source->getDatasourceURI(), 'placeholder' => $mailable_source->getPlaceholderText())), 'input' => 'batch-form-actions', 'priorityMap' => ManiphestTaskPriority::getTaskPriorityMap(), 'statusMap' => ManiphestTaskStatus::getTaskStatusMap())); $form = new AphrontFormView(); $form->setUser($user); $form->setID('maniphest-batch-edit-form'); foreach ($tasks as $task) { $form->appendChild(phutil_tag('input', array('type' => 'hidden', 'name' => 'batch[]', 'value' => $task->getID()))); } $form->appendChild(phutil_tag('input', array('type' => 'hidden', 'name' => 'actions', 'id' => 'batch-form-actions'))); $form->appendChild(phutil_tag('p', array(), pht('These tasks will be edited:'))); $form->appendChild($list); $form->appendChild(id(new AphrontFormInsetView())->setTitle('Actions')->setRightButton(javelin_tag('a', array('href' => '#', 'class' => 'button green', 'sigil' => 'add-action', 'mustcapture' => true), pht('Add Another Action')))->setContent(javelin_tag('table', array('sigil' => 'maniphest-batch-actions', 'class' => 'maniphest-batch-actions-table'), '')))->appendChild(id(new AphrontFormSubmitControl())->setValue(pht('Update Tasks'))->addCancelButton('/maniphest/')); $title = pht('Batch Editor'); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb($title); $form_box = id(new PHUIObjectBoxView())->setHeaderText(pht('Batch Edit Tasks'))->setForm($form); return $this->buildApplicationPage(array($crumbs, $form_box), array('title' => $title, 'device' => false)); }
public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $task_ids = $request->getArr('batch'); $tasks = id(new ManiphestTask())->loadAllWhere('id IN (%Ld)', $task_ids); $actions = $request->getStr('actions'); if ($actions) { $actions = json_decode($actions, true); } if ($request->isFormPost() && is_array($actions)) { foreach ($tasks as $task) { $xactions = $this->buildTransactions($actions, $task); if ($xactions) { $editor = new ManiphestTransactionEditor(); $editor->applyTransactions($task, $xactions); } } $task_ids = implode(',', mpull($tasks, 'getID')); return id(new AphrontRedirectResponse())->setURI('/maniphest/view/custom/?s=oc&tasks=' . $task_ids); } $panel = new AphrontPanelView(); $panel->setHeader('Maniphest Batch Editor'); $handle_phids = mpull($tasks, 'getOwnerPHID'); $handles = id(new PhabricatorObjectHandleData($handle_phids))->loadHandles(); $list = new ManiphestTaskListView(); $list->setTasks($tasks); $list->setUser($user); $list->setHandles($handles); $template = new AphrontTokenizerTemplateView(); $template = $template->render(); require_celerity_resource('maniphest-batch-editor'); Javelin::initBehavior('maniphest-batch-editor', array('root' => 'maniphest-batch-edit-form', 'tokenizerTemplate' => $template, 'sources' => array('project' => array('src' => '/typeahead/common/projects/', 'placeholder' => 'Type a project name...'), 'owner' => array('src' => '/typeahead/common/searchowner/', 'placeholder' => 'Type a user name...', 'limit' => 1)), 'input' => 'batch-form-actions', 'priorityMap' => ManiphestTaskPriority::getTaskPriorityMap(), 'statusMap' => ManiphestTaskStatus::getTaskStatusMap())); $form = new AphrontFormView(); $form->setUser($user); $form->setID('maniphest-batch-edit-form'); foreach ($tasks as $task) { $form->appendChild(phutil_render_tag('input', array('type' => 'hidden', 'name' => 'batch[]', 'value' => $task->getID()), null)); } $form->appendChild(phutil_render_tag('input', array('type' => 'hidden', 'name' => 'actions', 'id' => 'batch-form-actions'), null)); $form->appendChild('<p>These tasks will be edited:</p>'); $form->appendChild($list); $form->appendChild(id(new AphrontFormInsetView())->setTitle('Actions')->setRightButton(javelin_render_tag('a', array('href' => '#', 'class' => 'button green', 'sigil' => 'add-action', 'mustcapture' => true), 'Add Another Action'))->setContent(javelin_render_tag('table', array('sigil' => 'maniphest-batch-actions', 'class' => 'maniphest-batch-actions-table'), '')))->appendChild(id(new AphrontFormSubmitControl())->setValue('Update Tasks')->addCancelButton('/maniphest/', 'Done')); $panel->appendChild($form); return $this->buildStandardPageResponse($panel, array('title' => 'Batch Editor')); }
public function render() { $viewer = $this->getUser(); $tasks = $this->tasks; $query = $this->savedQuery; // If we didn't match anything, just pick up the default empty state. if (!$tasks) { return id(new PHUIObjectItemListView())->setUser($viewer)->setNoDataString(pht('No tasks found.')); } $group_parameter = nonempty($query->getParameter('group'), 'priority'); $order_parameter = nonempty($query->getParameter('order'), 'priority'); $handles = ManiphestTaskListView::loadTaskHandles($viewer, $tasks); $groups = $this->groupTasks($tasks, $group_parameter, $handles); $can_edit_priority = $this->canEditPriority; $can_drag = $order_parameter == 'priority' && $can_edit_priority && ($group_parameter == 'none' || $group_parameter == 'priority'); if (!$viewer->isLoggedIn()) { // TODO: (T7131) Eventually, we conceivably need to make each task // draggable individually, since the user may be able to edit some but // not others. $can_drag = false; } $result = array(); $lists = array(); foreach ($groups as $group => $list) { $task_list = new ManiphestTaskListView(); $task_list->setShowBatchControls($this->showBatchControls); if ($can_drag) { $task_list->setShowSubpriorityControls(true); } $task_list->setUser($viewer); $task_list->setTasks($list); $task_list->setHandles($handles); $header = id(new PHUIHeaderView())->addSigil('task-group')->setMetadata(array('priority' => head($list)->getPriority()))->setHeader(pht('%s (%s)', $group, phutil_count($list))); $lists[] = id(new PHUIObjectBoxView())->setHeader($header)->setObjectList($task_list); } if ($can_drag) { Javelin::initBehavior('maniphest-subpriority-editor', array('uri' => '/maniphest/subpriority/')); } return array($lists, $this->showBatchControls ? $this->renderBatchEditor($query) : null); }
public function processRequest() { $request = $this->getRequest(); $viewer = $request->getUser(); $show_hidden = $request->getBool('hidden'); $this->showHidden = $show_hidden; $project = id(new PhabricatorProjectQuery())->setViewer($viewer)->needImages(true); if ($this->slug) { $project->withSlugs(array($this->slug)); } else { $project->withIDs(array($this->id)); } $project = $project->executeOne(); if (!$project) { return new Aphront404Response(); } $this->setProject($project); $this->id = $project->getID(); $sort_key = $request->getStr('order'); switch ($sort_key) { case PhabricatorProjectColumn::ORDER_NATURAL: case PhabricatorProjectColumn::ORDER_PRIORITY: break; default: $sort_key = PhabricatorProjectColumn::DEFAULT_ORDER; break; } $this->sortKey = $sort_key; $column_query = id(new PhabricatorProjectColumnQuery())->setViewer($viewer)->withProjectPHIDs(array($project->getPHID())); if (!$show_hidden) { $column_query->withStatuses(array(PhabricatorProjectColumn::STATUS_ACTIVE)); } $columns = $column_query->execute(); $columns = mpull($columns, null, 'getSequence'); if (empty($columns[0])) { switch ($request->getStr('initialize-type')) { case 'backlog-only': $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); $column = PhabricatorProjectColumn::initializeNewColumn($viewer)->setSequence(0)->setProperty('isDefault', true)->setProjectPHID($project->getPHID())->save(); $column->attachProject($project); $columns[0] = $column; unset($unguarded); break; case 'import': return id(new AphrontRedirectResponse())->setURI($this->getApplicationURI('board/' . $project->getID() . '/import/')); break; default: return $this->initializeWorkboardDialog($project); break; } } ksort($columns); $board_uri = $this->getApplicationURI('board/' . $project->getID() . '/'); $engine = id(new ManiphestTaskSearchEngine())->setViewer($viewer)->setBaseURI($board_uri)->setIsBoardView(true); if ($request->isFormPost()) { $saved = $engine->buildSavedQueryFromRequest($request); $engine->saveQuery($saved); return id(new AphrontRedirectResponse())->setURI($this->getURIWithState($engine->getQueryResultsPageURI($saved->getQueryKey()))); } $query_key = $this->queryKey; if (!$query_key) { $query_key = 'open'; } $this->queryKey = $query_key; $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()))->setOrderBy(ManiphestTaskQuery::ORDER_PRIORITY)->setViewer($viewer)->execute(); $tasks = mpull($tasks, null, 'getPHID'); if ($tasks) { $positions = id(new PhabricatorProjectColumnPositionQuery())->setViewer($viewer)->withObjectPHIDs(mpull($tasks, 'getPHID'))->withColumns($columns)->execute(); $positions = mpull($positions, null, 'getObjectPHID'); } else { $positions = array(); } $task_map = array(); foreach ($tasks as $task) { $task_phid = $task->getPHID(); if (empty($positions[$task_phid])) { // This shouldn't normally be possible because we create positions on // demand, but we might have raced as an object was removed from the // board. Just drop the task if we don't have a position for it. continue; } $position = $positions[$task_phid]; $task_map[$position->getColumnPHID()][] = $task_phid; } // If we're showing the board in "natural" order, sort columns by their // column positions. if ($this->sortKey == PhabricatorProjectColumn::ORDER_NATURAL) { foreach ($task_map as $column_phid => $task_phids) { $order = array(); foreach ($task_phids as $task_phid) { if (isset($positions[$task_phid])) { $order[$task_phid] = $positions[$task_phid]->getOrderingKey(); } else { $order[$task_phid] = 0; } } asort($order); $task_map[$column_phid] = array_keys($order); } } $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/', 'order' => $this->sortKey)); $this->handles = ManiphestTaskListView::loadTaskHandles($viewer, $tasks); foreach ($columns as $column) { $task_phids = idx($task_map, $column->getPHID(), array()); $column_tasks = array_select_keys($tasks, $task_phids); $panel = id(new PHUIWorkpanelView())->setHeader($column->getDisplayName())->addSigil('workpanel'); $header_icon = $column->getHeaderIcon(); if ($header_icon) { $panel->setHeaderIcon($header_icon); } if ($column->isHidden()) { $panel->addClass('project-panel-hidden'); } $column_menu = $this->buildColumnMenu($project, $column); $panel->addHeaderAction($column_menu); $tag_id = celerity_generate_unique_node_id(); $tag_content_id = celerity_generate_unique_node_id(); $count_tag = id(new PHUITagView())->setType(PHUITagView::TYPE_SHADE)->setShade(PHUITagView::COLOR_BLUE)->setID($tag_id)->setName(phutil_tag('span', array('id' => $tag_content_id), '-'))->setStyle('display: none'); $panel->setHeaderTag($count_tag); $cards = id(new PHUIObjectItemListView())->setUser($viewer)->setFlush(true)->setAllowEmptyList(true)->addSigil('project-column')->setMetadata(array('columnPHID' => $column->getPHID(), 'countTagID' => $tag_id, 'countTagContentID' => $tag_content_id, 'pointLimit' => $column->getPointLimit())); foreach ($column_tasks 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); $board->addPanel($panel); } Javelin::initBehavior('boards-dropdown', array()); $sort_menu = $this->buildSortMenu($viewer, $sort_key); $filter_menu = $this->buildFilterMenu($viewer, $custom_query, $engine, $query_key); $manage_menu = $this->buildManageMenu($project, $show_hidden); $header_link = phutil_tag('a', array('href' => $this->getApplicationURI('view/' . $project->getID() . '/')), $project->getName()); $header = id(new PHUIHeaderView())->setHeader($header_link)->setUser($viewer)->setNoBackground(true)->setImage($project->getProfileImageURI())->setImageURL($this->getApplicationURI('view/' . $project->getID() . '/'))->addActionLink($sort_menu)->addActionLink($filter_menu)->addActionLink($manage_menu)->setPolicyObject($project); $board_box = id(new PHUIBoxView())->appendChild($board)->addClass('project-board-wrapper'); return $this->buildApplicationPage(array($header, $board_box), array('title' => pht('%s Board', $project->getName()), 'showFooter' => false)); }
public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); if ($request->isFormPost()) { // Redirect to GET so URIs can be copy/pasted. $user_phids = $request->getArr('set_users'); $proj_phids = $request->getArr('set_projects'); $task_ids = $request->getStr('set_tasks'); $user_phids = implode(',', $user_phids); $proj_phids = implode(',', $proj_phids); $user_phids = nonempty($user_phids, null); $proj_phids = nonempty($proj_phids, null); $task_ids = nonempty($task_ids, null); $uri = $request->getRequestURI()->alter('users', $user_phids)->alter('projects', $proj_phids)->alter('tasks', $task_ids); return id(new AphrontRedirectResponse())->setURI($uri); } $nav = new AphrontSideNavFilterView(); $nav->setBaseURI(new PhutilURI('/maniphest/view/')); $nav->addLabel('User Tasks'); $nav->addFilter('action', 'Assigned'); $nav->addFilter('created', 'Created'); $nav->addFilter('subscribed', 'Subscribed'); $nav->addFilter('triage', 'Need Triage'); $nav->addSpacer(); $nav->addLabel('All Tasks'); $nav->addFilter('alltriage', 'Need Triage'); $nav->addFilter('all', 'All Tasks'); $nav->addSpacer(); $nav->addFilter('custom', 'Custom'); $this->view = $nav->selectFilter($this->view, 'action'); $has_filter = array('action' => true, 'created' => true, 'subscribed' => true, 'triage' => true); list($status_map, $status_links) = $this->renderStatusLinks(); list($grouping, $group_links) = $this->renderGroupLinks(); list($order, $order_links) = $this->renderOrderLinks(); $user_phids = $request->getStr('users'); if (strlen($user_phids)) { $user_phids = explode(',', $user_phids); } else { $user_phids = array($user->getPHID()); } $project_phids = $request->getStr('projects'); if (strlen($project_phids)) { $project_phids = explode(',', $project_phids); } else { $project_phids = array(); } $task_ids = $request->getStrList('tasks'); $page = $request->getInt('page'); $page_size = self::DEFAULT_PAGE_SIZE; list($tasks, $handles, $total_count) = $this->loadTasks($user_phids, $project_phids, $task_ids, array('status' => $status_map, 'group' => $grouping, 'order' => $order, 'offset' => $page, 'limit' => $page_size)); $form = id(new AphrontFormView())->setUser($user)->setAction($request->getRequestURI()); if (isset($has_filter[$this->view])) { $tokens = array(); foreach ($user_phids as $phid) { $tokens[$phid] = $handles[$phid]->getFullName(); } $form->appendChild(id(new AphrontFormTokenizerControl())->setDatasource('/typeahead/common/searchowner/')->setName('set_users')->setLabel('Users')->setValue($tokens)); } if ($this->view == 'custom') { $form->appendChild(id(new AphrontFormTextControl())->setName('set_tasks')->setLabel('Task IDs')->setValue(join(',', $task_ids))); } $tokens = array(); foreach ($project_phids as $phid) { $tokens[$phid] = $handles[$phid]->getFullName(); } $form->appendChild(id(new AphrontFormTokenizerControl())->setDatasource('/typeahead/common/projects/')->setName('set_projects')->setLabel('Projects')->setValue($tokens)); $form->appendChild(id(new AphrontFormToggleButtonsControl())->setLabel('Status')->setValue($status_links))->appendChild(id(new AphrontFormToggleButtonsControl())->setLabel('Group')->setValue($group_links))->appendChild(id(new AphrontFormToggleButtonsControl())->setLabel('Order')->setValue($order_links)); $form->appendChild(id(new AphrontFormSubmitControl())->setValue('Filter Tasks')); $create_uri = new PhutilURI('/maniphest/task/create/'); if ($project_phids) { // If we have project filters selected, use them as defaults for task // creation. $create_uri->setQueryParam('projects', implode(';', $project_phids)); } $filter = new AphrontListFilterView(); $filter->addButton(phutil_render_tag('a', array('href' => (string) $create_uri, 'class' => 'green button'), 'Create New Task')); $filter->appendChild($form); $nav->appendChild($filter); $have_tasks = false; foreach ($tasks as $group => $list) { if (count($list)) { $have_tasks = true; break; } } require_celerity_resource('maniphest-task-summary-css'); if (!$have_tasks) { $nav->appendChild('<h1 class="maniphest-task-group-header">' . 'No matching tasks.' . '</h1>'); } else { $pager = new AphrontPagerView(); $pager->setURI($request->getRequestURI(), 'page'); $pager->setPageSize($page_size); $pager->setOffset($page); $pager->setCount($total_count); $cur = $pager->getOffset() + 1; $max = min($pager->getOffset() + $page_size, $total_count); $tot = $total_count; $cur = number_format($cur); $max = number_format($max); $tot = number_format($tot); $nav->appendChild('<div class="maniphest-total-result-count">' . "Displaying tasks {$cur} - {$max} of {$tot}." . '</div>'); foreach ($tasks as $group => $list) { $task_list = new ManiphestTaskListView(); $task_list->setUser($user); $task_list->setTasks($list); $task_list->setHandles($handles); $count = number_format(count($list)); $nav->appendChild('<h1 class="maniphest-task-group-header">' . phutil_escape_html($group) . ' (' . $count . ')' . '</h1>'); $nav->appendChild($task_list); } $nav->appendChild($pager); } return $this->buildStandardPageResponse($nav, array('title' => 'Task List')); }
public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); if ($request->isFormPost()) { // Redirect to GET so URIs can be copy/pasted. $task_ids = $request->getStr('set_tasks'); $task_ids = nonempty($task_ids, null); $search_text = $request->getStr('set_search'); $search_text = nonempty($search_text, null); $min_priority = $request->getInt('set_lpriority'); $min_priority = nonempty($min_priority, null); $max_priority = $request->getInt('set_hpriority'); $max_priority = nonempty($max_priority, null); $uri = $request->getRequestURI()->alter('users', $this->getArrToStrList('set_users'))->alter('projects', $this->getArrToStrList('set_projects'))->alter('xprojects', $this->getArrToStrList('set_xprojects'))->alter('owners', $this->getArrToStrList('set_owners'))->alter('authors', $this->getArrToStrList('set_authors'))->alter('lpriority', $min_priority)->alter('hpriority', $max_priority)->alter('tasks', $task_ids)->alter('search', $search_text); return id(new AphrontRedirectResponse())->setURI($uri); } $nav = $this->buildBaseSideNav(); $has_filter = array('action' => true, 'created' => true, 'subscribed' => true, 'triage' => true, 'projecttriage' => true, 'projectall' => true); $query = null; $key = $request->getStr('key'); if (!$key && !$this->view) { if ($this->getDefaultQuery()) { $key = $this->getDefaultQuery()->getQueryKey(); } } if ($key) { $query = id(new PhabricatorSearchQuery())->loadOneWhere('queryKey = %s', $key); } // If the user is running a saved query, load query parameters from that // query. Otherwise, build a new query object from the HTTP request. if ($query) { $nav->selectFilter('Q:' . $query->getQueryKey(), 'custom'); $this->view = 'custom'; } else { $this->view = $nav->selectFilter($this->view, 'action'); $query = $this->buildQueryFromRequest(); } // Execute the query. list($tasks, $handles, $total_count) = self::loadTasks($query); // Extract information we need to render the filters from the query. $search_text = $query->getParameter('fullTextSearch'); $user_phids = $query->getParameter('userPHIDs', array()); $task_ids = $query->getParameter('taskIDs', array()); $owner_phids = $query->getParameter('ownerPHIDs', array()); $author_phids = $query->getParameter('authorPHIDs', array()); $project_phids = $query->getParameter('projectPHIDs', array()); $exclude_project_phids = $query->getParameter('excludeProjectPHIDs', array()); $low_priority = $query->getParameter('lowPriority'); $high_priority = $query->getParameter('highPriority'); $page_size = $query->getParameter('limit'); $page = $query->getParameter('offset'); $q_status = $query->getParameter('status'); $q_group = $query->getParameter('group'); $q_order = $query->getParameter('order'); $form = id(new AphrontFormView())->setUser($user)->setAction($request->getRequestURI()->alter('key', null)->alter($this->getStatusRequestKey(), $this->getStatusRequestValue($q_status))->alter($this->getOrderRequestKey(), $this->getOrderRequestValue($q_order))->alter($this->getGroupRequestKey(), $this->getGroupRequestValue($q_group))); if (isset($has_filter[$this->view])) { $tokens = array(); foreach ($user_phids as $phid) { $tokens[$phid] = $handles[$phid]->getFullName(); } $form->appendChild(id(new AphrontFormTokenizerControl())->setDatasource('/typeahead/common/searchowner/')->setName('set_users')->setLabel('Users')->setValue($tokens)); } if ($this->view == 'custom') { $form->appendChild(id(new AphrontFormTextControl())->setName('set_search')->setLabel('Search')->setValue($search_text)); $form->appendChild(id(new AphrontFormTextControl())->setName('set_tasks')->setLabel('Task IDs')->setValue(join(',', $task_ids))); $tokens = array(); foreach ($owner_phids as $phid) { $tokens[$phid] = $handles[$phid]->getFullName(); } $form->appendChild(id(new AphrontFormTokenizerControl())->setDatasource('/typeahead/common/searchowner/')->setName('set_owners')->setLabel('Owners')->setValue($tokens)); $tokens = array(); foreach ($author_phids as $phid) { $tokens[$phid] = $handles[$phid]->getFullName(); } $form->appendChild(id(new AphrontFormTokenizerControl())->setDatasource('/typeahead/common/users/')->setName('set_authors')->setLabel('Authors')->setValue($tokens)); } $tokens = array(); foreach ($project_phids as $phid) { $tokens[$phid] = $handles[$phid]->getFullName(); } if ($this->view != 'projectall' && $this->view != 'projecttriage') { $form->appendChild(id(new AphrontFormTokenizerControl())->setDatasource('/typeahead/common/searchproject/')->setName('set_projects')->setLabel('Projects')->setValue($tokens)); } if ($this->view == 'custom') { $tokens = array(); foreach ($exclude_project_phids as $phid) { $tokens[$phid] = $handles[$phid]->getFullName(); } $form->appendChild(id(new AphrontFormTokenizerControl())->setDatasource('/typeahead/common/projects/')->setName('set_xprojects')->setLabel('Exclude Projects')->setValue($tokens)); $priority = ManiphestTaskPriority::getLowestPriority(); if ($low_priority) { $priority = $low_priority; } $form->appendChild(id(new AphrontFormSelectControl())->setLabel('Min Priority')->setName('set_lpriority')->setValue($priority)->setOptions(array_reverse(ManiphestTaskPriority::getTaskPriorityMap(), true))); $priority = ManiphestTaskPriority::getHighestPriority(); if ($high_priority) { $priority = $high_priority; } $form->appendChild(id(new AphrontFormSelectControl())->setLabel('Max Priority')->setName('set_hpriority')->setValue($priority)->setOptions(ManiphestTaskPriority::getTaskPriorityMap())); } $form->appendChild($this->renderStatusControl($q_status))->appendChild($this->renderGroupControl($q_group))->appendChild($this->renderOrderControl($q_order)); $submit = id(new AphrontFormSubmitControl())->setValue('Filter Tasks'); // Only show "Save..." for novel queries which have some kind of query // parameters set. if ($this->view === 'custom' && empty($key) && $request->getRequestURI()->getQueryParams()) { $submit->addCancelButton('/maniphest/custom/edit/?key=' . $query->getQueryKey(), 'Save Custom Query...'); } $form->appendChild($submit); $create_uri = new PhutilURI('/maniphest/task/create/'); if ($project_phids) { // If we have project filters selected, use them as defaults for task // creation. $create_uri->setQueryParam('projects', implode(';', $project_phids)); } $filter = new AphrontListFilterView(); $filter->addButton(phutil_render_tag('a', array('href' => (string) $create_uri, 'class' => 'green button'), 'Create New Task')); if (empty($key)) { $filter->appendChild($form); } $nav->appendChild($filter); $have_tasks = false; foreach ($tasks as $group => $list) { if (count($list)) { $have_tasks = true; break; } } require_celerity_resource('maniphest-task-summary-css'); $list_container = new AphrontNullView(); $list_container->appendChild('<div class="maniphest-list-container">'); if (!$have_tasks) { $list_container->appendChild('<h1 class="maniphest-task-group-header">' . 'No matching tasks.' . '</h1>'); } else { $pager = new AphrontPagerView(); $pager->setURI($request->getRequestURI(), 'offset'); $pager->setPageSize($page_size); $pager->setOffset($page); $pager->setCount($total_count); $cur = $pager->getOffset() + 1; $max = min($pager->getOffset() + $page_size, $total_count); $tot = $total_count; $cur = number_format($cur); $max = number_format($max); $tot = number_format($tot); $list_container->appendChild('<div class="maniphest-total-result-count">' . "Displaying tasks {$cur} - {$max} of {$tot}." . '</div>'); $selector = new AphrontNullView(); $group = $query->getParameter('group'); $order = $query->getParameter('order'); $is_draggable = $group == 'priority' || $group == 'none' && $order == 'priority'; $lists = new AphrontNullView(); $lists->appendChild('<div class="maniphest-group-container">'); foreach ($tasks as $group => $list) { $task_list = new ManiphestTaskListView(); $task_list->setShowBatchControls(true); if ($is_draggable) { $task_list->setShowSubpriorityControls(true); } $task_list->setUser($user); $task_list->setTasks($list); $task_list->setHandles($handles); $count = number_format(count($list)); $lists->appendChild(javelin_render_tag('h1', array('class' => 'maniphest-task-group-header', 'sigil' => 'task-group', 'meta' => array('priority' => head($list)->getPriority())), phutil_escape_html($group) . ' (' . $count . ')')); $lists->appendChild($task_list); } $lists->appendChild('</div>'); $selector->appendChild($lists); $selector->appendChild($this->renderBatchEditor($query)); $form_id = celerity_generate_unique_node_id(); $selector = phabricator_render_form($user, array('method' => 'POST', 'action' => '/maniphest/batch/', 'id' => $form_id), $selector->render()); $list_container->appendChild($selector); $list_container->appendChild($pager); Javelin::initBehavior('maniphest-subpriority-editor', array('root' => $form_id, 'uri' => '/maniphest/subpriority/')); } $list_container->appendChild('</div>'); $nav->appendChild($list_container); return $this->buildStandardPageResponse($nav, array('title' => 'Task List')); }
private function buildTaskListView(array $tasks) { assert_instances_of($tasks, 'ManiphestTask'); $user = $this->getRequest()->getUser(); $phids = array_merge(array_filter(mpull($tasks, 'getOwnerPHID')), array_mergev(mpull($tasks, 'getProjectPHIDs'))); $handles = $this->loadViewerHandles($phids); $view = new ManiphestTaskListView(); $view->setTasks($tasks); $view->setUser($user); $view->setHandles($handles); return $view; }
public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $id = $request->getURIData('id'); $show_hidden = $request->getBool('hidden'); $this->showHidden = $show_hidden; $project = id(new PhabricatorProjectQuery())->setViewer($viewer)->needImages(true); $id = $request->getURIData('id'); $slug = $request->getURIData('slug'); if ($slug) { $project->withSlugs(array($slug)); } else { $project->withIDs(array($id)); } $project = $project->executeOne(); if (!$project) { return new Aphront404Response(); } $this->setProject($project); $this->id = $project->getID(); $is_sprint = $this->isSprint($project); $sort_key = $request->getStr('order'); switch ($sort_key) { case PhabricatorProjectColumn::ORDER_NATURAL: case PhabricatorProjectColumn::ORDER_PRIORITY: break; default: $sort_key = PhabricatorProjectColumn::DEFAULT_ORDER; break; } $this->sortKey = $sort_key; $column_query = id(new PhabricatorProjectColumnQuery())->setViewer($viewer)->withProjectPHIDs(array($project->getPHID())); if (!$show_hidden) { $column_query->withStatuses(array(PhabricatorProjectColumn::STATUS_ACTIVE)); } $columns = $column_query->execute(); $columns = mpull($columns, null, 'getSequence'); // TODO: Expand the checks here if we add the ability // to hide the Backlog column if (!$columns) { switch ($request->getStr('initialize-type')) { case 'backlog-only': $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); $column = PhabricatorProjectColumn::initializeNewColumn($viewer)->setSequence(0)->setProperty('isDefault', true)->setProjectPHID($project->getPHID())->save(); $column->attachProject($project); $columns[0] = $column; unset($unguarded); break; case 'import': return id(new AphrontRedirectResponse())->setURI($this->getApplicationURI('board/' . $project->getID() . '/import/')); break; default: return $this->initializeWorkboardDialog($project); break; } } ksort($columns); $board_uri = $this->getApplicationURI('board/' . $project->getID() . '/'); $engine = id(new ManiphestTaskSearchEngine())->setViewer($viewer)->setBaseURI($board_uri)->setIsBoardView(true); if ($request->isFormPost()) { $saved = $engine->buildSavedQueryFromRequest($request); $engine->saveQuery($saved); $filter_form = id(new AphrontFormView())->setUser($viewer); $engine->buildSearchForm($filter_form, $saved); if ($engine->getErrors()) { return $this->newDialog()->setWidth(AphrontDialogView::WIDTH_FULL)->setTitle(pht('Advanced Filter'))->appendChild($filter_form->buildLayoutView())->setErrors($engine->getErrors())->setSubmitURI($board_uri)->addSubmitButton(pht('Apply Filter'))->addCancelButton($board_uri); } return id(new AphrontRedirectResponse())->setURI($this->getURIWithState($engine->getQueryResultsPageURI($saved->getQueryKey()))); } $query_key = $request->getURIData('queryKey'); if (!$query_key) { if ($is_sprint == true) { $query_key = 'all'; } else { $query_key = 'open'; } } $this->queryKey = $query_key; $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 ($request->getURIData('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->withEdgeLogicPHIDs(PhabricatorProjectObjectHasProjectEdgeType::EDGECONST, PhabricatorQueryConstraint::OPERATOR_AND, array($project->getPHID()))->setOrder(ManiphestTaskQuery::ORDER_PRIORITY)->setViewer($viewer)->execute(); $tasks = mpull($tasks, null, 'getPHID'); if ($tasks) { $positions = id(new PhabricatorProjectColumnPositionQuery())->setViewer($viewer)->withObjectPHIDs(mpull($tasks, 'getPHID'))->withColumns($columns)->execute(); $positions = mpull($positions, null, 'getObjectPHID'); } else { $positions = array(); } $task_map = array(); foreach ($tasks as $task) { $task_phid = $task->getPHID(); if (empty($positions[$task_phid])) { // This shouldn't normally be possible because we create positions on // demand, but we might have raced as an object was removed from the // board. Just drop the task if we don't have a position for it. continue; } $position = $positions[$task_phid]; $task_map[$position->getColumnPHID()][] = $task_phid; } // If we're showing the board in "natural" order, sort columns by their // column positions. if ($this->sortKey == PhabricatorProjectColumn::ORDER_NATURAL) { foreach ($task_map as $column_phid => $task_phids) { $order = array(); foreach ($task_phids as $task_phid) { if (isset($positions[$task_phid])) { $order[$task_phid] = $positions[$task_phid]->getOrderingKey(); } else { $order[$task_phid] = 0; } } asort($order); $task_map[$column_phid] = array_keys($order); } } $task_can_edit_map = id(new PhabricatorPolicyFilter())->setViewer($viewer)->requireCapabilities(array(PhabricatorPolicyCapability::CAN_EDIT))->apply($tasks); // If this is a batch edit, select the editable tasks in the chosen column // and ship the user into the batch editor. $batch_edit = $request->getStr('batch'); if ($batch_edit) { if ($batch_edit !== self::BATCH_EDIT_ALL) { $column_id_map = mpull($columns, null, 'getID'); $batch_column = idx($column_id_map, $batch_edit); if (!$batch_column) { return new Aphront404Response(); } $batch_task_phids = idx($task_map, $batch_column->getPHID(), array()); foreach ($batch_task_phids as $key => $batch_task_phid) { if (empty($task_can_edit_map[$batch_task_phid])) { unset($batch_task_phids[$key]); } } $batch_tasks = array_select_keys($tasks, $batch_task_phids); } else { $batch_tasks = $task_can_edit_map; } if (!$batch_tasks) { $cancel_uri = $this->getURIWithState($board_uri); return $this->newDialog()->setTitle(pht('No Editable Tasks'))->appendParagraph(pht('The selected column contains no visible tasks which you ' . 'have permission to edit.'))->addCancelButton($board_uri); } $batch_ids = mpull($batch_tasks, 'getID'); $batch_ids = implode(',', $batch_ids); if ($is_sprint == true) { $batch_uri = new PhutilURI('/project/sprint/board/batch/'); } else { $batch_uri = new PhutilURI('/maniphest/batch/'); } $batch_uri->setQueryParam('board', $this->id); $batch_uri->setQueryParam('batch', $batch_ids); return id(new AphrontRedirectResponse())->setURI($batch_uri); } $board_id = celerity_generate_unique_node_id(); $board = id(new PHUIWorkboardView())->setUser($viewer)->setID($board_id); if ($is_sprint == true) { $behavior_config = array('boardID' => $board_id, 'projectPHID' => $project->getPHID(), 'moveURI' => $this->getApplicationURI('move/' . $project->getID() . '/'), 'createURI' => '/project/sprint/board/task/create/', 'order' => $this->sortKey); $this->initSprintBehavior('sprint-boards', $behavior_config); $this->addExtraQuickSandConfig(array('boardConfig' => $behavior_config)); } else { $behavior_config = array('boardID' => $board_id, 'projectPHID' => $project->getPHID(), 'moveURI' => $this->getApplicationURI('move/' . $project->getID() . '/'), 'createURI' => '/maniphest/task/create/', 'order' => $this->sortKey); $this->initBehavior('project-boards', $behavior_config); $this->addExtraQuickSandConfig(array('boardConfig' => $behavior_config)); } $this->handles = ManiphestTaskListView::loadTaskHandles($viewer, $tasks); foreach ($columns as $column) { $task_phids = idx($task_map, $column->getPHID(), array()); $column_tasks = array_select_keys($tasks, $task_phids); $panel = id(new PHUIWorkpanelView())->setHeader($column->getDisplayName())->setSubHeader($column->getDisplayType())->addSigil('workpanel'); $header_icon = $column->getHeaderIcon(); if ($header_icon) { $panel->setHeaderIcon($header_icon); } if ($column->isHidden()) { $panel->addClass('project-panel-hidden'); } $column_menu = $this->buildColumnMenu($project, $column); $panel->addHeaderAction($column_menu); $tag_id = celerity_generate_unique_node_id(); $tag_content_id = celerity_generate_unique_node_id(); $count_tag = id(new PHUITagView())->setType(PHUITagView::TYPE_SHADE)->setShade(PHUITagView::COLOR_BLUE)->setID($tag_id)->setName(phutil_tag('span', array('id' => $tag_content_id), '-'))->setStyle('display: none'); $panel->setHeaderTag($count_tag); $cards = id(new PHUIObjectItemListView())->setUser($viewer)->setFlush(true)->setAllowEmptyList(true)->addSigil('project-column')->setMetadata(array('columnPHID' => $column->getPHID(), 'countTagID' => $tag_id, 'countTagContentID' => $tag_content_id, 'pointLimit' => $column->getPointLimit())); foreach ($column_tasks as $task) { $owner = null; if ($task->getOwnerPHID()) { $owner = $this->handles[$task->getOwnerPHID()]; } $can_edit = idx($task_can_edit_map, $task->getPHID(), false); if ($is_sprint == true) { $cards->addItem(id(new SprintBoardTaskCard())->setProject($project)->setViewer($viewer)->setTask($task)->setOwner($owner)->setCanEdit($can_edit)->getItem()); } else { $cards->addItem(id(new ProjectBoardTaskCard())->setViewer($viewer)->setTask($task)->setOwner($owner)->setCanEdit($can_edit)->getItem()); } } $panel->setCards($cards); $board->addPanel($panel); } $sort_menu = $this->buildSortMenu($viewer, $sort_key); $filter_menu = $this->buildFilterMenu($viewer, $custom_query, $engine, $query_key); $manage_menu = $this->buildManageMenu($project, $show_hidden); $header_link = phutil_tag('a', array('href' => $this->getApplicationURI('profile/' . $project->getID() . '/')), $project->getName()); $header = id(new PHUIHeaderView())->setHeader($header_link)->setUser($viewer)->setNoBackground(true)->addActionLink($sort_menu)->addActionLink($filter_menu)->addActionLink($manage_menu)->setPolicyObject($project); $header_box = id(new PHUIBoxView())->appendChild($header)->addClass('project-board-header'); $board_box = id(new PHUIBoxView())->appendChild($board)->addClass('project-board-wrapper'); $nav = $this->buildIconNavView($project); $nav->appendChild($header_box); $nav->appendChild($board_box); return $this->buildApplicationPage($nav, array('title' => pht('%s Board', $project->getName()), 'showFooter' => false, 'pageObjects' => array($project->getPHID()))); }
private function renderTasksPage(PhabricatorProject $project) { $user = $this->getRequest()->getUser(); $query = id(new ManiphestTaskQuery())->setViewer($user)->withAnyProjects(array($project->getPHID()))->withStatuses(ManiphestTaskStatus::getOpenStatusConstants())->setOrderBy(ManiphestTaskQuery::ORDER_PRIORITY)->setLimit(10); $tasks = $query->execute(); $phids = mpull($tasks, 'getOwnerPHID'); $phids = array_merge($phids, array_mergev(mpull($tasks, 'getProjectPHIDs'))); $phids = array_filter($phids); $handles = $this->loadViewerHandles($phids); $task_list = new ManiphestTaskListView(); $task_list->setUser($user); $task_list->setTasks($tasks); $task_list->setHandles($handles); $phid = $project->getPHID(); $view_uri = urisprintf('/maniphest/?statuses=%s&allProjects=%s#R', implode(',', ManiphestTaskStatus::getOpenStatusConstants()), $phid); $create_uri = '/maniphest/task/create/?projects=' . $phid; $icon = id(new PHUIIconView())->setIconFont('fa-list'); $button_view = id(new PHUIButtonView())->setTag('a')->setText(pht('View All'))->setHref($view_uri)->setIcon($icon); $icon_new = id(new PHUIIconView())->setIconFont('fa-plus'); $button_add = id(new PHUIButtonView())->setTag('a')->setText(pht('New Task'))->setHref($create_uri)->setIcon($icon_new); $header = id(new PHUIHeaderView())->setHeader(pht('Open Tasks'))->addActionLink($button_add)->addActionLink($button_view); $content = id(new PHUIObjectBoxView())->setHeader($header)->appendChild($task_list); return $content; }
public function handleRequest(AphrontRequest $request) { $viewer = $this->getViewer(); $this->requireApplicationCapability(ManiphestBulkEditCapability::CAPABILITY); $project = null; $board_id = $request->getInt('board'); if ($board_id) { $project = id(new PhabricatorProjectQuery())->setViewer($viewer)->withIDs(array($board_id))->executeOne(); if (!$project) { return new Aphront404Response(); } } $task_ids = $request->getArr('batch'); if (!$task_ids) { $task_ids = $request->getStrList('batch'); } if (!$task_ids) { throw new Exception(pht('No tasks are selected.')); } $tasks = id(new ManiphestTaskQuery())->setViewer($viewer)->withIDs($task_ids)->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->needSubscriberPHIDs(true)->needProjectPHIDs(true)->execute(); if (!$tasks) { throw new Exception(pht("You don't have permission to edit any of the selected tasks.")); } if ($project) { $cancel_uri = '/project/board/' . $project->getID() . '/'; $redirect_uri = $cancel_uri; } else { $cancel_uri = '/maniphest/'; $redirect_uri = '/maniphest/?ids=' . implode(',', mpull($tasks, 'getID')); } $actions = $request->getStr('actions'); if ($actions) { $actions = phutil_json_decode($actions); } if ($request->isFormPost() && $actions) { $job = PhabricatorWorkerBulkJob::initializeNewJob($viewer, new ManiphestTaskEditBulkJobType(), array('taskPHIDs' => mpull($tasks, 'getPHID'), 'actions' => $actions, 'cancelURI' => $cancel_uri, 'doneURI' => $redirect_uri)); $type_status = PhabricatorWorkerBulkJobTransaction::TYPE_STATUS; $xactions = array(); $xactions[] = id(new PhabricatorWorkerBulkJobTransaction())->setTransactionType($type_status)->setNewValue(PhabricatorWorkerBulkJob::STATUS_CONFIRM); $editor = id(new PhabricatorWorkerBulkJobEditor())->setActor($viewer)->setContentSourceFromRequest($request)->setContinueOnMissingFields(true)->applyTransactions($job, $xactions); return id(new AphrontRedirectResponse())->setURI($job->getMonitorURI()); } $handles = ManiphestTaskListView::loadTaskHandles($viewer, $tasks); $list = new ManiphestTaskListView(); $list->setTasks($tasks); $list->setUser($viewer); $list->setHandles($handles); $template = new AphrontTokenizerTemplateView(); $template = $template->render(); $projects_source = new PhabricatorProjectDatasource(); $mailable_source = new PhabricatorMetaMTAMailableDatasource(); $mailable_source->setViewer($viewer); $owner_source = new ManiphestAssigneeDatasource(); $owner_source->setViewer($viewer); $spaces_source = id(new PhabricatorSpacesNamespaceDatasource())->setViewer($viewer); require_celerity_resource('maniphest-batch-editor'); Javelin::initBehavior('maniphest-batch-editor', array('root' => 'maniphest-batch-edit-form', 'tokenizerTemplate' => $template, 'sources' => array('project' => array('src' => $projects_source->getDatasourceURI(), 'placeholder' => $projects_source->getPlaceholderText(), 'browseURI' => $projects_source->getBrowseURI()), 'owner' => array('src' => $owner_source->getDatasourceURI(), 'placeholder' => $owner_source->getPlaceholderText(), 'browseURI' => $owner_source->getBrowseURI(), 'limit' => 1), 'cc' => array('src' => $mailable_source->getDatasourceURI(), 'placeholder' => $mailable_source->getPlaceholderText(), 'browseURI' => $mailable_source->getBrowseURI()), 'spaces' => array('src' => $spaces_source->getDatasourceURI(), 'placeholder' => $spaces_source->getPlaceholderText(), 'browseURI' => $spaces_source->getBrowseURI(), 'limit' => 1)), 'input' => 'batch-form-actions', 'priorityMap' => ManiphestTaskPriority::getTaskPriorityMap(), 'statusMap' => ManiphestTaskStatus::getTaskStatusMap())); $form = id(new AphrontFormView())->setUser($viewer)->addHiddenInput('board', $board_id)->setID('maniphest-batch-edit-form'); foreach ($tasks as $task) { $form->appendChild(phutil_tag('input', array('type' => 'hidden', 'name' => 'batch[]', 'value' => $task->getID()))); } $form->appendChild(phutil_tag('input', array('type' => 'hidden', 'name' => 'actions', 'id' => 'batch-form-actions'))); $form->appendChild(id(new PHUIFormInsetView())->setTitle(pht('Actions'))->setRightButton(javelin_tag('a', array('href' => '#', 'class' => 'button green', 'sigil' => 'add-action', 'mustcapture' => true), pht('Add Another Action')))->setContent(javelin_tag('table', array('sigil' => 'maniphest-batch-actions', 'class' => 'maniphest-batch-actions-table'), '')))->appendChild(id(new AphrontFormSubmitControl())->setValue(pht('Update Tasks'))->addCancelButton($cancel_uri)); $title = pht('Batch Editor'); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb($title); $task_box = id(new PHUIObjectBoxView())->setHeaderText(pht('Selected Tasks'))->setObjectList($list); $form_box = id(new PHUIObjectBoxView())->setHeaderText(pht('Batch Editor'))->setForm($form); return $this->buildApplicationPage(array($crumbs, $task_box, $form_box), array('title' => $title)); }
public function handleRequest(AphrontRequest $request) { $viewer = $request->getUser(); $response = $this->loadProject(); if ($response) { return $response; } $project = $this->getProject(); $this->readRequestState(); $board_uri = $this->getApplicationURI('board/' . $project->getID() . '/'); $search_engine = id(new ManiphestTaskSearchEngine())->setViewer($viewer)->setBaseURI($board_uri)->setIsBoardView(true); if ($request->isFormPost() && !$request->getBool('initialize')) { $saved = $search_engine->buildSavedQueryFromRequest($request); $search_engine->saveQuery($saved); $filter_form = id(new AphrontFormView())->setUser($viewer); $search_engine->buildSearchForm($filter_form, $saved); if ($search_engine->getErrors()) { return $this->newDialog()->setWidth(AphrontDialogView::WIDTH_FULL)->setTitle(pht('Advanced Filter'))->appendChild($filter_form->buildLayoutView())->setErrors($search_engine->getErrors())->setSubmitURI($board_uri)->addSubmitButton(pht('Apply Filter'))->addCancelButton($board_uri); } return id(new AphrontRedirectResponse())->setURI($this->getURIWithState($search_engine->getQueryResultsPageURI($saved->getQueryKey()))); } $query_key = $request->getURIData('queryKey'); if (!$query_key) { $query_key = 'open'; } $this->queryKey = $query_key; $custom_query = null; if ($search_engine->isBuiltinQuery($query_key)) { $saved = $search_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 ($request->getURIData('filter')) { $filter_form = id(new AphrontFormView())->setUser($viewer); $search_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 = $search_engine->buildQueryFromSavedQuery($saved); $select_phids = array($project->getPHID()); if ($project->getHasSubprojects() || $project->getHasMilestones()) { $descendants = id(new PhabricatorProjectQuery())->setViewer($viewer)->withAncestorProjectPHIDs($select_phids)->execute(); foreach ($descendants as $descendant) { $select_phids[] = $descendant->getPHID(); } } $tasks = $task_query->withEdgeLogicPHIDs(PhabricatorProjectObjectHasProjectEdgeType::EDGECONST, PhabricatorQueryConstraint::OPERATOR_ANCESTOR, array($select_phids))->setOrder(ManiphestTaskQuery::ORDER_PRIORITY)->setViewer($viewer)->execute(); $tasks = mpull($tasks, null, 'getPHID'); $board_phid = $project->getPHID(); $layout_engine = id(new PhabricatorBoardLayoutEngine())->setViewer($viewer)->setBoardPHIDs(array($board_phid))->setObjectPHIDs(array_keys($tasks))->executeLayout(); $columns = $layout_engine->getColumns($board_phid); if (!$columns) { $can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $project, PhabricatorPolicyCapability::CAN_EDIT); if (!$can_edit) { $content = $this->buildNoAccessContent($project); } else { $content = $this->buildInitializeContent($project); } if ($content instanceof AphrontResponse) { return $content; } $nav = $this->getProfileMenu(); $nav->selectFilter(PhabricatorProject::PANEL_WORKBOARD); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb(pht('Workboard')); return $this->newPage()->setTitle(array(pht('Workboard'), $project->getName()))->setNavigation($nav)->setCrumbs($crumbs)->appendChild($content); } $task_can_edit_map = id(new PhabricatorPolicyFilter())->setViewer($viewer)->requireCapabilities(array(PhabricatorPolicyCapability::CAN_EDIT))->apply($tasks); // If this is a batch edit, select the editable tasks in the chosen column // and ship the user into the batch editor. $batch_edit = $request->getStr('batch'); if ($batch_edit) { if ($batch_edit !== self::BATCH_EDIT_ALL) { $column_id_map = mpull($columns, null, 'getID'); $batch_column = idx($column_id_map, $batch_edit); if (!$batch_column) { return new Aphront404Response(); } $batch_task_phids = $layout_engine->getColumnObjectPHIDs($board_phid, $batch_column->getPHID()); foreach ($batch_task_phids as $key => $batch_task_phid) { if (empty($task_can_edit_map[$batch_task_phid])) { unset($batch_task_phids[$key]); } } $batch_tasks = array_select_keys($tasks, $batch_task_phids); } else { $batch_tasks = $task_can_edit_map; } if (!$batch_tasks) { $cancel_uri = $this->getURIWithState($board_uri); return $this->newDialog()->setTitle(pht('No Editable Tasks'))->appendParagraph(pht('The selected column contains no visible tasks which you ' . 'have permission to edit.'))->addCancelButton($board_uri); } $batch_ids = mpull($batch_tasks, 'getID'); $batch_ids = implode(',', $batch_ids); $batch_uri = new PhutilURI('/maniphest/batch/'); $batch_uri->setQueryParam('board', $this->id); $batch_uri->setQueryParam('batch', $batch_ids); return id(new AphrontRedirectResponse())->setURI($batch_uri); } $board_id = celerity_generate_unique_node_id(); $board = id(new PHUIWorkboardView())->setUser($viewer)->setID($board_id); $behavior_config = array('boardID' => $board_id, 'projectPHID' => $project->getPHID(), 'moveURI' => $this->getApplicationURI('move/' . $project->getID() . '/'), 'createURI' => $this->getCreateURI(), 'order' => $this->sortKey); $this->initBehavior('project-boards', $behavior_config); $this->handles = ManiphestTaskListView::loadTaskHandles($viewer, $tasks); $all_project_phids = array(); foreach ($tasks as $task) { foreach ($task->getProjectPHIDs() as $project_phid) { $all_project_phids[$project_phid] = $project_phid; } } foreach ($select_phids as $phid) { unset($all_project_phids[$phid]); } $all_handles = $viewer->loadHandles($all_project_phids); $all_handles = iterator_to_array($all_handles); foreach ($columns as $column) { if (!$this->showHidden) { if ($column->isHidden()) { continue; } } $proxy = $column->getProxy(); if ($proxy && !$proxy->isMilestone()) { // TODO: For now, don't show subproject columns because we can't // handle tasks with multiple positions yet. continue; } $task_phids = $layout_engine->getColumnObjectPHIDs($board_phid, $column->getPHID()); $column_tasks = array_select_keys($tasks, $task_phids); // If we aren't using "natural" order, reorder the column by the original // query order. if ($this->sortKey != PhabricatorProjectColumn::ORDER_NATURAL) { $column_tasks = array_select_keys($column_tasks, array_keys($tasks)); } $panel = id(new PHUIWorkpanelView())->setHeader($column->getDisplayName())->setSubHeader($column->getDisplayType())->addSigil('workpanel'); $header_icon = $column->getHeaderIcon(); if ($header_icon) { $panel->setHeaderIcon($header_icon); } $display_class = $column->getDisplayClass(); if ($display_class) { $panel->addClass($display_class); } if ($column->isHidden()) { $panel->addClass('project-panel-hidden'); } $column_menu = $this->buildColumnMenu($project, $column); $panel->addHeaderAction($column_menu); $tag_id = celerity_generate_unique_node_id(); $tag_content_id = celerity_generate_unique_node_id(); $count_tag = id(new PHUITagView())->setType(PHUITagView::TYPE_SHADE)->setShade(PHUITagView::COLOR_BLUE)->setID($tag_id)->setName(phutil_tag('span', array('id' => $tag_content_id), '-'))->setStyle('display: none'); $panel->setHeaderTag($count_tag); $cards = id(new PHUIObjectItemListView())->setUser($viewer)->setFlush(true)->setAllowEmptyList(true)->addSigil('project-column')->setItemClass('phui-workcard')->setMetadata(array('columnPHID' => $column->getPHID(), 'countTagID' => $tag_id, 'countTagContentID' => $tag_content_id, 'pointLimit' => $column->getPointLimit())); foreach ($column_tasks as $task) { $owner = null; if ($task->getOwnerPHID()) { $owner = $this->handles[$task->getOwnerPHID()]; } $can_edit = idx($task_can_edit_map, $task->getPHID(), false); $handles = array_select_keys($all_handles, $task->getProjectPHIDs()); $cards->addItem(id(new ProjectBoardTaskCard())->setViewer($viewer)->setProjectHandles($handles)->setTask($task)->setOwner($owner)->setCanEdit($can_edit)->getItem()); } $panel->setCards($cards); $board->addPanel($panel); } $sort_menu = $this->buildSortMenu($viewer, $this->sortKey); $filter_menu = $this->buildFilterMenu($viewer, $custom_query, $search_engine, $query_key); $manage_menu = $this->buildManageMenu($project, $this->showHidden); $header_link = phutil_tag('a', array('href' => $this->getApplicationURI('profile/' . $project->getID() . '/')), $project->getName()); $board_box = id(new PHUIBoxView())->appendChild($board)->addClass('project-board-wrapper'); $nav = $this->getProfileMenu(); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb(pht('Workboard')); $crumbs->setBorder(true); $crumbs->addAction($sort_menu); $crumbs->addAction($filter_menu); $crumbs->addAction($manage_menu); return $this->newPage()->setTitle(pht('%s Board', $project->getName()))->setPageObjectPHIDs(array($project->getPHID()))->setShowFooter(false)->setNavigation($nav)->setCrumbs($crumbs)->addQuicksandConfig(array('boardConfig' => $behavior_config))->appendChild(array($board_box)); }