mirror of
https://github.com/Myxelium/Bridge-Multi.git
synced 2026-04-11 22:29:38 +00:00
Fix checkboxes and bulk download
This commit is contained in:
@@ -1,12 +1,13 @@
|
|||||||
<app-search-bar></app-search-bar>
|
<app-search-bar />
|
||||||
<div class="flex flex-1 overflow-hidden">
|
<div class="flex flex-1 overflow-hidden">
|
||||||
<div
|
<div
|
||||||
|
#resultTableDiv
|
||||||
class="basis-2/3 flex-1 overflow-y-auto scrollbar scrollbar-w-2 scrollbar-h-2 scrollbar-track-base-300 scrollbar-thumb-neutral scrollbar-thumb-rounded-full"
|
class="basis-2/3 flex-1 overflow-y-auto scrollbar scrollbar-w-2 scrollbar-h-2 scrollbar-track-base-300 scrollbar-thumb-neutral scrollbar-thumb-rounded-full"
|
||||||
(scroll)="resultTable.tableScrolled($event)">
|
(scroll)="resultTable.tableScrolled($event)">
|
||||||
<app-result-table #resultTable (rowClicked)="chartSidebar.onRowClicked($event)"></app-result-table>
|
<app-result-table #resultTable (rowClicked)="chartSidebar.onRowClicked($event)" />
|
||||||
</div>
|
</div>
|
||||||
<div class="basis-1/3 min-w-[310px] max-w-[512px]">
|
<div class="basis-1/3 min-w-[310px] max-w-[512px]">
|
||||||
<app-chart-sidebar #chartSidebar></app-chart-sidebar>
|
<app-chart-sidebar #chartSidebar />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<app-status-bar #statusBar></app-status-bar>
|
<app-status-bar />
|
||||||
|
|||||||
@@ -1,36 +1,21 @@
|
|||||||
import { Component, HostBinding, ViewChild } from '@angular/core'
|
import { AfterViewInit, Component, ElementRef, HostBinding, ViewChild } from '@angular/core'
|
||||||
|
|
||||||
import { SearchService } from 'src-angular/app/core/services/search.service'
|
import { SearchService } from 'src-angular/app/core/services/search.service'
|
||||||
|
|
||||||
import { ChartSidebarComponent } from './chart-sidebar/chart-sidebar.component'
|
|
||||||
import { ResultTableComponent } from './result-table/result-table.component'
|
|
||||||
import { StatusBarComponent } from './status-bar/status-bar.component'
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-browse',
|
selector: 'app-browse',
|
||||||
templateUrl: './browse.component.html',
|
templateUrl: './browse.component.html',
|
||||||
})
|
})
|
||||||
export class BrowseComponent {
|
export class BrowseComponent implements AfterViewInit {
|
||||||
@HostBinding('class.contents') contents = true
|
@HostBinding('class.contents') contents = true
|
||||||
@ViewChild('resultTable', { static: true }) resultTable: ResultTableComponent
|
|
||||||
@ViewChild('chartSidebar', { static: true }) chartSidebar: ChartSidebarComponent
|
@ViewChild('resultTableDiv', { static: true }) resultTableDiv: ElementRef
|
||||||
@ViewChild('statusBar', { static: true }) statusBar: StatusBarComponent
|
|
||||||
|
|
||||||
constructor(private searchService: SearchService) { }
|
constructor(private searchService: SearchService) { }
|
||||||
|
|
||||||
// TODO
|
ngAfterViewInit() {
|
||||||
// ngAfterViewInit() {
|
this.searchService.newSearch.subscribe(() => {
|
||||||
// const $tableColumn = $('#table-column')
|
this.resultTableDiv.nativeElement.scrollTop = 0
|
||||||
// $tableColumn.on('scroll', () => {
|
})
|
||||||
// const pos = $tableColumn[0].scrollTop + $tableColumn[0].offsetHeight
|
}
|
||||||
// const max = $tableColumn[0].scrollHeight
|
|
||||||
// if (pos >= max - 5) {
|
|
||||||
// this.searchService.updateScroll()
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
|
|
||||||
// this.searchService.onNewSearch(() => {
|
|
||||||
// $tableColumn.scrollTop(0)
|
|
||||||
// })
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ export class ChartSidebarComponent implements OnInit {
|
|||||||
) { }
|
) { }
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.searchService.searchUpdated.subscribe(() => {
|
this.searchService.newSearch.subscribe(() => {
|
||||||
this.charts = null
|
this.charts = null
|
||||||
this.selectedChart = null
|
this.selectedChart = null
|
||||||
})
|
})
|
||||||
@@ -280,8 +280,7 @@ export class ChartSidebarComponent implements OnInit {
|
|||||||
* Adds the selected chart to the download queue.
|
* Adds the selected chart to the download queue.
|
||||||
*/
|
*/
|
||||||
onDownloadClicked() {
|
onDownloadClicked() {
|
||||||
this.downloadService.addDownload(this.selectedChart!.md5, `${this.selectedChart!.artist ?? 'Unknown Artist'
|
this.downloadService.addDownload(this.selectedChart!)
|
||||||
} - ${this.selectedChart!.name ?? 'Unknown Name'} (${this.selectedChart!.charter ?? 'Unknown Charter'})`)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public showMenu() {
|
public showMenu() {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<td>
|
<td>
|
||||||
<input #checkAllCheckbox type="checkbox" class="checkbox" (click)="$event.stopPropagation()" [(ngModel)]="selected" />
|
<input type="checkbox" class="checkbox" (click)="$event.stopPropagation()" [(ngModel)]="selected" />
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<span *ngIf="song.length > 1" class="rounded-sm bg-accent text-accent-content px-1 mr-1 font-bold">{{ song.length }}</span> {{ song[0].name }}
|
<span *ngIf="song.length > 1" class="rounded-sm bg-accent text-accent-content px-1 mr-1 font-bold">{{ song.length }}</span> {{ song[0].name }}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ export class ResultTableRowComponent implements OnInit {
|
|||||||
constructor(private selectionService: SelectionService) { }
|
constructor(private selectionService: SelectionService) { }
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.selectionService.selections[this.groupId] = false
|
this.selectionService.selections[this.groupId] = this.selectionService.isAllSelected()
|
||||||
}
|
}
|
||||||
|
|
||||||
get groupId() {
|
get groupId() {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th class="collapsing" id="checkboxColumn">
|
<th class="collapsing" id="checkboxColumn">
|
||||||
<input #checkAllCheckbox type="checkbox" class="checkbox" (change)="checkAll(checkAllCheckbox.checked)" />
|
<input type="checkbox" class="checkbox" [(ngModel)]="allSelected" />
|
||||||
</th>
|
</th>
|
||||||
<th [ngClass]="sortDirection" (click)="onColClicked('name')">
|
<th [ngClass]="sortDirection" (click)="onColClicked('name')">
|
||||||
Name <i *ngIf="sortColumn === 'name'" class="bi bi-caret-{{ sortDirection === 'ascending' ? 'down' : 'up' }}-fill"></i>
|
Name <i *ngIf="sortColumn === 'name'" class="bi bi-caret-{{ sortDirection === 'ascending' ? 'down' : 'up' }}-fill"></i>
|
||||||
|
|||||||
@@ -32,8 +32,13 @@ export class ResultTableComponent implements OnInit {
|
|||||||
) { }
|
) { }
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.searchService.searchUpdated.subscribe(() => {
|
this.searchService.newSearch.subscribe(() => {
|
||||||
this.activeSong = null
|
this.activeSong = null
|
||||||
|
this.sortDirection = 'ascending'
|
||||||
|
this.sortColumn = null
|
||||||
|
this.updateSort()
|
||||||
|
})
|
||||||
|
this.searchService.updateSearch.subscribe(() => {
|
||||||
this.updateSort()
|
this.updateSort()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -65,18 +70,17 @@ export class ResultTableComponent implements OnInit {
|
|||||||
private updateSort() {
|
private updateSort() {
|
||||||
const col = this.sortColumn
|
const col = this.sortColumn
|
||||||
if (col !== null) {
|
if (col !== null) {
|
||||||
const groupedSongs = sortBy(this.searchService.groupedSongs, song => song[0][col])
|
const groupedSongs = sortBy(this.searchService.groupedSongs, song => song[0][col]?.toLowerCase())
|
||||||
if (this.sortDirection === 'descending') { groupedSongs.reverse() }
|
if (this.sortDirection === 'descending') { groupedSongs.reverse() }
|
||||||
this.searchService.groupedSongs = groupedSongs
|
this.searchService.groupedSongs = groupedSongs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
get allSelected() {
|
||||||
* Called when the user checks the `checkboxColumn`.
|
return this.selectionService.isAllSelected()
|
||||||
*/
|
}
|
||||||
checkAll(isChecked: boolean) {
|
set allSelected(value: boolean) {
|
||||||
console.log(isChecked)
|
if (value) {
|
||||||
if (isChecked) {
|
|
||||||
this.selectionService.selectAll()
|
this.selectionService.selectAll()
|
||||||
} else {
|
} else {
|
||||||
this.selectionService.deselectAll()
|
this.selectionService.deselectAll()
|
||||||
|
|||||||
@@ -14,16 +14,6 @@ export class StatusBarComponent {
|
|||||||
|
|
||||||
@ViewChild('downloadsModal', { static: false }) downloadsModalComponent: ElementRef
|
@ViewChild('downloadsModal', { static: false }) downloadsModalComponent: ElementRef
|
||||||
|
|
||||||
multipleCompleted = false
|
|
||||||
downloading = false
|
|
||||||
error = false
|
|
||||||
percent = 0
|
|
||||||
// TODO
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
batchResults: any[]
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
chartGroups: any[][]
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public downloadService: DownloadService,
|
public downloadService: DownloadService,
|
||||||
public searchService: SearchService,
|
public searchService: SearchService,
|
||||||
@@ -41,59 +31,10 @@ export class StatusBarComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async downloadSelected() {
|
async downloadSelected() {
|
||||||
// this.chartGroups = []
|
const selectedGroupIds = this.selectedGroupIds
|
||||||
// // TODO
|
for (const chart of this.searchService.groupedSongs.filter(gs => selectedGroupIds.includes(gs[0].groupId))) {
|
||||||
// // this.batchResults = await window.electron.invoke.getBatchSongDetails(this.selectedResults.map(result => result.id))
|
this.downloadService.addDownload(chart[0])
|
||||||
// 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) {
|
|
||||||
// // this.searchService.sortChart(versions)
|
|
||||||
// const downloadVersion = versions[0]
|
|
||||||
// const downloadSong = this.selectedResults.find(song => song.id === downloadVersion.songID)!
|
|
||||||
// this.downloadService.addDownload(
|
|
||||||
// downloadVersion.versionID, {
|
|
||||||
// chartName: downloadVersion.chartName,
|
|
||||||
// artist: downloadSong.artist,
|
|
||||||
// charter: downloadVersion.charters,
|
|
||||||
// driveData: downloadVersion.driveData,
|
|
||||||
// })
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// // TODO
|
|
||||||
// // $('#selectedModal').modal('show')
|
|
||||||
// // [download all charts for each song] [deselect these songs] [X]
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
downloadAllCharts() {
|
|
||||||
// const songChartGroups = groupBy(this.batchResults, 'songID', 'chartID')
|
|
||||||
// for (const chart of songChartGroups) {
|
|
||||||
// // this.searchService.sortChart(chart)
|
|
||||||
// const downloadVersion = chart[0]
|
|
||||||
// const downloadSong = this.selectedResults.find(song => song.id === downloadVersion.songID)!
|
|
||||||
// this.downloadService.addDownload(
|
|
||||||
// downloadVersion.versionID, {
|
|
||||||
// chartName: downloadVersion.chartName,
|
|
||||||
// artist: downloadSong.artist,
|
|
||||||
// charter: downloadVersion.charters,
|
|
||||||
// driveData: downloadVersion.driveData,
|
|
||||||
// }
|
|
||||||
// )
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
deselectSongsWithMultipleCharts() {
|
|
||||||
// TODO
|
|
||||||
// for (const chartGroup of this.chartGroups) {
|
|
||||||
// this.selectionService.deselectSong(chartGroup[0].songID)
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
clearCompleted() {
|
clearCompleted() {
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import { EventEmitter, Injectable, NgZone } from '@angular/core'
|
import { EventEmitter, Injectable, NgZone } from '@angular/core'
|
||||||
|
|
||||||
import { assign } from 'lodash'
|
import { assign } from 'lodash'
|
||||||
|
import { ChartData } from 'src-shared/interfaces/search.interface'
|
||||||
|
import { removeStyleTags } from 'src-shared/UtilFunctions'
|
||||||
|
|
||||||
import { DownloadProgress } from '../../../../src-shared/interfaces/download.interface'
|
import { DownloadProgress } from '../../../../src-shared/interfaces/download.interface'
|
||||||
|
|
||||||
@@ -16,7 +18,7 @@ export class DownloadService {
|
|||||||
window.electron.on.downloadQueueUpdate(download => zone.run(() => {
|
window.electron.on.downloadQueueUpdate(download => zone.run(() => {
|
||||||
const downloadIndex = this.downloads.findIndex(d => d.md5 === download.md5)
|
const downloadIndex = this.downloads.findIndex(d => d.md5 === download.md5)
|
||||||
if (download.type === 'cancel') {
|
if (download.type === 'cancel') {
|
||||||
this.downloads = this.downloads.filter(d => d.md5 !== this.downloads[downloadIndex].md5)
|
this.downloads = this.downloads.filter(d => d.md5 !== this.downloads[downloadIndex]?.md5)
|
||||||
} else if (downloadIndex === -1) {
|
} else if (downloadIndex === -1) {
|
||||||
this.downloads.push(download)
|
this.downloads.push(download)
|
||||||
} else {
|
} else {
|
||||||
@@ -50,13 +52,16 @@ export class DownloadService {
|
|||||||
return this.downloads.find(download => download.type === 'error') ? true : false
|
return this.downloads.find(download => download.type === 'error') ? true : false
|
||||||
}
|
}
|
||||||
|
|
||||||
addDownload(md5: string, chartName: string) {
|
addDownload(chart: ChartData) {
|
||||||
if (!this.downloads.find(d => d.md5 === md5)) { // Don't download something twice
|
if (!this.downloads.find(d => d.md5 === chart.md5)) { // Don't download something twice
|
||||||
if (this.downloads.every(d => d.type === 'done')) { // Reset overall progress bar if it finished
|
if (this.downloads.every(d => d.type === 'done')) { // Reset overall progress bar if it finished
|
||||||
this.downloads.forEach(d => d.stale = true)
|
this.downloads.forEach(d => d.stale = true)
|
||||||
}
|
}
|
||||||
|
const chartName = `${removeStyleTags(chart.artist ?? 'Unknown Artist')
|
||||||
|
} - ${removeStyleTags(chart.name ?? 'Unknown Name')
|
||||||
|
} (${removeStyleTags(chart.charter ?? 'Unknown Charter')})`
|
||||||
this.downloads.push({
|
this.downloads.push({
|
||||||
md5,
|
md5: chart.md5,
|
||||||
chartName,
|
chartName,
|
||||||
header: 'Waiting for other downloads to finish...',
|
header: 'Waiting for other downloads to finish...',
|
||||||
body: '',
|
body: '',
|
||||||
@@ -64,7 +69,7 @@ export class DownloadService {
|
|||||||
type: 'good',
|
type: 'good',
|
||||||
isPath: false,
|
isPath: false,
|
||||||
})
|
})
|
||||||
window.electron.emit.download({ action: 'add', md5, chartName })
|
window.electron.emit.download({ action: 'add', md5: chart.md5, chartName })
|
||||||
}
|
}
|
||||||
this.downloadCountChanges.emit(this.downloadCount)
|
this.downloadCountChanges.emit(this.downloadCount)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,8 @@ export class SearchService {
|
|||||||
public searchLoading = false
|
public searchLoading = false
|
||||||
public songsResponse: Partial<SearchResult>
|
public songsResponse: Partial<SearchResult>
|
||||||
public currentPage = 1
|
public currentPage = 1
|
||||||
public searchUpdated = new EventEmitter<Partial<SearchResult>>()
|
public newSearch = new EventEmitter<Partial<SearchResult>>()
|
||||||
|
public updateSearch = new EventEmitter<Partial<SearchResult>>()
|
||||||
public isDefaultSearch = true
|
public isDefaultSearch = true
|
||||||
|
|
||||||
public groupedSongs: ChartData[][]
|
public groupedSongs: ChartData[][]
|
||||||
@@ -115,7 +116,11 @@ export class SearchService {
|
|||||||
.value()
|
.value()
|
||||||
)
|
)
|
||||||
|
|
||||||
this.searchUpdated.emit(response)
|
if (nextPage) {
|
||||||
|
this.updateSearch.emit(response)
|
||||||
|
} else {
|
||||||
|
this.newSearch.emit(response)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -154,7 +159,7 @@ export class SearchService {
|
|||||||
.value()
|
.value()
|
||||||
)
|
)
|
||||||
|
|
||||||
this.searchUpdated.emit(response)
|
this.newSearch.emit(response)
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,34 +2,29 @@ import { EventEmitter, Injectable } from '@angular/core'
|
|||||||
|
|
||||||
import { SearchService } from './search.service'
|
import { SearchService } from './search.service'
|
||||||
|
|
||||||
// Note: this class prevents event cycles by only emitting events if the checkbox changes
|
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root',
|
providedIn: 'root',
|
||||||
})
|
})
|
||||||
export class SelectionService {
|
export class SelectionService {
|
||||||
|
|
||||||
|
private allSelected = false
|
||||||
private selectAllChangedEmitter = new EventEmitter<boolean>()
|
private selectAllChangedEmitter = new EventEmitter<boolean>()
|
||||||
|
|
||||||
public selections: { [groupId: number]: boolean | undefined } = {}
|
public selections: { [groupId: number]: boolean | undefined } = {}
|
||||||
|
|
||||||
constructor(searchService: SearchService) {
|
constructor(searchService: SearchService) {
|
||||||
searchService.searchUpdated.subscribe(() => {
|
searchService.newSearch.subscribe(() => {
|
||||||
this.selections = {}
|
this.selections = {}
|
||||||
|
this.deselectAll()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
getSelectedResults() {
|
isAllSelected() {
|
||||||
// TODO
|
return this.allSelected
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
return [] as any[] // this.searchResults.filter(result => this.selections[result.id] === true)
|
|
||||||
}
|
|
||||||
|
|
||||||
onSelectAllChanged(callback: (selected: boolean) => void) {
|
|
||||||
this.selectAllChangedEmitter.subscribe(callback)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
deselectAll() {
|
deselectAll() {
|
||||||
|
this.allSelected = false
|
||||||
for (const groupId in this.selections) {
|
for (const groupId in this.selections) {
|
||||||
this.selections[groupId] = false
|
this.selections[groupId] = false
|
||||||
}
|
}
|
||||||
@@ -37,6 +32,7 @@ export class SelectionService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
selectAll() {
|
selectAll() {
|
||||||
|
this.allSelected = true
|
||||||
for (const groupId in this.selections) {
|
for (const groupId in this.selections) {
|
||||||
this.selections[groupId] = true
|
this.selections[groupId] = true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,13 +67,17 @@ export class DownloadQueue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
remove(md5: string) {
|
remove(md5: string) {
|
||||||
if (this.downloadQueue[0]?.md5 === md5) {
|
const currentDownload = this.downloadQueue[0]
|
||||||
this.downloadQueue[0].cancel()
|
if (currentDownload?.md5 === md5) {
|
||||||
|
currentDownload.cancel()
|
||||||
this.downloadRunning = false
|
this.downloadRunning = false
|
||||||
}
|
}
|
||||||
this.downloadQueue = this.downloadQueue.filter(cd => cd.md5 !== md5)
|
this.downloadQueue = this.downloadQueue.filter(cd => cd.md5 !== md5)
|
||||||
this.retryQueue = this.retryQueue.filter(cd => cd.md5 !== md5)
|
this.retryQueue = this.retryQueue.filter(cd => cd.md5 !== md5)
|
||||||
this.erroredQueue = this.erroredQueue.filter(cd => cd.md5 !== md5)
|
this.erroredQueue = this.erroredQueue.filter(cd => cd.md5 !== md5)
|
||||||
|
if (currentDownload) {
|
||||||
|
this.moveQueue()
|
||||||
|
}
|
||||||
|
|
||||||
emitIpcEvent('downloadQueueUpdate', {
|
emitIpcEvent('downloadQueueUpdate', {
|
||||||
md5,
|
md5,
|
||||||
|
|||||||
Reference in New Issue
Block a user