-
-
Notifications
You must be signed in to change notification settings - Fork 297
Adding alphabetical file sorting #472
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
namespace Opcodes\LogViewer\Http\Controllers; | ||
|
||
use Opcodes\LogViewer\Enums\FolderSortingMethod; | ||
use Opcodes\LogViewer\Facades\LogViewer; | ||
use Opcodes\LogViewer\LogFolder; | ||
use Opcodes\LogViewer\Utils\Utils; | ||
|
@@ -14,6 +15,8 @@ public function __invoke() | |
abort(404); | ||
} | ||
|
||
$log_sort_by_time = config('log-viewer.defaults.log_sorting_method') === FolderSortingMethod::ModifiedTime; | ||
|
||
return view(LogViewer::getViewLayout(), [ | ||
'logViewerScriptVariables' => [ | ||
'headers' => (object) [], | ||
|
@@ -23,6 +26,7 @@ public function __invoke() | |
'path' => config('log-viewer.route_path'), | ||
'back_to_system_url' => config('log-viewer.back_to_system_url'), | ||
'back_to_system_label' => config('log-viewer.back_to_system_label'), | ||
'log_sort_by_time' => $log_sort_by_time, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here, call it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll try to get it done as quickly as possible |
||
'max_log_size_formatted' => Utils::bytesForHumans(LogViewer::maxLogSize()), | ||
'show_support_link' => config('log-viewer.show_support_link', true), | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
use Opcodes\LogViewer\Enums\FolderSortingMethod; | ||
|
||
use function Pest\Laravel\getJson; | ||
|
||
beforeEach(function () { | ||
config(['log-viewer.include_files' => ['*.log']]); | ||
}); | ||
|
||
it('you can get alphabetically sorted default desc logs files controller', function () { | ||
config(['log-viewer.defaults.log_sorting_method' => FolderSortingMethod::Alphabetical]); | ||
|
||
generateLogFiles([ | ||
'one.log', | ||
'two.log', | ||
'three.log', | ||
'four.log', | ||
], randomContent: true); | ||
|
||
$response = getJson(route('log-viewer.files')); | ||
|
||
expect(array_column($response->json(), 'name'))->toBe([ | ||
'two.log', | ||
'three.log', | ||
'one.log', | ||
'four.log', | ||
]); | ||
}); | ||
|
||
it('you can get alphabetically sorted asc logs files controller', function () { | ||
config(['log-viewer.defaults.log_sorting_method' => FolderSortingMethod::Alphabetical]); | ||
|
||
generateLogFiles([ | ||
'one.log', | ||
'two.log', | ||
'three.log', | ||
'four.log', | ||
], randomContent: true); | ||
|
||
$response = getJson(route('log-viewer.files', ['direction' => 'asc'])); | ||
|
||
expect(array_column($response->json(), 'name'))->toBe([ | ||
'four.log', | ||
'one.log', | ||
'three.log', | ||
'two.log', | ||
]); | ||
}); | ||
|
||
it('you can get alphabetically sorted desc logs files controller', function () { | ||
config(['log-viewer.defaults.log_sorting_method' => FolderSortingMethod::Alphabetical]); | ||
|
||
generateLogFiles([ | ||
'one.log', | ||
'two.log', | ||
'three.log', | ||
'four.log', | ||
], randomContent: true); | ||
|
||
$response = getJson(route('log-viewer.files', ['direction' => 'desc'])); | ||
|
||
expect(array_column($response->json(), 'name'))->toBe([ | ||
'two.log', | ||
'three.log', | ||
'one.log', | ||
'four.log', | ||
]); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
use Opcodes\LogViewer\Enums\FolderSortingMethod; | ||
|
||
use function Pest\Laravel\getJson; | ||
|
||
beforeEach(function () { | ||
config(['log-viewer.include_files' => ['*.log']]); | ||
}); | ||
|
||
it('you can get time sorted default desc logs files controller', function () { | ||
config(['log-viewer.defaults.log_sorting_method' => FolderSortingMethod::ModifiedTime]); | ||
|
||
$names = [ | ||
'one.log', | ||
'two.log', | ||
'three.log', | ||
]; | ||
generateLogFiles($names, randomContent: true); | ||
array_map(function (string $name) { | ||
$this->travelTo(now()->addSecond()); | ||
touch(storage_path('logs/'.$name), now()->timestamp); | ||
}, $names); | ||
|
||
$response = getJson(route('log-viewer.files')); | ||
|
||
expect(array_column($response->json(), 'name'))->toBe([ | ||
'three.log', | ||
'two.log', | ||
'one.log', | ||
]); | ||
}); | ||
|
||
it('you can get time sorted desc logs files controller', function () { | ||
config(['log-viewer.defaults.log_sorting_method' => FolderSortingMethod::ModifiedTime]); | ||
|
||
$names = [ | ||
'one.log', | ||
'two.log', | ||
'three.log', | ||
]; | ||
generateLogFiles($names, randomContent: true); | ||
array_map(function (string $name) { | ||
$this->travelTo(now()->addSecond()); | ||
touch(storage_path('logs/'.$name), now()->timestamp); | ||
}, $names); | ||
|
||
$response = getJson(route('log-viewer.files', ['direction' => 'desc'])); | ||
// dd($response->json()); | ||
|
||
expect(array_column($response->json(), 'name'))->toBe([ | ||
'three.log', | ||
'two.log', | ||
'one.log', | ||
]); | ||
}); | ||
|
||
it('you can get time sorted asc logs files controller', function () { | ||
config(['log-viewer.defaults.log_sorting_method' => FolderSortingMethod::ModifiedTime]); | ||
|
||
$names = [ | ||
'one.log', | ||
'two.log', | ||
'three.log', | ||
]; | ||
generateLogFiles($names, randomContent: true); | ||
array_map(function (string $name) { | ||
$this->travelTo(now()->addSecond()); | ||
touch(storage_path('logs/'.$name), now()->timestamp); | ||
}, $names); | ||
|
||
$response = getJson(route('log-viewer.files', ['direction' => 'asc'])); | ||
|
||
expect(array_column($response->json(), 'name'))->toBe([ | ||
'one.log', | ||
'two.log', | ||
'three.log', | ||
]); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
use Opcodes\LogViewer\Enums\FolderSortingMethod; | ||
|
||
use function Pest\Laravel\getJson; | ||
|
||
beforeEach(function () { | ||
clearGeneratedLogFiles(); | ||
config(['log-viewer.include_files' => ['*/**.log']]); | ||
}); | ||
|
||
it('you can get alphabetically sorted default desc logs folders controller', function () { | ||
config(['log-viewer.defaults.log_sorting_method' => FolderSortingMethod::Alphabetical]); | ||
|
||
generateLogFiles([ | ||
'sub/one.log', | ||
'sub/two.log', | ||
'sub/three.log', | ||
'sub/four.log', | ||
], randomContent: true); | ||
|
||
$response = getJson(route('log-viewer.folders')); | ||
|
||
expect(array_column($response->json()[0]['files'], 'name'))->toBe([ | ||
'two.log', | ||
'three.log', | ||
'one.log', | ||
'four.log', | ||
]); | ||
}); | ||
|
||
it('you can get alphabetically sorted asc logs folders controller', function () { | ||
config(['log-viewer.defaults.log_sorting_method' => FolderSortingMethod::Alphabetical]); | ||
|
||
generateLogFiles([ | ||
'sub/one.log', | ||
'sub/two.log', | ||
'sub/three.log', | ||
'sub/four.log', | ||
], randomContent: true); | ||
|
||
$response = getJson(route('log-viewer.folders', ['direction' => 'asc'])); | ||
|
||
expect(array_column($response->json()[0]['files'], 'name'))->toBe([ | ||
'four.log', | ||
'one.log', | ||
'three.log', | ||
'two.log', | ||
]); | ||
}); | ||
|
||
it('you can get alphabetically sorted desc logs folders controller', function () { | ||
config(['log-viewer.defaults.log_sorting_method' => FolderSortingMethod::Alphabetical]); | ||
|
||
generateLogFiles([ | ||
'sub/one.log', | ||
'sub/two.log', | ||
'sub/three.log', | ||
'sub/four.log', | ||
], randomContent: true); | ||
|
||
$response = getJson(route('log-viewer.folders', ['direction' => 'desc'])); | ||
|
||
expect(array_column($response->json()[0]['files'], 'name'))->toBe([ | ||
'two.log', | ||
'three.log', | ||
'one.log', | ||
'four.log', | ||
]); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's an important distinction between a "log" and a "file". Logs are individual log entries within a file, and here we want to sort files, not logs.
Call it
file_sorting_method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, I'll correct that