Skip to content

Commit b50218f

Browse files
committed
Show watch progress in show and season cards
1 parent e77cf61 commit b50218f

6 files changed

Lines changed: 65 additions & 0 deletions

File tree

src/main/php/tracky/model/Episode.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use tracky\model\traits\Runtime;
99
use tracky\orm\EpisodeRepository;
1010
use tracky\ViewType;
11+
use tracky\watchstats\WatchStatsProvider;
1112

1213
#[ORM\Entity(repositoryClass: EpisodeRepository::class)]
1314
#[ORM\Table(
@@ -121,6 +122,13 @@ public function getViewType(): ViewType
121122
return ViewType::EPISODE;
122123
}
123124

125+
public function isMarkedAsWatched(WatchStatsProvider $watchStatsProvider): bool
126+
{
127+
$watchStats = $watchStatsProvider->getItemStats($this);
128+
129+
return $watchStats !== null and $watchStats->getCount();
130+
}
131+
124132
public function __toString(): string
125133
{
126134
return sprintf("%dx%d %s", $this->getSeason()->getNumber(), $this->getNumber(), $this->getTitle());

src/main/php/tracky/model/Season.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use tracky\model\traits\Plot;
99
use tracky\model\traits\PosterImage;
1010
use tracky\orm\SeasonRepository;
11+
use tracky\watchstats\WatchStatsProvider;
1112

1213
#[ORM\Entity(repositoryClass: SeasonRepository::class)]
1314
#[ORM\Table(
@@ -195,4 +196,22 @@ public function getYear(): ?int
195196

196197
return (int)$airDate->format("Y");
197198
}
199+
200+
public function getWatchProgress(WatchStatsProvider $watchStatsProvider): int
201+
{
202+
$totalEpisodes = count($this->getEpisodes());
203+
$watchedEpisode = 0;
204+
205+
if (!$totalEpisodes) {
206+
return 0;
207+
}
208+
209+
foreach ($this->getEpisodes() as $episode) {
210+
if ($episode->isMarkedAsWatched($watchStatsProvider)) {
211+
$watchedEpisode++;
212+
}
213+
}
214+
215+
return (int)round(($watchedEpisode / $totalEpisodes) * 100);
216+
}
198217
}

src/main/php/tracky/model/Show.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,4 +278,23 @@ public function getUnwatchedEpisodes(WatchStatsProvider $watchStatsProvider): ar
278278

279279
return $unwatchedEpisodes;
280280
}
281+
282+
public function getWatchProgress(WatchStatsProvider $watchStatsProvider): int
283+
{
284+
$allEpisodes = $this->getAllEpisodes();
285+
$totalEpisodes = count($allEpisodes);
286+
$watchedEpisode = 0;
287+
288+
if (!$totalEpisodes) {
289+
return 0;
290+
}
291+
292+
foreach ($allEpisodes as $episode) {
293+
if ($episode->isMarkedAsWatched($watchStatsProvider)) {
294+
$watchedEpisode++;
295+
}
296+
}
297+
298+
return (int)round(($watchedEpisode / $totalEpisodes) * 100);
299+
}
281300
}

src/main/resources/assets/style/main.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ html {
105105
overflow-y: auto;
106106
}
107107

108+
.show-card-progress, .season-card-progress {
109+
background-color: inherit;
110+
height: 5px;
111+
}
112+
108113
.show-progress-image {
109114
display: block;
110115
}

templates/components/season-card-small.twig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,11 @@
1313
<small class="d-block">{{ "shows.count.episodes"|trans({"%count%": season.episodes|length}) }}</small>
1414
<small class="d-block"><i class="fa-solid fa-clock"></i> {{ "runtime"|trans({"%runtime%": season.totalRuntime}) }}</small>
1515
</div>
16+
17+
{% if app.user %}
18+
{% set watchProgress = season.getWatchProgress(watchStatsProvider) %}
19+
<div class="progress rounded-top-0 season-card-progress" title="{{ watchProgress }}%">
20+
<div class="progress-bar bg-success" style="width: {{ watchProgress }}%;"></div>
21+
</div>
22+
{% endif %}
1623
</div>

templates/components/show-card-small.twig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,11 @@
1111
<small class="d-block">{{ "shows.count.episodes"|trans({"%count%": show.totalEpisodes}) }}</small>
1212
{% include "components/show-status-badge.twig" with {"status": show.status} only %}
1313
</div>
14+
15+
{% if app.user %}
16+
{% set watchProgress = show.getWatchProgress(watchStatsProvider) %}
17+
<div class="progress rounded-top-0 show-card-progress" title="{{ watchProgress }}%">
18+
<div class="progress-bar bg-success" style="width: {{ watchProgress }}%;"></div>
19+
</div>
20+
{% endif %}
1421
</div>

0 commit comments

Comments
 (0)