فهرست منبع

Add counts to overview

Alan Lam 5 سال پیش
والد
کامیت
d51a59ae79
2فایلهای تغییر یافته به همراه30 افزوده شده و 10 حذف شده
  1. 18 8
      engine/project.php
  2. 12 2
      views/overview.php

+ 18 - 8
engine/project.php

@@ -229,20 +229,30 @@ class Project extends Model {
 	}
 
 	/**
-	 * @return float
+	 * @return array
 	 * @throws Exception
 	 */
-	public function getCompletedPercentage(): float {
-
-		$test_count = $this->test_count;
-
+	public function getCompletedTests(): array {
 		$tests = $this->getTests();
-		$completed_tests = array_filter($tests, static function($test) {
+		return array_filter($tests, static function($test) {
 			return (int) $test->status === Test::STATUS_COMPLETED;
 		});
-		$completed_test_count = count($completed_tests);
+	}
 
-		return floor(($completed_test_count / $test_count) * 100);
+	/**
+	 * @return int
+	 * @throws Exception
+	 */
+	public function getCompletedTestCount(): int {
+		return count($this->getCompletedTests());
+	}
+
+	/**
+	 * @return float
+	 * @throws Exception
+	 */
+	public function getCompletedPercentage(): float {
+		return floor((count($this->getCompletedTests()) / $this->test_count) * 100);
 
 	}
 

+ 12 - 2
views/overview.php

@@ -41,6 +41,8 @@ $exclude_project_ids = array_column($exclude_projects, "id");
 			$projects = Project::query([
 				"customer_id" => Constraint::notIn($exclude_customer_ids),
 				"dts_start" => Constraint::between($dts_start, $dts_end),
+			], [
+				"sort" => "name"
 			]);
 
 			?>
@@ -53,15 +55,23 @@ $exclude_project_ids = array_column($exclude_projects, "id");
 				<div class="list-group">
 					<?php
 					foreach($projects as $project) {
-						$percentage = $project->getCompletedPercentage();
+
+						$completed_count = $project->getCompletedTestCount();
+
+						$percentage = round(($completed_count / $project->test_count) * 100);
+						if($percentage > 100) $percentage = 100;
+
 						?>
 						<a class="list-group-item list-group-item-action text-nowrap" style="font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis;" href="/account/projects/<?=$project->id?>">
 							<?=htmlspecialchars($project->name)?>
 							<div class="progress">
 								<div class="progress-bar" role="progressbar" aria-valuenow="<?=$percentage?>" aria-valuemin="0" aria-valuemax="100" style="width: <?=$percentage?>%">
-
 								</div>
 							</div>
+							<strong><?=htmlspecialchars(__("Completed:"))?></strong>
+							<?=$percentage?>%
+							(<?=$completed_count?> of <?=$project->test_count?>)
+
 						</a>
 						<?php
 					}