Skip to content

Commit

Permalink
Merge pull request #243 from ARCANEDEV/patch-compact
Browse files Browse the repository at this point in the history
Fixing the compact issue with missing variables
  • Loading branch information
arcanedev-maroc authored Oct 16, 2018
2 parents a8cd768 + 83f81f6 commit ec59381
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 44 deletions.
33 changes: 22 additions & 11 deletions resources/views/bootstrap-3/show.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
<?php
/**
* @var Arcanedev\LogViewer\Entities\Log $log
* @var Illuminate\Pagination\LengthAwarePaginator $entries
* @var string|null $query
*/
?>

@extends('log-viewer::bootstrap-3._master')

@section('content')
Expand Down Expand Up @@ -80,12 +88,16 @@
<form action="{{ route('log-viewer::logs.search', [$log->date, $level]) }}" method="GET">
<div class=form-group">
<div class="input-group">
<input id="query" name="query" class="form-control" value="{!! request('query') !!}" placeholder="Type here to search">
<input id="query" name="query" class="form-control" value="{!! $query !!}" placeholder="Type here to search">
<span class="input-group-btn">
@if (request()->has('query'))
<a href="{{ route('log-viewer::logs.show', [$log->date]) }}" class="btn btn-default"><span class="glyphicon glyphicon-remove"></span></a>
@endif
<button id="search-btn" class="btn btn-primary"><span class="glyphicon glyphicon-search"></span></button>
@unless (is_null($query))
<a href="{{ route('log-viewer::logs.show', [$log->date]) }}" class="btn btn-default">
<span class="glyphicon glyphicon-remove"></span>
</a>
@endunless
<button id="search-btn" class="btn btn-primary">
<span class="glyphicon glyphicon-search"></span>
</button>
</span>
</div>
</div>
Expand All @@ -97,10 +109,10 @@
<div class="panel panel-default">
@if ($entries->hasPages())
<div class="panel-heading">
{!! $entries->appends(compact('query'))->render() !!}
{{ $entries->appends(compact('query'))->render() }}
<span class="label label-info pull-right">
Page {!! $entries->currentPage() !!} of {!! $entries->lastPage() !!}
Page {{ $entries->currentPage() }} of {{ $entries->lastPage() }}
</span>
</div>
@endif
Expand All @@ -118,14 +130,13 @@
</thead>
<tbody>
@forelse($entries as $key => $entry)
<?php /** @var Arcanedev\LogViewer\Entities\LogEntry $entry */ ?>
<tr>
<td>
<span class="label label-env">{{ $entry->env }}</span>
</td>
<td>
<span class="level level-{{ $entry->level }}">
{!! $entry->level() !!}
</span>
<span class="level level-{{ $entry->level }}">{!! $entry->level() !!}</span>
</td>
<td>
<span class="label label-default">
Expand Down Expand Up @@ -168,7 +179,7 @@
{!! $entries->appends(compact('query'))->render() !!}

<span class="label label-info pull-right">
Page {!! $entries->currentPage() !!} of {!! $entries->lastPage() !!}
Page {{ $entries->currentPage() }} of {{ $entries->lastPage() }}
</span>
</div>
@endif
Expand Down
17 changes: 13 additions & 4 deletions resources/views/bootstrap-4/show.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
<?php
/**
* @var Arcanedev\LogViewer\Entities\Log $log
* @var Illuminate\Pagination\LengthAwarePaginator $entries
* @var string|null $query
*/
?>

@extends('log-viewer::bootstrap-4._master')

@section('content')
Expand Down Expand Up @@ -74,13 +82,13 @@
<form action="{{ route('log-viewer::logs.search', [$log->date, $level]) }}" method="GET">
<div class=form-group">
<div class="input-group">
<input id="query" name="query" class="form-control" value="{!! request('query') !!}" placeholder="Type here to search">
<input id="query" name="query" class="form-control" value="{!! $query !!}" placeholder="Type here to search">
<div class="input-group-append">
@if (request()->has('query'))
@unless (is_null($query))
<a href="{{ route('log-viewer::logs.show', [$log->date]) }}" class="btn btn-secondary">
<i class="fa fa-fw fa-times"></i>
</a>
@endif
@endunless
<button id="search-btn" class="btn btn-primary">
<span class="fa fa-fw fa-search"></span>
</button>
Expand All @@ -96,7 +104,7 @@
@if ($entries->hasPages())
<div class="card-header">
<span class="badge badge-info float-right">
Page {!! $entries->currentPage() !!} of {!! $entries->lastPage() !!}
Page {{ $entries->currentPage() }} of {{ $entries->lastPage() }}
</span>
</div>
@endif
Expand All @@ -114,6 +122,7 @@
</thead>
<tbody>
@forelse($entries as $key => $entry)
<?php /** @var Arcanedev\LogViewer\Entities\LogEntry $entry */ ?>
<tr>
<td>
<span class="badge badge-env">{{ $entry->env }}</span>
Expand Down
38 changes: 22 additions & 16 deletions src/Http/Controllers/LogViewerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,44 +85,48 @@ public function listLogs(Request $request)
$headers = $stats->header();
$rows = $this->paginate($stats->rows(), $request);

