Browse Source

Resolve comments

pull/1531/head
yksolanki9 3 years ago
parent
commit
899191b0d4
  1. 8
      apps/client/src/app/pages/portfolio/activities/import-activities-dialog/import-activities-dialog.component.ts
  2. 29
      apps/client/src/app/services/import-activities.service.ts
  3. 2
      libs/ui/src/lib/activities-table/activities-table.component.html
  4. 4
      libs/ui/src/lib/activities-table/activities-table.component.scss

8
apps/client/src/app/pages/portfolio/activities/import-activities-dialog/import-activities-dialog.component.ts

@ -45,6 +45,8 @@ export class ImportActivitiesDialog implements OnDestroy {
public async onImportActivities() { public async onImportActivities() {
try { try {
this.snackBar.open('⏳ ' + $localize`Importing data...`);
await this.importActivitiesService.importSelectedActivities( await this.importActivitiesService.importSelectedActivities(
this.selectedActivities this.selectedActivities
); );
@ -81,7 +83,7 @@ export class ImportActivitiesDialog implements OnDestroy {
input.type = 'file'; input.type = 'file';
input.onchange = (event) => { input.onchange = (event) => {
this.snackBar.open('⏳ ' + $localize`Importing data...`); this.snackBar.open('⏳ ' + $localize`Validating data...`);
// Getting the file reference // Getting the file reference
const file = (event.target as HTMLInputElement).files[0]; const file = (event.target as HTMLInputElement).files[0];
@ -129,9 +131,9 @@ export class ImportActivitiesDialog implements OnDestroy {
} else if (file.name.endsWith('.csv')) { } else if (file.name.endsWith('.csv')) {
try { try {
this.activities = await this.importActivitiesService.importCsv({ this.activities = await this.importActivitiesService.importCsv({
dryRun: true,
fileContent, fileContent,
userAccounts: this.data.user.accounts, userAccounts: this.data.user.accounts
dryRun: true
}); });
} catch (error) { } catch (error) {
console.error(error); console.error(error);

29
apps/client/src/app/services/import-activities.service.ts

@ -26,13 +26,13 @@ export class ImportActivitiesService {
public constructor(private http: HttpClient) {} public constructor(private http: HttpClient) {}
public async importCsv({ public async importCsv({
dryRun = false,
fileContent, fileContent,
userAccounts, userAccounts
dryRun = false
}: { }: {
dryRun?: boolean;
fileContent: string; fileContent: string;
userAccounts: Account[]; userAccounts: Account[];
dryRun?: boolean;
}): Promise<Activity[]> { }): Promise<Activity[]> {
const content = csvToJson(fileContent, { const content = csvToJson(fileContent, {
dynamicTyping: true, dynamicTyping: true,
@ -91,20 +91,23 @@ export class ImportActivitiesService {
): Promise<Activity[]> { ): Promise<Activity[]> {
const importData: CreateOrderDto[] = []; const importData: CreateOrderDto[] = [];
for (const activity of selectedActivities) { for (const activity of selectedActivities) {
importData.push({ importData.push(this.convertToCreateOrderDto(activity));
currency: activity.SymbolProfile.currency,
date: activity.date.toString(),
fee: activity.fee,
quantity: activity.quantity,
symbol: activity.SymbolProfile.symbol,
type: activity.type,
unitPrice: activity.unitPrice
});
} }
return this.importJson({ content: importData }); return this.importJson({ content: importData });
} }
private convertToCreateOrderDto(aActivity: Activity): CreateOrderDto {
return {
currency: aActivity.SymbolProfile.currency,
date: aActivity.date.toString(),
fee: aActivity.fee,
quantity: aActivity.quantity,
symbol: aActivity.SymbolProfile.symbol,
type: aActivity.type,
unitPrice: aActivity.unitPrice
};
}
private lowercaseKeys(aObject: any) { private lowercaseKeys(aObject: any) {
return Object.keys(aObject).reduce((acc, key) => { return Object.keys(aObject).reduce((acc, key) => {
acc[key.toLowerCase()] = aObject[key]; acc[key.toLowerCase()] = aObject[key];

2
libs/ui/src/lib/activities-table/activities-table.component.html

@ -18,6 +18,7 @@
<ng-container matColumnDef="select"> <ng-container matColumnDef="select">
<th *matHeaderCellDef class="px-1" mat-header-cell> <th *matHeaderCellDef class="px-1" mat-header-cell>
<mat-checkbox <mat-checkbox
class="mt-2"
[checked]="selectedRows.hasValue() && areAllRowsSelected()" [checked]="selectedRows.hasValue() && areAllRowsSelected()"
[indeterminate]="selectedRows.hasValue() && !areAllRowsSelected()" [indeterminate]="selectedRows.hasValue() && !areAllRowsSelected()"
(change)="$event ? toggleAllRows() : null" (change)="$event ? toggleAllRows() : null"
@ -25,6 +26,7 @@
</th> </th>
<td *matCellDef="let element" class="px-1" mat-cell> <td *matCellDef="let element" class="px-1" mat-cell>
<mat-checkbox <mat-checkbox
class="mt-2"
[checked]="selectedRows.isSelected(element)" [checked]="selectedRows.isSelected(element)"
(change)="$event ? selectedRows.toggle(element) : null" (change)="$event ? selectedRows.toggle(element) : null"
(click)="$event.stopPropagation()" (click)="$event.stopPropagation()"

4
libs/ui/src/lib/activities-table/activities-table.component.scss

@ -25,10 +25,6 @@
} }
} }
.mat-checkbox {
margin-top: 8px;
}
.mat-row { .mat-row {
.type-badge { .type-badge {
background-color: rgba(var(--palette-foreground-text), 0.05); background-color: rgba(var(--palette-foreground-text), 0.05);

Loading…
Cancel
Save