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; 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 { return await this.projectService.getProjects(this.organizationId); } openEditProject(projectId: string) { this.dialogService.open(ProjectDialogComponent, { data: { organizationId: this.organizationId, operation: OperationType.Edit, projectId: projectId, }, }); } openNewProjectDialog() { this.dialogService.open(ProjectDialogComponent, { data: { organizationId: this.organizationId, operation: OperationType.Add, }, }); } openDeleteProjectDialog(event: ProjectListView[]) { this.dialogService.open(ProjectDeleteDialogComponent, { data: { projects: event, }, }); } }