|
@ -10,6 +10,7 @@ import { isFinite } from 'lodash'; |
|
|
import { parse as csvToJson } from 'papaparse'; |
|
|
import { parse as csvToJson } from 'papaparse'; |
|
|
import { EMPTY, map, firstValueFrom } from 'rxjs'; |
|
|
import { EMPTY, map, firstValueFrom } from 'rxjs'; |
|
|
import { catchError } from 'rxjs/operators'; |
|
|
import { catchError } from 'rxjs/operators'; |
|
|
|
|
|
import { NotificationService } from '@ghostfolio/client/core/notification/notification.service'; |
|
|
|
|
|
|
|
|
@Injectable({ |
|
|
@Injectable({ |
|
|
providedIn: 'root' |
|
|
providedIn: 'root' |
|
@ -32,7 +33,12 @@ export class ImportActivitiesService { |
|
|
'value' |
|
|
'value' |
|
|
]; |
|
|
]; |
|
|
|
|
|
|
|
|
public constructor(private http: HttpClient) {} |
|
|
private warnings: string[] = []; |
|
|
|
|
|
|
|
|
|
|
|
public constructor( |
|
|
|
|
|
private http: HttpClient, |
|
|
|
|
|
private notificationService: NotificationService |
|
|
|
|
|
) {} |
|
|
|
|
|
|
|
|
public async importCsv({ |
|
|
public async importCsv({ |
|
|
fileContent, |
|
|
fileContent, |
|
@ -45,6 +51,8 @@ export class ImportActivitiesService { |
|
|
}): Promise<{ |
|
|
}): Promise<{ |
|
|
activities: Activity[]; |
|
|
activities: Activity[]; |
|
|
}> { |
|
|
}> { |
|
|
|
|
|
this.warnings = []; |
|
|
|
|
|
|
|
|
const content = csvToJson(fileContent, { |
|
|
const content = csvToJson(fileContent, { |
|
|
dynamicTyping: true, |
|
|
dynamicTyping: true, |
|
|
header: true, |
|
|
header: true, |
|
@ -68,6 +76,14 @@ export class ImportActivitiesService { |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Process any possible warnings during import
|
|
|
|
|
|
if (this.warnings.length > 0) { |
|
|
|
|
|
this.notificationService.alert({ |
|
|
|
|
|
title: 'Import Warnings', |
|
|
|
|
|
message: this.warnings.join('<br/>') |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return await this.importJson({ activities, isDryRun }); |
|
|
return await this.importJson({ activities, isDryRun }); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -276,7 +292,6 @@ export class ImportActivitiesService { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private parseFee({ |
|
|
private parseFee({ |
|
|
// content,
|
|
|
|
|
|
index, |
|
|
index, |
|
|
item |
|
|
item |
|
|
}: { |
|
|
}: { |
|
@ -292,7 +307,7 @@ export class ImportActivitiesService { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
console.warn(`activities.${index}.fee was not provided, defaulting to 0`); |
|
|
this.warnings.push(`Activity ${index + 1}: Fee not provided, defaulting to 0`); |
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -343,7 +358,6 @@ export class ImportActivitiesService { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private parseType({ |
|
|
private parseType({ |
|
|
//content,
|
|
|
|
|
|
index, |
|
|
index, |
|
|
item |
|
|
item |
|
|
}: { |
|
|
}: { |
|
@ -376,7 +390,7 @@ export class ImportActivitiesService { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
console.warn(`activities.${index}.type was not provided, defaulting to BUY`); |
|
|
this.warnings.push(`Activity ${index + 1}: Type not provided, defaulting to BUY`); |
|
|
return 'BUY'; |
|
|
return 'BUY'; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|