Skip to content

Commit 1a4d190

Browse files
cinorap2hpoutre
authored andcommitted
Add 'delete all files' & only show download/delete links when possible (#84)
* Add 'delete all files' option & only show download/delete links when possible * Confirm dialog for delete-all-log * Return to /logs instead of /logs?delall=true
1 parent 75d0261 commit 1a4d190

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

src/controllers/LogViewerController.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,15 @@ public function index()
2828
} elseif ($this->request->has('del')) {
2929
app('files')->delete(LaravelLogViewer::pathToLogFile(base64_decode($this->request->input('del'))));
3030
return $this->redirect($this->request->url());
31+
} elseif ($this->request->has('delall')){
32+
foreach(LaravelLogViewer::getFiles(true) as $file){
33+
app('files')->delete(LaravelLogViewer::pathToLogFile($file));
34+
}
35+
return $this->redirect($this->request->url());
3136
}
3237

33-
$logs = LaravelLogViewer::all();
34-
3538
return app('view')->make('laravel-log-viewer::log', [
36-
'logs' => $logs,
39+
'logs' => LaravelLogViewer::all(),
3740
'files' => LaravelLogViewer::getFiles(true),
3841
'current_file' => LaravelLogViewer::getFileName()
3942
]);

src/views/log.blade.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,15 @@
9191
</table>
9292
@endif
9393
<div>
94-
<a href="?dl={{ base64_encode($current_file) }}"><span class="glyphicon glyphicon-download-alt"></span> Download file</a>
95-
-
96-
<a id="delete-log" href="?del={{ base64_encode($current_file) }}"><span class="glyphicon glyphicon-trash"></span> Delete file</a>
94+
@if($current_file)
95+
<a href="?dl={{ base64_encode($current_file) }}"><span class="glyphicon glyphicon-download-alt"></span> Download file</a>
96+
-
97+
<a id="delete-log" href="?del={{ base64_encode($current_file) }}"><span class="glyphicon glyphicon-trash"></span> Delete file</a>
98+
@if(count($files) > 1)
99+
-
100+
<a id="delete-all-log" href="?delall=true"><span class="glyphicon glyphicon-trash"></span> Delete all files</a>
101+
@endif
102+
@endif
97103
</div>
98104
</div>
99105
</div>
@@ -119,7 +125,7 @@
119125
$('.table-container').on('click', '.expand', function(){
120126
$('#' + $(this).data('display')).toggle();
121127
});
122-
$('#delete-log').click(function(){
128+
$('#delete-log, #delete-all-log').click(function(){
123129
return confirm('Are you sure?');
124130
});
125131
});

0 commit comments

Comments
 (0)