mirror of
https://github.com/bitwarden/browser.git
synced 2024-09-27 04:03:00 +02:00
76 lines
2.0 KiB
TypeScript
76 lines
2.0 KiB
TypeScript
|
import { Component, OnInit } from "@angular/core";
|
||
|
import { ActivatedRoute } from "@angular/router";
|
||
|
import { combineLatestWith, Observable, startWith, switchMap } from "rxjs";
|
||
|
|
||
|
import { DialogService } from "@bitwarden/components";
|
||
|
|
||
|
import { ProjectListView } from "../../models/view/project-list.view";
|
||
|
import {
|
||
|
ProjectDeleteDialogComponent,
|
||
|
ProjectDeleteOperation,
|
||
|
} from "../dialog/project-delete-dialog.component";
|
||
|
import {
|
||
|
OperationType,
|
||
|
ProjectDialogComponent,
|
||
|
ProjectOperation,
|
||
|
} from "../dialog/project-dialog.component";
|
||
|
import { ProjectService } from "../project.service";
|
||
|
|
||
|
@Component({
|
||
|
selector: "sm-projects",
|
||
|
templateUrl: "./projects.component.html",
|
||
|
})
|
||
|
export class ProjectsComponent implements OnInit {
|
||
|
projects$: Observable<ProjectListView[]>;
|
||
|
|
||
|
private organizationId: string;
|
||
|
|
||
|
constructor(
|
||
|
private route: ActivatedRoute,
|
||
|
private projectService: ProjectService,
|
||
|
private dialogService: DialogService
|
||
|
) {}
|
||
|
|
||
|
ngOnInit() {
|
||
|
this.projects$ = this.projectService.project$.pipe(
|
||
|
startWith(null),
|
||
|
combineLatestWith(this.route.params),
|
||
|
switchMap(async ([_, params]) => {
|
||
|
this.organizationId = params.organizationId;
|
||
|
return await this.getProjects();
|
||
|
})
|
||
|
);
|
||
|
}
|
||
|
|
||
|
private async getProjects(): Promise<ProjectListView[]> {
|
||
|
return await this.projectService.getProjects(this.organizationId);
|
||
|
}
|
||
|
|
||
|
openEditProject(projectId: string) {
|
||
|
this.dialogService.open<unknown, ProjectOperation>(ProjectDialogComponent, {
|
||
|
data: {
|
||
|
organizationId: this.organizationId,
|
||
|
operation: OperationType.Edit,
|
||
|
projectId: projectId,
|
||
|
},
|
||
|
});
|
||
|
}
|
||
|
|
||
|
openNewProjectDialog() {
|
||
|
this.dialogService.open<unknown, ProjectOperation>(ProjectDialogComponent, {
|
||
|
data: {
|
||
|
organizationId: this.organizationId,
|
||
|
operation: OperationType.Add,
|
||
|
},
|
||
|
});
|
||
|
}
|
||
|
|
||
|
openDeleteProjectDialog(event: ProjectListView[]) {
|
||
|
this.dialogService.open<unknown, ProjectDeleteOperation>(ProjectDeleteDialogComponent, {
|
||
|
data: {
|
||
|
projects: event,
|
||
|
},
|
||
|
});
|
||
|
}
|
||
|
}
|