Skip to content

Commit b37663c

Browse files
committed
Clean panel & events
1 parent f8653b4 commit b37663c

File tree

5 files changed

+109
-290
lines changed

5 files changed

+109
-290
lines changed

core/class/frigate.class.php

Lines changed: 82 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3639,28 +3639,6 @@ private static function jsonFromUrl($jsonUrl)
36393639
return $jsonArray;
36403640
}
36413641

3642-
/* private static function yamlToJsonFromUrl($yamlUrl)
3643-
{
3644-
// Télécharger le contenu YAML depuis l'URL
3645-
$yamlContent = file_get_contents($yamlUrl);
3646-
// Vérifier si le téléchargement a réussi
3647-
if ($yamlContent === false) {
3648-
log::add(__CLASS__, "error", "yamlToJsonFromUrl : Failed to retrieve YAML from URL");
3649-
return json_encode(["error" => "Failed to retrieve YAML from URL: $yamlUrl"]);
3650-
}
3651-
// Parser le contenu YAML
3652-
$yamlArray = yaml_parse($yamlContent);
3653-
// Vérifier si le parsing est réussi
3654-
if ($yamlArray === false) {
3655-
log::add(__CLASS__, "error", "yamlToJsonFromUrl : Invalid YAML content or file not found");
3656-
return json_encode(["error" => "Invalid YAML content or file not found"]);
3657-
}
3658-
// Convertir le tableau PHP en JSON
3659-
$jsonContent = json_encode($yamlArray, JSON_PRETTY_PRINT);
3660-
return $jsonContent;
3661-
}
3662-
3663-
*/
36643642
private static function checkFrigateStatus()
36653643
{
36663644
$frigate = frigate::byLogicalId('eqFrigateStats', 'frigate');
@@ -3730,6 +3708,88 @@ public static function getPluginVersion()
37303708
log::add('frigate', 'info', '[Plugin-Version] PluginVersion :: ' . $pluginVersion);
37313709
return $pluginVersion;
37323710
}
3711+
3712+
3713+
public static function timeElapsedString($datetime, $full = false)
3714+
{
3715+
$now = new DateTime();
3716+
$ago = new DateTime($datetime);
3717+
$diff = $now->diff($ago);
3718+
3719+
// On extrait les valeurs dans un tableau pour pouvoir ajouter les semaines
3720+
// sans modifier l'objet DateInterval original
3721+
$diffValues = [
3722+
'y' => $diff->y,
3723+
'm' => $diff->m,
3724+
'w' => (int)floor($diff->d / 7),
3725+
'd' => $diff->d % 7, // Le reste des jours après avoir retiré les semaines
3726+
'h' => $diff->h,
3727+
'i' => $diff->i,
3728+
's' => $diff->s,
3729+
];
3730+
3731+
$units = [
3732+
'y' => ['année', 'années'],
3733+
'm' => ['mois', 'mois'],
3734+
'w' => ['semaine', 'semaines'],
3735+
'd' => ['jour', 'jours'],
3736+
'h' => ['heure', 'heures'],
3737+
'i' => ['minute', 'minutes'],
3738+
's' => ['seconde', 'secondes'],
3739+
];
3740+
3741+
$strings = [];
3742+
foreach ($units as $key => $names) {
3743+
if ($diffValues[$key] > 0) {
3744+
$count = $diffValues[$key];
3745+
$strings[] = $count . ' ' . ($count > 1 ? $names[1] : $names[0]);
3746+
}
3747+
}
3748+
3749+
if (!$full) {
3750+
$strings = array_slice($strings, 0, 1);
3751+
}
3752+
3753+
return $strings ? 'il y a ' . implode(', ', $strings) : 'à l\'instant';
3754+
}
3755+
3756+
public static function getPercentageClass($score)
3757+
{
3758+
$score = (int) $score;
3759+
if ($score === 100) return 'percentage-100';
3760+
if ($score >= 90) return 'percentage-99';
3761+
if ($score >= 80) return 'percentage-89';
3762+
if ($score >= 70) return 'percentage-79';
3763+
if ($score >= 60) return 'percentage-69';
3764+
if ($score >= 50) return 'percentage-59';
3765+
if ($score >= 40) return 'percentage-49';
3766+
if ($score >= 30) return 'percentage-39';
3767+
if ($score >= 20) return 'percentage-29';
3768+
if ($score >= 10) return 'percentage-19';
3769+
if ($score > 0) return 'percentage-9';
3770+
3771+
return 'percentage-0';
3772+
}
3773+
3774+
public static function formatDuration($seconds)
3775+
{
3776+
$hours = floor($seconds / 3600);
3777+
$minutes = floor(($seconds % 3600) / 60);
3778+
$remainingSeconds = $seconds % 60;
3779+
3780+
$formattedDuration = '';
3781+
if ($hours > 0) {
3782+
$formattedDuration .= $hours . 'h';
3783+
$formattedDuration .= ' ' . str_pad((string)$minutes, 2, '0', STR_PAD_LEFT) . 'mn';
3784+
} elseif ($minutes > 0) {
3785+
$formattedDuration .= $minutes . 'mn';
3786+
$formattedDuration .= ' ' . str_pad((string)$remainingSeconds, 2, '0', STR_PAD_LEFT) . 's';
3787+
} else {
3788+
$formattedDuration .= str_pad((string)$remainingSeconds, 2, '0', STR_PAD_LEFT) . 's';
3789+
}
3790+
3791+
return $formattedDuration;
3792+
}
37333793
}
37343794
class frigateCmd extends cmd
37353795
{

desktop/php/event.template.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class="frigateEventContainer">
7878
<span class="inline-subtitle duration"> <?= $timeElapsed ?></span><br /><br />
7979
<i class="fas fa-minus-square"></i>
8080
<span> <?= $label ?>
81-
<div class="percentage <?= getPercentageClass($topScore) ?>"><?= $topScore ?>%</div>
81+
<div class="percentage <?= frigate::getPercentageClass($topScore) ?>"><?= $topScore ?>%</div>
8282
</span><br>
8383
<?php if ($cameraFound): ?>
8484
<div style='display: flex;align-items: center;gap: 10px;'>
@@ -103,7 +103,7 @@ class="frigateEventContainer">
103103
<?= $hasClip == 1 ? 'data-video="' . $clip . '"' : '' ?>
104104
data-title="
105105
<i class='fas fa-minus-square'>&nbsp;</i>&nbsp;<?= $label ?>
106-
<div class='percentage <?= getPercentageClass($topScore) ?>'><?= $topScore ?> %</div>
106+
<div class='percentage <?= frigate::getPercentageClass($topScore) ?>'><?= $topScore ?> %</div>
107107
<br><i class='fas fa-video'>&nbsp;</i>&nbsp;<?= $camera ?>
108108
<br><i class='fas fa-clock'>&nbsp;</i>&nbsp;<?= $date ?> <?= $hasClip == 1 ? $formattedDuration : '' ?>"
109109
data-description="<?= $description ?>">

desktop/php/events.php

Lines changed: 12 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
?>
88

99
<script language="javascript">
10-
window.onload = function(){
11-
const el = document.getElementById("div_mainContainer");
12-
const savedScroll = parseFloat(localStorage.getItem("frigateScrollTop"));
13-
if (el && savedScroll !== null) {
14-
// Repositionnement de la liste à sa position Y
15-
el.scrollTo(0, document.getElementById("frigateEventList").getBoundingClientRect().top + savedScroll);
16-
localStorage.removeItem("frigateScrollTop");
17-
}
18-
}
10+
window.onload = function() {
11+
const el = document.getElementById("div_mainContainer");
12+
const savedScroll = parseFloat(localStorage.getItem("frigateScrollTop"));
13+
if (el && savedScroll !== null) {
14+
// Repositionnement de la liste à sa position Y
15+
el.scrollTo(0, document.getElementById("frigateEventList").getBoundingClientRect().top + savedScroll);
16+
localStorage.removeItem("frigateScrollTop");
17+
}
18+
}
1919
</script>
2020

2121
<div class="col-lg-12">
@@ -30,96 +30,7 @@
3030

3131
<?php
3232

33-
// functions
34-
function getPercentageClass($score)
35-
{
36-
$score = (int) $score;
37-
if ($score === 100) return 'percentage-100';
38-
if ($score >= 90) return 'percentage-99';
39-
if ($score >= 80) return 'percentage-89';
40-
if ($score >= 70) return 'percentage-79';
41-
if ($score >= 60) return 'percentage-69';
42-
if ($score >= 50) return 'percentage-59';
43-
if ($score >= 40) return 'percentage-49';
44-
if ($score >= 30) return 'percentage-39';
45-
if ($score >= 20) return 'percentage-29';
46-
if ($score >= 10) return 'percentage-19';
47-
if ($score > 0) return 'percentage-9';
48-
49-
return 'percentage-0';
50-
}
51-
52-
function formatDuration($seconds)
53-
{
54-
$hours = floor($seconds / 3600);
55-
$minutes = floor(($seconds % 3600) / 60);
56-
$remainingSeconds = $seconds % 60;
57-
58-
$formattedDuration = '';
59-
if ($hours > 0) {
60-
$formattedDuration .= $hours . 'h';
61-
$formattedDuration .= ' ' . str_pad($minutes, 2, '0', STR_PAD_LEFT) . 'mn';
62-
//$formattedDuration .= str_pad($remainingSeconds, 2, '0', STR_PAD_LEFT) . 's';
63-
} elseif ($minutes > 0) {
64-
$formattedDuration .= $minutes . 'mn';
65-
$formattedDuration .= ' ' . str_pad($remainingSeconds, 2, '0', STR_PAD_LEFT) . 's';
66-
} else {
67-
$formattedDuration .= str_pad($remainingSeconds, 2, '0', STR_PAD_LEFT) . 's';
68-
}
69-
70-
return $formattedDuration;
71-
}
72-
73-
/**
74-
* @param string $datetime
75-
* @param bool $full
76-
* @return string
77-
*/
78-
function timeElapsedString($datetime, $full = false)
79-
{
80-
$now = new DateTime();
81-
$ago = new DateTime($datetime);
82-
$diff = $now->diff($ago);
83-
84-
// On extrait les valeurs dans un tableau pour pouvoir ajouter les semaines
85-
// sans modifier l'objet DateInterval original
86-
$diffValues = [
87-
'y' => $diff->y,
88-
'm' => $diff->m,
89-
'w' => (int)floor($diff->d / 7),
90-
'd' => $diff->d % 7, // Le reste des jours après avoir retiré les semaines
91-
'h' => $diff->h,
92-
'i' => $diff->i,
93-
's' => $diff->s,
94-
];
95-
96-
$units = [
97-
'y' => ['année', 'années'],
98-
'm' => ['mois', 'mois'],
99-
'w' => ['semaine', 'semaines'],
100-
'd' => ['jour', 'jours'],
101-
'h' => ['heure', 'heures'],
102-
'i' => ['minute', 'minutes'],
103-
's' => ['seconde', 'secondes'],
104-
];
105-
106-
$strings = [];
107-
foreach ($units as $key => $names) {
108-
if ($diffValues[$key] > 0) {
109-
$count = $diffValues[$key];
110-
$strings[] = $count . ' ' . ($count > 1 ? $names[1] : $names[0]);
111-
}
112-
}
113-
114-
if (!$full) {
115-
$strings = array_slice($strings, 0, 1);
116-
}
117-
118-
return $strings ? 'il y a ' . implode(', ', $strings) : 'à l\'instant';
119-
}
120-
121-
122-
$events = frigate::showEvents();
33+
$events = frigate::showEvents();
12334

12435
// cameras variables
12536
$selectedCameras = isset($_GET['cameras']) ? explode(',', $_GET['cameras']) : [];
@@ -153,7 +64,7 @@ function timeElapsedString($datetime, $full = false)
15364
$label = $event['label'];
15465
$type = $event['type'];
15566
$date = $event['date'];
156-
$timeElapsed = timeElapsedString($date);
67+
$timeElapsed = frigate::timeElapsedString($date);
15768
$percentage = $event['percentage'] ?? 0;
15869
$duration = $event['duration'] ?? 0;
15970
$favoriteClass = $event['isFavorite'] ? 'fas fa-star' : 'far fa-star';
@@ -177,7 +88,7 @@ function timeElapsedString($datetime, $full = false)
17788
$topScore = $event['top_score'];
17889
$description = $event['description'];
17990
$duree = $event['duree'];
180-
$formattedDuration = '<div class=\'duration\'>' . formatDuration($duree) . '</div>';
91+
$formattedDuration = '<div class=\'duration\'>' . frigate::formatDuration($duree) . '</div>';
18192
$img = $event['img'];
18293
$hasSnapshot = $event['hasSnapshot'];
18394
$snapshot = $event['snapshot'];

0 commit comments

Comments
 (0)