1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-10-09 05:57:40 +02:00
bitwarden-browser/src/app/vault/ciphers.component.ts

126 lines
3.9 KiB
TypeScript
Raw Normal View History

2018-06-08 18:04:03 +02:00
import {
Component,
EventEmitter,
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';
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';
import { CipherView } from 'jslib/models/view/cipherView';
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 {
@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>();
2018-06-07 23:12:11 +02:00
cipherType = CipherType;
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,
protected toasterService: ToasterService, protected i18nService: I18nService,
2018-08-13 22:27:17 +02:00
protected platformUtilsService: PlatformUtilsService, protected cipherService: CipherService) {
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
selectAll(select: boolean) {
if (select) {
this.selectAll(false);
}
const selectCount = select && this.ciphers.length > MaxCheckedCount ? MaxCheckedCount : this.ciphers.length;
for (let i = 0; i < selectCount; i++) {
this.checkCipher(this.ciphers[i], select);
}
}
2018-06-13 06:03:48 +02:00
getSelected(): CipherView[] {
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-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
}
2018-06-12 20:15:19 +02:00
async delete(c: CipherView): Promise<boolean> {
if (this.actionPromise != null) {
return;
}
2018-06-12 20:15:19 +02:00
const confirmed = await this.platformUtilsService.showDialog(
this.i18nService.t('deleteItemConfirmation'), this.i18nService.t('deleteItem'),
this.i18nService.t('yes'), this.i18nService.t('no'), 'warning');
if (!confirmed) {
return false;
}
try {
this.actionPromise = this.deleteCipher(c.id);
await this.actionPromise;
this.analytics.eventTrack.next({ action: 'Deleted Cipher' });
this.toasterService.popAsync('success', null, this.i18nService.t('deletedItem'));
this.refresh();
} catch { }
this.actionPromise = null;
2018-06-08 18:04:03 +02:00
}
copy(value: string, typeI18nKey: string, aType: string) {
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)));
}
protected deleteCipher(id: string) {
return this.cipherService.deleteWithServer(id);
}
protected showFixOldAttachments(c: CipherView) {
return c.hasOldAttachments && c.organizationId == null;
}
2018-06-06 23:25:57 +02:00
}