Adds widget to components page

main
Yasen Pramatarov 2024-07-28 13:35:09 +03:00
parent 16b7627b60
commit 3e0729c6cc
4 changed files with 71 additions and 103 deletions

View File

@ -48,103 +48,54 @@ try {
// list of all component events (default) // list of all component events (default)
//if ($jitsi_component) { $component = new Component($db);
try {
$component = new Component($db);
// prepare the result // prepare the result
$search = $component->jitsiComponents($jitsi_component, $component_id, $from_time, $until_time); $search = $component->jitsiComponents($jitsi_component, $component_id, $from_time, $until_time);
if (!empty($search)) { if (!empty($search)) {
$components = array(); $components = array();
$components['records'] = array(); $components['records'] = array();
foreach ($search as $item) { foreach ($search as $item) {
extract($item); extract($item);
$component_record = array( $component_record = array(
// assign title to the field in the array record // assign title to the field in the array record
'component' => $jitsi_component, 'component' => $jitsi_component,
'loglevel' => $loglevel, 'loglevel' => $loglevel,
'time' => $time, 'time' => $time,
'component ID' => $component_id, 'component ID' => $component_id,
'event' => $event_type, 'event' => $event_type,
'param' => $event_param, 'param' => $event_param,
); );
// populate the result array // populate the result array
array_push($components['records'], $component_record); array_push($components['records'], $component_record);
}
}
} catch (Exception $e) {
$error = 'Error: ' . $e->getMessage();
include 'templates/message.php';
exit();
} }
}
// display the result // prepare the widget
$widget['full'] = false;
$widget['name'] = 'AllComponents';
$widget['collapsible'] = false;
$widget['collapsed'] = false;
$widget['filter'] = true;
// format the header message // widget title
echo "<div class=\"results-header\">\n"; if (isset($_REQUEST['name']) && $_REQUEST['name'] != '') {
if (isset($_REQUEST['name']) && $_REQUEST['name'] != '') { $widget['title'] = 'Jitsi events for component <strong>' . $_REQUEST['name'] . '</strong>';
echo "<div class=\"results-message\">Jitsi events for component <strong>" . $_REQUEST['name'] . "</strong>"; } elseif (isset($_REQUEST['id']) && $_REQUEST['id'] != '') {
} elseif (isset($_REQUEST['id']) && $_REQUEST['id'] != '') { $widget['title'] = 'Jitsi events for component ID <br /><strong>' . $_REQUEST['id'] . '</strong>';
echo "<div class=\"results-message\">Jitsi events for component ID <br /><strong>" . $_REQUEST['id'] . "</strong>"; } else {
} else { $widget['title'] = 'Jitsi events for <strong>all components</strong>';
echo "<div class=\"results-message\">Jitsi events for <strong>all components</strong>"; }
} // widget records
if ($time_range_specified) { if (!empty($components['records'])) {
echo "<br />for the time period <strong>$from_time - $until_time</strong>"; $widget['full'] = true;
} $widget['table_headers'] = array_keys($components['records'][0]);
echo "</div>\n\n"; $widget['table_records'] = $components['records'];
}
// filters - time selection and sorting dropdowns // display the widget
include 'templates/results-filter.php'; include('templates/widget.php');
echo "</div>\n\n";
// results table
echo "<div class=\"mb-5\">\n";
if (!empty($components['records'])) {
echo "\t<table class=\"table table-striped table-hover table-bordered\">\n";
echo "\t\t<thead class=\"table-secondary\">\n";
echo "\t\t\t<tr>\n";
// table headers
foreach (array_keys($components['records'][0]) as $header) {
echo "\t\t\t\t<th scope=\"col\">" . htmlspecialchars($header) . "</th>\n";
}
echo "\t\t\t</tr>\n";
echo "\t\t</thead>\n";
echo "\t\t<tbody>\n";
//table rows
foreach ($components['records'] as $row) {
echo "\t\t\t<tr>\n";
// sometimes $column is empty, we make it '' then
foreach ($row as $key => $column) {
if ($key === 'component ID') {
echo "\t\t\t\t<td><a href=\"$app_root?page=components&id=" . htmlspecialchars($column ?? '') . "\">" . htmlspecialchars($column ?? '') . "</a></td>\n";
} elseif ($key === 'component') {
echo "\t\t\t\t<td><a href=\"$app_root?page=components&name=" . htmlspecialchars($column ?? '') . "\">" . htmlspecialchars($column ?? '') . "</a></td>\n";
} else {
echo "\t\t\t\t<td>" . htmlspecialchars($column ?? '') . "</td>\n";
}
}
echo "\t\t\t</tr>\n";
}
echo "\t\t</tbody>\n";
echo "\t</table>\n";
} else {
echo '<p class="m-3">No matching Jitsi component events found.</p>';
}
echo "\n</div>\n";
//}
?> ?>

View File

@ -68,6 +68,9 @@ try {
$widget['full'] = false; $widget['full'] = false;
$widget['name'] = 'LastDays'; $widget['name'] = 'LastDays';
$widget['title'] = 'Conferences for the last 2 days'; $widget['title'] = 'Conferences for the last 2 days';
$widget['collapsible'] = true;
$widget['collapsed'] = false;
$widget['filter'] = false;
if (!empty($conferences['records'])) { if (!empty($conferences['records'])) {
$widget['full'] = true; $widget['full'] = true;
$widget['table_headers'] = array_keys($conferences['records'][0]); $widget['table_headers'] = array_keys($conferences['records'][0]);
@ -138,6 +141,10 @@ try {
$widget['full'] = false; $widget['full'] = false;
$widget['name'] = 'LastConferences'; $widget['name'] = 'LastConferences';
$widget['title'] = 'The last ' . $conference_number . ' conferences'; $widget['title'] = 'The last ' . $conference_number . ' conferences';
$widget['collapsible'] = true;
$widget['collapsed'] = false;
$widget['filter'] = false;
if (!empty($conferences['records'])) { if (!empty($conferences['records'])) {
$widget['full'] = true; $widget['full'] = true;
$widget['table_headers'] = array_keys($conferences['records'][0]); $widget['table_headers'] = array_keys($conferences['records'][0]);

View File

@ -1,5 +1,5 @@
<div class="results-filter"> <div class="card w-auto bg-light card-body text-right">
<form method="POST" id="filter_form" action="?page=<?= $page ?>"> <form method="POST" id="filter_form" action="?page=<?= $page ?>">
@ -17,15 +17,9 @@
<input type="text" name="ip" placeholder="ip address"<?php if (isset($_REQUEST['ip'])) echo " value=\"" . $_REQUEST['ip'] . "\"" ?> maxlength="15" size="15" /> <input type="text" name="ip" placeholder="ip address"<?php if (isset($_REQUEST['ip'])) echo " value=\"" . $_REQUEST['ip'] . "\"" ?> maxlength="15" size="15" />
<?php } ?> <?php } ?>
<br /> <input type="button" onclick="clearFilter()" value="clear" />
<div class="float-end pt-3"> <input type="submit" value="search" />
<input type="button" onclick="clearFilter()" value="clear" />
<input type="submit" value="search" />
</div>
</form> </form>

View File

@ -1,13 +1,25 @@
<a style="text-decoration: none;" data-toggle="collapse" href="#collapse<?= $widget['name'] ?>" role="button" aria-expanded="true" aria-controls="collapse<?= $widget['name'] ?>"> <div class="row">
<div class="card bg-light card-body"><?= $widget['title'] ?></div></a>
<?php if ($widget['collapsible'] === true) { ?>
<a style="text-decoration: none;" data-toggle="collapse" href="#collapse<?= $widget['name'] ?>" role="button" aria-expanded="true" aria-controls="collapse<?= $widget['name'] ?>">
<?php } ?>
<div class="card w-25 bg-light card-body"><?= $widget['title'] ?></div>
<?php if ($widget['filter'] === true) {
include('templates/results-filter.php');
} ?>
<?php if ($widget['collapsible'] === true) { ?>
</a>
<?php } ?>
</div>
<div class="collapse show" id="collapse<?= $widget['name'] ?>"> <div class="collapse show" id="collapse<?= $widget['name'] ?>">
<?php if ($time_range_specified) { ?> <?php if ($time_range_specified) { ?>
<p class="m-3">time period: <strong><?= $from_time ?> - <?= $until_time ?></strong></p> <p class="m-3">time period: <strong><?= $from_time ?> - <?= $until_time ?></strong></p>
<?php } ?> <?php } ?>
<div class="mb-5"> <div class="mb-5">
<?php if ($widget['full'] == true) { ?> <?php if ($widget['full'] === true) { ?>
<table class="table table-striped table-hover table-bordered"> <table class="table table-striped table-hover table-bordered">
<thead class="thead-dark"> <thead class="thead-dark">
<tr> <tr>
@ -24,6 +36,10 @@
<td><a href="<?= $app_root ?>?page=conferences&id=<?= htmlspecialchars($column ?? '') ?>"><?= htmlspecialchars($column ?? '') ?></a></td> <td><a href="<?= $app_root ?>?page=conferences&id=<?= htmlspecialchars($column ?? '') ?>"><?= htmlspecialchars($column ?? '') ?></a></td>
<?php } elseif ($key === 'conference name') { ?> <?php } elseif ($key === 'conference name') { ?>
<td><a href="<?= $app_root ?>?page=conferences&name=<?= htmlspecialchars($column ?? '') ?>"><?= htmlspecialchars($column ?? '') ?></a></td> <td><a href="<?= $app_root ?>?page=conferences&name=<?= htmlspecialchars($column ?? '') ?>"><?= htmlspecialchars($column ?? '') ?></a></td>
<?php } elseif ($key === 'component ID') { ?>
<td><a href="<?= $app_root ?>?page=components&id=<?= htmlspecialchars($column ?? '') ?>"><?= htmlspecialchars($column ?? '') ?></a></td>
<?php } elseif ($key === 'component') { ?>
<td><a href="<?= $app_root ?>?page=components&name=<?= htmlspecialchars($column ?? '') ?>"><?= htmlspecialchars($column ?? '') ?></a></td>
<?php } else { ?> <?php } else { ?>
<td><?= htmlspecialchars($column ?? '') ?></td> <td><?= htmlspecialchars($column ?? '') ?></td>
<?php } <?php }