Browse Source

Feature/reuse notification service for confirm dialogs (#3671)

* Reuse notification service for confirm dialogs
pull/3676/head
Daniel Idem 5 months ago
committed by GitHub
parent
commit
952c2b71a2
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 16
      apps/client/src/app/components/access-table/access-table.component.ts
  2. 28
      apps/client/src/app/components/admin-market-data/admin-market-data.service.ts
  3. 54
      apps/client/src/app/components/admin-overview/admin-overview.component.ts
  4. 15
      apps/client/src/app/components/admin-platform/admin-platform.component.ts
  5. 15
      apps/client/src/app/components/admin-tag/admin-tag.component.ts
  6. 19
      apps/client/src/app/components/admin-users/admin-users.component.ts
  7. 28
      apps/client/src/app/components/user-account-settings/user-account-settings.component.ts
  8. 19
      libs/ui/src/lib/account-balances/account-balances.component.ts
  9. 25
      libs/ui/src/lib/activities-table/activities-table.component.ts

16
apps/client/src/app/components/access-table/access-table.component.ts

@ -1,3 +1,5 @@
import { ConfirmationDialogType } from '@ghostfolio/client/core/notification/confirmation-dialog/confirmation-dialog.type';
import { NotificationService } from '@ghostfolio/client/core/notification/notification.service';
import { DEFAULT_LANGUAGE_CODE } from '@ghostfolio/common/config'; import { DEFAULT_LANGUAGE_CODE } from '@ghostfolio/common/config';
import { Access } from '@ghostfolio/common/interfaces'; import { Access } from '@ghostfolio/common/interfaces';
@ -29,7 +31,7 @@ export class AccessTableComponent implements OnChanges, OnInit {
public defaultLanguageCode = DEFAULT_LANGUAGE_CODE; public defaultLanguageCode = DEFAULT_LANGUAGE_CODE;
public displayedColumns = []; public displayedColumns = [];
public constructor() {} public constructor(private notificationService: NotificationService) {}
public ngOnInit() {} public ngOnInit() {}
@ -46,12 +48,12 @@ export class AccessTableComponent implements OnChanges, OnInit {
} }
public onDeleteAccess(aId: string) { public onDeleteAccess(aId: string) {
const confirmation = confirm( this.notificationService.confirm({
$localize`Do you really want to revoke this granted access?` confirmFn: () => {
);
if (confirmation) {
this.accessDeleted.emit(aId); this.accessDeleted.emit(aId);
} },
confirmType: ConfirmationDialogType.Warn,
title: $localize`Do you really want to revoke this granted access?`
});
} }
} }

28
apps/client/src/app/components/admin-market-data/admin-market-data.service.ts

