Browse Source

feat(client): tighten up encapsulation and immutability

pull/6722/head
KenTandrian 1 month ago
parent
commit
8e5cff332c
  1. 101
      apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.component.ts

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

@ -130,23 +130,24 @@ export class GfAssetProfileDialogComponent implements OnInit {
)};123.45`; )};123.45`;
@ViewChild('assetProfileFormElement') @ViewChild('assetProfileFormElement')
assetProfileFormElement: ElementRef<HTMLFormElement>; public readonly assetProfileFormElement: ElementRef<HTMLFormElement>;
public assetClassLabel: string; protected assetClassLabel: string;
public assetSubClassLabel: string; protected assetSubClassLabel: string;
public assetClassOptions: AssetClassSelectorOption[] = Object.keys(AssetClass) protected readonly assetClassOptions: AssetClassSelectorOption[] =
.map((id) => { Object.keys(AssetClass)
return { id, label: translate(id) } as AssetClassSelectorOption; .map((id) => {
}) return { id, label: translate(id) } as AssetClassSelectorOption;
.sort((a, b) => { })
return a.label.localeCompare(b.label); .sort((a, b) => {
}); return a.label.localeCompare(b.label);
});
public assetSubClassOptions: AssetClassSelectorOption[] = []; protected assetSubClassOptions: AssetClassSelectorOption[] = [];
public assetProfile: AdminMarketDataDetails['assetProfile']; protected assetProfile: AdminMarketDataDetails['assetProfile'];
public assetProfileForm = this.formBuilder.group({ protected readonly assetProfileForm = this.formBuilder.group({
assetClass: new FormControl<AssetClass | null>(null), assetClass: new FormControl<AssetClass | null>(null),
assetSubClass: new FormControl<AssetSubClass | null>(null), assetSubClass: new FormControl<AssetSubClass | null>(null),
comment: '', comment: '',
@ -174,7 +175,7 @@ export class GfAssetProfileDialogComponent implements OnInit {
url: '' url: ''
}); });
public assetProfileIdentifierForm = this.formBuilder.group( protected readonly assetProfileIdentifierForm = this.formBuilder.group(
{ {
assetProfileIdentifier: new FormControl< assetProfileIdentifier: new FormControl<
AssetProfileIdentifier | { symbol: null; dataSource: null } AssetProfileIdentifier | { symbol: null; dataSource: null }
@ -187,16 +188,15 @@ export class GfAssetProfileDialogComponent implements OnInit {
} }
); );
public benchmarks: Partial<SymbolProfile>[]; protected canEditAssetProfile = true;
public canEditAssetProfile = true;
public countries: { protected countries: {
[code: string]: { name: string; value: number }; [code: string]: { name: string; value: number };
}; };
public currencies: string[] = []; protected currencies: string[] = [];
public readonly dateRangeOptions = [ protected readonly dateRangeOptions = [
{ {
label: $localize`Current week` + ' (' + $localize`WTD` + ')', label: $localize`Current week` + ' (' + $localize`WTD` + ')',
value: 'wtd' value: 'wtd'
@ -222,14 +222,14 @@ export class GfAssetProfileDialogComponent implements OnInit {
value: 'max' value: 'max'
} }
]; ];
public historicalDataItems: LineChartItem[]; protected historicalDataItems: LineChartItem[];
public isBenchmark = false; protected isBenchmark = false;
public isDataGatheringEnabled: boolean; protected isDataGatheringEnabled: boolean;
public isEditAssetProfileIdentifierMode = false; protected isEditAssetProfileIdentifierMode = false;
public readonly isUUID = isUUID; protected readonly isUUID = isUUID;
public marketDataItems: MarketData[] = []; protected marketDataItems: MarketData[] = [];
public modeValues = [ protected readonly modeValues = [
{ {
value: 'lazy', value: 'lazy',
viewValue: $localize`Lazy` + ' (' + $localize`end of day` + ')' viewValue: $localize`Lazy` + ' (' + $localize`end of day` + ')'
@ -240,20 +240,22 @@ export class GfAssetProfileDialogComponent implements OnInit {
} }
]; ];
public sectors: { protected sectors: {
[name: string]: { name: string; value: number }; [name: string]: { name: string; value: number };
}; };
public user: User; protected user: User;
private benchmarks: Partial<SymbolProfile>[];
public constructor( public constructor(
public adminMarketDataService: AdminMarketDataService, protected adminMarketDataService: AdminMarketDataService,
private adminService: AdminService, private adminService: AdminService,
private changeDetectorRef: ChangeDetectorRef, private changeDetectorRef: ChangeDetectorRef,
@Inject(MAT_DIALOG_DATA) public data: AssetProfileDialogParams, @Inject(MAT_DIALOG_DATA) protected data: AssetProfileDialogParams,
private dataService: DataService, private dataService: DataService,
private destroyRef: DestroyRef, private destroyRef: DestroyRef,
public dialogRef: MatDialogRef<GfAssetProfileDialogComponent>, private dialogRef: MatDialogRef<GfAssetProfileDialogComponent>,
private formBuilder: FormBuilder, private formBuilder: FormBuilder,
private notificationService: NotificationService, private notificationService: NotificationService,
private snackBar: MatSnackBar, private snackBar: MatSnackBar,
@ -268,7 +270,7 @@ export class GfAssetProfileDialogComponent implements OnInit {
}); });
} }
public get canSaveAssetProfileIdentifier() { protected get canSaveAssetProfileIdentifier() {
return !this.assetProfileForm.dirty && this.canEditAssetProfile; return !this.assetProfileForm.dirty && this.canEditAssetProfile;
} }
@ -281,7 +283,7 @@ export class GfAssetProfileDialogComponent implements OnInit {
this.initialize(); this.initialize();
} }
public initialize() { protected initialize() {
this.historicalDataItems = []; this.historicalDataItems = [];
this.adminService this.adminService
@ -428,7 +430,7 @@ export class GfAssetProfileDialogComponent implements OnInit {
}); });
} }
public onCancelEditAssetProfileIdentifierMode() { protected onCancelEditAssetProfileIdentifierMode() {
this.isEditAssetProfileIdentifierMode = false; this.isEditAssetProfileIdentifierMode = false;
if (this.canEditAssetProfile) { if (this.canEditAssetProfile) {
@ -438,17 +440,20 @@ export class GfAssetProfileDialogComponent implements OnInit {
this.assetProfileIdentifierForm.reset(); this.assetProfileIdentifierForm.reset();
} }
public onClose() { protected onClose() {
this.dialogRef.close(); this.dialogRef.close();
} }
public onDeleteProfileData({ dataSource, symbol }: AssetProfileIdentifier) { protected onDeleteProfileData({
dataSource,
symbol
}: AssetProfileIdentifier) {
this.adminMarketDataService.deleteAssetProfile({ dataSource, symbol }); this.adminMarketDataService.deleteAssetProfile({ dataSource, symbol });
this.dialogRef.close(); this.dialogRef.close();
} }
public onGatherProfileDataBySymbol({ protected onGatherProfileDataBySymbol({
dataSource, dataSource,
symbol symbol
}: AssetProfileIdentifier) { }: AssetProfileIdentifier) {
@ -458,7 +463,7 @@ export class GfAssetProfileDialogComponent implements OnInit {
.subscribe(); .subscribe();
} }
public onGatherSymbol({ protected onGatherSymbol({
dataSource, dataSource,
range, range,
symbol symbol
@ -471,13 +476,13 @@ export class GfAssetProfileDialogComponent implements OnInit {
.subscribe(); .subscribe();
} }
public onMarketDataChanged(withRefresh: boolean = false) { protected onMarketDataChanged(withRefresh: boolean = false) {
if (withRefresh) { if (withRefresh) {
this.initialize(); this.initialize();
} }
} }
public onSetBenchmark({ dataSource, symbol }: AssetProfileIdentifier) { protected onSetBenchmark({ dataSource, symbol }: AssetProfileIdentifier) {
this.dataService this.dataService
.postBenchmark({ dataSource, symbol }) .postBenchmark({ dataSource, symbol })
.pipe(takeUntilDestroyed(this.destroyRef)) .pipe(takeUntilDestroyed(this.destroyRef))
@ -490,13 +495,13 @@ export class GfAssetProfileDialogComponent implements OnInit {
}); });
} }
public onSetEditAssetProfileIdentifierMode() { protected onSetEditAssetProfileIdentifierMode() {
this.isEditAssetProfileIdentifierMode = true; this.isEditAssetProfileIdentifierMode = true;
this.assetProfileForm.disable(); this.assetProfileForm.disable();
} }
public async onSubmitAssetProfileForm() { protected async onSubmitAssetProfileForm() {
let countries = []; let countries = [];
let scraperConfiguration: Prisma.InputJsonObject | undefined = { let scraperConfiguration: Prisma.InputJsonObject | undefined = {
selector: '', selector: '',
@ -636,7 +641,7 @@ export class GfAssetProfileDialogComponent implements OnInit {
}); });
} }
public async onSubmitAssetProfileIdentifierForm() { protected async onSubmitAssetProfileIdentifierForm() {
const assetProfileIdentifier: UpdateAssetProfileDto = { const assetProfileIdentifier: UpdateAssetProfileDto = {
dataSource: this.assetProfileIdentifierForm.get('assetProfileIdentifier') dataSource: this.assetProfileIdentifierForm.get('assetProfileIdentifier')
?.value.dataSource, ?.value.dataSource,
@ -698,7 +703,7 @@ export class GfAssetProfileDialogComponent implements OnInit {
}); });
} }
public onTestMarketData() { protected onTestMarketData() {
this.adminService this.adminService
.testMarketData({ .testMarketData({
dataSource: this.data.dataSource, dataSource: this.data.dataSource,
@ -751,7 +756,7 @@ export class GfAssetProfileDialogComponent implements OnInit {
}); });
} }
public onToggleIsActive({ checked }: MatCheckboxChange) { protected onToggleIsActive({ checked }: MatCheckboxChange) {
if (checked) { if (checked) {
this.assetProfileForm.get('isActive')?.setValue(true); this.assetProfileForm.get('isActive')?.setValue(true);
} else { } else {
@ -765,7 +770,7 @@ export class GfAssetProfileDialogComponent implements OnInit {
} }
} }
public onUnsetBenchmark({ dataSource, symbol }: AssetProfileIdentifier) { protected onUnsetBenchmark({ dataSource, symbol }: AssetProfileIdentifier) {
this.dataService this.dataService
.deleteBenchmark({ dataSource, symbol }) .deleteBenchmark({ dataSource, symbol })
.pipe(takeUntilDestroyed(this.destroyRef)) .pipe(takeUntilDestroyed(this.destroyRef))
@ -778,7 +783,7 @@ export class GfAssetProfileDialogComponent implements OnInit {
}); });
} }
public onTriggerSubmitAssetProfileForm() { protected onTriggerSubmitAssetProfileForm() {
if (this.assetProfileForm.valid) { if (this.assetProfileForm.valid) {
this.onSubmitAssetProfileForm(); this.onSubmitAssetProfileForm();
} }

Loading…
Cancel
Save