mirror of
https://github.com/bitwarden/browser.git
synced 2024-09-27 04:03:00 +02:00
66 lines
1.9 KiB
TypeScript
66 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 { ProjectListView } from "../../models/view/project-list.view";
|
||
|
|
||
|
@Component({
|
||
|
selector: "sm-projects-list",
|
||
|
templateUrl: "./projects-list.component.html",
|
||
|
})
|
||
|
export class ProjectsListComponent implements OnDestroy {
|
||
|
@Input()
|
||
|
get projects(): ProjectListView[] {
|
||
|
return this._projects;
|
||
|
}
|
||
|
set projects(projects: ProjectListView[]) {
|
||
|
this.selection.clear();
|
||
|
this._projects = projects;
|
||
|
}
|
||
|
private _projects: ProjectListView[];
|
||
|
|
||
|
@Output() editProjectEvent = new EventEmitter<string>();
|
||
|
@Output() viewProjectEvent = new EventEmitter<string>();
|
||
|
@Output() deleteProjectEvent = new EventEmitter<ProjectListView[]>();
|
||
|
@Output() onProjectCheckedEvent = new EventEmitter<string[]>();
|
||
|
@Output() newProjectEvent = 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.onProjectCheckedEvent.emit(this.selection.selected));
|
||
|
}
|
||
|
|
||
|
ngOnDestroy(): void {
|
||
|
this.destroy$.next();
|
||
|
this.destroy$.complete();
|
||
|
}
|
||
|
|
||
|
isAllSelected() {
|
||
|
const numSelected = this.selection.selected.length;
|
||
|
const numRows = this.projects.length;
|
||
|
return numSelected === numRows;
|
||
|
}
|
||
|
|
||
|
toggleAll() {
|
||
|
this.isAllSelected()
|
||
|
? this.selection.clear()
|
||
|
: this.selection.select(...this.projects.map((s) => s.id));
|
||
|
}
|
||
|
|
||
|
deleteProject(projectId: string) {
|
||
|
this.deleteProjectEvent.emit(this.projects.filter((p) => p.id == projectId));
|
||
|
}
|
||
|
|
||
|
bulkDeleteProjects() {
|
||
|
this.deleteProjectEvent.emit(
|
||
|
this.projects.filter((project) => this.selection.isSelected(project.id))
|
||
|
);
|
||
|
}
|
||
|
}
|