[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/maniphest/view/ -> ManiphestTaskResultListView.php (source)

   1  <?php
   2  
   3  final class ManiphestTaskResultListView extends ManiphestView {
   4  
   5    private $tasks;
   6    private $savedQuery;
   7    private $canEditPriority;
   8    private $canBatchEdit;
   9    private $showBatchControls;
  10  
  11    public function setSavedQuery(PhabricatorSavedQuery $query) {
  12      $this->savedQuery = $query;
  13      return $this;
  14    }
  15  
  16    public function setTasks(array $tasks) {
  17      $this->tasks = $tasks;
  18      return $this;
  19    }
  20  
  21    public function setCanEditPriority($can_edit_priority) {
  22      $this->canEditPriority = $can_edit_priority;
  23      return $this;
  24    }
  25  
  26    public function setCanBatchEdit($can_batch_edit) {
  27      $this->canBatchEdit = $can_batch_edit;
  28      return $this;
  29    }
  30  
  31    public function setShowBatchControls($show_batch_controls) {
  32      $this->showBatchControls = $show_batch_controls;
  33      return $this;
  34    }
  35  
  36    public function render() {
  37      $viewer = $this->getUser();
  38      $tasks = $this->tasks;
  39      $query = $this->savedQuery;
  40  
  41      // If we didn't match anything, just pick up the default empty state.
  42      if (!$tasks) {
  43        return id(new PHUIObjectItemListView())
  44          ->setUser($viewer);
  45      }
  46  
  47      $group_parameter = nonempty($query->getParameter('group'), 'priority');
  48      $order_parameter = nonempty($query->getParameter('order'), 'priority');
  49  
  50      $handles = ManiphestTaskListView::loadTaskHandles($viewer, $tasks);
  51      $groups = $this->groupTasks(
  52        $tasks,
  53        $group_parameter,
  54        $handles);
  55  
  56      $can_edit_priority = $this->canEditPriority;
  57  
  58      $can_drag = ($order_parameter == 'priority') &&
  59                  ($can_edit_priority) &&
  60                  ($group_parameter == 'none' || $group_parameter == 'priority');
  61  
  62      if (!$viewer->isLoggedIn()) {
  63        // TODO: (T603) Eventually, we conceivably need to make each task
  64        // draggable individually, since the user may be able to edit some but
  65        // not others.
  66        $can_drag = false;
  67      }
  68  
  69      $result = array();
  70  
  71      $lists = array();
  72      foreach ($groups as $group => $list) {
  73        $task_list = new ManiphestTaskListView();
  74        $task_list->setShowBatchControls($this->showBatchControls);
  75        if ($can_drag) {
  76          $task_list->setShowSubpriorityControls(true);
  77        }
  78        $task_list->setUser($viewer);
  79        $task_list->setTasks($list);
  80        $task_list->setHandles($handles);
  81  
  82        $header = javelin_tag(
  83          'h1',
  84          array(
  85            'class' => 'maniphest-task-group-header',
  86            'sigil' => 'task-group',
  87            'meta'  => array(
  88              'priority' => head($list)->getPriority(),
  89            ),
  90          ),
  91          pht('%s (%s)', $group, new PhutilNumber(count($list))));
  92  
  93        $lists[] = phutil_tag(
  94          'div',
  95          array(
  96            'class' => 'maniphest-task-group',
  97          ),
  98          array(
  99            $header,
 100            $task_list,
 101          ));
 102      }
 103  
 104      if ($can_drag) {
 105        Javelin::initBehavior(
 106          'maniphest-subpriority-editor',
 107          array(
 108            'uri'   =>  '/maniphest/subpriority/',
 109          ));
 110      }
 111  
 112      return phutil_tag(
 113        'div',
 114        array(
 115          'class' => 'maniphest-list-container',
 116        ),
 117        array(
 118          $lists,
 119          $this->showBatchControls ? $this->renderBatchEditor($query) : null,
 120        ));
 121    }
 122  
 123  
 124    private function groupTasks(array $tasks, $group, array $handles) {
 125      assert_instances_of($tasks, 'ManiphestTask');
 126      assert_instances_of($handles, 'PhabricatorObjectHandle');
 127  
 128      $groups = $this->getTaskGrouping($tasks, $group);
 129  
 130      $results = array();
 131      foreach ($groups as $label_key => $tasks) {
 132        $label = $this->getTaskLabelName($group, $label_key, $handles);
 133        $results[$label][] = $tasks;
 134      }
 135      foreach ($results as $label => $task_groups) {
 136        $results[$label] = array_mergev($task_groups);
 137      }
 138  
 139      return $results;
 140    }
 141  
 142    private function getTaskGrouping(array $tasks, $group) {
 143      switch ($group) {
 144        case 'priority':
 145          return mgroup($tasks, 'getPriority');
 146        case 'status':
 147          return mgroup($tasks, 'getStatus');
 148        case 'assigned':
 149          return mgroup($tasks, 'getOwnerPHID');
 150        case 'project':
 151          return mgroup($tasks, 'getGroupByProjectPHID');
 152        default:
 153          return array(pht('Tasks') => $tasks);
 154      }
 155    }
 156  
 157    private function getTaskLabelName($group, $label_key, array $handles) {
 158      switch ($group) {
 159        case 'priority':
 160          return ManiphestTaskPriority::getTaskPriorityName($label_key);
 161        case 'status':
 162          return ManiphestTaskStatus::getTaskStatusFullName($label_key);
 163        case 'assigned':
 164          if ($label_key) {
 165            return $handles[$label_key]->getFullName();
 166          } else {
 167            return pht('(Not Assigned)');
 168          }
 169        case 'project':
 170          if ($label_key) {
 171            return $handles[$label_key]->getFullName();
 172          } else {
 173            // This may mean "No Projects", or it may mean the query has project
 174            // constraints but the task is only in constrained projects (in this
 175            // case, we don't show the group because it would always have all
 176            // of the tasks). Since distinguishing between these two cases is
 177            // messy and the UI is reasonably clear, label generically.
 178            return pht('(Ungrouped)');
 179          }
 180        default:
 181          return pht('Tasks');
 182      }
 183    }
 184  
 185    private function renderBatchEditor(PhabricatorSavedQuery $saved_query) {
 186      $user = $this->getUser();
 187  
 188      if (!$this->canBatchEdit) {
 189        return null;
 190      }
 191  
 192      if (!$user->isLoggedIn()) {
 193        // Don't show the batch editor or excel export for logged-out users.
 194        // Technically we //could// let them export, but ehh.
 195        return null;
 196      }
 197  
 198      Javelin::initBehavior(
 199        'maniphest-batch-selector',
 200        array(
 201          'selectAll'   => 'batch-select-all',
 202          'selectNone'  => 'batch-select-none',
 203          'submit'      => 'batch-select-submit',
 204          'status'      => 'batch-select-status-cell',
 205          'idContainer' => 'batch-select-id-container',
 206          'formID'      => 'batch-select-form',
 207        ));
 208  
 209      $select_all = javelin_tag(
 210        'a',
 211        array(
 212          'href'        => '#',
 213          'mustcapture' => true,
 214          'class'       => 'grey button',
 215          'id'          => 'batch-select-all',
 216        ),
 217        pht('Select All'));
 218  
 219      $select_none = javelin_tag(
 220        'a',
 221        array(
 222          'href'        => '#',
 223          'mustcapture' => true,
 224          'class'       => 'grey button',
 225          'id'          => 'batch-select-none',
 226        ),
 227        pht('Clear Selection'));
 228  
 229      $submit = phutil_tag(
 230        'button',
 231        array(
 232          'id'          => 'batch-select-submit',
 233          'disabled'    => 'disabled',
 234          'class'       => 'disabled',
 235        ),
 236        pht("Batch Edit Selected \xC2\xBB"));
 237  
 238      $export = javelin_tag(
 239        'a',
 240        array(
 241          'href' => '/maniphest/export/'.$saved_query->getQueryKey().'/',
 242          'class' => 'grey button',
 243        ),
 244        pht('Export to Excel'));
 245  
 246      $hidden = phutil_tag(
 247        'div',
 248        array(
 249          'id' => 'batch-select-id-container',
 250        ),
 251        '');
 252  
 253      $editor = hsprintf(
 254        '<div class="maniphest-batch-editor">'.
 255          '<div class="batch-editor-header">%s</div>'.
 256          '<table class="maniphest-batch-editor-layout">'.
 257            '<tr>'.
 258              '<td>%s%s</td>'.
 259              '<td>%s</td>'.
 260              '<td id="batch-select-status-cell">%s</td>'.
 261              '<td class="batch-select-submit-cell">%s%s</td>'.
 262            '</tr>'.
 263          '</table>'.
 264        '</div>',
 265        pht('Batch Task Editor'),
 266        $select_all,
 267        $select_none,
 268        $export,
 269        '',
 270        $submit,
 271        $hidden);
 272  
 273      $editor = phabricator_form(
 274        $user,
 275        array(
 276          'method' => 'POST',
 277          'action' => '/maniphest/batch/',
 278          'id'     => 'batch-select-form',
 279        ),
 280        $editor);
 281  
 282      return $editor;
 283    }
 284  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1