소스 검색

Add support to batch unassign tests

Alan Lam 8 년 전
부모
커밋
54a13ed829
3개의 변경된 파일과 159개의 추가작업 그리고 82개의 파일을 삭제
  1. 39 0
      controllers/tests_admin_list.php
  2. 9 0
      engine/test.php
  3. 111 82
      views/test_list.php

+ 39 - 0
controllers/tests_admin_list.php

@@ -1,5 +1,44 @@
 <?php
 
+// Batch Action
+$submit = http::value("submit");
+if($submit) {
+	try {
+		Core::validateCSRFToken($submit);
+
+		$test_ids = http::value("test_ids", "int");
+		$batch_action = http::value("batch_action");
+
+		$tests = Test::load($test_ids);
+		$test_count = count($tests);
+
+		switch($batch_action) {
+			case "unassign":
+
+				$test_unassigned_count = 0;
+
+				foreach($tests as $test) {
+					$success = $test->unassignTester();
+					$test_unassigned_count += $success;
+				}
+
+				Core::addAlert("success", "$test_unassigned_count of $test_count test(s) unassigned successfully.");
+
+				break;
+			default:
+				throw new Exception("Invalid action.");
+		}
+
+		HTTP::redirect($_SERVER["REQUEST_URI"]);
+
+
+	}
+	catch(Exception $e) {
+		Core::addAlert("danger", $e->getMessage());
+	}
+}
+// Batch Action End
+
 $status = http::value("status", "int");
 $customer_id = http::value("customer_id", "int");
 $project_id = http::value("project_id", "int");

+ 9 - 0
engine/test.php

@@ -326,6 +326,15 @@ class Test extends Model {
 
 	}
 
+	public function unassignTester() {
+		$this->tester_id = null;
+		$this->dts_due = null;
+		$this->dts_assigned = null;
+		$success = $this->commit();
+
+		return $success;
+	}
+
 }
 
 ?>

+ 111 - 82
views/test_list.php

