From 88f9d0b45e52680e63ef1a8593ea5932b1be653b Mon Sep 17 00:00:00 2001 From: Manushreshta B L Date: Sat, 14 Oct 2023 00:27:44 +0530 Subject: [PATCH] Provided support for adding Manual asset https://github.com/ghostfolio/ghostfolio/issues/2283 -Added Radio button and Input --- apps/api/src/app/admin/admin.service.ts | 5 ++ .../create-asset-profile-dialog.component.ts | 48 +++++++++++++++++-- .../create-asset-profile-dialog.html | 32 +++++++++---- .../create-asset-profile-dialog.module.ts | 5 ++ 4 files changed, 77 insertions(+), 13 deletions(-) diff --git a/apps/api/src/app/admin/admin.service.ts b/apps/api/src/app/admin/admin.service.ts index dd9e3f9ce..c062bdc37 100644 --- a/apps/api/src/app/admin/admin.service.ts +++ b/apps/api/src/app/admin/admin.service.ts @@ -45,6 +45,11 @@ export class AdminService { symbol }: UniqueAsset): Promise { try { + if(dataSource==="MANUAL") + return await this.symbolProfileService.add( + {symbol, currency:DEFAULT_CURRENCY, dataSource:"MANUAL"} + ); + const assetProfiles = await this.dataProviderService.getAssetProfiles([ { dataSource, symbol } ]); diff --git a/apps/client/src/app/components/admin-market-data/create-asset-profile-dialog/create-asset-profile-dialog.component.ts b/apps/client/src/app/components/admin-market-data/create-asset-profile-dialog/create-asset-profile-dialog.component.ts index c3c2fb2eb..4f9324cf9 100644 --- a/apps/client/src/app/components/admin-market-data/create-asset-profile-dialog/create-asset-profile-dialog.component.ts +++ b/apps/client/src/app/components/admin-market-data/create-asset-profile-dialog/create-asset-profile-dialog.component.ts @@ -7,9 +7,11 @@ import { OnInit } from '@angular/core'; import { + AbstractControl, FormBuilder, FormControl, FormGroup, + ValidationErrors, Validators } from '@angular/forms'; import { MatDialogRef } from '@angular/material/dialog'; @@ -23,31 +25,67 @@ import { AdminService } from '@ghostfolio/client/services/admin.service'; }) export class CreateAssetProfileDialog implements OnInit, OnDestroy { public createAssetProfileForm: FormGroup; + public selectedOption: string; public constructor( public readonly adminService: AdminService, public readonly changeDetectorRef: ChangeDetectorRef, public readonly dialogRef: MatDialogRef, - public readonly formBuilder: FormBuilder + public readonly formBuilder: FormBuilder, + ) {} + + public ngOnInit() { - public ngOnInit() { + this.createAssetProfileForm = this.formBuilder.group({ - searchSymbol: new FormControl(null, [Validators.required]) + searchSymbol: new FormControl(null, [Validators.required]), + addSymbol: new FormControl(null, [Validators.required]) + }, + { + validators: atLeastOneValid, }); + + this.selectedOption = 'auto'; } public onCancel() { this.dialogRef.close(); } + public onRadioChange(option: string) { + this.selectedOption = option; + } + public onSubmit() { + console.log(this.createAssetProfileForm.controls['addSymbol'].value) + this.selectedOption==='auto'? this.dialogRef.close({ dataSource: this.createAssetProfileForm.controls['searchSymbol'].value.dataSource, symbol: this.createAssetProfileForm.controls['searchSymbol'].value.symbol - }); + }) + : + this.dialogRef.close({ + dataSource:"MANUAL", + symbol: this.createAssetProfileForm.controls['addSymbol'].value + }) } - + public ngOnDestroy() {} } + +const atLeastOneValid = (control: AbstractControl): ValidationErrors | null => { + const searchSymbolControl = control.get('searchSymbol'); + const addSymbolControl = control.get('addSymbol'); + + if(searchSymbolControl.valid && addSymbolControl.valid){ + return { atLeastOneValid: true }; + } + + if ((!searchSymbolControl || !addSymbolControl) || (searchSymbolControl.valid || addSymbolControl.valid)) { + return null; + } + + return { atLeastOneValid: true }; +}; \ No newline at end of file diff --git a/apps/client/src/app/components/admin-market-data/create-asset-profile-dialog/create-asset-profile-dialog.html b/apps/client/src/app/components/admin-market-data/create-asset-profile-dialog/create-asset-profile-dialog.html index 43eadf93e..9f36e7825 100644 --- a/apps/client/src/app/components/admin-market-data/create-asset-profile-dialog/create-asset-profile-dialog.html +++ b/apps/client/src/app/components/admin-market-data/create-asset-profile-dialog/create-asset-profile-dialog.html @@ -6,13 +6,29 @@ >

Add Asset Profile

- - Name, symbol or ISIN - - +
+ +
+
+
+
+ +
+ + Name, symbol or ISIN + + +
+
+ + Symbol + + +
+
@@ -20,7 +36,7 @@ color="primary" mat-flat-button type="submit" - [disabled]="!createAssetProfileForm.valid" + [disabled]="createAssetProfileForm.hasError('atLeastOneValid')" > Save diff --git a/apps/client/src/app/components/admin-market-data/create-asset-profile-dialog/create-asset-profile-dialog.module.ts b/apps/client/src/app/components/admin-market-data/create-asset-profile-dialog/create-asset-profile-dialog.module.ts index e99d8f788..f342137aa 100644 --- a/apps/client/src/app/components/admin-market-data/create-asset-profile-dialog/create-asset-profile-dialog.module.ts +++ b/apps/client/src/app/components/admin-market-data/create-asset-profile-dialog/create-asset-profile-dialog.module.ts @@ -3,7 +3,10 @@ import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core'; import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { MatButtonModule } from '@angular/material/button'; import { MatDialogModule } from '@angular/material/dialog'; +import { MatInputModule } from '@angular/material/input'; import { MatFormFieldModule } from '@angular/material/form-field'; +import { MatRadioModule } from '@angular/material/radio'; + import { GfSymbolAutocompleteModule } from '@ghostfolio/ui/symbol-autocomplete'; import { CreateAssetProfileDialog } from './create-asset-profile-dialog.component'; @@ -17,6 +20,8 @@ import { CreateAssetProfileDialog } from './create-asset-profile-dialog.componen MatDialogModule, MatButtonModule, MatFormFieldModule, + MatInputModule, + MatRadioModule, ReactiveFormsModule ], schemas: [CUSTOM_ELEMENTS_SCHEMA]