Browse Source

Provided support for adding Manual asset

https://github.com/ghostfolio/ghostfolio/issues/2283

-Added Radio button and Input
pull/2479/head
Manushreshta B L 2 years ago
parent
commit
88f9d0b45e
  1. 5
      apps/api/src/app/admin/admin.service.ts
  2. 48
      apps/client/src/app/components/admin-market-data/create-asset-profile-dialog/create-asset-profile-dialog.component.ts
  3. 32
      apps/client/src/app/components/admin-market-data/create-asset-profile-dialog/create-asset-profile-dialog.html
  4. 5
      apps/client/src/app/components/admin-market-data/create-asset-profile-dialog/create-asset-profile-dialog.module.ts

5
apps/api/src/app/admin/admin.service.ts

@ -45,6 +45,11 @@ export class AdminService {
symbol symbol
}: UniqueAsset): Promise<SymbolProfile | never> { }: UniqueAsset): Promise<SymbolProfile | never> {
try { try {
if(dataSource==="MANUAL")
return await this.symbolProfileService.add(
{symbol, currency:DEFAULT_CURRENCY, dataSource:"MANUAL"}
);
const assetProfiles = await this.dataProviderService.getAssetProfiles([ const assetProfiles = await this.dataProviderService.getAssetProfiles([
{ dataSource, symbol } { dataSource, symbol }
]); ]);

48
apps/client/src/app/components/admin-market-data/create-asset-profile-dialog/create-asset-profile-dialog.component.ts

@ -7,9 +7,11 @@ import {
OnInit OnInit
} from '@angular/core'; } from '@angular/core';
import { import {
AbstractControl,
FormBuilder, FormBuilder,
FormControl, FormControl,
FormGroup, FormGroup,
ValidationErrors,
Validators Validators
} from '@angular/forms'; } from '@angular/forms';
import { MatDialogRef } from '@angular/material/dialog'; import { MatDialogRef } from '@angular/material/dialog';
@ -23,31 +25,67 @@ import { AdminService } from '@ghostfolio/client/services/admin.service';
}) })
export class CreateAssetProfileDialog implements OnInit, OnDestroy { export class CreateAssetProfileDialog implements OnInit, OnDestroy {
public createAssetProfileForm: FormGroup; public createAssetProfileForm: FormGroup;
public selectedOption: string;
public constructor( public constructor(
public readonly adminService: AdminService, public readonly adminService: AdminService,
public readonly changeDetectorRef: ChangeDetectorRef, public readonly changeDetectorRef: ChangeDetectorRef,
public readonly dialogRef: MatDialogRef<CreateAssetProfileDialog>, public readonly dialogRef: MatDialogRef<CreateAssetProfileDialog>,
public readonly formBuilder: FormBuilder public readonly formBuilder: FormBuilder,
) {} ) {}
public ngOnInit() {
public ngOnInit() {
this.createAssetProfileForm = this.formBuilder.group({ 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() { public onCancel() {
this.dialogRef.close(); this.dialogRef.close();
} }
public onRadioChange(option: string) {
this.selectedOption = option;
}
public onSubmit() { public onSubmit() {
console.log(this.createAssetProfileForm.controls['addSymbol'].value)
this.selectedOption==='auto'?
this.dialogRef.close({ this.dialogRef.close({
dataSource: dataSource:
this.createAssetProfileForm.controls['searchSymbol'].value.dataSource, this.createAssetProfileForm.controls['searchSymbol'].value.dataSource,
symbol: this.createAssetProfileForm.controls['searchSymbol'].value.symbol symbol: this.createAssetProfileForm.controls['searchSymbol'].value.symbol
}); })
:
this.dialogRef.close({
dataSource:"MANUAL",
symbol: this.createAssetProfileForm.controls['addSymbol'].value
})
} }
public ngOnDestroy() {} 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 };
};

32
apps/client/src/app/components/admin-market-data/create-asset-profile-dialog/create-asset-profile-dialog.html

@ -6,13 +6,29 @@
> >
<h1 i18n mat-dialog-title>Add Asset Profile</h1> <h1 i18n mat-dialog-title>Add Asset Profile</h1>
<div class="flex-grow-1 py-3" mat-dialog-content> <div class="flex-grow-1 py-3" mat-dialog-content>
<mat-form-field appearance="outline" class="w-100"> <div class="my-2">
<mat-label i18n>Name, symbol or ISIN</mat-label> <mat-radio-group [(ngModel)]="selectedOption" name="radioOptions">
<gf-symbol-autocomplete <div class="flex"><mat-radio-button [checked]="selectedOption==='auto'" value="auto" (click)="onRadioChange('auto')" name="auto"></mat-radio-button><label for="auto">Search</label></div>
formControlName="searchSymbol" <div class="flex"><mat-radio-button value="manual" (click)="onRadioChange('manual')" name="manual"></mat-radio-button><label for="auto">Add Manually</label></div>
[includeIndices]="true" </mat-radio-group>
/> </div>
</mat-form-field>
<div *ngIf="selectedOption === 'auto'">
<mat-form-field appearance="outline" class="w-100">
<mat-label i18n>Name, symbol or ISIN</mat-label>
<gf-symbol-autocomplete
formControlName="searchSymbol"
[includeIndices]="true"
/>
</mat-form-field>
</div>
<div *ngIf="selectedOption === 'manual'">
<mat-form-field appearance="outline" class="w-100">
<mat-label>Symbol</mat-label>
<input matInput formControlName="addSymbol" placeholder="Enter symbol"/>
</mat-form-field>
</div>
</div> </div>
<div class="d-flex justify-content-end" mat-dialog-actions> <div class="d-flex justify-content-end" mat-dialog-actions>
<button i18n mat-button type="button" (click)="onCancel()">Cancel</button> <button i18n mat-button type="button" (click)="onCancel()">Cancel</button>
@ -20,7 +36,7 @@
color="primary" color="primary"
mat-flat-button mat-flat-button
type="submit" type="submit"
[disabled]="!createAssetProfileForm.valid" [disabled]="createAssetProfileForm.hasError('atLeastOneValid')"
> >
<ng-container i18n>Save</ng-container> <ng-container i18n>Save</ng-container>
</button> </button>

5
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 { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { MatButtonModule } from '@angular/material/button'; import { MatButtonModule } from '@angular/material/button';
import { MatDialogModule } from '@angular/material/dialog'; import { MatDialogModule } from '@angular/material/dialog';
import { MatInputModule } from '@angular/material/input';
import { MatFormFieldModule } from '@angular/material/form-field'; import { MatFormFieldModule } from '@angular/material/form-field';
import { MatRadioModule } from '@angular/material/radio';
import { GfSymbolAutocompleteModule } from '@ghostfolio/ui/symbol-autocomplete'; import { GfSymbolAutocompleteModule } from '@ghostfolio/ui/symbol-autocomplete';
import { CreateAssetProfileDialog } from './create-asset-profile-dialog.component'; import { CreateAssetProfileDialog } from './create-asset-profile-dialog.component';
@ -17,6 +20,8 @@ import { CreateAssetProfileDialog } from './create-asset-profile-dialog.componen
MatDialogModule, MatDialogModule,
MatButtonModule, MatButtonModule,
MatFormFieldModule, MatFormFieldModule,
MatInputModule,
MatRadioModule,
ReactiveFormsModule ReactiveFormsModule
], ],
schemas: [CUSTOM_ELEMENTS_SCHEMA] schemas: [CUSTOM_ELEMENTS_SCHEMA]

Loading…
Cancel
Save