diff --git a/.gitignore b/.gitignore index 813157f..051fb78 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,4 @@ ###< symfony/web-server-bundle ### /node_modules +/public/motion/snapshots/* diff --git a/config/services.yaml b/config/services.yaml index 5c4b417..78fa0d9 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -4,6 +4,7 @@ # Put parameters here that don't need to change on each machine where the app is deployed # https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration parameters: + motion_snapshots_directory: "motion/snapshots" services: # default configuration for services in *this* file diff --git a/public/assets/css/app.css b/public/assets/css/app.css index 911ae4e..1488b65 100644 --- a/public/assets/css/app.css +++ b/public/assets/css/app.css @@ -10,3 +10,7 @@ .camera { cursor: pointer; } + +.table.is-full { + width: 100%; +} diff --git a/public/assets/js/app.js b/public/assets/js/app.js index 1782187..2276e43 100644 --- a/public/assets/js/app.js +++ b/public/assets/js/app.js @@ -81,7 +81,25 @@ var CameraEvent = function() { }); } +var SnapshotEvent = function() { + var links = document.querySelectorAll('.snapshot-link'); + var view = document.querySelector('#snapshot-view'); + var template = document.querySelector('#snapshot-template'); + + + forEach(links, function(i, link) { + link.addEventListener('click', function(e) { + e.preventDefault(); + view.innerHTML = template.innerHTML.replace('{src}', link.getAttribute('href')); + view.querySelector('.modal-close').addEventListener('click', function() { + view.innerHTML = ''; + }, false); + }); + }); +} + window.addEventListener('load', function() { ChartLoader(); CameraEvent(); + SnapshotEvent(); }, false) diff --git a/src/Controller/MonitoringApiController.php b/src/Controller/MonitoringApiController.php index 1d5fec9..3b93541 100644 --- a/src/Controller/MonitoringApiController.php +++ b/src/Controller/MonitoringApiController.php @@ -10,7 +10,7 @@ use Symfony\Component\HttpFoundation\Request; class MonitoringApiController extends AbstractController { /** - * @Route("/api/temperature", name="api_temperature") + * @Route("/api/monitoring/temperature", name="api_monitoring_temperature") */ public function temperature(Request $request) { @@ -52,7 +52,7 @@ class MonitoringApiController extends AbstractController } /** - * @Route("/api/hygrometry", name="api_hygrometry") + * @Route("/api/monitoring/hygrometry", name="api_monitoring_hygrometry") */ public function hygrometry(Request $request) { diff --git a/src/Controller/MonitoringController.php b/src/Controller/MonitoringController.php index a09d5ea..bda7e9a 100644 --- a/src/Controller/MonitoringController.php +++ b/src/Controller/MonitoringController.php @@ -4,6 +4,8 @@ namespace App\Controller; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Filesystem\Filesystem; +use App\Motion\SnapshotRepository; class MonitoringController extends AbstractController { @@ -18,8 +20,12 @@ class MonitoringController extends AbstractController /** * @Route("/camera", name="camera") */ - public function camera() + public function camera(SnapshotRepository $snapshotRepository) { - return $this->render('camera.html.twig'); + $snapshots = $snapshotRepository->find(); + + return $this->render('camera.html.twig', [ + 'snapshots' => $snapshots, + ]); } } diff --git a/src/Controller/MotionApiController.php b/src/Controller/MotionApiController.php new file mode 100644 index 0000000..b696132 --- /dev/null +++ b/src/Controller/MotionApiController.php @@ -0,0 +1,20 @@ + + */ +class Snapshot +{ + protected DateTime $date; + + protected string $path; + + public function setDate(DateTime $date): self + { + $this->date = $date; + + return $this; + } + + public function getDate(): ? \DateTime + { + return $this->date; + } + + public function setPath(string $path): self + { + $this->path = $path; + + return $this; + } + + public function getPath(): ? string + { + return $this->path; + } +} diff --git a/src/Motion/SnapshotRepository.php b/src/Motion/SnapshotRepository.php new file mode 100644 index 0000000..a34ff66 --- /dev/null +++ b/src/Motion/SnapshotRepository.php @@ -0,0 +1,51 @@ + + */ +class SnapshotRepository +{ + protected Finder $finder; + + protected ParameterBagInterface $parameters; + + public function __construct(ParameterBagInterface $parameters) + { + $this->finder = new Finder(); + $this->parameters = $parameters; + } + + public function find(): array + { + $objects = []; + + $files = $this->finder + ->files() + ->in($this->parameters->get('motion_snapshots_directory')) + ->name('/.*\.mp4$/s') + ->sortByModifiedTime(); + + foreach ($files as $file) { + $date = basename($file->getPath()); + $time = str_replace(['.mp4', '-'], ['', ':'], $file->getBasename()); + + $snapshot = new Snapshot(); + $snapshot + ->setDate(new \DateTime($date.' '.$time)) + ->setPath($file->getPath().'/'.$file->getBasename()); + + $objects[] = $snapshot; + } + + return $objects; + } +} diff --git a/templates/camera.html.twig b/templates/camera.html.twig index 0678981..97f3c85 100644 --- a/templates/camera.html.twig +++ b/templates/camera.html.twig @@ -7,5 +7,48 @@
Caméra 1
+ +
+ + {% if snapshots|length %} +
+ Évènements +
+ + + + + + + + + + {% for snapshot in snapshots %} + + + + + {% endfor %} + +
DateFichier
{{ snapshot.date.format('d/m/Y H:i:s') }} + + {{ snapshot.path }} + +
+ {% endif %} + +
+ + {% endblock %} diff --git a/templates/charts.html.twig b/templates/charts.html.twig index df90dce..8d96eb9 100644 --- a/templates/charts.html.twig +++ b/templates/charts.html.twig @@ -7,7 +7,7 @@
Température
-
+
@@ -15,7 +15,7 @@
Hygrométrie
-
+