Преглед изворни кода

Add export button to "Test Results" page

Alan Lam пре 2 година
родитељ
комит
e8b5928cd7
2 измењених фајлова са 24 додато и 5 уклоњено
  1. 13 4
      controllers/project_export.php
  2. 11 1
      views/test_results_test_list.php

+ 13 - 4
controllers/project_export.php

@@ -11,7 +11,9 @@ else {
 }
 }
 
 
 $projects = Project::query(["id" => $ids]);
 $projects = Project::query(["id" => $ids]);
-if(!$projects) throw new Exception("No projects to export.");
+if(!$projects) {
+	throw new RuntimeException("No projects to export.");
+}
 
 
 $template_processing = false;
 $template_processing = false;
 
 
@@ -25,10 +27,14 @@ switch($type) {
 if($template_processing) {
 if($template_processing) {
 	$template_ids = array_column($projects, "template_id");
 	$template_ids = array_column($projects, "template_id");
 	$template_ids = array_unique($template_ids);
 	$template_ids = array_unique($template_ids);
-	if(count($template_ids) != 1) throw new Exception("Cannot create export with different templates.");
+	if(count($template_ids) !== 1) {
+		throw new RuntimeException("Cannot create export with different templates.");
+	}
 
 
 	$template = Template::get($template_ids[0]);
 	$template = Template::get($template_ids[0]);
-	if(!$template) throw new Exception("Template cannot be found.");
+	if(!$template) {
+		throw new RuntimeException("Template cannot be found.");
+	}
 }
 }
 
 
 $tests = Test::query([
 $tests = Test::query([
@@ -39,7 +45,10 @@ $tests = Test::query([
 switch($type) {
 switch($type) {
 
 
 	case "admin":
 	case "admin":
-		if(!$user->canExportProjectCsv()) throw new Exception("You do not have permission to perform this action.");
+		if(!$user->canExportProjectCsv()) {
+			throw new RuntimeException("You do not have permission to perform this action.");
+		}
+
 		$template->exportTestsCSV("project_csv.php", $tests);
 		$template->exportTestsCSV("project_csv.php", $tests);
 		break;
 		break;
 
 

+ 11 - 1
views/test_results_test_list.php

@@ -1,11 +1,21 @@
 <?php
 <?php
 /**
 /**
+ * @var Project $project
  * @var Test[] $tests
  * @var Test[] $tests
  */
  */
 ?>
 ?>
 <div class="container mt-3 py-4">
 <div class="container mt-3 py-4">
 
 
-    <h2><?=htmlspecialchars(__("%s Test Results", $project->name))?></h2>
+	<div class="row">
+		<div class="col">
+			<h2><?=htmlspecialchars(__("%s Test Results", $project->name))?></h2>
+		</div>
+		<div class="col-auto text-right">
+			<a href="/account/projects/export-csv?ids=<?=$project->id?>&amp;type=customer" class="btn btn-primary" target="_blank">
+				<?=htmlspecialchars(__("Export CSV"))?>
+			</a>
+		</div>
+	</div>
 
 
     <?php
     <?php