-
+
- + +
+ {{ info.systemMessage }} +
diff --git a/apps/client/src/app/app.component.scss b/apps/client/src/app/app.component.scss index bcefe5d71..9afa6eaab 100644 --- a/apps/client/src/app/app.component.scss +++ b/apps/client/src/app/app.component.scss @@ -8,14 +8,13 @@ min-height: 100vh; padding-top: 5rem; - .create-account-container { + .info-message-container { height: 3.5rem; margin-top: -0.5rem; - .create-account-box { + .info-message { background-color: rgba(0, 0, 0, $alpha-hover); border-radius: 2rem; - cursor: pointer; font-size: 80%; a { 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 ce4a9cd53..76c78378a 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 @@ -5,9 +5,11 @@ import { DataService } from '@ghostfolio/client/services/data.service'; import { UserService } from '@ghostfolio/client/services/user/user.service'; import { DEFAULT_DATE_FORMAT, - PROPERTY_CURRENCIES + PROPERTY_CURRENCIES, + PROPERTY_SYSTEM_MESSAGE } from '@ghostfolio/common/config'; -import { User } from '@ghostfolio/common/interfaces'; +import { InfoItem, User } from '@ghostfolio/common/interfaces'; +import { hasPermission, permissions } from '@ghostfolio/common/permissions'; import { differenceInSeconds, formatDistanceToNowStrict, @@ -29,6 +31,8 @@ export class AdminOverviewComponent implements OnDestroy, OnInit { public dataGatheringProgress: number; public defaultDateFormat = DEFAULT_DATE_FORMAT; public exchangeRates: { label1: string; label2: string; value: number }[]; + public hasPermissionForSystemMessage: boolean; + public info: InfoItem; public lastDataGathering: string; public transactionCount: number; public userCount: number; @@ -45,7 +49,14 @@ export class AdminOverviewComponent implements OnDestroy, OnInit { private changeDetectorRef: ChangeDetectorRef, private dataService: DataService, private userService: UserService - ) {} + ) { + this.info = this.dataService.fetchInfo(); + + this.hasPermissionForSystemMessage = hasPermission( + this.info.globalPermissions, + permissions.enableSystemMessage + ); + } /** * Initializes the controller @@ -62,6 +73,21 @@ export class AdminOverviewComponent implements OnDestroy, OnInit { }); } + public formatDistanceToNow(aDateString: string) { + if (aDateString) { + const distanceString = formatDistanceToNowStrict(parseISO(aDateString), { + addSuffix: true + }); + + return Math.abs(differenceInSeconds(parseISO(aDateString), new Date())) < + 60 + ? 'just now' + : distanceString; + } + + return ''; + } + public onAddCurrency() { const currency = prompt('Please add a currency:'); @@ -82,6 +108,10 @@ export class AdminOverviewComponent implements OnDestroy, OnInit { } } + public onDeleteSystemMessage() { + this.putSystemMessage(''); + } + public onFlushCache() { this.cacheService .flush() @@ -117,19 +147,12 @@ export class AdminOverviewComponent implements OnDestroy, OnInit { .subscribe(() => {}); } - public formatDistanceToNow(aDateString: string) { - if (aDateString) { - const distanceString = formatDistanceToNowStrict(parseISO(aDateString), { - addSuffix: true - }); + public onSetSystemMessage() { + const systemMessage = prompt('Please set your system message:'); - return Math.abs(differenceInSeconds(parseISO(aDateString), new Date())) < - 60 - ? 'just now' - : distanceString; + if (systemMessage) { + this.putSystemMessage(systemMessage); } - - return ''; } public ngOnDestroy() { @@ -187,4 +210,17 @@ export class AdminOverviewComponent implements OnDestroy, OnInit { }, 300); }); } + + private putSystemMessage(aSystemMessage: string) { + this.dataService + .putAdminSetting(PROPERTY_SYSTEM_MESSAGE, { + value: aSystemMessage + }) + .pipe(takeUntil(this.unsubscribeSubject)) + .subscribe(() => { + setTimeout(() => { + window.location.reload(); + }, 300); + }); + } } 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 3d702ac90..ca81b5143 100644 --- a/apps/client/src/app/components/admin-overview/admin-overview.html +++ b/apps/client/src/app/components/admin-overview/admin-overview.html @@ -118,6 +118,34 @@
+
+
System Message
+
+
+ {{ info.systemMessage }} + +
+ +
+
diff --git a/apps/client/src/app/pages/admin/admin-page.component.ts b/apps/client/src/app/pages/admin/admin-page.component.ts index 9865e23c3..8d1e10797 100644 --- a/apps/client/src/app/pages/admin/admin-page.component.ts +++ b/apps/client/src/app/pages/admin/admin-page.component.ts @@ -1,4 +1,5 @@ -import { Component, OnDestroy, OnInit } from '@angular/core'; +import { Component, HostBinding, OnDestroy, OnInit } from '@angular/core'; +import { DataService } from '@ghostfolio/client/services/data.service'; import { Subject } from 'rxjs'; @Component({ @@ -7,12 +8,22 @@ import { Subject } from 'rxjs'; templateUrl: './admin-page.html' }) export class AdminPageComponent implements OnDestroy, OnInit { + @HostBinding('class.with-info-message') get getHasMessage() { + return this.hasMessage; + } + + public hasMessage: boolean; + private unsubscribeSubject = new Subject(); /** * @constructor */ - public constructor() {} + public constructor(private dataService: DataService) { + const { systemMessage } = this.dataService.fetchInfo(); + + this.hasMessage = !!systemMessage; + } /** * Initializes the controller diff --git a/apps/client/src/app/pages/home/home-page.component.ts b/apps/client/src/app/pages/home/home-page.component.ts index 06e533236..213c3854a 100644 --- a/apps/client/src/app/pages/home/home-page.component.ts +++ b/apps/client/src/app/pages/home/home-page.component.ts @@ -5,11 +5,10 @@ import { OnDestroy, OnInit } from '@angular/core'; -import { ImpersonationStorageService } from '@ghostfolio/client/services/impersonation-storage.service'; +import { DataService } from '@ghostfolio/client/services/data.service'; import { UserService } from '@ghostfolio/client/services/user/user.service'; import { User } from '@ghostfolio/common/interfaces'; import { hasPermission, permissions } from '@ghostfolio/common/permissions'; -import { DeviceDetectorService } from 'ngx-device-detector'; import { Subject } from 'rxjs'; import { takeUntil } from 'rxjs/operators'; @@ -19,11 +18,11 @@ import { takeUntil } from 'rxjs/operators'; templateUrl: './home-page.html' }) export class HomePageComponent implements OnDestroy, OnInit { - @HostBinding('class.with-create-account-container') get isDemo() { - return this.canCreateAccount; + @HostBinding('class.with-info-message') get getHasMessage() { + return this.hasMessage; } - public canCreateAccount: boolean; + public hasMessage: boolean; public hasPermissionToAccessFearAndGreedIndex: boolean; public tabs: { iconName: string; path: string }[] = []; public user: User; @@ -35,10 +34,11 @@ export class HomePageComponent implements OnDestroy, OnInit { */ public constructor( private changeDetectorRef: ChangeDetectorRef, - private deviceService: DeviceDetectorService, - private impersonationStorageService: ImpersonationStorageService, + private dataService: DataService, private userService: UserService ) { + const { systemMessage } = this.dataService.fetchInfo(); + this.userService.stateChanged .pipe(takeUntil(this.unsubscribeSubject)) .subscribe((state) => { @@ -50,10 +50,11 @@ export class HomePageComponent implements OnDestroy, OnInit { ]; this.user = state.user; - this.canCreateAccount = hasPermission( - this.user?.permissions, - permissions.createUserAccount - ); + this.hasMessage = + hasPermission( + this.user?.permissions, + permissions.createUserAccount + ) || !!systemMessage; this.hasPermissionToAccessFearAndGreedIndex = hasPermission( this.user.permissions, diff --git a/apps/client/src/app/pages/home/home-page.scss b/apps/client/src/app/pages/home/home-page.scss index fb2adc79c..344e79d3c 100644 --- a/apps/client/src/app/pages/home/home-page.scss +++ b/apps/client/src/app/pages/home/home-page.scss @@ -10,10 +10,6 @@ padding-bottom: env(safe-area-inset-bottom); padding-bottom: constant(safe-area-inset-bottom); - &.with-create-account-container { - height: calc(100vh - 5rem - 3.5rem); - } - ::ng-deep { gf-home-holdings, gf-home-market, diff --git a/apps/client/src/app/services/data.service.ts b/apps/client/src/app/services/data.service.ts index 6a21db0da..b15dd1723 100644 --- a/apps/client/src/app/services/data.service.ts +++ b/apps/client/src/app/services/data.service.ts @@ -42,8 +42,6 @@ import { map } from 'rxjs/operators'; providedIn: 'root' }) export class DataService { - private info: InfoItem; - public constructor(private http: HttpClient) {} public createCheckoutSession({ @@ -241,7 +239,6 @@ export class DataService { } public putAdminSetting(key: string, aData: PropertyDto) { - console.log(key, aData); return this.http.put(`/api/admin/settings/${key}`, aData); } diff --git a/apps/client/src/styles.scss b/apps/client/src/styles.scss index 6093c451f..5cc4d43c2 100644 --- a/apps/client/src/styles.scss +++ b/apps/client/src/styles.scss @@ -175,3 +175,7 @@ ngx-skeleton-loader { .text-decoration-underline { text-decoration: underline !important; } + +.with-info-message { + height: calc(100vh - 5rem - 3.5rem) !important; +} diff --git a/libs/common/src/lib/config.ts b/libs/common/src/lib/config.ts index 5781fc65c..6697c92f9 100644 --- a/libs/common/src/lib/config.ts +++ b/libs/common/src/lib/config.ts @@ -34,5 +34,6 @@ export const PROPERTY_CURRENCIES = 'CURRENCIES'; export const PROPERTY_LAST_DATA_GATHERING = 'LAST_DATA_GATHERING'; export const PROPERTY_LOCKED_DATA_GATHERING = 'LOCKED_DATA_GATHERING'; export const PROPERTY_STRIPE_CONFIG = 'STRIPE_CONFIG'; +export const PROPERTY_SYSTEM_MESSAGE = 'SYSTEM_MESSAGE'; export const UNKNOWN_KEY = 'UNKNOWN'; diff --git a/libs/common/src/lib/interfaces/info-item.interface.ts b/libs/common/src/lib/interfaces/info-item.interface.ts index 630b37403..08b511cf3 100644 --- a/libs/common/src/lib/interfaces/info-item.interface.ts +++ b/libs/common/src/lib/interfaces/info-item.interface.ts @@ -8,10 +8,7 @@ export interface InfoItem { demoAuthToken: string; globalPermissions: string[]; lastDataGathering?: Date; - message?: { - text: string; - type: string; - }; + systemMessage?: string; platforms: { id: string; name: string }[]; primaryDataSource: DataSource; statistics: Statistics; diff --git a/libs/common/src/lib/permissions.ts b/libs/common/src/lib/permissions.ts index 0dba2e81f..8feab7466 100644 --- a/libs/common/src/lib/permissions.ts +++ b/libs/common/src/lib/permissions.ts @@ -17,6 +17,7 @@ export const permissions = { enableSocialLogin: 'enableSocialLogin', enableStatistics: 'enableStatistics', enableSubscription: 'enableSubscription', + enableSystemMessage: 'enableSystemMessage', updateAccount: 'updateAccount', updateAuthDevice: 'updateAuthDevice', updateOrder: 'updateOrder',