Fix checkboxes and bulk download

This commit is contained in:
Geomitron
2023-12-25 10:29:57 -06:00
parent 5644ea2447
commit 199374b2e2
12 changed files with 66 additions and 126 deletions

View File

@@ -2,34 +2,29 @@ import { EventEmitter, Injectable } from '@angular/core'
import { SearchService } from './search.service'
// Note: this class prevents event cycles by only emitting events if the checkbox changes
@Injectable({
providedIn: 'root',
})
export class SelectionService {
private allSelected = false
private selectAllChangedEmitter = new EventEmitter<boolean>()
public selections: { [groupId: number]: boolean | undefined } = {}
constructor(searchService: SearchService) {
searchService.searchUpdated.subscribe(() => {
searchService.newSearch.subscribe(() => {
this.selections = {}
this.deselectAll()
})
}
getSelectedResults() {
// TODO
// 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)
isAllSelected() {
return this.allSelected
}
deselectAll() {
this.allSelected = false
for (const groupId in this.selections) {
this.selections[groupId] = false
}
@@ -37,6 +32,7 @@ export class SelectionService {
}
selectAll() {
this.allSelected = true
for (const groupId in this.selections) {
this.selections[groupId] = true
}