wip-feat: movie result filter

This commit is contained in:
2025-04-22 13:27:08 -05:00
parent d6328786ba
commit 5c3aa595bf
5 changed files with 115 additions and 16 deletions

View File

@@ -10,11 +10,20 @@ export default class extends Controller {
imdbId: String imdbId: String
}; };
static targets = ['list']
options = []
connect() { connect() {
fetch(`/torrentio/movies/${this.imdbIdValue}`) fetch(`/torrentio/movies/${this.imdbIdValue}`)
.then(res => res.text()) .then(res => res.text())
.then(response => { .then(response => {
this.element.innerHTML = response; this.element.innerHTML = response;
this.options = this.element.querySelectorAll('tbody tr');
}); });
} }
listTargetConnected(target) {
// console.log(target);
}
} }

View File

@@ -6,5 +6,100 @@ import { Controller } from '@hotwired/stimulus';
*/ */
/* stimulusFetch: 'lazy' */ /* stimulusFetch: 'lazy' */
export default class extends Controller { export default class extends Controller {
// ... H264_CODECS = ['h264', 'h.264', 'x264']
H265_CODECS = ['h265', 'h.265', 'x265', 'hevc']
static outlets = ['movie-results']
static targets = ['resolution', 'codec', 'language', 'provider', 'season', 'episode']
static values = {
'media-type': String
}
filter() {
let resultList = this.movieResultsOutlet;
this.activeFilter = {
"resolution": this.resolutionTarget.value,
"codec": this.codecTarget.value,
// "language": this.languageTarget.value,
// "episodeNumber": this.episodeTarget.value,
}
if ("tvshows" === this.mediaTypeValue) {
this.activeFilter.season = this.seasonTarget.value;
}
console.log(this.activeFilter);
const filterOperation = (resultList) => {
if (resultList.options.length <= 0) {
return false;
}
let firstIncluded = true;
let count = 0;
let selectedCount = 0;
resultList.options.forEach((option) => {
if (option.classList.contains('header-row')) {
return;
}
const props = {
"resolution": option.querySelector('#resolution').textContent.trim(),
"codec": option.querySelector('#codec').textContent.trim(),
// "provider": option.querySelector('#provider').textContent,
// "language": option.querySelector('#language').textContent,
// "codec": option.querySelector('#codec').textContent,
}
let include = true;
option.classList.remove('hidden');
// option.selectInput.checked = false;
for (let [key, value] of Object.entries(this.activeFilter)) {
if (value === "") {
continue;
}
if (key === "codec" && value === "h264") {
if (!this.H264_CODECS.includes(props[key].toLowerCase())) {
include = false;
}
} else if (key === "codec" && value === "h265") {
if (!this.H265_CODECS.includes(props[key].toLowerCase())) {
include = false;
}
} else if (key === "language") {
if (!props["languages"].includes(value)) {
include = false;
}
} else if (props[key] !== value) {
include = false;
}
}
if (false === include) {
option.classList.add('hidden');
} else if (true === firstIncluded) {
count = 1;
selectedCount = selectedCount + 1;
// option.selectInput.checked = true;
firstIncluded = false;
} else {
count = count + 1;
}
});
// resultList.getOptionCountEl().innerHTML = `${count} options`;
// resultList.getSelectedCountEl().innerHTML = `${selectedCount} selected`;
this.dispatch('setSeason', {
detail: {season: parseInt(this.activeFilter.season)}
});
}
if (resultList) {
filterOperation(resultList);
} else {
this.resultListOutlets.forEach((resultList) => filterOperation(resultList));
}
}
} }

View File

@@ -26,6 +26,9 @@
<div id="filter" class="w-full p-4 flex flex-row gap-4 bg-stone-500 text-md text-gray-500 dark:text-gray-50 rounded-lg" <div id="filter" class="w-full p-4 flex flex-row gap-4 bg-stone-500 text-md text-gray-500 dark:text-gray-50 rounded-lg"
{{ stimulus_controller('result_filter') }} {{ stimulus_controller('result_filter') }}
{{ stimulus_action('result_filter', 'filter', 'change') }}
data-result-filter-media-type-value="{{ results.media.mediaType }}"
data-result-filter-movie-results-outlet=".results"
> >
<label for="resolution"> <label for="resolution">
Resolution Resolution
@@ -100,7 +103,6 @@
{% endfor %} {% endfor %}
{% endfor %} {% endfor %}
{% endif %} {% endif %}
</twig:Card> </twig:Card>
</div> </div>
</div> </div>

View File

@@ -1,10 +1,6 @@
<div class="p-4 flex flex-col gap-6 bg-orange-500 bg-clip-padding backdrop-filter backdrop-blur-md bg-opacity-60 rounded-md"> <div class="p-4 flex flex-col gap-6 bg-orange-500 bg-clip-padding backdrop-filter backdrop-blur-md bg-opacity-60 rounded-md">
<div class="overflow-hidden rounded-md"> <div class="overflow-hidden rounded-md">
<table class="w-full text-sm text-left rtl:text-right text-gray-500 dark:text-gray-400" <table class="w-full text-sm text-left rtl:text-right text-gray-500 dark:text-gray-400" {{ stimulus_target('movie_results', 'list') }} >
data-movies-list-target="list"
>
<thead class="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400"> <thead class="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400">
<tr class="dark:bg-stone-600 overflow-hidden"> <tr class="dark:bg-stone-600 overflow-hidden">
<th scope="col" <th scope="col"
@@ -39,22 +35,22 @@
<tbody> <tbody>
{% for result in results.results %} {% for result in results.results %}
<tr class="bg-white border-b dark:bg-slate-700 dark:border-gray-600 border-gray-200"> <tr class="bg-white border-b dark:bg-slate-700 dark:border-gray-600 border-gray-200">
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-800 dark:text-gray-50"> <td id="size" class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-800 dark:text-gray-50">
{{ result.size }} {{ result.size }}
</td> </td>
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-800 dark:text-gray-50"> <td id="resolution" class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-800 dark:text-gray-50">
{{ result.resolution }} {{ result.resolution }}
</td> </td>
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-800 dark:text-gray-50"> <td id="codec" class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-800 dark:text-gray-50">
{{ result.codec }} {{ result.codec }}
</td> </td>
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-800 dark:text-gray-50"> <td id="seeders" class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-800 dark:text-gray-50">
{{ result.seeders }} {{ result.seeders }}
</td> </td>
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-800 dark:text-gray-50"> <td id="provider" class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-800 dark:text-gray-50">
{{ result.provider }} {{ result.provider }}
</td> </td>
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-800 dark:text-gray-50"> <td id="language" class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-800 dark:text-gray-50">
{{ result.languageFlags }} {{ result.languageFlags }}
</td> </td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-end text-gray-800 dark:text-gray-50 flex flex-row gap-2 items-center justify-end"> <td class="px-6 py-4 whitespace-nowrap text-sm text-end text-gray-800 dark:text-gray-50 flex flex-row gap-2 items-center justify-end">

View File

@@ -84,9 +84,6 @@
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
<caption>
{{ results.results|length }} results
</caption>
</table> </table>
</div> </div>
</div> </div>