Просмотр исходного кода

Add log search to the logs page (#9059)

* Add log search to the logs page

Closes #8471. Adds a search field and filters log level, timestamp, and message before pagination

* Fix log search formatting

* Type the log search view property

* Fix missing i18n
Another option could be `index.menu.search_short`

* Fix form submit

---------

Co-authored-by: Gerard Alvear <gerard.alvear@logiqd.me>
Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>
Gerard Alvear Porras 3 дней назад
Родитель
Сommit
7321c1e9fb
3 измененных файлов с 17 добавлено и 0 удалено
  1. 8 0
      app/Controllers/indexController.php
  2. 1 0
      app/Models/View.php
  3. 8 0
      app/views/index/logs.phtml

+ 8 - 0
app/Controllers/indexController.php

@@ -452,6 +452,14 @@ class FreshRSS_index_Controller extends FreshRSS_ActionController {
 		}
 
 		$logs = FreshRSS_LogDAO::lines();	//TODO: ask only the necessary lines
+		$search = trim(Minz_Request::paramString('search', plaintext: true));
+		if ($search !== '') {
+			$logs = array_values(array_filter($logs, static fn(FreshRSS_Log $log): bool =>
+				stripos($log->level(), $search) !== false ||
+				stripos($log->date(), $search) !== false ||
+				stripos($log->info(), $search) !== false));
+		}
+		$this->view->logSearch = $search;
 
 		//gestion pagination
 		$page = Minz_Request::paramInt('page') ?: 1;

+ 1 - 0
app/Models/View.php

@@ -110,6 +110,7 @@ class FreshRSS_View extends Minz_View {
 	public int $currentPage;
 	public Minz_Paginator $logsPaginator;
 	public int $nbPage;
+	public string $logSearch = '';
 
 	// RSS view
 	public FreshRSS_UserQuery $userQuery;

+ 8 - 0
app/views/index/logs.phtml

@@ -6,6 +6,14 @@
 <main class="post">
 	<h1><?= _t('index.log') ?></h1>
 
+	<form method="get" action="<?= _url('index', 'logs') ?>" class="form-inline">
+		<input type="hidden" name="c" value="index" />
+		<input type="hidden" name="a" value="logs" />
+		<label for="log-search"><?= _t('gen.action.filter') ?></label>
+		<input type="search" id="log-search" name="search" value="<?= htmlspecialchars($this->logSearch, ENT_COMPAT, 'UTF-8') ?>" />
+		<button type="submit" class="btn"><?= _t('gen.action.filter') ?></button>
+	</form>
+
 	<?php
 		/** @var list<FreshRSS_Log> $items */
 		$items = $this->logsPaginator->items();