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

Use test IDs when moving tests instead of location IDs

Alan Lam 2 лет назад
Родитель
Сommit
6d57d1b649
4 измененных файлов с 32 добавлено и 45 удалено
  1. 12 7
      controllers/project.php
  2. 15 33
      controllers/project_ajax.php
  3. 4 4
      public/js/app-project.js
  4. 1 1
      views/project.php

+ 12 - 7
controllers/project.php

@@ -26,15 +26,15 @@ Core::addScript("public/js/markerclusterer.js");
 
 $action = http::value("action", "string");
 $target_project_id = http::value("target_project_id");
-$location_ids_json = http::value("location_ids_json", "string");
+$test_ids_json = http::value("test_ids_json", "string");
 
 if($action) {
 	switch($action) {
 		case "move-tests":
 
-			$location_ids = json_decode($location_ids_json);
-			if(!is_array($location_ids)) {
-				$location_ids = [];
+			$test_ids = json_decode($test_ids_json);
+			if(!is_array($test_ids)) {
+				$test_ids = [];
 			}
 
 			$target_project = Project::get($target_project_id);
@@ -46,16 +46,21 @@ if($action) {
 				throw new RuntimeException("Target project template is not the same as this project.");
 			}
 
-			$source_tests = Test::query(["location_id" => $location_ids, "project_id" => $id]);
+			$source_tests = Test::query(["id" => $test_ids, "project_id" => $id, "status" => Constraint::notEquals(Test::STATUS_CANCELLED)]);
 
 			$source_test_count = count($source_tests);
-			$expected_test_count = count($location_ids);
+			$expected_test_count = count($test_ids);
 
 			if($source_test_count !== $expected_test_count) {
 				throw new RuntimeException("Tests do not match number of IDs submitted. $source_test_count $expected_test_count");
 			}
 
-			$conflicting_tests = Test::query(["location_id" => $location_ids, "project_id" => $target_project_id]);
+			$location_ids = [];
+			foreach($source_tests as $source_test) {
+				$location_ids[] = $source_test->location_id;
+			}
+
+			$conflicting_tests = Test::query(["location_id" => $location_ids, "project_id" => $target_project_id, "status" => Constraint::notEquals(Test::STATUS_CANCELLED)]);
 			$conflicting_test_count = count($conflicting_tests);
 			if($conflicting_test_count > 0) {
 				throw new RuntimeException(__("%d conflicting test(s) for a location was found in the target project. Please remove from the target project and try again.", $conflicting_test_count));

+ 15 - 33
controllers/project_ajax.php

@@ -35,44 +35,26 @@ if($submit) {
 				$location_tests = [];
 
 				foreach($tests as $test) {
-					if($test->status == Test::STATUS_CANCELLED) continue;
 					$location_tests[$test->location_id] = $test;
 				}
 
 				$output = [];
 
-				foreach($locations as $location) {
-
-					$test = $location_tests[$location->id] ?? false;
-
-					$test_id = null;
-					$tester_id = null;
-					$status = 0;
-					$status_text = "";
-
-					$pass = 0;
-					$pass_class = "";
-					$pass_text = "";
-					$pass_icon = "";
-
-					$retest = false;
-					$paid = true;
-
-					$class = "secondary";
-					if($test) {
-						$test_id = (int) $test->id;
-						$tester_id = (int) $test->tester_id;
-						$class = $test->getStatusClass();
-						$status = $test->status;
-						$status_text = $test->getStatusText();
-						$pass = (int) $test->pass;
-						$pass_class = $test->getPassClass();
-						$pass_text = $test->getPassText();
-						$pass_icon = $test->getPassIcon();
-						$retest = (bool) $test->retest;
-						$payment_required = (bool) $test->payment_required;
-						$paid = (bool) $test->dts_paid;
-					}
+				foreach($location_tests as $test) {
+					$location = $test->getLocation();
+
+					$test_id = (int) $test->id;
+					$tester_id = (int) $test->tester_id;
+					$class = $test->getStatusClass();
+					$status = $test->status;
+					$status_text = $test->getStatusText();
+					$pass = (int) $test->pass;
+					$pass_class = $test->getPassClass();
+					$pass_text = $test->getPassText();
+					$pass_icon = $test->getPassIcon();
+					$retest = (bool) $test->retest;
+					$payment_required = (bool) $test->payment_required;
+					$paid = (bool) $test->dts_paid;
 
 					$output[] = (object) [
 						"id" => (int) $location->id,

+ 4 - 4
public/js/app-project.js

@@ -86,12 +86,12 @@ $(function() {
 		}, 1000);
 	}
 
-	$(document).on("change", ".location-checkbox", event => {
-		const locationIds = $(document).find(".location-checkbox:checked").map((index, element) => {
+	$(document).on("change", ".test-checkbox", event => {
+		const testIds = $(document).find(".test-checkbox:checked").map((index, element) => {
 			return element.value;
 		}).get();
 
-		$("input[name=location_ids_json]").val(JSON.stringify(locationIds));
+		$("input[name=test_ids_json]").val(JSON.stringify(testIds));
 
 	});
 
@@ -185,7 +185,7 @@ function initialiseLocations() {
 			// Populate table
 			var tr = $("<tr data-location-id=\"" + location.id + "\" data-internal-id=\"" + location.internalId + "\" data-tester-id=\"" + location.testerId + "\" data-latitude=\"" + location.latitude + "\" data-longitude=\"" + location.longitude + "\" data-filter-value=\"" + filterValue + "\"></tr>");
 
-			const $checkboxCell = $(`<td class="text-center"><input class="location-checkbox" type="checkbox" value="${location.id}" /></td>`);
+			const $checkboxCell = $(`<td class="text-center"><input class="test-checkbox" type="checkbox" value="${location.testId}" /></td>`);
 			tr.append($checkboxCell);
 
 			var locationIdTd = $("<td class=\"text-right\"></td>");

+ 1 - 1
views/project.php

@@ -298,7 +298,7 @@ if($auto_select_location_id) {
 								</select>
 							</div>
 
-							<input type="hidden" name="location_ids_json" value="" />
+							<input type="hidden" name="test_ids_json" value="" />
 
 							<button type="submit" class="btn btn-primary">
 								<?=htmlspecialchars(__("Submit"))?>