Skip to content

Commit

Permalink
Update letterboxd job history UI
Browse files Browse the repository at this point in the history
  • Loading branch information
leepeuker committed Jun 27, 2023
1 parent 46b4bb4 commit 0bca390
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 93 deletions.
6 changes: 6 additions & 0 deletions public/js/job-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ function setJobModalTitle(jobType) {
case 'trakt_import_history':
title = 'History imports';
break;
case 'letterboxd_import_ratings':
title = 'Rating imports';
break;
case 'letterboxd_import_history':
title = 'History imports';
break;
default:
throw new Error('Not supported job type: ' + jobType);
}
Expand Down
1 change: 0 additions & 1 deletion src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ public static function createSettingsController(ContainerInterface $container, C
{
return new SettingsController(
$container->get(Twig\Environment::class),
$container->get(JobQueueApi::class),
$container->get(Authentication::class),
$container->get(UserApi::class),
$container->get(MovieApi::class),
Expand Down
2 changes: 0 additions & 2 deletions src/HttpController/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class SettingsController
{
public function __construct(
private readonly Environment $twig,
private readonly JobQueueApi $workerService,
private readonly Authentication $authenticationService,
private readonly UserApi $userApi,
private readonly Movie\MovieApi $movieApi,
Expand Down Expand Up @@ -306,7 +305,6 @@ public function renderLetterboxdPage() : Response
'letterboxdRatingsSyncSuccessful' => $letterboxdRatingsSyncSuccessful,
'letterboxdRatingsImportFileInvalid' => $letterboxdRatingsImportFileInvalid,
'letterboxdDiaryImportFileInvalid' => $letterboxdDiaryImportFileInvalid,
'lastLetterboxdImportJobs' => $this->workerService->findLastLetterboxdImportsForUser($user->getId()),
]),
);
}
Expand Down
21 changes: 0 additions & 21 deletions src/JobQueue/JobQueueApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,27 +88,6 @@ public function find(int $userId, JobType $jobType) : ?JobEntityList
return $this->repository->find($userId, $jobType);
}

public function findLastLetterboxdImportsForUser(int $userId) : array
{
return $this->repository->findLastLetterboxdImportsForUser($userId);
}

public function findLastTmdbSync() : ?DateTime
{
$lastMovieSync = $this->repository->findLastDateForJobByType(JobType::createTmdbMovieSync());
$lastPersonSync = $this->repository->findLastDateForJobByType(JobType::createTmdbPersonSync());

if ($lastMovieSync === null) {
return $lastPersonSync;
}

if ($lastPersonSync === null) {
return $lastMovieSync;
}

return $lastMovieSync->isAfter($lastPersonSync) ? $lastMovieSync : $lastPersonSync;
}

public function purgeAllJobs() : void
{
$this->repository->purgeProcessedJobs();
Expand Down
27 changes: 0 additions & 27 deletions src/JobQueue/JobQueueRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,33 +70,6 @@ public function find(int $userId, JobType $jobType) : ?JobEntityList
return JobEntityList::createFromArray($data);
}

public function findLastDateForJobByType(JobType $jobType) : ?DateTime
{
$data = $this->dbConnection->fetchOne('SELECT created_at FROM `job_queue` WHERE job_type = ? AND job_status = ? ORDER BY created_at', [$jobType, JobStatus::createDone()]);

if ($data === false) {
return null;
}

return DateTime::createFromString($data);
}

public function findLastLetterboxdImportsForUser(int $userId) : array
{
return $this->dbConnection->fetchAllAssociative(
'SELECT *
FROM `job_queue`
WHERE job_type IN (?, ?) AND user_id = ?
ORDER BY created_at DESC
LIMIT 10',
[
JobType::createLetterboxdImportHistory(),
JobType::createLetterboxdImportRatings(),
$userId,
],
);
}

