Skip to content

Commit

Permalink
Reformatting and minor refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
leepeuker committed Dec 3, 2023
1 parent c085c5f commit 78ce65a
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 46 deletions.
11 changes: 5 additions & 6 deletions public/css/bootstrap-icons-1.10.2.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ url("../fonts/bootstrap-icons.woff?24e3eb84d0bcaf83d77f904c78ac1f47") format("wo
.bi-calendar-date::before { content: "\f1e4"; }
.bi-chat-square-text::before { content: "\f264"; }
.bi-check-circle-fill::before { content: "\f26a"; }
.bi-chevron-contract::before { content: "\f27d"; }
.bi-chevron-down::before { content: "\f282"; }
.bi-chevron-expand::before { content: "\f283"; }
.bi-chevron-up::before { content: "\f286"; }
.bi-eye::before { content: "\f341"; }
.bi-eye-slash::before { content: "\f340"; }
.bi-filter::before { content:"\f3ca"; }
.bi-moon-fill::before { content: "\f494"; }
.bi-pencil-square::before { content: "\f4ca"; }
.bi-search::before { content: "\f52a"; }
Expand All @@ -39,11 +42,7 @@ url("../fonts/bootstrap-icons.woff?24e3eb84d0bcaf83d77f904c78ac1f47") format("wo
.bi-sun::before { content: "\f5a2"; }
.bi-trash-fill::before { content: "\f5dd"; }
.bi-three-dots-vertical::before { content: "\f5d3"; }
.bi-upload::before { content:"\f603"; }
.bi-question-lg::before { content: "\f64e"; }
.bi-x-circle-fill::before { content: "\f622"; }
.bi-x-lg::before { content: "\f659"; }
.bi-chevron-expand::before { content: "\f283"; }
.bi-chevron-contract::before { content: "\f27d"; }
.bi-question-lg::before { content: "\f64e"; }
.bi-filter::before{content:"\f3ca"; }
.bi-upload::before {content:"\f603"; }
.bi-search::before {content: "\F52A"; }
10 changes: 5 additions & 5 deletions public/css/movie.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
border-width: 0.1rem;
}

.PosterOptionsDiv {
.posterOptionsDiv {
border: var(--bs-tertiary-color) 2px solid;
width: 20vh;
height: 10vh;
Expand All @@ -25,14 +25,14 @@
margin: 0 5px 0 5px;
}

.PosterOptionsDiv:hover {
.posterOptionsDiv:hover {
background-color: var(--bs-tertiary-color);
}

.TMDBPosterImage, .SelectedPoster {
.tmdbPosterImage, .selectedPoster {
cursor: pointer;
}

.TMDBPosterImage:hover, .SelectedPoster {
.tmdbPosterImage:hover, .selectedPoster {
filter: brightness(50%);
}
}
12 changes: 6 additions & 6 deletions public/js/movie.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,14 +380,14 @@ function processTMDBPosters(TMDBData) {
for(let i = 0; i < TMDBData.length; i++) {
let imageData = TMDBData[i];
let image = document.createElement('img');
image.classList.add('img-fluid', 'm-1', 'TMDBPosterImage');
image.classList.add('img-fluid', 'm-1', 'tmdbPosterImage');
image.dataset.filepath = imageData['file_path'];
image.src = 'https://image.tmdb.org/t/p/w154' + imageData['file_path'];
image.addEventListener('click', function() {
if(document.getElementsByClassName('SelectedPoster').length > 0) {
document.querySelector('.SelectedPoster').className = 'img-fluid m-1 TMDBPosterImage';
if(document.getElementsByClassName('selectedPoster').length > 0) {
document.querySelector('.selectedPoster').className = 'img-fluid m-1 tmdbPosterImage';
}
this.className = 'img-fluid m-1 SelectedPoster';
this.className = 'img-fluid m-1 selectedPoster';
document.getElementById('updatePosterButton').classList.remove('disabled');
document.getElementById('updatePosterButton').removeAttribute('disabled');
});
Expand All @@ -397,7 +397,7 @@ function processTMDBPosters(TMDBData) {

function updateSelectedPoster() {
let movieId = document.getElementById('movieId').value;
let selectedPoster = document.querySelector('.SelectedPoster');
let selectedPoster = document.querySelector('.selectedPoster');
let filePath = selectedPoster.dataset.filepath;

const updatePosterRequest = fetch('/movies/' + movieId + '/update-poster', {
Expand Down Expand Up @@ -493,4 +493,4 @@ function createSpinner(parent) {
span.innerText = 'Loading...';
div.append(span);
parent.append(div);
}
}
9 changes: 2 additions & 7 deletions src/Api/Tmdb/Cache/TmdbIsoLanguageCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,7 @@ public function delete() : void

public function getLanguageByCode(string $languageCode) : string
{
if ($this->languages === []) {
$this->loadFromDatabase();
}

if ($this->languages === []) {
$this->loadFromTmdb();
}
$this->fetchAll();

foreach ($this->languages as $iso6931 => $englishName) {
if ($iso6931 === $languageCode) {
Expand All @@ -51,6 +45,7 @@ public function fetchAll() : array
if ($this->languages === []) {
$this->loadFromTmdb();
}

return $this->languages;
}

Expand Down
10 changes: 6 additions & 4 deletions src/Api/Tmdb/TmdbApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,15 @@ public function getWatchProviders(int $tmdbId, string $country) : TmdbWatchProvi
);
}

public function getImages(int $tmdbId, string $country) : array
public function getPosters(int $tmdbId, ?string $country) : array
{
$path = "/movie/$tmdbId/images";
if(empty($country)) {
return $this->client->get($path);

if (empty($country) === true) {
return $this->client->get($path)['posters'];
}
return $this->client->get($path, ['languages' => $country, 'include_image_language' => "$country,null"]);

return $this->client->get($path, ['languages' => $country, 'include_image_language' => "$country,null"])['posters'];
}

public function searchMovie(string $searchTerm, ?Year $year = null, ?int $page = null) : array
Expand Down
22 changes: 18 additions & 4 deletions src/Domain/Movie/MovieApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -537,16 +537,30 @@ public function updateLetterboxdId(int $movieId, string $letterboxdId) : void

public function updatePosterPath(int $movieId, string $posterPath, ?string $oldPosterPath) : void
{
if($oldPosterPath !== null) {
if ($oldPosterPath !== null) {
$this->imageCacheService->deleteImageByPosterPath($oldPosterPath);
}

$this->repository->updateTmdbPosterPath($movieId, $posterPath);

if ($this->imageCacheService->isImageCachingEnabled() === false) {
return;
}

$tmdbPosterUrl = $this->tmdbUrlGenerator->generateImageUrl($posterPath);
if($this->imageCacheService->isImageCachingEnabled() === true) {
$newPosterPath = $this->imageCacheService->cacheImage($tmdbPosterUrl, $movieId, ResourceType::createMovie(), true);
$this->repository->updatePosterPath($movieId, $newPosterPath);

$newPosterPath = $this->imageCacheService->cacheImage(
$tmdbPosterUrl,
$movieId,
ResourceType::createMovie(),
true,
);

if ($newPosterPath === null) {
throw new \RuntimeException('Could not cache new poster and update the poster path');
}

$this->repository->updatePosterPath($movieId, $newPosterPath);
}

public function updateProductionCompanies(int $movieId, CompanyEntityList $productionCompanies) : void
Expand Down
23 changes: 12 additions & 11 deletions src/HttpController/Web/Movie/MovieController.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ public function renderPage(Request $request) : Response
if ($this->authenticationService->isUserAuthenticated() === true) {
$currentUser = $this->authenticationService->getCurrentUser();
}
$canChangePoster = $currentUser->isAdmin();

$movieId = (int)$request->getRouteParameters()['id'];

Expand All @@ -89,7 +88,6 @@ public function renderPage(Request $request) : Response

$movie['personalRating'] = $this->movieApi->findUserRating($movieId, $userId)?->asInt();

$languages = $this->tmdbIsoLanguageCache->fetchAll();
return Response::create(
StatusCode::createOk(),
$this->twig->render('page/movie.html.twig', [
Expand All @@ -102,27 +100,27 @@ public function renderPage(Request $request) : Response
'watchDates' => $this->movieApi->fetchHistoryByMovieId($movieId, $userId),
'isOnWatchlist' => $this->movieWatchlistApi->hasMovieInWatchlist($userId, $movieId),
'countries' => $this->tmdbIsoCountryCache->fetchAll(),
'userCountry' => $currentUser->getCountry(),
'userCountry' => $currentUser?->getCountry(),
'displayCharacterNames' => $currentUser?->getDisplayCharacterNames() ?? true,
'canChangePoster' => $canChangePoster,
'availableLanguages' => $languages
'canChangePoster' => $currentUser?->isAdmin(),
'availableLanguages' => $this->tmdbIsoLanguageCache->fetchAll()
]),
);
}

public function searchPosters(Request $request) : Response
{
$movieId = (int)$request->getRouteParameters()['id'];
$country = (string)$request->getGetParameters()['country'];

$getParameters = $request->getGetParameters();
$country = empty($getParameters['country']) ? null : $getParameters['country'];

$movie = $this->movieApi->findById($movieId);
if ($movie === null) {
return Response::createNotFound();
}

$tmdbId = $movie->getTmdbId();

$images = $this->tmdbApi->getImages($tmdbId, $country)['posters'];
$images = $this->tmdbApi->getPosters($movie->getTmdbId(), $country);

return Response::createJson(Json::encode($images));
}
Expand All @@ -137,13 +135,16 @@ public function updatePoster(Request $request) : Response
}

$posterFilepath = $request->getBody();
$oldPosterPath = $movie->getPosterPath();

if ($posterFilepath === $movie->getTmdbPosterPath()) {
return Response::createBadRequest();
}

$this->movieApi->updatePosterPath($movieId, $posterFilepath, $oldPosterPath);
$this->movieApi->updatePosterPath(
$movieId,
$posterFilepath,
$movie->getPosterPath(),
);

return Response::createOk();
}
Expand Down
6 changes: 3 additions & 3 deletions templates/component/modal-change-movie-poster.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
</div>
<div class="modal-body">
<div class="d-flex flex-sm-row flex-xs-column justify-content-around" id="PosterOptionsContainer">
<div class="PosterOptionsDiv" onclick="toggleChangePosterSection(this)" id="searchTMDBOption">Search TMDB for posters <br/> <i class="bi bi-search"></i></div>
<div class="PosterOptionsDiv d-none" onclick="toggleChangePosterSection(this)" id="pasteUrlOption">Manually paste an URL to a poster <br/> <span style="font-style: italic; ">https://</span></div>
<div class="PosterOptionsDiv d-none" onclick="toggleChangePosterSection(this)" id="uploadImageOption">Manually upload your own poster <br/> <i class="bi bi-upload"></i></div>
<div class="posterOptionsDiv" onclick="toggleChangePosterSection(this)" id="searchTMDBOption">Search TMDB for posters <br/> <i class="bi bi-search"></i></div>
<div class="posterOptionsDiv d-none" onclick="toggleChangePosterSection(this)" id="pasteUrlOption">Manually paste an URL to a poster <br/> <span style="font-style: italic; ">https://</span></div>
<div class="posterOptionsDiv d-none" onclick="toggleChangePosterSection(this)" id="uploadImageOption">Manually upload your own poster <br/> <i class="bi bi-upload"></i></div>
</div>
<div class="d-none" id="searchTMDBSection">
<div class="mb-3">
Expand Down

0 comments on commit 78ce65a

Please sign in to comment.