From 80c5ded7855862d82539a57c0d65af3947da328f Mon Sep 17 00:00:00 2001 From: Addison Beck Date: Thu, 16 Jul 2020 15:39:19 -0500 Subject: [PATCH] moved some cipher selection logic to base component --- src/angular/components/ciphers.component.ts | 27 +++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/angular/components/ciphers.component.ts b/src/angular/components/ciphers.component.ts index 50beab2f543..0b0b8b19781 100644 --- a/src/angular/components/ciphers.component.ts +++ b/src/angular/components/ciphers.component.ts @@ -31,6 +31,8 @@ export class CiphersComponent { private pagedCiphersCount = 0; private refreshing = false; + private maxCheckedCount = 500; + constructor(protected searchService: SearchService) { } async load(filter: (cipher: CipherView) => boolean = null, deleted: boolean = false) { @@ -126,4 +128,29 @@ export class CiphersComponent { this.pagedCiphers = []; this.loadMore(); } + + selectAll(select: boolean) { + if (select) { + this.selectAll(false); + } + const selectCount = select && this.ciphers.length > this.maxCheckedCount ? this.maxCheckedCount : this.ciphers.length; + for (let i = 0; i < selectCount; i++) { + this.checkCipher(this.ciphers[i], select); + } + } + + checkCipher(c: CipherView, select?: boolean) { + (c as any).checked = select == null ? !(c as any).checked : select; + } + + getSelected(): CipherView[] { + if (this.ciphers == null) { + return []; + } + return this.ciphers.filter((c) => !!(c as any).checked); + } + + getSelectedIds(): string[] { + return this.getSelected().map((c) => c.id); + } }