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

79 lines
2.2 KiB
TypeScript
Raw Normal View History

2021-12-16 13:36:21 +01:00
import { Component, Input, OnInit } from "@angular/core";
2021-12-16 13:36:21 +01:00
import { I18nService } from "jslib-common/abstractions/i18n.service";
import { MasterPasswordPolicyOptions } from "jslib-common/models/domain/masterPasswordPolicyOptions";
@Component({
2021-12-16 13:36:21 +01:00
selector: "app-callout",
templateUrl: "callout.component.html",
})
export class CalloutComponent implements OnInit {
2021-12-16 13:36:21 +01:00
@Input() type = "info";
@Input() icon: string;
@Input() title: string;
@Input() clickable: boolean;
@Input() enforcedPolicyOptions: MasterPasswordPolicyOptions;
@Input() enforcedPolicyMessage: string;
@Input() useAlertRole = false;
2021-12-16 13:36:21 +01:00
calloutStyle: string;
2021-12-16 13:36:21 +01:00
constructor(private i18nService: I18nService) {}
2021-12-16 13:36:21 +01:00
ngOnInit() {
this.calloutStyle = this.type;
2021-12-16 13:36:21 +01:00
if (this.enforcedPolicyMessage === undefined) {
this.enforcedPolicyMessage = this.i18nService.t("masterPasswordPolicyInEffect");
}
2021-12-16 13:36:21 +01:00
if (this.type === "warning" || this.type === "danger") {
if (this.type === "danger") {
this.calloutStyle = "danger";
}
if (this.title === undefined) {
this.title = this.i18nService.t("warning");
}
if (this.icon === undefined) {
this.icon = "bwi-exclamation-triangle";
2021-12-16 13:36:21 +01:00
}
} else if (this.type === "error") {
this.calloutStyle = "danger";
if (this.title === undefined) {
this.title = this.i18nService.t("error");
}
if (this.icon === undefined) {
this.icon = "bwi-error";
2021-12-16 13:36:21 +01:00
}
} else if (this.type === "tip") {
this.calloutStyle = "success";
if (this.title === undefined) {
this.title = this.i18nService.t("tip");
}
if (this.icon === undefined) {
this.icon = "bwi-lightbulb";
2021-12-16 13:36:21 +01:00
}
}
2021-12-16 13:36:21 +01:00
}
2021-12-16 13:36:21 +01:00
getPasswordScoreAlertDisplay() {
if (this.enforcedPolicyOptions == null) {
return "";
}
2021-12-16 13:36:21 +01:00
let str: string;
switch (this.enforcedPolicyOptions.minComplexity) {
case 4:
str = this.i18nService.t("strong");
break;
case 3:
str = this.i18nService.t("good");
break;
default:
str = this.i18nService.t("weak");
break;
}
2021-12-16 13:36:21 +01:00
return str + " (" + this.enforcedPolicyOptions.minComplexity + ")";
}
}