Add music management to admin area

This commit is contained in:
DariusIII
2025-10-09 15:19:40 +02:00
parent ecd62a39e9
commit 602ea59460
5 changed files with 441 additions and 32 deletions
@@ -22,7 +22,7 @@ class AdminGameController extends BasePageController
// Get search parameter
$search = $request->input('gamesearch', '');
if (!empty($search)) {
if (! empty($search)) {
$gamelist = $game->getRange($search);
$lastSearch = $search;
} else {
@@ -88,6 +88,7 @@ class AdminGameController extends BasePageController
case 'view':
default:
$genres = $gen->getGenres(Genres::GAME_TYPE);
return view('admin.game-edit', compact('title', 'meta_title', 'game', 'genres'));
}
}
@@ -7,41 +7,42 @@ use Blacklight\Genres;
use Blacklight\Music;
use Blacklight\utility\Utility;
use Illuminate\Http\Request;
use Illuminate\Support\Carbon;
class AdminMusicController extends BasePageController
{
/**
* @throws \Exception
* Display a listing of music
*/
public function index(): void
public function index(Request $request)
{
$this->setAdminPrefs();
$meta_title = $title = 'Music List';
$musicList = Utility::getRange('musicinfo');
// Get search parameter
$search = $request->input('musicsearch', '');
$this->smarty->assign('musiclist', $musicList);
if (! empty($search)) {
$musicList = Utility::getRange('musicinfo', $search);
$lastSearch = $search;
} else {
$musicList = Utility::getRange('musicinfo');
$lastSearch = '';
}
$content = $this->smarty->fetch('music-list.tpl');
$this->smarty->assign(compact('title', 'meta_title', 'content'));
$this->adminrender();
return view('admin.music-list', compact('title', 'meta_title', 'musicList', 'lastSearch'));
}
/**
* @return \Illuminate\Http\RedirectResponse|void
*
* @throws \Exception
* Show the form for editing music
*/
public function edit(Request $request)
{
$this->setAdminPrefs();
$music = new Music;
$gen = new Genres;
$meta_title = $title = 'Music Edit';
// set the current action
// Set the current action
$action = $request->input('action') ?? 'view';
if ($request->has('id')) {
@@ -49,40 +50,52 @@ class AdminMusicController extends BasePageController
$mus = $music->getMusicInfo($id);
if (! $mus) {
$this->show404();
abort(404, 'Music not found');
}
switch ($action) {
case 'submit':
$coverLoc = storage_path('covers/music/'.$id.'.jpg');
if ($_FILES['cover']['size'] > 0) {
$tmpName = $_FILES['cover']['tmp_name'];
$file_info = getimagesize($tmpName);
if ($request->hasFile('cover') && $request->file('cover')->isValid()) {
$file = $request->file('cover');
$file_info = getimagesize($file->getPathname());
if (! empty($file_info)) {
move_uploaded_file($_FILES['cover']['tmp_name'], $coverLoc);
$file->move(storage_path('covers/music/'), $id.'.jpg');
}
}
$request->merge(['cover' => file_exists($coverLoc) ? 1 : 0]);
$request->merge(['salesrank' => (empty($request->input('salesrank')) || ! ctype_digit($request->input('salesrank'))) ? 'null' : $request->input('salesrank')]);
$request->merge(['releasedate' => (empty($request->input('releasedate')) || ! strtotime($request->input('releasedate'))) ? $mus['releasedate'] : Carbon::parse($request->input('releasedate'))->timestamp]);
$cover = file_exists($coverLoc) ? 1 : 0;
$salesrank = (empty($request->input('salesrank')) || ! ctype_digit($request->input('salesrank'))) ? null : $request->input('salesrank');
$releasedate = (empty($request->input('releasedate')) || ! strtotime($request->input('releasedate')))
? $mus['releasedate']
: Carbon::parse($request->input('releasedate'))->timestamp;
$music->update($id, $request->input('title'), $request->input('asin'), $request->input('url'), $request->input('salesrank'), $request->input('artist'), $request->input('publisher'), $request->input('releasedate'), $request->input('year'), $request->input('tracks'), $request->input('cover'), $request->input('genre'));
$music->update(
$id,
$request->input('title'),
$request->input('asin'),
$request->input('url'),
$salesrank,
$request->input('artist'),
$request->input('publisher'),
$releasedate,
$request->input('year'),
$request->input('tracks'),
$cover,
$request->input('genre')
);
return redirect()->to('admin/music-list');
return redirect()->route('admin.music-list')->with('success', 'Music updated successfully');
break;
case 'view':
default:
$this->smarty->assign('music', $mus);
$this->smarty->assign('genres', $gen->getGenres(Genres::MUSIC_TYPE));
break;
$genres = $gen->getGenres(Genres::MUSIC_TYPE);
return view('admin.music-edit', compact('title', 'meta_title', 'mus', 'genres'));
}
}
$content = $this->smarty->fetch('music-edit.tpl');
$this->smarty->assign(compact('title', 'meta_title', 'content'));
$this->adminrender();
abort(404, 'Music ID required');
}
}
+236
View File
@@ -0,0 +1,236 @@
@extends('layouts.admin')
@section('content')
<div class="container mx-auto px-4 py-6">
<div class="bg-white dark:bg-gray-800 rounded-lg shadow-sm">
<!-- Header -->
<div class="px-6 py-4 border-b border-gray-200">
<h1 class="text-2xl font-semibold text-gray-800 dark:text-gray-200">
<i class="fa fa-music mr-2"></i>{{ $title }}
</h1>
</div>
<!-- Success/Error/Warning Messages -->
@if(session('success'))
<div class="mx-6 mt-4 p-4 bg-green-50 dark:bg-green-900 border border-green-200 dark:border-green-700 rounded-lg">
<p class="text-green-800 dark:text-green-200">
<i class="fa fa-check-circle mr-2"></i>{{ session('success') }}
</p>
</div>
@endif
@if(session('error'))
<div class="mx-6 mt-4 p-4 bg-red-50 dark:bg-red-900 border border-red-200 dark:border-red-700 rounded-lg">
<p class="text-red-800 dark:text-red-200">
<i class="fa fa-exclamation-circle mr-2"></i>{{ session('error') }}
</p>
</div>
@endif
@if(session('warning'))
<div class="mx-6 mt-4 p-4 bg-yellow-50 dark:bg-yellow-900 border border-yellow-200 dark:border-yellow-700 rounded-lg">
<p class="text-yellow-800 dark:text-yellow-200">
<i class="fa fa-exclamation-triangle mr-2"></i>{{ session('warning') }}
</p>
</div>
@endif
<!-- Edit Music Form -->
<form method="POST" action="{{ url('admin/music-edit') }}" enctype="multipart/form-data" class="p-6">
@csrf
<input type="hidden" name="id" value="{{ $mus['id'] }}">
<input type="hidden" name="action" value="submit">
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
<!-- Left Column -->
<div class="space-y-6">
<!-- Title -->
<div>
<label for="title" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
Album Title <span class="text-red-500">*</span>
</label>
<input type="text"
id="title"
name="title"
value="{{ $mus['title'] ?? '' }}"
required
class="w-full px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:text-white">
</div>
<!-- Artist -->
<div>
<label for="artist" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
Artist
</label>
<input type="text"
id="artist"
name="artist"
value="{{ $mus['artist'] ?? '' }}"
class="w-full px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:text-white">
</div>
<!-- Publisher -->
<div>
<label for="publisher" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
Publisher/Label
</label>
<input type="text"
id="publisher"
name="publisher"
value="{{ $mus['publisher'] ?? '' }}"
class="w-full px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:text-white">
</div>
<!-- ASIN -->
<div>
<label for="asin" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
ASIN
</label>
<input type="text"
id="asin"
name="asin"
value="{{ $mus['asin'] ?? '' }}"
class="w-full px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:text-white">
</div>
<!-- URL -->
<div>
<label for="url" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
URL
</label>
<input type="url"
id="url"
name="url"
value="{{ $mus['url'] ?? '' }}"
class="w-full px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:text-white">
</div>
</div>
<!-- Right Column -->
<div class="space-y-6">
<!-- Genre -->
<div>
<label for="genre" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
Genre
</label>
<select id="genre"
name="genre"
class="w-full px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:text-white">
<option value="">-- Select Genre --</option>
@if(!empty($genres))
@foreach($genres as $genreItem)
<option value="{{ $genreItem['id'] }}"
{{ (isset($mus['genre_id']) && $mus['genre_id'] == $genreItem['id']) ? 'selected' : '' }}>
{{ $genreItem['title'] }}
</option>
@endforeach
@endif
</select>
</div>
<!-- Year -->
<div>
<label for="year" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
Year
</label>
<input type="number"
id="year"
name="year"
min="1900"
max="2100"
value="{{ $mus['year'] ?? '' }}"
class="w-full px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:text-white">
</div>
<!-- Release Date -->
<div>
<label for="releasedate" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
Release Date
</label>
<input type="date"
id="releasedate"
name="releasedate"
value="{{ !empty($mus['releasedate']) ? date('Y-m-d', $mus['releasedate']) : '' }}"
class="w-full px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:text-white">
</div>
<!-- Tracks -->
<div>
<label for="tracks" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
Number of Tracks
</label>
<input type="number"
id="tracks"
name="tracks"
min="0"
value="{{ $mus['tracks'] ?? '' }}"
class="w-full px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:text-white">
</div>
<!-- Sales Rank -->
<div>
<label for="salesrank" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
Sales Rank
</label>
<input type="number"
id="salesrank"
name="salesrank"
min="0"
value="{{ $mus['salesrank'] ?? '' }}"
class="w-full px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:text-white">
</div>
<!-- Cover Image -->
<div>
<label for="cover" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
Cover Image
</label>
@if(!empty($mus['cover']) && $mus['cover'] == 1)
<div class="mb-3">
<img src="{{ asset('storage/covers/music/' . $mus['id'] . '.jpg') }}"
alt="Album Cover"
class="max-w-xs rounded-lg shadow-md border border-gray-300 dark:border-gray-600">
</div>
@endif
<input type="file"
id="cover"
name="cover"
accept="image/jpeg,image/jpg"
class="w-full px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:text-white">
<p class="mt-2 text-sm text-gray-500 dark:text-gray-400">
Upload a new cover image (JPG format)
</p>
</div>
<!-- Current Cover Status -->
<div>
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
Current Cover Status
</label>
@if(!empty($mus['cover']) && $mus['cover'] == 1)
<span class="inline-flex items-center px-3 py-1 text-sm font-semibold rounded-full bg-green-100 text-green-800">
<i class="fa fa-check mr-2"></i> Cover Available
</span>
@else
<span class="inline-flex items-center px-3 py-1 text-sm font-semibold rounded-full bg-red-100 text-red-800">
<i class="fa fa-times mr-2"></i> No Cover
</span>
@endif
</div>
</div>
</div>
<!-- Action Buttons -->
<div class="mt-8 flex gap-3 border-t border-gray-200 pt-6">
<button type="submit" class="px-6 py-2 bg-blue-600 dark:bg-blue-700 text-white rounded-lg hover:bg-blue-700">
<i class="fa fa-save mr-2"></i>Save Changes
</button>
<a href="{{ route('admin.music-list') }}" class="px-6 py-2 bg-gray-600 text-white rounded-lg hover:bg-gray-700">
<i class="fa fa-arrow-left mr-2"></i>Back to Music List
</a>
</div>
</form>
</div>
</div>
@endsection
+145
View File
@@ -0,0 +1,145 @@
@extends('layouts.admin')
@section('content')
<div class="container mx-auto px-4 py-6">
<div class="bg-white dark:bg-gray-800 rounded-lg shadow-sm">
<!-- Header -->
<div class="px-6 py-4 border-b border-gray-200">
<div class="flex justify-between items-center">
<h1 class="text-2xl font-semibold text-gray-800 dark:text-gray-200">
<i class="fa fa-music mr-2"></i>{{ $title }}
</h1>
</div>
</div>
<!-- Success/Error/Warning Messages -->
@if(session('success'))
<div class="mx-6 mt-4 p-4 bg-green-50 dark:bg-green-900 border border-green-200 dark:border-green-700 rounded-lg">
<p class="text-green-800 dark:text-green-200">
<i class="fa fa-check-circle mr-2"></i>{{ session('success') }}
</p>
</div>
@endif
@if(session('error'))
<div class="mx-6 mt-4 p-4 bg-red-50 dark:bg-red-900 border border-red-200 dark:border-red-700 rounded-lg">
<p class="text-red-800 dark:text-red-200">
<i class="fa fa-exclamation-circle mr-2"></i>{{ session('error') }}
</p>
</div>
@endif
@if(session('warning'))
<div class="mx-6 mt-4 p-4 bg-yellow-50 dark:bg-yellow-900 border border-yellow-200 dark:border-yellow-700 rounded-lg">
<p class="text-yellow-800 dark:text-yellow-200">
<i class="fa fa-exclamation-triangle mr-2"></i>{{ session('warning') }}
</p>
</div>
@endif
<!-- Search Form -->
<div class="px-6 py-4 bg-gray-50 dark:bg-gray-900 border-b border-gray-200">
<form method="GET" action="{{ url('admin/music-list') }}">
<div class="flex gap-2">
<div class="relative flex-1">
<div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
<i class="fa fa-search text-gray-400"></i>
</div>
<input type="text"
name="musicsearch"
value="{{ $lastSearch ?? '' }}"
placeholder="Search by artist, album title..."
class="pl-10 w-full px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:text-white">
</div>
<button type="submit" class="px-4 py-2 bg-blue-600 dark:bg-blue-700 text-white rounded-lg hover:bg-blue-700">
Search
</button>
@if(!empty($lastSearch))
<a href="{{ url('admin/music-list') }}" class="px-4 py-2 bg-gray-600 text-white rounded-lg hover:bg-gray-700">
Clear
</a>
@endif
</div>
</form>
</div>
<!-- Music List Table -->
@if(!empty($musicList) && count($musicList) > 0)
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50 dark:bg-gray-700">
<tr>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider">ID</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider">Title</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider">Artist</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider">Publisher</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider">Year</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider">Genre</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider">Tracks</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider">Cover</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider">Actions</th>
</tr>
</thead>
<tbody class="bg-white dark:bg-gray-800 divide-y divide-gray-200">
@foreach($musicList as $music)
<tr class="hover:bg-gray-50 dark:hover:bg-gray-700">
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900 dark:text-gray-200">
{{ $music['id'] ?? 'N/A' }}
</td>
<td class="px-6 py-4">
<div class="text-sm font-medium text-gray-900 dark:text-gray-200">
{{ $music['title'] ?? 'N/A' }}
</div>
</td>
<td class="px-6 py-4 text-sm text-gray-500 dark:text-gray-400">
{{ $music['artist'] ?? 'N/A' }}
</td>
<td class="px-6 py-4 text-sm text-gray-500 dark:text-gray-400">
{{ $music['publisher'] ?? 'N/A' }}
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500 dark:text-gray-400">
{{ $music['year'] ?? 'N/A' }}
</td>
<td class="px-6 py-4 text-sm text-gray-500 dark:text-gray-400">
{{ \Illuminate\Support\Str::limit($music['genre'] ?? 'N/A', 30) }}
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500 dark:text-gray-400">
{{ $music['tracks'] ?? 'N/A' }}
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm">
@if(!empty($music['cover']) && $music['cover'] == 1)
<span class="px-2 py-1 text-xs font-semibold rounded-full bg-green-100 text-green-800">
<i class="fa fa-check"></i> Yes
</span>
@else
<span class="px-2 py-1 text-xs font-semibold rounded-full bg-red-100 text-red-800">
<i class="fa fa-times"></i> No
</span>
@endif
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium">
<a href="{{ url('admin/music-edit?id=' . $music['id']) }}" class="text-blue-600 dark:text-blue-400 hover:text-blue-900">
<i class="fa fa-edit"></i> Edit
</a>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@else
<div class="px-6 py-12 text-center">
<i class="fa fa-music text-gray-400 text-5xl mb-4"></i>
<p class="text-gray-500 dark:text-gray-400 text-lg">
@if(!empty($lastSearch))
No music found matching "{{ $lastSearch }}".
@else
No music found in the database.
@endif
</p>
</div>
@endif
</div>
</div>
@endsection
@@ -81,6 +81,20 @@
</div>
</div>
<!-- Music -->
<div class="mb-4">
<button type="button" class="flex items-center justify-between w-full text-left text-gray-300 dark:text-gray-400 hover:text-white dark:hover:text-white transition" onclick="toggleAdminSubmenu('music-menu')">
<div class="flex items-center space-x-3">
<i class="fas fa-music"></i>
<span>Music</span>
</div>
<i class="fas fa-chevron-down text-sm transform transition-transform" id="music-menu-icon"></i>
</button>
<div id="music-menu" class="hidden mt-2 ml-6 space-y-1">
<a href="{{ url('/admin/music-list') }}" class="block py-2 px-3 text-gray-400 dark:text-gray-500 hover:text-white dark:hover:text-white hover:bg-gray-800 dark:hover:bg-gray-800 rounded transition">Music List</a>
</div>
</div>
<!-- Blacklist -->
<div class="mb-4">
<button type="button" class="flex items-center justify-between w-full text-left text-gray-300 dark:text-gray-400 hover:text-white dark:hover:text-white transition" onclick="toggleAdminSubmenu('blacklist-menu')">