mirror of
https://github.com/bitwarden/browser.git
synced 2024-09-27 04:03:00 +02:00
79 lines
2.2 KiB
TypeScript
79 lines
2.2 KiB
TypeScript
|
import { Component } from "@angular/core";
|
||
|
import { ActivatedRoute } from "@angular/router";
|
||
|
import { combineLatestWith, Observable, startWith, switchMap } from "rxjs";
|
||
|
|
||
|
import { DialogService } from "@bitwarden/components";
|
||
|
|
||
|
import { SecretListView } from "../../models/view/secret-list.view";
|
||
|
import {
|
||
|
SecretDeleteDialogComponent,
|
||
|
SecretDeleteOperation,
|
||
|
} from "../../secrets/dialog/secret-delete.component";
|
||
|
import {
|
||
|
OperationType,
|
||
|
SecretDialogComponent,
|
||
|
SecretOperation,
|
||
|
} from "../../secrets/dialog/secret-dialog.component";
|
||
|
import { SecretService } from "../../secrets/secret.service";
|
||
|
|
||
|
@Component({
|
||
|
selector: "sm-project-secrets",
|
||
|
templateUrl: "./project-secrets.component.html",
|
||
|
})
|
||
|
export class ProjectSecretsComponent {
|
||
|
secrets$: Observable<SecretListView[]>;
|
||
|
|
||
|
private organizationId: string;
|
||
|
private projectId: string;
|
||
|
|
||
|
constructor(
|
||
|
private route: ActivatedRoute,
|
||
|
private secretService: SecretService,
|
||
|
private dialogService: DialogService
|
||
|
) {}
|
||
|
|
||
|
ngOnInit() {
|
||
|
this.secrets$ = this.secretService.secret$.pipe(
|
||
|
startWith(null),
|
||
|
combineLatestWith(this.route.params),
|
||
|
switchMap(async ([_, params]) => {
|
||
|
this.organizationId = params.organizationId;
|
||
|
this.projectId = params.projectId;
|
||
|
return await this.getSecretsByProject();
|
||
|
})
|
||
|
);
|
||
|
}
|
||
|
|
||
|
private async getSecretsByProject(): Promise<SecretListView[]> {
|
||
|
return await this.secretService.getSecretsByProject(this.organizationId, this.projectId);
|
||
|
}
|
||
|
|
||
|
openEditSecret(secretId: string) {
|
||
|
this.dialogService.open<unknown, SecretOperation>(SecretDialogComponent, {
|
||
|
data: {
|
||
|
organizationId: this.organizationId,
|
||
|
operation: OperationType.Edit,
|
||
|
secretId: secretId,
|
||
|
},
|
||
|
});
|
||
|
}
|
||
|
|
||
|
openDeleteSecret(secretIds: string[]) {
|
||
|
this.dialogService.open<unknown, SecretDeleteOperation>(SecretDeleteDialogComponent, {
|
||
|
data: {
|
||
|
secretIds: secretIds,
|
||
|
},
|
||
|
});
|
||
|
}
|
||
|
|
||
|
openNewSecretDialog() {
|
||
|
this.dialogService.open<unknown, SecretOperation>(SecretDialogComponent, {
|
||
|
data: {
|
||
|
organizationId: this.organizationId,
|
||
|
operation: OperationType.Add,
|
||
|
projectId: this.projectId,
|
||
|
},
|
||
|
});
|
||
|
}
|
||
|
}
|