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

Add "Do Not Test" field for locations

Alan Lam пре 7 година
родитељ
комит
117f2f1e9e

+ 1 - 0
controllers/location_edit.php

@@ -41,6 +41,7 @@ if($submit) {
 		$location->area_manager = http::value("area_manager", "trim");
 		$location->area_manager_email = http::value("area_manager_email", "email");
 
+		$location->do_not_test = http::value("do_not_test", "int") ? 1 : 0;
 		$location->closed = http::value("closed", "int") ? 1 : 0;
 
 		if(empty($location->name)) $form_exception->addError("Name is required.");

+ 3 - 1
controllers/map_overview_ajax.php

@@ -123,6 +123,8 @@ if($submit) {
 						"longitude" => (float) $location->longitude,
 						"icon" => $icon,
 						"test" => null,
+						"doNotTest" => (bool) $location->do_not_test,
+						"closed" => (bool) $location->closed,
 					];
 
 					if($test) {
@@ -250,4 +252,4 @@ if($submit) {
 
 JSON::fail("Invalid request.");
 
-?>
+?>

+ 2 - 1
engine/location.php

@@ -25,6 +25,7 @@
  * @property string $area_manager_name
  * @property string $area_manager_email
  * @property string $operations_manager_name
+ * @property bool $do_not_test
  * @property bool $closed
  * @property double $latitude
  * @property double $longitude
@@ -35,7 +36,7 @@ class Location extends Model {
 
 	protected static $table = "location";
 	protected static $id_field = "id";
-	protected static $fillable_fields = ["customer_id", "name", "legal_entity_name", "address_1", "address_2", "city", "county", "postal_code", "state", "country", "email", "phone", "opening_hours", "shop_left", "shop_right", "brand", "region", "region_name", "internal_id", "area_manager", "area_manager_name", "area_manager_email", "operations_manager_name", "closed", "latitude", "longitude", "dts_verified"];
+	protected static $fillable_fields = ["customer_id", "name", "legal_entity_name", "address_1", "address_2", "city", "county", "postal_code", "state", "country", "email", "phone", "opening_hours", "shop_left", "shop_right", "brand", "region", "region_name", "internal_id", "area_manager", "area_manager_name", "area_manager_email", "operations_manager_name", "do_not_test", "closed", "latitude", "longitude", "dts_verified"];
 
 	// Object methods
 

BIN
public/img/markers/closed.png


BIN
public/img/markers/do_not_test.png


+ 98 - 51
public/js/app-map-overview.js

@@ -3,6 +3,7 @@ var infoWindow = false;
 
 $(function() {
 
+	// On customer select
 	$("a[data-customer-id]").click(function(event) {
 		let customerId = $(this).data("customer-id");
 
@@ -26,6 +27,7 @@ $(function() {
 		return false;
 	});
 
+	// On project select
 	$("a[data-project-id]").click(function(event) {
 		let projectId = $(this).data("project-id");
 
@@ -49,6 +51,7 @@ $(function() {
 		return false;
 	});
 
+	// On all addresses select
 	$("a[data-all-addresses]").click(function(event) {
 
 		let key = "all-addresses";
@@ -75,13 +78,21 @@ $(function() {
 
 function loadCustomerLocations(customerId) {
 
-	if(infoWindow == false) {
+	if(infoWindow === false) {
 		infoWindow = new google.maps.InfoWindow();
 	}
 
 	let minDate = $("#min-date").val();
 	let maxDate = $("#max-date").val();
 
+	let $customerItem = $("a[data-customer-id=" + customerId + "]");
+
+	/**
+	 * @property {Object} response
+	 * @property {Array} response.locations
+	 * @property {Boolean} response.success
+	 */
+
 	$.get("/account/map-overview/get-customer-locations", {
 		customer_id: customerId,
 		min_date: minDate,
@@ -95,32 +106,36 @@ function loadCustomerLocations(customerId) {
 
 		markerGroups[key] = [];
 
-		for(let i in response.locations) {
-			let l = response.locations[i];
+		let count = response.locations.length;
+
+		for(let i = 0; i < count; ++i) {
+			let location = response.locations[i];
 
 			let position = {
-				lat: l.latitude,
-				lng: l.longitude
+				lat: location.latitude,
+				lng: location.longitude
 			};
 
 			var options = {
 				position: position,
-				title: l.name,
+				title: location.name,
 				map: map
 			};
 
-			if(l.icon) options.icon = "/img/markers/" + l.icon;
+			if(location.icon) options.icon = "/img/markers/" + location.icon;
+			if(location.doNotTest) options.icon = "/img/markers/do_not_test.png";
+			if(location.closed) options.icon = "/img/markers/closed.png";
 
 			infoWindow.setContent("");
 
 			let marker = new google.maps.Marker(options);
-			addMarkerClickListenerForLocation(marker, l);
+			addMarkerClickListenerForLocation(marker, location);
 
 			markerGroups[key].push(marker);
 		}
 
-		$("a[data-customer-id=" + customerId + "]").data("selected", true);
-		$("a[data-customer-id=" + customerId + "]").find(".badge").addClass("badge-danger").text(response.locations.length);
+		$customerItem.data("selected", true);
+		$customerItem.find(".badge").addClass("badge-danger").text(response.locations.length);
 
 	});
 
@@ -128,13 +143,21 @@ function loadCustomerLocations(customerId) {
 
 function loadProjectLocations(projectId) {
 
-	if(infoWindow == false) {
+	if(infoWindow === false) {
 		infoWindow = new google.maps.InfoWindow();
 	}
 
 	let minDate = $("#min-date").val();
 	let maxDate = $("#max-date").val();
 
+	let $projectItem = $("a[data-project-id=" + projectId + "]");
+
+	/**
+	 * @property {Object} response
+	 * @property {Array} response.locations
+	 * @property {Boolean} response.success
+	 */
+
 	$.get("/account/map-overview/get-project-locations", {
 		project_id: projectId,
 		min_date: minDate,
@@ -148,42 +171,55 @@ function loadProjectLocations(projectId) {
 
 		markerGroups[key] = [];
 
-		for(let i in response.locations) {
+		let count = response.locations.length;
+
+		for(let i = 0; i < count; ++i) {
 
-			let l = response.locations[i];
+			let location = response.locations[i];
 
 			let position = {
-				lat: l.latitude,
-				lng: l.longitude
+				lat: location.latitude,
+				lng: location.longitude
 			};
 
 			var options = {
 				position: position,
-				title: l.name,
+				title: location.name,
 				map: map
 			};
 
-			if(l.icon) options.icon = "/img/markers/" + l.icon;
+			if(location.icon) options.icon = "/img/markers/" + location.icon;
+			if(location.doNotTest) options.icon = "/img/markers/do_not_test.png";
+			if(location.closed) options.icon = "/img/markers/closed.png";
+
 
 			let marker = new google.maps.Marker(options);
-			addMarkerClickListenerForLocation(marker, l);
+			addMarkerClickListenerForLocation(marker, location);
 
 			markerGroups[key].push(marker);
 
 		}
 
-		$("a[data-project-id=" + projectId + "]").data("selected", true);
-		$("a[data-project-id=" + projectId + "]").find(".badge").addClass("badge-danger").text(response.locations.length);
+		$projectItem.data("selected", true);
+		$projectItem.find(".badge").addClass("badge-danger").text(response.locations.length);
 
 	});
 }
 
 function loadAllAddresses() {
 
-	if(infoWindow == false) {
+	if(infoWindow === false) {
 		infoWindow = new google.maps.InfoWindow();
 	}
 
+	/**
+	 * @property {Object} response
+	 * @property {Array} response.addresses
+	 * @property {Boolean} response.success
+	 */
+
+	let $allAddresses = $("a[data-all-addresses]");
+
 	$.get("/api/addresses/get-all", {
 		submit: $("#submit").val()
 	}, function(response) {
@@ -194,82 +230,93 @@ function loadAllAddresses() {
 
 		markerGroups[key] = [];
 
-		for(let i in response.addresses) {
+		let addressCount = response.addresses.length;
+
+		for(let i = 0; i < addressCount; ++i) {
 
-			let a = response.addresses[i];
+			let address = response.addresses[i];
 
 			let position = {
-				lat: a.latitude,
-				lng: a.longitude
+				lat: address.latitude,
+				lng: address.longitude
 			};
 
 			var options = {
 				position: position,
-				title: a.name,
+				title: address.name,
 				map: map
 			};
 
 			let marker = new google.maps.Marker(options);
-			addMarkerClickListenerForAddress(marker, a);
+			addMarkerClickListenerForAddress(marker, address);
 
 			markerGroups[key].push(marker);
 
 		}
 
-		$("a[data-all-addresses]").data("selected", true);
-		$("a[data-all-addresses]").find(".badge").addClass("badge-danger").text(response.addresses.length);
+		$allAddresses.data("selected", true);
+		$allAddresses.find(".badge").addClass("badge-danger").text(response.addresses.length);
 
 	});
 }
 
-function addMarkerClickListenerForLocation(m, l) {
+function addMarkerClickListenerForLocation(marker, location) {
 	let map = maps["map"];
-	m.addListener("click", function() {
-		let content = "<strong><a href=\"/account/locations/" + l.id + "\" target=\"_blank\">" + l.name + "</a></strong><br />";
-		if(l.internalId) {
-			content += "<div class=\"small\"><strong>Internal ID:</strong> " + l.internalId + "</div>";
+	marker.addListener("click", function() {
+		let content = "<div><strong><a href=\"/account/locations/" + location.id + "\" target=\"_blank\">" + location.name + "</a></strong></div>";
+
+		if(location.doNotTest) {
+			content += "<span class=\"badge badge-warning\">Do Not Test</span>";
+		}
+
+		if(location.closed) {
+			content += "<span class=\"badge badge-danger\">Closed</span>";
+		}
+
+		if(location.internalId) {
+			content += "<div class=\"small\"><strong>Internal ID:</strong> " + location.internalId + "</div>";
 		}
-		content += "<div class=\"small\"><strong>Location ID:</strong> " + l.id + "</div>";
+		content += "<div class=\"small\"><strong>Location ID:</strong> " + location.id + "</div>";
 
-		if(l.test) {
+		if(location.test) {
 
 			content += '<hr />';
 
-			content += '<div class="small"><strong>Test ID:</strong> <a href="/account/tests/' + l.test.id + '" target="_blank">' + l.test.id + '</a></div>';
+			content += '<div class="small"><strong>Test ID:</strong> <a href="/account/tests/' + location.test.id + '" target="_blank">' + location.test.id + '</a></div>';
 
-			if(l.test.formattedStartDts) {
-				content += '<div class="small"><strong>Date/Time:</strong> ' + l.test.formattedStartDts + '</div>';
+			if(location.test.formattedStartDts) {
+				content += '<div class="small"><strong>Date/Time:</strong> ' + location.test.formattedStartDts + '</div>';
 			}
 
-			if(l.test.tester) {
-				content += '<div class="small"><strong>Tester ID:</strong> ' + l.test.tester.id + '</div>';
-				content += '<div class="small"><strong>Tester Name:</strong> <a href="/account/users/' + l.test.tester.id + '" target="_blank">' + l.test.tester.name + '</a></div>';
+			if(location.test.tester) {
+				content += '<div class="small"><strong>Tester ID:</strong> ' + location.test.tester.id + '</div>';
+				content += '<div class="small"><strong>Tester Name:</strong> <a href="/account/users/' + location.test.tester.id + '" target="_blank">' + location.test.tester.name + '</a></div>';
 			}
 
 			let pastDueBadge = '';
-			if(l.test.pastDue) {
+			if(location.test.pastDue) {
 				pastDueBadge = '<span class="badge badge-lg badge-primary">Past Due</span>';
 			}
 
-			if(l.test.formattedDueDts) {
-				content += '<div class="small"><strong>Due:</strong> ' + l.test.formattedDueDts + ' ' + pastDueBadge + '</div>';
+			if(location.test.formattedDueDts) {
+				content += '<div class="small"><strong>Due:</strong> ' + location.test.formattedDueDts + ' ' + pastDueBadge + '</div>';
 			}
 
 		}
 
 
 		infoWindow.setContent(content);
-		infoWindow.open(map, m);
+		infoWindow.open(map, marker);
 	});
 }
 
-function addMarkerClickListenerForAddress(m, a) {
+function addMarkerClickListenerForAddress(marker, address) {
 	let map = maps["map"];
-	m.addListener("click", function() {
-		let content = "<strong><a href=\"/account/users/" + a.userId + "\" target=\"_blank\">" + a.name + "</a></strong><br />";
-		content += "ID: " + a.userId + "<br />";
+	marker.addListener("click", function() {
+		let content = "<strong><a href=\"/account/users/" + address.userId + "\" target=\"_blank\">" + address.name + "</a></strong><br />";
+		content += "ID: " + address.userId + "<br />";
 
 		infoWindow.setContent(content);
-		infoWindow.open(map, m);
+		infoWindow.open(map, marker);
 	});
 }

+ 9 - 0
views/location_form.php

@@ -119,6 +119,15 @@ if($location->id) {
 							</div>
 						</div>
 
+                        <div class="row mb-1">
+                            <div class="col-sm offset-sm-4">
+                                <div class="form-check">
+                                    <input class="form-check-input" type="checkbox" name="do_not_test" id="do-not-test" value="1" <?=Form::checked($location->do_not_test)?> />
+                                    <label for="do-not-test">Do Not Test</label>
+                                </div>
+                            </div>
+                        </div>
+
 						<div class="row mb-1">
 							<div class="col-sm offset-sm-4">
 								<div class="form-check">