diff --git a/app/Http/Controllers/Admin/AdminBookController.php b/app/Http/Controllers/Admin/AdminBookController.php index 9a789ad58..ab8737894 100644 --- a/app/Http/Controllers/Admin/AdminBookController.php +++ b/app/Http/Controllers/Admin/AdminBookController.php @@ -5,15 +5,17 @@ namespace App\Http\Controllers\Admin; use App\Http\Controllers\BasePageController; use App\Models\BookInfo; use Blacklight\Books; +use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; use Illuminate\Support\Carbon; +use Illuminate\View\View; class AdminBookController extends BasePageController { /** - * @throws \Exception + * Display a listing of books */ - public function index(): void + public function index(): View { $this->setAdminPrefs(); @@ -21,21 +23,13 @@ class AdminBookController extends BasePageController $bookList = BookInfo::query()->orderByDesc('created_at')->paginate(config('nntmux.items_per_page')); - $this->smarty->assign('booklist', $bookList); - - $content = $this->smarty->fetch('book-list.tpl'); - - $this->smarty->assign(compact('title', 'meta_title', 'content')); - - $this->adminrender(); + return view('admin.books.index', compact('bookList', 'title', 'meta_title')); } /** - * @return \Illuminate\Http\RedirectResponse|void - * - * @throws \Exception + * Show the form for editing a book */ - public function edit(Request $request) + public function edit(Request $request): View|RedirectResponse { $this->setAdminPrefs(); $book = new Books; @@ -50,38 +44,44 @@ class AdminBookController extends BasePageController $b = $book->getBookInfo($id); if (! $b) { - $this->show404(); + abort(404); } switch ($action) { case 'submit': $coverLoc = storage_path('covers/book/'.$id.'.jpg'); - if ($_FILES['cover']['size'] > 0) { - $tmpName = $_FILES['cover']['tmp_name']; - $file_info = getimagesize($tmpName); + if ($request->hasFile('cover') && $request->file('cover')->isValid()) { + $uploadedFile = $request->file('cover'); + $file_info = getimagesize($uploadedFile->getRealPath()); if (! empty($file_info)) { - move_uploaded_file($_FILES['cover']['tmp_name'], $coverLoc); + $uploadedFile->move(storage_path('covers/book'), $id.'.jpg'); } } - $request->merge(['cover' => file_exists($coverLoc) ? 1 : 0]); - $request->merge(['publishdate' => (empty($request->input('publishdate')) || ! strtotime($request->input('publishdate'))) ? $con['publishdate'] : Carbon::parse($request->input('publishdate'))->timestamp]); - $book->update($id, $request->input('title'), $request->input('asin'), $request->input('url'), $request->input('author'), $request->input('publisher'), $request->input('publishdate'), $request->input('cover')); + $hasCover = file_exists($coverLoc) ? 1 : 0; + $publishdate = (empty($request->input('publishdate')) || ! strtotime($request->input('publishdate'))) + ? ($b['publishdate'] ?? null) + : Carbon::parse($request->input('publishdate'))->timestamp; - return redirect()->to('admin/book-list'); - break; + $book->update( + $id, + $request->input('title'), + $request->input('asin'), + $request->input('url'), + $request->input('author'), + $request->input('publisher'), + $publishdate, + $hasCover + ); + + return redirect()->route('admin.book-list')->with('success', 'Book updated successfully'); case 'view': default: - $this->smarty->assign('book', $b); - break; + return view('admin.books.edit', compact('book', 'title', 'meta_title'))->with('book', $b); } } - $content = $this->smarty->fetch('book-edit.tpl'); - - $this->smarty->assign(compact('title', 'meta_title', 'content')); - - $this->adminrender(); + return redirect()->route('admin.book-list'); } } diff --git a/resources/views/admin/books/edit.blade.php b/resources/views/admin/books/edit.blade.php new file mode 100644 index 000000000..bedc408dc --- /dev/null +++ b/resources/views/admin/books/edit.blade.php @@ -0,0 +1,210 @@ +@extends('layouts.admin') + +@section('content') +
+
+ +
+
+

+ {{ $title }} +

+ + Back to List + +
+
+ + +
+
+ @csrf + + + +
+ +
+ +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + + @if(!empty($book['url'])) + + View on Amazon + + @endif +
+
+ + +
+ +
+ +
+ @if(isset($book['cover']) && $book['cover'] == 1) + {{ $book['title'] }} + @else +
+ +

No cover image available

+
+ @endif +
+
+ + +
+ +
+ +

+ PNG, JPG, GIF up to 10MB +

+
+
+ + +
+

Book Information

+
+
+
ID:
+
{{ $book['id'] }}
+
+ @if(isset($book['created_at'])) +
+
Created:
+
{{ $book['created_at'] }}
+
+ @endif + @if(isset($book['updated_at'])) +
+
Updated:
+
{{ $book['updated_at'] }}
+
+ @endif +
+
+
+
+ + +
+ + Cancel + + +
+
+
+
+
+ +@push('scripts') + +@endpush +@endsection + diff --git a/resources/views/admin/books/index.blade.php b/resources/views/admin/books/index.blade.php new file mode 100644 index 000000000..2a9d6a666 --- /dev/null +++ b/resources/views/admin/books/index.blade.php @@ -0,0 +1,107 @@ +@extends('layouts.admin') + +@section('content') +
+
+ +
+
+

+ {{ $title }} +

+
+ Total: {{ $bookList->total() }} books +
+
+
+ + +
+ + + + + + + + + + + + + + @forelse($bookList as $book) + + + + + + + + + + @empty + + + + @endforelse + +
CoverTitleAuthorPublisherPublishedCreatedActions
+ @if($book->cover == 1) + {{ $book->title }} + @else +
+ +
+ @endif +
+
+ {{ $book->title ?? 'N/A' }} +
+ @if($book->asin) +
+ ASIN: {{ $book->asin }} +
+ @endif +
+ {{ $book->author ?? '—' }} + + {{ $book->publisher ?? '—' }} + + @if($book->publishdate) + {{ date('Y-m-d', $book->publishdate) }} + @else + — + @endif + + {{ $book->created_at ? $book->created_at->format('Y-m-d') : '—' }} + + + + + @if($book->url) + + + + @endif +
+ No books found. +
+
+ + +
+ {{ $bookList->links() }} +
+
+
+@endsection + diff --git a/resources/views/partials/admin-menu.blade.php b/resources/views/partials/admin-menu.blade.php index 6be71cbe7..b4443efe2 100644 --- a/resources/views/partials/admin-menu.blade.php +++ b/resources/views/partials/admin-menu.blade.php @@ -101,6 +101,20 @@ + +
+ + +
+