This commit is contained in:
kevinpauer 2022-04-28 21:02:33 +02:00
parent 006b65d790
commit 4788159865
5 changed files with 76 additions and 21 deletions

View File

@ -50,7 +50,8 @@ export class DataService {
* @returns Observable * @returns Observable
*/ */
public createTransaction( public createTransaction(
symbol: string, comment: string,
isin: string,
time: string, time: string,
count: number, count: number,
price: number price: number
@ -60,9 +61,10 @@ export class DataService {
return this.http.post( return this.http.post(
API_URL + 'transaction', API_URL + 'transaction',
{ {
comment,
count, count,
isin,
price, price,
symbol,
time, time,
}, },
{ {

View File

@ -123,6 +123,12 @@
<td mat-cell *matCellDef="let element">{{ element.count }}</td> <td mat-cell *matCellDef="let element">{{ element.count }}</td>
</ng-container> </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 --> <!-- Name Column -->
<ng-container matColumnDef="name"> <ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef>Price</th> <th mat-header-cell *matHeaderCellDef>Price</th>
@ -131,8 +137,8 @@
<!-- Weight Column --> <!-- Weight Column -->
<ng-container matColumnDef="weight"> <ng-container matColumnDef="weight">
<th mat-header-cell *matHeaderCellDef>Symbol</th> <th mat-header-cell *matHeaderCellDef>ISIN</th>
<td mat-cell *matCellDef="let element">{{ element.symbol }}</td> <td mat-cell *matCellDef="let element">{{ element.isin }}</td>
</ng-container> </ng-container>
<!-- Symbol Column --> <!-- Symbol Column -->

View File

@ -2,7 +2,6 @@ import { Component, OnInit } from '@angular/core';
import { DataService } from 'src/app/Services/data.service'; import { DataService } from 'src/app/Services/data.service';
import { MatDialog } from '@angular/material/dialog'; import { MatDialog } from '@angular/material/dialog';
import { UserDialogComponent } from './user-dialog/user-dialog.component'; import { UserDialogComponent } from './user-dialog/user-dialog.component';
import { C } from '@angular/cdk/keycodes';
import { HelperService } from 'src/app/Helpers/helper.service'; import { HelperService } from 'src/app/Helpers/helper.service';
export interface PeriodicElement { export interface PeriodicElement {
@ -31,7 +30,8 @@ var TRANSACTION_DATA: TransactionData[] = [];
var STOCK_DATA: Stock[] = []; var STOCK_DATA: Stock[] = [];
export interface TransactionData { export interface TransactionData {
symbol: string; comment: string;
isin: string;
time: string; time: string;
count: number; count: number;
price: number; price: number;
@ -44,8 +44,8 @@ export interface TransactionData {
}) })
export class DashboardComponent implements OnInit { export class DashboardComponent implements OnInit {
constructor( constructor(
private helper: HelperService,
private dataService: DataService, private dataService: DataService,
private helper: HelperService,
public dialog: MatDialog public dialog: MatDialog
) {} ) {}
@ -55,11 +55,34 @@ export class DashboardComponent implements OnInit {
depotCost: number = 0; depotCost: number = 0;
profit: 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() { ngOnInit() {
this.dataService.getStockData().subscribe((response: any) => { this.dataService.getStockData().subscribe((response: any) => {
var data = JSON.parse(response); var data = JSON.parse(response);
this.depotCurrentValue = 0;
for (let i = 0; i < data.data.length; i++) { 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({ STOCK_DATA.push({
count: data.data[i].count, count: data.data[i].count,
currentPrice: data.data[i].current_price, currentPrice: data.data[i].current_price,
@ -75,10 +98,12 @@ export class DashboardComponent implements OnInit {
this.dataService.getTransactionData().subscribe((response: any) => { this.dataService.getTransactionData().subscribe((response: any) => {
var data = JSON.parse(response); var data = JSON.parse(response);
this.depotCost = 0;
for (let i = 0; i < data.data.length; i++) { for (let i = 0; i < data.data.length; i++) {
this.depotCost += data.data[i].price; this.depotCost += data.data[i].price;
TRANSACTION_DATA.push({ TRANSACTION_DATA.push({
symbol: data.data[i].symbol, comment: data.data[i].comment,
isin: data.data[i].isin,
time: data.data[i].time, time: data.data[i].time,
count: data.data[i].count, count: data.data[i].count,
price: data.data[i].price, price: data.data[i].price,
@ -91,7 +116,8 @@ export class DashboardComponent implements OnInit {
}); });
} }
symbol: string = ''; comment: string = '';
isin: string = '';
time: Date = new Date(); time: Date = new Date();
count: number = 0.0; count: number = 0.0;
price: number = 0.0; price: number = 0.0;
@ -100,7 +126,8 @@ export class DashboardComponent implements OnInit {
const dialogRef = this.dialog.open(UserDialogComponent, { const dialogRef = this.dialog.open(UserDialogComponent, {
width: '50vw', width: '50vw',
data: { data: {
symbol: this.symbol, comment: this.comment,
isin: this.isin,
time: this.time, time: this.time,
count: this.count, count: this.count,
price: this.price, price: this.price,
@ -108,11 +135,18 @@ export class DashboardComponent implements OnInit {
}); });
dialogRef.afterClosed().subscribe((result) => { 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[] = [ displayedColumnsStocks: string[] = [
'position', 'position',
'name', 'name',

View File

@ -7,15 +7,27 @@
class="backgorund" class="backgorund"
> >
<div class="form-group"> <div class="form-group">
<label for="symbol">Symbol</label> <label for="comment">Comment</label>
<input <input
type="symbol" type="comment"
class="form-control" class="form-control"
name="symbol" name="comment"
[(ngModel)]="data.symbol" [(ngModel)]="data.comment"
required required
symbol comment
#symbol="ngModel" #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>
<div class="form-group"> <div class="form-group">

View File

@ -22,11 +22,12 @@ export class UserDialogComponent {
) {} ) {}
onSubmit() { onSubmit() {
//TODO check tat price is decimal //TODO check that price is decimal
console.log( console.log(
this.dataService this.dataService
.createTransaction( .createTransaction(
this.data.symbol, this.data.comment,
this.data.isin,
this.data.time, this.data.time,
+this.data.count, +this.data.count,
+this.data.price.toFixed(2) +this.data.price.toFixed(2)