Bugfix/fix date picker date format (#912)
* Fix date picker date format * Update changelog
This commit is contained in:
parent
1a4dc51825
commit
d5c96d1cb7
@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
- Fixed the date format of the date picker and support manual changes
|
||||||
- Fixed the state of the account delete button (disable if account contains activities)
|
- Fixed the state of the account delete button (disable if account contains activities)
|
||||||
- Fixed an issue in the activities filter component (typing a search term)
|
- Fixed an issue in the activities filter component (typing a search term)
|
||||||
|
|
||||||
|
@ -1,20 +1,28 @@
|
|||||||
import { Platform } from '@angular/cdk/platform';
|
import { Platform } from '@angular/cdk/platform';
|
||||||
import { Inject, forwardRef } from '@angular/core';
|
import { Inject, forwardRef } from '@angular/core';
|
||||||
import { MAT_DATE_LOCALE, NativeDateAdapter } from '@angular/material/core';
|
import { MAT_DATE_LOCALE, NativeDateAdapter } from '@angular/material/core';
|
||||||
import { format, isValid } from 'date-fns';
|
import { getDateFormatString } from '@ghostfolio/common/helper';
|
||||||
import * as deDateFnsLocale from 'date-fns/locale/de/index';
|
import { format, parse } from 'date-fns';
|
||||||
|
|
||||||
export class CustomDateAdapter extends NativeDateAdapter {
|
export class CustomDateAdapter extends NativeDateAdapter {
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
public constructor(
|
public constructor(
|
||||||
|
@Inject(MAT_DATE_LOCALE) public locale: string,
|
||||||
@Inject(forwardRef(() => MAT_DATE_LOCALE)) matDateLocale: string,
|
@Inject(forwardRef(() => MAT_DATE_LOCALE)) matDateLocale: string,
|
||||||
platform: Platform
|
platform: Platform
|
||||||
) {
|
) {
|
||||||
super(matDateLocale, platform);
|
super(matDateLocale, platform);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Formats a date as a string
|
||||||
|
*/
|
||||||
|
public format(aDate: Date, aParseFormat: string): string {
|
||||||
|
return format(aDate, getDateFormatString(this.locale));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the first day of the week to Monday
|
* Sets the first day of the week to Monday
|
||||||
*/
|
*/
|
||||||
@ -22,44 +30,10 @@ export class CustomDateAdapter extends NativeDateAdapter {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Formats a date as a string according to the given format
|
|
||||||
*/
|
|
||||||
public format(aDate: Date, aParseFormat: string): string {
|
|
||||||
return format(aDate, aParseFormat, {
|
|
||||||
locale: <any>deDateFnsLocale
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses a date from a provided value
|
* Parses a date from a provided value
|
||||||
*/
|
*/
|
||||||
public parse(aValue: any): Date {
|
public parse(aValue: string): Date {
|
||||||
let date: Date;
|
return parse(aValue, getDateFormatString(this.locale), new Date());
|
||||||
|
|
||||||
try {
|
|
||||||
// TODO
|
|
||||||
// Native date parser from the following formats:
|
|
||||||
// - 'd.M.yyyy'
|
|
||||||
// - 'dd.MM.yyyy'
|
|
||||||
// https://github.com/you-dont-need/You-Dont-Need-Momentjs#string--date-format
|
|
||||||
const datePattern = /^(\d{1,2}).(\d{1,2}).(\d{4})$/;
|
|
||||||
const [, day, month, year] = datePattern.exec(aValue);
|
|
||||||
|
|
||||||
date = new Date(
|
|
||||||
parseInt(year, 10),
|
|
||||||
parseInt(month, 10) - 1, // monthIndex
|
|
||||||
parseInt(day, 10)
|
|
||||||
);
|
|
||||||
} catch (error) {
|
|
||||||
} finally {
|
|
||||||
const isDateValid = date && isValid(date);
|
|
||||||
|
|
||||||
if (isDateValid) {
|
|
||||||
return date;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,11 +8,13 @@ import {
|
|||||||
Output
|
Output
|
||||||
} from '@angular/core';
|
} from '@angular/core';
|
||||||
import { MatDialog } from '@angular/material/dialog';
|
import { MatDialog } from '@angular/material/dialog';
|
||||||
|
import { UserService } from '@ghostfolio/client/services/user/user.service';
|
||||||
import {
|
import {
|
||||||
DATE_FORMAT,
|
DATE_FORMAT,
|
||||||
getDateFormatString,
|
getDateFormatString,
|
||||||
getLocale
|
getLocale
|
||||||
} from '@ghostfolio/common/helper';
|
} from '@ghostfolio/common/helper';
|
||||||
|
import { User } from '@ghostfolio/common/interfaces';
|
||||||
import { LineChartItem } from '@ghostfolio/ui/line-chart/interfaces/line-chart.interface';
|
import { LineChartItem } from '@ghostfolio/ui/line-chart/interfaces/line-chart.interface';
|
||||||
import { DataSource, MarketData } from '@prisma/client';
|
import { DataSource, MarketData } from '@prisma/client';
|
||||||
import {
|
import {
|
||||||
@ -53,14 +55,24 @@ export class AdminMarketDataDetailComponent implements OnChanges, OnInit {
|
|||||||
[day: string]: Pick<MarketData, 'date' | 'marketPrice'> & { day: number };
|
[day: string]: Pick<MarketData, 'date' | 'marketPrice'> & { day: number };
|
||||||
};
|
};
|
||||||
} = {};
|
} = {};
|
||||||
|
public user: User;
|
||||||
|
|
||||||
private unsubscribeSubject = new Subject<void>();
|
private unsubscribeSubject = new Subject<void>();
|
||||||
|
|
||||||
public constructor(
|
public constructor(
|
||||||
private deviceService: DeviceDetectorService,
|
private deviceService: DeviceDetectorService,
|
||||||
private dialog: MatDialog
|
private dialog: MatDialog,
|
||||||
|
private userService: UserService
|
||||||
) {
|
) {
|
||||||
this.deviceType = this.deviceService.getDeviceInfo().deviceType;
|
this.deviceType = this.deviceService.getDeviceInfo().deviceType;
|
||||||
|
|
||||||
|
this.userService.stateChanged
|
||||||
|
.pipe(takeUntil(this.unsubscribeSubject))
|
||||||
|
.subscribe((state) => {
|
||||||
|
if (state?.user) {
|
||||||
|
this.user = state.user;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public ngOnInit() {}
|
public ngOnInit() {}
|
||||||
@ -145,7 +157,8 @@ export class AdminMarketDataDetailComponent implements OnChanges, OnInit {
|
|||||||
date,
|
date,
|
||||||
marketPrice,
|
marketPrice,
|
||||||
dataSource: this.dataSource,
|
dataSource: this.dataSource,
|
||||||
symbol: this.symbol
|
symbol: this.symbol,
|
||||||
|
user: this.user
|
||||||
},
|
},
|
||||||
height: this.deviceType === 'mobile' ? '97.5vh' : '80vh',
|
height: this.deviceType === 'mobile' ? '97.5vh' : '80vh',
|
||||||
width: this.deviceType === 'mobile' ? '100vw' : '50rem'
|
width: this.deviceType === 'mobile' ? '100vw' : '50rem'
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { User } from '@ghostfolio/common/interfaces';
|
||||||
import { DataSource } from '@prisma/client';
|
import { DataSource } from '@prisma/client';
|
||||||
|
|
||||||
export interface MarketDataDetailDialogParams {
|
export interface MarketDataDetailDialogParams {
|
||||||
@ -5,4 +6,5 @@ export interface MarketDataDetailDialogParams {
|
|||||||
date: Date;
|
date: Date;
|
||||||
marketPrice: number;
|
marketPrice: number;
|
||||||
symbol: string;
|
symbol: string;
|
||||||
|
user: User;
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import {
|
|||||||
Inject,
|
Inject,
|
||||||
OnDestroy
|
OnDestroy
|
||||||
} from '@angular/core';
|
} from '@angular/core';
|
||||||
|
import { DateAdapter, MAT_DATE_LOCALE } from '@angular/material/core';
|
||||||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
||||||
import { AdminService } from '@ghostfolio/client/services/admin.service';
|
import { AdminService } from '@ghostfolio/client/services/admin.service';
|
||||||
import { Subject, takeUntil } from 'rxjs';
|
import { Subject, takeUntil } from 'rxjs';
|
||||||
@ -24,11 +25,16 @@ export class MarketDataDetailDialog implements OnDestroy {
|
|||||||
public constructor(
|
public constructor(
|
||||||
private adminService: AdminService,
|
private adminService: AdminService,
|
||||||
private changeDetectorRef: ChangeDetectorRef,
|
private changeDetectorRef: ChangeDetectorRef,
|
||||||
|
@Inject(MAT_DIALOG_DATA) public data: MarketDataDetailDialogParams,
|
||||||
|
private dateAdapter: DateAdapter<any>,
|
||||||
public dialogRef: MatDialogRef<MarketDataDetailDialog>,
|
public dialogRef: MatDialogRef<MarketDataDetailDialog>,
|
||||||
@Inject(MAT_DIALOG_DATA) public data: MarketDataDetailDialogParams
|
@Inject(MAT_DATE_LOCALE) private locale: string
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public ngOnInit() {}
|
public ngOnInit() {
|
||||||
|
this.locale = this.data.user?.settings?.locale;
|
||||||
|
this.dateAdapter.setLocale(this.locale);
|
||||||
|
}
|
||||||
|
|
||||||
public onCancel(): void {
|
public onCancel(): void {
|
||||||
this.dialogRef.close({ withRefresh: false });
|
this.dialogRef.close({ withRefresh: false });
|
||||||
|
@ -8,6 +8,7 @@ import {
|
|||||||
} from '@angular/core';
|
} from '@angular/core';
|
||||||
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||||
import { MatAutocompleteSelectedEvent } from '@angular/material/autocomplete';
|
import { MatAutocompleteSelectedEvent } from '@angular/material/autocomplete';
|
||||||
|
import { DateAdapter, MAT_DATE_LOCALE } from '@angular/material/core';
|
||||||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
||||||
import { CreateOrderDto } from '@ghostfolio/api/app/order/create-order.dto';
|
import { CreateOrderDto } from '@ghostfolio/api/app/order/create-order.dto';
|
||||||
import { UpdateOrderDto } from '@ghostfolio/api/app/order/update-order.dto';
|
import { UpdateOrderDto } from '@ghostfolio/api/app/order/update-order.dto';
|
||||||
@ -54,13 +55,18 @@ export class CreateOrUpdateTransactionDialog implements OnDestroy {
|
|||||||
|
|
||||||
public constructor(
|
public constructor(
|
||||||
private changeDetectorRef: ChangeDetectorRef,
|
private changeDetectorRef: ChangeDetectorRef,
|
||||||
|
@Inject(MAT_DIALOG_DATA) public data: CreateOrUpdateTransactionDialogParams,
|
||||||
private dataService: DataService,
|
private dataService: DataService,
|
||||||
|
private dateAdapter: DateAdapter<any>,
|
||||||
public dialogRef: MatDialogRef<CreateOrUpdateTransactionDialog>,
|
public dialogRef: MatDialogRef<CreateOrUpdateTransactionDialog>,
|
||||||
private formBuilder: FormBuilder,
|
private formBuilder: FormBuilder,
|
||||||
@Inject(MAT_DIALOG_DATA) public data: CreateOrUpdateTransactionDialogParams
|
@Inject(MAT_DATE_LOCALE) private locale: string
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public ngOnInit() {
|
public ngOnInit() {
|
||||||
|
this.locale = this.data.user?.settings?.locale;
|
||||||
|
this.dateAdapter.setLocale(this.locale);
|
||||||
|
|
||||||
const { currencies, platforms } = this.dataService.fetchInfo();
|
const { currencies, platforms } = this.dataService.fetchInfo();
|
||||||
|
|
||||||
this.currencies = currencies;
|
this.currencies = currencies;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user