Christopher Johnson (WMDE) has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/176874

Change subject: remove before and after from Sprint
......................................................................

remove before and after from Sprint

correct SprintTransaction behavior
move getStoryPoints to SprintQuery

Change-Id: I6c0dce06638f13e734179381726fb1a4b7ede388
---
M src/query/SprintQuery.php
M src/storage/SprintBuildStats.php
M src/storage/SprintTransaction.php
M src/view/SprintBoardTaskCard.php
4 files changed, 78 insertions(+), 90 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/phabricator/extensions/Sprint 
refs/changes/74/176874/1

diff --git a/src/query/SprintQuery.php b/src/query/SprintQuery.php
index 709d1f5..be3e756 100644
--- a/src/query/SprintQuery.php
+++ b/src/query/SprintQuery.php
@@ -57,6 +57,24 @@
     return $tasks;
   }
 
+  private function getTaskStoryPoints($task_phid,$points_data) {
+    $storypoints = array();
+    foreach ($points_data as $k=>$subarray) {
+      if (isset ($subarray['objectPHID']) && $subarray['objectPHID'] == 
$task_phid) {
+        $points_data[$k] = $subarray;
+        $storypoints = $subarray['newValue'];
+      }
+    }
+    return $storypoints;
+  }
+
+  public function getStoryPoints($task_phid)  {
+    $data = $this->getXactionData(SprintConstants::CUSTOMFIELD_TYPE_STATUS);
+    $points = $this->getTaskStoryPoints($task_phid,$data);
+    $points = trim($points, '"');
+    return $points;
+  }
+
   public function getXactions($tasks) {
     $task_phids = mpull($tasks, 'getPHID');
 
diff --git a/src/storage/SprintBuildStats.php b/src/storage/SprintBuildStats.php
index 711d600..96d24e1 100644
--- a/src/storage/SprintBuildStats.php
+++ b/src/storage/SprintBuildStats.php
@@ -16,13 +16,13 @@
         id(new DateTime("@" . $end, $timezone))->modify('+1 day')->setTime(17, 
0));
 
 
-    $dates = array('before' =>$this->getBurndownDate('Before Sprint'));
+//    $dates = array('before' =>$this->getBurndownDate('Before Sprint'));
 
     foreach ($period as $day) {
       $dates[$day->format('D M j')] = $this->getBurndownDate(
           $day->format('D M j'));
     }
-    $dates['after'] = $this->getBurndownDate('After Sprint');
+//    $dates['after'] = $this->getBurndownDate('After Sprint');
     return $dates;
   }
 
