Quellcode durchsuchen

Convert project list list group into table

Alan Lam vor 7 Jahren
Ursprung
Commit
09a272d7f1
3 geänderte Dateien mit 66 neuen und 21 gelöschten Zeilen
  1. 2 0
      controllers/test_results_project_list.php
  2. 34 9
      engine/project.php
  3. 30 12
      views/test_results_project_list.php

+ 2 - 0
controllers/test_results_project_list.php

@@ -15,6 +15,8 @@ $projects = array_filter($projects, function($project) {
 
 
 $test_results_url = $customer->getTestResultsUrl();
 $test_results_url = $customer->getTestResultsUrl();
 
 
+$page_title = $customer->name;
+
 Core::addBreadcrumb("/account", __("Account"));
 Core::addBreadcrumb("/account", __("Account"));
 Core::addBreadcrumb("/account/test-results", __("Test Results"));
 Core::addBreadcrumb("/account/test-results", __("Test Results"));
 Core::addBreadcrumb($test_results_url, $customer->name);
 Core::addBreadcrumb($test_results_url, $customer->name);

+ 34 - 9
engine/project.php

@@ -26,6 +26,10 @@
 
 
 class Project extends Model {
 class Project extends Model {
 
 
+	const TOD_ANYTIME = "A";
+	const TOD_DAYTIME = "D";
+	const TOD_NIGHTTIME = "N";
+
 	protected static $table = "project";
 	protected static $table = "project";
 	protected static $id_field = "id";
 	protected static $id_field = "id";
 	protected static $fillable_fields = ["customer_id", "template_id", "name", "test_count", "min_age", "max_age", "default_customer_fee", "default_tester_fee", "time_of_day", "tester_can_claim", "template_overrides_json", "dts_start", "dts_deadline", "dts_created", "dts_updated", "dts_report", "dts_finished", "user_id_finished"];
 	protected static $fillable_fields = ["customer_id", "template_id", "name", "test_count", "min_age", "max_age", "default_customer_fee", "default_tester_fee", "time_of_day", "tester_can_claim", "template_overrides_json", "dts_start", "dts_deadline", "dts_created", "dts_updated", "dts_report", "dts_finished", "user_id_finished"];
@@ -94,6 +98,15 @@ class Project extends Model {
 		return $count;
 		return $count;
 	}
 	}
 
 
+	public function getPassRate(): string {
+		$pass_count = $this->getPassCount();
+		$fail_count = $this->getFailCount();
+		$pass_fail_count = $pass_count + $fail_count;
+		if($pass_fail_count == 0) return "0%";
+
+		return (number_format($pass_count / $pass_fail_count, 4) * 100) . "%";
+	}
+
 	public function getLocations() {
 	public function getLocations() {
 		$tests = $this->getTests();
 		$tests = $this->getTests();
 		return Location::query(["id" => array_column($tests, "location_id")]);
 		return Location::query(["id" => array_column($tests, "location_id")]);
@@ -115,6 +128,18 @@ class Project extends Model {
 
 
 	}
 	}
 
 
+	public function getNameHtml(): string {
+
+		if($this->isAnytime()) {
+			return htmlspecialchars($this->name);
+		}
+
+		$icon = $this->getTimeOfDayIcon();
+		$time_of_day = $this->getTimeOfDayText();
+
+		return htmlspecialchars($this->name) . " <i class=\"fa fa-fw fa-{$icon}\" data-toggle=\"tooltip\" title=\"{$time_of_day}\"></i>";
+	}
+
 	public function getCompletedPercentage() {
 	public function getCompletedPercentage() {
 
 
 		$test_count = $this->test_count;
 		$test_count = $this->test_count;
@@ -143,17 +168,17 @@ class Project extends Model {
 
 
 	public function getTimeOfDayText() {
 	public function getTimeOfDayText() {
 		switch($this->time_of_day) {
 		switch($this->time_of_day) {
-			case "A": return "Any";
-			case "D": return "Day";
-			case "N": return "Night";
+			case self::TOD_ANYTIME: return "Any";
+			case self::TOD_DAYTIME: return "Day";
+			case self::TOD_NIGHTTIME: return "Night";
 		}
 		}
 	}
 	}
 
 
 	public function getTimeOfDayIcon() {
 	public function getTimeOfDayIcon() {
 		switch($this->time_of_day) {
 		switch($this->time_of_day) {
-			case "A": return "adjust";
-			case "D": return "sun";
-			case "N": return "moon";
+			case self::TOD_ANYTIME: return "adjust";
+			case self::TOD_DAYTIME: return "sun";
+			case self::TOD_NIGHTTIME: return "moon";
 		}
 		}
 	}
 	}
 
 
@@ -173,15 +198,15 @@ class Project extends Model {
 	}
 	}
 
 
 	public function isAnytime() {
 	public function isAnytime() {
-		return $this->time_of_day == "A";
+		return $this->time_of_day == self::TOD_ANYTIME;
 	}
 	}
 
 
 	public function isDaytime() {
 	public function isDaytime() {
-		return $this->time_of_day == "D";
+		return $this->time_of_day == self::TOD_DAYTIME;
 	}
 	}
 
 
 	public function isNighttime() {
 	public function isNighttime() {
-		return $this->time_of_day == "N";
+		return $this->time_of_day == self::TOD_NIGHTTIME;
 	}
 	}
 
 
 	public function isPastDeadline() {
 	public function isPastDeadline() {

+ 30 - 12
views/test_results_project_list.php

@@ -22,20 +22,38 @@
     }
     }
     else {
     else {
         ?>
         ?>
-        <div class="list-group">
-        <?php
-        foreach($projects as $project) {
-
-            $url = $project->getTestResultsUrl();
 
 
-            ?>
-            <a class="list-group-item list-group-item-action" href="<?=htmlspecialchars($url)?>">
-                <?=htmlspecialchars($project->name)?>
-            </a>
+        <table class="table table-bordered">
+            <col style="width: 40%;">
+            <col style="width: 15%;">
+            <col style="width: 15%;">
+            <col style="width: 15%;">
+            <col style="width: 15%;">
+            <thead>
+                <th><?=htmlspecialchars(__("Name"))?></th>
+                <th><?=htmlspecialchars(__("Report Month"))?></th>
+                <th><?=htmlspecialchars(__("Test Count"))?></th>
+                <th><?=htmlspecialchars(__("Pass / Fail"))?></th>
+                <th><?=htmlspecialchars(__("Pass Rate"))?></th>
+            </thead>
+            <tbody>
             <?php
             <?php
-        }
-        ?>
-        </div>
+            foreach($projects as $project) {
+                $url = $project->getTestResultsUrl();
+                ?>
+                <tr>
+                    <td><a href="<?=htmlspecialchars($url)?>"><?=$project->getNameHtml()?></a></td>
+                    <td><?=$project->getDisplayReportMonth()?></td>
+                    <td><?=$project->getTestCount()?></td>
+                    <td><?=$project->getPassCount()?> / <?=$project->getFailCount()?></td>
+                    <td><?=$project->getPassRate()?></td>
+                </tr>
+                <?php
+            }
+            ?>
+            </tbody>
+        </table>
+
         <?php
         <?php
     }
     }
     ?>
     ?>