M3 Integration fixes
This commit is contained in:
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
+16
-20
@@ -15,6 +15,10 @@ use Modules\Documentation\Models\DocumentationDocument;
|
||||
|
||||
class DocumentationController extends Controller
|
||||
{
|
||||
private const string STORAGE_DISK_CONFIG = 'documentation.storage_disk';
|
||||
|
||||
private const string UPLOAD_PATH_CONFIG = 'documentation.upload_path';
|
||||
|
||||
/**
|
||||
* Display the documentation dashboard and document list.
|
||||
*/
|
||||
@@ -170,7 +174,7 @@ class DocumentationController extends Controller
|
||||
{
|
||||
abort_if(blank($document->attachment_path), 404);
|
||||
|
||||
return Storage::disk($document->attachment_disk ?: config('documentation.storage_disk', 'public'))
|
||||
return Storage::disk($document->attachment_disk ?: config(self::STORAGE_DISK_CONFIG, 'public'))
|
||||
->download($document->attachment_path, $document->attachment_name);
|
||||
}
|
||||
|
||||
@@ -202,27 +206,19 @@ class DocumentationController extends Controller
|
||||
*/
|
||||
private function extractMarkdownBody(Request $request): ?string
|
||||
{
|
||||
if (! config('documentation.import_markdown_attachments', true)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$file = $request->file('attachment');
|
||||
$canImport = config('documentation.import_markdown_attachments', true)
|
||||
&& $file !== null
|
||||
&& $this->isMarkdownUpload($request)
|
||||
&& $file->getSize() <= (int) config('documentation.max_markdown_import_bytes', 1048576);
|
||||
|
||||
if ($file === null || ! $this->isMarkdownUpload($request)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($file->getSize() > (int) config('documentation.max_markdown_import_bytes', 1048576)) {
|
||||
if (! $canImport) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$content = file_get_contents($file->getRealPath());
|
||||
|
||||
if ($content === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return trim($content);
|
||||
return $content === false ? null : trim($content);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -250,8 +246,8 @@ class DocumentationController extends Controller
|
||||
private function storeAttachment(Request $request): array
|
||||
{
|
||||
$file = $request->file('attachment');
|
||||
$disk = config('documentation.storage_disk', 'public');
|
||||
$path = $file->store(config('documentation.upload_path', 'documentation'), $disk);
|
||||
$disk = config(self::STORAGE_DISK_CONFIG, 'public');
|
||||
$path = $file->store(config(self::UPLOAD_PATH_CONFIG, 'documentation'), $disk);
|
||||
|
||||
return [
|
||||
'attachment_disk' => $disk,
|
||||
@@ -271,14 +267,14 @@ class DocumentationController extends Controller
|
||||
return;
|
||||
}
|
||||
|
||||
$disk = config('documentation.storage_disk', 'public');
|
||||
$disk = config(self::STORAGE_DISK_CONFIG, 'public');
|
||||
|
||||
foreach ((array) $request->file('attachments') as $file) {
|
||||
if ($file === null || ! $file->isValid()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$path = $file->store(config('documentation.upload_path', 'documentation'), $disk);
|
||||
$path = $file->store(config(self::UPLOAD_PATH_CONFIG, 'documentation'), $disk);
|
||||
|
||||
$document->attachments()->create([
|
||||
'disk' => $disk,
|
||||
@@ -297,7 +293,7 @@ class DocumentationController extends Controller
|
||||
private function deleteAttachment(DocumentationDocument $document): void
|
||||
{
|
||||
if (filled($document->attachment_path)) {
|
||||
Storage::disk($document->attachment_disk ?: config('documentation.storage_disk', 'public'))->delete($document->attachment_path);
|
||||
Storage::disk($document->attachment_disk ?: config(self::STORAGE_DISK_CONFIG, 'public'))->delete($document->attachment_path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
+8
-10
@@ -52,18 +52,16 @@ class DocumentationAttachment extends Model
|
||||
{
|
||||
$bytes = (int) $this->size;
|
||||
|
||||
$label = number_format($bytes / 1048576, 1) . ' MB';
|
||||
|
||||
if ($bytes <= 0) {
|
||||
return 'Unknown size';
|
||||
$label = 'Unknown size';
|
||||
} elseif ($bytes < 1024) {
|
||||
$label = $bytes . ' B';
|
||||
} elseif ($bytes < 1048576) {
|
||||
$label = number_format($bytes / 1024, 1) . ' KB';
|
||||
}
|
||||
|
||||
if ($bytes < 1024) {
|
||||
return $bytes . ' B';
|
||||
}
|
||||
|
||||
if ($bytes < 1048576) {
|
||||
return number_format($bytes / 1024, 1) . ' KB';
|
||||
}
|
||||
|
||||
return number_format($bytes / 1048576, 1) . ' MB';
|
||||
return $label;
|
||||
}
|
||||
}
|
||||
|
||||
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
-12
@@ -14,18 +14,6 @@ class RouteServiceProvider extends ServiceProvider
|
||||
*/
|
||||
protected $moduleNamespace = 'Modules\Documentation\Http\Controllers';
|
||||
|
||||
/**
|
||||
* Called before routes are registered.
|
||||
*
|
||||
* Register any model bindings or pattern based filters.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
parent::boot();
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the routes for the application.
|
||||
*
|
||||
|
||||
Regular → Executable
Regular → Executable
Regular → Executable
+1
@@ -21,6 +21,7 @@
|
||||
</div>
|
||||
<div class="doc-card-body">
|
||||
<table class="doc-table">
|
||||
<caption class="sr-only">Data table</caption>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
|
||||
Regular → Executable
Regular → Executable
Regular → Executable
+6
-4
@@ -44,15 +44,16 @@
|
||||
</div>
|
||||
<div class="doc-card-body">
|
||||
<form class="doc-filter" method="GET" action="{{ route('documentation.documents.index') }}">
|
||||
<input class="doc-input" name="search" value="{{ request('search') }}"
|
||||
placeholder="Search title, reference, summary or body">
|
||||
<select class="doc-select" name="status">
|
||||
<label for="sonar-input-9f8539cc9d" class="visually-hidden">Search title, reference, summary or body</label>
|
||||
<input class="doc-input" name="search" value="{{ request('search') }}"
|
||||
placeholder="Search title, reference, summary or body" id="sonar-input-9f8539cc9d">
|
||||
<select aria-label="Status" class="doc-select" name="status">
|
||||
<option value="">All statuses</option>
|
||||
@foreach ($statuses as $value => $label)
|
||||
<option value="{{ $value }}" @selected(request('status') === $value)>{{ $label }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
<select class="doc-select" name="category">
|
||||
<select aria-label="Category" class="doc-select" name="category">
|
||||
<option value="">All categories</option>
|
||||
@foreach ($categories as $category)
|
||||
<option value="{{ $category->id }}" @selected((string) request('category') === (string) $category->id)>{{ $category->name }}
|
||||
@@ -63,6 +64,7 @@
|
||||
</form>
|
||||
|
||||
<table class="doc-table">
|
||||
<caption class="sr-only">Data table</caption>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Document</th>
|
||||
|
||||
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
+9
-7
@@ -6,6 +6,8 @@ use Illuminate\Support\Facades\Route;
|
||||
use Modules\Documentation\Http\Controllers\DocumentationCategoryController;
|
||||
use Modules\Documentation\Http\Controllers\DocumentationController;
|
||||
|
||||
const DOCUMENT_ROUTE = '/documents/{document}';
|
||||
|
||||
Route::middleware(['web', 'auth'])
|
||||
->prefix('documentation')
|
||||
->name('documentation.')
|
||||
@@ -15,13 +17,13 @@ Route::middleware(['web', 'auth'])
|
||||
Route::get('/documents', [DocumentationController::class, 'index'])->name('documents.index');
|
||||
Route::get('/documents/create', [DocumentationController::class, 'create'])->name('documents.create');
|
||||
Route::post('/documents', [DocumentationController::class, 'store'])->name('documents.store');
|
||||
Route::get('/documents/{document}', [DocumentationController::class, 'show'])->name('documents.show');
|
||||
Route::get('/documents/{document}/edit', [DocumentationController::class, 'edit'])->name('documents.edit');
|
||||
Route::put('/documents/{document}', [DocumentationController::class, 'update'])->name('documents.update');
|
||||
Route::delete('/documents/{document}', [DocumentationController::class, 'destroy'])->name('documents.destroy');
|
||||
Route::get('/documents/{document}/download', [DocumentationController::class, 'download'])->name('documents.download');
|
||||
Route::get('/documents/{document}/attachments/{attachment}/download', [DocumentationController::class, 'downloadAttachment'])->name('documents.attachments.download');
|
||||
Route::delete('/documents/{document}/attachments/{attachment}', [DocumentationController::class, 'destroyAttachment'])->name('documents.attachments.destroy');
|
||||
Route::get(DOCUMENT_ROUTE, [DocumentationController::class, 'show'])->name('documents.show');
|
||||
Route::get(DOCUMENT_ROUTE . '/edit', [DocumentationController::class, 'edit'])->name('documents.edit');
|
||||
Route::put(DOCUMENT_ROUTE, [DocumentationController::class, 'update'])->name('documents.update');
|
||||
Route::delete(DOCUMENT_ROUTE, [DocumentationController::class, 'destroy'])->name('documents.destroy');
|
||||
Route::get(DOCUMENT_ROUTE . '/download', [DocumentationController::class, 'download'])->name('documents.download');
|
||||
Route::get(DOCUMENT_ROUTE . '/attachments/{attachment}/download', [DocumentationController::class, 'downloadAttachment'])->name('documents.attachments.download');
|
||||
Route::delete(DOCUMENT_ROUTE . '/attachments/{attachment}', [DocumentationController::class, 'destroyAttachment'])->name('documents.attachments.destroy');
|
||||
|
||||
Route::resource('categories', DocumentationCategoryController::class)->except(['show']);
|
||||
});
|
||||
|
||||
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Reference in New Issue
Block a user