|
@ -1,3 +1,7 @@ |
|
|
|
|
|
import { |
|
|
|
|
|
StepperOrientation, |
|
|
|
|
|
StepperSelectionEvent |
|
|
|
|
|
} from '@angular/cdk/stepper'; |
|
|
import { |
|
|
import { |
|
|
ChangeDetectionStrategy, |
|
|
ChangeDetectionStrategy, |
|
|
ChangeDetectorRef, |
|
|
ChangeDetectorRef, |
|
@ -8,6 +12,7 @@ import { |
|
|
import { FormBuilder, FormGroup, Validators } from '@angular/forms'; |
|
|
import { FormBuilder, FormGroup, Validators } from '@angular/forms'; |
|
|
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; |
|
|
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; |
|
|
import { MatSnackBar } from '@angular/material/snack-bar'; |
|
|
import { MatSnackBar } from '@angular/material/snack-bar'; |
|
|
|
|
|
import { MatStepper } from '@angular/material/stepper'; |
|
|
import { CreateAccountDto } from '@ghostfolio/api/app/account/create-account.dto'; |
|
|
import { CreateAccountDto } from '@ghostfolio/api/app/account/create-account.dto'; |
|
|
import { Activity } from '@ghostfolio/api/app/order/interfaces/activities.interface'; |
|
|
import { Activity } from '@ghostfolio/api/app/order/interfaces/activities.interface'; |
|
|
import { DataService } from '@ghostfolio/client/services/data.service'; |
|
|
import { DataService } from '@ghostfolio/client/services/data.service'; |
|
@ -15,8 +20,10 @@ import { ImportActivitiesService } from '@ghostfolio/client/services/import-acti |
|
|
import { Position } from '@ghostfolio/common/interfaces'; |
|
|
import { Position } from '@ghostfolio/common/interfaces'; |
|
|
import { AssetClass } from '@prisma/client'; |
|
|
import { AssetClass } from '@prisma/client'; |
|
|
import { isArray, sortBy } from 'lodash'; |
|
|
import { isArray, sortBy } from 'lodash'; |
|
|
|
|
|
import { DeviceDetectorService } from 'ngx-device-detector'; |
|
|
import { Subject, takeUntil } from 'rxjs'; |
|
|
import { Subject, takeUntil } from 'rxjs'; |
|
|
|
|
|
|
|
|
|
|
|
import { ImportStep } from './enums/import-step'; |
|
|
import { ImportActivitiesDialogParams } from './interfaces/interfaces'; |
|
|
import { ImportActivitiesDialogParams } from './interfaces/interfaces'; |
|
|
|
|
|
|
|
|
@Component({ |
|
|
@Component({ |
|
@ -29,12 +36,14 @@ export class ImportActivitiesDialog implements OnDestroy { |
|
|
public accounts: CreateAccountDto[] = []; |
|
|
public accounts: CreateAccountDto[] = []; |
|
|
public activities: Activity[] = []; |
|
|
public activities: Activity[] = []; |
|
|
public details: any[] = []; |
|
|
public details: any[] = []; |
|
|
|
|
|
public deviceType: string; |
|
|
public errorMessages: string[] = []; |
|
|
public errorMessages: string[] = []; |
|
|
public holdings: Position[] = []; |
|
|
public holdings: Position[] = []; |
|
|
public isFileSelected = false; |
|
|
public importStep: ImportStep = ImportStep.UPLOAD_FILE; |
|
|
public maxSafeInteger = Number.MAX_SAFE_INTEGER; |
|
|
public maxSafeInteger = Number.MAX_SAFE_INTEGER; |
|
|
public mode: 'DIVIDEND'; |
|
|
public mode: 'DIVIDEND'; |
|
|
public selectedActivities: Activity[] = []; |
|
|
public selectedActivities: Activity[] = []; |
|
|
|
|
|
public stepperOrientation: StepperOrientation; |
|
|
public uniqueAssetForm: FormGroup; |
|
|
public uniqueAssetForm: FormGroup; |
|
|
|
|
|
|
|
|
private unsubscribeSubject = new Subject<void>(); |
|
|
private unsubscribeSubject = new Subject<void>(); |
|
@ -43,6 +52,7 @@ export class ImportActivitiesDialog implements OnDestroy { |
|
|
private changeDetectorRef: ChangeDetectorRef, |
|
|
private changeDetectorRef: ChangeDetectorRef, |
|
|
@Inject(MAT_DIALOG_DATA) public data: ImportActivitiesDialogParams, |
|
|
@Inject(MAT_DIALOG_DATA) public data: ImportActivitiesDialogParams, |
|
|
private dataService: DataService, |
|
|
private dataService: DataService, |
|
|
|
|
|
private deviceService: DeviceDetectorService, |
|
|
private formBuilder: FormBuilder, |
|
|
private formBuilder: FormBuilder, |
|
|
public dialogRef: MatDialogRef<ImportActivitiesDialog>, |
|
|
public dialogRef: MatDialogRef<ImportActivitiesDialog>, |
|
|
private importActivitiesService: ImportActivitiesService, |
|
|
private importActivitiesService: ImportActivitiesService, |
|
@ -50,6 +60,10 @@ export class ImportActivitiesDialog implements OnDestroy { |
|
|
) {} |
|
|
) {} |
|
|
|
|
|
|
|
|
public ngOnInit() { |
|
|
public ngOnInit() { |
|
|
|
|
|
this.deviceType = this.deviceService.getDeviceInfo().deviceType; |
|
|
|
|
|
this.stepperOrientation = |
|
|
|
|
|
this.deviceType === 'mobile' ? 'vertical' : 'horizontal'; |
|
|
|
|
|
|
|
|
this.uniqueAssetForm = this.formBuilder.group({ |
|
|
this.uniqueAssetForm = this.formBuilder.group({ |
|
|
uniqueAsset: [undefined, Validators.required] |
|
|
uniqueAsset: [undefined, Validators.required] |
|
|
}); |
|
|
}); |
|
@ -116,7 +130,15 @@ export class ImportActivitiesDialog implements OnDestroy { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public onLoadDividends() { |
|
|
public onImportStepChange(event: StepperSelectionEvent) { |
|
|
|
|
|
if (event.selectedIndex === ImportStep.UPLOAD_FILE) { |
|
|
|
|
|
this.importStep = ImportStep.UPLOAD_FILE; |
|
|
|
|
|
} else if (event.selectedIndex === ImportStep.SELECT_ACTIVITIES) { |
|
|
|
|
|
this.importStep = ImportStep.SELECT_ACTIVITIES; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public onLoadDividends(aStepper: MatStepper) { |
|
|
this.uniqueAssetForm.controls['uniqueAsset'].disable(); |
|
|
this.uniqueAssetForm.controls['uniqueAsset'].disable(); |
|
|
|
|
|
|
|
|
const { dataSource, symbol } = |
|
|
const { dataSource, symbol } = |
|
@ -130,19 +152,23 @@ export class ImportActivitiesDialog implements OnDestroy { |
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
.subscribe(({ activities }) => { |
|
|
.subscribe(({ activities }) => { |
|
|
this.activities = activities; |
|
|
this.activities = activities; |
|
|
this.isFileSelected = true; |
|
|
|
|
|
|
|
|
aStepper.next(); |
|
|
|
|
|
|
|
|
this.changeDetectorRef.markForCheck(); |
|
|
this.changeDetectorRef.markForCheck(); |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public onReset() { |
|
|
public onReset(aStepper: MatStepper) { |
|
|
this.details = []; |
|
|
this.details = []; |
|
|
this.errorMessages = []; |
|
|
this.errorMessages = []; |
|
|
this.isFileSelected = false; |
|
|
this.importStep = ImportStep.SELECT_ACTIVITIES; |
|
|
|
|
|
this.uniqueAssetForm.controls['uniqueAsset'].enable(); |
|
|
|
|
|
|
|
|
|
|
|
aStepper.reset(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public onSelectFile() { |
|
|
public onSelectFile(aStepper: MatStepper) { |
|
|
const input = document.createElement('input'); |
|
|
const input = document.createElement('input'); |
|
|
input.accept = 'application/JSON, .csv'; |
|
|
input.accept = 'application/JSON, .csv'; |
|
|
input.type = 'file'; |
|
|
input.type = 'file'; |
|
@ -225,8 +251,11 @@ export class ImportActivitiesDialog implements OnDestroy { |
|
|
error: { error: { message: ['Unexpected format'] } } |
|
|
error: { error: { message: ['Unexpected format'] } } |
|
|
}); |
|
|
}); |
|
|
} finally { |
|
|
} finally { |
|
|
this.isFileSelected = true; |
|
|
this.importStep = ImportStep.SELECT_ACTIVITIES; |
|
|
this.snackBar.dismiss(); |
|
|
this.snackBar.dismiss(); |
|
|
|
|
|
|
|
|
|
|
|
aStepper.next(); |
|
|
|
|
|
|
|
|
this.changeDetectorRef.markForCheck(); |
|
|
this.changeDetectorRef.markForCheck(); |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|