delete item
This commit is contained in:
parent
eee5f6ff32
commit
450ada64cb
|
@ -36,6 +36,7 @@ export class AddEditComponent implements OnChanges {
|
||||||
@Input() folderId: string;
|
@Input() folderId: string;
|
||||||
@Input() cipherId: string;
|
@Input() cipherId: string;
|
||||||
@Output() onSavedCipher = new EventEmitter<CipherView>();
|
@Output() onSavedCipher = new EventEmitter<CipherView>();
|
||||||
|
@Output() onDeletedCipher = new EventEmitter<CipherView>();
|
||||||
@Output() onCancelled = new EventEmitter<CipherView>();
|
@Output() onCancelled = new EventEmitter<CipherView>();
|
||||||
@Output() onEditAttachments = new EventEmitter<CipherView>();
|
@Output() onEditAttachments = new EventEmitter<CipherView>();
|
||||||
|
|
||||||
|
@ -134,7 +135,7 @@ export class AddEditComponent implements OnChanges {
|
||||||
this.analytics.eventTrack.next({ action: this.editMode ? 'Edited Cipher' : 'Added Cipher' });
|
this.analytics.eventTrack.next({ action: this.editMode ? 'Edited Cipher' : 'Added Cipher' });
|
||||||
this.toasterService.popAsync('success', null, this.i18nService.t(this.editMode ? 'editedItem' : 'addedItem'));
|
this.toasterService.popAsync('success', null, this.i18nService.t(this.editMode ? 'editedItem' : 'addedItem'));
|
||||||
this.onSavedCipher.emit(this.cipher);
|
this.onSavedCipher.emit(this.cipher);
|
||||||
};
|
}
|
||||||
|
|
||||||
addField() {
|
addField() {
|
||||||
if (this.cipher.fields == null) {
|
if (this.cipher.fields == null) {
|
||||||
|
@ -144,7 +145,7 @@ export class AddEditComponent implements OnChanges {
|
||||||
const f = new FieldView();
|
const f = new FieldView();
|
||||||
f.type = this.addFieldType;
|
f.type = this.addFieldType;
|
||||||
this.cipher.fields.push(f);
|
this.cipher.fields.push(f);
|
||||||
};
|
}
|
||||||
|
|
||||||
removeField(field: FieldView) {
|
removeField(field: FieldView) {
|
||||||
const i = this.cipher.fields.indexOf(field);
|
const i = this.cipher.fields.indexOf(field);
|
||||||
|
@ -155,9 +156,20 @@ export class AddEditComponent implements OnChanges {
|
||||||
|
|
||||||
cancel() {
|
cancel() {
|
||||||
this.onCancelled.emit(this.cipher);
|
this.onCancelled.emit(this.cipher);
|
||||||
};
|
}
|
||||||
|
|
||||||
attachments() {
|
attachments() {
|
||||||
this.onEditAttachments.emit(this.cipher);
|
this.onEditAttachments.emit(this.cipher);
|
||||||
};
|
}
|
||||||
|
|
||||||
|
async delete() {
|
||||||
|
if (!confirm(this.i18nService.t('deleteItemConfirmation'))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.cipherService.deleteWithServer(this.cipher.id);
|
||||||
|
this.analytics.eventTrack.next({ action: 'Deleted Cipher' });
|
||||||
|
this.toasterService.popAsync('success', null, this.i18nService.t('deletedItem'));
|
||||||
|
this.onDeletedCipher.emit(this.cipher);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,20 +4,49 @@ import {
|
||||||
Component,
|
Component,
|
||||||
EventEmitter,
|
EventEmitter,
|
||||||
Input,
|
Input,
|
||||||
|
OnInit,
|
||||||
Output,
|
Output,
|
||||||
} from '@angular/core';
|
} from '@angular/core';
|
||||||
|
|
||||||
import { CipherView } from 'jslib/models/view/cipherView';
|
import { CipherView } from 'jslib/models/view/cipherView';
|
||||||
|
|
||||||
|
import { CipherService } from 'jslib/abstractions/cipher.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-vault-ciphers',
|
selector: 'app-vault-ciphers',
|
||||||
template: template,
|
template: template,
|
||||||
})
|
})
|
||||||
export class CiphersComponent {
|
export class CiphersComponent implements OnInit {
|
||||||
@Input() ciphers: CipherView[];
|
|
||||||
@Output() onCipherClicked = new EventEmitter<CipherView>();
|
@Output() onCipherClicked = new EventEmitter<CipherView>();
|
||||||
@Output() onAddCipher = new EventEmitter();
|
@Output() onAddCipher = new EventEmitter();
|
||||||
|
|
||||||
|
ciphers: CipherView[] = [];
|
||||||
|
|
||||||
|
constructor(private cipherService: CipherService) {
|
||||||
|
}
|
||||||
|
|
||||||
|
async ngOnInit() {
|
||||||
|
await this.loadCiphers();
|
||||||
|
}
|
||||||
|
|
||||||
|
async refresh() {
|
||||||
|
await this.loadCiphers();
|
||||||
|
}
|
||||||
|
|
||||||
|
updateCipher(cipher: CipherView) {
|
||||||
|
const i = this.ciphers.findIndex((c) => c.id === cipher.id);
|
||||||
|
if (i > -1) {
|
||||||
|
this.ciphers[i] = cipher;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
removeCipher(cipherId: string) {
|
||||||
|
const i = this.ciphers.findIndex((c) => c.id === cipherId);
|
||||||
|
if (i > -1) {
|
||||||
|
this.ciphers.splice(i, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
cipherClicked(cipher: CipherView) {
|
cipherClicked(cipher: CipherView) {
|
||||||
this.onCipherClicked.emit(cipher);
|
this.onCipherClicked.emit(cipher);
|
||||||
}
|
}
|
||||||
|
@ -25,4 +54,8 @@ export class CiphersComponent {
|
||||||
addCipher() {
|
addCipher() {
|
||||||
this.onAddCipher.emit();
|
this.onAddCipher.emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async loadCiphers() {
|
||||||
|
this.ciphers = await this.cipherService.getAllDecrypted();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
<app-vault-groupings id="groupings">
|
<app-vault-groupings id="groupings">
|
||||||
</app-vault-groupings>
|
</app-vault-groupings>
|
||||||
<app-vault-ciphers id="items"
|
<app-vault-ciphers id="items"
|
||||||
[ciphers]="ciphers"
|
|
||||||
(onCipherClicked)="viewCipher($event)"
|
(onCipherClicked)="viewCipher($event)"
|
||||||
(onAddCipher)="addCipher($event)">
|
(onAddCipher)="addCipher($event)">
|
||||||
</app-vault-ciphers>
|
</app-vault-ciphers>
|
||||||
|
@ -16,6 +15,7 @@
|
||||||
[folderId]="null"
|
[folderId]="null"
|
||||||
[cipherId]="action === 'edit' ? cipherId : null"
|
[cipherId]="action === 'edit' ? cipherId : null"
|
||||||
(onSavedCipher)="savedCipher($event)"
|
(onSavedCipher)="savedCipher($event)"
|
||||||
|
(onDeletedCipher)="deletedCipher($event)"
|
||||||
(onEditAttachments)="editCipherAttachments($event)"
|
(onEditAttachments)="editCipherAttachments($event)"
|
||||||
(onCancelled)="cancelledAddEdit($event)">
|
(onCancelled)="cancelledAddEdit($event)">
|
||||||
</app-vault-add-edit>
|
</app-vault-add-edit>
|
||||||
|
|
|
@ -3,6 +3,7 @@ import * as template from './vault.component.html';
|
||||||
import {
|
import {
|
||||||
Component,
|
Component,
|
||||||
OnInit,
|
OnInit,
|
||||||
|
ViewChild,
|
||||||
} from '@angular/core';
|
} from '@angular/core';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
@ -12,7 +13,7 @@ import {
|
||||||
|
|
||||||
import { Location } from '@angular/common';
|
import { Location } from '@angular/common';
|
||||||
|
|
||||||
import { CipherService } from 'jslib/abstractions/cipher.service';
|
import { CiphersComponent } from './ciphers.component';
|
||||||
|
|
||||||
import { CipherView } from 'jslib/models/view/cipherView';
|
import { CipherView } from 'jslib/models/view/cipherView';
|
||||||
|
|
||||||
|
@ -21,17 +22,15 @@ import { CipherView } from 'jslib/models/view/cipherView';
|
||||||
template: template,
|
template: template,
|
||||||
})
|
})
|
||||||
export class VaultComponent implements OnInit {
|
export class VaultComponent implements OnInit {
|
||||||
ciphers: CipherView[];
|
@ViewChild(CiphersComponent) ciphersComponent: CiphersComponent;
|
||||||
|
|
||||||
cipherId: string;
|
cipherId: string;
|
||||||
action: string;
|
action: string;
|
||||||
|
|
||||||
constructor(private cipherService: CipherService, private route: ActivatedRoute, private router: Router,
|
constructor(private route: ActivatedRoute, private router: Router, private location: Location) {
|
||||||
private location: Location) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async ngOnInit() {
|
async ngOnInit() {
|
||||||
this.ciphers = await this.cipherService.getAllDecrypted();
|
|
||||||
|
|
||||||
this.route.queryParams.subscribe((params) => {
|
this.route.queryParams.subscribe((params) => {
|
||||||
if (params['cipherId']) {
|
if (params['cipherId']) {
|
||||||
const cipherView = new CipherView();
|
const cipherView = new CipherView();
|
||||||
|
@ -81,10 +80,14 @@ export class VaultComponent implements OnInit {
|
||||||
this.cipherId = cipher.id;
|
this.cipherId = cipher.id;
|
||||||
this.action = 'view';
|
this.action = 'view';
|
||||||
this.go({ action: this.action, cipherId: this.cipherId });
|
this.go({ action: this.action, cipherId: this.cipherId });
|
||||||
|
this.ciphersComponent.updateCipher(cipher);
|
||||||
}
|
}
|
||||||
|
|
||||||
deletedCipher(cipher: CipherView) {
|
deletedCipher(cipher: CipherView) {
|
||||||
|
this.cipherId = null;
|
||||||
|
this.action = null;
|
||||||
|
this.go({ action: this.action, cipherId: this.cipherId });
|
||||||
|
this.ciphersComponent.removeCipher(cipher.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
editCipherAttachments(cipher: CipherView) {
|
editCipherAttachments(cipher: CipherView) {
|
||||||
|
|
Loading…
Reference in New Issue