diff --git a/src/models/view/cardView.ts b/src/models/view/cardView.ts index cb4b2380fe..2e052fff55 100644 --- a/src/models/view/cardView.ts +++ b/src/models/view/cardView.ts @@ -4,13 +4,48 @@ import { Card } from '../domain/card'; export class CardView implements View { cardholderName: string; - brand: string; - number: string; expMonth: string; expYear: string; code: string; + // tslint:disable + private _brand: string; + private _number: string; + private _subTitle: string; + // tslint:enable + constructor(c?: Card) { // ctor } + + get brand(): string { + return this._brand; + } + set brand(value: string) { + this._brand = value; + this._subTitle = null; + } + + get number(): string { + return this._number; + } + set number(value: string) { + this._number = value; + this._subTitle = null; + } + + get subTitle(): string { + if (this._subTitle == null) { + this._subTitle = this.brand; + if (this.number != null && this.number.length >= 4) { + if (this._subTitle != null && this._subTitle !== '') { + this._subTitle += ', '; + } else { + this._subTitle = ''; + } + this._subTitle += ('*' + this.number.substr(this.number.length - 4)); + } + } + return this._subTitle; + } } diff --git a/src/models/view/cipherView.ts b/src/models/view/cipherView.ts index 50218527f8..e7ca481e7c 100644 --- a/src/models/view/cipherView.ts +++ b/src/models/view/cipherView.ts @@ -27,9 +27,6 @@ export class CipherView implements View { fields: FieldView[]; collectionIds: string[]; - // tslint:disable-next-line - private _subTitle: string; - constructor(c?: Cipher) { if (!c) { return; @@ -45,40 +42,19 @@ export class CipherView implements View { } get subTitle(): string { - if (this._subTitle == null) { - switch (this.type) { - case CipherType.Login: - this._subTitle = this.login.username; - break; - case CipherType.SecureNote: - this._subTitle = null; - break; - case CipherType.Card: - this._subTitle = this.card.brand; - if (this.card.number != null && this.card.number.length >= 4) { - if (this._subTitle !== '') { - this._subTitle += ', '; - } - this._subTitle += ('*' + this.card.number.substr(this.card.number.length - 4)); - } - break; - case CipherType.Identity: - this._subTitle = ''; - if (this.identity.firstName != null) { - this._subTitle = this.identity.firstName; - } - if (this.identity.lastName != null) { - if (this._subTitle !== '') { - this._subTitle += ' '; - } - this._subTitle += this.identity.lastName; - } - break; - default: - break; - } + switch (this.type) { + case CipherType.Login: + return this.login.subTitle; + case CipherType.SecureNote: + return this.secureNote.subTitle; + case CipherType.Card: + return this.card.subTitle; + case CipherType.Identity: + return this.identity.subTitle; + default: + break; } - return this._subTitle; + return null; } } diff --git a/src/models/view/identityView.ts b/src/models/view/identityView.ts index fb644c84a4..e1c3a2255f 100644 --- a/src/models/view/identityView.ts +++ b/src/models/view/identityView.ts @@ -4,9 +4,7 @@ import { Identity } from '../domain/identity'; export class IdentityView implements View { title: string; - firstName: string; middleName: string; - lastName: string; address1: string; address2: string; address3: string; @@ -22,7 +20,46 @@ export class IdentityView implements View { passportNumber: string; licenseNumber: string; + // tslint:disable + private _firstName: string; + private _lastName: string; + private _subTitle: string; + // tslint:enable + constructor(i?: Identity) { // ctor } + + get firstName(): string { + return this._firstName; + } + set firstName(value: string) { + this._firstName = value; + this._subTitle = null; + } + + get lastName(): string { + return this._lastName; + } + set lastName(value: string) { + this._lastName = value; + this._subTitle = null; + } + + get subTitle(): string { + if (this._subTitle == null && (this.firstName != null || this.lastName != null)) { + this._subTitle = ''; + if (this.firstName != null) { + this._subTitle = this.firstName; + } + if (this.lastName != null) { + if (this._subTitle !== '') { + this._subTitle += ' '; + } + this._subTitle += this.lastName; + } + } + + return this._subTitle; + } } diff --git a/src/models/view/loginView.ts b/src/models/view/loginView.ts index c2e5270f05..874bd5e494 100644 --- a/src/models/view/loginView.ts +++ b/src/models/view/loginView.ts @@ -5,19 +5,37 @@ import { Login } from '../domain/login'; import { PlatformUtilsService } from '../../abstractions/platformUtils.service'; export class LoginView implements View { - uri: string; username: string; - password: string; - maskedPassword: string; totp: string; - // tslint:disable-next-line + // tslint:disable + private _uri: string; + private _username: string; + private _password: string; private _domain: string; + private _maskedPassword: string; + // tslint:enable constructor(l?: Login) { // ctor } + get uri(): string { + return this._uri; + } + set uri(value: string) { + this._uri = value; + this._domain = null; + } + + get password(): string { + return this._password; + } + set password(value: string) { + this._password = value; + this._maskedPassword = null; + } + get domain(): string { if (this._domain == null && this.uri != null) { const containerService = (window as any).bitwardenContainerService; @@ -31,4 +49,19 @@ export class LoginView implements View { return this._domain; } + + get maskedPassword(): string { + if (this._maskedPassword == null && this.password != null) { + this._maskedPassword = ''; + for (var i = 0; i < this.password.length; i++) { + this._maskedPassword += '•'; + } + } + + return this._maskedPassword; + } + + get subTitle(): string { + return this.username; + } } diff --git a/src/models/view/secureNoteView.ts b/src/models/view/secureNoteView.ts index b4eae6d446..4c131b884f 100644 --- a/src/models/view/secureNoteView.ts +++ b/src/models/view/secureNoteView.ts @@ -10,4 +10,8 @@ export class SecureNoteView implements View { constructor(n: SecureNote) { this.type = n.type; } + + get subTitle(): string { + return null; + } }