Frontend #171

Merged
Rripped merged 3 commits from frontend into main 2022-05-10 15:27:36 +00:00
10 changed files with 66 additions and 10 deletions
Showing only changes of commit 0fc9e8d37f - Show all commits

View File

@ -9,12 +9,17 @@ export class HelperService {
constructor(private botService: BotService) {}
/**
* Function to delay loading of webpage for a smoother user experience
* @param {number} ms
*/
delay(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
/**
* Function to format share data
* @returns Share
*/
formatShareData(): Share[] {
var shares: Share[] = [];
this.botService.getSymbols().subscribe((result) => {
@ -27,7 +32,10 @@ export class HelperService {
});
return shares;
}
/**
* @returns Keyword
* Function to format keyword data
*/
formatKeywordsData(): Keyword[] {
var keywords: Keyword[] = [];
this.botService.getKeywords().subscribe((result) => {

View File

@ -14,6 +14,7 @@ export class AuthService {
constructor(private http: HttpClient) {}
/**
* Function to login user
* @param {string} email
* @param {string} password
* @returns Observable
@ -26,6 +27,7 @@ export class AuthService {
}
/**
* Function to register user
* @param {string} email
* @param {string} username
* @param {string} password

View File

@ -15,6 +15,7 @@ export class BotService {
) {}
/**
* Function to get all keywords
* @returns Observable
*/
public getKeywords(): Observable<any> {
@ -28,6 +29,7 @@ export class BotService {
}
/**
* Function to create a keyword
* @param {string} keyword
* @returns Observable
*/
@ -47,6 +49,7 @@ export class BotService {
}
/**
* Function to delete a keyword
* @param {string} keyword
* @returns Observable
*/
@ -63,6 +66,7 @@ export class BotService {
}
/**
* Function to get all shares
* @returns Observable
*/
public getSymbols(): Observable<any> {
@ -76,6 +80,7 @@ export class BotService {
}
/**
* Function to create a share
* @param {string} keyword
* @returns Observable
*/
@ -96,6 +101,7 @@ export class BotService {
}
/**
* Function to delete a share
* @param {string} symbol
* @returns Observable
*/

View File

@ -17,6 +17,7 @@ export class DataService {
) {}
/**
* Function to get all portfolio data
* @returns Observable
*/
public getStockData(): Observable<any> {
@ -30,6 +31,7 @@ export class DataService {
}
/**
* Function to get all transaction data
* @returns Observable
*/
public getTransactionData(): Observable<any> {
@ -43,6 +45,7 @@ export class DataService {
}
/**
* Function to create a transaction
* @param {string} symbol
* @param {Date} time
* @param {number} count
@ -77,6 +80,7 @@ export class DataService {
}
/**
* Function to get all keywords
* @returns Observable
*/
public getKeywords(): Observable<any> {

View File

@ -15,6 +15,7 @@ export class ProfileService {
) {}
/**
* Function to get all Userdata
* @returns Observable
*/
public getUserData(): Observable<any> {
@ -28,6 +29,7 @@ export class ProfileService {
}
/**
* Function to update user profile
* @param {string} username
* @param {number} password
* @returns Observable
@ -49,6 +51,7 @@ export class ProfileService {
}
/**
* Function to add a telegram id
* @param {string} telegramUserID
* @returns Observable
*/
@ -68,6 +71,7 @@ export class ProfileService {
}
/**
* Function to add a cron string for automatic updates
* @param {string} cronString
* @returns Observable
*/

View File

@ -8,6 +8,7 @@ export class TokenStorageService {
constructor() {}
/**
* Function to sign out user
* @returns void
*/
signOut(): void {
@ -15,6 +16,7 @@ export class TokenStorageService {
}
/**
* Function to save token
* @param {string} token
* @returns void
*/
@ -24,6 +26,7 @@ export class TokenStorageService {
}
/**
* Function to get token
* @returns string
*/
public getToken(): string | null {
@ -31,6 +34,7 @@ export class TokenStorageService {
}
/**
* Function to save user
* @param {any} user
* @returns void
*/
@ -40,6 +44,7 @@ export class TokenStorageService {
}
/**
* Function to get user
* @returns any
*/
public getUser(): any {

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;