mirror of
https://github.com/bitwarden/browser
synced 2026-01-09 03:53:53 +00:00
105 lines
2.9 KiB
TypeScript
105 lines
2.9 KiB
TypeScript
import { Component, OnInit } from "@angular/core";
|
|
import { ActivatedRoute } from "@angular/router";
|
|
import { combineLatestWith, Observable, startWith, switchMap } from "rxjs";
|
|
|
|
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
|
|
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
|
|
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 {
|
|
protected secrets$: Observable<SecretListView[]>;
|
|
protected search: string;
|
|
|
|
private organizationId: string;
|
|
|
|
constructor(
|
|
private route: ActivatedRoute,
|
|
private secretService: SecretService,
|
|
private dialogService: DialogService,
|
|
private platformUtilsService: PlatformUtilsService,
|
|
private i18nService: I18nService
|
|
) {}
|
|
|
|
ngOnInit() {
|
|
this.secrets$ = this.secretService.secret$.pipe(
|
|
startWith(null),
|
|
combineLatestWith(this.route.params),
|
|
switchMap(async ([_, params]) => {
|
|
this.organizationId = params.organizationId;
|
|
return await this.getSecrets();
|
|
})
|
|
);
|
|
|
|
if (this.route.snapshot.queryParams.search) {
|
|
this.search = this.route.snapshot.queryParams.search;
|
|
}
|
|
}
|
|
|
|
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,
|
|
},
|
|
});
|
|
}
|
|
|
|
copySecretName(name: string) {
|
|
this.platformUtilsService.copyToClipboard(name);
|
|
this.platformUtilsService.showToast(
|
|
"success",
|
|
null,
|
|
this.i18nService.t("valueCopied", this.i18nService.t("name"))
|
|
);
|
|
}
|
|
|
|
async copySecretValue(id: string) {
|
|
const secret = await this.secretService.getBySecretId(id);
|
|
this.platformUtilsService.copyToClipboard(secret.value);
|
|
this.platformUtilsService.showToast(
|
|
"success",
|
|
null,
|
|
this.i18nService.t("valueCopied", this.i18nService.t("value"))
|
|
);
|
|
}
|
|
}
|