2018-02-19 19:07:19 +01:00
|
|
|
import { CipherType } from '../../enums/cipherType';
|
2018-01-24 17:33:15 +01:00
|
|
|
|
2018-02-19 19:07:19 +01:00
|
|
|
import { Cipher } from '../domain/cipher';
|
2018-01-24 17:33:15 +01:00
|
|
|
|
|
|
|
import { AttachmentView } from './attachmentView';
|
|
|
|
import { CardView } from './cardView';
|
|
|
|
import { FieldView } from './fieldView';
|
|
|
|
import { IdentityView } from './identityView';
|
|
|
|
import { LoginView } from './loginView';
|
2018-07-27 22:44:20 +02:00
|
|
|
import { PasswordHistoryView } from './passwordHistoryView';
|
2018-01-24 17:33:15 +01:00
|
|
|
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;
|
2018-06-25 20:15:34 +02:00
|
|
|
favorite = false;
|
|
|
|
organizationUseTotp = false;
|
|
|
|
edit = false;
|
2018-01-24 17:33:15 +01:00
|
|
|
localData: any;
|
|
|
|
login: LoginView;
|
|
|
|
identity: IdentityView;
|
|
|
|
card: CardView;
|
|
|
|
secureNote: SecureNoteView;
|
|
|
|
attachments: AttachmentView[];
|
|
|
|
fields: FieldView[];
|
2018-07-27 22:44:20 +02:00
|
|
|
passwordHistory: PasswordHistoryView[];
|
2018-01-24 17:33:15 +01:00
|
|
|
collectionIds: string[];
|
2018-07-28 05:37:36 +02:00
|
|
|
revisionDate: Date;
|
2018-01-24 17:33:15 +01:00
|
|
|
|
2018-01-24 19:27:32 +01:00
|
|
|
constructor(c?: Cipher) {
|
|
|
|
if (!c) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-24 17:33:15 +01:00
|
|
|
this.id = c.id;
|
|
|
|
this.organizationId = c.organizationId;
|
|
|
|
this.folderId = c.folderId;
|
|
|
|
this.favorite = c.favorite;
|
2018-06-20 05:40:10 +02:00
|
|
|
this.organizationUseTotp = c.organizationUseTotp;
|
|
|
|
this.edit = c.edit;
|
2018-01-24 17:33:15 +01:00
|
|
|
this.type = c.type;
|
|
|
|
this.localData = c.localData;
|
|
|
|
this.collectionIds = c.collectionIds;
|
2018-07-28 05:37:36 +02:00
|
|
|
this.revisionDate = c.revisionDate;
|
2018-01-24 17:33:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
get subTitle(): string {
|
2018-01-24 22:58:34 +01:00
|
|
|
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;
|
2018-01-24 17:33:15 +01:00
|
|
|
}
|
|
|
|
|
2018-01-24 22:58:34 +01:00
|
|
|
return null;
|
2018-01-24 17:33:15 +01:00
|
|
|
}
|
2018-01-25 05:27:04 +01:00
|
|
|
|
2018-07-27 22:44:20 +02:00
|
|
|
get hasPasswordHistory(): boolean {
|
|
|
|
return this.passwordHistory && this.passwordHistory.length > 0;
|
|
|
|
}
|
|
|
|
|
2018-01-25 05:27:04 +01:00
|
|
|
get hasAttachments(): boolean {
|
|
|
|
return this.attachments && this.attachments.length > 0;
|
|
|
|
}
|
|
|
|
|
2018-11-14 21:19:59 +01:00
|
|
|
get hasOldAttachments(): boolean {
|
|
|
|
if (this.hasAttachments) {
|
|
|
|
for (let i = 0; i < this.attachments.length; i++) {
|
|
|
|
if (this.attachments[i].key == null) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-01-25 05:27:04 +01:00
|
|
|
get hasFields(): boolean {
|
|
|
|
return this.fields && this.fields.length > 0;
|
|
|
|
}
|
2018-02-28 21:15:10 +01:00
|
|
|
|
2018-07-28 05:37:36 +02:00
|
|
|
get passwordRevisionDisplayDate(): Date {
|
|
|
|
if (this.login == null) {
|
|
|
|
return null;
|
|
|
|
} else if (this.login.password == null || this.login.password === '') {
|
|
|
|
return null;
|
|
|
|
}
|
2018-07-31 04:01:21 +02:00
|
|
|
return this.login.passwordRevisionDate;
|
2018-07-28 05:37:36 +02:00
|
|
|
}
|
2018-01-24 17:33:15 +01:00
|
|
|
}
|