77 lines
2.0 KiB
TypeScript
77 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 { SecretListView } from "../models/view/secret-list.view";
|
|
|
|
import {
|
|
SecretDeleteDialogComponent,
|
|
SecretDeleteOperation,
|
|
} from "./dialog/secret-delete.component";
|
|
import {
|
|
OperationType,
|
|
SecretDialogComponent,
|
|
SecretOperation,
|
|
} from "./dialog/secret-dialog.component";
|
|
import { SecretService } from "./secret.service";
|
|
|
|
@Component({
|
|
selector: "sm-secrets",
|
|
templateUrl: "./secrets.component.html",
|
|
})
|
|
export class SecretsComponent implements OnInit {
|
|
secrets$: Observable<SecretListView[]>;
|
|
|
|
private organizationId: 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;
|
|
return await this.getSecrets();
|
|
})
|
|
);
|
|
}
|
|
|
|
private async getSecrets(): Promise<SecretListView[]> {
|
|
return await this.secretService.getSecrets(this.organizationId);
|
|
}
|
|
|
|
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,
|
|
},
|
|
});
|
|
}
|
|
}
|