mirror of https://github.com/ghostfolio/ghostfolio
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
2.6 KiB
81 lines
2.6 KiB
import { ConfirmationDialogType } from '@ghostfolio/client/core/notification/confirmation-dialog/confirmation-dialog.type';
|
|
import { NotificationService } from '@ghostfolio/client/core/notification/notification.service';
|
|
import { AdminService } from '@ghostfolio/client/services/admin.service';
|
|
import { ghostfolioScraperApiSymbolPrefix } from '@ghostfolio/common/config';
|
|
import { getCurrencyFromSymbol, isCurrency } from '@ghostfolio/common/helper';
|
|
import {
|
|
AssetProfileIdentifier,
|
|
AdminMarketDataItem
|
|
} from '@ghostfolio/common/interfaces';
|
|
|
|
import { Injectable } from '@angular/core';
|
|
import { EMPTY, catchError, finalize, forkJoin, takeUntil } from 'rxjs';
|
|
|
|
@Injectable()
|
|
export class AdminMarketDataService {
|
|
public constructor(
|
|
private adminService: AdminService,
|
|
private notificationService: NotificationService
|
|
) {}
|
|
|
|
public deleteAssetProfile({ dataSource, symbol }: AssetProfileIdentifier) {
|
|
this.notificationService.confirm({
|
|
confirmFn: () => {
|
|
this.adminService
|
|
.deleteProfileData({ dataSource, symbol })
|
|
.subscribe(() => {
|
|
setTimeout(() => {
|
|
window.location.reload();
|
|
}, 300);
|
|
});
|
|
},
|
|
confirmType: ConfirmationDialogType.Warn,
|
|
title: $localize`Do you really want to delete this asset profile?`
|
|
});
|
|
}
|
|
|
|
public deleteAssetProfiles(
|
|
aAssetProfileIdentifiers: AssetProfileIdentifier[]
|
|
) {
|
|
this.notificationService.confirm({
|
|
confirmFn: () => {
|
|
const deleteRequests = aAssetProfileIdentifiers.map(
|
|
({ dataSource, symbol }) => {
|
|
return this.adminService.deleteProfileData({ dataSource, symbol });
|
|
}
|
|
);
|
|
|
|
forkJoin(deleteRequests)
|
|
.pipe(
|
|
catchError(() => {
|
|
this.notificationService.alert({
|
|
title: $localize`Oops! Could not delete profiles.`
|
|
});
|
|
|
|
return EMPTY;
|
|
}),
|
|
finalize(() => {
|
|
window.location.reload();
|
|
setTimeout(() => {}, 300);
|
|
})
|
|
)
|
|
.subscribe(() => {});
|
|
},
|
|
confirmType: ConfirmationDialogType.Warn,
|
|
title: $localize`Do you really want to delete these profiles?`
|
|
});
|
|
}
|
|
|
|
public hasPermissionToDeleteAssetProfile({
|
|
activitiesCount,
|
|
isBenchmark,
|
|
symbol
|
|
}: Pick<AdminMarketDataItem, 'activitiesCount' | 'isBenchmark' | 'symbol'>) {
|
|
return (
|
|
activitiesCount === 0 &&
|
|
!isBenchmark &&
|
|
!isCurrency(getCurrencyFromSymbol(symbol)) &&
|
|
!symbol.startsWith(ghostfolioScraperApiSymbolPrefix)
|
|
);
|
|
}
|
|
}
|
|
|