Add duplicate action on transactions table (#68)

* feat: add duplicate action on transactions table

* fix: review changes

* fix: add type and dataSource
pull/70/head
Mantovani Gabriele 3 years ago committed by GitHub
parent a3d1ac2ce4
commit 631efff7ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -177,6 +177,9 @@
<button i18n mat-menu-item (click)="onUpdateTransaction(element)"> <button i18n mat-menu-item (click)="onUpdateTransaction(element)">
Edit Edit
</button> </button>
<button i18n mat-menu-item (click)="onCloneTransaction(element)">
Clone
</button>
<button i18n mat-menu-item (click)="onDeleteTransaction(element.id)"> <button i18n mat-menu-item (click)="onDeleteTransaction(element.id)">
Delete Delete
</button> </button>

@ -35,6 +35,7 @@ export class TransactionsTableComponent
@Input() transactions: OrderModel[]; @Input() transactions: OrderModel[];
@Output() transactionDeleted = new EventEmitter<string>(); @Output() transactionDeleted = new EventEmitter<string>();
@Output() transactionToClone = new EventEmitter<OrderModel>();
@Output() transactionToUpdate = new EventEmitter<OrderModel>(); @Output() transactionToUpdate = new EventEmitter<OrderModel>();
@ViewChild(MatSort) sort: MatSort; @ViewChild(MatSort) sort: MatSort;
@ -123,6 +124,10 @@ export class TransactionsTableComponent
this.transactionToUpdate.emit(aTransaction); this.transactionToUpdate.emit(aTransaction);
} }
public onCloneTransaction(aTransaction: OrderModel) {
this.transactionToClone.emit(aTransaction);
}
public openPositionDialog({ public openPositionDialog({
symbol, symbol,
title title

@ -109,6 +109,10 @@ export class TransactionsPageComponent implements OnInit {
}); });
} }
public onCloneTransaction(aTransaction: OrderModel) {
this.openCreateTransactionDialog(aTransaction);
}
public onDeleteTransaction(aId: string) { public onDeleteTransaction(aId: string) {
this.dataService.deleteOrder(aId).subscribe({ this.dataService.deleteOrder(aId).subscribe({
next: () => { next: () => {
@ -175,20 +179,21 @@ export class TransactionsPageComponent implements OnInit {
this.unsubscribeSubject.complete(); this.unsubscribeSubject.complete();
} }
private openCreateTransactionDialog(): void { private openCreateTransactionDialog(aTransaction?: OrderModel): void {
const dialogRef = this.dialog.open(CreateOrUpdateTransactionDialog, { const dialogRef = this.dialog.open(CreateOrUpdateTransactionDialog, {
data: { data: {
accounts: this.user?.accounts, accounts: this.user?.accounts,
transaction: { transaction: {
accountId: this.user?.accounts.find((account) => { accountId: aTransaction?.accountId ?? this.user?.accounts.find((account) => {
return account.isDefault; return account.isDefault;
})?.id, })?.id,
currency: null, currency: aTransaction?.currency ?? null,
dataSource: aTransaction?.dataSource ?? null,
date: new Date(), date: new Date(),
fee: 0, fee: 0,
quantity: null, quantity: null,
symbol: null, symbol: aTransaction?.symbol ?? null,
type: 'BUY', type: aTransaction?.type ?? 'BUY',
unitPrice: null unitPrice: null
} }
}, },

@ -9,6 +9,7 @@
[showActions]="!hasImpersonationId && hasPermissionToDeleteOrder" [showActions]="!hasImpersonationId && hasPermissionToDeleteOrder"
[transactions]="transactions" [transactions]="transactions"
(transactionDeleted)="onDeleteTransaction($event)" (transactionDeleted)="onDeleteTransaction($event)"
(transactionToClone)="onCloneTransaction($event)"
(transactionToUpdate)="onUpdateTransaction($event)" (transactionToUpdate)="onUpdateTransaction($event)"
></gf-transactions-table> ></gf-transactions-table>
</div> </div>

Loading…
Cancel
Save