mirror of
https://github.com/bitwarden/browser
synced 2025-12-23 19:53:43 +00:00
view model types
This commit is contained in:
18
src/models/view/attachmentView.ts
Normal file
18
src/models/view/attachmentView.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { View } from './view';
|
||||
|
||||
import { Attachment } from '../domain/attachment';
|
||||
|
||||
export class AttachmentView implements View {
|
||||
id: string;
|
||||
url: string;
|
||||
size: number;
|
||||
sizeName: string;
|
||||
fileName: string;
|
||||
|
||||
constructor(a: Attachment) {
|
||||
this.id = a.id;
|
||||
this.url = a.url;
|
||||
this.size = a.size;
|
||||
this.sizeName = a.sizeName;
|
||||
}
|
||||
}
|
||||
16
src/models/view/cardView.ts
Normal file
16
src/models/view/cardView.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { View } from './view';
|
||||
|
||||
import { Card } from '../domain/card';
|
||||
|
||||
export class CardView implements View {
|
||||
cardholderName: string;
|
||||
brand: string;
|
||||
number: string;
|
||||
expMonth: string;
|
||||
expYear: string;
|
||||
code: string;
|
||||
|
||||
constructor(c?: Card) {
|
||||
// ctor
|
||||
}
|
||||
}
|
||||
80
src/models/view/cipherView.ts
Normal file
80
src/models/view/cipherView.ts
Normal file
@@ -0,0 +1,80 @@
|
||||
import { CipherType } from '../../enums/cipherType';
|
||||
|
||||
import { Cipher } from '../domain/cipher';
|
||||
|
||||
import { AttachmentView } from './attachmentView';
|
||||
import { CardView } from './cardView';
|
||||
import { FieldView } from './fieldView';
|
||||
import { IdentityView } from './identityView';
|
||||
import { LoginView } from './loginView';
|
||||
import { SecureNoteView } from './secureNoteView';
|
||||
import { View } from './view';
|
||||
|
||||
export class CipherView implements View {
|
||||
id: string;
|
||||
organizationId: string;
|
||||
folderId: string;
|
||||
name: string;
|
||||
notes: string;
|
||||
type: CipherType;
|
||||
favorite: boolean;
|
||||
localData: any;
|
||||
login: LoginView;
|
||||
identity: IdentityView;
|
||||
card: CardView;
|
||||
secureNote: SecureNoteView;
|
||||
attachments: AttachmentView[];
|
||||
fields: FieldView[];
|
||||
collectionIds: string[];
|
||||
|
||||
// tslint:disable-next-line
|
||||
private _subTitle: string;
|
||||
|
||||
constructor(c: Cipher) {
|
||||
this.id = c.id;
|
||||
this.organizationId = c.organizationId;
|
||||
this.folderId = c.folderId;
|
||||
this.favorite = c.favorite;
|
||||
this.type = c.type;
|
||||
this.localData = c.localData;
|
||||
this.collectionIds = c.collectionIds;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
return this._subTitle;
|
||||
}
|
||||
}
|
||||
15
src/models/view/fieldView.ts
Normal file
15
src/models/view/fieldView.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { FieldType } from '../../enums/fieldType';
|
||||
|
||||
import { View } from './view';
|
||||
|
||||
import { Field } from '../domain/field';
|
||||
|
||||
export class FieldView implements View {
|
||||
name: string;
|
||||
vault: string;
|
||||
type: FieldType;
|
||||
|
||||
constructor(f: Field) {
|
||||
this.type = f.type;
|
||||
}
|
||||
}
|
||||
28
src/models/view/identityView.ts
Normal file
28
src/models/view/identityView.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { View } from './view';
|
||||
|
||||
import { Identity } from '../domain/identity';
|
||||
|
||||
export class IdentityView implements View {
|
||||
title: string;
|
||||
firstName: string;
|
||||
middleName: string;
|
||||
lastName: string;
|
||||
address1: string;
|
||||
address2: string;
|
||||
address3: string;
|
||||
city: string;
|
||||
state: string;
|
||||
postalCode: string;
|
||||
country: string;
|
||||
company: string;
|
||||
email: string;
|
||||
phone: string;
|
||||
ssn: string;
|
||||
username: string;
|
||||
passportNumber: string;
|
||||
licenseNumber: string;
|
||||
|
||||
constructor(i?: Identity) {
|
||||
// ctor
|
||||
}
|
||||
}
|
||||
8
src/models/view/index.ts
Normal file
8
src/models/view/index.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
export { AttachmentView } from './attachmentView';
|
||||
export { CardView } from './cardView';
|
||||
export { CipherView } from './cipherView';
|
||||
export { FieldView } from './fieldView';
|
||||
export { IdentityView } from './identityView';
|
||||
export { LoginView } from './loginView';
|
||||
export { SecureNoteView } from './secureNoteView';
|
||||
export { View } from './view';
|
||||
34
src/models/view/loginView.ts
Normal file
34
src/models/view/loginView.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { View } from './view';
|
||||
|
||||
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
|
||||
private _domain: string;
|
||||
|
||||
constructor(l?: Login) {
|
||||
// ctor
|
||||
}
|
||||
|
||||
get domain(): string {
|
||||
if (this._domain == null && this.uri != null) {
|
||||
const containerService = (window as any).bitwardenContainerService;
|
||||
if (containerService) {
|
||||
const platformUtilsService: PlatformUtilsService = containerService.getPlatformUtilsService();
|
||||
this._domain = platformUtilsService.getDomain(this.uri);
|
||||
} else {
|
||||
throw new Error('window.bitwardenContainerService not initialized.');
|
||||
}
|
||||
}
|
||||
|
||||
return this._domain;
|
||||
}
|
||||
}
|
||||
13
src/models/view/secureNoteView.ts
Normal file
13
src/models/view/secureNoteView.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { SecureNoteType } from '../../enums/secureNoteType';
|
||||
|
||||
import { View } from './view';
|
||||
|
||||
import { SecureNote } from '../domain/secureNote';
|
||||
|
||||
export class SecureNoteView implements View {
|
||||
type: SecureNoteType;
|
||||
|
||||
constructor(n: SecureNote) {
|
||||
this.type = n.type;
|
||||
}
|
||||
}
|
||||
2
src/models/view/view.ts
Normal file
2
src/models/view/view.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export class View {
|
||||
}
|
||||
Reference in New Issue
Block a user