2018-06-08 18:04:03 +02:00
|
|
|
import {
|
|
|
|
Component,
|
|
|
|
EventEmitter,
|
2018-07-04 15:55:52 +02:00
|
|
|
Input,
|
2018-07-28 04:05:03 +02:00
|
|
|
OnDestroy,
|
2018-06-08 18:04:03 +02:00
|
|
|
Output,
|
|
|
|
} from '@angular/core';
|
|
|
|
|
|
|
|
import { ToasterService } from 'angular2-toaster';
|
|
|
|
import { Angulartics2 } from 'angulartics2';
|
2018-06-06 23:25:57 +02:00
|
|
|
|
|
|
|
import { CipherService } from 'jslib/abstractions/cipher.service';
|
2019-07-12 21:34:27 +02:00
|
|
|
import { EventService } from 'jslib/abstractions/event.service';
|
2018-06-08 18:04:03 +02:00
|
|
|
import { I18nService } from 'jslib/abstractions/i18n.service';
|
|
|
|
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
|
2018-08-13 22:27:17 +02:00
|
|
|
import { SearchService } from 'jslib/abstractions/search.service';
|
2018-06-06 23:25:57 +02:00
|
|
|
|
|
|
|
import { CiphersComponent as BaseCiphersComponent } from 'jslib/angular/components/ciphers.component';
|
|
|
|
|
2018-06-07 23:12:11 +02:00
|
|
|
import { CipherType } from 'jslib/enums/cipherType';
|
2019-07-12 21:34:27 +02:00
|
|
|
import { EventType } from 'jslib/enums/eventType';
|
2018-06-07 23:12:11 +02:00
|
|
|
|
|
|
|
import { CipherView } from 'jslib/models/view/cipherView';
|
|
|
|
|
2018-06-12 23:11:24 +02:00
|
|
|
const MaxCheckedCount = 500;
|
|
|
|
|
2018-06-06 23:25:57 +02:00
|
|
|
@Component({
|
|
|
|
selector: 'app-vault-ciphers',
|
|
|
|
templateUrl: 'ciphers.component.html',
|
|
|
|
})
|
2018-07-28 04:05:03 +02:00
|
|
|
export class CiphersComponent extends BaseCiphersComponent implements OnDestroy {
|
2018-07-04 15:55:52 +02:00
|
|
|
@Input() showAddNew = true;
|
2018-06-08 18:04:03 +02:00
|
|
|
@Output() onAttachmentsClicked = new EventEmitter<CipherView>();
|
2018-06-12 17:46:11 +02:00
|
|
|
@Output() onShareClicked = new EventEmitter<CipherView>();
|
|
|
|
@Output() onCollectionsClicked = new EventEmitter<CipherView>();
|
2020-02-10 20:03:36 +01:00
|
|
|
@Output() onCloneClicked = new EventEmitter<CipherView>();
|
2018-06-12 23:11:24 +02:00
|
|
|
|
2018-06-07 23:12:11 +02:00
|
|
|
cipherType = CipherType;
|
2018-07-28 04:36:25 +02:00
|
|
|
actionPromise: Promise<any>;
|
2018-06-07 23:12:11 +02:00
|
|
|
|
2018-08-13 22:27:17 +02:00
|
|
|
constructor(searchService: SearchService, protected analytics: Angulartics2,
|
2018-07-05 15:58:15 +02:00
|
|
|
protected toasterService: ToasterService, protected i18nService: I18nService,
|
2019-07-12 21:34:27 +02:00
|
|
|
protected platformUtilsService: PlatformUtilsService, protected cipherService: CipherService,
|
|
|
|
protected eventService: EventService) {
|
2018-08-13 22:27:17 +02:00
|
|
|
super(searchService);
|
2019-03-19 19:55:19 +01:00
|
|
|
this.pageSize = 200;
|
2018-06-06 23:25:57 +02:00
|
|
|
}
|
2018-06-07 23:12:11 +02:00
|
|
|
|
2018-07-28 04:05:03 +02:00
|
|
|
ngOnDestroy() {
|
|
|
|
this.selectAll(false);
|
|
|
|
}
|
|
|
|
|
2018-07-09 22:27:54 +02:00
|
|
|
checkCipher(c: CipherView, select?: boolean) {
|
|
|
|
(c as any).checked = select == null ? !(c as any).checked : select;
|
2018-06-07 23:12:11 +02:00
|
|
|
}
|
2018-06-08 18:04:03 +02:00
|
|
|
|
2019-04-26 15:12:37 +02:00
|
|
|
launch(uri: string) {
|
2019-04-26 15:07:57 +02:00
|
|
|
this.platformUtilsService.eventTrack('Launched Login URI');
|
2019-04-26 15:12:37 +02:00
|
|
|
this.platformUtilsService.launchUri(uri);
|
2019-04-26 15:07:57 +02:00
|
|
|
}
|
|
|
|
|
2018-06-12 23:11:24 +02:00
|
|
|
selectAll(select: boolean) {
|
|
|
|
if (select) {
|
|
|
|
this.selectAll(false);
|
|
|
|
}
|
2018-12-08 16:47:22 +01:00
|
|
|
const selectCount = select && this.ciphers.length > MaxCheckedCount ? MaxCheckedCount : this.ciphers.length;
|
2018-06-12 23:11:24 +02:00
|
|
|
for (let i = 0; i < selectCount; i++) {
|
2018-12-08 16:47:22 +01:00
|
|
|
this.checkCipher(this.ciphers[i], select);
|
2018-06-12 23:11:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-13 06:03:48 +02:00
|
|
|
getSelected(): CipherView[] {
|
2018-06-12 23:11:24 +02:00
|
|
|
if (this.ciphers == null) {
|
|
|
|
return [];
|
|
|
|
}
|
2018-06-13 06:03:48 +02:00
|
|
|
return this.ciphers.filter((c) => !!(c as any).checked);
|
|
|
|
}
|
|
|
|
|
|
|
|
getSelectedIds(): string[] {
|
|
|
|
return this.getSelected().map((c) => c.id);
|
2018-06-12 23:11:24 +02:00
|
|
|
}
|
|
|
|
|
2018-06-08 18:04:03 +02:00
|
|
|
attachments(c: CipherView) {
|
|
|
|
this.onAttachmentsClicked.emit(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
share(c: CipherView) {
|
2018-06-12 17:46:11 +02:00
|
|
|
this.onShareClicked.emit(c);
|
2018-06-08 18:04:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
collections(c: CipherView) {
|
2018-06-12 17:46:11 +02:00
|
|
|
this.onCollectionsClicked.emit(c);
|
2018-06-08 18:04:03 +02:00
|
|
|
}
|
|
|
|
|
2020-02-10 20:03:36 +01:00
|
|
|
clone(c: CipherView) {
|
|
|
|
this.onCloneClicked.emit(c);
|
|
|
|
}
|
|
|
|
|
2018-06-12 20:15:19 +02:00
|
|
|
async delete(c: CipherView): Promise<boolean> {
|
2018-07-28 04:36:25 +02:00
|
|
|
if (this.actionPromise != null) {
|
|
|
|
return;
|
|
|
|
}
|
2020-04-08 22:48:30 +02:00
|
|
|
const permanent = c.isDeleted;
|
2018-06-12 20:15:19 +02:00
|
|
|
const confirmed = await this.platformUtilsService.showDialog(
|
2020-04-08 22:48:30 +02:00
|
|
|
this.i18nService.t(permanent ? 'permanentlyDeleteItemConfirmation' : 'deleteItemConfirmation'),
|
|
|
|
this.i18nService.t(permanent ? 'permanentlyDeleteItem' : 'deleteItem'),
|
2018-06-12 20:15:19 +02:00
|
|
|
this.i18nService.t('yes'), this.i18nService.t('no'), 'warning');
|
|
|
|
if (!confirmed) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-07-28 04:36:25 +02:00
|
|
|
try {
|
2020-04-08 22:48:30 +02:00
|
|
|
this.actionPromise = this.deleteCipher(c.id, permanent);
|
2018-07-28 04:36:25 +02:00
|
|
|
await this.actionPromise;
|
|
|
|
this.analytics.eventTrack.next({ action: 'Deleted Cipher' });
|
2020-04-08 22:48:30 +02:00
|
|
|
this.toasterService.popAsync('success', null, this.i18nService.t(permanent ? 'permanentlyDeletedItem'
|
|
|
|
: 'deletedItem'));
|
|
|
|
this.refresh();
|
|
|
|
} catch { }
|
|
|
|
this.actionPromise = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
async restore(c: CipherView): Promise<boolean> {
|
|
|
|
if (this.actionPromise != null || !c.isDeleted) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const confirmed = await this.platformUtilsService.showDialog(
|
|
|
|
this.i18nService.t('restoreItemConfirmation'),
|
|
|
|
this.i18nService.t('restoreItem'),
|
|
|
|
this.i18nService.t('yes'), this.i18nService.t('no'), 'warning');
|
|
|
|
if (!confirmed) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
this.actionPromise = this.cipherService.restoreWithServer(c.id);
|
|
|
|
await this.actionPromise;
|
|
|
|
this.analytics.eventTrack.next({ action: 'Restored Cipher' });
|
|
|
|
this.toasterService.popAsync('success', null, this.i18nService.t('restoredItem'));
|
2018-07-28 04:36:25 +02:00
|
|
|
this.refresh();
|
|
|
|
} catch { }
|
|
|
|
this.actionPromise = null;
|
2018-06-08 18:04:03 +02:00
|
|
|
}
|
|
|
|
|
2019-07-12 21:34:27 +02:00
|
|
|
copy(cipher: CipherView, value: string, typeI18nKey: string, aType: string) {
|
2018-06-08 18:04:03 +02:00
|
|
|
if (value == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.analytics.eventTrack.next({ action: 'Copied ' + aType.toLowerCase() + ' from listing.' });
|
2018-08-17 18:25:21 +02:00
|
|
|
this.platformUtilsService.copyToClipboard(value, { window: window });
|
2018-06-08 18:04:03 +02:00
|
|
|
this.toasterService.popAsync('info', null,
|
|
|
|
this.i18nService.t('valueCopied', this.i18nService.t(typeI18nKey)));
|
2019-07-12 21:34:27 +02:00
|
|
|
|
|
|
|
if (typeI18nKey === 'password') {
|
|
|
|
this.eventService.collect(EventType.Cipher_ClientToggledHiddenFieldVisible, cipher.id);
|
|
|
|
} else if (typeI18nKey === 'securityCode') {
|
|
|
|
this.eventService.collect(EventType.Cipher_ClientCopiedCardCode, cipher.id);
|
|
|
|
}
|
2018-06-08 18:04:03 +02:00
|
|
|
}
|
2018-07-28 04:36:25 +02:00
|
|
|
|
2020-04-08 22:48:30 +02:00
|
|
|
protected deleteCipher(id: string, permanent: boolean) {
|
|
|
|
return permanent ? this.cipherService.deleteWithServer(id) : this.cipherService.softDeleteWithServer(id);
|
2018-07-28 04:36:25 +02:00
|
|
|
}
|
2018-11-14 21:20:17 +01:00
|
|
|
|
|
|
|
protected showFixOldAttachments(c: CipherView) {
|
|
|
|
return c.hasOldAttachments && c.organizationId == null;
|
|
|
|
}
|
2018-06-06 23:25:57 +02:00
|
|
|
}
|