@@ -219,99 +219,128 @@ $custom_filters = [
 			?>
 		</div>
 
-		<div class="table-responsive mb-3">
+		<form method="post">
 
-			<table class="table table-sm table-hover" style="min-width: 1024px;">
-				<thead>
-					<th>ID</th>
-					<th>Location</th>
-					<th>Project</th>
-					<th>Tester</th>
-					<th>Due Date</th>
-					<th>Status</th>
-					<th>Result</th>
-					<th></th>
-				</thead>
-				<tbody>
-				<?php
+			<div class="table-responsive mb-3">
 
-				foreach($tests as $test) {
-					$location = $test->getLocation();
-					$project = $test->getProject();
-					$tester = $test->getTester();
+				<table class="table table-sm table-hover" style="min-width: 1024px;">
+					<thead>
+						<th></th>
+						<th>ID</th>
+						<th>Location</th>
+						<th>Project</th>
+						<th>Tester</th>
+						<th>Due Date</th>
+						<th>Status</th>
+						<th>Result</th>
+						<th></th>
+					</thead>
+					<tbody>
+					<?php
 
-					$unix_start = strtotime($test->dts_start . " UTC");
-					$unix_end = strtotime($test->dts_end . " UTC");
+					foreach($tests as $test) {
+						$location = $test->getLocation();
+						$project = $test->getProject();
+						$tester = $test->getTester();
 
-					?>
+						$unix_start = strtotime($test->dts_start . " UTC");
+						$unix_end = strtotime($test->dts_end . " UTC");
 
-					<tr>
-						<td>
-							<?=$test->id?>
-						</td>
-						<td class="align-middle">
-							<a href="/account/locations/<?=$location->id?>">
-								<?=htmlspecialchars($location->name)?>
-								<?php
-								if($location->internal_id) {
-									?>
-									<small>(Internal ID: <?=htmlspecialchars($location->internal_id)?>)</small>
+						?>
+
+						<tr>
+							<td>
+								<input type="checkbox" name="test_ids[]" value="<?=$test->id?>" />
+							</td>
+							<td>
+								<?=$test->id?>
+							</td>
+							<td class="align-middle">
+								<a href="/account/locations/<?=$location->id?>">
+									<?=htmlspecialchars($location->name)?>
 									<?php
-								}
+									if($location->internal_id) {
+										?>
+										<small>(Internal ID: <?=htmlspecialchars($location->internal_id)?>)</small>
+										<?php
+									}
+									?>
+								</a><br />
+								<small><?=htmlspecialchars($location->getDisplayAddress(["address_1", "address_2", "city"]))?></small>
+							</td>
+							<td class="align-middle">
+								<a href="/account/projects/<?=$project->id?>"><?=htmlspecialchars($project->name)?></a><br />
+								<small><strong>Deadline:</strong> <?=date("d/m/Y", strtotime($project->dts_deadline . " UTC"))?><small>
+							</td>
+							<td class="align-middle">
+							<?php
+							if($tester) {
 								?>
-							</a><br />
-							<small><?=htmlspecialchars($location->getDisplayAddress(["address_1", "address_2", "city"]))?></small>
-						</td>
-						<td class="align-middle">
-							<a href="/account/projects/<?=$project->id?>"><?=htmlspecialchars($project->name)?></a><br />
-							<small><strong>Deadline:</strong> <?=date("d/m/Y", strtotime($project->dts_deadline . " UTC"))?><small>
-						</td>
-						<td class="align-middle">
-						<?php
-						if($tester) {
+								<a href="/account/users/<?=$tester->id?>"><?=htmlspecialchars($tester->getDisplayName())?></a>
+								<?php
+							}
+							else {
+								?>
+								<small class="text-muted">N/A</small>
+								<?php
+							}
 							?>
-							<a href="/account/users/<?=$tester->id?>"><?=htmlspecialchars($tester->getDisplayName())?></a>
+							</td>
+							<td class="text-center align-middle">
 							<?php
-						}
-						else {
+							if(is_null($test->dts_due)) {
+								?>
+								<small class="text-muted">N/A</small>
+								<?php
+							}
+							else {
+								?>
+								<?=explode(" ", $test->dts_due)[0]?>
+								<?php
+							}
 							?>
-							<small class="text-muted">N/A</small>
-							<?php
-						}
-						?>
-						</td>
-						<td class="text-center align-middle">
+							</td>
+							<td class="text-center align-middle">
+								<span class="badge badge-<?=$test->getStatusClass()?>"><?=$test->getStatusText()?></span>
+							</td>
+							<td class="text-center align-middle text-<?=$test->getPassClass()?>">
+								<div data-toggle="tooltip" title="<?=$test->getPassText()?>">
+									<i class="fas fa-2x fa-fw fa-<?=$test->getPassIcon()?>"></i>
+								</div>
+							</td>
+							<td class="text-right align-middle">
+								<a class="btn btn-outline-primary" href="/account/tests/<?=$test->id?>">View</a>
+							</td>
+						</tr>
 						<?php
-						if(is_null($test->dts_due)) {
-							?>
-							<small class="text-muted">N/A</small>
-							<?php
-						}
-						else {
-							?>
-							<?=explode(" ", $test->dts_due)[0]?>
-							<?php
-						}
-						?>
-						</td>
-						<td class="text-center align-middle">
-							<span class="badge badge-<?=$test->getStatusClass()?>"><?=$test->getStatusText()?></span>
-						</td>
-						<td class="text-center align-middle text-<?=$test->getPassClass()?>">
-							<div data-toggle="tooltip" title="<?=$test->getPassText()?>">
-								<i class="fas fa-2x fa-fw fa-<?=$test->getPassIcon()?>"></i>
-							</div>
-						</td>
-						<td class="text-right align-middle">
-							<a class="btn btn-outline-primary" href="/account/tests/<?=$test->id?>">View</a>
-						</td>
-					</tr>
-					<?php
-				}
-				?>
-				</tbody>
-			</table>
-		</div>
+					}
+					?>
+					</tbody>
+				</table>
+			</div>
+
+			<div class="row">
+				<div class="col-md-6 offset-md-6">
+					<div class="input-group">
+						<div class="input-group-prepend">
+							<span class="input-group-text">
+								Batch Action
+							</span>
+						</div>
+						<select class="form-control" name="batch_action" required>
+							<option value="">Select Action</option>
+							<option value="unassign">Unassign</option>
+						</select>
+						<div class="input-group-append">
+							<button type="submit" class="btn btn-primary" name="submit" value="<?=htmlspecialchars($_SESSION["csrf_token"])?>">
+								Submit
+							</button>
+						</div>
+					</div>
+				</div>
+			</div>
+
+		</form>
 
 		<div class="mt-3">
 			<?php