2020-02-28 22:57:34 +01:00
|
|
|
import {
|
|
|
|
Component,
|
|
|
|
Input,
|
|
|
|
OnInit,
|
|
|
|
} from '@angular/core';
|
|
|
|
|
2021-06-03 18:58:57 +02:00
|
|
|
import { I18nService } from 'jslib-common/abstractions/i18n.service';
|
2020-02-28 22:57:34 +01:00
|
|
|
|
2021-08-20 17:51:11 +02:00
|
|
|
import { MasterPasswordPolicyOptions } from 'jslib-common/models/domain/masterPasswordPolicyOptions';
|
|
|
|
|
2020-02-28 22:57:34 +01:00
|
|
|
@Component({
|
|
|
|
selector: 'app-callout',
|
|
|
|
templateUrl: 'callout.component.html',
|
|
|
|
})
|
|
|
|
export class CalloutComponent implements OnInit {
|
|
|
|
@Input() type = 'info';
|
|
|
|
@Input() icon: string;
|
|
|
|
@Input() title: string;
|
2021-02-23 03:32:40 +01:00
|
|
|
@Input() clickable: boolean;
|
2021-08-20 17:51:11 +02:00
|
|
|
@Input() enforcedPolicyOptions: MasterPasswordPolicyOptions;
|
|
|
|
@Input() enforcedPolicyMessage: string;
|
2021-10-26 17:41:46 +02:00
|
|
|
@Input() useAlertRole = false;
|
2020-02-28 22:57:34 +01:00
|
|
|
|
|
|
|
calloutStyle: string;
|
|
|
|
|
|
|
|
constructor(private i18nService: I18nService) { }
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.calloutStyle = this.type;
|
|
|
|
|
2021-08-20 17:51:11 +02:00
|
|
|
if (this.enforcedPolicyMessage === undefined) {
|
|
|
|
this.enforcedPolicyMessage = this.i18nService.t('masterPasswordPolicyInEffect');
|
|
|
|
}
|
|
|
|
|
2020-02-28 22:57:34 +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 = 'fa-warning';
|
|
|
|
}
|
|
|
|
} else if (this.type === 'error') {
|
|
|
|
this.calloutStyle = 'danger';
|
|
|
|
if (this.title === undefined) {
|
|
|
|
this.title = this.i18nService.t('error');
|
|
|
|
}
|
|
|
|
if (this.icon === undefined) {
|
|
|
|
this.icon = 'fa-bolt';
|
|
|
|
}
|
|
|
|
} else if (this.type === 'tip') {
|
|
|
|
this.calloutStyle = 'success';
|
|
|
|
if (this.title === undefined) {
|
|
|
|
this.title = this.i18nService.t('tip');
|
|
|
|
}
|
|
|
|
if (this.icon === undefined) {
|
|
|
|
this.icon = 'fa-lightbulb-o';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-08-20 17:51:11 +02:00
|
|
|
|
|
|
|
getPasswordScoreAlertDisplay() {
|
|
|
|
if (this.enforcedPolicyOptions == null) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
return str + ' (' + this.enforcedPolicyOptions.minComplexity + ')';
|
|
|
|
}
|
2020-02-28 22:57:34 +01:00
|
|
|
}
|