Files
start-os/web/projects/ui/src/app/modals/backup-select/backup-select.page.ts
Matt Hill 1c90303914 closes #2340 and #2431, fixes bug with select all for backup (#2780)
* closes #2340 and #2431, fixes bug with select all for backup

* revefrt mock
2024-11-08 11:57:42 -07:00

71 lines
1.8 KiB
TypeScript

import { Component } from '@angular/core'
import { ModalController } from '@ionic/angular'
import { map } from 'rxjs/operators'
import { DataModel } from 'src/app/services/patch-db/data-model'
import { PatchDB } from 'patch-db-client'
import { firstValueFrom } from 'rxjs'
import { getManifest } from 'src/app/util/get-package-data'
@Component({
selector: 'backup-select',
templateUrl: './backup-select.page.html',
styleUrls: ['./backup-select.page.scss'],
})
export class BackupSelectPage {
hasSelection = false
selectAll = true
pkgs: {
id: string
title: string
icon: string
disabled: boolean
checked: boolean
}[] = []
constructor(
private readonly modalCtrl: ModalController,
private readonly patch: PatchDB<DataModel>,
) {}
async ngOnInit() {
this.pkgs = await firstValueFrom(
this.patch.watch$('packageData').pipe(
map(pkgs => {
return Object.values(pkgs)
.map(pkg => {
const { id, title } = getManifest(pkg)
return {
id,
title,
icon: pkg.icon,
disabled: pkg.stateInfo.state !== 'installed',
checked: false,
}
})
.sort((a, b) =>
b.title.toLowerCase() > a.title.toLowerCase() ? -1 : 1,
)
}),
),
)
}
dismiss(success = false) {
if (success) {
const ids = this.pkgs.filter(p => p.checked).map(p => p.id)
this.modalCtrl.dismiss(ids)
} else {
this.modalCtrl.dismiss()
}
}
handleChange() {
this.hasSelection = this.pkgs.some(p => p.checked)
}
toggleSelectAll() {
this.pkgs.forEach(pkg => (pkg.checked = this.selectAll))
this.selectAll = !this.selectAll
}
}