Download Selected button, Various small improvements

This commit is contained in:
Geomitron
2020-02-11 23:52:22 -05:00
parent db083d573a
commit 7d4d339018
17 changed files with 192 additions and 58 deletions

View File

@@ -1,6 +1,9 @@
import { Component, ChangeDetectorRef } from '@angular/core'
import { Component, ChangeDetectorRef, Output, EventEmitter } from '@angular/core'
import { SongResult } from 'src/electron/shared/interfaces/search.interface'
import { DownloadService } from 'src/app/core/services/download.service'
import { ElectronService } from 'src/app/core/services/electron.service'
import { groupBy } from 'src/electron/shared/UtilFunctions'
import { VersionResult } from 'src/electron/shared/interfaces/songDetails.interface'
@Component({
selector: 'app-status-bar',
@@ -9,12 +12,16 @@ import { DownloadService } from 'src/app/core/services/download.service'
})
export class StatusBarComponent {
@Output() deselectSongs = new EventEmitter<SongResult['id'][]>()
resultCount = 0
downloading = false
percent = 0
selectedResults: SongResult[] = []
batchResults: VersionResult[]
chartGroups: VersionResult[][]
constructor(downloadService: DownloadService, ref: ChangeDetectorRef) {
constructor(private electronService: ElectronService, private downloadService: DownloadService, ref: ChangeDetectorRef) {
downloadService.onDownloadUpdated(() => {
this.downloading = downloadService.downloadCount > 0
this.percent = downloadService.totalPercent
@@ -36,9 +43,50 @@ export class StatusBarComponent {
this.selectedResults = this.selectedResults.filter(oldResult => oldResult.id != result.id)
}
downloadSelected() {
// TODO send query to get versions; for any with more than one chart, show modal for confirmation:
// "some selected songs have more than one chart: ___" [download all charts for each song] [deselect these songs] [X]
console.log(this.selectedResults)
async downloadSelected() {
this.chartGroups = []
this.batchResults = await this.electronService.invoke('batch-song-details', this.selectedResults.map(result => result.id))
const versionGroups = groupBy(this.batchResults, 'songID')
for (const versionGroup of versionGroups) {
if (versionGroup.findIndex(version => version.chartID != versionGroup[0].chartID) != -1) {
// Must have multiple charts of this song
this.chartGroups.push(versionGroup.filter(version => version.versionID == version.latestVersionID))
}
}
if (this.chartGroups.length == 0) {
for (const versions of versionGroups) {
const downloadVersion = versions.find(version => version.versionID == version.latestVersionID)
const downloadSong = this.selectedResults.find(song => song.id == downloadVersion.songID)
this.downloadService.addDownload(
downloadVersion.versionID, {
avTagName: downloadVersion.avTagName,
artist: downloadSong.artist,
charter: downloadVersion.charters,
links: JSON.parse(downloadVersion.downloadLink)
})
}
} else {
$('#selectedModal').modal('show')
//[download all charts for each song] [deselect these songs] [X]
}
}
downloadAllCharts() {
for (const version of this.batchResults) {
if (version.versionID != version.latestVersionID) { continue }
const downloadSong = this.selectedResults.find(song => song.id == version.songID)
this.downloadService.addDownload(
version.versionID, {
avTagName: version.avTagName,
artist: downloadSong.artist,
charter: version.charters,
links: JSON.parse(version.downloadLink)
})
}
}
deselectSongsWithMultipleCharts() {
this.deselectSongs.emit(this.chartGroups.map(group => group[0].songID))
}
}