|
@ -2,9 +2,11 @@ import { |
|
|
ChangeDetectionStrategy, |
|
|
ChangeDetectionStrategy, |
|
|
ChangeDetectorRef, |
|
|
ChangeDetectorRef, |
|
|
Component, |
|
|
Component, |
|
|
|
|
|
ElementRef, |
|
|
Inject, |
|
|
Inject, |
|
|
OnDestroy, |
|
|
OnDestroy, |
|
|
OnInit |
|
|
OnInit, |
|
|
|
|
|
ViewChild |
|
|
} from '@angular/core'; |
|
|
} from '@angular/core'; |
|
|
import { FormBuilder, FormControl, Validators } from '@angular/forms'; |
|
|
import { FormBuilder, FormControl, Validators } from '@angular/forms'; |
|
|
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; |
|
|
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; |
|
@ -21,7 +23,8 @@ import { |
|
|
AssetClass, |
|
|
AssetClass, |
|
|
AssetSubClass, |
|
|
AssetSubClass, |
|
|
MarketData, |
|
|
MarketData, |
|
|
SymbolProfile |
|
|
SymbolProfile, |
|
|
|
|
|
Tag |
|
|
} from '@prisma/client'; |
|
|
} from '@prisma/client'; |
|
|
import { format } from 'date-fns'; |
|
|
import { format } from 'date-fns'; |
|
|
import { parse as csvToJson } from 'papaparse'; |
|
|
import { parse as csvToJson } from 'papaparse'; |
|
@ -29,6 +32,8 @@ import { Subject } from 'rxjs'; |
|
|
import { takeUntil } from 'rxjs/operators'; |
|
|
import { takeUntil } from 'rxjs/operators'; |
|
|
|
|
|
|
|
|
import { AssetProfileDialogParams } from './interfaces/interfaces'; |
|
|
import { AssetProfileDialogParams } from './interfaces/interfaces'; |
|
|
|
|
|
import { MatAutocompleteSelectedEvent } from '@angular/material/autocomplete'; |
|
|
|
|
|
import { COMMA, ENTER } from '@angular/cdk/keycodes'; |
|
|
|
|
|
|
|
|
@Component({ |
|
|
@Component({ |
|
|
host: { class: 'd-flex flex-column h-100' }, |
|
|
host: { class: 'd-flex flex-column h-100' }, |
|
@ -38,6 +43,8 @@ import { AssetProfileDialogParams } from './interfaces/interfaces'; |
|
|
styleUrls: ['./asset-profile-dialog.component.scss'] |
|
|
styleUrls: ['./asset-profile-dialog.component.scss'] |
|
|
}) |
|
|
}) |
|
|
export class AssetProfileDialog implements OnDestroy, OnInit { |
|
|
export class AssetProfileDialog implements OnDestroy, OnInit { |
|
|
|
|
|
@ViewChild('tagInput') tagInput: ElementRef<HTMLInputElement>; |
|
|
|
|
|
public separatorKeysCodes: number[] = [ENTER, COMMA]; |
|
|
public assetProfileClass: string; |
|
|
public assetProfileClass: string; |
|
|
public assetClasses = Object.keys(AssetClass).map((assetClass) => { |
|
|
public assetClasses = Object.keys(AssetClass).map((assetClass) => { |
|
|
return { id: assetClass, label: translate(assetClass) }; |
|
|
return { id: assetClass, label: translate(assetClass) }; |
|
@ -51,6 +58,7 @@ export class AssetProfileDialog implements OnDestroy, OnInit { |
|
|
assetSubClass: new FormControl<AssetSubClass>(undefined), |
|
|
assetSubClass: new FormControl<AssetSubClass>(undefined), |
|
|
comment: '', |
|
|
comment: '', |
|
|
name: ['', Validators.required], |
|
|
name: ['', Validators.required], |
|
|
|
|
|
tags: new FormControl<Tag[]>(undefined), |
|
|
scraperConfiguration: '', |
|
|
scraperConfiguration: '', |
|
|
symbolMapping: '' |
|
|
symbolMapping: '' |
|
|
}); |
|
|
}); |
|
@ -66,6 +74,8 @@ export class AssetProfileDialog implements OnDestroy, OnInit { |
|
|
[name: string]: { name: string; value: number }; |
|
|
[name: string]: { name: string; value: number }; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
public HoldingTags: { id: string; name: string }[]; |
|
|
|
|
|
|
|
|
private static readonly HISTORICAL_DATA_TEMPLATE = `date;marketPrice\n${format( |
|
|
private static readonly HISTORICAL_DATA_TEMPLATE = `date;marketPrice\n${format( |
|
|
new Date(), |
|
|
new Date(), |
|
|
DATE_FORMAT |
|
|
DATE_FORMAT |
|
@ -91,6 +101,18 @@ export class AssetProfileDialog implements OnDestroy, OnInit { |
|
|
this.historicalDataAsCsvString = |
|
|
this.historicalDataAsCsvString = |
|
|
AssetProfileDialog.HISTORICAL_DATA_TEMPLATE; |
|
|
AssetProfileDialog.HISTORICAL_DATA_TEMPLATE; |
|
|
|
|
|
|
|
|
|
|
|
this.adminService |
|
|
|
|
|
.fetchTags() |
|
|
|
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
|
|
|
.subscribe((tags) => { |
|
|
|
|
|
this.HoldingTags = tags.map(({ id, name }) => { |
|
|
|
|
|
return { id, name }; |
|
|
|
|
|
}); |
|
|
|
|
|
this.dataService.updateInfo(); |
|
|
|
|
|
|
|
|
|
|
|
this.changeDetectorRef.markForCheck(); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
this.adminService |
|
|
this.adminService |
|
|
.fetchAdminMarketDataBySymbol({ |
|
|
.fetchAdminMarketDataBySymbol({ |
|
|
dataSource: this.data.dataSource, |
|
|
dataSource: this.data.dataSource, |
|
@ -131,6 +153,7 @@ export class AssetProfileDialog implements OnDestroy, OnInit { |
|
|
assetClass: this.assetProfile.assetClass ?? null, |
|
|
assetClass: this.assetProfile.assetClass ?? null, |
|
|
assetSubClass: this.assetProfile.assetSubClass ?? null, |
|
|
assetSubClass: this.assetProfile.assetSubClass ?? null, |
|
|
comment: this.assetProfile?.comment ?? '', |
|
|
comment: this.assetProfile?.comment ?? '', |
|
|
|
|
|
tags: this.assetProfile?.tags, |
|
|
name: this.assetProfile.name ?? this.assetProfile.symbol, |
|
|
name: this.assetProfile.name ?? this.assetProfile.symbol, |
|
|
scraperConfiguration: JSON.stringify( |
|
|
scraperConfiguration: JSON.stringify( |
|
|
this.assetProfile?.scraperConfiguration ?? {} |
|
|
this.assetProfile?.scraperConfiguration ?? {} |
|
@ -225,6 +248,7 @@ export class AssetProfileDialog implements OnDestroy, OnInit { |
|
|
assetSubClass: this.assetProfileForm.controls['assetSubClass'].value, |
|
|
assetSubClass: this.assetProfileForm.controls['assetSubClass'].value, |
|
|
comment: this.assetProfileForm.controls['comment'].value ?? null, |
|
|
comment: this.assetProfileForm.controls['comment'].value ?? null, |
|
|
name: this.assetProfileForm.controls['name'].value, |
|
|
name: this.assetProfileForm.controls['name'].value, |
|
|
|
|
|
tags: this.assetProfileForm.controls['tags'].value, |
|
|
scraperConfiguration, |
|
|
scraperConfiguration, |
|
|
symbolMapping |
|
|
symbolMapping |
|
|
}; |
|
|
}; |
|
@ -253,6 +277,24 @@ export class AssetProfileDialog implements OnDestroy, OnInit { |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public onRemoveTag(aTag: Tag) { |
|
|
|
|
|
this.assetProfileForm.controls['tags'].setValue( |
|
|
|
|
|
this.assetProfileForm.controls['tags'].value.filter(({ id }) => { |
|
|
|
|
|
return id !== aTag.id; |
|
|
|
|
|
}) |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public onAddTag(event: MatAutocompleteSelectedEvent) { |
|
|
|
|
|
this.assetProfileForm.controls['tags'].setValue([ |
|
|
|
|
|
...(this.assetProfileForm.controls['tags'].value ?? []), |
|
|
|
|
|
this.HoldingTags.find(({ id }) => { |
|
|
|
|
|
return id === event.option.value; |
|
|
|
|
|
}) |
|
|
|
|
|
]); |
|
|
|
|
|
this.tagInput.nativeElement.value = ''; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public ngOnDestroy() { |
|
|
public ngOnDestroy() { |
|
|
this.unsubscribeSubject.next(); |
|
|
this.unsubscribeSubject.next(); |
|
|
this.unsubscribeSubject.complete(); |
|
|
this.unsubscribeSubject.complete(); |
|
|