Browse Source

Refactoring

pull/4080/head
Thomas Kaul 9 months ago
parent
commit
6f03a52b55
  1. 2
      apps/client/src/app/components/admin-market-data/admin-market-data.component.ts
  2. 14
      apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.component.ts
  3. 1
      apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.html
  4. 2
      apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.module.ts
  5. 0
      apps/client/src/app/components/admin-market-data/asset-profile-dialog/interfaces/interfaces.ts
  6. 2
      libs/ui/src/lib/market-data-detail/market-data-detail-dialog/market-data-detail-dialog.component.ts
  7. 23
      libs/ui/src/lib/market-data-detail/market-data-detail.component.ts

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

@ -39,9 +39,9 @@ import { distinctUntilChanged, switchMap, takeUntil } from 'rxjs/operators';
import { AdminMarketDataService } from './admin-market-data.service'; import { AdminMarketDataService } from './admin-market-data.service';
import { AssetProfileDialog } from './asset-profile-dialog/asset-profile-dialog.component'; import { AssetProfileDialog } from './asset-profile-dialog/asset-profile-dialog.component';
import { AssetProfileDialogParams } from './asset-profile-dialog/interfaces/interfaces';
import { CreateAssetProfileDialog } from './create-asset-profile-dialog/create-asset-profile-dialog.component'; import { CreateAssetProfileDialog } from './create-asset-profile-dialog/create-asset-profile-dialog.component';
import { CreateAssetProfileDialogParams } from './create-asset-profile-dialog/interfaces/interfaces'; import { CreateAssetProfileDialogParams } from './create-asset-profile-dialog/interfaces/interfaces';
import { AssetProfileDialogParams } from './interfaces/interfaces';
@Component({ @Component({
changeDetection: ChangeDetectionStrategy.OnPush, changeDetection: ChangeDetectionStrategy.OnPush,

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

@ -10,8 +10,8 @@ import { DATE_FORMAT } from '@ghostfolio/common/helper';
import { import {
AdminMarketDataDetails, AdminMarketDataDetails,
AssetProfileIdentifier, AssetProfileIdentifier,
User, LineChartItem,
LineChartItem User
} from '@ghostfolio/common/interfaces'; } from '@ghostfolio/common/interfaces';
import { translate } from '@ghostfolio/ui/i18n'; import { translate } from '@ghostfolio/ui/i18n';
@ -35,7 +35,7 @@ import { format } from 'date-fns';
import { EMPTY, Subject } from 'rxjs'; import { EMPTY, Subject } from 'rxjs';
import { catchError, takeUntil } from 'rxjs/operators'; import { catchError, takeUntil } from 'rxjs/operators';
import { AssetProfileDialogParams } from '../interfaces/interfaces'; import { AssetProfileDialogParams } from './interfaces/interfaces';
@Component({ @Component({
host: { class: 'd-flex flex-column h-100' }, host: { class: 'd-flex flex-column h-100' },
@ -118,6 +118,7 @@ export class AssetProfileDialog implements OnDestroy, OnInit {
this.user = state.user; this.user = state.user;
} }
}); });
this.adminService this.adminService
.fetchAdminMarketDataBySymbol({ .fetchAdminMarketDataBySymbol({
dataSource: this.data.dataSource, dataSource: this.data.dataSource,
@ -130,10 +131,10 @@ export class AssetProfileDialog implements OnDestroy, OnInit {
this.assetProfileClass = translate(this.assetProfile?.assetClass); this.assetProfileClass = translate(this.assetProfile?.assetClass);
this.assetProfileSubClass = translate(this.assetProfile?.assetSubClass); this.assetProfileSubClass = translate(this.assetProfile?.assetSubClass);
this.countries = {}; this.countries = {};
this.isBenchmark = this.benchmarks.some(({ id }) => { this.isBenchmark = this.benchmarks.some(({ id }) => {
return id === this.assetProfile.id; return id === this.assetProfile.id;
}); });
this.marketDataDetails = marketData;
this.historicalDataItems = this.marketDataDetails.map( this.historicalDataItems = this.marketDataDetails.map(
({ date, marketPrice }) => { ({ date, marketPrice }) => {
@ -144,6 +145,7 @@ export class AssetProfileDialog implements OnDestroy, OnInit {
} }
); );
this.marketDataDetails = marketData;
this.sectors = {}; this.sectors = {};
if (this.assetProfile?.countries?.length > 0) { if (this.assetProfile?.countries?.length > 0) {
@ -225,10 +227,6 @@ export class AssetProfileDialog implements OnDestroy, OnInit {
} }
} }
public onImportHistoricalDataChanged() {
this.initialize();
}
public onSetBenchmark({ dataSource, symbol }: AssetProfileIdentifier) { public onSetBenchmark({ dataSource, symbol }: AssetProfileIdentifier) {
this.dataService this.dataService
.postBenchmark({ dataSource, symbol }) .postBenchmark({ dataSource, symbol })

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

@ -87,7 +87,6 @@
[marketData]="marketDataDetails" [marketData]="marketDataDetails"
[symbol]="data.symbol" [symbol]="data.symbol"
[user]="user" [user]="user"
(historicalDataUpdated)="onImportHistoricalDataChanged()"
(marketDataChanged)="onMarketDataChanged($event)" (marketDataChanged)="onMarketDataChanged($event)"
/> />

2
apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.module.ts

@ -23,12 +23,12 @@ import { AssetProfileDialog } from './asset-profile-dialog.component';
@NgModule({ @NgModule({
declarations: [AssetProfileDialog], declarations: [AssetProfileDialog],
imports: [ imports: [
GfMarketDataDetailComponent,
CommonModule, CommonModule,
FormsModule, FormsModule,
GfAssetProfileIconComponent, GfAssetProfileIconComponent,
GfCurrencySelectorComponent, GfCurrencySelectorComponent,
GfLineChartComponent, GfLineChartComponent,
GfMarketDataDetailComponent,
GfPortfolioProportionChartComponent, GfPortfolioProportionChartComponent,
GfValueComponent, GfValueComponent,
MatButtonModule, MatButtonModule,

0
apps/client/src/app/components/admin-market-data/interfaces/interfaces.ts → apps/client/src/app/components/admin-market-data/asset-profile-dialog/interfaces/interfaces.ts

2
libs/ui/src/lib/market-data-detail/market-data-detail-dialog/market-data-detail-dialog.component.ts

@ -25,6 +25,7 @@ import { Subject, takeUntil } from 'rxjs';
import { MarketDataDetailDialogParams } from './interfaces/interfaces'; import { MarketDataDetailDialogParams } from './interfaces/interfaces';
@Component({ @Component({
changeDetection: ChangeDetectionStrategy.OnPush,
host: { class: 'h-100' }, host: { class: 'h-100' },
imports: [ imports: [
CommonModule, CommonModule,
@ -37,7 +38,6 @@ import { MarketDataDetailDialogParams } from './interfaces/interfaces';
ReactiveFormsModule ReactiveFormsModule
], ],
selector: 'gf-market-data-detail-dialog', selector: 'gf-market-data-detail-dialog',
changeDetection: ChangeDetectionStrategy.OnPush,
schemas: [CUSTOM_ELEMENTS_SCHEMA], schemas: [CUSTOM_ELEMENTS_SCHEMA],
standalone: true, standalone: true,
styleUrls: ['./market-data-detail-dialog.scss'], styleUrls: ['./market-data-detail-dialog.scss'],

23
libs/ui/src/lib/market-data-detail/market-data-detail.component.ts

@ -14,6 +14,7 @@ import {
EventEmitter, EventEmitter,
Input, Input,
OnChanges, OnChanges,
OnDestroy,
OnInit, OnInit,
Output Output
} from '@angular/core'; } from '@angular/core';
@ -53,7 +54,9 @@ import { MarketDataDetailDialogComponent } from './market-data-detail-dialog/mar
styleUrls: ['./market-data-detail.component.scss'], styleUrls: ['./market-data-detail.component.scss'],
templateUrl: './market-data-detail.component.html' templateUrl: './market-data-detail.component.html'
}) })
export class GfMarketDataDetailComponent implements OnChanges, OnInit { export class GfMarketDataDetailComponent
implements OnChanges, OnDestroy, OnInit
{
@Input() currency: string; @Input() currency: string;
@Input() dataSource: DataSource; @Input() dataSource: DataSource;
@Input() dateOfFirstActivity: string; @Input() dateOfFirstActivity: string;
@ -63,7 +66,6 @@ export class GfMarketDataDetailComponent implements OnChanges, OnInit {
@Input() user: User; @Input() user: User;
@Output() marketDataChanged = new EventEmitter<boolean>(); @Output() marketDataChanged = new EventEmitter<boolean>();
@Output() historicalDataUpdated = new EventEmitter();
public days = Array(31); public days = Array(31);
public defaultDateFormat: string; public defaultDateFormat: string;
@ -90,8 +92,8 @@ export class GfMarketDataDetailComponent implements OnChanges, OnInit {
public constructor( public constructor(
private adminService: AdminService, private adminService: AdminService,
private deviceService: DeviceDetectorService, private deviceService: DeviceDetectorService,
private formBuilder: FormBuilder,
private dialog: MatDialog, private dialog: MatDialog,
private formBuilder: FormBuilder,
private snackBar: MatSnackBar private snackBar: MatSnackBar
) { ) {
this.deviceType = this.deviceService.getDeviceInfo().deviceType; this.deviceType = this.deviceService.getDeviceInfo().deviceType;
@ -215,7 +217,7 @@ export class GfMarketDataDetailComponent implements OnChanges, OnInit {
.afterClosed() .afterClosed()
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntil(this.unsubscribeSubject))
.subscribe(({ withRefresh } = { withRefresh: false }) => { .subscribe(({ withRefresh } = { withRefresh: false }) => {
this.marketDataChanged.next(withRefresh); this.marketDataChanged.emit(withRefresh);
}); });
} }
@ -249,8 +251,9 @@ export class GfMarketDataDetailComponent implements OnChanges, OnInit {
takeUntil(this.unsubscribeSubject) takeUntil(this.unsubscribeSubject)
) )
.subscribe(() => { .subscribe(() => {
this.historicalDataUpdated.emit();
this.initializeHistoricalDataForm(); this.initializeHistoricalDataForm();
this.marketDataChanged.emit(true);
}); });
} catch { } catch {
this.snackBar.open( this.snackBar.open(
@ -261,6 +264,11 @@ export class GfMarketDataDetailComponent implements OnChanges, OnInit {
} }
} }
public ngOnDestroy() {
this.unsubscribeSubject.next();
this.unsubscribeSubject.complete();
}
private initializeHistoricalDataForm() { private initializeHistoricalDataForm() {
this.historicalDataForm.setValue({ this.historicalDataForm.setValue({
historicalData: { historicalData: {
@ -268,9 +276,4 @@ export class GfMarketDataDetailComponent implements OnChanges, OnInit {
} }
}); });
} }
public ngOnDestroy() {
this.unsubscribeSubject.next();
this.unsubscribeSubject.complete();
}
} }

Loading…
Cancel
Save