Просмотр исходного кода

Add map column to locations table

Alan Lam 3 лет назад
Родитель
Сommit
fc8f85690d
2 измененных файлов с 30 добавлено и 3 удалено
  1. 10 0
      public/js/map.js
  2. 20 3
      views/locations_table.php

+ 10 - 0
public/js/map.js

@@ -15,6 +15,16 @@ class Map {
 
 		this.$table = $("#customers-table");
 
+		const $icons = $(".lat-lng-icon");
+		$icons.on("click", event => {
+			const { latitude, longitude } = event.currentTarget.dataset;
+			this.map.setCenter({
+				lat: parseFloat(latitude),
+				lng: parseFloat(longitude)
+			});
+			this.map.setZoom(15);
+		});
+
 		const $checkboxes = this.$table.find("tbody input[type=checkbox]");
 		const $rows = this.$table.find("tbody tr");
 		$rows.on("click", event => {

+ 20 - 3
views/locations_table.php

@@ -12,8 +12,9 @@ namespace App;
 		<col style="width: 1%"/>
 		<col style="width: 20%"/>
 		<col style="width: 20%"/>
-		<col style="width: 40%"/>
-		<col style="width: 20%"/>
+		<col style="width: 50%"/>
+		<col style="width: 10%"/>
+		<col style="width: 1%"/>
 	</colgroup>
 	<thead>
 	<tr>
@@ -21,6 +22,7 @@ namespace App;
 		<th><?=htmlspecialchars(__("Customer"))?></th>
 		<th><?=htmlspecialchars(__("Name"))?></th>
 		<th><?=htmlspecialchars(__("Address"))?></th>
+		<th><?=htmlspecialchars(__("Map"))?></th>
 		<th><?=htmlspecialchars(__("Actions"))?></th>
 	</tr>
 	</thead>
@@ -28,6 +30,7 @@ namespace App;
 	<?php
 	foreach($locations as $location) {
 		$customer = $location->getCustomer();
+		$address = $location->getAddress();
 		?>
 		<tr>
 			<td class="text-end"><?=$location->id?></td>
@@ -40,7 +43,21 @@ namespace App;
 				<?=htmlspecialchars($location->name)?>
 			</td>
 			<td>
-				<?=htmlspecialchars(implode(", ", $location->getAddress()->getLines()))?>
+				<?=htmlspecialchars(implode(", ", $address->getLines()))?>
+			</td>
+			<td>
+				<?php
+				if($address->hasGeolocation()) {
+					?>
+					<i class="fa fa-fw fa-check text-success lat-lng-icon" data-latitude="<?=$address->latitude?>" data-longitude="<?=$address->longitude?>" style="cursor: pointer"></i>
+					<?php
+				}
+				else {
+					?>
+					<i class="fa fa-fw fa-times text-danger"></i>
+					<?php
+				}
+				?>
 			</td>
 			<td class="p-1">
 				<a class="btn btn-sm btn-primary" href="<?=htmlspecialchars($location->getUrl())?>">