Browse Source

Merge branch 'main' into feature/support-enter-to-submit-create-or-update-transaction-dialog-form

pull/913/head
Thomas Kaul 3 years ago
committed by GitHub
parent
commit
950d15bda6
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      CHANGELOG.md
  2. 48
      apps/client/src/app/adapter/custom-date-adapter.ts
  3. 2
      apps/client/src/app/components/accounts-table/accounts-table.component.html
  4. 17
      apps/client/src/app/components/admin-market-data-detail/admin-market-data-detail.component.ts
  5. 2
      apps/client/src/app/components/admin-market-data-detail/market-data-detail-dialog/interfaces/interfaces.ts
  6. 10
      apps/client/src/app/components/admin-market-data-detail/market-data-detail-dialog/market-data-detail-dialog.component.ts
  7. 8
      apps/client/src/app/pages/portfolio/transactions/create-or-update-transaction-dialog/create-or-update-transaction-dialog.component.ts
  8. 12
      libs/ui/src/lib/activities-filter/activities-filter.component.ts

6
CHANGELOG.md

@ -11,6 +11,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Supported enter key press to submit the form of the create or edit transaction dialog - Supported enter key press to submit the form of the create or edit transaction dialog
### 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 an issue in the activities filter component (typing a search term)
## 1.147.0 - 10.05.2022 ## 1.147.0 - 10.05.2022
### Changed ### Changed

48
apps/client/src/app/adapter/custom-date-adapter.ts

@ -1,14 +1,15 @@
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
) { ) {
@ -16,50 +17,23 @@ export class CustomDateAdapter extends NativeDateAdapter {
} }
/** /**
* Sets the first day of the week to Monday * Formats a date as a string
*/ */
public getFirstDayOfWeek(): number { public format(aDate: Date, aParseFormat: string): string {
return 1; return format(aDate, getDateFormatString(this.locale));
} }
/** /**
* Formats a date as a string according to the given format * Sets the first day of the week to Monday
*/ */
public format(aDate: Date, aParseFormat: string): string { public getFirstDayOfWeek(): number {
return format(aDate, aParseFormat, { return 1;
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;
}
} }
} }

2
apps/client/src/app/components/accounts-table/accounts-table.component.html

@ -200,7 +200,7 @@
</button> </button>
<button <button
mat-menu-item mat-menu-item
[disabled]="element.isDefault || element.Order?.length > 0" [disabled]="element.isDefault || element.transactionCount > 0"
(click)="onDeleteAccount(element.id)" (click)="onDeleteAccount(element.id)"
> >
<ion-icon class="mr-2" name="trash-outline"></ion-icon> <ion-icon class="mr-2" name="trash-outline"></ion-icon>

17
apps/client/src/app/components/admin-market-data-detail/admin-market-data-detail.component.ts

@ -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'

2
apps/client/src/app/components/admin-market-data-detail/market-data-detail-dialog/interfaces/interfaces.ts

@ -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;
} }

10
apps/client/src/app/components/admin-market-data-detail/market-data-detail-dialog/market-data-detail-dialog.component.ts

@ -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
apps/client/src/app/pages/portfolio/transactions/create-or-update-transaction-dialog/create-or-update-transaction-dialog.component.ts

@ -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;

12
libs/ui/src/lib/activities-filter/activities-filter.component.ts

@ -48,8 +48,8 @@ export class ActivitiesFilterComponent implements OnChanges, OnDestroy {
public constructor() { public constructor() {
this.searchControl.valueChanges this.searchControl.valueChanges
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntil(this.unsubscribeSubject))
.subscribe((currentFilter: Filter) => { .subscribe((filterOrSearchTerm: Filter | string) => {
if (currentFilter) { if (filterOrSearchTerm) {
this.filters$.next( this.filters$.next(
this.allFilters this.allFilters
.filter((filter) => { .filter((filter) => {
@ -59,9 +59,15 @@ export class ActivitiesFilterComponent implements OnChanges, OnDestroy {
}); });
}) })
.filter((filter) => { .filter((filter) => {
if (typeof filterOrSearchTerm === 'string') {
return filter.label
.toLowerCase()
.startsWith(filterOrSearchTerm.toLowerCase());
}
return filter.label return filter.label
.toLowerCase() .toLowerCase()
.startsWith(currentFilter.label.toLowerCase()); .startsWith(filterOrSearchTerm?.label?.toLowerCase());
}) })
.sort((a, b) => a.label.localeCompare(b.label)) .sort((a, b) => a.label.localeCompare(b.label))
); );

Loading…
Cancel
Save