This commit is contained in:
jqh 2020-07-10 14:37:20 +08:00
parent 2ed3d0a624
commit 4c77f96f24
4 changed files with 19 additions and 19 deletions

View File

@ -248,13 +248,13 @@
<form action="{{ route('dcat-log-viewer') }}" style="display: inline-block;width: 220px;padding-left: 15px"> <form action="{{ route('dcat-log-viewer') }}" style="display: inline-block;width: 220px;padding-left: 15px">
<div class="input-group-sm" style="display: inline-block;width: 100%"> <div class="input-group-sm" style="display: inline-block;width: 100%">
<input name="filename" class="form-control" value="{{ request('filename') }}" type="text" placeholder="Search..." /> <input name="filename" class="form-control" value="{{ app('request')->get('filename') }}" type="text" placeholder="Search..." />
</div> </div>
</form> </form>
<div class="box-body no-padding"> <div class="box-body no-padding">
<ul class="nav nav-pills nav-stacked"> <ul class="nav nav-pills nav-stacked">
@if(! request('filename')) @if(! app('request')->get('filename'))
@foreach($logDirs as $d) @foreach($logDirs as $d)
<li @if($d === $fileName) class="active" @endif> <li @if($d === $fileName) class="active" @endif>
<a class="dir" href="{{ route('dcat-log-viewer', ['dir' => $d]) }}"> <a class="dir" href="{{ route('dcat-log-viewer', ['dir' => $d]) }}">
@ -284,18 +284,18 @@
<div class="col-md-10"> <div class="col-md-10">
<div class="box box-primary"> <div class="box box-primary">
<div class="box-header with-border"> <div class="box-header with-border">
<a href="{{ route('dcat-log-viewer.download', ['dir' => $dir, 'file' => $fileName]) }}" class="btn btn-primary btn-sm download" style="color: #fff"><i class="fa-download fa"></i> {{ __('Download') }}</a> <a href="{{ route('dcat-log-viewer.download', ['dir' => $dir, 'file' => $fileName]) }}" class="btn btn-primary btn-sm download" style="color: #fff"><i class="fa-download fa"></i> {{ trans('Download') }}</a>
{{-- <button class="btn btn-default btn-sm download"><i class="fa-trash-o fa"></i> {{ __('Delete') }}</button>--}} {{-- <button class="btn btn-default btn-sm download"><i class="fa-trash-o fa"></i> {{ trans('Delete') }}</button>--}}
&nbsp; &nbsp;
<form style="display: inline-block;width: 180px"> <form style="display: inline-block;width: 180px">
<div class="input-group-sm" style="display: inline-block;width: 100%"> <div class="input-group-sm" style="display: inline-block;width: 100%">
<input name="keyword" class="form-control" value="{{ request('keyword') }}" type="text" placeholder="Search..." /> <input name="keyword" class="form-control" value="{{ app('request')->get('keyword') }}" type="text" placeholder="Search..." />
</div> </div>
</form> </form>
<div class="float-right"> <div class="float-right">
<a class=""><strong>Size:</strong> {{ $size }} &nbsp; <strong>Updated at:</strong> <a class=""><strong>Size:</strong> {{ $size }} &nbsp; <strong>Updated at:</strong>
{{ \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', date('Y-m-d H:i:s', filectime($filePath)))->diffForHumans() }}</a> {{ date('Y-m-d H:i:s', filectime($filePath)) }}</a>
&nbsp; &nbsp;
<div class="btn-group"> <div class="btn-group">
@if ($prevUrl) @if ($prevUrl)

View File

@ -2,8 +2,6 @@
namespace Dcat\LogViewer; namespace Dcat\LogViewer;
use Illuminate\Routing\Router;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
class DcatLogViewerServiceProvider extends ServiceProvider class DcatLogViewerServiceProvider extends ServiceProvider
@ -21,14 +19,14 @@ class DcatLogViewerServiceProvider extends ServiceProvider
protected function registerRoutes() protected function registerRoutes()
{ {
Route::group([ app('router')->group([
'prefix' => config('dcat-log-viewer.route.prefix', 'dcat-logs'), 'prefix' => config('dcat-log-viewer.route.prefix', 'dcat-logs'),
'namespace' => config('dcat-log-viewer.route.namespace', 'Dcat\LogViewer'), 'namespace' => config('dcat-log-viewer.route.namespace', 'Dcat\LogViewer'),
'middleware' => config('dcat-log-viewer.route.middleware'), 'middleware' => config('dcat-log-viewer.route.middleware'),
], function (Router $router) { ], function ($router) {
$router->get('/', 'LogController@index')->name('dcat-log-viewer'); $router->get('/', ['as' => 'dcat-log-viewer', 'uses' => 'LogController@index',]);
$router->get('{file}', 'LogController@index')->name('dcat-log-viewer.file'); $router->get('{file}', ['as' => 'dcat-log-viewer.file', 'uses' => 'LogController@index',]);
$router->get('download/{file}', 'LogController@download')->name('dcat-log-viewer.download'); $router->get('download/{file}', ['as' => 'dcat-log-viewer.download', 'uses' => 'LogController@download',]);
}); });
} }
} }

View File

@ -8,10 +8,12 @@ class LogController
{ {
public function index($file = null) public function index($file = null)
{ {
$dir = trim(request('dir')); $request = app('request');
$filename = trim(request('filename'));
$offset = request('offset'); $dir = trim($request->get('dir'));
$keyword = trim(request('keyword')); $filename = trim($request->get('filename'));
$offset = $request->get('offset');
$keyword = trim($request->get('keyword'));
$lines = $keyword ? (config('dcat-log-viewer.search_page_items') ?: 500) : (config('dcat-log-viewer.page_items') ?: 30); $lines = $keyword ? (config('dcat-log-viewer.search_page_items') ?: 500) : (config('dcat-log-viewer.page_items') ?: 30);
$viewer = new LogViewer($this->getDirectory(), $dir, $file); $viewer = new LogViewer($this->getDirectory(), $dir, $file);

View File

@ -98,7 +98,7 @@ class LogViewer
public function setKeyword($value) public function setKeyword($value)
{ {
$this->keyword = $value; $this->keyword = strtolower($value);
} }
public function setFilename($value) public function setFilename($value)
@ -261,7 +261,7 @@ class LogViewer
$result = []; $result = [];
foreach ($logs as $log) { foreach ($logs as $log) {
if (Str::contains(implode(' ', $log), $this->keyword)) { if (Str::contains(strtolower(implode(' ', $log)), $this->keyword)) {
$result[] = $log; $result[] = $log;
} }
} }