wip: working 'download selected' button
This commit is contained in:
@@ -3,6 +3,7 @@ export default class DownloadOptionTr extends HTMLTableRowElement {
|
||||
H265_CODECS = ['h265', 'h.265', 'x265', 'hevc']
|
||||
|
||||
#downloadBtnEl;
|
||||
#selectEpisodeInputEl;
|
||||
|
||||
url;
|
||||
size;
|
||||
@@ -37,8 +38,10 @@ export default class DownloadOptionTr extends HTMLTableRowElement {
|
||||
this.season = this.getAttribute('season') ?? null;
|
||||
this.episode = this.getAttribute('episode') ?? null;
|
||||
this.episodeId = this.getAttribute('episode-id') ?? null;
|
||||
|
||||
this.#downloadBtnEl = this.querySelector('.download-btn');
|
||||
this.#selectEpisodeInputEl = this.querySelector('input[type="checkbox"]');
|
||||
console.log(this.#selectEpisodeInputEl)
|
||||
|
||||
this.#downloadBtnEl.addEventListener('click', () => this.download());
|
||||
// document.addEventListener('filterDownloadOptions', this.filter.bind(this));
|
||||
}
|
||||
@@ -46,6 +49,14 @@ export default class DownloadOptionTr extends HTMLTableRowElement {
|
||||
|
||||
}
|
||||
|
||||
get isSelected() {
|
||||
return this.#selectEpisodeInputEl.checked;
|
||||
}
|
||||
|
||||
set isSelected(value) {
|
||||
this.#selectEpisodeInputEl.checked = value;
|
||||
}
|
||||
|
||||
// attribute change
|
||||
attributeChangedCallback(property, oldValue, newValue) {
|
||||
if (oldValue === newValue) return;
|
||||
|
||||
@@ -24,6 +24,7 @@ export default class EpisodeContainer extends HTMLElement {
|
||||
this.#resultsCountBadgeEl.addEventListener('click', () => this.toggleResults());
|
||||
|
||||
document.addEventListener('filterDownloadOptions', this.filter.bind(this));
|
||||
document.addEventListener('downloadSelectedEpisodes', this.downloadSelectedResults.bind(this));
|
||||
document.addEventListener('selectEpisodeForDownload', (e) => this.selectEpisodeForDownload(e.detail.select));
|
||||
}
|
||||
connectedCallback() {
|
||||
@@ -52,6 +53,20 @@ export default class EpisodeContainer extends HTMLElement {
|
||||
}
|
||||
}
|
||||
|
||||
downloadSelectedResults() {
|
||||
if (this.#episodeSelectorEl.disabled === false &&
|
||||
this.#episodeSelectorEl.checked === true
|
||||
) {
|
||||
console.log('episode is selected')
|
||||
this.options.forEach(option => {
|
||||
if (option.isSelected === true) {
|
||||
option.download();
|
||||
}
|
||||
option.isSelected = false;
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
filter({ detail: { activeFilter } }) {
|
||||
let firstIncluded = true;
|
||||
let count = 0;
|
||||
|
||||
@@ -164,10 +164,6 @@ export default class extends Controller {
|
||||
this.tvEpisodeListOutlet.setSeason(event.target.value);
|
||||
}
|
||||
|
||||
uncheckSelectAllBtn() {
|
||||
this.selectAllTarget.checked = false;
|
||||
}
|
||||
|
||||
downloadSeason() {
|
||||
fetch(`/api/download/season/${this.imdbIdValue}/${this.activeFilter['season']}`, {
|
||||
headers: {
|
||||
@@ -177,11 +173,6 @@ export default class extends Controller {
|
||||
}
|
||||
|
||||
downloadSelectedEpisodes() {
|
||||
this.tvResultsOutlets.forEach(episode => {
|
||||
if (episode.isActive() && episode.isSelected()) {
|
||||
episode.download();
|
||||
}
|
||||
});
|
||||
this.selectAllTarget.checked = false;
|
||||
document.dispatchEvent(new CustomEvent('downloadSelectedEpisodes', {}));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user