Просмотр исходного кода

Allow retest creation from verify page

Alan Lam 7 лет назад
Родитель
Сommit
db826d0dce
4 измененных файлов с 56 добавлено и 2 удалено
  1. 5 1
      controllers/project_ajax.php
  2. 26 1
      controllers/test.php
  3. 10 0
      public/js/app-project.js
  4. 15 0
      views/test_verify_form.php

+ 5 - 1
controllers/project_ajax.php

@@ -46,6 +46,8 @@ if($submit) {
 					$pass_text = "";
 					$pass_icon = "";
 
+					$retest = false;
+
 					$class = "secondary";
 					if($test) {
 						$test_id = (int) $test->id;
@@ -57,6 +59,7 @@ if($submit) {
 						$pass_class = $test->getPassClass();
 						$pass_text = $test->getPassText();
 						$pass_icon = $test->getPassIcon();
+						$retest = (bool) $test->retest;
 					}
 
 					$output[] = (object) [
@@ -75,7 +78,8 @@ if($submit) {
 						"passIcon" => $pass_icon,
 						"class" => $class,
 						"latitude" => (float) $location->latitude,
-						"longitude" => (float) $location->longitude
+						"longitude" => (float) $location->longitude,
+						"retest" => $retest,
 					];
 				}
 

+ 26 - 1
controllers/test.php

@@ -265,6 +265,14 @@ else if(Core::$user->level >= User::LEVEL_ADMIN) {
 
 			$test->verifier_notes = http::value("verifier_notes", "trim");
 
+			// Check selected retest project
+			$retest_project = false;
+			$retest_project_id = http::value("retest_project_id", "int");
+			if($retest_project_id) {
+				$retest_project = Project::get($retest_project_id);
+				if(!$retest_project || $retest_project->customer_id != $customer->id) throw new Exception("The retest project selected is invalid.");
+			}
+
 			// Modify test values
 
 			// Overrides
@@ -354,6 +362,16 @@ else if(Core::$user->level >= User::LEVEL_ADMIN) {
 				$tester->score++;
 				$tester->commit();
 
+				if(!$test->pass && $retest_project) {
+					$retest = new Test;
+					$retest->project_id = $retest_project->id;
+					$retest->location_id = $location->id;
+					$retest->status = Test::STATUS_UNASSIGNED;
+					$retest->dts_created = Util::getDateTime();
+					$retest->retest = 1;
+					$success = $retest->commit();
+				}
+
 				// Save PDF
 				$pdf = $test->getPDF();
 				$pdf_string = $pdf->Output("S");
@@ -398,8 +416,15 @@ else if(Core::$user->level >= User::LEVEL_ADMIN) {
 		}
 	}
 
+	$projects = $customer->getProjects();
+	$future_projects = array_filter($projects, function($p) use ($project) {
+		if($p->id == $project->id) return false;
+		$unix_deadline = Util::getUnixTimeFromUTC($p->dts_deadline);
+		return ($unix_deadline > time());
+	});
+
 	View::includeOnce("header", compact("page_title"));
-	View::include("test_verify_form", compact("test", "has_pdf", "tester", "location", "project", "customer", "template", "fields", "values", "tester_message"));
+	View::include("test_verify_form", compact("test", "has_pdf", "tester", "location", "project", "future_projects", "customer", "template", "fields", "values", "tester_message"));
 	View::includeOnce("footer");
 	return;
 }

+ 10 - 0
public/js/app-project.js

@@ -151,6 +151,11 @@ function initialiseLocations() {
 
 			var td = $("<td></td>");
 			td.append(a);
+
+			if(location.retest) {
+				td.append(" <span class=\"badge badge-primary\">Retest</span>");
+			}
+
 			td.append("<br />");
 
 			if(location.internalId) {
@@ -456,6 +461,11 @@ function handleAssignButtonClick(event) {
 		assignMarkers.push(marker);
 
 		$("#modal-assign-tester").find("[data-location-name]").text(location.name);
+
+		if(location.retest) {
+			$("#modal-assign-tester").find("[data-location-name]").append(" <span class=\"badge badge-primary\">Retest</span>");
+		}
+
 		$("#modal-assign-tester").find("[data-location-address]").text(location.address);
 	}
 

+ 15 - 0
views/test_verify_form.php

@@ -304,6 +304,21 @@ function render_card_list_group($details) {
 						<?php
 						if($test->status == Test::STATUS_PENDING_VERIFICATION) {
 							?>
+							<div class="row mb-1">
+								<div class="col-sm-4 col-form-label">Create Retest</div>
+								<div class="col-sm">
+									<select class="form-control" name="retest_project_id">
+										<option value="0">None</option>
+										<?php
+										foreach($future_projects as $future_project) {
+											?>
+											<option value="<?=$future_project->id?>"><?=htmlspecialchars($future_project->name)?></option>
+											<?php
+										}
+										?>
+									</select>
+								</div>
+							</div>
 							<?php
 							if($customer->email) {
 								?>