Add front button to Export
This commit is contained in:
parent
f9e7d2cdbe
commit
1d94b1773d
5 changed files with 52 additions and 0 deletions
34
app/Http/Controllers/Bo/ExportController.php
Normal file
34
app/Http/Controllers/Bo/ExportController.php
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Bo;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Jobs\ShowroomExport;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
|
||||
class ExportController extends Controller
|
||||
{
|
||||
/**
|
||||
* Export and download zip File
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\StreamedResponse
|
||||
*/
|
||||
public function exportToZip(): StreamedResponse
|
||||
{
|
||||
$exportedFiles = File::allFiles(storage_path('app/export'));
|
||||
\dispatch_sync(new ShowroomExport());
|
||||
$exportedFile = collect(File::allFiles(storage_path('app/export')))->diff($exportedFiles)->first();
|
||||
if (!$exportedFile) {
|
||||
response()->redirectToRoute('bo.dashboard')->withErrors([
|
||||
'Export failed to catch the exported file'
|
||||
])->throwResponse();
|
||||
}
|
||||
/** @var \Symfony\Component\Finder\SplFileInfo $exportedFile */
|
||||
return response()->streamDownload(function () use ($exportedFile) {
|
||||
echo $exportedFile->getContents();
|
||||
}, $exportedFile->getBasename(), [
|
||||
'Content-Type' => File::mimeType($exportedFile->getRealPath())
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -26,5 +26,8 @@ class AuthServiceProvider extends ServiceProvider
|
|||
Gate::define('isConceptor', function (User $user) {
|
||||
return $user->role === RoleEnum::conceptor;
|
||||
});
|
||||
Gate::define('exportZip', function (User $user) {
|
||||
return $user->role === RoleEnum::conceptor;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import {
|
|||
faEraser,
|
||||
faEye,
|
||||
faEyeSlash,
|
||||
faFileExport,
|
||||
faFolderOpen,
|
||||
faListUl,
|
||||
faPaintRoller,
|
||||
|
|
@ -88,5 +89,6 @@ library.add(faChevronRight);
|
|||
library.add(faCircleXmark);
|
||||
library.add(faCircleNotch);
|
||||
library.add(faSliders);
|
||||
library.add(faFileExport);
|
||||
|
||||
dom.watch();
|
||||
|
|
|
|||
|
|
@ -78,5 +78,14 @@
|
|||
</a>
|
||||
</li>
|
||||
@endcan
|
||||
|
||||
@can('exportZip')
|
||||
<li class="nav-item">
|
||||
<a class="nav-link btn btn-link" data-bs-toggle="tooltip" href="{{ route('bo.export') }}"
|
||||
title="{{ __('Exporter le zip de pour l\'application Borne') }}">
|
||||
<i class="fa-solid fa-file-export"></i>
|
||||
</a>
|
||||
</li>
|
||||
@endcan
|
||||
</ul>
|
||||
@endauth
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
use App\Http\Controllers\Bo\ActivityLogController;
|
||||
use App\Http\Controllers\Bo\BrandController;
|
||||
use App\Http\Controllers\Bo\DashboardController;
|
||||
use App\Http\Controllers\Bo\ExportController;
|
||||
use App\Http\Controllers\Bo\ProductController;
|
||||
use App\Http\Controllers\Bo\RangeController;
|
||||
use App\Http\Controllers\Bo\SettingsController;
|
||||
|
|
@ -31,6 +32,9 @@ Route::prefix('bo')
|
|||
Route::middleware('auth:backend')->group(function () {
|
||||
Route::get('/', [DashboardController::class, 'index'])->name('dashboard');
|
||||
|
||||
// * EXPORT.
|
||||
Route::get('export', [ExportController::class, 'exportToZip'])->name('export');
|
||||
|
||||
// * USERS.
|
||||
Route::resource('users', UserController::class)->except('show');
|
||||
Route::patch('/users/{user}/change-published', [
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue