Skip to content

Commit

Permalink
Merge pull request #562 from leepeuker/add-user-rating-filter
Browse files Browse the repository at this point in the history
Add user rating filter to "All movies" page
  • Loading branch information
leepeuker authored Dec 31, 2023
2 parents 47509c4 + 7756759 commit b79707b
Show file tree
Hide file tree
Showing 10 changed files with 395 additions and 131 deletions.
82 changes: 82 additions & 0 deletions public/js/component/modal-advanced-search-movie.html.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ const searchGenreSelect = document.getElementById('searchGenreSelect');
const searchLanguageSelect = document.getElementById('searchLanguageSelect');
const searchReleaseYearSelect = document.getElementById('searchReleaseYearSelect');
const searchPerPageSelect = document.getElementById('searchPerPageSelect');
const searchUserRatingSelect = document.getElementById('searchUserRatingSelect');
const searchMinUserRatingSelect = document.getElementById('searchMinUserRatingSelect');
const searchMaxUserRatingSelect = document.getElementById('searchMaxUserRatingSelect');

function search() {
let sortBy = searchSortBySelect.value
Expand All @@ -19,6 +22,9 @@ function search() {
let searchLanguage = searchLanguageSelect.value
let searchReleaseYear = searchReleaseYearSelect.value
let searchPerPage = searchPerPageSelect.value
let searchUserRating = searchUserRatingSelect.value
let searchMinUserRating = searchMinUserRatingSelect.value
let searchMaxUserRating = searchMaxUserRatingSelect.value
let searchTerm = document.getElementById('searchTermInput').value

let getParameters = '?'
Expand All @@ -39,6 +45,13 @@ function search() {
if (searchTerm != '') {
getParameters += '&s=' + searchTerm
}
if (searchUserRating != '') {
getParameters += '&ur=' + searchUserRating
if (searchUserRating === '1') {
getParameters += '&minur=' + searchMinUserRating
getParameters += '&maxur=' + searchMaxUserRating
}
}

const urlWithoutGetParameters = window.location.href.split('?')[0];

Expand All @@ -51,5 +64,74 @@ function resetSearchOptions() {
searchGenreSelect.value = ''
searchLanguageSelect.value = ''
searchReleaseYearSelect.value = ''
searchUserRatingSelect.value = ''
searchMinUserRatingSelect.value = ''
searchMaxUserRatingSelect.value = ''
searchPerPageSelect.value = '24'
}


function toggleMinAndMaxUserRatingDivVisibility(displayUserRating) {
if (displayUserRating === false) {
document.getElementById('searchMinUserRatingDiv').classList.add('d-none')
document.getElementById('searchMaxUserRatingDiv').classList.add('d-none')

return
}

document.getElementById('searchMinUserRatingDiv').classList.remove('d-none')
document.getElementById('searchMaxUserRatingDiv').classList.remove('d-none')
}

document.getElementById('searchUserRatingSelect').addEventListener('change', (e) => {
toggleMinAndMaxUserRatingDivVisibility(e.target.value === '1')
})

document.getElementById('searchOptionsMovieModal').addEventListener('show.bs.modal', function () {
toggleMinAndMaxUserRatingDivVisibility(document.getElementById('searchUserRatingSelect').value === '1')
})

document.getElementById('searchMinUserRatingDiv').addEventListener('change', (e) => {
adjustMaxRatingToMatchMinRating(Number(e.target.value))
})

document.getElementById('searchMaxUserRatingDiv').addEventListener('change', (e) => {
adjustMinRatingToMatchMaxRating(Number(e.target.value))
})

function adjustMaxRatingToMatchMinRating(minRating) {
const maxUserRatingSelect = document.getElementById('searchMaxUserRatingSelect');

for (let i = 0; i < maxUserRatingSelect.options.length; i++) {
let maxOption = maxUserRatingSelect.options[i];

maxOption.disabled = Number(maxOption.value) < minRating
}

if (Number(maxUserRatingSelect.value) < minRating) {
maxUserRatingSelect.value = minRating
}
}

function adjustMinRatingToMatchMaxRating(maxRating) {
const minUserRatingSelect = document.getElementById('searchMinUserRatingSelect');

for (let i = 0; i < minUserRatingSelect.options.length; i++) {
let minOption = minUserRatingSelect.options[i];

minOption.disabled = Number(minOption.value) > maxRating
}

if (Number(minUserRatingSelect.value) > maxRating) {
minUserRatingSelect.value = maxRating
}
}

document.addEventListener('DOMContentLoaded', function () {
if (document.getElementById('searchMinUserRatingSelect').classList.contains('d-none')) {
return
}

adjustMaxRatingToMatchMinRating(Number(document.getElementById('searchMinUserRatingSelect').value))
adjustMinRatingToMatchMaxRating(Number(document.getElementById('searchMaxUserRatingSelect').value))
})
45 changes: 37 additions & 8 deletions src/Domain/Movie/History/MovieHistoryApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ public function create(int $movieId, int $userId, ?Date $watchedAt, int $plays,
$this->jobQueueApi->addJellyfinExportMoviesJob($userId, [$movieId]);
}

public function findHighestPositionForWatchDate(int $movieIdToIgnore, int $userId, ?Date $watchedAt) : ?int
{
return $this->repository->fetchHighestPositionForWatchDate($movieIdToIgnore, $userId, $watchedAt);
}

public function deleteByUserAndMovieId(int $userId, int $movieId) : void
{
$this->repository->deleteByUserAndMovieId($userId, $movieId);
Expand Down Expand Up @@ -260,6 +255,9 @@ public function fetchPlayedMoviesPaginated(
?Year $releaseYear = null,
?string $language = null,
?string $genre = null,
?bool $hasUserRating = null,
?int $userRatingMin = null,
?int $userRatingMax = null,
) : array {
if ($sortOrder === null) {
$sortOrder = SortOrder::createAsc();
Expand All @@ -275,6 +273,9 @@ public function fetchPlayedMoviesPaginated(
$releaseYear,
$language,
$genre,
$hasUserRating,
$userRatingMin,
$userRatingMax,
);

return $this->urlGenerator->replacePosterPathWithImageSrcUrl($movies);
Expand Down Expand Up @@ -390,9 +391,26 @@ public function fetchUniqueMovieReleaseYears(int $userId) : array
return $this->movieRepository->fetchUniqueMovieReleaseYears($userId);
}

public function fetchUniqueWatchedMoviesCount(int $userId, ?string $searchTerm = null, ?Year $releaseYear = null, ?string $language = null, ?string $genre = null) : int
{
return $this->movieRepository->fetchUniqueWatchedMoviesCount($userId, $searchTerm, $releaseYear, $language, $genre);
public function fetchUniqueWatchedMoviesCount(
int $userId,
?string $searchTerm = null,
?Year $releaseYear = null,
?string $language = null,
?string $genre = null,
?bool $hasUserRating = null,
?int $userRatingMin = null,
?int $userRatingMax = null,
) : int {
return $this->movieRepository->fetchUniqueWatchedMoviesCount(
$userId,
$searchTerm,
$releaseYear,
$language,
$genre,
$hasUserRating,
$userRatingMin,
$userRatingMax,
);
}

public function fetchUniqueWatchedMoviesPaginated(
Expand All @@ -405,6 +423,9 @@ public function fetchUniqueWatchedMoviesPaginated(
?Year $releaseYear = null,
?string $language = null,
?string $genre = null,
?bool $hasUserRating = null,
?int $userRatingMin = null,
?int $userRatingMax = null,
) : array {
if ($sortOrder === null) {
$sortOrder = SortOrder::createAsc();
Expand All @@ -420,6 +441,9 @@ public function fetchUniqueWatchedMoviesPaginated(
$releaseYear,
$language,
$genre,
$hasUserRating,
$userRatingMin,
$userRatingMax,
);

return $this->urlGenerator->replacePosterPathWithImageSrcUrl($movies);
Expand All @@ -444,6 +468,11 @@ public function fetchWatchDatesOrderedByWatchedAtDesc(int $userId) : array
return $this->movieRepository->fetchWatchDatesOrderedByWatchedAtDesc($userId);
}

public function findHighestPositionForWatchDate(int $movieIdToIgnore, int $userId, ?Date $watchedAt) : ?int
{
return $this->repository->fetchHighestPositionForWatchDate($movieIdToIgnore, $userId, $watchedAt);
}

public function findHistoryEntryForMovieByUserOnDate(int $movieId, int $userId, ?Date $watchedAt) : ?MovieHistoryEntity
{
return $this->movieRepository->findHistoryEntryForMovieByUserOnDate($movieId, $userId, $watchedAt);
Expand Down
92 changes: 68 additions & 24 deletions src/Domain/Movie/MovieApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,20 @@ public function fetchByTraktId(TraktId $traktId) : MovieEntity
return $movie;
}

public function fetchFromWatchlistWithActor(int $personId, int $userId) : array
{
$movies = $this->repository->fetchFromWatchlistWithActor($personId, $userId);

return $this->urlGenerator->replacePosterPathWithImageSrcUrl($movies);
}

public function fetchFromWatchlistWithDirector(int $personId, int $userId) : array
{
$movies = $this->repository->fetchFromWatchlistWithDirector($personId, $userId);

return $this->urlGenerator->replacePosterPathWithImageSrcUrl($movies);
}

public function fetchHistoryByMovieId(int $movieId, int $userId) : array
{
return $this->historyApi->fetchHistoryByMovieId($movieId, $userId);
Expand All @@ -190,6 +204,28 @@ public function fetchMovieIdsHavingImdbIdOrderedByLastImdbUpdatedAt(
return $this->movieRepository->fetchMovieIdsHavingImdbIdOrderedByLastImdbUpdatedAt($maxAgeInHours, $limit, $filterMovieIds, $onlyNeverSynced);
}

public function fetchPlayedMoviesCount(
int $userId,
?string $searchTerm,
?Year $releaseYear,
?string $language,
?string $genre,
?bool $hasUserRating,
?int $userRatingMin,
?int $userRatingMax,
) : int {
return $this->historyApi->fetchUniqueWatchedMoviesCount(
$userId,
$searchTerm,
$releaseYear,
$language,
$genre,
$hasUserRating,
$userRatingMin,
$userRatingMax,
);
}

public function fetchPlayedMoviesPaginated(
int $userId,
int $limit,
Expand All @@ -200,6 +236,9 @@ public function fetchPlayedMoviesPaginated(
?Year $releaseYear,
?string $language,
?string $genre,
?bool $hasUserRating,
?int $userRatingMin,
?int $userRatingMax,
) : array {
return $this->historyApi->fetchPlayedMoviesPaginated(
$userId,
Expand All @@ -211,6 +250,9 @@ public function fetchPlayedMoviesPaginated(
$releaseYear,
$language,
$genre,
$hasUserRating,
$userRatingMin,
$userRatingMax,
);
}

Expand Down Expand Up @@ -239,14 +281,26 @@ public function fetchUniqueMovieReleaseYears(int $userId) : array
return $this->historyApi->fetchUniqueMovieReleaseYears($userId);
}

public function fetchUniqueWatchedMoviesCount(int $userId, ?string $searchTerm, ?Year $releaseYear, ?string $language, ?string $genre) : int
{
return $this->historyApi->fetchUniqueWatchedMoviesCount($userId, $searchTerm, $releaseYear, $language, $genre);
}

public function fetchPlayedMoviesCount(int $userId, ?string $searchTerm, ?Year $releaseYear, ?string $language, ?string $genre) : int
{
return $this->historyApi->fetchUniqueWatchedMoviesCount($userId, $searchTerm, $releaseYear, $language, $genre);
public function fetchUniqueWatchedMoviesCount(
int $userId,
?string $searchTerm,
?Year $releaseYear,
?string $language,
?string $genre,
?bool $hasUserRating,
?int $userRatingMin,
?int $userRatingMax,
) : int {
return $this->historyApi->fetchUniqueWatchedMoviesCount(
$userId,
$searchTerm,
$releaseYear,
$language,
$genre,
$hasUserRating,
$userRatingMin,
$userRatingMax,
);
}

public function fetchUniqueWatchedMoviesPaginated(
Expand All @@ -259,6 +313,9 @@ public function fetchUniqueWatchedMoviesPaginated(
?Year $releaseYear,
?string $language,
?string $genre,
?bool $hasUserRating,
?int $userRatingMin,
?int $userRatingMax,
) : array {
return $this->historyApi->fetchUniqueWatchedMoviesPaginated(
$userId,
Expand All @@ -270,6 +327,9 @@ public function fetchUniqueWatchedMoviesPaginated(
$releaseYear,
$language,
$genre,
$hasUserRating,
$userRatingMin,
$userRatingMax,
);
}

Expand Down Expand Up @@ -303,22 +363,6 @@ public function fetchWithDirector(int $personId, int $userId) : array
return $this->urlGenerator->replacePosterPathWithImageSrcUrl($movies);
}


public function fetchFromWatchlistWithActor(int $personId, int $userId) : array
{
$movies = $this->repository->fetchFromWatchlistWithActor($personId, $userId);

return $this->urlGenerator->replacePosterPathWithImageSrcUrl($movies);
}


public function fetchFromWatchlistWithDirector(int $personId, int $userId) : array
{
$movies = $this->repository->fetchFromWatchlistWithDirector($personId, $userId);

return $this->urlGenerator->replacePosterPathWithImageSrcUrl($movies);
}

public function findById(int $movieId) : ?MovieEntity
{
return $this->repository->findById($movieId);
Expand Down
Loading

0 comments on commit b79707b

Please sign in to comment.