bitwarden-estensione-browser/libs/angular/src/components/environment.component.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

64 lines
1.8 KiB
TypeScript
Raw Normal View History

2018-04-04 15:47:43 +02:00
import { Directive, EventEmitter, Output } from "@angular/core";
2022-06-14 17:10:53 +02:00
import { EnvironmentService } from "@bitwarden/common/abstractions/environment.service";
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
2018-04-04 15:47:43 +02:00
@Directive()
2018-04-04 15:47:43 +02:00
export class EnvironmentComponent {
@Output() onSaved = new EventEmitter();
2021-12-16 13:36:21 +01:00
2018-04-04 15:47:43 +02:00
iconsUrl: string;
identityUrl: string;
apiUrl: string;
webVaultUrl: string;
2018-08-20 19:45:32 +02:00
notificationsUrl: string;
2018-04-04 15:47:43 +02:00
baseUrl: string;
showCustom = false;
2021-12-16 13:36:21 +01:00
constructor(
protected platformUtilsService: PlatformUtilsService,
protected environmentService: EnvironmentService,
protected i18nService: I18nService
) {
const urls = this.environmentService.getUrls();
2021-12-16 13:36:21 +01:00
this.baseUrl = urls.base || "";
this.webVaultUrl = urls.webVault || "";
this.apiUrl = urls.api || "";
this.identityUrl = urls.identity || "";
this.iconsUrl = urls.icons || "";
this.notificationsUrl = urls.notifications || "";
2018-04-04 15:47:43 +02:00
}
2021-12-16 13:36:21 +01:00
2018-04-04 15:47:43 +02:00
async submit() {
const resUrls = await this.environmentService.setUrls({
base: this.baseUrl,
api: this.apiUrl,
identity: this.identityUrl,
webVault: this.webVaultUrl,
icons: this.iconsUrl,
2018-08-20 19:45:32 +02:00
notifications: this.notificationsUrl,
2018-04-04 15:47:43 +02:00
});
2021-12-16 13:36:21 +01:00
2018-04-04 15:47:43 +02:00
// re-set urls since service can change them, ex: prefixing https://
this.baseUrl = resUrls.base;
this.apiUrl = resUrls.api;
this.identityUrl = resUrls.identity;
this.webVaultUrl = resUrls.webVault;
this.iconsUrl = resUrls.icons;
2018-08-20 19:45:32 +02:00
this.notificationsUrl = resUrls.notifications;
2021-12-16 13:36:21 +01:00
2018-10-03 05:09:19 +02:00
this.platformUtilsService.showToast("success", null, this.i18nService.t("environmentSaved"));
2018-04-04 15:47:43 +02:00
this.saved();
}
2021-12-16 13:36:21 +01:00
2018-04-04 15:47:43 +02:00
toggleCustom() {
this.showCustom = !this.showCustom;
}
2021-12-16 13:36:21 +01:00
2018-04-04 15:47:43 +02:00
protected saved() {
this.onSaved.emit();
}
}