Skip to content

Commit 57e2375

Browse files
committed
show number of media instances per item in media list
1 parent 5a5d13f commit 57e2375

File tree

5 files changed

+79
-5
lines changed

5 files changed

+79
-5
lines changed

src/app/models.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@
1010
from django.db import models
1111
from django.db.models import (
1212
CheckConstraint,
13+
Count,
14+
F,
1315
IntegerField,
1416
Max,
1517
Prefetch,
1618
Q,
1719
UniqueConstraint,
20+
Window,
1821
)
19-
from django.db.models.functions import Cast
22+
from django.db.models.functions import Cast, RowNumber
2023
from django.utils import timezone
2124
from model_utils import FieldTracker
2225
from model_utils.fields import MonitorField
@@ -237,6 +240,18 @@ def get_media_list(self, user, media_type, status_filter, sort_filter, search=No
237240
if search:
238241
queryset = queryset.filter(item__title__icontains=search)
239242

243+
queryset = queryset.annotate(
244+
repeats=Window(
245+
expression=Count("id"),
246+
partition_by=[F("item")],
247+
),
248+
row_number=Window(
249+
expression=RowNumber(),
250+
partition_by=[F("item")],
251+
order_by=F("created_at").desc(),
252+
),
253+
).filter(row_number=1)
254+
240255
queryset = queryset.select_related("item")
241256
queryset = self._apply_prefetch_related(queryset, media_type)
242257

src/static/css/main.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
--color-fuchsia-400: oklch(74% 0.238 322.16);
4444
--color-fuchsia-600: oklch(59.1% 0.293 322.896);
4545
--color-fuchsia-700: oklch(51.8% 0.253 323.949);
46+
--color-slate-200: oklch(92.9% 0.013 255.508);
4647
--color-gray-100: oklch(96.7% 0.003 264.542);
4748
--color-gray-200: oklch(92.8% 0.006 264.531);
4849
--color-gray-300: oklch(87.2% 0.01 258.338);
@@ -344,6 +345,9 @@
344345
.bottom-4 {
345346
bottom: calc(var(--spacing) * 4);
346347
}
348+
.bottom-10 {
349+
bottom: calc(var(--spacing) * 10);
350+
}
347351
.bottom-full {
348352
bottom: 100%;
349353
}
@@ -1444,6 +1448,9 @@
14441448
.pe-3 {
14451449
padding-inline-end: calc(var(--spacing) * 3);
14461450
}
1451+
.pe-8 {
1452+
padding-inline-end: calc(var(--spacing) * 8);
1453+
}
14471454
.pt-2 {
14481455
padding-top: calc(var(--spacing) * 2);
14491456
}
@@ -1643,6 +1650,9 @@
16431650
.text-red-500 {
16441651
color: var(--color-red-500);
16451652
}
1653+
.text-slate-200 {
1654+
color: var(--color-slate-200);
1655+
}
16461656
.text-white {
16471657
color: var(--color-white);
16481658
}
@@ -2324,6 +2334,11 @@
23242334
right: calc(var(--spacing) * 2);
23252335
}
23262336
}
2337+
.sm\:bottom-2 {
2338+
@media (width >= 40rem) {
2339+
bottom: calc(var(--spacing) * 2);
2340+
}
2341+
}
23272342
.sm\:left-auto {
23282343
@media (width >= 40rem) {
23292344
left: auto;

src/templates/app/components/media_card.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,27 @@
120120
</div>
121121
{% endif %}
122122

123+
{% if media.repeats > 1 %}
124+
<div class="absolute sm:bottom-2 sm:right-2 sm:left-auto bottom-10 left-2 bg-gray-900/90 text-white text-xs px-2 py-1 rounded-md flex items-center shadow-md">
125+
<svg xmlns="http://www.w3.org/2000/svg"
126+
width="24"
127+
height="24"
128+
viewBox="0 0 24 24"
129+
fill="none"
130+
stroke="currentColor"
131+
stroke-width="2"
132+
stroke-linecap="round"
133+
stroke-linejoin="round"
134+
class="w-4 h-4 text-slate-200 mr-1">
135+
<path d="m17 2 4 4-4 4" />
136+
<path d="M3 11v-1a4 4 0 0 1 4-4h14" />
137+
<path d="m7 22-4-4 4-4" />
138+
<path d="M21 13v1a4 4 0 0 1-4 4H3" />
139+
</svg>
140+
<span class="text-sm text-white">{{ media.repeats }}</span>
141+
</div>
142+
{% endif %}
143+
123144
<div class="absolute inset-0 bg-black/50 flex items-center justify-center opacity-0 hover-tap:opacity-100">
124145
<a href="{{ item|media_url }}" class="absolute inset-0"></a>
125146

src/templates/app/components/media_table_items.html

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,32 @@
4040
</div>
4141
</div>
4242
</td>
43-
<td class="p-2 font-medium">
44-
<a href="{{ media.item|media_url }}"
45-
class="hover:text-indigo-400 transition-colors line-clamp-2">{{ media.item }}</a>
43+
<td class="p-2 pe-8 font-medium">
44+
<div class=" flex justify-between items-center">
45+
<a href="{{ media.item|media_url }}"
46+
class="hover:text-indigo-400 transition-colors line-clamp-1">{{ media.item }}</a>
47+
48+
{% if media.repeats > 1 %}
49+
<div class="flex items-center">
50+
<svg xmlns="http://www.w3.org/2000/svg"
51+
width="24"
52+
height="24"
53+
viewBox="0 0 24 24"
54+
fill="none"
55+
stroke="currentColor"
56+
stroke-width="2"
57+
stroke-linecap="round"
58+
stroke-linejoin="round"
59+
class="w-4 h-4 text-slate-200 mr-1">
60+
<path d="m17 2 4 4-4 4" />
61+
<path d="M3 11v-1a4 4 0 0 1 4-4h14" />
62+
<path d="m7 22-4-4 4-4" />
63+
<path d="M21 13v1a4 4 0 0 1-4 4H3" />
64+
</svg>
65+
<span class="text-sm text-white">{{ media.repeats }}</span>
66+
</div>
67+
{% endif %}
68+
</div>
4669
</td>
4770
{% if media.score is not None %}
4871
<td class="p-2 text-center">

src/templates/app/media_list.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ <h3 class="text-xl font-semibold mb-2">No {{ media_type|media_type_readable_plur
260260
<thead class="text-left text-gray-400 text-sm">
261261
<tr>
262262
<th class="p-2 w-15"></th>
263-
<th class="p-2 w-2/5">Title</th>
263+
<th class="p-2 pe-8 w-2/5">Title</th>
264264
<th class="p-2 text-center">Score</th>
265265
{% if media_type != MediaTypes.MOVIE.value %}<th class="p-2 text-center">Progress</th>{% endif %}
266266
{% if media_type == MediaTypes.TV.value %}<th class="p-2 text-center">Last Watched</th>{% endif %}

0 commit comments

Comments
 (0)