From 71d0984e9d85d89502d3482ca68f5d6fc65dbca2 Mon Sep 17 00:00:00 2001 From: Yasen Pramatarov Date: Sun, 26 Jan 2025 14:39:10 +0200 Subject: [PATCH] Redesigns the components page --- app/classes/component.php | 69 +++++++++++++----- app/pages/components.php | 57 ++++++++++----- app/templates/components.php | 97 +++++++++++++++++++++++++ app/templates/event-list-components.php | 76 ------------------- 4 files changed, 188 insertions(+), 111 deletions(-) create mode 100644 app/templates/components.php delete mode 100644 app/templates/event-list-components.php diff --git a/app/classes/component.php b/app/classes/component.php index f02a5f2..82a5f54 100644 --- a/app/classes/component.php +++ b/app/classes/component.php @@ -49,25 +49,14 @@ class Component { $until_time = htmlspecialchars(strip_tags($until_time)); // list of jitsi component events - $sql = " -SELECT - jitsi_component, loglevel, time, component_id, event_type, event_param -FROM - jitsi_components -WHERE - jitsi_component = %s -AND - component_id = %s"; + $sql = "SELECT jitsi_component, loglevel, time, component_id, event_type, event_param + FROM jitsi_components + WHERE LOWER(jitsi_component) = LOWER(%s) + AND component_id = %s"; if ($event_type != '' && $event_type != 'event_type') { - $sql .= " -AND - event_type LIKE '%%%s%%'"; + $sql .= " AND event_type LIKE '%%%s%%'"; } - $sql .= " -AND - (time >= '%s 00:00:00' AND time <= '%s 23:59:59') -ORDER BY - time"; + $sql .= " AND (time >= '%s 00:00:00' AND time <= '%s 23:59:59') ORDER BY time"; if ($items_per_page) { $items_per_page = (int)$items_per_page; @@ -89,6 +78,52 @@ ORDER BY return $query->fetchAll(PDO::FETCH_ASSOC); } + /** + * Gets the total count of components events matching the filter criteria + * + * @param string $jitsi_component The Jitsi component name. + * @param int $component_id The component ID. + * @param string $event_type The type of event to filter by. + * @param string $from_time The start date in 'YYYY-MM-DD' format. + * @param string $until_time The end date in 'YYYY-MM-DD' format. + * + * @return int The total count of matching components + */ + public function getComponentEventsCount($jitsi_component, $component_id, $event_type, $from_time, $until_time) { + // time period drill-down + if (empty($from_time)) { + $from_time = '0000-01-01'; + } + if (empty($until_time)) { + $until_time = '9999-12-31'; + } + $from_time = htmlspecialchars(strip_tags($from_time)); + $until_time = htmlspecialchars(strip_tags($until_time)); + + // Build the query + $sql = "SELECT COUNT(*) as total + FROM jitsi_events + WHERE time >= :from_time + AND time <= :until_time + AND LOWER(jitsi_component) = LOWER(:jitsi_component) + AND component_id) = :component_id + AND LOWER(event_type) = LOWER(:event_type)"; + + try { + $stmt = $this->db->prepare($sql); + $stmt->bindParam(':from_time', $from_time); + $stmt->bindParam(':until_time', $until_time); + $stmt->bindParam(':jitsi_component', $jitsi_component); + $stmt->bindParam(':component_id', $component_id); + $stmt->bindParam(':event_type', $event_type); + $stmt->execute(); + $result = $stmt->fetch(PDO::FETCH_ASSOC); + return (int)$result['total']; + } catch (PDOException $e) { + error_log("Error in getComponentCount: " . $e->getMessage()); + return 0; + } + } } ?> diff --git a/app/pages/components.php b/app/pages/components.php index b2f5325..e34f661 100644 --- a/app/pages/components.php +++ b/app/pages/components.php @@ -25,9 +25,35 @@ if ($response['db'] === null) { } else { $db = $response['db']; + // Get current page for pagination + $currentPage = $_REQUEST['page_num'] ?? 1; + $currentPage = (int)$currentPage; + // specify time range include '../app/helpers/time_range.php'; + // Build params for pagination + $params = ''; + if (!empty($_REQUEST['from_time'])) { + $params .= '&from_time=' . urlencode($_REQUEST['from_time']); + } + if (!empty($_REQUEST['until_time'])) { + $params .= '&until_time=' . urlencode($_REQUEST['until_time']); + } + if (!empty($_REQUEST['name'])) { + $params .= '&name=' . urlencode($_REQUEST['name']); + } + if (!empty($_REQUEST['id'])) { + $params .= '&id=' . urlencode($_REQUEST['id']); + } + if (isset($_REQUEST['event'])) { + $params .= '&event=' . urlencode($_REQUEST['event']); + } + + // pagination variables + $items_per_page = 15; + $offset = ($currentPage -1) * $items_per_page; + // jitsi component events list // we use $_REQUEST, so that both links and forms work // if it's there, but empty, we make it same as the field name; otherwise assign the value @@ -44,11 +70,6 @@ if ($response['db'] === null) { // list of all component events (default) $componentObject = new Component($db); - // pagination variables - $items_per_page = 15; - $browse_page = $_REQUEST['p'] ?? 1; - $browse_page = (int)$browse_page; - $offset = ($browse_page -1) * $items_per_page; // prepare the result $search = $componentObject->jitsiComponents($jitsi_component, $component_id, $event_type, $from_time, $until_time, $offset, $items_per_page); @@ -57,7 +78,7 @@ if ($response['db'] === null) { if (!empty($search)) { // we get total items and number of pages $item_count = count($search_all); - $page_count = ceil($item_count / $items_per_page); + $totalPages = ceil($item_count / $items_per_page); $components = array(); $components['records'] = array(); @@ -78,11 +99,11 @@ if ($response['db'] === null) { } } - // prepare the widget - $widget['full'] = false; - $widget['name'] = 'AllComponents'; - $widget['filter'] = true; - $widget['pagination'] = true; +// // prepare the widget +// $widget['full'] = false; +// $widget['name'] = 'AllComponents'; +// $widget['filter'] = true; +// $widget['pagination'] = true; // widget title if (isset($_REQUEST['name']) && $_REQUEST['name'] != '') { @@ -92,15 +113,15 @@ if ($response['db'] === null) { } else { $widget['title'] = 'Jitsi events for all components'; } - // widget records - if (!empty($components['records'])) { - $widget['full'] = true; - $widget['table_headers'] = array_keys($components['records'][0]); - $widget['table_records'] = $components['records']; - } +// // widget records +// if (!empty($components['records'])) { +// $widget['full'] = true; +// $widget['table_headers'] = array_keys($components['records'][0]); +// $widget['table_records'] = $components['records']; +// } // display the widget - include '../app/templates/event-list-components.php'; + include '../app/templates/components.php'; } diff --git a/app/templates/components.php b/app/templates/components.php new file mode 100644 index 0000000..a1d3bd4 --- /dev/null +++ b/app/templates/components.php @@ -0,0 +1,97 @@ + + +
+
+
+

Jitsi components events

+ Log events related to Jitsi Meet components like Jicofo, Videobridge, Jigasi, etc. +
+
+ + +
+
+
+ +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + + Clear + +
+
+
+
+ + + + +
+ Time period: - +
+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
ComponentLogLevelTimeComponent IDEventParameter
+ + + + + + + +
+
+ + +
+ No component events found for the specified criteria. +
+ +
+
+
+
+ diff --git a/app/templates/event-list-components.php b/app/templates/event-list-components.php deleted file mode 100644 index ce77717..0000000 --- a/app/templates/event-list-components.php +++ /dev/null @@ -1,76 +0,0 @@ - -
-
- - -
-
- - /> - - /> - /> - /> - /> - - -
- -
- - -
- - -
- -

time period: -

- -
- - - - - - - - - - - - - $column) { ?> - - - - - - - - - - -
- $items_per_page) { - $url = "$app_root?platform=$platform_id&page=$page"; - include '../app/helpers/pagination.php'; -} -?> - -

No matching records found.

- -
-
-