1
0
mirror of https://github.com/bitwarden/browser synced 2025-01-06 15:38:42 +01:00
bitwarden-estensione-browser/apps/web/src/app/settings/domain-rules.component.ts

88 lines
2.5 KiB
TypeScript
Raw Normal View History

2021-12-17 15:57:11 +01:00
import { Component, OnInit } from "@angular/core";
2018-06-26 05:16:59 +02:00
2022-06-14 17:10:53 +02:00
import { ApiService } from "@bitwarden/common/abstractions/api.service";
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/abstractions/log.service";
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
import { UpdateDomainsRequest } from "@bitwarden/common/models/request/updateDomainsRequest";
2018-06-26 05:16:59 +02:00
@Component({
2021-12-17 15:57:11 +01:00
selector: "app-domain-rules",
templateUrl: "domain-rules.component.html",
2018-06-26 05:16:59 +02:00
})
export class DomainRulesComponent implements OnInit {
2021-12-17 15:57:11 +01:00
loading = true;
custom: string[] = [];
global: any[] = [];
formPromise: Promise<any>;
2018-06-26 05:16:59 +02:00
2021-12-17 15:57:11 +01:00
constructor(
private apiService: ApiService,
private i18nService: I18nService,
private platformUtilsService: PlatformUtilsService,
private logService: LogService
) {}
2018-06-26 05:16:59 +02:00
2021-12-17 15:57:11 +01:00
async ngOnInit() {
const response = await this.apiService.getSettingsDomains();
this.loading = false;
if (response.equivalentDomains != null) {
this.custom = response.equivalentDomains.map((d) => d.join(", "));
2018-06-26 17:50:23 +02:00
}
2021-12-17 15:57:11 +01:00
if (response.globalEquivalentDomains != null) {
this.global = response.globalEquivalentDomains.map((d) => {
return {
domains: d.domains.join(", "),
excluded: d.excluded,
key: d.type,
};
});
2018-06-26 17:50:23 +02:00
}
2021-12-17 15:57:11 +01:00
}
2018-06-26 17:50:23 +02:00
2021-12-17 15:57:11 +01:00
toggleExcluded(globalDomain: any) {
globalDomain.excluded = !globalDomain.excluded;
}
2018-06-26 17:50:23 +02:00
2021-12-17 15:57:11 +01:00
customize(globalDomain: any) {
globalDomain.excluded = true;
this.custom.push(globalDomain.domains);
}
2018-06-26 17:50:23 +02:00
2021-12-17 15:57:11 +01:00
remove(index: number) {
this.custom.splice(index, 1);
}
2018-06-26 05:16:59 +02:00
2021-12-17 15:57:11 +01:00
add() {
this.custom.push("");
}
2018-06-26 17:50:23 +02:00
2021-12-17 15:57:11 +01:00
async submit() {
const request = new UpdateDomainsRequest();
request.excludedGlobalEquivalentDomains = this.global
.filter((d) => d.excluded)
.map((d) => d.key);
if (request.excludedGlobalEquivalentDomains.length === 0) {
request.excludedGlobalEquivalentDomains = null;
}
request.equivalentDomains = this.custom
.filter((d) => d != null && d.trim() !== "")
.map((d) => d.split(",").map((d2) => d2.trim()));
if (request.equivalentDomains.length === 0) {
request.equivalentDomains = null;
2018-06-26 17:50:23 +02:00
}
2018-06-26 05:16:59 +02:00
2021-12-17 15:57:11 +01:00
try {
this.formPromise = this.apiService.putSettingsDomains(request);
await this.formPromise;
this.platformUtilsService.showToast("success", null, this.i18nService.t("domainsUpdated"));
} catch (e) {
this.logService.error(e);
2018-06-26 05:16:59 +02:00
}
2021-12-17 15:57:11 +01:00
}
indexTrackBy(index: number, obj: any): any {
return index;
}
2018-06-26 05:16:59 +02:00
}