Moved callout to jslib, made policyInEffect a prop (#77)

* Moved callout to jslib, made policyInEffect a prop

* remove true condition
This commit is contained in:
Kyle Spearrin 2020-02-28 16:57:34 -05:00 committed by GitHub
parent 6c52942204
commit fb48091bb8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 69 additions and 18 deletions

View File

@ -0,0 +1,7 @@
<div class="callout callout-{{calloutStyle}}" role="alert">
<h3 class="callout-heading" *ngIf="title">
<i class="fa {{icon}}" *ngIf="icon" aria-hidden="true"></i>
{{title}}
</h3>
<ng-content></ng-content>
</div>

View File

@ -0,0 +1,53 @@
import {
Component,
Input,
OnInit,
} from '@angular/core';
import { I18nService } from '../../abstractions/i18n.service';
@Component({
selector: 'app-callout',
templateUrl: 'callout.component.html',
})
export class CalloutComponent implements OnInit {
@Input() type = 'info';
@Input() icon: string;
@Input() title: string;
calloutStyle: string;
constructor(private i18nService: I18nService) { }
ngOnInit() {
this.calloutStyle = this.type;
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';
}
}
}
}

View File

@ -19,6 +19,7 @@ export class PasswordGeneratorComponent implements OnInit {
password: string = '-'; password: string = '-';
showOptions = false; showOptions = false;
avoidAmbiguous = false; avoidAmbiguous = false;
policyInEffect = false;
enforcedPolicyOptions: PasswordGeneratorPolicyOptions; enforcedPolicyOptions: PasswordGeneratorPolicyOptions;
constructor(protected passwordGenerationService: PasswordGenerationService, constructor(protected passwordGenerationService: PasswordGenerationService,
@ -29,6 +30,14 @@ export class PasswordGeneratorComponent implements OnInit {
const optionsResponse = await this.passwordGenerationService.getOptions(); const optionsResponse = await this.passwordGenerationService.getOptions();
this.options = optionsResponse[0]; this.options = optionsResponse[0];
this.enforcedPolicyOptions = optionsResponse[1]; this.enforcedPolicyOptions = optionsResponse[1];
this.policyInEffect = this.enforcedPolicyOptions != null && (
this.enforcedPolicyOptions.minLength > 0 ||
this.enforcedPolicyOptions.numberCount > 0 ||
this.enforcedPolicyOptions.specialCount > 0 ||
this.enforcedPolicyOptions.useUppercase ||
this.enforcedPolicyOptions.useLowercase ||
this.enforcedPolicyOptions.useNumbers ||
this.enforcedPolicyOptions.useSpecial);
this.avoidAmbiguous = !this.options.ambiguous; this.avoidAmbiguous = !this.options.ambiguous;
this.options.type = this.options.type === 'passphrase' ? 'passphrase' : 'password'; this.options.type = this.options.type === 'passphrase' ? 'passphrase' : 'password';
this.password = await this.passwordGenerationService.generatePassword(this.options); this.password = await this.passwordGenerationService.generatePassword(this.options);
@ -79,24 +88,6 @@ export class PasswordGeneratorComponent implements OnInit {
this.showOptions = !this.showOptions; this.showOptions = !this.showOptions;
} }
hasPolicyInEffect() {
if (this.enforcedPolicyOptions == null) {
return false;
}
if (this.enforcedPolicyOptions.minLength > 0
|| this.enforcedPolicyOptions.numberCount > 0
|| this.enforcedPolicyOptions.specialCount > 0
|| this.enforcedPolicyOptions.useUppercase
|| this.enforcedPolicyOptions.useLowercase
|| this.enforcedPolicyOptions.useNumbers
|| this.enforcedPolicyOptions.useSpecial) {
return true;
} else {
return false;
}
}
private normalizeOptions() { private normalizeOptions() {
this.options.minLowercase = 0; this.options.minLowercase = 0;
this.options.minUppercase = 0; this.options.minUppercase = 0;