ManiphestTaskListView.php 4.57 KB
Newer Older
epriestley's avatar
epriestley committed
1 2
<?php

3
final class ManiphestTaskListView extends ManiphestView {
epriestley's avatar
epriestley committed
4 5 6

  private $tasks;
  private $handles;
epriestley's avatar
epriestley committed
7
  private $showBatchControls;
8
  private $noDataString;
epriestley's avatar
epriestley committed
9 10

  public function setTasks(array $tasks) {
11
    assert_instances_of($tasks, 'ManiphestTask');
epriestley's avatar
epriestley committed
12 13 14 15 16
    $this->tasks = $tasks;
    return $this;
  }

  public function setHandles(array $handles) {
17
    assert_instances_of($handles, 'PhabricatorObjectHandle');
epriestley's avatar
epriestley committed
18 19 20 21
    $this->handles = $handles;
    return $this;
  }

epriestley's avatar
epriestley committed
22 23 24 25 26
  public function setShowBatchControls($show_batch_controls) {
    $this->showBatchControls = $show_batch_controls;
    return $this;
  }

27 28 29 30 31
  public function setNoDataString($text) {
    $this->noDataString = $text;
    return $this;
  }

epriestley's avatar
epriestley committed
32
  public function render() {
33 34
    $handles = $this->handles;

35 36
    require_celerity_resource('maniphest-task-summary-css');

37
    $list = new PHUIObjectItemListView();
38

39 40 41 42 43 44
    if ($this->noDataString) {
      $list->setNoDataString($this->noDataString);
    } else {
      $list->setNoDataString(pht('No tasks.'));
    }

45
    $status_map = ManiphestTaskStatus::getTaskStatusMap();
46
    $color_map = ManiphestTaskPriority::getColorMap();
47
    $priority_map = ManiphestTaskPriority::getTaskPriorityMap();
epriestley's avatar
epriestley committed
48

49 50 51 52
    if ($this->showBatchControls) {
      Javelin::initBehavior('maniphest-list-editor');
    }

epriestley's avatar
epriestley committed
53
    foreach ($this->tasks as $task) {
epriestley's avatar
epriestley committed
54 55 56 57 58 59
      $item = id(new PHUIObjectItemView())
        ->setUser($this->getUser())
        ->setObject($task)
        ->setObjectName('T'.$task->getID())
        ->setHeader($task->getTitle())
        ->setHref('/T'.$task->getID());
60 61

      if ($task->getOwnerPHID()) {
62 63
        $owner = $handles[$task->getOwnerPHID()];
        $item->addByline(pht('Assigned: %s', $owner->renderLink()));
64 65 66
      }

      $status = $task->getStatus();
67 68 69 70
      $pri = idx($priority_map, $task->getPriority());
      $status_name = idx($status_map, $task->getStatus());
      $tooltip = pht('%s, %s', $status_name, $pri);

71 72
      $icon = ManiphestTaskStatus::getStatusIcon($task->getStatus());
      $color = idx($color_map, $task->getPriority(), 'grey');
73
      if ($task->isClosed()) {
74
        $item->setDisabled(true);
75
        $color = 'grey';
76
      }
77

78
      $item->setStatusIcon($icon.' '.$color, $tooltip);
79

80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
      if ($task->isClosed()) {
        $closed_epoch = $task->getClosedEpoch();

        // We don't expect a task to be closed without a closed epoch, but
        // recover if we find one. This can happen with older objects or with
        // lipsum test data.
        if (!$closed_epoch) {
          $closed_epoch = $task->getDateModified();
        }

        $item->addIcon(
          'fa-check-square-o grey',
          phabricator_datetime($closed_epoch, $this->getUser()));
      } else {
        $item->addIcon(
          'none',
          phabricator_datetime($task->getDateModified(), $this->getUser()));
      }
98

99
      if ($this->showBatchControls) {
100 101 102
        $item->addSigil('maniphest-task');
      }

103 104 105 106 107 108 109
      $subtype = $task->newSubtypeObject();
      if ($subtype && $subtype->hasTagView()) {
        $subtype_tag = $subtype->newTagView()
          ->setSlimShady(true);
        $item->addAttribute($subtype_tag);
      }

110 111
      $project_handles = array_select_keys(
        $handles,
112
        array_reverse($task->getProjectPHIDs()));
113 114 115 116 117
      foreach ($project_handles as $key => $project_handle) {
        if ($project_handle->getPolicyFiltered()) {
	  unset($project_handles[$key]);
	}
      }
118

119 120 121 122
      $item->addAttribute(
        id(new PHUIHandleTagListView())
          ->setLimit(4)
          ->setNoDataString(pht('No Projects'))
epriestley's avatar
epriestley committed
123
          ->setSlim(true)
124
          ->setHandles($project_handles));
125 126 127 128 129 130

      $item->setMetadata(
        array(
          'taskID' => $task->getID(),
        ));

131
      if ($this->showBatchControls) {
132
        $href = new PhutilURI('/maniphest/task/edit/'.$task->getID().'/');
133
        $item->addAction(
Chad Little's avatar
Chad Little committed
134
          id(new PHUIListItemView())
135
            ->setIcon('fa-pencil')
136
            ->addSigil('maniphest-edit-task')
137
            ->setHref($href));
138 139
      }

140
      $list->addItem($item);
epriestley's avatar
epriestley committed
141 142
    }

143
    return $list;
epriestley's avatar
epriestley committed
144 145
  }

146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
  public static function loadTaskHandles(
    PhabricatorUser $viewer,
    array $tasks) {
    assert_instances_of($tasks, 'ManiphestTask');

    $phids = array();
    foreach ($tasks as $task) {
      $assigned_phid = $task->getOwnerPHID();
      if ($assigned_phid) {
        $phids[] = $assigned_phid;
      }
      foreach ($task->getProjectPHIDs() as $project_phid) {
        $phids[] = $project_phid;
      }
    }

    if (!$phids) {
      return array();
    }

    return id(new PhabricatorHandleQuery())
      ->setViewer($viewer)
      ->withPHIDs($phids)
      ->execute();
  }

epriestley's avatar
epriestley committed
172
}