Add transaction skeletton

This commit is contained in:
kevinpauer 2022-03-31 22:32:42 +02:00
parent e9f1e7d38a
commit c5e66b4720
10 changed files with 225 additions and 5 deletions

View File

@ -1,7 +1,7 @@
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs';
const AUTH_API = 'https://aktienbot.flokaiser.com/api/user';
const AUTH_API = 'https://gruppe1.testsites.info/api/user';
const httpOptions = {
headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
};

View File

@ -2,16 +2,23 @@ import { Injectable, OnInit } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { delay, Observable } from 'rxjs';
import { TokenStorageService } from './token.service';
const API_URL = 'https://aktienbot.flokaiser.com/api/';
const API_URL = 'https://gruppe1.testsites.info/api/';
@Injectable({
providedIn: 'root',
})
export class DataService {
/**
* @param {HttpClient} privatehttp
* @param {TokenStorageService} privatetokenStorage
*/
constructor(
private http: HttpClient,
private tokenStorage: TokenStorageService
) {}
/**
* @returns Observable
*/
public getStockData(): Observable<any> {
return this.http.get(API_URL + 'portfolio', {
headers: new HttpHeaders({
@ -22,6 +29,9 @@ export class DataService {
});
}
/**
* @returns Observable
*/
public getTransactionData(): Observable<any> {
return this.http.get(API_URL + 'transactions', {
headers: new HttpHeaders({
@ -32,6 +42,34 @@ export class DataService {
});
}
/**
* @param {string} symbol
* @param {Date} time
* @param {number} count
* @param {number} price
* @returns Observable
*/
public createTransaction(
symbol: string,
time: Date,
count: number,
price: number
): Observable<any> {
return this.http.post(API_URL + 'transactions', {
headers: new HttpHeaders({
'Content-Type': 'application/json',
Authorization: 'Bearer ' + this.tokenStorage.getToken(),
}),
symbol,
time,
count,
price,
});
}
/**
* @returns Observable
*/
public getKeywords(): Observable<any> {
return this.http.get(API_URL + 'keywords', {
headers: new HttpHeaders({

View File

@ -63,6 +63,16 @@
<div class="depotOverview">
<div class="heading fix-right-side">
<div class="vertical-center">Transaktionen</div>
<span class="spacer"></span>
<button
mat-icon-button
class="add-icon"
aria-label="Example icon-button with heart icon"
[disableRipple]="true"
(click)="openDialog()"
>
<mat-icon>add</mat-icon>
</button>
</div>
<div class="stockTable">
<table mat-table [dataSource]="dataSource" class="mat-elevation-z8">

View File

@ -62,3 +62,11 @@ table {
.placeholder {
height: 100%;
}
side-heading {
display: inline;
}
.mat-ripple-element {
display: none !important;
}

View File

@ -1,7 +1,7 @@
import { Component, OnInit } from '@angular/core';
import { throwToolbarMixedModesError } from '@angular/material/toolbar';
import { DataService } from 'src/app/Services/data.service';
import { TokenStorageService } from 'src/app/Services/token.service';
import { MatDialog } from '@angular/material/dialog';
import { UserDialogComponent } from './user-dialog/user-dialog.component';
export interface PeriodicElement {
name: string;
@ -43,13 +43,21 @@ const ELEMENT_DATA: PeriodicElement[] = [
{ position: 20, name: 'Neon', weight: 20.1797, symbol: 'Ne' },
];
export interface TransactionData {
symbol: string;
time: Date;
count: number;
price: number;
}
@Component({
selector: 'app-dashboard',
templateUrl: './dashboard.component.html',
styleUrls: ['./dashboard.component.scss'],
})
export class DashboardComponent implements OnInit {
constructor(private dataService: DataService) {}
constructor(private dataService: DataService, public dialog: MatDialog) {}
ngOnInit() {
this.dataService.getStockData().subscribe((response: any) => {
console.log(response);
@ -61,6 +69,28 @@ export class DashboardComponent implements OnInit {
});
}
symbol: string = '';
time: Date = new Date();
count: number = 0.0;
price: number = 0.0;
openDialog(): void {
const dialogRef = this.dialog.open(UserDialogComponent, {
width: '50vw',
height: '55vh',
data: {
symbol: this.symbol,
time: this.time,
count: this.count,
price: this.price,
},
});
dialogRef.afterClosed().subscribe((result) => {
console.log('The dialog was closed');
});
}
displayedColumns: string[] = ['position', 'name', 'weight', 'symbol'];
dataSource = ELEMENT_DATA;
}

View File

@ -0,0 +1,60 @@
<h1 mat-dialog-title>Neue Transaktion hinzufügen</h1>
<form
name="form"
(ngSubmit)="f.form.valid && onSubmit()"
#f="ngForm"
novalidate
class="backgorund"
>
<div class="form-group">
<label for="symbol">Symbol</label>
<input
type="symbol"
class="form-control"
name="symbol"
[(ngModel)]="data.symbol"
required
symbol
#symbol="ngModel"
/>
</div>
<div class="form-group">
<label for="time">Time</label>
<input
type="date"
class="form-control"
name="time"
[(ngModel)]="data.time"
required
time
#time="ngModel"
/>
</div>
<div class="form-group">
<label for="count">Count</label>
<input
type="count"
class="form-control"
name="count"
[(ngModel)]="data.count"
required
count
#count="ngModel"
/>
</div>
<div class="form-group">
<label for="price">Price</label>
<input
class="form-control"
name="price"
[(ngModel)]="data.price"
required
#price="ngModel"
/>
</div>
<div class="form-group footer-buttons">
<button class="btn btn-danger btn-block" mat-dialog-close>Cancel</button>
<span class="spacer"></span>
<button class="btn btn-primary btn-block">Confirm</button>
</div>
</form>

View File

@ -0,0 +1,9 @@
.spacer {
flex-grow: 1;
width: 5%;
}
.footer-buttons {
display: flex;
width: 100%;
}

View File

@ -0,0 +1,25 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { UserDialogComponent } from './user-dialog.component';
describe('UserDialogComponent', () => {
let component: UserDialogComponent;
let fixture: ComponentFixture<UserDialogComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ UserDialogComponent ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(UserDialogComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,36 @@
import { Component, Inject, OnInit } from '@angular/core';
import {
MatDialog,
MatDialogRef,
MAT_DIALOG_DATA,
} from '@angular/material/dialog';
import { DataService } from 'src/app/Services/data.service';
import { TransactionData } from '../dashboard.component';
@Component({
selector: 'app-user-dialog',
templateUrl: './user-dialog.component.html',
styleUrls: ['./user-dialog.component.scss'],
})
export class UserDialogComponent implements OnInit {
constructor(
private dataService: DataService,
public dialog: MatDialog,
public dialogRef: MatDialogRef<UserDialogComponent>,
@Inject(MAT_DIALOG_DATA) public data: TransactionData
) {}
ngOnInit(): void {}
onSubmit() {
console.log(this.data);
this.dataService.createTransaction(
this.data.symbol,
this.data.time,
this.data.count,
this.data.price
);
this.dialog.closeAll();
}
}

View File

@ -10,6 +10,7 @@ import { MatGridListModule } from '@angular/material/grid-list';
import { MatCardModule } from '@angular/material/card';
import { MatTableModule } from '@angular/material/table';
import { MatMenuModule } from '@angular/material/menu';
import { MatDialogModule } from '@angular/material/dialog';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
@ -20,6 +21,7 @@ import { DashboardComponent } from './Views/dashboard/dashboard.component';
import { RegisterComponent } from './Views/register/register.component';
import { ProfileComponent } from './Views/profile/profile.component';
import { BotSettingsComponent } from './Views/bot-settings/bot-settings.component';
import { UserDialogComponent } from './Views/dashboard/user-dialog/user-dialog.component';
@NgModule({
declarations: [
@ -30,6 +32,7 @@ import { BotSettingsComponent } from './Views/bot-settings/bot-settings.componen
RegisterComponent,
ProfileComponent,
BotSettingsComponent,
UserDialogComponent,
],
imports: [
BrowserModule,
@ -44,6 +47,7 @@ import { BotSettingsComponent } from './Views/bot-settings/bot-settings.componen
FormsModule,
HttpClientModule,
MatMenuModule,
MatDialogModule,
],
providers: [],
bootstrap: [AppComponent],