mirror of
https://github.com/bitwarden/browser
synced 2025-12-18 01:03:35 +00:00
defining more abstractions
This commit is contained in:
@@ -48,4 +48,18 @@ export class CardView implements View {
|
||||
}
|
||||
return this._subTitle;
|
||||
}
|
||||
|
||||
get expiration(): string {
|
||||
if (!this.expMonth && !this.expYear) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let exp = this.expMonth != null ? ('0' + this.expMonth).slice(-2) : '__';
|
||||
exp += (' / ' + (this.expYear != null ? this.formatYear(this.expYear) : '____'));
|
||||
return exp;
|
||||
}
|
||||
|
||||
private formatYear(year: string): string {
|
||||
return year.length === 2 ? '20' + year : year;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,10 +6,33 @@ import { Field } from '../domain/field';
|
||||
|
||||
export class FieldView implements View {
|
||||
name: string;
|
||||
vault: string;
|
||||
type: FieldType;
|
||||
|
||||
// tslint:disable
|
||||
private _value: string;
|
||||
private _maskedValue: string;
|
||||
// tslint:enable
|
||||
|
||||
constructor(f: Field) {
|
||||
this.type = f.type;
|
||||
}
|
||||
|
||||
get value(): string {
|
||||
return this._value;
|
||||
}
|
||||
set value(value: string) {
|
||||
this._value = value;
|
||||
this._maskedValue = null;
|
||||
}
|
||||
|
||||
get maskedValue(): string {
|
||||
if (this._maskedValue == null && this.value != null) {
|
||||
this._maskedValue = '';
|
||||
for (let i = 0; i < this.value.length; i++) {
|
||||
this._maskedValue += '•';
|
||||
}
|
||||
}
|
||||
|
||||
return this._maskedValue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,4 +62,25 @@ export class IdentityView implements View {
|
||||
|
||||
return this._subTitle;
|
||||
}
|
||||
|
||||
get fullName(): string {
|
||||
if (this.title != null || this.firstName != null || this.middleName != null || this.lastName != null) {
|
||||
let name = '';
|
||||
if (this.title != null) {
|
||||
name += (this.title + ' ');
|
||||
}
|
||||
if (this.firstName != null) {
|
||||
name += (this.firstName + ' ');
|
||||
}
|
||||
if (this.middleName != null) {
|
||||
name += (this.middleName + ' ');
|
||||
}
|
||||
if (this.lastName != null) {
|
||||
name += this.lastName;
|
||||
}
|
||||
return name.trim();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user