wip-feat: season filter
This commit is contained in:
@@ -14,9 +14,10 @@ export default class extends Controller {
|
|||||||
seasons = []
|
seasons = []
|
||||||
|
|
||||||
static outlets = ['movie-results', 'tv-results']
|
static outlets = ['movie-results', 'tv-results']
|
||||||
static targets = ['resolution', 'codec', 'language', 'provider', 'season', 'episode']
|
static targets = ['resolution', 'codec', 'language', 'provider', 'season']
|
||||||
static values = {
|
static values = {
|
||||||
'media-type': String
|
'media-type': String,
|
||||||
|
'episodes': Array,
|
||||||
}
|
}
|
||||||
|
|
||||||
async movieResultsOutletConnected(outlet) {
|
async movieResultsOutletConnected(outlet) {
|
||||||
@@ -34,8 +35,6 @@ export default class extends Controller {
|
|||||||
outlet.options.forEach((option) => {
|
outlet.options.forEach((option) => {
|
||||||
this.addLanguages(option, option.dataset);
|
this.addLanguages(option, option.dataset);
|
||||||
this.addProviders(option, option.dataset);
|
this.addProviders(option, option.dataset);
|
||||||
// this.addSeasons(option, props);
|
|
||||||
// this.addEpisodes(option, props);
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,32 +64,7 @@ export default class extends Controller {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
addSeasons(option, props) {
|
async filter() {
|
||||||
if (!this.seasons.includes(parseInt(props['season']))) {
|
|
||||||
this.seasons.push(parseInt(props['season']));
|
|
||||||
}
|
|
||||||
|
|
||||||
this.seasonTarget.innerHTML = '<option value="">n/a</option>';
|
|
||||||
this.seasonTarget.innerHTML += this.seasons.sort((a, b) => a - b)
|
|
||||||
.filter((season) => parseInt(season))
|
|
||||||
.map((season) => '<option value="'+season+'">'+season+'</option>')
|
|
||||||
.join('');
|
|
||||||
this.seasonTarget.querySelectorAll('option')[1].selected = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
addEpisodes(option, props) {
|
|
||||||
if (!this.episodes.includes(parseInt(props['episodeNumber']))) {
|
|
||||||
this.episodes.push(parseInt(props['episodeNumber']));
|
|
||||||
}
|
|
||||||
|
|
||||||
this.episodeTarget.innerHTML = this.episodes.sort((a, b) => a - b)
|
|
||||||
.filter((episode) => parseInt(episode))
|
|
||||||
.map((episode) => '<option value="'+episode+'">'+episode+'</option>')
|
|
||||||
.join('');
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
filter() {
|
|
||||||
let results = [];
|
let results = [];
|
||||||
this.activeFilter = {
|
this.activeFilter = {
|
||||||
"resolution": this.resolutionTarget.value,
|
"resolution": this.resolutionTarget.value,
|
||||||
@@ -107,8 +81,8 @@ export default class extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const filterOperation = (resultList) => {
|
const filterOperation = (resultList) => {
|
||||||
if (resultList.options.length <= 0) {
|
if (false === resultList.isActive) {
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let firstIncluded = true;
|
let firstIncluded = true;
|
||||||
@@ -121,12 +95,10 @@ export default class extends Controller {
|
|||||||
"codec": option.querySelector('#codec').textContent.trim(),
|
"codec": option.querySelector('#codec').textContent.trim(),
|
||||||
"provider": option.querySelector('#provider').textContent.trim(),
|
"provider": option.querySelector('#provider').textContent.trim(),
|
||||||
"languages": JSON.parse(option.dataset['languages']),
|
"languages": JSON.parse(option.dataset['languages']),
|
||||||
// "codec": option.querySelector('#codec').textContent,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let include = true;
|
let include = true;
|
||||||
option.classList.remove('hidden');
|
option.classList.remove('hidden');
|
||||||
// option.selectInput.checked = false;
|
|
||||||
|
|
||||||
for (let [key, value] of Object.entries(this.activeFilter)) {
|
for (let [key, value] of Object.entries(this.activeFilter)) {
|
||||||
if (value === "") {
|
if (value === "") {
|
||||||
@@ -164,13 +136,17 @@ export default class extends Controller {
|
|||||||
resultList.countTarget.innerText = count;
|
resultList.countTarget.innerText = count;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// resultList.getOptionCountEl().innerHTML = `${count} options`;
|
|
||||||
// resultList.getSelectedCountEl().innerHTML = `${selectedCount} selected`;
|
|
||||||
this.dispatch('setSeason', {
|
|
||||||
detail: {season: parseInt(this.activeFilter.season)}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ("tvshows" === this.mediaTypeValue) {
|
||||||
|
await results.forEach(async (list) => {
|
||||||
|
if (list.seasonValue === this.seasonTarget.value) {
|
||||||
|
await list.setActive();
|
||||||
|
} else {
|
||||||
|
list.setInActive();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
results.forEach((list) => filterOperation(list));
|
results.forEach((list) => filterOperation(list));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ export default class extends Controller {
|
|||||||
static outlets = ['loading-icon']
|
static outlets = ['loading-icon']
|
||||||
|
|
||||||
options = []
|
options = []
|
||||||
|
optionsLoaded = false
|
||||||
|
|
||||||
async connect() {
|
async connect() {
|
||||||
await this.setOptions();
|
await this.setOptions();
|
||||||
@@ -30,11 +31,27 @@ export default class extends Controller {
|
|||||||
.then(response => {
|
.then(response => {
|
||||||
this.element.innerHTML = response;
|
this.element.innerHTML = response;
|
||||||
this.options = this.element.querySelectorAll('tbody tr');
|
this.options = this.element.querySelectorAll('tbody tr');
|
||||||
|
this.optionsLoaded = true;
|
||||||
this.loadingIconOutlet.increaseCount();
|
this.loadingIconOutlet.increaseCount();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async setActive() {
|
||||||
|
this.activeValue = true;
|
||||||
|
this.element.classList.remove('hidden');
|
||||||
|
await this.setOptions();
|
||||||
|
}
|
||||||
|
|
||||||
|
setInActive() {
|
||||||
|
this.activeValue = false;
|
||||||
|
this.element.classList.add('hidden');
|
||||||
|
}
|
||||||
|
|
||||||
|
isActive() {
|
||||||
|
return this.activeValue;
|
||||||
|
}
|
||||||
|
|
||||||
toggleList() {
|
toggleList() {
|
||||||
this.listTarget.classList.toggle('hidden');
|
this.listTarget.classList.toggle('hidden');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,16 +72,19 @@
|
|||||||
{% if results.media.mediaType == "tvshows" %}
|
{% if results.media.mediaType == "tvshows" %}
|
||||||
<label for="season">
|
<label for="season">
|
||||||
Season
|
Season
|
||||||
<select id="season" name="season" data-result-filter-target="season" class="px-1 py-0.5 bg-stone-100 text-gray-800 rounded-sm">
|
<select id="season" name="season" value="1" data-result-filter-target="season" class="px-1 py-0.5 bg-stone-100 text-gray-800 rounded-sm">
|
||||||
<option selected value="">n/a</option>
|
<option selected value="1">1</option>
|
||||||
</select>
|
{% for season in range(2, results.media.episodes|length) %}
|
||||||
</label>
|
<option value="{{ season }}">{{ season }}</option>
|
||||||
<label for="episodeNumber">
|
{% endfor %}
|
||||||
Episode
|
|
||||||
<select id="episodeNumber" name="episodeNumber" data-result-filter-target="episode" class="px-1 py-0.5 bg-stone-100 text-gray-800 rounded-sm">
|
|
||||||
<option selected value="">n/a</option>
|
|
||||||
</select>
|
</select>
|
||||||
</label>
|
</label>
|
||||||
|
{# <label for="episodeNumber">#}
|
||||||
|
{# Episode#}
|
||||||
|
{# <select id="episodeNumber" name="episodeNumber" data-result-filter-target="episode" class="px-1 py-0.5 bg-stone-100 text-gray-800 rounded-sm">#}
|
||||||
|
{# <option selected value="">n/a</option>#}
|
||||||
|
{# </select>#}
|
||||||
|
{# </label>#}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -54,7 +54,7 @@
|
|||||||
</thead>
|
</thead>
|
||||||
<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" data-languages="{{ result.languages|json_encode }}" data-provider="{{ result.provider }}">
|
<tr class="bg-white border-b dark:bg-slate-700 dark:border-gray-600 border-gray-200" data-languages="{{ result.languages|json_encode }}" data-season="{{ results.season }}">
|
||||||
<td id="size" 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>
|
||||||
@@ -71,7 +71,7 @@
|
|||||||
{{ result.provider }}
|
{{ result.provider }}
|
||||||
</td>
|
</td>
|
||||||
<td id="language" class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-800 dark:text-gray-50" data-languages="{{ result.languages|json_encode }}">
|
<td id="language" class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-800 dark:text-gray-50" data-languages="{{ result.languages|json_encode }}">
|
||||||
{{ result.languageFlags }}
|
{{ result.languageFlags|raw }}
|
||||||
</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">
|
||||||
<span class="p-1.5 bg-green-600 rounded-md text-gray-50">
|
<span class="p-1.5 bg-green-600 rounded-md text-gray-50">
|
||||||
|
|||||||
Reference in New Issue
Block a user