Browse Source

feat(client): enforce encapsulation

pull/7309/head
KenTandrian 2 days ago
parent
commit
f3f8bf2335
  1. 127
      apps/client/src/app/pages/portfolio/activities/activities-page.component.ts

127
apps/client/src/app/pages/portfolio/activities/activities-page.component.ts

@ -31,7 +31,6 @@ import { MatTableDataSource } from '@angular/material/table';
import { ActivatedRoute, Router, RouterModule } from '@angular/router'; import { ActivatedRoute, Router, RouterModule } from '@angular/router';
import { format, parseISO } from 'date-fns'; import { format, parseISO } from 'date-fns';
import { DeviceDetectorService } from 'ngx-device-detector'; import { DeviceDetectorService } from 'ngx-device-detector';
import { Subscription } from 'rxjs';
import { GfCreateOrUpdateActivityDialogComponent } from './create-or-update-activity-dialog/create-or-update-activity-dialog.component'; import { GfCreateOrUpdateActivityDialogComponent } from './create-or-update-activity-dialog/create-or-update-activity-dialog.component';
import { CreateOrUpdateActivityDialogParams } from './create-or-update-activity-dialog/interfaces/interfaces'; import { CreateOrUpdateActivityDialogParams } from './create-or-update-activity-dialog/interfaces/interfaces';
@ -51,19 +50,19 @@ import { ImportActivitiesDialogParams } from './import-activities-dialog/interfa
templateUrl: './activities-page.html' templateUrl: './activities-page.html'
}) })
export class GfActivitiesPageComponent implements OnInit { export class GfActivitiesPageComponent implements OnInit {
public activityTypesFilter: string[] = []; protected dataSource: MatTableDataSource<Activity> | undefined;
public dataSource: MatTableDataSource<Activity> | undefined; protected deviceType: string;
public deviceType: string; protected hasImpersonationId: boolean;
public hasImpersonationId: boolean; protected hasPermissionToCreateActivity: boolean;
public hasPermissionToCreateActivity: boolean; protected hasPermissionToDeleteActivity: boolean;
public hasPermissionToDeleteActivity: boolean; protected pageIndex = 0;
public pageIndex = 0; protected pageSize = DEFAULT_PAGE_SIZE;
public pageSize = DEFAULT_PAGE_SIZE; protected sortColumn = 'date';
public routeQueryParams: Subscription; protected sortDirection: SortDirection = 'desc';
public sortColumn = 'date'; protected totalItems: number | undefined;
public sortDirection: SortDirection = 'desc'; protected user: User;
public totalItems: number | undefined;
public user: User; private activityTypesFilter: string[] = [];
public constructor( public constructor(
private changeDetectorRef: ChangeDetectorRef, private changeDetectorRef: ChangeDetectorRef,
@ -77,7 +76,7 @@ export class GfActivitiesPageComponent implements OnInit {
private router: Router, private router: Router,
private userService: UserService private userService: UserService
) { ) {
this.routeQueryParams = route.queryParams route.queryParams
.pipe(takeUntilDestroyed(this.destroyRef)) .pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((params) => { .subscribe((params) => {
if (params['createDialog']) { if (params['createDialog']) {
@ -131,49 +130,13 @@ export class GfActivitiesPageComponent implements OnInit {
}); });
} }
public fetchActivities() { protected onChangePage(page: PageEvent) {
// Reset dataSource and totalItems to show loading state
this.dataSource = undefined;
this.totalItems = undefined;
const dateRange = this.user?.settings?.dateRange;
const range = this.isCalendarYear(dateRange) ? dateRange : undefined;
this.dataService
.fetchActivities({
range,
activityTypes: this.activityTypesFilter.length
? this.activityTypesFilter
: undefined,
filters: this.userService.getFilters(),
skip: this.pageIndex * this.pageSize,
sortColumn: this.sortColumn,
sortDirection: this.sortDirection,
take: this.pageSize
})
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(({ activities, count }) => {
this.dataSource = new MatTableDataSource(activities);
this.totalItems = count;
if (
this.hasPermissionToCreateActivity &&
this.user?.activitiesCount === 0
) {
this.router.navigate([], { queryParams: { createDialog: true } });
}
this.changeDetectorRef.markForCheck();
});
}
public onChangePage(page: PageEvent) {
this.pageIndex = page.pageIndex; this.pageIndex = page.pageIndex;
this.fetchActivities(); this.fetchActivities();
} }
public onClickActivity({ dataSource, symbol }: AssetProfileIdentifier) { protected onClickActivity({ dataSource, symbol }: AssetProfileIdentifier) {
this.router.navigate([], { this.router.navigate([], {
queryParams: { queryParams: {
dataSource, dataSource,
@ -183,11 +146,11 @@ export class GfActivitiesPageComponent implements OnInit {
}); });
} }
public onCloneActivity(aActivity: Activity) { protected onCloneActivity(aActivity: Activity) {
this.openCreateActivityDialog(aActivity); this.openCreateActivityDialog(aActivity);
} }
public onDeleteActivities() { protected onDeleteActivities() {
this.dataService this.dataService
.deleteActivities({ .deleteActivities({
filters: this.userService.getFilters() filters: this.userService.getFilters()
@ -205,7 +168,7 @@ export class GfActivitiesPageComponent implements OnInit {
}); });
} }
public onDeleteActivity(aId: string) { protected onDeleteActivity(aId: string) {
this.dataService this.dataService
.deleteActivity(aId) .deleteActivity(aId)
.pipe(takeUntilDestroyed(this.destroyRef)) .pipe(takeUntilDestroyed(this.destroyRef))
@ -221,7 +184,7 @@ export class GfActivitiesPageComponent implements OnInit {
}); });
} }
public onExport(activityIds?: string[]) { protected onExport(activityIds?: string[]) {
let fetchExportParams: any = { activityIds }; let fetchExportParams: any = { activityIds };
if (!activityIds) { if (!activityIds) {
@ -252,7 +215,7 @@ export class GfActivitiesPageComponent implements OnInit {
}); });
} }
public onExportDrafts(activityIds?: string[]) { protected onExportDrafts(activityIds?: string[]) {
this.dataService this.dataService
.fetchExport({ activityIds }) .fetchExport({ activityIds })
.pipe(takeUntilDestroyed(this.destroyRef)) .pipe(takeUntilDestroyed(this.destroyRef))
@ -270,7 +233,7 @@ export class GfActivitiesPageComponent implements OnInit {
}); });
} }
public onImport() { protected onImport() {
const dialogRef = this.dialog.open< const dialogRef = this.dialog.open<
GfImportActivitiesDialogComponent, GfImportActivitiesDialogComponent,
ImportActivitiesDialogParams ImportActivitiesDialogParams
@ -298,7 +261,7 @@ export class GfActivitiesPageComponent implements OnInit {
}); });
} }
public onImportDividends() { protected onImportDividends() {
const dialogRef = this.dialog.open< const dialogRef = this.dialog.open<
GfImportActivitiesDialogComponent, GfImportActivitiesDialogComponent,
ImportActivitiesDialogParams ImportActivitiesDialogParams
@ -327,7 +290,7 @@ export class GfActivitiesPageComponent implements OnInit {
}); });
} }
public onSortChanged({ active, direction }: Sort) { protected onSortChanged({ active, direction }: Sort) {
this.pageIndex = 0; this.pageIndex = 0;
this.sortColumn = active; this.sortColumn = active;
this.sortDirection = direction; this.sortDirection = direction;
@ -335,20 +298,56 @@ export class GfActivitiesPageComponent implements OnInit {
this.fetchActivities(); this.fetchActivities();
} }
public onTypesFilterChanged(aTypes: string[]) { protected onTypesFilterChanged(aTypes: string[]) {
this.activityTypesFilter = aTypes; this.activityTypesFilter = aTypes;
this.pageIndex = 0; this.pageIndex = 0;
this.fetchActivities(); this.fetchActivities();
} }
public onUpdateActivity(aActivity: Activity) { protected onUpdateActivity(aActivity: Activity) {
this.router.navigate([], { this.router.navigate([], {
queryParams: { activityId: aActivity.id, editDialog: true } queryParams: { activityId: aActivity.id, editDialog: true }
}); });
} }
public openUpdateActivityDialog(aActivity: Activity) { private fetchActivities() {
// Reset dataSource and totalItems to show loading state
this.dataSource = undefined;
this.totalItems = undefined;
const dateRange = this.user?.settings?.dateRange;
const range = this.isCalendarYear(dateRange) ? dateRange : undefined;
this.dataService
.fetchActivities({
range,
activityTypes: this.activityTypesFilter.length
? this.activityTypesFilter
: undefined,
filters: this.userService.getFilters(),
skip: this.pageIndex * this.pageSize,
sortColumn: this.sortColumn,
sortDirection: this.sortDirection,
take: this.pageSize
})
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(({ activities, count }) => {
this.dataSource = new MatTableDataSource(activities);
this.totalItems = count;
if (
this.hasPermissionToCreateActivity &&
this.user?.activitiesCount === 0
) {
this.router.navigate([], { queryParams: { createDialog: true } });
}
this.changeDetectorRef.markForCheck();
});
}
private openUpdateActivityDialog(aActivity: Activity) {
const dialogRef = this.dialog.open< const dialogRef = this.dialog.open<
GfCreateOrUpdateActivityDialogComponent, GfCreateOrUpdateActivityDialogComponent,
CreateOrUpdateActivityDialogParams CreateOrUpdateActivityDialogParams

Loading…
Cancel
Save