Skip to content

Commit 41fe59d

Browse files
committed
add: playlist categories
1 parent e9acd76 commit 41fe59d

15 files changed

+571
-2
lines changed

app/Http/Controllers/PlaylistController.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use App\Http\Requests\UpdatePlaylistRequest;
2121
use App\Models\TmdbMovie;
2222
use App\Models\Playlist;
23+
use App\Models\PlaylistCategory;
2324
use App\Models\TmdbTv;
2425
use App\Repositories\ChatRepository;
2526
use App\Traits\TorrentMeta;
@@ -55,7 +56,9 @@ public function index(): \Illuminate\Contracts\View\Factory|\Illuminate\View\Vie
5556
*/
5657
public function create(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
5758
{
58-
return view('playlist.create');
59+
return view('playlist.create', [
60+
'playlistCategories' => PlaylistCategory::query()->orderBy('position')->get(),
61+
]);
5962
}
6063

6164
/**
@@ -136,7 +139,10 @@ public function edit(Request $request, Playlist $playlist): \Illuminate\Contract
136139
{
137140
abort_unless($request->user()->id === $playlist->user_id || $request->user()->group->is_modo, 403);
138141

139-
return view('playlist.edit', ['playlist' => $playlist]);
142+
return view('playlist.edit', [
143+
'playlist' => $playlist,
144+
'playlistCategories' => PlaylistCategory::query()->orderBy('position')->get(),
145+
]);
140146
}
141147

142148
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* NOTICE OF LICENSE.
7+
*
8+
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
9+
* The details is bundled with this project in the file LICENSE.txt.
10+
*
11+
* @project UNIT3D Community Edition
12+
*
13+
* @author Roardom <roardom@protonmail.com>
14+
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
15+
*/
16+
17+
namespace App\Http\Controllers\Staff;
18+
19+
use App\Http\Controllers\Controller;
20+
use App\Http\Requests\Staff\StorePlaylistCategoryRequest;
21+
use App\Http\Requests\Staff\UpdatePlaylistCategoryRequest;
22+
use App\Models\Category;
23+
use App\Models\PlaylistCategory;
24+
use Exception;
25+
26+
class PlaylistCategoryController extends Controller
27+
{
28+
/**
29+
* Display all playlist categories.
30+
*/
31+
public function index(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
32+
{
33+
return view('Staff.playlist-category.index', [
34+
'playlistCategories' => PlaylistCategory::query()->orderBy('position')->get(),
35+
]);
36+
}
37+
38+
/**
39+
* Show form for creating a new category.
40+
*/
41+
public function create(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
42+
{
43+
return view('Staff.playlist-category.create');
44+
}
45+
46+
/**
47+
* Store a category.
48+
*/
49+
public function store(StorePlaylistCategoryRequest $request): \Illuminate\Http\RedirectResponse
50+
{
51+
PlaylistCategory::create($request->validated());
52+
53+
return to_route('staff.playlist_categories.index');
54+
}
55+
56+
/**
57+
* Playlist category edit form.
58+
*/
59+
public function edit(PlaylistCategory $playlistCategory): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
60+
{
61+
return view('Staff.playlist-category.edit', [
62+
'playlistCategory' => $playlistCategory,
63+
]);
64+
}
65+
66+
/**
67+
* Update a playlist category.
68+
*/
69+
public function update(UpdatePlaylistCategoryRequest $request, PlaylistCategory $playlistCategory): \Illuminate\Http\RedirectResponse
70+
{
71+
$playlistCategory->update($request->validated());
72+
73+
return to_route('staff.playlist_categories.index');
74+
}
75+
76+
/**
77+
* Destroy a category.
78+
*
79+
* @throws Exception
80+
*/
81+
public function destroy(PlaylistCategory $playlistCategory): \Illuminate\Http\RedirectResponse
82+
{
83+
$playlistCategory->delete();
84+
85+
return to_route('staff.playlist_categories.index');
86+
}
87+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* NOTICE OF LICENSE.
7+
*
8+
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
9+
* The details is bundled with this project in the file LICENSE.txt.
10+
*
11+
* @project UNIT3D Community Edition
12+
*
13+
* @author Roardom <roardom@protonmail.com>
14+
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
15+
*/
16+
17+
namespace App\Http\Requests\Staff;
18+
19+
use Illuminate\Foundation\Http\FormRequest;
20+
21+
class StorePlaylistCategoryRequest extends FormRequest
22+
{
23+
/**
24+
* Get the validation rules that apply to the request.
25+
*
26+
* @return array<string, list<string>>
27+
*/
28+
public function rules(): array
29+
{
30+
return [
31+
'name' => [
32+
'required',
33+
'string',
34+
],
35+
'position' => [
36+
'required',
37+
'numeric',
38+
'decimal:0',
39+
],
40+
];
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* NOTICE OF LICENSE.
7+
*
8+
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
9+
* The details is bundled with this project in the file LICENSE.txt.
10+
*
11+
* @project UNIT3D Community Edition
12+
*
13+
* @author Roardom <roardom@protonmail.com>
14+
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
15+
*/
16+
17+
namespace App\Http\Requests\Staff;
18+
19+
use Illuminate\Foundation\Http\FormRequest;
20+
21+
class UpdatePlaylistCategoryRequest extends FormRequest
22+
{
23+
/**
24+
* Get the validation rules that apply to the request.
25+
*
26+
* @return array<string, list<string>>
27+
*/
28+
public function rules(): array
29+
{
30+
return [
31+
'name' => [
32+
'required',
33+
'string',
34+
],
35+
'position' => [
36+
'required',
37+
'numeric',
38+
'decimal:0',
39+
],
40+
];
41+
}
42+
}

app/Http/Requests/StorePlaylistRequest.php

+4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ public function rules(): array
4343
'required',
4444
'max:255',
4545
],
46+
'playlist_category_id' => [
47+
'nullable',
48+
'exists:playlist_categories,id',
49+
],
4650
'description' => [
4751
'required',
4852
'max:65535',

app/Http/Requests/UpdatePlaylistRequest.php

+4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ public function rules(): array
4343
'required',
4444
'max:255',
4545
],
46+
'playlist_category_id' => [
47+
'nullable',
48+
'exists:playlist_categories,id',
49+
],
4650
'description' => [
4751
'required',
4852
'max:65536',

app/Models/PlaylistCategory.php

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* NOTICE OF LICENSE.
7+
*
8+
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
9+
* The details is bundled with this project in the file LICENSE.txt.
10+
*
11+
* @project UNIT3D Community Edition
12+
*
13+
* @author Roardom <roardom@protonmail.com>
14+
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
15+
*/
16+
17+
namespace App\Models;
18+
19+
use App\Traits\Auditable;
20+
use Illuminate\Database\Eloquent\Model;
21+
22+
/**
23+
* App\Models\PlaylistCategory.
24+
*
25+
* @property int $id
26+
* @property string $name
27+
* @property int $position
28+
*/
29+
class PlaylistCategory extends Model
30+
{
31+
use Auditable;
32+
33+
/**
34+
* Indicates if the model should be timestamped.
35+
*
36+
* @var bool
37+
*/
38+
public $timestamps = false;
39+
40+
/**
41+
* The attributes that aren't mass assignable.
42+
*
43+
* @var list<string>
44+
*/
45+
protected $guarded = [];
46+
47+
/**
48+
* Has many playlists.
49+
*
50+
* @return \Illuminate\Database\Eloquent\Relations\HasMany<Torrent, $this>
51+
*/
52+
public function playlists(): \Illuminate\Database\Eloquent\Relations\HasMany
53+
{
54+
return $this->hasMany(Playlist::class);
55+
}
56+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* NOTICE OF LICENSE.
7+
*
8+
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
9+
* The details is bundled with this project in the file LICENSE.txt.
10+
*
11+
* @project UNIT3D Community Edition
12+
*
13+
* @author Roardom <roardom@protonmail.com>
14+
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
15+
*/
16+
17+
use Illuminate\Database\Migrations\Migration;
18+
use Illuminate\Database\Schema\Blueprint;
19+
use Illuminate\Support\Facades\Schema;
20+
21+
return new class () extends Migration {
22+
/**
23+
* Run the migrations.
24+
*/
25+
public function up(): void
26+
{
27+
Schema::create('playlist_categories', function (Blueprint $table): void {
28+
$table->increments('id');
29+
$table->smallInteger('position');
30+
$table->string('name');
31+
});
32+
33+
Schema::table('playlists', function (Blueprint $table): void {
34+
$table->unsignedInteger('playlist_category_id')->nullable()->after('id');
35+
36+
$table->foreign('playlist_category_id')->references('id')->on('playlist_categories');
37+
});
38+
}
39+
};

resources/views/Staff/dashboard/index.blade.php

+9
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,15 @@ class="form__button form__button--text"
252252
{{ __('staff.blocked-ips') }}
253253
</a>
254254
</p>
255+
<p class="form__group form__group--horizontal">
256+
<a
257+
class="form__button form__button--text"
258+
href="{{ route('staff.playlist_categories.index') }}"
259+
>
260+
<i class="{{ config('other.font-awesome') }} fa-list"></i>
261+
Playlist Categories
262+
</a>
263+
</p>
255264
</div>
256265
</section>
257266
<section class="panelV2 panel--grid-item">
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
@extends('layout.with-main')
2+
3+
@section('breadcrumbs')
4+
<li class="breadcrumbV2">
5+
<a href="{{ route('staff.dashboard.index') }}" class="breadcrumb__link">
6+
{{ __('staff.staff-dashboard') }}
7+
</a>
8+
</li>
9+
<li class="breadcrumbV2">
10+
<a href="{{ route('staff.playlist_categories.index') }}" class="breadcrumb__link">
11+
Playlist Categories
12+
</a>
13+
</li>
14+
<li class="breadcrumb--active">
15+
{{ __('common.new-adj') }}
16+
</li>
17+
@endsection
18+
19+
@section('page', 'page__playlist-category--create')
20+
21+
@section('main')
22+
<section class="panelV2">
23+
<h2 class="panel__heading">Add Playlist Category</h2>
24+
<div class="panel__body">
25+
<form
26+
class="form"
27+
method="POST"
28+
action="{{ route('staff.playlist_categories.store') }}"
29+
enctype="multipart/form-data"
30+
>
31+
@csrf
32+
<p class="form__group">
33+
<input id="name" class="form__text" type="text" name="name" placeholder=" " />
34+
<label class="form__label form__label--floating" for="name">
35+
{{ __('common.name') }}
36+
</label>
37+
</p>
38+
<p class="form__group">
39+
<input
40+
id="position"
41+
class="form__text"
42+
type="text"
43+
name="position"
44+
placeholder=" "
45+
/>
46+
<label class="form__label form__label--floating" for="position">
47+
{{ __('common.position') }}
48+
</label>
49+
</p>
50+
<p class="form__group">
51+
<button class="form__button form__button--filled">
52+
{{ __('common.submit') }}
53+
</button>
54+
</p>
55+
</form>
56+
</div>
57+
</section>
58+
@endsection

0 commit comments

Comments
 (0)