public function purgeNotProcessedJobs() : void
{
$this->dbConnection->delete('job_queue', ['job_status' => (string)JobStatus::createWaiting()]);
Expand Down
53 changes: 13 additions & 40 deletions templates/page/settings-integration-letterboxd.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

{% block scripts %}
<script src="/js/settings-integration-letterboxd.js"></script>
<script src="/js/job-modal.js"></script>
{% endblock %}

{% block body %}
Expand Down Expand Up @@ -34,13 +35,15 @@
</div>

<form action="/jobs/schedule/letterboxd-diary-sync" method="post" enctype="multipart/form-data">
<h5 style="margin-bottom: 0.5rem">Import Diary</h5>
<h5 style="margin-bottom: 0.5rem">Import History</h5>
<p class="text-muted" style="margin-bottom: 0.5rem">Upload the diary.csv file</p>
<div class="input-group mb-3">
<input type="file" class="form-control" accept=".csv" name="diaryCsv" id="diaryCsv" required
{% if coreAccountChangesDisabled == true %}disabled{% endif %}>
</div>
<button type="submit" class="btn btn-primary" {% if coreAccountChangesDisabled == true %}disabled{% endif %}>Schedule import</button>

<button type="button" class="btn btn-outline-primary" onclick="showJobModal('letterboxd_import_history')" style="margin-right: .3rem">Show imports</button>
<button type="submit" class="btn btn-warning" {% if coreAccountChangesDisabled == true %}disabled{% endif %}>Import history</button>

{% if letterboxdDiarySyncSuccessful == true %}
<div class="alert alert-success alert-dismissible" role="alert" style="margin-left: 5%;margin-right: 5%;margin-bottom: 0!important;margin-top: 1rem">
Expand All @@ -56,15 +59,19 @@
</div>
{% endif %}
</form>

<br>

<form action="/jobs/schedule/letterboxd-ratings-sync" method="post" enctype="multipart/form-data">
<h5 style="margin-bottom: 0.5rem">Import Ratings</h5>
<p class="text-muted" style="margin-bottom: 0.5rem">Upload the ratings.csv file</p>
<div class="input-group mb-3">
<input type="file" class="form-control" accept=".csv" name="ratingsCsv" id="ratingsCsv" required
{% if coreAccountChangesDisabled == true %}disabled{% endif %}>
</div>
<button type="submit" class="btn btn-primary" {% if coreAccountChangesDisabled == true %}disabled{% endif %}>Schedule import</button>

<button type="button" class="btn btn-outline-primary" onclick="showJobModal('letterboxd_import_ratings')" style="margin-right: .3rem">Show imports</button>
<button type="submit" class="btn btn-warning" {% if coreAccountChangesDisabled == true %}disabled{% endif %}>Import ratings</button>

{% if letterboxdRatingsSyncSuccessful == true %}
<div class="alert alert-success alert-dismissible" role="alert" style="margin-left: 5%;margin-right: 5%;margin-bottom: 0!important;margin-top: 1rem">
Expand All @@ -82,43 +89,7 @@

<hr>

<h5 style="margin-top: 0.9rem">Import Log</h5>

<p class="text-muted">List of your last Letterboxd imports (max 10).</p>

<button class="w-100 btn btn-primary mb-3" type="submit" id="showImportTableButton" onclick="toggleTableVisibility()" style="margin-bottom: 0!important;">Show</button>

<div class="table-responsive d-none" style="text-align: center;margin-top: .5rem;margin-bottom: 0" id="importTable">
<table class="table">
<thead>
<tr>
<th scope="col">Type</th>
<th scope="col">Status</th>
<th scope="col">Created</th>
<th scope="col">Finished</th>
</tr>
</thead>
<tbody>
{% for job in lastLetterboxdImportJobs %}
<tr>
<td>{% if job.job_type == 'letterboxd_import_history' %} History {% else %} Ratings {% endif %}</td>
<td>{{ job.job_status }}</td>
<td>{{ job.created_at }}</td>
<td>{% if job.job_status == 'done' %}{{ job.updated_at }}{% else %}-{% endif %}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% if lastLetterboxdImportJobs|length == 0 %}
<tr>
No logged imports
</tr>
{% endif %}
</div>

<hr>

<h4 style="margin-bottom: 0.5rem">Export</h4>
<h4 style="margin-bottom: 0.5rem">Letterboxd Export</h4>

<p class="text-muted" style="margin-bottom: 0.8rem">
Download your data as csv and import them via the <a href="https://letterboxd.com/about/importing-data/" target="_blank">letterboxd importer</a>.
Expand All @@ -129,5 +100,7 @@
<a class="btn btn-primary" href="/settings/letterboxd-export" target="_blank">Generate export data</a>
</div>
</div>

{{ include('component/modal-job.html.twig') }}
</main>
{% endblock %}
4 changes: 2 additions & 2 deletions templates/page/settings-integration-trakt.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
<div style="margin-top: 0.9rem">
<button type="button" class="btn btn-outline-primary" onclick="showJobModal('trakt_import_history')" style="margin-right: .3rem">Show imports</button>
<a class="btn btn-warning {% if coreAccountChangesDisabled == true or traktUserName is null or traktClientId is null %}disabled{% endif %}"
href="/jobs/schedule/trakt-history-sync">History import</a>
href="/jobs/schedule/trakt-history-sync">Import history</a>

<br>

Expand All @@ -96,7 +96,7 @@

<button type="button" class="btn btn-outline-primary" onclick="showJobModal('trakt_import_ratings')" style="margin-right: .3rem;margin-top: 1rem">Show imports</button>
<a class="btn btn-warning {% if coreAccountChangesDisabled == true or traktUserName is null or traktClientId is null %}disabled{% endif %}"
href="/jobs/schedule/trakt-ratings-sync" style="margin-top: 1rem">Ratings import</a>
href="/jobs/schedule/trakt-ratings-sync" style="margin-top: 1rem">Import ratings</a>
</div>
</div>
</div>
Expand Down

0 comments on commit 0bca390

Please sign in to comment.