Add downloads page
This commit is contained in:
parent
36a7886668
commit
3dba586f83
@ -54,7 +54,7 @@ class FileController extends Controller
|
||||
$file = $request->file('file');
|
||||
$this->fileSvc->saveFile($file, 'files', [
|
||||
'name' => $attrs['filename'],
|
||||
'description' => $attrs['file_descriptoin'],
|
||||
'description' => $attrs['file_description'],
|
||||
'ref_model' => $attrs['ref_model'],
|
||||
'ref_model_id' => $attrs['ref_model_id'],
|
||||
]);
|
||||
|
85
app/Http/Controllers/Frontend/DownloadController.php
Normal file
85
app/Http/Controllers/Frontend/DownloadController.php
Normal file
@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Frontend;
|
||||
|
||||
use App\Interfaces\Controller;
|
||||
use App\Models\File;
|
||||
use Auth;
|
||||
use Flash;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
/**
|
||||
* Class DownloadController
|
||||
* @package App\Http\Controllers\Frontend
|
||||
*/
|
||||
class DownloadController extends Controller
|
||||
{
|
||||
/**
|
||||
* Show all of the available files
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$files = File::orderBy('ref_model', 'asc')->get();
|
||||
|
||||
/**
|
||||
* Group all the files but compound the model with the ID,
|
||||
* since we can have multiple files for every `ref_model`
|
||||
*/
|
||||
$grouped_files = $files->groupBy(function($item, $key) {
|
||||
return $item['ref_model'].'_'.$item['ref_model_id'];
|
||||
});
|
||||
|
||||
/**
|
||||
* The $group here looks like: App\Models\Airport_KAUS
|
||||
* Split it into the $class and $id, and then change the
|
||||
* name of the group to the object instance "name"
|
||||
*/
|
||||
$regrouped_files = [];
|
||||
foreach($grouped_files as $group => $files) {
|
||||
[$class, $id] = explode('_', $group);
|
||||
$klass = new $class();
|
||||
$obj = $klass->find($id);
|
||||
|
||||
$category = explode('\\', $class);
|
||||
$category = end($category);
|
||||
|
||||
$group_name = $category.' - '.$obj->name;
|
||||
$regrouped_files[$group_name] = $files;
|
||||
}
|
||||
|
||||
return view('downloads.index', [
|
||||
'grouped_files' => $regrouped_files,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the application dashboard.
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
/**
|
||||
* @var File $file
|
||||
*/
|
||||
$file = File::find($id);
|
||||
if (!$file) {
|
||||
Flash::error('File doesn\'t exist');
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
// Allowed to download? If not, direct to login
|
||||
if (!$file->public && !Auth::check()) {
|
||||
return redirect(config('app.login_redirect'));
|
||||
}
|
||||
|
||||
++$file->download_count;
|
||||
$file->save();
|
||||
|
||||
if($file->disk === 'public') {
|
||||
$storage = Storage::disk('public');
|
||||
return $storage->download($file->path, $file->filename);
|
||||
}
|
||||
|
||||
// TODO: Config for streamed response?
|
||||
return redirect()->to($file->url);
|
||||
}
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Frontend;
|
||||
|
||||
use App\Interfaces\Controller;
|
||||
use App\Models\File;
|
||||
use Auth;
|
||||
use Flash;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
/**
|
||||
* Class FileController
|
||||
* @package App\Http\Controllers\Frontend
|
||||
*/
|
||||
class FileController extends Controller
|
||||
{
|
||||
/**
|
||||
* Show the application dashboard.
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
/**
|
||||
* @var File $file
|
||||
*/
|
||||
$file = File::find($id);
|
||||
if (!$file) {
|
||||
Flash::error('File doesn\'t exist');
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
// Allowed to download? If not, direct to login
|
||||
if (!$file->public && !Auth::check()) {
|
||||
return redirect(config('app.login_redirect'));
|
||||
}
|
||||
|
||||
++$file->download_count;
|
||||
$file->save();
|
||||
|
||||
if($file->disk === 'public') {
|
||||
$storage = Storage::disk('public');
|
||||
return $storage->download($file->path, $file->filename);
|
||||
}
|
||||
|
||||
// TODO: Config for streamed response?
|
||||
return redirect()->to($file->url);
|
||||
}
|
||||
}
|
@ -10,10 +10,10 @@ Route::group([
|
||||
Route::get('r/{id}', 'PirepController@show')->name('pirep.show.public');
|
||||
Route::get('p/{id}', 'ProfileController@show')->name('profile.show.public');
|
||||
|
||||
Route::get('users', 'UserController@index')->name('users.show');
|
||||
Route::get('pilots', 'UserController@index')->name('users.show');
|
||||
Route::get('users', 'UserController@index')->name('users.index');
|
||||
Route::get('pilots', 'UserController@index')->name('pilots.index');
|
||||
|
||||
Route::get('livemap', 'AcarsController@index')->name('livemap.public');
|
||||
Route::get('livemap', 'AcarsController@index')->name('livemap.index');
|
||||
});
|
||||
|
||||
/**
|
||||
@ -28,7 +28,8 @@ Route::group([
|
||||
Route::get('airports/{id}', 'AirportController@show')->name('airports.show');
|
||||
|
||||
// Download a file
|
||||
Route::get('files/{id}', 'FileController@show')->name('files.show');
|
||||
Route::get('downloads', 'DownloadController@index')->name('downloads.index');
|
||||
Route::get('downloads/{id}', 'DownloadController@show')->name('downloads.download');
|
||||
|
||||
Route::get('flights/bids', 'FlightController@bids')->name('flights.bids');
|
||||
Route::get('flights/search', 'FlightController@search')->name('flights.search');
|
||||
|
@ -29,21 +29,7 @@
|
||||
@if($airport->files && Auth::check())
|
||||
<div class="col-12">
|
||||
<h3 class="description">Downloads</h3>
|
||||
<ul class="list-group">
|
||||
@foreach($airport->files as $file)
|
||||
<li class="list-group-item">
|
||||
<a href="{{route('frontend.files.show', [$file->id])}}" target="_blank">
|
||||
{{ $file->name }}
|
||||
</a>
|
||||
|
||||
{{-- only show description is one is provided --}}
|
||||
@if($file->description)
|
||||
- {{$file->description}}
|
||||
@endif
|
||||
<span style="margin-left: 20px">{{$file->download_count}} downloads</span>
|
||||
</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
@include('files.table', ['files' => $airport->files])
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
|
23
resources/views/layouts/default/downloads/index.blade.php
Normal file
23
resources/views/layouts/default/downloads/index.blade.php
Normal file
@ -0,0 +1,23 @@
|
||||
@extends('app')
|
||||
@section('title', 'downloads')
|
||||
|
||||
@section('content')
|
||||
@include('flash::message')
|
||||
<div class="row">
|
||||
<div class="row-sm-12">
|
||||
<h2 class="description">Downloads</h2>
|
||||
</div>
|
||||
</div>
|
||||
@foreach($grouped_files as $group => $files)
|
||||
<div class="row" style="margin-bottom: 40px;">
|
||||
<div class="col-12">
|
||||
<h4 class="description">{{ $group }}</h4>
|
||||
</div>
|
||||
|
||||
<div class="col-12">
|
||||
@include('downloads.table', ['files' => $files])
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
@endsection
|
||||
|
15
resources/views/layouts/default/downloads/table.blade.php
Normal file
15
resources/views/layouts/default/downloads/table.blade.php
Normal file
@ -0,0 +1,15 @@
|
||||
<ul class="list-group">
|
||||
@foreach($files as $file)
|
||||
<li class="list-group-item">
|
||||
<a href="{{route('frontend.downloads.download', [$file->id])}}" target="_blank">
|
||||
{{ $file->name }}
|
||||
</a>
|
||||
|
||||
{{-- only show description is one is provided --}}
|
||||
@if($file->description)
|
||||
- {{$file->description}}
|
||||
@endif
|
||||
<span style="margin-left: 20px">{{$file->download_count}} downloads</span>
|
||||
</li>
|
||||
@endforeach
|
||||
</ul>
|
@ -1,7 +1,7 @@
|
||||
<ul class="navbar-nav">
|
||||
@if(Auth::check())
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{{ url('/dashboard') }}">
|
||||
<a class="nav-link" href="{{ route('frontend.dashboard.index') }}">
|
||||
<i class="fas fa-tachometer-alt"></i>
|
||||
<p>Dashboard</p>
|
||||
</a>
|
||||
@ -9,14 +9,14 @@
|
||||
@endif
|
||||
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{{ url('/livemap') }}">
|
||||
<a class="nav-link" href="{{ route('frontend.livemap.index') }}">
|
||||
<i class="fas fa-globe"></i>
|
||||
<p>Live Map</p>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{{ url('/pilots') }}">
|
||||
<a class="nav-link" href="{{ route('frontend.pilots.index') }}">
|
||||
<i class="fas fa-users"></i>
|
||||
<p>Pilots</p>
|
||||
</a>
|
||||
@ -49,23 +49,29 @@
|
||||
@else
|
||||
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{{ url('/flights') }}">
|
||||
<a class="nav-link" href="{{ route('frontend.flights.index') }}">
|
||||
<i class="fab fa-avianex"></i>
|
||||
<p>Flights</p>
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{{ url('/pireps') }}">
|
||||
<a class="nav-link" href="{{ route('frontend.pireps.index') }}">
|
||||
<i class="fas fa-cloud-upload-alt"></i>
|
||||
<p>PIREPs</p>
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{{ url('/profile') }}">
|
||||
<a class="nav-link" href="{{ route('frontend.profile.index') }}">
|
||||
<i class="far fa-user"></i>
|
||||
<p>Profile</p>
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{{ route('frontend.downloads.index') }}">
|
||||
<i class="fas fa-download"></i>
|
||||
<p>Downloads</p>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
@role('admin')
|
||||
<li class="nav-item">
|
||||
|
Loading…
Reference in New Issue
Block a user