return $this->view('logs', compact('headers', 'rows', 'footer'));
return $this->view('logs', compact('headers', 'rows'));
}

/**
* Show the log.
*
* @param string $date
* @param string $date
* @param \Illuminate\Http\Request $request
*
* @return \Illuminate\View\View
*/
public function show($date)
public function show($date, Request $request)
{
$level = 'all';
$log = $this->getLogOrFail($date);
$query = $request->get('query');
$levels = $this->logViewer->levelsNames();
$entries = $log->entries($level = 'all')->paginate($this->perPage);
$entries = $log->entries($level)->paginate($this->perPage);

return $this->view('show', compact('log', 'levels', 'level', 'search', 'entries'));
return $this->view('show', compact('level', 'log', 'query', 'levels', 'entries'));
}

/**
* Filter the log entries by level.
*
* @param string $date
* @param string $level
* @param string $date
* @param string $level
* @param \Illuminate\Http\Request $request
*
* @return \Illuminate\View\View|\Illuminate\Http\RedirectResponse
*/
public function showByLevel($date, $level)
public function showByLevel($date, $level, Request $request)
{
$log = $this->getLogOrFail($date);

if ($level === 'all')
return redirect()->route($this->showRoute, [$date]);

$log = $this->getLogOrFail($date);
$query = $request->get('query');
$levels = $this->logViewer->levelsNames();
$entries = $this->logViewer->entries($date, $level)->paginate($this->perPage);

return $this->view('show', compact('log', 'levels', 'level', 'search', 'entries'));
return $this->view('show', compact('level', 'log', 'query', 'levels', 'entries'));
}

/**
Expand All @@ -134,18 +138,20 @@ public function showByLevel($date, $level)
*
* @return \Illuminate\View\View|\Illuminate\Http\RedirectResponse
*/
public function search($date, $level = 'all', Request $request) {
$log = $this->getLogOrFail($date);
public function search($date, $level = 'all', Request $request)
{
$query = $request->get('query');

if (is_null($query = $request->get('query')))
return redirect()->route('log-viewer::logs.show', [$date]);
if (is_null($query))
return redirect()->route($this->showRoute, [$date]);

$log = $this->getLogOrFail($date);
$levels = $this->logViewer->levelsNames();
$entries = $log->entries($level)->filter(function (LogEntry $value) use ($query) {
return Str::contains($value->header, $query);
})->paginate($this->perPage);

return $this->view('show', compact('log', 'levels', 'level', 'query', 'entries'));
return $this->view('show', compact('level', 'log', 'query', 'levels', 'entries'));
}

/**
Expand Down
26 changes: 13 additions & 13 deletions src/Utilities/LogChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,22 +265,22 @@ private function checkLogFiles()
*/
private function checkLogFile($path)
{
$status = true;
$file = basename($path);
$message = "The log file [$file] is valid.";

if ($this->isSingleLogFile($file)) {
$this->status = $status = false;
$this->messages['files'][$file] = $message =
"You have a single log file in your application, you should split the [$file] into separate log files.";
$status = true;
$filename = basename($path);
$message = "The log file [$filename] is valid.";

if ($this->isSingleLogFile($filename)) {
$this->status = $status = false;
$this->messages['files'][$filename] = $message =
"You have a single log file in your application, you should split the [$filename] into separate log files.";
}
elseif ($this->isInvalidLogDate($file)) {
$this->status = $status = false;
$this->messages['files'][$file] = $message =
"The log file [$file] has an invalid date, the format must be like laravel-YYYY-MM-DD.log.";
elseif ($this->isInvalidLogDate($filename)) {
$this->status = $status = false;
$this->messages['files'][$filename] = $message =
"The log file [$filename] has an invalid date, the format must be like laravel-YYYY-MM-DD.log.";
}

$this->files[$file] = compact('filename', 'status', 'message', 'path');
$this->files[$filename] = compact('filename', 'status', 'message', 'path');
}

/**
Expand Down

0 comments on commit ec59381

Please sign in to comment.