Explorar o código

Improve display of template overrides

Alan Lam %!s(int64=8) %!d(string=hai) anos
pai
achega
5a7af0782c
Modificáronse 2 ficheiros con 44 adicións e 20 borrados
  1. 16 0
      engine/template.php
  2. 28 20
      views/project_form.php

+ 16 - 0
engine/template.php

@@ -29,6 +29,22 @@ class Template extends Model {
 		return "/account/templates/" . $this->id;
 	}
 
+	public function getFields() {
+		$fields = [];
+
+		$json = json_decode($this->json);
+		$before_fields = $json->beforeTest;
+		$during_fields = $json->duringTest;
+		$all_fields = array_merge($before_fields, $during_fields);
+
+		foreach($all_fields as $field) {
+			if(empty($field->name)) continue;
+			$fields[$field->name] = $field;
+		}
+
+		return $fields;
+	}
+
 	public function setOverrides($overrides) {
 		$this->overrides = $overrides;
 	}

+ 28 - 20
views/project_form.php

@@ -196,28 +196,36 @@ $time_of_day_options = [
 		}
 		else {
 			$overrides = $project->getTemplateOverrides();
+			$fields = $template->getFields();
 			?>
-			<div class="list-group">
-			<?php
-			foreach($overrides as $override) {
-				?>
-				<div class="list-group-item">
-					<div class="row">
-						<div class="col-lg-4">
-							<strong>Field:</strong> <?=htmlspecialchars($override->field)?>
-						</div>
-						<div class="col-lg-4">
-							<strong>Element:</strong> <?=htmlspecialchars($override->element)?>
-						</div>
-						<div class="col-lg-4">
-							<strong>Value:</strong> <?=htmlspecialchars($override->value)?>
-						</div>
-					</div>
-				</div>
+			<table class="table table-bordered table-hover">
+				<thead>
+					<tr>
+						<th>Field</th>
+						<th>Element</th>
+						<th>Value</th>
+					</tr>
+				</thead>
+				<tbody>
 				<?php
-			}
-			?>
-			</div>
+				foreach($overrides as $override) {
+					?>
+					<tr>
+						<td>
+							<?=htmlspecialchars($fields[$override->field]->label)?>
+						</td>
+						<td>
+							<?=ucfirst($override->element)?>
+						</td>
+						<td>
+							<?=htmlspecialchars($override->value)?>
+						</td>
+					</tr>
+					<?php
+				}
+				?>
+				</tbody>
+			</table>
 			<?php
 		}
 		?>