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

77 lines
2.6 KiB
TypeScript
Raw Normal View History

2018-06-08 18:04:03 +02:00
import {
Component,
EventEmitter,
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';
2018-06-06 23:25:57 +02:00
@Component({
selector: 'app-vault-ciphers',
templateUrl: 'ciphers.component.html',
})
export class CiphersComponent extends BaseCiphersComponent {
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;
2018-06-08 18:04:03 +02:00
constructor(cipherService: CipherService, private analytics: Angulartics2,
private toasterService: ToasterService, private i18nService: I18nService,
private 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
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
}