* camera images ordered by mtime
* display image by camera is now second to last, not the last one * indent changes in javascript code * js code should now be more roboust if there are camera folders getting deleted
This commit is contained in:
parent
07a95f5c4b
commit
139116d76f
@ -27,7 +27,7 @@ jQuery(document).ready(function () {
|
|||||||
|
|
||||||
// change displayed image
|
// change displayed image
|
||||||
window.setInterval(function () {
|
window.setInterval(function () {
|
||||||
cameraPointer = cameraPointer === cameraImages.length - 1
|
cameraPointer = cameraPointer >= cameraImages.length - 1
|
||||||
? 0
|
? 0
|
||||||
: cameraPointer + 1;
|
: cameraPointer + 1;
|
||||||
changeImage(cameraPointer);
|
changeImage(cameraPointer);
|
||||||
|
|||||||
@ -31,7 +31,10 @@ class CameraPictureManagerService
|
|||||||
$cameraImageFolders = array_diff(scandir($cameraImageBaseFolder), ['.', '..']);
|
$cameraImageFolders = array_diff(scandir($cameraImageBaseFolder), ['.', '..']);
|
||||||
|
|
||||||
foreach ($cameraImageFolders as $cameraImageFolder) {
|
foreach ($cameraImageFolders as $cameraImageFolder) {
|
||||||
$cameraImages[] = $this->getLatestImageInDirectory("{$cameraImageBaseFolder}/{$cameraImageFolder}");
|
$theImage = $this->getLatestCompleteImageInDirectory("{$cameraImageBaseFolder}/{$cameraImageFolder}");
|
||||||
|
if (null != $theImage) {
|
||||||
|
$cameraImages[] = $theImage;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $cameraImages;
|
return $cameraImages;
|
||||||
@ -66,13 +69,21 @@ class CameraPictureManagerService
|
|||||||
* @param string $directory
|
* @param string $directory
|
||||||
* @return CameraImage
|
* @return CameraImage
|
||||||
*/
|
*/
|
||||||
private function getLatestImageInDirectory(string $directory): CameraImage
|
private function getLatestCompleteImageInDirectory(string $directory): ?CameraImage
|
||||||
{
|
{
|
||||||
$cameraImage = new CameraImage();
|
$cameraImage = new CameraImage();
|
||||||
$cameraImage->setCamera(basename($directory));
|
$cameraImage->setCamera(basename($directory));
|
||||||
|
|
||||||
$allImages = glob("{$directory}/*.{png,jpeg,jpg}", GLOB_NOSORT | GLOB_BRACE);
|
$allImages = glob("{$directory}/*.{png,jpeg,jpg}", GLOB_NOSORT | GLOB_BRACE);
|
||||||
$latestImage = array_pop($allImages);
|
if (count($allImages) < 2) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$imageModificationTimes = array_map('filemtime', $allImages);
|
||||||
|
array_multisort($imageModificationTimes, SORT_DESC, $allImages);
|
||||||
|
|
||||||
|
$latestImage = $allImages[1];
|
||||||
|
unset($allImages);
|
||||||
|
|
||||||
$cameraImage->setImageName(pathinfo($latestImage, PATHINFO_BASENAME))
|
$cameraImage->setImageName(pathinfo($latestImage, PATHINFO_BASENAME))
|
||||||
->setCreatedAt(new \DateTime(sprintf("@%s", filemtime($latestImage))));
|
->setCreatedAt(new \DateTime(sprintf("@%s", filemtime($latestImage))));
|
||||||
|
|||||||
@ -12,7 +12,7 @@ class CameraPictureManagerServiceTest extends TestCase
|
|||||||
{
|
{
|
||||||
const EXISTING_CAM_DIR = 'cam1';
|
const EXISTING_CAM_DIR = 'cam1';
|
||||||
const EXISTING_IMAGE = 'img1.png';
|
const EXISTING_IMAGE = 'img1.png';
|
||||||
const MISSING_IMAGE = 'img9.png';
|
const MISSING_IMAGE = 'imgXX.png';
|
||||||
const TEST_DATA_DIR = 'test/data';
|
const TEST_DATA_DIR = 'test/data';
|
||||||
|
|
||||||
/** @var Config */
|
/** @var Config */
|
||||||
|
|||||||
BIN
test/data/cam1/img9.png
Normal file
BIN
test/data/cam1/img9.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.4 KiB |
BIN
test/data/cam2/img9.png
Normal file
BIN
test/data/cam2/img9.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.2 KiB |
BIN
test/data/cam3/img9.jpeg
Normal file
BIN
test/data/cam3/img9.jpeg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.2 KiB |
BIN
test/data/cam5/img1.png
Normal file
BIN
test/data/cam5/img1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.4 KiB |
1
test/data/cam5/overlay.txt
Normal file
1
test/data/cam5/overlay.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
img1
|
||||||
Loading…
x
Reference in New Issue
Block a user