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

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

75 lines
2.1 KiB
TypeScript
Raw Normal View History

2018-04-04 15:47:43 +02:00
import { Directive, EventEmitter, Output } from "@angular/core";
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
2018-04-04 15:47:43 +02:00
import {
EnvironmentService,
Region,
} from "@bitwarden/common/platform/abstractions/environment.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
2018-04-04 15:47:43 +02:00
import { ModalService } from "../../services/modal.service";
@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,
private modalService: ModalService,
) {
this.environmentService.environment$.pipe(takeUntilDestroyed()).subscribe((env) => {
if (env.getRegion() !== Region.SelfHosted) {
this.baseUrl = "";
this.webVaultUrl = "";
this.apiUrl = "";
this.identityUrl = "";
this.iconsUrl = "";
this.notificationsUrl = "";
return;
}
2021-12-16 13:36:21 +01:00
const urls = env.getUrls();
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() {
await this.environmentService.setEnvironment(Region.SelfHosted, {
2018-04-04 15:47:43 +02:00
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-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();
this.modalService.closeAll();
2018-04-04 15:47:43 +02:00
}
}