|
|
@ -14,7 +14,13 @@ import { DateRange } from '@ghostfolio/common/types'; |
|
|
import { GfActivitiesTableComponent } from '@ghostfolio/ui/activities-table'; |
|
|
import { GfActivitiesTableComponent } from '@ghostfolio/ui/activities-table'; |
|
|
import { DataService } from '@ghostfolio/ui/services'; |
|
|
import { DataService } from '@ghostfolio/ui/services'; |
|
|
|
|
|
|
|
|
import { ChangeDetectorRef, Component, OnDestroy, OnInit } from '@angular/core'; |
|
|
import { |
|
|
|
|
|
ChangeDetectorRef, |
|
|
|
|
|
Component, |
|
|
|
|
|
DestroyRef, |
|
|
|
|
|
OnInit |
|
|
|
|
|
} from '@angular/core'; |
|
|
|
|
|
import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; |
|
|
import { MatButtonModule } from '@angular/material/button'; |
|
|
import { MatButtonModule } from '@angular/material/button'; |
|
|
import { MatDialog } from '@angular/material/dialog'; |
|
|
import { MatDialog } from '@angular/material/dialog'; |
|
|
import { PageEvent } from '@angular/material/paginator'; |
|
|
import { PageEvent } from '@angular/material/paginator'; |
|
|
@ -27,8 +33,7 @@ import { format, parseISO } from 'date-fns'; |
|
|
import { addIcons } from 'ionicons'; |
|
|
import { addIcons } from 'ionicons'; |
|
|
import { addOutline } from 'ionicons/icons'; |
|
|
import { addOutline } from 'ionicons/icons'; |
|
|
import { DeviceDetectorService } from 'ngx-device-detector'; |
|
|
import { DeviceDetectorService } from 'ngx-device-detector'; |
|
|
import { Subject, Subscription } from 'rxjs'; |
|
|
import { Subscription } from 'rxjs'; |
|
|
import { takeUntil } from 'rxjs/operators'; |
|
|
|
|
|
|
|
|
|
|
|
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'; |
|
|
@ -48,7 +53,7 @@ import { ImportActivitiesDialogParams } from './import-activities-dialog/interfa |
|
|
styleUrls: ['./activities-page.scss'], |
|
|
styleUrls: ['./activities-page.scss'], |
|
|
templateUrl: './activities-page.html' |
|
|
templateUrl: './activities-page.html' |
|
|
}) |
|
|
}) |
|
|
export class GfActivitiesPageComponent implements OnDestroy, OnInit { |
|
|
export class GfActivitiesPageComponent implements OnInit { |
|
|
public dataSource: MatTableDataSource<Activity>; |
|
|
public dataSource: MatTableDataSource<Activity>; |
|
|
public deviceType: string; |
|
|
public deviceType: string; |
|
|
public hasImpersonationId: boolean; |
|
|
public hasImpersonationId: boolean; |
|
|
@ -62,11 +67,10 @@ export class GfActivitiesPageComponent implements OnDestroy, OnInit { |
|
|
public totalItems: number; |
|
|
public totalItems: number; |
|
|
public user: User; |
|
|
public user: User; |
|
|
|
|
|
|
|
|
private unsubscribeSubject = new Subject<void>(); |
|
|
|
|
|
|
|
|
|
|
|
public constructor( |
|
|
public constructor( |
|
|
private changeDetectorRef: ChangeDetectorRef, |
|
|
private changeDetectorRef: ChangeDetectorRef, |
|
|
private dataService: DataService, |
|
|
private dataService: DataService, |
|
|
|
|
|
private destroyRef: DestroyRef, |
|
|
private deviceService: DeviceDetectorService, |
|
|
private deviceService: DeviceDetectorService, |
|
|
private dialog: MatDialog, |
|
|
private dialog: MatDialog, |
|
|
private icsService: IcsService, |
|
|
private icsService: IcsService, |
|
|
@ -76,13 +80,13 @@ export class GfActivitiesPageComponent implements OnDestroy, OnInit { |
|
|
private userService: UserService |
|
|
private userService: UserService |
|
|
) { |
|
|
) { |
|
|
this.routeQueryParams = route.queryParams |
|
|
this.routeQueryParams = route.queryParams |
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
.pipe(takeUntilDestroyed(this.destroyRef)) |
|
|
.subscribe((params) => { |
|
|
.subscribe((params) => { |
|
|
if (params['createDialog']) { |
|
|
if (params['createDialog']) { |
|
|
if (params['activityId']) { |
|
|
if (params['activityId']) { |
|
|
this.dataService |
|
|
this.dataService |
|
|
.fetchActivity(params['activityId']) |
|
|
.fetchActivity(params['activityId']) |
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
.pipe(takeUntilDestroyed(this.destroyRef)) |
|
|
.subscribe((activity) => { |
|
|
.subscribe((activity) => { |
|
|
this.openCreateActivityDialog(activity); |
|
|
this.openCreateActivityDialog(activity); |
|
|
}); |
|
|
}); |
|
|
@ -93,7 +97,7 @@ export class GfActivitiesPageComponent implements OnDestroy, OnInit { |
|
|
if (params['activityId']) { |
|
|
if (params['activityId']) { |
|
|
this.dataService |
|
|
this.dataService |
|
|
.fetchActivity(params['activityId']) |
|
|
.fetchActivity(params['activityId']) |
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
.pipe(takeUntilDestroyed(this.destroyRef)) |
|
|
.subscribe((activity) => { |
|
|
.subscribe((activity) => { |
|
|
this.openUpdateActivityDialog(activity); |
|
|
this.openUpdateActivityDialog(activity); |
|
|
}); |
|
|
}); |
|
|
@ -111,13 +115,13 @@ export class GfActivitiesPageComponent implements OnDestroy, OnInit { |
|
|
|
|
|
|
|
|
this.impersonationStorageService |
|
|
this.impersonationStorageService |
|
|
.onChangeHasImpersonation() |
|
|
.onChangeHasImpersonation() |
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
.pipe(takeUntilDestroyed(this.destroyRef)) |
|
|
.subscribe((impersonationId) => { |
|
|
.subscribe((impersonationId) => { |
|
|
this.hasImpersonationId = !!impersonationId; |
|
|
this.hasImpersonationId = !!impersonationId; |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
this.userService.stateChanged |
|
|
this.userService.stateChanged |
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
.pipe(takeUntilDestroyed(this.destroyRef)) |
|
|
.subscribe((state) => { |
|
|
.subscribe((state) => { |
|
|
if (state?.user) { |
|
|
if (state?.user) { |
|
|
this.updateUser(state.user); |
|
|
this.updateUser(state.user); |
|
|
@ -143,7 +147,7 @@ export class GfActivitiesPageComponent implements OnDestroy, OnInit { |
|
|
sortDirection: this.sortDirection, |
|
|
sortDirection: this.sortDirection, |
|
|
take: this.pageSize |
|
|
take: this.pageSize |
|
|
}) |
|
|
}) |
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
.pipe(takeUntilDestroyed(this.destroyRef)) |
|
|
.subscribe(({ activities, count }) => { |
|
|
.subscribe(({ activities, count }) => { |
|
|
this.dataSource = new MatTableDataSource(activities); |
|
|
this.dataSource = new MatTableDataSource(activities); |
|
|
this.totalItems = count; |
|
|
this.totalItems = count; |
|
|
@ -184,11 +188,11 @@ export class GfActivitiesPageComponent implements OnDestroy, OnInit { |
|
|
.deleteActivities({ |
|
|
.deleteActivities({ |
|
|
filters: this.userService.getFilters() |
|
|
filters: this.userService.getFilters() |
|
|
}) |
|
|
}) |
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
.pipe(takeUntilDestroyed(this.destroyRef)) |
|
|
.subscribe(() => { |
|
|
.subscribe(() => { |
|
|
this.userService |
|
|
this.userService |
|
|
.get(true) |
|
|
.get(true) |
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
.pipe(takeUntilDestroyed(this.destroyRef)) |
|
|
.subscribe(); |
|
|
.subscribe(); |
|
|
|
|
|
|
|
|
this.fetchActivities(); |
|
|
this.fetchActivities(); |
|
|
@ -198,11 +202,11 @@ export class GfActivitiesPageComponent implements OnDestroy, OnInit { |
|
|
public onDeleteActivity(aId: string) { |
|
|
public onDeleteActivity(aId: string) { |
|
|
this.dataService |
|
|
this.dataService |
|
|
.deleteActivity(aId) |
|
|
.deleteActivity(aId) |
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
.pipe(takeUntilDestroyed(this.destroyRef)) |
|
|
.subscribe(() => { |
|
|
.subscribe(() => { |
|
|
this.userService |
|
|
this.userService |
|
|
.get(true) |
|
|
.get(true) |
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
.pipe(takeUntilDestroyed(this.destroyRef)) |
|
|
.subscribe(); |
|
|
.subscribe(); |
|
|
|
|
|
|
|
|
this.fetchActivities(); |
|
|
this.fetchActivities(); |
|
|
@ -218,7 +222,7 @@ export class GfActivitiesPageComponent implements OnDestroy, OnInit { |
|
|
|
|
|
|
|
|
this.dataService |
|
|
this.dataService |
|
|
.fetchExport(fetchExportParams) |
|
|
.fetchExport(fetchExportParams) |
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
.pipe(takeUntilDestroyed(this.destroyRef)) |
|
|
.subscribe((data) => { |
|
|
.subscribe((data) => { |
|
|
for (const activity of data.activities) { |
|
|
for (const activity of data.activities) { |
|
|
delete activity.id; |
|
|
delete activity.id; |
|
|
@ -238,7 +242,7 @@ export class GfActivitiesPageComponent implements OnDestroy, OnInit { |
|
|
public onExportDrafts(activityIds?: string[]) { |
|
|
public onExportDrafts(activityIds?: string[]) { |
|
|
this.dataService |
|
|
this.dataService |
|
|
.fetchExport({ activityIds }) |
|
|
.fetchExport({ activityIds }) |
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
.pipe(takeUntilDestroyed(this.destroyRef)) |
|
|
.subscribe((data) => { |
|
|
.subscribe((data) => { |
|
|
downloadAsFile({ |
|
|
downloadAsFile({ |
|
|
content: this.icsService.transformActivitiesToIcsContent( |
|
|
content: this.icsService.transformActivitiesToIcsContent( |
|
|
@ -268,11 +272,11 @@ export class GfActivitiesPageComponent implements OnDestroy, OnInit { |
|
|
|
|
|
|
|
|
dialogRef |
|
|
dialogRef |
|
|
.afterClosed() |
|
|
.afterClosed() |
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
.pipe(takeUntilDestroyed(this.destroyRef)) |
|
|
.subscribe(() => { |
|
|
.subscribe(() => { |
|
|
this.userService |
|
|
this.userService |
|
|
.get(true) |
|
|
.get(true) |
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
.pipe(takeUntilDestroyed(this.destroyRef)) |
|
|
.subscribe(); |
|
|
.subscribe(); |
|
|
|
|
|
|
|
|
this.fetchActivities(); |
|
|
this.fetchActivities(); |
|
|
@ -295,11 +299,11 @@ export class GfActivitiesPageComponent implements OnDestroy, OnInit { |
|
|
|
|
|
|
|
|
dialogRef |
|
|
dialogRef |
|
|
.afterClosed() |
|
|
.afterClosed() |
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
.pipe(takeUntilDestroyed(this.destroyRef)) |
|
|
.subscribe(() => { |
|
|
.subscribe(() => { |
|
|
this.userService |
|
|
this.userService |
|
|
.get(true) |
|
|
.get(true) |
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
.pipe(takeUntilDestroyed(this.destroyRef)) |
|
|
.subscribe(); |
|
|
.subscribe(); |
|
|
|
|
|
|
|
|
this.fetchActivities(); |
|
|
this.fetchActivities(); |
|
|
@ -336,12 +340,12 @@ export class GfActivitiesPageComponent implements OnDestroy, OnInit { |
|
|
|
|
|
|
|
|
dialogRef |
|
|
dialogRef |
|
|
.afterClosed() |
|
|
.afterClosed() |
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
.pipe(takeUntilDestroyed(this.destroyRef)) |
|
|
.subscribe((activity: UpdateOrderDto) => { |
|
|
.subscribe((activity: UpdateOrderDto) => { |
|
|
if (activity) { |
|
|
if (activity) { |
|
|
this.dataService |
|
|
this.dataService |
|
|
.putActivity(activity) |
|
|
.putActivity(activity) |
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
.pipe(takeUntilDestroyed(this.destroyRef)) |
|
|
.subscribe({ |
|
|
.subscribe({ |
|
|
next: () => { |
|
|
next: () => { |
|
|
this.fetchActivities(); |
|
|
this.fetchActivities(); |
|
|
@ -353,11 +357,6 @@ export class GfActivitiesPageComponent implements OnDestroy, OnInit { |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public ngOnDestroy() { |
|
|
|
|
|
this.unsubscribeSubject.next(); |
|
|
|
|
|
this.unsubscribeSubject.complete(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private isCalendarYear(dateRange: DateRange) { |
|
|
private isCalendarYear(dateRange: DateRange) { |
|
|
if (!dateRange) { |
|
|
if (!dateRange) { |
|
|
return false; |
|
|
return false; |
|
|
@ -369,7 +368,7 @@ export class GfActivitiesPageComponent implements OnDestroy, OnInit { |
|
|
private openCreateActivityDialog(aActivity?: Activity) { |
|
|
private openCreateActivityDialog(aActivity?: Activity) { |
|
|
this.userService |
|
|
this.userService |
|
|
.get() |
|
|
.get() |
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
.pipe(takeUntilDestroyed(this.destroyRef)) |
|
|
.subscribe((user) => { |
|
|
.subscribe((user) => { |
|
|
this.updateUser(user); |
|
|
this.updateUser(user); |
|
|
|
|
|
|
|
|
@ -396,14 +395,14 @@ export class GfActivitiesPageComponent implements OnDestroy, OnInit { |
|
|
|
|
|
|
|
|
dialogRef |
|
|
dialogRef |
|
|
.afterClosed() |
|
|
.afterClosed() |
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
.pipe(takeUntilDestroyed(this.destroyRef)) |
|
|
.subscribe((transaction: CreateOrderDto | null) => { |
|
|
.subscribe((transaction: CreateOrderDto | null) => { |
|
|
if (transaction) { |
|
|
if (transaction) { |
|
|
this.dataService.postActivity(transaction).subscribe({ |
|
|
this.dataService.postActivity(transaction).subscribe({ |
|
|
next: () => { |
|
|
next: () => { |
|
|
this.userService |
|
|
this.userService |
|
|
.get(true) |
|
|
.get(true) |
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
.pipe(takeUntilDestroyed(this.destroyRef)) |
|
|
.subscribe(); |
|
|
.subscribe(); |
|
|
|
|
|
|
|
|
this.fetchActivities(); |
|
|
this.fetchActivities(); |
|
|
|