@@ -60,8 +60,6 @@
   public function computeIdealPoints($dates) {
     $total_business_days = 0;
     foreach ($dates as $key => $date) {
-      if ($key == 'before' OR $key == 'after')
-        continue;
       $day_of_week = id(new DateTime($date->getDate()))->format('w');
       if ($day_of_week != 0 AND $day_of_week != 6) {
         $total_business_days++;
@@ -70,13 +68,7 @@
 
     $elapsed_business_days = 0;
     foreach ($dates as $key => $date) {
-      if ($key == 'before') {
-        $date->setPointsIdealRemaining($date->getPointsTotal());
-        continue;
-      } else if ($key == 'after') {
-        $date->setPointsIdealRemaining (null);
-        continue;
-      }
+      $date->setPointsIdealRemaining($date->getPointsTotal());
 
       $day_of_week = id(new DateTime($date->getDate()))->format('w');
       if ($day_of_week != 0 AND $day_of_week != 6) {
@@ -99,10 +91,9 @@
 
     $future = false;
     foreach ($dates as $key => $date) {
-      if ($key != 'before' AND $key != 'after') {
         $now = id(new DateTime('now', $this->timezone));
         $future = new DateTime($date->getDate(), $this->timezone) > $now;
-      }
+
       $data[] = array(
           $future ? null : $date->getPointsTotal(),
           $future ? null : $date->getPointsRemaining(),
diff --git a/src/storage/SprintTransaction.php 
b/src/storage/SprintTransaction.php
index 9d69a32..29132e9 100644
--- a/src/storage/SprintTransaction.php
+++ b/src/storage/SprintTransaction.php
@@ -14,54 +14,54 @@
 
   public function buildDailyData($events, $start, $end, $dates, $xactions) {
 
+    $query = id(new SprintQuery());
+
     foreach ($events as $event) {
       $xaction = $xactions[$event['transactionPHID']];
       $xaction_date = $xaction->getDateCreated();
-      $task_phid = $xaction->getObjectPHID();
 
       // Determine which date to attach this data to
-      if ($xaction_date < $start) {
-        $date = 'before';
-      } else if ($xaction_date > $end) {
-        $date = 'after';
-      } else {
-        //$date = id(new DateTime("@".$xaction_date))->format('D M j');
+      $date = null;
+      if ($xaction_date >= $start && $xaction_date <= $end) {
+        $task_phid = $xaction->getObjectPHID();
+        $points = $query->getStoryPoints($task_phid);
         $date = phabricator_format_local_time($xaction_date, $this->viewer, 'D 
M j');
-      }
 
-      switch ($event['type']) {
-        case "create":
-          // Will be accounted for by "task-add" when the project is added
-          // But we still include it so it shows on the Events list
-          break;
-        case "task-add":
-          // A task was added to the sprint
-          $this->AddTasksToday($date, $dates);
-//          $this->AddPointsToday($date, $task_phid, $dates);
-          $this->AddTaskInSprint($task_phid);
-          break;
-        case "task-remove":
-          // A task was removed from the sprint
-          $this->RemoveTasksToday($date, $dates);
-          $this->RemovePointsToday($date, $task_phid, $dates);
-          $this->RemoveTaskInSprint($task_phid);
-          break;
-        case "close":
-          // A task was closed, mark it as done
-          $this->CloseTasksToday($date, $dates);
-          $this->ClosePointsToday($date, $task_phid, $dates);
-          $this->CloseTaskStatus($task_phid);
-          break;
-        case "reopen":
-          // A task was reopened, subtract from done
-          $this->ReopenedTasksToday($date, $dates);
-          $this->ReopenedPointsToday($date, $task_phid, $dates);
-          $this->OpenTaskStatus($task_phid);
-          break;
-        case "points":
-          // Points were changed
-          $this->changePoints($date, $task_phid, $xaction, $dates);
-          break;
+          switch ($event['type']) {
+            case "create":
+              // Will be accounted for by "task-add" when the project is added
+              // But we still include it so it shows on the Events list
+              break;
+            case "task-add":
+              // A task was added to the sprint
+              $this->AddTasksToday($date, $dates);
+              $this->AddPointsToday($date, $points, $dates);
+              $this->AddTaskInSprint($task_phid);
+              break;
+            case "task-remove":
+              // A task was removed from the sprint
+              $this->RemoveTasksToday($date, $dates);
+              $this->RemovePointsToday($date, $points, $dates);
+              $this->RemoveTaskInSprint($task_phid);
+              break;
+            case "close":
+              // A task was closed, mark it as done
+              $this->CloseTasksToday($date, $dates);
+              $this->ClosePointsToday($date, $points, $dates);
+              $this->CloseTaskStatus($task_phid);
+              break;
+            case "reopen":
+              // A task was reopened, subtract from done
+              $this->ReopenedTasksToday($date, $dates);
+              $this->ReopenedPointsToday($date, $points, $dates);
+              $this->OpenTaskStatus($task_phid);
+              break;
+            case "points":
+              // Points were changed
+              $old_point_value = $xaction->getOldValue();
+              $this->changePoints($date, $task_phid, $points, 
$old_point_value, $dates);
+              break;
+          }
       }
     }
     return $dates;
@@ -97,23 +97,23 @@
     return $dates;
   }
 
-  private function AddPointsToday($date, $task_phid, $dates) {
-    $dates[$date]->setPointsAddedToday($this->task_points[$task_phid]);
+  private function AddPointsToday($date, $points, $dates) {
+    $dates[$date]->setPointsAddedToday($points);
     return $dates;
   }
 
-  private function RemovePointsToday($date, $task_phid, $dates) {
-    $dates[$date]->setPointsRemovedToday($this->task_points[$task_phid]);
+  private function RemovePointsToday($date, $points, $dates) {
+    $dates[$date]->setPointsRemovedToday($points);
     return $dates;
   }
 
-  private function ClosePointsToday($date, $task_phid, $dates) {
-   $dates[$date]->setPointsClosedToday($this->task_points[$task_phid]);
+  private function ClosePointsToday($date, $points, $dates) {
+   $dates[$date]->setPointsClosedToday($points);
     return $dates;
   }
 
-  private function ReopenedPointsToday($date, $task_phid, $dates) {
-    $dates[$date]->setPointsReopenedToday($this->task_points[$task_phid]);
+  private function ReopenedPointsToday($date, $points, $dates) {
+    $dates[$date]->setPointsReopenedToday($points);
     return $dates;
   }
 
@@ -137,22 +137,17 @@
     return $this->task_statuses[$task_phid];
   }
 
-  private function changePoints($date, $task_phid, $xaction, $dates) {
-    $this->task_points[$task_phid] = $xaction->getNewValue();
+  private function changePoints($date, $task_phid, $points, $old_point_value, 
$dates) {
 
-    // Only make changes if the task is in the sprint
-    if (isset($this->task_in_sprint[$task_phid])) {
-
-      // Adjust points for that day
-      $this->task_points[$task_phid] = $xaction->getNewValue() - 
$xaction->getOldValue();
+       // Adjust points for that day
+      $this->task_points[$task_phid] = $points - $old_point_value;
       $dates[$date]->setPointsAddedToday($this->task_points[$task_phid]);
 
       // If the task is closed, adjust completed points as well
       if (isset($this->task_statuses[$task_phid]) && 
$this->task_statuses[$task_phid] == 'closed') {
-        $this->task_points[$task_phid] = $xaction->getNewValue() - 
$xaction->getOldValue();
+        $this->task_points[$task_phid] = $points - $old_point_value;
         $dates[$date]->setPointsClosedToday($this->task_points[$task_phid]);
       }
-    }
     return $dates;
   }
 }
\ No newline at end of file
diff --git a/src/view/SprintBoardTaskCard.php b/src/view/SprintBoardTaskCard.php
index a85e482..43d6bf5 100644
--- a/src/view/SprintBoardTaskCard.php
+++ b/src/view/SprintBoardTaskCard.php
@@ -54,32 +54,16 @@
     return $this->canEdit;
   }
 
-  private function getTaskStoryPoints($task,$points_data) {
-    $storypoints = array();
-    foreach ($points_data as $k=>$subarray) {
-      if (isset ($subarray['objectPHID']) && $subarray['objectPHID'] == $task) 
{
-        $points_data[$k] = $subarray;
-        $storypoints = $subarray['newValue'];
-      }
-    }
-    return $storypoints;
-  }
 
-  public function getStoryPoints($task)  {
+  public function getItem() {
     $query = id(new SprintQuery())
         ->setProject($this->project)
         ->setViewer($this->viewer);
 
-    $data = $query->getXactionData(SprintConstants::CUSTOMFIELD_TYPE_STATUS);
-    $points = $this->getTaskStoryPoints($task->getPHID(),$data);
-    $points = trim($points, '"');
-    return $points;
-  }
-
-  public function getItem() {
     $task = $this->getTask();
+    $task_phid = $task->getPHID();
     $owner = $this->getOwner();
-    $points = $this->getStoryPoints($task);
+    $points = $query->getStoryPoints($task_phid);
     $can_edit = $this->getCanEdit();
 
     $color_map = ManiphestTaskPriority::getColorMap();

-- 
To view, visit https://gerrit.wikimedia.org/r/176874
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6c0dce06638f13e734179381726fb1a4b7ede388
Gerrit-PatchSet: 1
Gerrit-Project: phabricator/extensions/Sprint
Gerrit-Branch: master
Gerrit-Owner: Christopher Johnson (WMDE) <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to