@ -1,3 +1,4 @@
import { ConfirmationDialogType } from '@ghostfolio/client/core/notification/confirmation-dialog/confirmation-dialog.type';
import { NotificationService } from '@ghostfolio/client/core/notification/notification.service'; import { NotificationService } from '@ghostfolio/client/core/notification/notification.service';
import { AdminService } from '@ghostfolio/client/services/admin.service'; import { AdminService } from '@ghostfolio/client/services/admin.service';
import { ghostfolioScraperApiSymbolPrefix } from '@ghostfolio/common/config'; import { ghostfolioScraperApiSymbolPrefix } from '@ghostfolio/common/config';
@ -18,11 +19,8 @@ export class AdminMarketDataService {
) {} ) {}
public deleteAssetProfile({ dataSource, symbol }: AssetProfileIdentifier) { public deleteAssetProfile({ dataSource, symbol }: AssetProfileIdentifier) {
const confirmation = confirm( this.notificationService.confirm({
$localize`Do you really want to delete this asset profile?` confirmFn: () => {
);
if (confirmation) {
this.adminService this.adminService
.deleteProfileData({ dataSource, symbol }) .deleteProfileData({ dataSource, symbol })
.subscribe(() => { .subscribe(() => {
@ -30,17 +28,17 @@ export class AdminMarketDataService {
window.location.reload(); window.location.reload();
}, 300); }, 300);
}); });
} },
confirmType: ConfirmationDialogType.Warn,
title: $localize`Do you really want to delete this asset profile?`
});
} }
public deleteAssetProfiles( public deleteAssetProfiles(
aAssetProfileIdentifiers: AssetProfileIdentifier[] aAssetProfileIdentifiers: AssetProfileIdentifier[]
) { ) {
const confirmation = confirm( this.notificationService.confirm({
$localize`Do you really want to delete these profiles?` confirmFn: () => {
);
if (confirmation) {
const deleteRequests = aAssetProfileIdentifiers.map( const deleteRequests = aAssetProfileIdentifiers.map(
({ dataSource, symbol }) => { ({ dataSource, symbol }) => {
return this.adminService.deleteProfileData({ dataSource, symbol }); return this.adminService.deleteProfileData({ dataSource, symbol });
@ -57,13 +55,15 @@ export class AdminMarketDataService {
return EMPTY; return EMPTY;
}), }),
finalize(() => { finalize(() => {
setTimeout(() => {
window.location.reload(); window.location.reload();
}, 300); setTimeout(() => {}, 300);
}) })
) )
.subscribe(() => {}); .subscribe(() => {});
} },
confirmType: ConfirmationDialogType.Warn,
title: $localize`Do you really want to delete these profiles?`
});
} }
public hasPermissionToDeleteAssetProfile({ public hasPermissionToDeleteAssetProfile({

54
apps/client/src/app/components/admin-overview/admin-overview.component.ts

@ -1,3 +1,4 @@
import { ConfirmationDialogType } from '@ghostfolio/client/core/notification/confirmation-dialog/confirmation-dialog.type';
import { NotificationService } from '@ghostfolio/client/core/notification/notification.service'; import { NotificationService } from '@ghostfolio/client/core/notification/notification.service';
import { AdminService } from '@ghostfolio/client/services/admin.service'; import { AdminService } from '@ghostfolio/client/services/admin.service';
import { CacheService } from '@ghostfolio/client/services/cache.service'; import { CacheService } from '@ghostfolio/client/services/cache.service';
@ -140,39 +141,42 @@ export class AdminOverviewComponent implements OnDestroy, OnInit {
} }
public onDeleteCoupon(aCouponCode: string) { public onDeleteCoupon(aCouponCode: string) {
const confirmation = confirm( this.notificationService.confirm({
$localize`Do you really want to delete this coupon?` confirmFn: () => {
);
if (confirmation === true) {
const coupons = this.coupons.filter((coupon) => { const coupons = this.coupons.filter((coupon) => {
return coupon.code !== aCouponCode; return coupon.code !== aCouponCode;
}); });
this.putAdminSetting({ key: PROPERTY_COUPONS, value: coupons }); this.putAdminSetting({ key: PROPERTY_COUPONS, value: coupons });
} },
confirmType: ConfirmationDialogType.Warn,
title: $localize`Do you really want to delete this coupon?`
});
} }
public onDeleteCurrency(aCurrency: string) { public onDeleteCurrency(aCurrency: string) {
const confirmation = confirm( this.notificationService.confirm({
$localize`Do you really want to delete this currency?` confirmFn: () => {
);
if (confirmation === true) {
const currencies = this.customCurrencies.filter((currency) => { const currencies = this.customCurrencies.filter((currency) => {
return currency !== aCurrency; return currency !== aCurrency;
}); });
this.putAdminSetting({ key: PROPERTY_CURRENCIES, value: currencies }); this.putAdminSetting({ key: PROPERTY_CURRENCIES, value: currencies });
} },
confirmType: ConfirmationDialogType.Warn,
title: $localize`Do you really want to delete this currency?`
});
} }
public onDeleteSystemMessage() { public onDeleteSystemMessage() {
const confirmation = confirm( this.notificationService.confirm({
$localize`Do you really want to delete this system message?` confirmFn: () => {
); this.putAdminSetting({
key: PROPERTY_SYSTEM_MESSAGE,
if (confirmation === true) { value: undefined
this.putAdminSetting({ key: PROPERTY_SYSTEM_MESSAGE, value: undefined }); });
} },
confirmType: ConfirmationDialogType.Warn,
title: $localize`Do you really want to delete this system message?`
});
} }
public onEnableDataGatheringChange(aEvent: MatSlideToggleChange) { public onEnableDataGatheringChange(aEvent: MatSlideToggleChange) {
@ -183,11 +187,8 @@ export class AdminOverviewComponent implements OnDestroy, OnInit {
} }
public onFlushCache() { public onFlushCache() {
const confirmation = confirm( this.notificationService.confirm({
$localize`Do you really want to flush the cache?` confirmFn: () => {
);
if (confirmation === true) {
this.cacheService this.cacheService
.flush() .flush()
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntil(this.unsubscribeSubject))
@ -196,7 +197,10 @@ export class AdminOverviewComponent implements OnDestroy, OnInit {
window.location.reload(); window.location.reload();
}, 300); }, 300);
}); });
} },
confirmType: ConfirmationDialogType.Warn,
title: $localize`Do you really want to flush the cache?`
});
} }
public onEnableUserSignupModeChange(aEvent: MatSlideToggleChange) { public onEnableUserSignupModeChange(aEvent: MatSlideToggleChange) {

15
apps/client/src/app/components/admin-platform/admin-platform.component.ts

@ -1,5 +1,7 @@
import { CreatePlatformDto } from '@ghostfolio/api/app/platform/create-platform.dto'; import { CreatePlatformDto } from '@ghostfolio/api/app/platform/create-platform.dto';
import { UpdatePlatformDto } from '@ghostfolio/api/app/platform/update-platform.dto'; import { UpdatePlatformDto } from '@ghostfolio/api/app/platform/update-platform.dto';
import { ConfirmationDialogType } from '@ghostfolio/client/core/notification/confirmation-dialog/confirmation-dialog.type';
import { NotificationService } from '@ghostfolio/client/core/notification/notification.service';
import { AdminService } from '@ghostfolio/client/services/admin.service'; import { AdminService } from '@ghostfolio/client/services/admin.service';
import { DataService } from '@ghostfolio/client/services/data.service'; import { DataService } from '@ghostfolio/client/services/data.service';
import { UserService } from '@ghostfolio/client/services/user/user.service'; import { UserService } from '@ghostfolio/client/services/user/user.service';
@ -45,6 +47,7 @@ export class AdminPlatformComponent implements OnInit, OnDestroy {
private dataService: DataService, private dataService: DataService,
private deviceService: DeviceDetectorService, private deviceService: DeviceDetectorService,
private dialog: MatDialog, private dialog: MatDialog,
private notificationService: NotificationService,
private route: ActivatedRoute, private route: ActivatedRoute,
private router: Router, private router: Router,
private userService: UserService private userService: UserService
@ -75,13 +78,13 @@ export class AdminPlatformComponent implements OnInit, OnDestroy {
} }
public onDeletePlatform(aId: string) { public onDeletePlatform(aId: string) {
const confirmation = confirm( this.notificationService.confirm({
$localize`Do you really want to delete this platform?` confirmFn: () => {
);
if (confirmation) {
this.deletePlatform(aId); this.deletePlatform(aId);
} },
confirmType: ConfirmationDialogType.Warn,
title: $localize`Do you really want to delete this platform?`
});
} }
public onUpdatePlatform({ id }: Platform) { public onUpdatePlatform({ id }: Platform) {

15
apps/client/src/app/components/admin-tag/admin-tag.component.ts

@ -1,5 +1,7 @@
import { CreateTagDto } from '@ghostfolio/api/app/tag/create-tag.dto'; import { CreateTagDto } from '@ghostfolio/api/app/tag/create-tag.dto';
import { UpdateTagDto } from '@ghostfolio/api/app/tag/update-tag.dto'; import { UpdateTagDto } from '@ghostfolio/api/app/tag/update-tag.dto';
import { ConfirmationDialogType } from '@ghostfolio/client/core/notification/confirmation-dialog/confirmation-dialog.type';
import { NotificationService } from '@ghostfolio/client/core/notification/notification.service';
import { AdminService } from '@ghostfolio/client/services/admin.service'; import { AdminService } from '@ghostfolio/client/services/admin.service';
import { DataService } from '@ghostfolio/client/services/data.service'; import { DataService } from '@ghostfolio/client/services/data.service';
import { UserService } from '@ghostfolio/client/services/user/user.service'; import { UserService } from '@ghostfolio/client/services/user/user.service';
@ -45,6 +47,7 @@ export class AdminTagComponent implements OnInit, OnDestroy {
private dataService: DataService, private dataService: DataService,
private deviceService: DeviceDetectorService, private deviceService: DeviceDetectorService,
private dialog: MatDialog, private dialog: MatDialog,
private notificationService: NotificationService,
private route: ActivatedRoute, private route: ActivatedRoute,
private router: Router, private router: Router,
private userService: UserService private userService: UserService
@ -75,13 +78,13 @@ export class AdminTagComponent implements OnInit, OnDestroy {
} }
public onDeleteTag(aId: string) { public onDeleteTag(aId: string) {
const confirmation = confirm( this.notificationService.confirm({
$localize`Do you really want to delete this tag?` confirmFn: () => {
);
if (confirmation) {
this.deleteTag(aId); this.deleteTag(aId);
} },
confirmType: ConfirmationDialogType.Warn,
title: $localize`Do you really want to delete this tag?`
});
} }
public onUpdateTag({ id }: Tag) { public onUpdateTag({ id }: Tag) {

19
apps/client/src/app/components/admin-users/admin-users.component.ts

@ -1,3 +1,5 @@
import { ConfirmationDialogType } from '@ghostfolio/client/core/notification/confirmation-dialog/confirmation-dialog.type';
import { NotificationService } from '@ghostfolio/client/core/notification/notification.service';
import { AdminService } from '@ghostfolio/client/services/admin.service'; import { AdminService } from '@ghostfolio/client/services/admin.service';
import { DataService } from '@ghostfolio/client/services/data.service'; import { DataService } from '@ghostfolio/client/services/data.service';
import { ImpersonationStorageService } from '@ghostfolio/client/services/impersonation-storage.service'; import { ImpersonationStorageService } from '@ghostfolio/client/services/impersonation-storage.service';
@ -39,6 +41,7 @@ export class AdminUsersComponent implements OnDestroy, OnInit {
private changeDetectorRef: ChangeDetectorRef, private changeDetectorRef: ChangeDetectorRef,
private dataService: DataService, private dataService: DataService,
private impersonationStorageService: ImpersonationStorageService, private impersonationStorageService: ImpersonationStorageService,
private notificationService: NotificationService,
private userService: UserService private userService: UserService
) { ) {
this.info = this.dataService.fetchInfo(); this.info = this.dataService.fetchInfo();
@ -109,20 +112,18 @@ export class AdminUsersComponent implements OnDestroy, OnInit {
} }
public onDeleteUser(aId: string) { public onDeleteUser(aId: string) {
const confirmation = confirm( this.notificationService.confirm({
$localize`Do you really want to delete this user?` confirmFn: () => {
);
if (confirmation) {
this.dataService this.dataService
.deleteUser(aId) .deleteUser(aId)
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntil(this.unsubscribeSubject))
.subscribe({ .subscribe(() => {
next: () => {
this.fetchAdminData(); this.fetchAdminData();
}
}); });
} },
confirmType: ConfirmationDialogType.Warn,
title: $localize`Do you really want to delete this user?`
});
} }
public onImpersonateUser(aId: string) { public onImpersonateUser(aId: string) {

28
apps/client/src/app/components/user-account-settings/user-account-settings.component.ts

@ -1,3 +1,4 @@
import { ConfirmationDialogType } from '@ghostfolio/client/core/notification/confirmation-dialog/confirmation-dialog.type';
import { NotificationService } from '@ghostfolio/client/core/notification/notification.service'; import { NotificationService } from '@ghostfolio/client/core/notification/notification.service';
import { DataService } from '@ghostfolio/client/services/data.service'; import { DataService } from '@ghostfolio/client/services/data.service';
import { import {
@ -146,11 +147,8 @@ export class UserAccountSettingsComponent implements OnDestroy, OnInit {
} }
public onCloseAccount() { public onCloseAccount() {
const confirmation = confirm( this.notificationService.confirm({
$localize`Do you really want to close your Ghostfolio account?` confirmFn: () => {
);
if (confirmation) {
this.dataService this.dataService
.deleteOwnUser({ .deleteOwnUser({
accessToken: this.deleteOwnUserForm.get('accessToken').value accessToken: this.deleteOwnUserForm.get('accessToken').value
@ -171,7 +169,10 @@ export class UserAccountSettingsComponent implements OnDestroy, OnInit {
document.location.href = `/${document.documentElement.lang}`; document.location.href = `/${document.documentElement.lang}`;
}); });
} },
confirmType: ConfirmationDialogType.Warn,
title: $localize`Do you really want to close your Ghostfolio account?`
});
} }
public onExperimentalFeaturesChange(aEvent: MatSlideToggleChange) { public onExperimentalFeaturesChange(aEvent: MatSlideToggleChange) {
@ -240,15 +241,16 @@ export class UserAccountSettingsComponent implements OnDestroy, OnInit {
this.changeDetectorRef.markForCheck(); this.changeDetectorRef.markForCheck();
} }
} else { } else {
const confirmation = confirm( this.notificationService.confirm({
$localize`Do you really want to remove this sign in method?` confirmFn: () => {
);
if (confirmation) {
this.deregisterDevice(); this.deregisterDevice();
} else { },
discardFn: () => {
this.update(); this.update();
} },
confirmType: ConfirmationDialogType.Warn,
title: $localize`Do you really want to remove this sign in method?`
});
} }
} }

19
libs/ui/src/lib/account-balances/account-balances.component.ts

@ -1,4 +1,6 @@
import { CreateAccountBalanceDto } from '@ghostfolio/api/app/account-balance/create-account-balance.dto'; import { CreateAccountBalanceDto } from '@ghostfolio/api/app/account-balance/create-account-balance.dto';
import { ConfirmationDialogType } from '@ghostfolio/client/core/notification/confirmation-dialog/confirmation-dialog.type';
import { NotificationService } from '@ghostfolio/client/core/notification/notification.service';
import { validateObjectForForm } from '@ghostfolio/client/util/form.util'; import { validateObjectForForm } from '@ghostfolio/client/util/form.util';
import { getLocale } from '@ghostfolio/common/helper'; import { getLocale } from '@ghostfolio/common/helper';
import { AccountBalancesResponse } from '@ghostfolio/common/interfaces'; import { AccountBalancesResponse } from '@ghostfolio/common/interfaces';
@ -81,7 +83,10 @@ export class GfAccountBalancesComponent
private unsubscribeSubject = new Subject<void>(); private unsubscribeSubject = new Subject<void>();
public constructor(private dateAdapter: DateAdapter<any>) {} public constructor(
private dateAdapter: DateAdapter<any>,
private notificationService: NotificationService
) {}
public ngOnInit() { public ngOnInit() {
this.dateAdapter.setLocale(this.locale); this.dateAdapter.setLocale(this.locale);
@ -97,13 +102,13 @@ export class GfAccountBalancesComponent
} }
public onDeleteAccountBalance(aId: string) { public onDeleteAccountBalance(aId: string) {
const confirmation = confirm( this.notificationService.confirm({
$localize`Do you really want to delete this account balance?` confirmFn: () => {
);
if (confirmation) {
this.accountBalanceDeleted.emit(aId); this.accountBalanceDeleted.emit(aId);
} },
confirmType: ConfirmationDialogType.Warn,
title: $localize`Do you really want to delete this account balance?`
});
} }
public async onSubmitAccountBalance() { public async onSubmitAccountBalance() {

25
libs/ui/src/lib/activities-table/activities-table.component.ts

@ -1,5 +1,6 @@
import { Activity } from '@ghostfolio/api/app/order/interfaces/activities.interface'; import { Activity } from '@ghostfolio/api/app/order/interfaces/activities.interface';
import { GfAssetProfileIconComponent } from '@ghostfolio/client/components/asset-profile-icon/asset-profile-icon.component'; import { GfAssetProfileIconComponent } from '@ghostfolio/client/components/asset-profile-icon/asset-profile-icon.component';
import { ConfirmationDialogType } from '@ghostfolio/client/core/notification/confirmation-dialog/confirmation-dialog.type';
import { NotificationService } from '@ghostfolio/client/core/notification/notification.service'; import { NotificationService } from '@ghostfolio/client/core/notification/notification.service';
import { GfSymbolModule } from '@ghostfolio/client/pipes/symbol/symbol.module'; import { GfSymbolModule } from '@ghostfolio/client/pipes/symbol/symbol.module';
import { DEFAULT_PAGE_SIZE } from '@ghostfolio/common/config'; import { DEFAULT_PAGE_SIZE } from '@ghostfolio/common/config';
@ -216,23 +217,23 @@ export class GfActivitiesTableComponent
} }
public onDeleteActivities() { public onDeleteActivities() {
const confirmation = confirm( this.notificationService.confirm({
$localize`Do you really want to delete these activities?` confirmFn: () => {
);
if (confirmation) {
this.activitiesDeleted.emit(); this.activitiesDeleted.emit();
} },
confirmType: ConfirmationDialogType.Warn,
title: $localize`Do you really want to delete these activities?`
});
} }
public onDeleteActivity(aId: string) { public onDeleteActivity(aId: string) {
const confirmation = confirm( this.notificationService.confirm({
$localize`Do you really want to delete this activity?` confirmFn: () => {
);
if (confirmation) {
this.activityDeleted.emit(aId); this.activityDeleted.emit(aId);
} },
confirmType: ConfirmationDialogType.Warn,
title: $localize`Do you really want to delete this activity?`
});
} }
public onExport() { public onExport() {

Loading…
Cancel
Save