mirror of
https://github.com/bitwarden/browser.git
synced 2024-09-27 04:03:00 +02:00
64 lines
1.9 KiB
TypeScript
64 lines
1.9 KiB
TypeScript
|
import { SelectionModel } from "@angular/cdk/collections";
|
||
|
import { Component, EventEmitter, Input, OnDestroy, Output } from "@angular/core";
|
||
|
import { Subject, takeUntil } from "rxjs";
|
||
|
|
||
|
import { SecretListView } from "../models/view/secret-list.view";
|
||
|
|
||
|
@Component({
|
||
|
selector: "sm-secrets-list",
|
||
|
templateUrl: "./secrets-list.component.html",
|
||
|
})
|
||
|
export class SecretsListComponent implements OnDestroy {
|
||
|
@Input()
|
||
|
get secrets(): SecretListView[] {
|
||
|
return this._secrets;
|
||
|
}
|
||
|
set secrets(secrets: SecretListView[]) {
|
||
|
this.selection.clear();
|
||
|
this._secrets = secrets;
|
||
|
}
|
||
|
private _secrets: SecretListView[];
|
||
|
|
||
|
@Output() editSecretEvent = new EventEmitter<string>();
|
||
|
@Output() copySecretNameEvent = new EventEmitter<string>();
|
||
|
@Output() copySecretValueEvent = new EventEmitter<string>();
|
||
|
@Output() projectsEvent = new EventEmitter<string>();
|
||
|
@Output() onSecretCheckedEvent = new EventEmitter<string[]>();
|
||
|
@Output() deleteSecretsEvent = new EventEmitter<string[]>();
|
||
|
@Output() newSecretEvent = new EventEmitter();
|
||
|
@Output() importSecretsEvent = new EventEmitter();
|
||
|
|
||
|
private destroy$: Subject<void> = new Subject<void>();
|
||
|
|
||
|
selection = new SelectionModel<string>(true, []);
|
||
|
|
||
|
constructor() {
|
||
|
this.selection.changed
|
||
|
.pipe(takeUntil(this.destroy$))
|
||
|
.subscribe((_) => this.onSecretCheckedEvent.emit(this.selection.selected));
|
||
|
}
|
||
|
|
||
|
ngOnDestroy(): void {
|
||
|
this.destroy$.next();
|
||
|
this.destroy$.complete();
|
||
|
}
|
||
|
|
||
|
isAllSelected() {
|
||
|
const numSelected = this.selection.selected.length;
|
||
|
const numRows = this.secrets.length;
|
||
|
return numSelected === numRows;
|
||
|
}
|
||
|
|
||
|
toggleAll() {
|
||
|
this.isAllSelected()
|
||
|
? this.selection.clear()
|
||
|
: this.selection.select(...this.secrets.map((s) => s.id));
|
||
|
}
|
||
|
|
||
|
bulkDeleteSecrets() {
|
||
|
if (this.selection.selected.length >= 1) {
|
||
|
this.deleteSecretsEvent.emit(this.selection.selected);
|
||
|
}
|
||
|
}
|
||
|
}
|