diff --git a/public/assets/js/app.js b/public/assets/js/app.js index d796f90..295a891 100644 --- a/public/assets/js/app.js +++ b/public/assets/js/app.js @@ -89,12 +89,14 @@ var CameraEvent = function() { var SnapshotEvent = function() { var links = document.querySelectorAll('.snapshot-link'); var view = document.querySelector('#snapshot-view'); - var template = document.querySelector('#snapshot-template'); var body = document.querySelector('body'); forEach(links, function(i, link) { link.addEventListener('click', function(e) { e.preventDefault(); + + var template = document.querySelector(link.getAttribute('data-template')); + body.classList.add('modal-open'); view.innerHTML = template.innerHTML.replace(/{src}/g, link.getAttribute('href')); diff --git a/src/Motion/Snapshot.php b/src/Motion/Snapshot.php index dd758ed..ae2f464 100644 --- a/src/Motion/Snapshot.php +++ b/src/Motion/Snapshot.php @@ -13,6 +13,8 @@ class Snapshot { protected DateTime $date; + protected string $picture; + protected string $movie; protected string $thumbnail; @@ -29,6 +31,18 @@ class Snapshot return $this->date; } + public function setPicture(string $picture): self + { + $this->picture = $picture; + + return $this; + } + + public function getPicture(): ? string + { + return $this->picture; + } + public function setMovie(string $movie): self { $this->movie = $movie; diff --git a/src/Motion/SnapshotRepository.php b/src/Motion/SnapshotRepository.php index 62b0a51..7ac1ef6 100644 --- a/src/Motion/SnapshotRepository.php +++ b/src/Motion/SnapshotRepository.php @@ -42,20 +42,33 @@ class SnapshotRepository $files = $moviesFinder ->files() ->in($directory->getPathName()) - ->name('*.mp4') ->sortByName(); $date = $directory->getFilename(); foreach ($files as $file) { - $time = str_replace(['.mp4', '-'], ['', ':'], $file->getBasename()); - $thumbnail = str_replace('.mp4', '.jpg', $file->getPathName()); + $time = str_replace(['.mp4', '.jpg', '-'], ['', '', ':'], $file->getBasename()); $snapshot = new Snapshot(); - $snapshot - ->setDate(new \DateTime($date.' '.$time)) - ->setMovie($file->getPathName()) - ->setThumbnail($thumbnail); + $snapshot->setDate(new \DateTime($date.' '.$time)); + + if (substr($file->getFilename(), -3) === 'jpg') { + $movie = str_replace('.jpg', '.mp4', $file->getPathName()); + + if (file_exists($movie)) { + continue; + } + + $thumbnail = $file->getPathName(); + $snapshot->setPicture($file->getPathName()); + $snapshot->setMovie(''); + } else { + $thumbnail = str_replace('.mp4', '.jpg', $file->getPathName()); + $snapshot->setMovie($file->getPathName()); + $snapshot->setPicture(''); + } + + $snapshot->setThumbnail($thumbnail); $objects[] = $snapshot; } diff --git a/templates/events.html.twig b/templates/events.html.twig index f9ca1e6..65dd8c2 100644 --- a/templates/events.html.twig +++ b/templates/events.html.twig @@ -22,7 +22,7 @@ {% for snapshot in snapshots %} {% if date == snapshot.date.format('Y-m-d') %}
- + {{ snapshot.date.format('d/m/Y H:i:s') }}
@@ -33,7 +33,20 @@
-