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.
71 lines
2.0 KiB
71 lines
2.0 KiB
import { AdminService } from '@ghostfolio/client/services/admin.service';
|
|
import { ghostfolioScraperApiSymbolPrefix } from '@ghostfolio/common/config';
|
|
import { getCurrencyFromSymbol, isCurrency } from '@ghostfolio/common/helper';
|
|
import {
|
|
AdminMarketDataItem,
|
|
UniqueAsset
|
|
} 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) {}
|
|
|
|
public deleteAssetProfile({ dataSource, symbol }: UniqueAsset) {
|
|
const confirmation = confirm(
|
|
$localize`Do you really want to delete this asset profile?`
|
|
);
|
|
|
|
if (confirmation) {
|
|
this.adminService
|
|
.deleteProfileData({ dataSource, symbol })
|
|
.subscribe(() => {
|
|
setTimeout(() => {
|
|
window.location.reload();
|
|
}, 300);
|
|
});
|
|
}
|
|
}
|
|
|
|
public deleteAssetProfiles(uniqueAssets: UniqueAsset[]) {
|
|
const confirmation = confirm(
|
|
$localize`Do you really want to delete these asset profiles?`
|
|
);
|
|
|
|
if (confirmation) {
|
|
const deleteRequests = uniqueAssets.map(({ dataSource, symbol }) => {
|
|
return this.adminService.deleteProfileData({ dataSource, symbol });
|
|
});
|
|
|
|
forkJoin(deleteRequests)
|
|
.pipe(
|
|
catchError(() => {
|
|
alert($localize`Oops! Could not delete profiles.`);
|
|
|
|
return EMPTY;
|
|
}),
|
|
finalize(() => {
|
|
setTimeout(() => {
|
|
window.location.reload();
|
|
}, 300);
|
|
})
|
|
)
|
|
.subscribe(() => {});
|
|
}
|
|
}
|
|
|
|
public hasPermissionToDeleteAssetProfile({
|
|
activitiesCount,
|
|
isBenchmark,
|
|
symbol
|
|
}: Pick<AdminMarketDataItem, 'activitiesCount' | 'isBenchmark' | 'symbol'>) {
|
|
return (
|
|
activitiesCount === 0 &&
|
|
!isBenchmark &&
|
|
!isCurrency(getCurrencyFromSymbol(symbol)) &&
|
|
!symbol.startsWith(ghostfolioScraperApiSymbolPrefix)
|
|
);
|
|
}
|
|
}
|
|
|