Skip to content

Commit

Permalink
update: allow sorting torrent list by tmdb rating
Browse files Browse the repository at this point in the history
  • Loading branch information
Roardom committed Oct 20, 2024
1 parent dd033ec commit 60a909b
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 5 deletions.
1 change: 1 addition & 0 deletions app/Http/Livewire/TorrentSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ final public function torrents(): \Illuminate\Contracts\Pagination\LengthAwarePa
// Whitelist which columns are allowed to be ordered by
if (!\in_array($this->sortField, [
'name',
'rating',
'size',
'seeders',
'leechers',
Expand Down
26 changes: 26 additions & 0 deletions app/Models/Torrent.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,28 @@ protected function casts(): array
WHERE torrents.resolution_id = resolutions.id
LIMIT 1
) AS json_resolution,
(
SELECT vote_average
FROM movies
WHERE
torrents.tmdb = movies.id
AND torrents.category_id in (
SELECT id
FROM categories
WHERE movie_meta = 1
)
UNION
SELECT vote_average
FROM tv
WHERE
torrents.tmdb = tv.id
AND torrents.category_id in (
SELECT id
FROM categories
WHERE tv_meta = 1
)
LIMIT 1
) AS rating,
(
SELECT JSON_OBJECT(
'id', movies.id,
Expand All @@ -290,6 +312,7 @@ protected function casts(): array
'poster', movies.poster,
'original_language', movies.original_language,
'adult', movies.adult != 0,
'rating', movies.vote_average,
'companies', (
SELECT COALESCE(JSON_ARRAYAGG(JSON_OBJECT(
'id', companies.id,
Expand Down Expand Up @@ -344,6 +367,7 @@ protected function casts(): array
'year', YEAR(tv.first_air_date),
'poster', tv.poster,
'original_language', tv.original_language,
'rating', tv.vote_average,
'companies', (
SELECT COALESCE(JSON_ARRAYAGG(JSON_OBJECT(
'id', companies.id,
Expand Down Expand Up @@ -831,6 +855,7 @@ public function toSearchableArray(): array
'region_id',
'personal_release',
'info_hash',
'rating',
'json_user',
'json_type',
'json_category',
Expand Down Expand Up @@ -901,6 +926,7 @@ public function toSearchableArray(): array
'region_id' => $torrent->region_id,
'personal_release' => (bool) $torrent->personal_release,
'info_hash' => bin2hex($torrent->info_hash),
'rating' => (float) $torrent->rating, /** @phpstan-ignore property.notFound (This property is selected in the query but doesn't exist on the model) */
'user' => json_decode($torrent->json_user ?? 'null'),
'type' => json_decode($torrent->json_type ?? 'null'),
'category' => json_decode($torrent->json_category ?? 'null'),
Expand Down
1 change: 1 addition & 0 deletions config/scout.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@
],
'sortableAttributes' => [
'name',
'rating',
'size',
'seeders',
'leechers',
Expand Down
8 changes: 4 additions & 4 deletions resources/sass/pages/_torrents.scss
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,15 @@
.torrent-search--list__row {
display: grid;
grid-template-rows: auto;
grid-template-columns: 60px 100px 1fr 150px 60px 100px 50px 50px 50px 120px;
grid-template-columns: 60px 100px 1fr 150px 68px 100px 50px 50px 50px 120px;
grid-template-areas: 'poster format overview buttons rating size seeders leechers completed age';
}

.torrent-search--list__no-poster-headers,
.torrent-search--list__no-poster-row {
display: grid;
grid-template-rows: auto;
grid-template-columns: 100px 1fr 150px 60px 100px 50px 50px 50px 120px;
grid-template-columns: 100px 1fr 150px 68px 100px 50px 50px 50px 120px;
grid-template-areas: 'format overview buttons rating size seeders leechers completed age';
}

Expand Down Expand Up @@ -292,6 +292,7 @@
}

.torrent-search--list__name-header,
.torrent-search--list__ratings-header,
.torrent-search--list__size-header,
.torrent-search--list__seeders-header,
.torrent-search--list__leechers-header,
Expand All @@ -302,8 +303,7 @@

.torrent-search--list__poster-header,
.torrent-search--list__format-header,
.torrent-search--list__actions-header,
.torrent-search--list__ratings-header {
.torrent-search--list__actions-header {
display: none;
}

Expand Down
9 changes: 8 additions & 1 deletion resources/views/livewire/torrent-search.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,14 @@ class="torrent-search--list__name-header"
<th class="torrent-search--list__actions-header">
{{ __('common.actions') }}
</th>
<th class="torrent-search--list__ratings-header">Rating</th>
<th
class="torrent-search--list__ratings-header"
wire:click="sortBy('rating')"
role="columnheader button"
>
Rating
@include('livewire.includes._sort-icon', ['field' => 'rating'])
</th>
<th
class="torrent-search--list__size-header"
wire:click="sortBy('size')"
Expand Down

0 comments on commit 60a909b

Please sign in to comment.