Browse Source

feat(lib): resolve ts errors

pull/6337/head
KenTandrian 2 months ago
parent
commit
2f8e22fd41
  1. 18
      libs/ui/src/lib/historical-market-data-editor/historical-market-data-editor-dialog/historical-market-data-editor-dialog.component.ts
  2. 2
      libs/ui/src/lib/historical-market-data-editor/historical-market-data-editor-dialog/interfaces/interfaces.ts
  3. 8
      libs/ui/src/lib/historical-market-data-editor/historical-market-data-editor.component.html
  4. 58
      libs/ui/src/lib/historical-market-data-editor/historical-market-data-editor.component.ts

18
libs/ui/src/lib/historical-market-data-editor/historical-market-data-editor-dialog/historical-market-data-editor-dialog.component.ts

@ -5,7 +5,7 @@ import {
ChangeDetectorRef, ChangeDetectorRef,
Component, Component,
CUSTOM_ELEMENTS_SCHEMA, CUSTOM_ELEMENTS_SCHEMA,
Inject, inject,
OnDestroy, OnDestroy,
OnInit OnInit
} from '@angular/core'; } from '@angular/core';
@ -48,23 +48,23 @@ import { HistoricalMarketDataEditorDialogParams } from './interfaces/interfaces'
export class GfHistoricalMarketDataEditorDialogComponent export class GfHistoricalMarketDataEditorDialogComponent
implements OnDestroy, OnInit implements OnDestroy, OnInit
{ {
public data = inject<HistoricalMarketDataEditorDialogParams>(MAT_DIALOG_DATA);
private locale = inject<string>(MAT_DATE_LOCALE);
private unsubscribeSubject = new Subject<void>(); private unsubscribeSubject = new Subject<void>();
public constructor( public constructor(
private adminService: AdminService, private adminService: AdminService,
private changeDetectorRef: ChangeDetectorRef, private changeDetectorRef: ChangeDetectorRef,
@Inject(MAT_DIALOG_DATA)
public data: HistoricalMarketDataEditorDialogParams,
private dataService: DataService, private dataService: DataService,
private dateAdapter: DateAdapter<any>, private dateAdapter: DateAdapter<Date, string>,
public dialogRef: MatDialogRef<GfHistoricalMarketDataEditorDialogComponent>, public dialogRef: MatDialogRef<GfHistoricalMarketDataEditorDialogComponent>
@Inject(MAT_DATE_LOCALE) private locale: string
) { ) {
addIcons({ calendarClearOutline, refreshOutline }); addIcons({ calendarClearOutline, refreshOutline });
} }
public ngOnInit() { public ngOnInit() {
this.locale = this.data.user?.settings?.locale; this.locale = this.data.user.settings.locale ?? this.locale;
this.dateAdapter.setLocale(this.locale); this.dateAdapter.setLocale(this.locale);
} }
@ -88,6 +88,10 @@ export class GfHistoricalMarketDataEditorDialogComponent
} }
public onUpdate() { public onUpdate() {
if (this.data.marketPrice === undefined) {
return;
}
this.dataService this.dataService
.postMarketData({ .postMarketData({
dataSource: this.data.dataSource, dataSource: this.data.dataSource,

2
libs/ui/src/lib/historical-market-data-editor/historical-market-data-editor-dialog/interfaces/interfaces.ts

@ -6,7 +6,7 @@ export interface HistoricalMarketDataEditorDialogParams {
currency: string; currency: string;
dataSource: DataSource; dataSource: DataSource;
dateString: string; dateString: string;
marketPrice: number; marketPrice?: number;
symbol: string; symbol: string;
user: User; user: User;
} }

8
libs/ui/src/lib/historical-market-data-editor/historical-market-data-editor.component.html

@ -24,7 +24,7 @@
" "
(click)=" (click)="
onOpenMarketDataDetail({ onOpenMarketDataDetail({
day: i + 1 < 10 ? `0${i + 1}` : i + 1, day: i + 1 < 10 ? `0${i + 1}` : (i + 1).toString(),
yearMonth: itemByMonth.key yearMonth: itemByMonth.key
}) })
" "
@ -61,10 +61,10 @@
mat-flat-button mat-flat-button
type="button" type="button"
[disabled]=" [disabled]="
!historicalDataForm.controls['historicalData']?.controls['csvString'] !historicalDataForm.controls.historicalData.controls.csvString
.touched || .touched ||
historicalDataForm.controls['historicalData']?.controls['csvString'] historicalDataForm.controls.historicalData.controls.csvString
?.value === '' .value === ''
" "
(click)="onImportHistoricalData()" (click)="onImportHistoricalData()"
> >

58
libs/ui/src/lib/historical-market-data-editor/historical-market-data-editor.component.ts

@ -8,6 +8,7 @@ import { LineChartItem, User } from '@ghostfolio/common/interfaces';
import { DataService } from '@ghostfolio/ui/services'; import { DataService } from '@ghostfolio/ui/services';
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import type { HttpErrorResponse } from '@angular/common/http';
import { import {
ChangeDetectionStrategy, ChangeDetectionStrategy,
Component, Component,
@ -56,6 +57,11 @@ import { HistoricalMarketDataEditorDialogParams } from './historical-market-data
export class GfHistoricalMarketDataEditorComponent export class GfHistoricalMarketDataEditorComponent
implements OnChanges, OnDestroy, OnInit implements OnChanges, OnDestroy, OnInit
{ {
private static readonly HISTORICAL_DATA_TEMPLATE = `date;marketPrice\n${format(
new Date(),
DATE_FORMAT
)};123.45`;
@Input() currency: string; @Input() currency: string;
@Input() dataSource: DataSource; @Input() dataSource: DataSource;
@Input() dateOfFirstActivity: string; @Input() dateOfFirstActivity: string;
@ -77,15 +83,14 @@ export class GfHistoricalMarketDataEditorComponent
public historicalDataItems: LineChartItem[]; public historicalDataItems: LineChartItem[];
public marketDataByMonth: { public marketDataByMonth: {
[yearMonth: string]: { [yearMonth: string]: {
[day: string]: Pick<MarketData, 'date' | 'marketPrice'> & { day: number }; [day: string]: {
date: Date;
day: number;
marketPrice?: number;
};
}; };
} = {}; } = {};
private static readonly HISTORICAL_DATA_TEMPLATE = `date;marketPrice\n${format(
new Date(),
DATE_FORMAT
)};123.45`;
private unsubscribeSubject = new Subject<void>(); private unsubscribeSubject = new Subject<void>();
public constructor( public constructor(
@ -115,7 +120,7 @@ export class GfHistoricalMarketDataEditorComponent
if (this.dateOfFirstActivity) { if (this.dateOfFirstActivity) {
let date = parseISO(this.dateOfFirstActivity); let date = parseISO(this.dateOfFirstActivity);
const missingMarketData: Partial<MarketData>[] = []; const missingMarketData: { date: Date; marketPrice?: number }[] = [];
if (this.historicalDataItems?.[0]?.date) { if (this.historicalDataItems?.[0]?.date) {
while ( while (
@ -135,7 +140,8 @@ export class GfHistoricalMarketDataEditorComponent
const marketDataItems = [...missingMarketData, ...this.marketData]; const marketDataItems = [...missingMarketData, ...this.marketData];
if (!isToday(last(marketDataItems)?.date)) { const lastDate = last(marketDataItems)?.date;
if (!lastDate || !isToday(lastDate)) {
marketDataItems.push({ date: new Date() }); marketDataItems.push({ date: new Date() });
} }
@ -160,21 +166,26 @@ export class GfHistoricalMarketDataEditorComponent
// Fill up missing months // Fill up missing months
const dates = Object.keys(this.marketDataByMonth).sort(); const dates = Object.keys(this.marketDataByMonth).sort();
const startDateString = first(dates);
const startDate = min([ const startDate = min([
parseISO(this.dateOfFirstActivity), parseISO(this.dateOfFirstActivity),
parseISO(first(dates)) ...(startDateString ? [parseISO(startDateString)] : [])
]); ]);
const endDate = parseISO(last(dates)); const endDateString = last(dates);
let currentDate = startDate; if (endDateString) {
const endDate = parseISO(endDateString);
while (isBefore(currentDate, endDate)) { let currentDate = startDate;
const key = format(currentDate, 'yyyy-MM');
if (!this.marketDataByMonth[key]) {
this.marketDataByMonth[key] = {};
}
currentDate = addMonths(currentDate, 1); while (isBefore(currentDate, endDate)) {
const key = format(currentDate, 'yyyy-MM');
if (!this.marketDataByMonth[key]) {
this.marketDataByMonth[key] = {};
}
currentDate = addMonths(currentDate, 1);
}
} }
} }
} }
@ -201,7 +212,8 @@ export class GfHistoricalMarketDataEditorComponent
const dialogRef = this.dialog.open< const dialogRef = this.dialog.open<
GfHistoricalMarketDataEditorDialogComponent, GfHistoricalMarketDataEditorDialogComponent,
HistoricalMarketDataEditorDialogParams HistoricalMarketDataEditorDialogParams,
{ withRefresh: boolean }
>(GfHistoricalMarketDataEditorDialogComponent, { >(GfHistoricalMarketDataEditorDialogComponent, {
data: { data: {
marketPrice, marketPrice,
@ -225,15 +237,15 @@ export class GfHistoricalMarketDataEditorComponent
public onImportHistoricalData() { public onImportHistoricalData() {
try { try {
const marketData = csvToJson( const marketData = csvToJson<UpdateMarketDataDto>(
this.historicalDataForm.controls['historicalData'].controls['csvString'] this.historicalDataForm.controls.historicalData.controls.csvString
.value, .value ?? '',
{ {
dynamicTyping: true, dynamicTyping: true,
header: true, header: true,
skipEmptyLines: true skipEmptyLines: true
} }
).data as UpdateMarketDataDto[]; ).data;
this.dataService this.dataService
.postMarketData({ .postMarketData({
@ -244,7 +256,7 @@ export class GfHistoricalMarketDataEditorComponent
symbol: this.symbol symbol: this.symbol
}) })
.pipe( .pipe(
catchError(({ error, message }) => { catchError(({ error, message }: HttpErrorResponse) => {
this.snackBar.open(`${error}: ${message[0]}`, undefined, { this.snackBar.open(`${error}: ${message[0]}`, undefined, {
duration: ms('3 seconds') duration: ms('3 seconds')
}); });

Loading…
Cancel
Save