Browse Source

Refactoring

pull/4469/head
Thomas Kaul 2 weeks ago
parent
commit
a1446a665b
  1. 6
      apps/api/src/app/admin/update-asset-profile.dto.ts
  2. 6
      apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.component.scss
  3. 153
      apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.component.ts
  4. 33
      apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.html

6
apps/api/src/app/admin/update-asset-profile.dto.ts

@ -19,8 +19,8 @@ export class UpdateAssetProfileDto {
@IsOptional()
assetSubClass?: AssetSubClass;
@IsString()
@IsOptional()
@IsString()
comment?: string;
@IsArray()
@ -35,8 +35,8 @@ export class UpdateAssetProfileDto {
@IsOptional()
dataSource?: DataSource;
@IsString()
@IsOptional()
@IsString()
name?: string;
@IsObject()
@ -47,8 +47,8 @@ export class UpdateAssetProfileDto {
@IsOptional()
sectors?: Prisma.InputJsonArray;
@IsString()
@IsOptional()
@IsString()
symbol?: string;
@IsObject()

6
apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.component.scss

@ -8,6 +8,12 @@
aspect-ratio: 16/9;
}
.edit-asset-profile-identifier-container {
bottom: 0;
right: 1rem;
top: 0;
}
.mat-expansion-panel {
--mat-expansion-container-background-color: transparent;

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

@ -59,6 +59,11 @@ import { AssetProfileDialogParams } from './interfaces/interfaces';
standalone: false
})
export class AssetProfileDialog implements OnDestroy, OnInit {
private static readonly HISTORICAL_DATA_TEMPLATE = `date;marketPrice\n${format(
new Date(),
DATE_FORMAT
)};123.45`;
@ViewChild('assetProfileFormElement')
assetProfileFormElement: ElementRef<HTMLFormElement>;
@ -130,10 +135,6 @@ export class AssetProfileDialog implements OnDestroy, OnInit {
};
public user: User;
private static readonly HISTORICAL_DATA_TEMPLATE = `date;marketPrice\n${format(
new Date(),
DATE_FORMAT
)};123.45`;
private unsubscribeSubject = new Subject<void>();
public constructor(
@ -149,6 +150,18 @@ export class AssetProfileDialog implements OnDestroy, OnInit {
private userService: UserService
) {}
public get canEditAssetProfileIdentifier() {
return (
this.assetProfile?.assetClass &&
!['MANUAL'].includes(this.assetProfile?.dataSource) &&
this.user?.settings?.isExperimentalFeatures
);
}
public get canSaveAssetProfileIdentifier() {
return !this.assetProfileForm.dirty;
}
public ngOnInit() {
const { benchmarks, currencies } = this.dataService.fetchInfo();
@ -251,14 +264,6 @@ export class AssetProfileDialog implements OnDestroy, OnInit {
});
}
public get isAssetProfileIdentifierEditable() {
return !this.assetProfileForm.dirty;
}
public get isAssetProfileIdentifierEditButtonVisible() {
return this.assetProfile?.dataSource !== 'MANUAL';
}
public onCancelEditAssetProfileIdentifierMode() {
this.isEditAssetProfileIdentifierMode = false;
@ -323,68 +328,6 @@ export class AssetProfileDialog implements OnDestroy, OnInit {
this.changeDetectorRef.markForCheck();
}
public async onSubmitAssetProfileIdentifierForm() {
const assetProfileIdentifier: UpdateAssetProfileDto = {
dataSource: this.assetProfileIdentifierForm.get('assetProfileIdentifier')
.value.dataSource,
symbol: this.assetProfileIdentifierForm.get('assetProfileIdentifier')
.value.symbol
};
try {
await validateObjectForForm({
classDto: UpdateAssetProfileDto,
form: this.assetProfileIdentifierForm,
object: assetProfileIdentifier
});
} catch (error) {
console.error(error);
return;
}
this.adminService
.patchAssetProfile(
{
dataSource: this.data.dataSource,
symbol: this.data.symbol
},
assetProfileIdentifier
)
.pipe(
catchError((error: HttpErrorResponse) => {
if (error.status === StatusCodes.CONFLICT) {
this.snackBar.open(
$localize`${assetProfileIdentifier.symbol} (${assetProfileIdentifier.dataSource}) is already in use.`,
undefined,
{
duration: ms('3 seconds')
}
);
} else {
this.snackBar.open(
$localize`An error occurred while updating to ${assetProfileIdentifier.symbol} (${assetProfileIdentifier.dataSource}).`,
undefined,
{
duration: ms('3 seconds')
}
);
}
return EMPTY;
}),
takeUntil(this.unsubscribeSubject)
)
.subscribe(() => {
const newAssetProfileIdentifier = {
dataSource: assetProfileIdentifier.dataSource,
symbol: assetProfileIdentifier.symbol
};
this.dialogRef.close(newAssetProfileIdentifier);
});
}
public async onSubmitAssetProfileForm() {
let countries = [];
let scraperConfiguration = {};
@ -470,6 +413,68 @@ export class AssetProfileDialog implements OnDestroy, OnInit {
});
}
public async onSubmitAssetProfileIdentifierForm() {
const assetProfileIdentifier: UpdateAssetProfileDto = {
dataSource: this.assetProfileIdentifierForm.get('assetProfileIdentifier')
.value.dataSource,
symbol: this.assetProfileIdentifierForm.get('assetProfileIdentifier')
.value.symbol
};
try {
await validateObjectForForm({
classDto: UpdateAssetProfileDto,
form: this.assetProfileIdentifierForm,
object: assetProfileIdentifier
});
} catch (error) {
console.error(error);
return;
}
this.adminService
.patchAssetProfile(
{
dataSource: this.data.dataSource,
symbol: this.data.symbol
},
assetProfileIdentifier
)
.pipe(
catchError((error: HttpErrorResponse) => {
if (error.status === StatusCodes.CONFLICT) {
this.snackBar.open(
$localize`${assetProfileIdentifier.symbol} (${assetProfileIdentifier.dataSource}) is already in use.`,
undefined,
{
duration: ms('3 seconds')
}
);
} else {
this.snackBar.open(
$localize`An error occurred while updating to ${assetProfileIdentifier.symbol} (${assetProfileIdentifier.dataSource}).`,
undefined,
{
duration: ms('3 seconds')
}
);
}
return EMPTY;
}),
takeUntil(this.unsubscribeSubject)
)
.subscribe(() => {
const newAssetProfileIdentifier = {
dataSource: assetProfileIdentifier.dataSource,
symbol: assetProfileIdentifier.symbol
};
this.dialogRef.close(newAssetProfileIdentifier);
});
}
public onTestMarketData() {
this.adminService
.testMarketData({

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

@ -105,7 +105,7 @@
/>
</mat-form-field>
<button
class="mx-1 no-min-width px-2"
class="ml-2 no-min-width px-2"
color="primary"
mat-flat-button
type="submit"
@ -122,7 +122,7 @@
<ng-container i18n>Apply</ng-container>
</button>
<button
class="mx-1 no-min-width px-2"
class="ml-2 no-min-width px-2"
mat-button
type="button"
(click)="onCancelEditAssetProfileIdentifierMode()"
@ -137,9 +137,8 @@
>Symbol</gf-value
>
</div>
<div class="col-6 d-flex justify-content-between mb-3">
<div class="col-6 mb-3">
<gf-value
class="col-11"
i18n
size="medium"
[value]="
@ -147,18 +146,22 @@
"
>Data Source</gf-value
>
<button
class="col-1 mx-1 no-min-width px-2"
mat-button
type="button"
[disabled]="!isAssetProfileIdentifierEditable"
[ngClass]="{
'd-none': !isAssetProfileIdentifierEditButtonVisible
}"
(click)="onSetEditAssetProfileIdentifierMode()"
<div
class="edit-asset-profile-identifier-container position-absolute"
>
<ion-icon name="create-outline"></ion-icon>
</button>
<button
class="h-100 no-min-width px-2"
mat-button
type="button"
[disabled]="!canSaveAssetProfileIdentifier"
[ngClass]="{
'd-none': !canEditAssetProfileIdentifier
}"
(click)="onSetEditAssetProfileIdentifierMode()"
>
<ion-icon name="create-outline" />
</button>
</div>
</div>
}
<div class="col-6 mb-3">

Loading…
Cancel
Save