Fix #83
This commit is contained in:
parent
006b65d790
commit
4788159865
@ -50,7 +50,8 @@ export class DataService {
|
||||
* @returns Observable
|
||||
*/
|
||||
public createTransaction(
|
||||
symbol: string,
|
||||
comment: string,
|
||||
isin: string,
|
||||
time: string,
|
||||
count: number,
|
||||
price: number
|
||||
@ -60,9 +61,10 @@ export class DataService {
|
||||
return this.http.post(
|
||||
API_URL + 'transaction',
|
||||
{
|
||||
comment,
|
||||
count,
|
||||
isin,
|
||||
price,
|
||||
symbol,
|
||||
time,
|
||||
},
|
||||
{
|
||||
|
@ -123,6 +123,12 @@
|
||||
<td mat-cell *matCellDef="let element">{{ element.count }}</td>
|
||||
</ng-container>
|
||||
|
||||
<!-- Comment Column -->
|
||||
<ng-container matColumnDef="comment">
|
||||
<th mat-header-cell *matHeaderCellDef>Comment</th>
|
||||
<td mat-cell *matCellDef="let element">{{ element.comment }}</td>
|
||||
</ng-container>
|
||||
|
||||
<!-- Name Column -->
|
||||
<ng-container matColumnDef="name">
|
||||
<th mat-header-cell *matHeaderCellDef>Price</th>
|
||||
@ -131,8 +137,8 @@
|
||||
|
||||
<!-- Weight Column -->
|
||||
<ng-container matColumnDef="weight">
|
||||
<th mat-header-cell *matHeaderCellDef>Symbol</th>
|
||||
<td mat-cell *matCellDef="let element">{{ element.symbol }}</td>
|
||||
<th mat-header-cell *matHeaderCellDef>ISIN</th>
|
||||
<td mat-cell *matCellDef="let element">{{ element.isin }}</td>
|
||||
</ng-container>
|
||||
|
||||
<!-- Symbol Column -->
|
||||
|
@ -2,7 +2,6 @@ import { Component, OnInit } from '@angular/core';
|
||||
import { DataService } from 'src/app/Services/data.service';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { UserDialogComponent } from './user-dialog/user-dialog.component';
|
||||
import { C } from '@angular/cdk/keycodes';
|
||||
import { HelperService } from 'src/app/Helpers/helper.service';
|
||||
|
||||
export interface PeriodicElement {
|
||||
@ -31,7 +30,8 @@ var TRANSACTION_DATA: TransactionData[] = [];
|
||||
var STOCK_DATA: Stock[] = [];
|
||||
|
||||
export interface TransactionData {
|
||||
symbol: string;
|
||||
comment: string;
|
||||
isin: string;
|
||||
time: string;
|
||||
count: number;
|
||||
price: number;
|
||||
@ -44,8 +44,8 @@ export interface TransactionData {
|
||||
})
|
||||
export class DashboardComponent implements OnInit {
|
||||
constructor(
|
||||
private helper: HelperService,
|
||||
private dataService: DataService,
|
||||
private helper: HelperService,
|
||||
public dialog: MatDialog
|
||||
) {}
|
||||
|
||||
@ -55,11 +55,34 @@ export class DashboardComponent implements OnInit {
|
||||
depotCost: number = 0;
|
||||
profit: number = 0;
|
||||
|
||||
getTransactions() {
|
||||
var TRANSACTION_DATA: TransactionData[] = [];
|
||||
this.dataService.getTransactionData().subscribe((response: any) => {
|
||||
var data = JSON.parse(response);
|
||||
this.depotCost = 0;
|
||||
for (let i = 0; i < data.data.length; i++) {
|
||||
this.depotCost += data.data[i].price;
|
||||
TRANSACTION_DATA.push({
|
||||
comment: data.data[i].comment,
|
||||
isin: data.data[i].isin,
|
||||
time: data.data[i].time,
|
||||
count: data.data[i].count,
|
||||
price: data.data[i].price,
|
||||
});
|
||||
}
|
||||
this.dataSourceTransactions = TRANSACTION_DATA;
|
||||
//TODO move to helper service
|
||||
|
||||
this.profit = this.depotCurrentValue - this.depotCost;
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.dataService.getStockData().subscribe((response: any) => {
|
||||
var data = JSON.parse(response);
|
||||
this.depotCurrentValue = 0;
|
||||
for (let i = 0; i < data.data.length; i++) {
|
||||
this.depotCurrentValue += data.data[i].current_price;
|
||||
this.depotCurrentValue = data.data[i].current_price;
|
||||
STOCK_DATA.push({
|
||||
count: data.data[i].count,
|
||||
currentPrice: data.data[i].current_price,
|
||||
@ -75,10 +98,12 @@ export class DashboardComponent implements OnInit {
|
||||
|
||||
this.dataService.getTransactionData().subscribe((response: any) => {
|
||||
var data = JSON.parse(response);
|
||||
this.depotCost = 0;
|
||||
for (let i = 0; i < data.data.length; i++) {
|
||||
this.depotCost += data.data[i].price;
|
||||
TRANSACTION_DATA.push({
|
||||
symbol: data.data[i].symbol,
|
||||
comment: data.data[i].comment,
|
||||
isin: data.data[i].isin,
|
||||
time: data.data[i].time,
|
||||
count: data.data[i].count,
|
||||
price: data.data[i].price,
|
||||
@ -91,7 +116,8 @@ export class DashboardComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
symbol: string = '';
|
||||
comment: string = '';
|
||||
isin: string = '';
|
||||
time: Date = new Date();
|
||||
count: number = 0.0;
|
||||
price: number = 0.0;
|
||||
@ -100,7 +126,8 @@ export class DashboardComponent implements OnInit {
|
||||
const dialogRef = this.dialog.open(UserDialogComponent, {
|
||||
width: '50vw',
|
||||
data: {
|
||||
symbol: this.symbol,
|
||||
comment: this.comment,
|
||||
isin: this.isin,
|
||||
time: this.time,
|
||||
count: this.count,
|
||||
price: this.price,
|
||||
@ -108,11 +135,18 @@ export class DashboardComponent implements OnInit {
|
||||
});
|
||||
|
||||
dialogRef.afterClosed().subscribe((result) => {
|
||||
console.log('The dialog was closed');
|
||||
this.helper.delay(1000);
|
||||
this.getTransactions();
|
||||
});
|
||||
}
|
||||
|
||||
displayedColumns: string[] = ['weight', 'position', 'name', 'symbol'];
|
||||
displayedColumns: string[] = [
|
||||
'comment',
|
||||
'weight',
|
||||
'position',
|
||||
'name',
|
||||
'symbol',
|
||||
];
|
||||
displayedColumnsStocks: string[] = [
|
||||
'position',
|
||||
'name',
|
||||
|
@ -7,15 +7,27 @@
|
||||
class="backgorund"
|
||||
>
|
||||
<div class="form-group">
|
||||
<label for="symbol">Symbol</label>
|
||||
<label for="comment">Comment</label>
|
||||
<input
|
||||
type="symbol"
|
||||
type="comment"
|
||||
class="form-control"
|
||||
name="symbol"
|
||||
[(ngModel)]="data.symbol"
|
||||
name="comment"
|
||||
[(ngModel)]="data.comment"
|
||||
required
|
||||
symbol
|
||||
#symbol="ngModel"
|
||||
comment
|
||||
#comment="ngModel"
|
||||
/>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="isin">isin</label>
|
||||
<input
|
||||
type="isin"
|
||||
class="form-control"
|
||||
name="isin"
|
||||
[(ngModel)]="data.isin"
|
||||
required
|
||||
isin
|
||||
#isin="ngModel"
|
||||
/>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
|
@ -22,11 +22,12 @@ export class UserDialogComponent {
|
||||
) {}
|
||||
|
||||
onSubmit() {
|
||||
//TODO check tat price is decimal
|
||||
//TODO check that price is decimal
|
||||
console.log(
|
||||
this.dataService
|
||||
.createTransaction(
|
||||
this.data.symbol,
|
||||
this.data.comment,
|
||||
this.data.isin,
|
||||
this.data.time,
|
||||
+this.data.count,
|
||||
+this.data.price.toFixed(2)
|
||||
|
Loading…
Reference in New Issue
Block a user