From 12aac101bd0e0467d74a0c3baf4a18307d03aae4 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Thu, 9 Nov 2023 19:23:36 +0100 Subject: [PATCH] Feature/extend system message (#2628) * Extend system message * Update changelog --- CHANGELOG.md | 4 +++ apps/api/src/app/info/info.service.ts | 7 ---- apps/api/src/app/user/user.service.ts | 19 ++++++++++- apps/client/src/app/app.component.html | 8 ++--- apps/client/src/app/app.component.ts | 17 +++++----- .../admin-overview.component.ts | 32 ++++++++++++++++--- .../admin-overview/admin-overview.html | 5 +-- libs/common/src/lib/interfaces/index.ts | 2 ++ .../src/lib/interfaces/info-item.interface.ts | 1 - .../interfaces/system-message.interface.ts | 7 ++++ .../src/lib/interfaces/user.interface.ts | 2 ++ 11 files changed, 77 insertions(+), 27 deletions(-) create mode 100644 libs/common/src/lib/interfaces/system-message.interface.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index a38fc82ad..1daee99af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Changed + +- Extended the system message + ### Fixed - Fixed the unit for the _Zen Mode_ in the overview tab of the home page diff --git a/apps/api/src/app/info/info.service.ts b/apps/api/src/app/info/info.service.ts index 4fc4aec4e..744e86c9c 100644 --- a/apps/api/src/app/info/info.service.ts +++ b/apps/api/src/app/info/info.service.ts @@ -15,7 +15,6 @@ import { PROPERTY_IS_READ_ONLY_MODE, PROPERTY_SLACK_COMMUNITY_USERS, PROPERTY_STRIPE_CONFIG, - PROPERTY_SYSTEM_MESSAGE, ghostfolioFearAndGreedIndexDataSource } from '@ghostfolio/common/config'; import { @@ -58,7 +57,6 @@ export class InfoService { const platforms = await this.platformService.getPlatforms({ orderBy: { name: 'asc' } }); - let systemMessage: string; const globalPermissions: string[] = []; @@ -104,10 +102,6 @@ export class InfoService { if (this.configurationService.get('ENABLE_FEATURE_SYSTEM_MESSAGE')) { globalPermissions.push(permissions.enableSystemMessage); - - systemMessage = (await this.propertyService.getByKey( - PROPERTY_SYSTEM_MESSAGE - )) as string; } const isUserSignupEnabled = @@ -135,7 +129,6 @@ export class InfoService { platforms, statistics, subscriptions, - systemMessage, tags, baseCurrency: DEFAULT_CURRENCY, currencies: this.exchangeRateDataService.getCurrencies() diff --git a/apps/api/src/app/user/user.service.ts b/apps/api/src/app/user/user.service.ts index 91490528e..f9f39b185 100644 --- a/apps/api/src/app/user/user.service.ts +++ b/apps/api/src/app/user/user.service.ts @@ -7,9 +7,14 @@ import { TagService } from '@ghostfolio/api/services/tag/tag.service'; import { DEFAULT_CURRENCY, PROPERTY_IS_READ_ONLY_MODE, + PROPERTY_SYSTEM_MESSAGE, locale } from '@ghostfolio/common/config'; -import { User as IUser, UserSettings } from '@ghostfolio/common/interfaces'; +import { + User as IUser, + SystemMessage, + UserSettings +} from '@ghostfolio/common/interfaces'; import { getPermissions, hasRole, @@ -48,6 +53,17 @@ export class UserService { orderBy: { alias: 'asc' }, where: { GranteeUser: { id } } }); + + let systemMessage: SystemMessage; + + const systemMessageProperty = (await this.propertyService.getByKey( + PROPERTY_SYSTEM_MESSAGE + )) as SystemMessage; + + if (systemMessageProperty?.targetGroups?.includes(subscription.type)) { + systemMessage = systemMessageProperty; + } + let tags = await this.tagService.getByUser(id); if ( @@ -61,6 +77,7 @@ export class UserService { id, permissions, subscription, + systemMessage, tags, access: access.map((accessItem) => { return { diff --git a/apps/client/src/app/app.component.html b/apps/client/src/app/app.component.html index e792598a7..c6ff195f1 100644 --- a/apps/client/src/app/app.component.html +++ b/apps/client/src/app/app.component.html @@ -1,6 +1,6 @@
@@ -19,11 +19,11 @@
- {{ info.systemMessage }} + {{ user.systemMessage.message }}
diff --git a/apps/client/src/app/app.component.ts b/apps/client/src/app/app.component.ts index 2317279b1..1cf4e4b4d 100644 --- a/apps/client/src/app/app.component.ts +++ b/apps/client/src/app/app.component.ts @@ -155,10 +155,7 @@ export class AppComponent implements OnDestroy, OnInit { ); this.hasInfoMessage = - hasPermission( - this.user?.permissions, - permissions.createUserAccount - ) || !!this.info.systemMessage; + this.canCreateAccount || !!this.user?.systemMessage; this.initializeTheme(this.user?.settings.colorScheme); @@ -166,12 +163,16 @@ export class AppComponent implements OnDestroy, OnInit { }); } - public onCreateAccount() { - this.tokenStorageService.signOut(); + public onClickSystemMessage() { + if (this.user.systemMessage.routerLink) { + this.router.navigate(this.user.systemMessage.routerLink); + } else { + alert(this.user.systemMessage.message); + } } - public onShowSystemMessage() { - alert(this.info.systemMessage); + public onCreateAccount() { + this.tokenStorageService.signOut(); } public onSignOut() { diff --git a/apps/client/src/app/components/admin-overview/admin-overview.component.ts b/apps/client/src/app/components/admin-overview/admin-overview.component.ts index 6c4c72f70..0ab1cb27b 100644 --- a/apps/client/src/app/components/admin-overview/admin-overview.component.ts +++ b/apps/client/src/app/components/admin-overview/admin-overview.component.ts @@ -12,7 +12,12 @@ import { PROPERTY_SYSTEM_MESSAGE, ghostfolioPrefix } from '@ghostfolio/common/config'; -import { Coupon, InfoItem, User } from '@ghostfolio/common/interfaces'; +import { + Coupon, + InfoItem, + SystemMessage, + User +} from '@ghostfolio/common/interfaces'; import { hasPermission, permissions } from '@ghostfolio/common/permissions'; import { differenceInSeconds, @@ -39,6 +44,7 @@ export class AdminOverviewComponent implements OnDestroy, OnInit { public hasPermissionToToggleReadOnlyMode: boolean; public info: InfoItem; public permissions = permissions; + public systemMessage: SystemMessage; public transactionCount: number; public userCount: number; public user: User; @@ -149,7 +155,13 @@ export class AdminOverviewComponent implements OnDestroy, OnInit { } public onDeleteSystemMessage() { - this.putAdminSetting({ key: PROPERTY_SYSTEM_MESSAGE, value: undefined }); + const confirmation = confirm( + $localize`Do you really want to delete this system message?` + ); + + if (confirmation === true) { + this.putAdminSetting({ key: PROPERTY_SYSTEM_MESSAGE, value: undefined }); + } } public onFlushCache() { @@ -184,12 +196,21 @@ export class AdminOverviewComponent implements OnDestroy, OnInit { } public onSetSystemMessage() { - const systemMessage = prompt($localize`Please set your system message:`); + const systemMessage = prompt( + $localize`Please set your system message:`, + JSON.stringify( + this.systemMessage ?? + { + message: '⚒️ Scheduled maintenance in progress...', + targetGroups: ['Basic', 'Premium'] + } + ) + ); if (systemMessage) { this.putAdminSetting({ key: PROPERTY_SYSTEM_MESSAGE, - value: systemMessage + value: JSON.parse(systemMessage) }); } } @@ -208,6 +229,9 @@ export class AdminOverviewComponent implements OnDestroy, OnInit { this.coupons = (settings[PROPERTY_COUPONS] as Coupon[]) ?? []; this.customCurrencies = settings[PROPERTY_CURRENCIES] as string[]; this.exchangeRates = exchangeRates; + this.systemMessage = settings[ + PROPERTY_SYSTEM_MESSAGE + ] as SystemMessage; this.transactionCount = transactionCount; this.userCount = userCount; this.version = version; diff --git a/apps/client/src/app/components/admin-overview/admin-overview.html b/apps/client/src/app/components/admin-overview/admin-overview.html index e82f787f9..da14baea0 100644 --- a/apps/client/src/app/components/admin-overview/admin-overview.html +++ b/apps/client/src/app/components/admin-overview/admin-overview.html @@ -115,8 +115,8 @@
System Message
-
- {{ info.systemMessage }} +
+
{{ systemMessage | json }}