Alan Lam 8 лет назад
Родитель
Сommit
b481bf2363

+ 19 - 2
Gulpfile.js

@@ -16,6 +16,15 @@ var autoprefixerOptions = {
 	"browsers": ["last 2 versions", "ie >= 9", "and_chr >= 2.3"]
 };
 
+var jsFiles = [
+	"./node_modules/bootstrap/dist/js/bootstrap.min.*",
+	"./node_modules/popper.js/dist/umd/popper.min.*",
+];
+
+gulp.task("copy-js", function() {
+	return gulp.src(jsFiles).pipe(gulp.dest("./public/js"));
+});
+
 gulp.task("sass", function() {
 	return gulp
 		.src(input)
@@ -32,8 +41,16 @@ gulp.task("watch", function() {
 	return gulp
 		.watch(input, ["sass"])
 		.on("change", function(event) {
-			console.log("File " + event.path + " was " + event.type + ", running tasks...");
+			console.log("File " + event.path + " was " + event.type + ", running 'sass' task...");
+		});
+});
+
+gulp.task("watch-js", function() {
+	return gulp
+		.watch(jsFiles, ["copy-js"])
+		.on("change", function(event) {
+			console.log("File " + event.path + " was " + event.type + ", running 'copy-js' task...");
 		});
 });
 
-gulp.task("default", ["sass", "watch"]);
+gulp.task("default", ["sass", "copy-js", "watch", "watch-js"]);

+ 101 - 11
controllers/performance.php

@@ -166,6 +166,8 @@ if($submit) {
 				break;
 		}
 
+		$same_year = ($min_year == $max_year);
+
 		// Filter tests based on date range
 		$tests = array_filter($tests, function($test) use ($min_unix, $max_unix) {
 
@@ -247,7 +249,8 @@ if($submit) {
 
 					foreach(range(1, 12) as $month) {
 
-						$label = date("M Y", mktime(0, 0, 0, $month, 1, date("Y")));
+						if(!$same_year) $label = date("M Y", mktime(0, 0, 0, $month, 1, date("Y")));
+						else $label = date("M", mktime(0, 0, 0, $month, 1, date("Y")));
 
 						$month = str_pad($month, 2, "0", STR_PAD_LEFT);
 						$key = "$year-$month";
@@ -277,7 +280,8 @@ if($submit) {
 
 					foreach(range(1, 4) as $quarter) {
 
-						$label = "Q$quarter $year";
+						if(!$same_year) $label = "Q$quarter $year";
+						else $label = "Q$quarter";
 
 						$key = "$year-$quarter";
 						$data[$key] = clone $empty_data;
@@ -345,6 +349,7 @@ if($submit) {
 
 			$stage_key = "stage" . $test->challenge_stage . "Count";
 			$data[$key]->$stage_key++;
+			$total_data->{$stage_key}++;
 
 			if($test->pass) {
 				$data[$key]->passCount++;
@@ -422,13 +427,13 @@ if($submit) {
 		$chart = new Chart;
 		$chart->setType("pie");
 		$chart->setTitle("Tests by Stage $date_range_label");
-		$chart->setLabels(["On Entry", "While Browsing", "During Play", "On Exit", "No Challenge"]);
+		$chart->setLabels(["1 - On Entry", "2 - While Browsing", "3 - During Play", "4 - On Exit", "5 - No Challenge"]);
 		$chart->addDataset("Counts", [
-			array_sum(array_column($data, "stage1Count")),
-			array_sum(array_column($data, "stage2Count")),
-			array_sum(array_column($data, "stage3Count")),
-			array_sum(array_column($data, "stage4Count")),
-			array_sum(array_column($data, "stage5Count")),
+			$total_data->stage1Count,
+			$total_data->stage2Count,
+			$total_data->stage3Count,
+			$total_data->stage4Count,
+			$total_data->stage5Count,
 		], [
 			"background_colours" => [
 				"#4CAF50",
@@ -439,6 +444,67 @@ if($submit) {
 			]
 		]);
 		$chart->setDatalabelSuffixes(" Test");
+
+		// Generate table
+		ob_start();
+		?>
+
+		<table class="table table-sm small table-bordered mt-3">
+			<thead>
+				<tr>
+					<th></th>
+					<th>Stage 1</th>
+					<th>Stage 2</th>
+					<th>Stage 3</th>
+					<th>Stage 4</th>
+					<th>Stage 5</th>
+				</tr>
+			</thead>
+			<tbody>
+			<?php
+			foreach(["value", "percent"] as $field) {
+
+				switch($field) {
+					case "value": $label = "Test Count"; break;
+					case "percent": $label = "Percentage"; break;
+				}
+
+				?>
+				<tr>
+					<td><?=htmlspecialchars($label)?></td>
+					<?php
+					foreach(range(1, 5) as $stage) {
+
+						$key = "stage{$stage}Count";
+						$count = $total_data->{$key};
+
+						switch($field) {
+							case "value":
+								$string = $count;
+								break;
+							case "percent":
+								$string = (floor(($count * 10000) / $test_count) / 100) . "%";
+								break;
+						}
+
+						?>
+						<td class="text-right"><?=$string?></td>
+						<?php
+					}
+					?>
+				</tr>
+				<?php
+
+			}
+			?>
+			</tbody>
+		</table>
+
+		<?php
+		$html = ob_get_clean();
+
+		$chart->setAfterHtml($html);
+
 		$charts[] = $chart;
 
 
@@ -510,7 +576,7 @@ if($submit) {
 		$chart->setDatalabelSuffixes("%");
 		$charts[] = $chart;
 
-		// Monthly Totals by Period
+		// Totals by Period
 
 		$test_counts = array_column($data, "testCount");
 		$pass_counts = array_column($data, "passCount");
@@ -520,7 +586,7 @@ if($submit) {
 		$chart->setType("bar");
 		$chart->setTitle("Totals by $resolution_name");
 		$chart->setLabels($x_data_labels);
-		$chart->addYAxis("linear", "left", "y-axis-1", true, ["min" => 0, "max" => ceil($test_count / 10) * 10]);
+		$chart->addYAxis("linear", "left", "y-axis-1", true, ["min" => 0, "max" => ceil(max($test_counts) / 10) * 10]);
 		$chart->addYAxis("linear", "right", "y-axis-2", false, ["min" => 0, "max" => 100]);
 
 		$chart->addDataset("Pass Rate (%)", $performance, [
@@ -536,18 +602,28 @@ if($submit) {
 			"background_colours" => "#2196F3",
 			"type" => "bar",
 			"y_axis_id" => "y-axis-1",
+			"datalabels" => [
+				"display" => false
+			],
 		]);
 		$chart->addDataset("Pass", $pass_counts, [
 			"background_colours" => "#4CAF50",
 			"type" => "bar",
 			"y_axis_id" => "y-axis-1",
+			"datalabels" => [
+				"display" => false
+			],
 		]);
 		$chart->addDataset("Fail", $fail_counts, [
 			"background_colours" => "#F44336",
 			"type" => "bar",
 			"y_axis_id" => "y-axis-1",
+			"datalabels" => [
+				"display" => false
+			],
 		]);
-		$chart->setDatalabelSuffixes(" %", " T", " P", " F");
+		$chart->setDatalabelSuffixes("%", "", "", "");
+		$chart->print = true;
 		$charts[] = $chart;
 
 		// Point of Challenge (Each Period)
@@ -696,6 +772,13 @@ if($submit) {
 			}
 
 			$chart = new Chart;
+			$chart->addXAxis([
+				"type" => "category",
+				"scale_label_config" => [
+					"display" => true,
+					"labelString" => "Area Manager",
+				]
+			]);
 			$chart->addYAxis("linear", "left", "y-axis-1", true, ["min" => 0, "max" => 100]);
 			$chart->setType("bar");
 			$chart->setTitle("Area Manager Pass Rate $date_range_label");
@@ -708,6 +791,13 @@ if($submit) {
 
 			// Area Pass Rate Period
 			$chart = new Chart;
+			$chart->addXAxis([
+				"type" => "category",
+				"scale_label_config" => [
+					"display" => true,
+					"labelString" => "Area Manager",
+				]
+			]);
 			$chart->addYAxis("linear", "left", "y-axis-1", true, ["min" => 0, "max" => 100]);
 			$chart->setType("bar");
 			$chart->setTitle("Area Manager Pass Rate by $resolution_name");

+ 1 - 1
controllers/project_kml.php

@@ -9,7 +9,7 @@ $slug = Util::slug($project->name);
 $locations = $project->getLocations();
 
 header("Content-Type: text/xml; charset=utf-8");
-//header("Content-Disposition: attachment; filename={$slug}-export.kml");
+header("Content-Disposition: attachment; filename={$slug}-export.kml");
 
 $xml = simplexml_load_file(ROOT_DIR . "/files/empty.kml");
 

+ 3 - 113
controllers/tests.php

@@ -9,127 +9,17 @@ $user = Core::$user;
 
 // Admin / Super Admin
 if($user->level >= User::LEVEL_ADMIN) {
-
-	$status = http::value("status", "int");
-	$customer_id = http::value("customer_id", "int");
-	$project_id = http::value("project_id", "int");
-	$location_id = http::value("location_id", "int");
-	$test_id = http::value("test_id", "int");
-	$location_internal_id = http::value("location_internal_id", "int");
-	$pass = http::value("pass", "int");
-	$custom = http::value("custom");
-
-	$filter_count_offset = 0;
-
-	$nvp = [];
-	if(strlen($status) > 0) $nvp["status"] = $status;
-	else {
-		$nvp["status"] = (new Constraint("NOT_EQUALS"))->setValues(Test::STATUS_CANCELLED);
-		$filter_count_offset--;
-	}
-	if($project_id) $nvp["project_id"] = $project_id;
-	else if($customer_id) {
-		$projects = Project::query(["customer_id" => $customer_id]);
-		$nvp["project_id"] = array_column($projects, "id");
-	}
-	if($location_id) $nvp["location_id"] = $location_id;
-	else if($location_internal_id) {
-		$locations = Location::query(["internal_id" => $location_internal_id]);
-		if($locations) {
-			$nvp["location_id"] = array_column($locations, "id");
-		}
-	}
-	if($test_id) $nvp["id"] = $test_id;
-	if(strlen($pass) > 0) $nvp["pass"] = $pass;
-
-	$filter_count = count($nvp);
-
-	$sort = http::value("sort");
-	switch($sort) {
-		case "updated":
-			$query_options = ["sort" => "dts_updated", "order" => "desc"];
-			break;
-		case "due":
-			$query_options = ["sort" => "dts_due", "order" => "desc"];
-			break;
-		default:
-			$sort = "status";
-			$query_options = ["sort" => "status", "order" => "asc"];
-			break;
-	}
-
-	$tests = Test::query($nvp, $query_options);
-	$projects = Project::load(array_column($tests, "project_id"));
-
-	switch($custom) {
-		case "overdue_project":
-			$tests = array_filter($tests, function($test) {
-				if($test->status == Test::STATUS_CANCELLED) return false;
-				$project = $test->getProject();
-
-				$unix_deadline = Util::getUnixTimeFromUTC($project->dts_deadline);
-
-				return ($test->status != Test::STATUS_COMPLETED && time() > $unix_deadline);
-			});
-
-			$filter_count++;
-
-			break;
-		case "overdue_test":
-			$tests = array_filter($tests, function($test) {
-				if($test->status == Test::STATUS_CANCELLED) return false;
-				if(is_null($test->dts_due)) return false;
-
-				$unix_due = Util::getUnixTimeFromUTC($test->dts_due);
-
-				return ($test->status < Test::STATUS_STARTED && time() > $unix_due);
-			});
-
-			$filter_count++;
-
-			break;
-	}
-
-	$filter_count += $filter_count_offset;
-	if(!$filter_count) $filter_count = "";
-
-	$pagination_object = Util::getPaginationObject($tests);
-	$tests = array_slice($tests, $pagination_object->offset, $pagination_object->pageSize);
-
-	$testers = User::load(array_column($tests, "tester_id"));
-	$customers = Customer::query([], ["sort" => "name"]);
-
-
-	usort($projects, function($a, $b) {
-		return $a->name <=> $b->name;
-	});
-
-	$sorts = [
-		"status" => "Status",
-		"updated" => "Update",
-		"due" => "Due",
-	];
-
-	View::includeOnce("header", compact("page_title"));
-	View::include("test_list", compact("tests", "pagination_object", "sort", "sorts", "projects", "customers", "customer_id", "project_id", "location_id", "location_internal_id", "pass", "custom", "test_id", "filter_count", "status"));
+	require "tests_admin_list.php";
 }
 
 // HQ / Venue (view completed tests)
 else if($user->level >= User::LEVEL_VENUE) {
-
-	//$testers = User::load(array_column($tests, "tester_id"));
-
-	View::includeOnce("header", compact("page_title"));
-	View::include("test_list_venue", compact("tests"));
+	require "tests_location_list.php";
 }
 
 // Tester
 else if($user->level == User::LEVEL_TESTER) {
-	$tests = $user->getPendingTests();
-	$testers = User::load(array_column($tests, "tester_id"));
-
-	View::includeOnce("header", compact("page_title"));
-	View::include("test_list_assigned", compact("tests"));
+	require "tests_tester_list.php";
 }
 
 View::includeOnce("modal_page_jump");

+ 106 - 0
controllers/tests_admin_list.php

@@ -0,0 +1,106 @@
+<?php
+
+$status = http::value("status", "int");
+$customer_id = http::value("customer_id", "int");
+$project_id = http::value("project_id", "int");
+$location_id = http::value("location_id", "int");
+$test_id = http::value("test_id", "int");
+$location_internal_id = http::value("location_internal_id", "int");
+$pass = http::value("pass", "int");
+$custom = http::value("custom");
+
+$filter_count_offset = 0;
+
+$nvp = [];
+if(strlen($status) > 0) $nvp["status"] = $status;
+else {
+	$nvp["status"] = (new Constraint("NOT_EQUALS"))->setValues(Test::STATUS_CANCELLED);
+	$filter_count_offset--;
+}
+if($project_id) $nvp["project_id"] = $project_id;
+else if($customer_id) {
+	$projects = Project::query(["customer_id" => $customer_id]);
+	$nvp["project_id"] = array_column($projects, "id");
+}
+if($location_id) $nvp["location_id"] = $location_id;
+else if($location_internal_id) {
+	$locations = Location::query(["internal_id" => $location_internal_id]);
+	if($locations) {
+		$nvp["location_id"] = array_column($locations, "id");
+	}
+}
+if($test_id) $nvp["id"] = $test_id;
+if(strlen($pass) > 0) $nvp["pass"] = $pass;
+
+$filter_count = count($nvp);
+
+$sort = http::value("sort");
+switch($sort) {
+	case "updated":
+		$query_options = ["sort" => "dts_updated", "order" => "desc"];
+		break;
+	case "due":
+		$query_options = ["sort" => "dts_due", "order" => "desc"];
+		break;
+	default:
+		$sort = "status";
+		$query_options = ["sort" => "status", "order" => "asc"];
+		break;
+}
+
+$tests = Test::query($nvp, $query_options);
+$projects = Project::load(array_column($tests, "project_id"));
+
+switch($custom) {
+	case "overdue_project":
+		$tests = array_filter($tests, function($test) {
+			if($test->status == Test::STATUS_CANCELLED) return false;
+			$project = $test->getProject();
+
+			$unix_deadline = Util::getUnixTimeFromUTC($project->dts_deadline);
+
+			return ($test->status != Test::STATUS_COMPLETED && time() > $unix_deadline);
+		});
+
+		$filter_count++;
+
+		break;
+	case "overdue_test":
+		$tests = array_filter($tests, function($test) {
+			if($test->status == Test::STATUS_CANCELLED) return false;
+			if(is_null($test->dts_due)) return false;
+
+			$unix_due = Util::getUnixTimeFromUTC($test->dts_due);
+
+			return ($test->status < Test::STATUS_STARTED && time() > $unix_due);
+		});
+
+		$filter_count++;
+
+		break;
+}
+
+$filter_count += $filter_count_offset;
+if(!$filter_count) $filter_count = "";
+
+$pagination_object = Util::getPaginationObject($tests);
+$tests = array_slice($tests, $pagination_object->offset, $pagination_object->pageSize);
+
+$testers = User::load(array_column($tests, "tester_id"));
+$customers = Customer::query([], ["sort" => "name"]);
+
+
+usort($projects, function($a, $b) {
+	return $a->name <=> $b->name;
+});
+
+$sorts = [
+	"status" => "Status",
+	"updated" => "Update",
+	"due" => "Due",
+];
+
+View::includeOnce("header", compact("page_title"));
+View::include("test_list", compact("tests", "pagination_object", "sort", "sorts", "projects", "customers", "customer_id", "project_id", "location_id", "location_internal_id", "pass", "custom", "test_id", "filter_count", "status"));
+
+?>

+ 6 - 0
controllers/tests_location_list.php

@@ -0,0 +1,6 @@
+<?php
+
+View::includeOnce("header", compact("page_title"));
+View::include("test_list_venue", compact("tests"));
+
+?>

+ 32 - 0
controllers/tests_tester_kml.php

@@ -0,0 +1,32 @@
+<?php
+
+$user = Core::$user;
+$tests = $user->getPendingTests();
+$locations = Location::load(array_column($tests, "location_id"));
+
+$dts = date("d/m/Y H:i:s");
+$dts_slug = date("Ymd-His");
+
+header("Content-Type: text/xml; charset=utf-8");
+header("Content-Disposition: attachment; filename=tests-$dts_slug.kml");
+
+$xml = simplexml_load_file(ROOT_DIR . "/files/empty.kml");
+
+$folder_node = $xml->addChild("Folder");
+$folder_node->addChild("name", "Tests");
+$folder_node->addChild("open", 1);
+$folder_node->addChild("description", "Test locations as of $dts");
+
+foreach($locations as $location) {
+	$placemark_node = $folder_node->addChild("Placemark");
+
+	$placemark_node->addChild("name", htmlspecialchars($location->name));
+	$placemark_node->addChild("description", htmlspecialchars($location->getDisplayAddress()));
+
+	$point_node = $placemark_node->addChild("Point");
+	$point_node->addChild("coordinates", $location->longitude . "," . $location->latitude);
+}
+
+echo $xml->asXML();
+
+?>

+ 71 - 0
controllers/tests_tester_list.php

@@ -0,0 +1,71 @@
+<?php
+
+Core::addScript("public/js/app-tests-tester-list.js");
+
+$tests = $user->getPendingTests();
+$locations = Location::load(array_column($tests, "location_id"));
+
+$bounds = new GeolocationBounds;
+
+foreach($tests as $test) {
+	$location = $test->getLocation();
+	$bounds->extend($location->latitude, $location->longitude);
+}
+
+$latitude = 51.3555177;
+$longitude = -1.1743197;
+
+if(HTTP::isAJAX()) {
+	JSON::header();
+
+	$action = http::value("action");
+	switch($action) {
+		case "get-tests":
+
+			$output = [];
+			foreach($tests as $test) {
+				$location = $test->getLocation();
+				$icon = null;
+
+				switch($test->status) {
+					case 2:
+						$icon = "building-orange";
+						break;
+					case 3:
+						$icon = "building-green";
+						break;
+					case 4:
+						$icon = "building-pink";
+						break;
+					case 8:
+						$icon = "building-grey";
+						break;
+				}
+
+				$output[] = (object) [
+					"status" => $test->getStatusText(),
+					"statusClass" => $test->getStatusClass(),
+					"name" => $location->name,
+					"address" => $location->getDisplayAddress(["address_1", "address_2", "city", "county", "postal_code", "state"]),
+					"icon" => $icon,
+					"geolocation" => $location->getGeolocation(),
+				];
+			}
+
+			JSON::success([
+				"tests" => $output,
+				"southWest" => $bounds->getSouthWest(),
+				"northEast" => $bounds->getNorthEast(),
+			]);
+
+			break;
+		default:
+			JSON::fail("Invalid action");
+	}
+
+}
+
+View::includeOnce("header", compact("page_title"));
+View::include("test_list_assigned", compact("tests", "latitude", "longitude"));
+
+?>

+ 106 - 3
engine/chart.php

@@ -7,14 +7,51 @@ class Chart {
 	private $type = "bar";
 	private $datasets = [];
 	private $labels = [];
+
+	private $xAxes = [];
 	private $yAxes = [];
 
 	private $datalabelSuffixes = [];
+	private $datalabelFormatterCallback = false;
+
+	public $beforeHtml = null;
+	public $afterHtml = null;
+	public $print = false;
 
 	public function __construct() {
 		$this->id = bin2hex(random_bytes(8));
 	}
 
+	public function addXAxis($options = []) {
+
+		$type = $options["type"] ?? "linear";
+		$position = $options["position"] ?? "bottom";
+		$id = $options["id"] ?? "x-axis";
+		$grid_lines = $options["grid_lines"] ?? true;
+		$tick_config = $options["tick_config"] ?? null;
+		$scale_label_config = $options["scale_label_config"] ?? null;
+
+		$axis = [
+			"type" => $type,
+			"display" => true,
+			"position" => $position,
+			"id" => $id,
+			"gridLines" => [
+				"drawOnChartArea" => $grid_lines
+			],
+		];
+
+		if($tick_config) {
+			$axis["ticks"] = $tick_config;
+		}
+
+		if($scale_label_config) {
+			$axis["scaleLabel"] = $scale_label_config;
+		}
+
+		$this->xAxes[] = $axis;
+	}
+
 	public function addYAxis($type, $position, $id, $grid_lines = true, $tick_config = []) {
 
 		$axis = [
@@ -71,7 +108,7 @@ class Chart {
 		if($type) $dataset["type"] = $type;
 		if($datalabels) $dataset["datalabels"] = $datalabels;
 
-		$this->datasets[] = $dataset;
+		$this->datasets[] = (object) $dataset;
 
 	}
 
@@ -83,6 +120,10 @@ class Chart {
 		$this->datalabelSuffixes = $suffixes;
 	}
 
+	public function setDatalabelFormatterCallback($callback) {
+		$this->datalabelFormatterCallback = $callback;
+	}
+
 	public function getJSON() {
 
 		$object = (object) [
@@ -110,20 +151,82 @@ class Chart {
 			],
 		];
 
-		if($this->yAxes) {
+		if($this->xAxes || $this->yAxes) {
 			$object->options->scales = new stdClass;
-			$object->options->scales->yAxes = $this->yAxes;
+
+			if($this->xAxes) {
+				$object->options->scales->xAxes = $this->xAxes;
+			}
+
+			if($this->yAxes) {
+				$object->options->scales->yAxes = $this->yAxes;
+			}
 		}
 
 		if($this->datalabelSuffixes) {
 			$object->options->datalabelSuffixes = $this->datalabelSuffixes;
 		}
 
+		if($this->datalabelFormatterCallback) {
+			$object->datalabelFormatterCallback = $this->datalabelFormatterCallback;
+		}
+
 
 		return json_encode($object);
 
 	}
 
+	public function printDataTable() {
+		?>
+		<table class="mt-3 w-100 table table-sm small table-bordered">
+			<thead>
+				<tr>
+					<th></th>
+					<?php
+					foreach($this->labels as $label) {
+						?>
+						<th><?=htmlspecialchars($label)?></th>
+						<?php
+					}
+					?>
+				</tr>
+			</thead>
+			<tbody>
+			<?php
+			foreach($this->datasets as $index => $dataset) {
+
+				$suffix = "";
+				if($this->datalabelSuffixes) {
+					$suffix = $this->datalabelSuffixes[$index];
+				}
+
+				?>
+				<tr>
+					<td><?=htmlspecialchars($dataset->label)?></td>
+					<?php
+					foreach($dataset->data as $value) {
+						?>
+						<td class="text-right"><?=htmlspecialchars($value)?><?=htmlspecialchars($suffix)?></td>
+						<?php
+					}
+					?>
+				</tr>
+				<?php
+			}
+			?>
+			</tbody>
+		</table>
+		<?php
+	}
+
+	public function setBeforeHtml($html) {
+		$this->beforeHtml = $html;
+	}
+
+	public function setAfterHtml($html) {
+		$this->afterHtml = $html;
+	}
+
 }
 
 ?>

+ 1 - 1
engine/core.php

@@ -29,7 +29,7 @@ class Core {
 	}
 
 	public static function addScript($path) {
-		Core::$scripts[] = $path;
+		Core::$scripts[] = $path; // Path is relative to root directory
 	}
 
 	public static function getScripts() {

+ 3 - 3
engine/form.php

@@ -80,7 +80,7 @@ class Form {
 		for($i = 0; $i <= 23; $i++) {
 			$selected = ($selected_value === $i) ? "selected" : "";
 			?>
-			<option value="<?=$i?>" <?=$selected?>><?=$i?></option>
+			<option value="<?=$i?>" <?=$selected?>><?=str_pad($i, 2, "0", STR_PAD_LEFT)?></option>
 			<?php
 		}
 	}
@@ -89,7 +89,7 @@ class Form {
 		for($i = 0; $i <= 59; $i++) {
 			$selected = ($selected_value === $i) ? "selected" : "";
 			?>
-			<option value="<?=$i?>" <?=$selected?>><?=$i?></option>
+			<option value="<?=$i?>" <?=$selected?>><?=str_pad($i, 2, "0", STR_PAD_LEFT)?></option>
 			<?php
 		}
 	}
@@ -98,7 +98,7 @@ class Form {
 		for($i = 0; $i <= 59; $i++) {
 			$selected = ($selected_value === $i) ? "selected" : "";
 			?>
-			<option value="<?=$i?>" <?=$selected?>><?=$i?></option>
+			<option value="<?=$i?>" <?=$selected?>><?=str_pad($i, 2, "0", STR_PAD_LEFT)?></option>
 			<?php
 		}
 	}

+ 44 - 0
engine/geolocation_bounds.php

@@ -0,0 +1,44 @@
+<?php
+
+class GeolocationBounds {
+
+	protected $minLat = 180;
+	protected $minLng = 180;
+	protected $maxLat = -180;
+	protected $maxLng = -180;
+
+	public function __construct() {
+	}
+
+	public function extend($lat, $lng) {
+
+		if($lat > $this->maxLat) $this->maxLat = $lat;
+		if($lng > $this->maxLng) $this->maxLng = $lng;
+
+		if($lat < $this->minLat) $this->minLat = $lat;
+		if($lng < $this->minLng) $this->minLng = $lng;
+
+	}
+
+	public function getCenter() {
+		return $this->getCentre();
+	}
+
+	public function getCentre() {
+		return [
+			($this->minLat + $this->maxLat) / 2,
+			($this->minLng + $this->maxLng) / 2,
+		];
+	}
+
+	public function getSouthWest() {
+		return [$this->minLat, $this->minLng];
+	}
+
+	public function getNorthEast() {
+		return [$this->maxLat, $this->maxLng];
+	}
+
+}
+
+?>

+ 4 - 1
engine/location.php

@@ -28,7 +28,10 @@ class Location extends Model {
 	}
 
 	public function getGeolocation() {
-		return [$this->latitude, $this->longitude];
+		return [
+			doubleval($this->latitude),
+			doubleval($this->longitude)
+		];
 	}
 
 	public function getPhotos() {

+ 29 - 29
engine/template.php

@@ -98,26 +98,8 @@ class Template extends Model {
 				<p>If you are submitting this form outside of the actual test, please use the following fields to specify when you did the test.</p>
 
 				<div class="row mb-1">
-					<label class="col-sm-4 col-form-label" for="start-override-day">Test Start</label>
+					<label class="col-sm-4 col-form-label" for="start-override-hour">Test Start</label>
 					<div class="col-sm">
-						<select class="form-control w-auto d-inline-block" name="start_override_day" id="start-override-day">
-							<option value="">Day</option>
-							<?php
-							Form::renderDayOptions(date("j"));
-							?>
-						</select>
-						<select class="form-control w-auto d-inline-block" name="start_override_month" id="start-override-month">
-							<option value="">Month</option>
-							<?php
-							Form::renderMonthOptions(date("n"));
-							?>
-						</select>
-						<select class="form-control w-auto d-inline-block" name="start_override_year" id="start-override-year">
-							<option value="">Year</option>
-							<?php
-							Form::renderYearOptionsDescending(2017, date("Y"), date("Y"));
-							?>
-						</select>
 						<select class="form-control w-auto d-inline-block" name="start_override_hour" id="start-override-hour">
 							<option value="">HH</option>
 							<?php
@@ -135,31 +117,31 @@ class Template extends Model {
 							<?php
 							Form::renderSecondOptions(0);
 							?>
-						</select>
-					</div>
-				</div>
-
-				<div class="row mb-1">
-					<label class="col-sm-4 col-form-label" for="end-override-day">Test End</label>
-					<div class="col-sm">
-						<select class="form-control w-auto d-inline-block" name="end_override_day" id="end-override-day">
+						</select><br />
+						<select class="form-control w-auto d-inline-block" name="start_override_day" id="start-override-day">
 							<option value="">Day</option>
 							<?php
 							Form::renderDayOptions(date("j"));
 							?>
 						</select>
-						<select class="form-control w-auto d-inline-block" name="end_override_month" id="end-override-month">
+						<select class="form-control w-auto d-inline-block" name="start_override_month" id="start-override-month">
 							<option value="">Month</option>
 							<?php
 							Form::renderMonthOptions(date("n"));
 							?>
 						</select>
-						<select class="form-control w-auto d-inline-block" name="end_override_year" id="end-override-year">
+						<select class="form-control w-auto d-inline-block" name="start_override_year" id="start-override-year">
 							<option value="">Year</option>
 							<?php
 							Form::renderYearOptionsDescending(2017, date("Y"), date("Y"));
 							?>
 						</select>
+					</div>
+				</div>
+
+				<div class="row mb-1">
+					<label class="col-sm-4 col-form-label" for="end-override-hour">Test End</label>
+					<div class="col-sm">
 						<select class="form-control w-auto d-inline-block" name="end_override_hour" id="end-override-hour">
 							<option value="">HH</option>
 							<?php
@@ -177,6 +159,24 @@ class Template extends Model {
 							<?php
 							Form::renderSecondOptions(0);
 							?>
+						</select><br />
+						<select class="form-control w-auto d-inline-block" name="end_override_day" id="end-override-day">
+							<option value="">Day</option>
+							<?php
+							Form::renderDayOptions(date("j"));
+							?>
+						</select>
+						<select class="form-control w-auto d-inline-block" name="end_override_month" id="end-override-month">
+							<option value="">Month</option>
+							<?php
+							Form::renderMonthOptions(date("n"));
+							?>
+						</select>
+						<select class="form-control w-auto d-inline-block" name="end_override_year" id="end-override-year">
+							<option value="">Year</option>
+							<?php
+							Form::renderYearOptionsDescending(2017, date("Y"), date("Y"));
+							?>
 						</select>
 					</div>
 				</div>

+ 2 - 2
package.json

@@ -9,12 +9,12 @@
   "author": "Alan Lam",
   "license": "ISC",
   "dependencies": {
-    "bootstrap": "^4.0.0",
+    "bootstrap": "^4.1.2",
     "chart.js": "^2.7.2",
     "clipboard": "^2.0.0",
     "holderjs": "^2.9.4",
     "jquery": "^3.3.1",
-    "popper.js": "^1.12.9"
+    "popper.js": "^1.14.3"
   },
   "devDependencies": {
     "gulp": "^3.9.1",

Разница между файлами не показана из-за своего большого размера
+ 1 - 1
public/css/bootstrap.min.css


+ 26 - 3
public/js/app-performance.js

@@ -9,13 +9,18 @@ $(function() {
 			var value = dataset.data[context.dataIndex];
 			return value;
 		};
-			console.log(object);
+
+		if(object.datalabelFormatterCallback) {
+			object.options.plugins.datalabels.formatter = window[object.datalabelFormatterCallback];
+		}
+
+
 
 		if(object.options.datalabelSuffixes) {
 			object.options.plugins.datalabels.formatter = function(value, context) {
 				let suffix = object.options.datalabelSuffixes[context.datasetIndex];
 
-				if(suffix != "%" && value != 1) {
+				if(suffix.length > 2 && value != 1) {
 					suffix += "s";
 				}
 
@@ -37,4 +42,22 @@ $(function() {
 		}
 	});
 
-});
+});
+
+function testsByStageFormatter(value, context) {
+	let dataset = context.dataset;
+	let data = dataset.data;
+	let total = data.reduce((total, value) => { return total + value; });
+	let percentage = Math.round((value * 10000) / total) / 100;
+
+	let suffix = "Test";
+	if(value != 1) {
+		suffix += "s";
+	}
+
+	let label = "Stage " + (context.dataIndex + 1) + "\n";
+	label += value + " " + suffix + "\n";
+	label += percentage + "%";
+
+	return label;
+}

+ 2 - 0
public/js/app-project-form.js

@@ -40,6 +40,8 @@ $(function() {
 		return true;
 	});
 
+	initialiseTooltips();
+
 });
 
 function handleSelectButton() {

+ 59 - 0
public/js/app-tests-tester-list.js

@@ -0,0 +1,59 @@
+$(function() {
+
+});
+
+var infoWindow = false;
+
+function initialiseMarkers() {
+
+	if(infoWindow == false) {
+		infoWindow = new google.maps.InfoWindow();
+	}
+
+
+	$.get(window.location, {
+		action: "get-tests"
+	}, function(response) {
+
+		if(!response.success) return;
+
+		let tests = response.tests;
+		let map = maps["map"];
+		let bounds = new google.maps.LatLngBounds();
+
+		for(let i in tests) {
+			let test = tests[i];
+			let latLng = {
+				lat: test.geolocation[0],
+				lng: test.geolocation[1]
+			};
+
+			bounds.extend(latLng);
+
+			let markerOptions = {
+				position: latLng,
+				map: map,
+				title: test.name
+			};
+
+			if(test.icon) {
+				markerOptions.icon = "/img/markers/" + test.icon + ".png";
+			}
+
+			let marker = new google.maps.Marker(markerOptions);
+
+			marker.addListener("click", function() {
+				infoWindow.setContent("<strong>" + test.name + "</strong> " + "<span class=\"badge badge-" + test.statusClass + "\">" + test.status + "</span>" + "<br />" +
+				"<small>" + test.address + "</small>"
+				);
+				infoWindow.open(map, marker);
+			});
+
+		}
+
+		map.fitBounds(bounds);
+
+
+
+	});
+}

Разница между файлами не показана из-за своего большого размера
+ 1 - 1
public/js/bootstrap.min.js


Разница между файлами не показана из-за своего большого размера
+ 0 - 0
public/js/bootstrap.min.js.map


Разница между файлами не показана из-за своего большого размера
+ 1 - 1
public/js/popper.min.js


Разница между файлами не показана из-за своего большого размера
+ 0 - 0
public/js/popper.min.js.map


+ 1 - 0
routes.php

@@ -70,6 +70,7 @@ $routes = [
 
 	// Tests
 	"/^account\/tests$/" => ["controller" => "tests", "require_user_level" => User::LEVEL_TESTER],
+	"/^account\/tests\/kml$/" => ["controller" => "tests_tester_kml", "require_user_level" => User::LEVEL_TESTER],
 	"/^account\/tests\/completed$/" => ["controller" => "tests_completed", "require_user_level" => User::LEVEL_TESTER],
 	"/^account\/tests\/$id_pattern$/" => ["controller" => "test", "params" => ["id"], "require_user_level" => User::LEVEL_TESTER],
 	"/^account\/tests\/$id_pattern\/(selfie)$/" => ["controller" => "test_file", "params" => ["id", "name"], "require_user_level" => User::LEVEL_TESTER],

+ 17 - 0
scss/_main.scss

@@ -106,4 +106,21 @@ input[required], select[required], textarea[required] {
 	background-image: url(/img/bg_required.png);
 	background-position: center right;
 	background-repeat: no-repeat;
+}
+
+.hover-container {
+	.visible-on-hover {
+		display: none;
+	}
+	&:hover {
+		.visible-on-hover {
+			display: initial;
+		}
+	}
+}
+
+.gm-style .gm-style-iw {
+	font-weight: initial;
+	font-size: initial;
+	line-height: 1.5;
 }

+ 13 - 0
views/performance.php

@@ -265,11 +265,24 @@ $date_range_custom_style = ($date_range == "custom") ? "" : "display: none";
 					<br />
 					<?php
 				}
+
+				if($chart->beforeHtml) {
+					echo $chart->beforeHtml;
+				}
+
 				?>
 				<a id="chart-<?=$index?>" style="display: block; position: relative; top: -7rem; visibility: hidden;"></a>
 				<canvas id="<?=$chart->getID()?>" data-chart="<?=htmlspecialchars($chart->getJSON())?>" width="400" height="300">
 				</canvas>
 				<?php
+				if($chart->print) {
+					$chart->printDataTable();
+				}
+
+				if($chart->afterHtml) {
+					echo $chart->afterHtml;
+				}
+
 			}
 			?>
 			</div>

+ 1 - 1
views/project.php

@@ -57,7 +57,7 @@ var projectID = <?=$project->id?>;
 		<div class="col-md-6">
 			<div class="card mb-3">
 				<div class="card-body">
-					Pass/Fail Ratio
+					Pass/Fail Ratio (including Unverified)
 					<div class="stat mb-3">
 						<?=number_format($pass_count)?> Pass / <?=number_format($fail_count)?> Fail (<?=intval($pass_percentage)?>%)
 					</div>

+ 8 - 6
views/project_form.php

@@ -227,16 +227,17 @@ $time_of_day_options = [
 						?>
 						<div class="list-group-item" data-location-id="<?=$location->id?>" data-internal-id="<?=htmlspecialchars($location->internal_id)?>" data-name="<?=htmlspecialchars($location->name)?>" data-filter-value="<?=htmlspecialchars($filter)?>">
 							<div class="row no-gutters">
-								<div class="col-2 text-right pr-3">
+								<div class="col-2 text-right">
 									<?=$location->id?>
 								</div>
-								<div class="col">
+								<div class="col hover-container px-3">
 									<a href="/account/locations/<?=$location->id?>" target="_blank"><?=htmlspecialchars($location->name)?></a>
+									<a class="visible-on-hover float-right" href="/account/locations/<?=$location->id?>/edit" target="_blank"><i class="fal fa-pencil"></i> Edit</a>
 									<?php
 									if($location->internal_id) {
 										?>
 										<br />
-										<small class="text-primary">Customer Internal ID: <?=htmlspecialchars($location->internal_id)?></small>
+										<small class="text-primary">Internal ID: <?=htmlspecialchars($location->internal_id)?></small>
 										<?php
 									}
 									?><br />
@@ -289,16 +290,17 @@ $time_of_day_options = [
 						?>
 						<div class="list-group-item" data-location-id="<?=$location->id?>" data-internal-id="<?=htmlspecialchars($location->internal_id)?>" data-name="<?=htmlspecialchars($location->name)?>" data-filter-value="<?=htmlspecialchars($filter)?>">
 							<div class="row no-gutters">
-								<div class="col-2 text-right pr-3">
+								<div class="col-2 text-right">
 									<?=$location->id?>
 								</div>
-								<div class="col">
+								<div class="col hover-container px-3">
 									<a href="/account/locations/<?=$location->id?>" target="_blank"><?=htmlspecialchars($location->name)?></a>
+									<a class="visible-on-hover float-right" href="/account/locations/<?=$location->id?>/edit" target="_blank"><i class="fal fa-pencil"></i> Edit</a>
 									<?php
 									if($location->internal_id) {
 										?>
 										<br />
-										<small class="text-primary">Customer Internal ID: <?=htmlspecialchars($location->internal_id)?></small>
+										<small class="text-primary">Internal ID: <?=htmlspecialchars($location->internal_id)?></small>
 										<?php
 									}
 									?>

+ 24 - 1
views/test_list_assigned.php

@@ -1,7 +1,27 @@
 <div class="container mt-3 py-4">
 
-	<h2>Your Tests</h2>
+	<div class="row">
+		<div class="col">
+			<h2>Your Tests</h2>
+		</div>
+		<?php
+		if(!empty($tests)) {
+			?>
+			<div class="col-auto">
+				<div class="dropdown">
+					<a class="btn btn-secondary dropdown-toggle" href="#" role="button" id="actions-button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
+						Actions
+					</a>
 
+					<div class="dropdown-menu" aria-labelledby="actions-button">
+						<a class="dropdown-item" href="/account/tests/kml">Export KML</a>
+					</div>
+				</div>
+			</div>
+			<?php
+		}
+		?>
+	</div>
 
 
 	<?php
@@ -15,6 +35,9 @@
 	}
 	else {
 		?>
+		<div class="mb-3" id="map" data-maps data-lat="<?=$latitude?>" data-lng="<?=$longitude?>" data-zoom="7" data-callback="initialiseMarkers" style="height: 24rem; width: 100%;">
+		</div>
+
 		<div class="list-group">
 
 		<?php

Некоторые файлы не были показаны из-за большого количества измененных файлов