bitwarden-estensione-browser/src/app/vault/ciphers.component.ts

103 lines
3.2 KiB
TypeScript
Raw Normal View History

2018-06-08 18:04:03 +02:00
import {
Component,
EventEmitter,
Input,
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-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',
})
export class CiphersComponent extends BaseCiphersComponent {
@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;
constructor(cipherService: CipherService, protected analytics: Angulartics2,
protected toasterService: ToasterService, protected i18nService: I18nService,
protected platformUtilsService: PlatformUtilsService) {
2018-06-06 23:25:57 +02:00
super(cipherService);
}
2018-06-07 23:12:11 +02:00
checkCipher(c: CipherView) {
(c as any).checked = !(c as any).checked;
}
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.ciphers[i] as any).checked = 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> {
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;
}
await this.cipherService.deleteWithServer(c.id);
this.analytics.eventTrack.next({ action: 'Deleted Cipher' });
this.toasterService.popAsync('success', null, this.i18nService.t('deletedItem'));
this.refresh();
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.' });
this.platformUtilsService.copyToClipboard(value, { doc: window.document });
this.toasterService.popAsync('info', null,
this.i18nService.t('valueCopied', this.i18nService.t(typeI18nKey)));
}
2018-06-06 23:25:57 +02:00
}