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">
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