Skip to content

Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍

Feature/simplify admin settings management (#1340)

Thomas Kaul5398da0dc8fe
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9e06ac7a3c..05b7406654 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+## Unreleased
+
+### Changed
+
+- Simplified the settings management in the admin control panel
+
## 1.203.0 - 08.10.2022
### Added
diff --git a/apps/api/src/app/admin/admin.service.ts b/apps/api/src/app/admin/admin.service.ts
index 42ee800ba5..5c7f8698aa 100644
--- a/apps/api/src/app/admin/admin.service.ts
+++ b/apps/api/src/app/admin/admin.service.ts
@@ -181,10 +181,10 @@ export class AdminService {
public async putSetting(key: string, value: string) {
let response: Property;
- if (value === '') {
- response = await this.propertyService.delete({ key });
- } else {
+ if (value) {
response = await this.propertyService.put({ key, value });
+ } else {
+ response = await this.propertyService.delete({ key });
}
if (key === PROPERTY_CURRENCIES) {
diff --git a/apps/api/src/services/property/property.dto.ts b/apps/api/src/services/property/property.dto.ts
index 62f90875a8..037b4703c8 100644
--- a/apps/api/src/services/property/property.dto.ts
+++ b/apps/api/src/services/property/property.dto.ts
@@ -1,6 +1,7 @@
-import { IsString } from 'class-validator';
+import { IsOptional, IsString } from 'class-validator';
export class PropertyDto {
+ @IsOptional()
@IsString()
value: string;
}
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 c351f1a689..d80d409b3a 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
@@ -99,7 +99,7 @@ export class AdminOverviewComponent implements OnDestroy, OnInit {
...this.coupons,
{ code: this.generateCouponCode(16), duration: this.couponDuration }
];
- this.putCoupons(coupons);
+ this.putAdminSetting({ key: PROPERTY_COUPONS, value: coupons });
}
public onAddCurrency() {
@@ -107,7 +107,7 @@ export class AdminOverviewComponent implements OnDestroy, OnInit {
if (currency) {
const currencies = uniq([...this.customCurrencies, currency]);
- this.putCurrencies(currencies);
+ this.putAdminSetting({ key: PROPERTY_CURRENCIES, value: currencies });
}
}
@@ -124,7 +124,7 @@ export class AdminOverviewComponent implements OnDestroy, OnInit {
const coupons = this.coupons.filter((coupon) => {
return coupon.code !== aCouponCode;
});
- this.putCoupons(coupons);
+ this.putAdminSetting({ key: PROPERTY_COUPONS, value: coupons });
}
}
@@ -137,12 +137,12 @@ export class AdminOverviewComponent implements OnDestroy, OnInit {
const currencies = this.customCurrencies.filter((currency) => {
return currency !== aCurrency;
});
- this.putCurrencies(currencies);
+ this.putAdminSetting({ key: PROPERTY_CURRENCIES, value: currencies });
}
}
public onDeleteSystemMessage() {
- this.putSystemMessage('');
+ this.putAdminSetting({ key: PROPERTY_SYSTEM_MESSAGE, value: undefined });
}
public onFlushCache() {
@@ -192,14 +192,20 @@ export class AdminOverviewComponent implements OnDestroy, OnInit {
}
public onReadOnlyModeChange(aEvent: MatSlideToggleChange) {
- this.setReadOnlyMode(aEvent.checked);
+ this.putAdminSetting({
+ key: PROPERTY_IS_READ_ONLY_MODE,
+ value: aEvent.checked ? true : undefined
+ });
}
public onSetSystemMessage() {
const systemMessage = prompt($localize`Please set your system message:`);
if (systemMessage) {
- this.putSystemMessage(systemMessage);
+ this.putAdminSetting({
+ key: PROPERTY_SYSTEM_MESSAGE,
+ value: systemMessage
+ });
}
}
@@ -236,49 +242,10 @@ export class AdminOverviewComponent implements OnDestroy, OnInit {
return couponCode;
}
- private putCoupons(aCoupons: Coupon[]) {
- this.dataService
- .putAdminSetting(PROPERTY_COUPONS, {
- value: JSON.stringify(aCoupons)
- })
- .pipe(takeUntil(this.unsubscribeSubject))
- .subscribe(() => {
- setTimeout(() => {
- window.location.reload();
- }, 300);
- });
- }
-
- private putCurrencies(aCurrencies: string[]) {
- this.dataService
- .putAdminSetting(PROPERTY_CURRENCIES, {
- value: JSON.stringify(aCurrencies)
- })
- .pipe(takeUntil(this.unsubscribeSubject))
- .subscribe(() => {
- setTimeout(() => {
- window.location.reload();
- }, 300);
- });
- }
-
- private putSystemMessage(aSystemMessage: string) {
- this.dataService
- .putAdminSetting(PROPERTY_SYSTEM_MESSAGE, {
- value: aSystemMessage
- })
- .pipe(takeUntil(this.unsubscribeSubject))
- .subscribe(() => {
- setTimeout(() => {
- window.location.reload();
- }, 300);
- });
- }
-
- private setReadOnlyMode(aValue: boolean) {
+ private putAdminSetting({ key, value }: { key: string; value: any }) {
this.dataService
- .putAdminSetting(PROPERTY_IS_READ_ONLY_MODE, {
- value: aValue ? 'true' : ''
+ .putAdminSetting(key, {
+ value: value ? JSON.stringify(value) : undefined
})
.pipe(takeUntil(this.unsubscribeSubject))
.subscribe(() => {
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 97be48141c..798afa139c 100644
--- a/apps/client/src/app/components/admin-overview/admin-overview.html
+++ b/apps/client/src/app/components/admin-overview/admin-overview.html
@@ -119,10 +119,20 @@
</div>
</div>
</div>
+ <div class="align-items-start d-flex my-3">
+ <div class="w-50" i18n>Benchmarks</div>
+ <div class="w-50">
+ <table>
+ <tr *ngFor="let benchmark of info?.benchmarks">
+ <td class="pl-1">{{ benchmark.symbol }}</td>
+ </tr>
+ </table>
+ </div>
+ </div>
<div *ngIf="hasPermissionForSystemMessage" class="d-flex my-3">
<div class="w-50" i18n>System Message</div>
<div class="w-50">
- <div *ngIf="info.systemMessage">
+ <div *ngIf="info?.systemMessage">
<span>{{ info.systemMessage }}</span>
<button
class="mini-icon mx-1 no-min-width px-2"
@@ -133,7 +143,7 @@
</button>
</div>
<button
- *ngIf="!info.systemMessage"
+ *ngIf="!info?.systemMessage"
color="accent"
mat-flat-button
(click)="onSetSystemMessage()"