Add Latitude and Longitude to Monitors and monitor edit as well as using the geolocation api to auto-populate them

This commit is contained in:
Isaac Connor 2020-09-24 09:01:30 -04:00
parent f7ec83323d
commit 624bcdcde0
6 changed files with 81 additions and 0 deletions

View File

@ -536,6 +536,8 @@ CREATE TABLE `Monitors` (
`ArchivedEventDiskSpace` bigint default NULL, `ArchivedEventDiskSpace` bigint default NULL,
`ZoneCount` TINYINT NOT NULL DEFAULT 0, `ZoneCount` TINYINT NOT NULL DEFAULT 0,
`Refresh` int(10) unsigned default NULL, `Refresh` int(10) unsigned default NULL,
`Latitude` DECIMAL(10,8),
`Longitude` DECIMAL(10,8),
PRIMARY KEY (`Id`) PRIMARY KEY (`Id`)
) ENGINE=@ZM_MYSQL_ENGINE@; ) ENGINE=@ZM_MYSQL_ENGINE@;

20
db/zm_update-1.31.30.sql Normal file
View File

@ -0,0 +1,20 @@
DROP TABLE IF EXISTS `Monitor_Status`;
CREATE TABLE `Monitor_Status` (
`MonitorId` int(10) unsigned NOT NULL,
`Status` enum('Unknown','NotRunning','Running','Connected','Signal') NOT NULL default 'Unknown',
`CaptureFPS` DECIMAL(10,2) NOT NULL default 0,
`AnalysisFPS` DECIMAL(5,2) NOT NULL default 0,
PRIMARY KEY (`MonitorId`)
) ENGINE=MEMORY;
SET SESSION sql_mode='NO_AUTO_VALUE_ON_ZERO';
SET @s = (SELECT IF(
(SELECT COUNT(*) FROM Storage WHERE Name = 'Default' AND Id=0 AND Path='/var/cache/zoneminder/events'
) > 0,
"SELECT 'Default Storage Area already exists.'",
"INSERT INTO Storage (Id,Name,Path,Scheme,ServerId) VALUES (0,'Default','/var/cache/zoneminder/events','Medium',NULL)"
));
PREPARE stmt FROM @s;
EXECUTE stmt;

23
db/zm_update-1.35.7.sql Normal file
View File

@ -0,0 +1,23 @@
SET @s = (SELECT IF(
(SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = DATABASE()
AND table_name = 'Monitors'
AND column_name = 'Latitude'
) > 0,
"SELECT 'Column Latitude already exists in Monitors'",
"ALTER TABLE `Monitors` ADD `Latitude` DECIMAL(10,8) AFTER `Refresh`"
));
PREPARE stmt FROM @s;
EXECUTE stmt;
SET @s = (SELECT IF(
(SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = DATABASE()
AND table_name = 'Monitors'
AND column_name = 'Longitude'
) > 0,
"SELECT 'Column Longitude already exists in Monitors'",
"ALTER TABLE `Monitors` ADD `Longitude` DECIMAL(10,8) AFTER `Latitude`"
));
PREPARE stmt FROM @s;
EXECUTE stmt;

View File

@ -129,6 +129,8 @@ class Monitor extends ZM_Object {
'Refresh' => null, 'Refresh' => null,
'DefaultCodec' => 'auto', 'DefaultCodec' => 'auto',
'GroupIds' => array('default'=>array(), 'do_not_update'=>1), 'GroupIds' => array('default'=>array(), 'do_not_update'=>1),
'Latitude' => null,
'Longitude' => null,
); );
private $status_fields = array( private $status_fields = array(
'Status' => null, 'Status' => null,

View File

@ -241,5 +241,19 @@ function update_estimated_ram_use() {
document.getElementById('estimated_ram_use').innerHTML = human_filesize(buffer_count * width * height * colours, 0); document.getElementById('estimated_ram_use').innerHTML = human_filesize(buffer_count * width * height * colours, 0);
} }
function updateLatitudeAndLongitude(latitude,longitude) {
var form = document.getElementById('contentForm');
form.elements['newMonitor[Latitude]'].value = latitude;
form.elements['newMonitor[Longitude]'].value = longitude;
}
function getLocation() {
if('geolocation' in navigator) {
navigator.geolocation.getCurrentPosition((position) => {
updateLatitudeAndLongitude(position.coords.latitude, position.coords.longitude);
});
} else {
console.log("Geolocation not available");
}
}
window.addEventListener('DOMContentLoaded', initPage); window.addEventListener('DOMContentLoaded', initPage);

View File

@ -404,6 +404,7 @@ if ( $monitor->Type() != 'WebSite' ) {
if ( ZM_OPT_X10 ) if ( ZM_OPT_X10 )
$tabs['x10'] = translate('X10'); $tabs['x10'] = translate('X10');
$tabs['misc'] = translate('Misc'); $tabs['misc'] = translate('Misc');
$tabs['location'] = translate('Location');
} }
if ( isset($_REQUEST['tab']) ) if ( isset($_REQUEST['tab']) )
@ -1151,6 +1152,25 @@ echo htmlSelect('newMonitor[ReturnLocation]', $return_options, $monitor->ReturnL
<?php <?php
break; break;
} }
case 'location':
?>
<tr>
<td class="text-right pr-3"><?php echo translate('Latitude') ?></td>
<td><input type="number" name="newMonitor[Latitude]" step="any" value="<?php echo $monitor->Latitude() ?>" min="-90" max="90"/></td>
</tr>
<tr>
<td class="text-right pr-3"><?php echo translate('Longitude') ?></td>
<td><input type="number" name="newMonitor[Longitude]" step="any" value="<?php echo $monitor->Longitude() ?>" min="-180" max="180"/></td>
</tr>
<tr>
<td class="text-right pr-3"><?php echo translate('Longitude') ?></td>
<td><button type="button" data-on-click="getLocation"><?php echo translate('GetCurrentLocation') ?></button></td>
</tr>
<?php
break;
default :
ZM\Error("Unknown tab $tab");
} // end switch tab } // end switch tab
?> ?>
</tbody> </tbody>