Improve code quality and add comments

This commit is contained in:
kevinpauer
2022-05-08 19:52:08 +02:00
parent a2b4686528
commit 0fc9e8d37f
10 changed files with 66 additions and 10 deletions

View File

@@ -41,6 +41,12 @@ export class DashboardComponent implements OnInit {
depotCost: number = 0;
profit: number = 0;
comment: string = '';
isin: string = '';
time: Date = new Date();
count: number = 0.0;
price: number = 0.0;
getTransactions() {
var TRANSACTION_DATA: TransactionData[] = [];
this.dataService.getTransactionData().subscribe((response: any) => {
@@ -64,6 +70,9 @@ export class DashboardComponent implements OnInit {
}
ngOnInit() {
/**
* Function gets the stock data and pushes it in the temporary object array
*/
this.dataService.getStockData().subscribe((response: any) => {
var data = JSON.parse(response);
console.log(data);
@@ -78,11 +87,14 @@ export class DashboardComponent implements OnInit {
current_price: data.data[i].current_price,
});
}
console.log(STOCK_DATA);
// assign data source
this.dataSourceStocks = STOCK_DATA;
this.profit += this.depotCurrentValue;
});
/**
* Function gets the transaction data and pushes it in the temporary object array
*/
this.dataService.getTransactionData().subscribe((response: any) => {
var data = JSON.parse(response);
this.depotCost = 0;
@@ -96,19 +108,13 @@ export class DashboardComponent implements OnInit {
price: data.data[i].price,
});
}
// assign data source
this.dataSourceTransactions = TRANSACTION_DATA;
//TODO move to helper service
this.profit += this.depotCost;
});
}
comment: string = '';
isin: string = '';
time: Date = new Date();
count: number = 0.0;
price: number = 0.0;
// function to open the user dialog to create a new transaction
openDialog(): void {
const dialogRef = this.dialog.open(UserDialogComponent, {
width: '50vw',
@@ -127,6 +133,7 @@ export class DashboardComponent implements OnInit {
});
}
// assign columns for transactions to display in html, you can change order and add/remove columns
displayedColumns: string[] = [
'comment',
'weight',
@@ -134,6 +141,8 @@ export class DashboardComponent implements OnInit {
'name',
'symbol',
];
// assign columns to display in html, you can change order and add/remove columns
displayedColumnsStocks: string[] = [
'count',
'comment',

View File

@@ -13,6 +13,7 @@ export class LoginComponent implements OnInit {
email: null,
password: null,
};
isLoggedIn = false;
isLoginFailed = false;
errorMessage = '';

View File

@@ -32,6 +32,9 @@ export class ProfileComponent implements OnInit {
) {}
ngOnInit(): void {
/**
* get user data to display
*/
this.profileService.getUserData().subscribe((result) => {
console.log(result);
result = JSON.parse(result);
@@ -42,6 +45,9 @@ export class ProfileComponent implements OnInit {
});
}
/**
* Add telegram user id in database
*/
onSubmit() {
if (this.userId != '') {
console.log(this.userId);
@@ -51,6 +57,9 @@ export class ProfileComponent implements OnInit {
}
}
/**
* Function to update user information
*/
updateUser() {
const { username, email, password } = this.form;
this.profileService
@@ -60,12 +69,14 @@ export class ProfileComponent implements OnInit {
});
}
// opens confirmation dialog
openDialog(action: string) {
const dialogRef = this.dialog.open(ConfirmationDialogComponent, {
width: '50vw',
height: '20vh',
});
// on close dialog, if action is "addTelegram" update telegram id, else update user information
dialogRef.afterClosed().subscribe((result) => {
if (result === true) {
if (action === 'addTelegram') {
@@ -77,6 +88,7 @@ export class ProfileComponent implements OnInit {
});
}
// helper user dialog to explain the process of getting the telegram id
openHelp() {
const dialogRef = this.dialog.open(HelpDialogComponent, {
width: '50vw',

View File

@@ -25,7 +25,12 @@ export class RegisterComponent {
* @param {Router} privaterouter
*/
constructor(private authService: AuthService, private router: Router) {}
/**
* On submit, send user information to backend
*/
onSubmit(): void {
// validate that passwords match
if (this.form.password === this.form.passwordRepeat) {
this.checkPasswordFailed = false;
const { email, username, password } = this.form;