diff --git a/backend/src/collections/preferencesdb/preferencedefaults.service.ts b/backend/src/collections/preferencesdb/preferencedefaults.service.ts index 0c6cb72..775823d 100644 --- a/backend/src/collections/preferencesdb/preferencedefaults.service.ts +++ b/backend/src/collections/preferencesdb/preferencedefaults.service.ts @@ -17,9 +17,7 @@ export class PreferenceDefaultsService { public readonly usrDefaults: { [key in UsrPreference]: () => PrefValueType; } = { - [UsrPreference.TestString]: () => 'test_string', - [UsrPreference.TestNumber]: () => 123, - [UsrPreference.TestBoolean]: () => true, + [UsrPreference.ExifStripping]: () => true, }; public readonly sysDefaults: { @@ -39,9 +37,5 @@ export class PreferenceDefaultsService { [SysPreference.JwtExpiresIn]: () => this.jwtConfigService.getJwtExpiresIn() ?? '7d', [SysPreference.BCryptStrength]: () => 12, - - [SysPreference.TestString]: () => 'test_string', - [SysPreference.TestNumber]: () => 123, - [SysPreference.TestBoolean]: () => true, }; } diff --git a/backend/src/collections/preferencesdb/usrpreferencedb.service.ts b/backend/src/collections/preferencesdb/usrpreferencedb.service.ts index bcd535e..66c8101 100644 --- a/backend/src/collections/preferencesdb/usrpreferencedb.service.ts +++ b/backend/src/collections/preferencesdb/usrpreferencedb.service.ts @@ -3,18 +3,18 @@ import { InjectRepository } from '@nestjs/typeorm'; import { DecodedUsrPref, PrefValueType, - PrefValueTypeStrings, + PrefValueTypeStrings } from 'picsur-shared/dist/dto/preferences.dto'; import { UsrPreference } from 'picsur-shared/dist/dto/usrpreferences.dto'; import { AsyncFailable, Fail, HasFailed } from 'picsur-shared/dist/types'; import { Repository } from 'typeorm'; import { UsrPreferenceList, - UsrPreferenceValueTypes, + UsrPreferenceValueTypes } from '../../models/dto/usrpreferences.dto'; import { EUsrPreferenceBackend, - EUsrPreferenceSchema, + EUsrPreferenceSchema } from '../../models/entities/usrpreference.entity'; import { FallBackMutex } from '../../models/util/FallBackMutex'; import { PreferenceCommonService } from './preferencecommon.service'; @@ -173,7 +173,7 @@ export class UsrPreferenceService { return this.setPreference( userid, key, - this.defaultsService.sysDefaults[key](), + this.defaultsService.usrDefaults[key](), ); } diff --git a/backend/src/models/dto/syspreferences.dto.ts b/backend/src/models/dto/syspreferences.dto.ts index 867ecec..3905e9a 100644 --- a/backend/src/models/dto/syspreferences.dto.ts +++ b/backend/src/models/dto/syspreferences.dto.ts @@ -11,7 +11,4 @@ export const SysPreferenceValueTypes: { [SysPreference.JwtSecret]: 'string', [SysPreference.JwtExpiresIn]: 'string', [SysPreference.BCryptStrength]: 'number', - [SysPreference.TestString]: 'string', - [SysPreference.TestNumber]: 'number', - [SysPreference.TestBoolean]: 'boolean', }; diff --git a/backend/src/models/dto/usrpreferences.dto.ts b/backend/src/models/dto/usrpreferences.dto.ts index 4b73f70..71dfc0b 100644 --- a/backend/src/models/dto/usrpreferences.dto.ts +++ b/backend/src/models/dto/usrpreferences.dto.ts @@ -8,7 +8,5 @@ export const UsrPreferenceList: string[] = Object.values(UsrPreference); export const UsrPreferenceValueTypes: { [key in UsrPreference]: PrefValueTypeStrings; } = { - [UsrPreference.TestString]: 'string', - [UsrPreference.TestNumber]: 'number', - [UsrPreference.TestBoolean]: 'boolean', + [UsrPreference.ExifStripping]: 'boolean', }; diff --git a/frontend/src/app/components/pref-option/pref-option.component.ts b/frontend/src/app/components/pref-option/pref-option.component.ts index 9122bf5..b65e5cc 100644 --- a/frontend/src/app/components/pref-option/pref-option.component.ts +++ b/frontend/src/app/components/pref-option/pref-option.component.ts @@ -1,16 +1,13 @@ import { Component, Input, OnInit } from '@angular/core'; import { AutoUnsubscribe } from 'ngx-auto-unsubscribe-decorator'; import { - DecodedSysPref, + DecodedPref, PrefValueType } from 'picsur-shared/dist/dto/preferences.dto'; -import { SysPreference } from 'picsur-shared/dist/dto/syspreferences.dto'; import { AsyncFailable, HasFailed } from 'picsur-shared/dist/types'; import { Subject } from 'rxjs'; -import { SysPreferenceFriendlyNames } from 'src/app/i18n/syspref.i18n'; import { Required } from 'src/app/models/decorators/required.decorator'; import { SnackBarType } from 'src/app/models/dto/snack-bar-type.dto'; -import { SysPrefService } from 'src/app/services/api/syspref.service'; import { Throttle } from 'src/app/util/throttle'; import { UtilService } from 'src/app/util/util.service'; @@ -20,28 +17,25 @@ import { UtilService } from 'src/app/util/util.service'; styleUrls: ['./pref-option.component.scss'], }) export class PrefOptionComponent implements OnInit { - @Input() @Required pref: DecodedSysPref; + @Input() @Required pref: DecodedPref; @Input('update') @Required updateFunction: ( key: string, pref: PrefValueType ) => AsyncFailable; + @Input() @Required translator: { + [key in string]: string; + }; private updateSubject = new Subject(); - constructor( - private sysprefService: SysPrefService, - private utilService: UtilService - ) {} + constructor(private utilService: UtilService) {} ngOnInit(): void { this.subscribeUpdate(); } get name(): string { - return ( - SysPreferenceFriendlyNames[this.pref.key as SysPreference] ?? - this.pref.key - ); + return this.translator[this.pref.key] ?? this.pref.key; } get valString(): string { @@ -83,8 +77,18 @@ export class PrefOptionComponent implements OnInit { private async updatePreference(value: PrefValueType) { const result = await this.updateFunction(this.pref.key, value); if (!HasFailed(result)) { + const message = + this.pref.type === 'string' + ? `Updated ${this.name}` + : this.pref.type === 'number' + ? `Updated ${this.name}` + : this.pref.type === 'boolean' + ? value + ? `Enabled ${this.name}` + : `Disabled ${this.name}` + : ''; this.utilService.showSnackBar( - `Updated ${this.name}`, + message, SnackBarType.Success ); } else { diff --git a/frontend/src/app/i18n/syspref.i18n.ts b/frontend/src/app/i18n/syspref.i18n.ts index fe0ce2e..f94bc52 100644 --- a/frontend/src/app/i18n/syspref.i18n.ts +++ b/frontend/src/app/i18n/syspref.i18n.ts @@ -6,7 +6,4 @@ export const SysPreferenceFriendlyNames: { [SysPreference.JwtSecret]: 'JWT Secret', [SysPreference.JwtExpiresIn]: 'JWT Expiry Time', [SysPreference.BCryptStrength]: 'BCrypt Strength', - [SysPreference.TestString]: 'Test String', - [SysPreference.TestNumber]: 'Test Number', - [SysPreference.TestBoolean]: 'Test Boolean', }; diff --git a/frontend/src/app/i18n/usrpref.i18n.ts b/frontend/src/app/i18n/usrpref.i18n.ts index fb3f709..698d9a2 100644 --- a/frontend/src/app/i18n/usrpref.i18n.ts +++ b/frontend/src/app/i18n/usrpref.i18n.ts @@ -3,7 +3,5 @@ import { UsrPreference } from 'picsur-shared/dist/dto/usrpreferences.dto'; export const UsrPreferenceFriendlyNames: { [key in UsrPreference]: string; } = { - [UsrPreference.TestString]: 'Test String', - [UsrPreference.TestNumber]: 'Test Number', - [UsrPreference.TestBoolean]: 'Test Boolean', + [UsrPreference.ExifStripping]: 'EXIF data stripping', }; diff --git a/frontend/src/app/routes/settings/general/settings-general.component.html b/frontend/src/app/routes/settings/general/settings-general.component.html index 8f4758a..d9ad3b5 100644 --- a/frontend/src/app/routes/settings/general/settings-general.component.html +++ b/frontend/src/app/routes/settings/general/settings-general.component.html @@ -4,5 +4,6 @@ diff --git a/frontend/src/app/routes/settings/general/settings-general.component.ts b/frontend/src/app/routes/settings/general/settings-general.component.ts index 20ee2cb..1b22591 100644 --- a/frontend/src/app/routes/settings/general/settings-general.component.ts +++ b/frontend/src/app/routes/settings/general/settings-general.component.ts @@ -1,12 +1,15 @@ import { Component } from '@angular/core'; import { DecodedPref } from 'picsur-shared/dist/dto/preferences.dto'; import { Observable } from 'rxjs'; +import { UsrPreferenceFriendlyNames } from 'src/app/i18n/usrpref.i18n'; import { UsrPrefService } from 'src/app/services/api/usrpref.service'; @Component({ templateUrl: './settings-general.component.html', }) export class SettingsGeneralComponent { + public translator = UsrPreferenceFriendlyNames; + preferences: Observable; constructor(public usrPrefService: UsrPrefService) { diff --git a/frontend/src/app/routes/settings/syspref/settings-syspref.component.html b/frontend/src/app/routes/settings/syspref/settings-syspref.component.html index 455f154..ce4bf15 100644 --- a/frontend/src/app/routes/settings/syspref/settings-syspref.component.html +++ b/frontend/src/app/routes/settings/syspref/settings-syspref.component.html @@ -4,5 +4,6 @@ diff --git a/frontend/src/app/routes/settings/syspref/settings-syspref.component.ts b/frontend/src/app/routes/settings/syspref/settings-syspref.component.ts index ead1957..88a5085 100644 --- a/frontend/src/app/routes/settings/syspref/settings-syspref.component.ts +++ b/frontend/src/app/routes/settings/syspref/settings-syspref.component.ts @@ -1,12 +1,15 @@ import { Component } from '@angular/core'; import { DecodedPref } from 'picsur-shared/dist/dto/preferences.dto'; import { Observable } from 'rxjs'; +import { SysPreferenceFriendlyNames } from 'src/app/i18n/syspref.i18n'; import { SysPrefService } from 'src/app/services/api/syspref.service'; @Component({ templateUrl: './settings-syspref.component.html', }) export class SettingsSysprefComponent { + public translator = SysPreferenceFriendlyNames; + preferences: Observable; constructor(public sysPrefService: SysPrefService) { diff --git a/shared/src/dto/syspreferences.dto.ts b/shared/src/dto/syspreferences.dto.ts index 711762e..2f42b2c 100644 --- a/shared/src/dto/syspreferences.dto.ts +++ b/shared/src/dto/syspreferences.dto.ts @@ -4,7 +4,4 @@ export enum SysPreference { JwtSecret = 'jwt_secret', JwtExpiresIn = 'jwt_expires_in', BCryptStrength = 'bcrypt_strength', - TestString = 'test_string', - TestNumber = 'test_number', - TestBoolean = 'test_boolean', } diff --git a/shared/src/dto/usrpreferences.dto.ts b/shared/src/dto/usrpreferences.dto.ts index a87e0a6..09b638f 100644 --- a/shared/src/dto/usrpreferences.dto.ts +++ b/shared/src/dto/usrpreferences.dto.ts @@ -1,8 +1,6 @@ // This enum is only here to make accessing the values easier, and type checking in the backend export enum UsrPreference { - TestString = 'test_string', - TestNumber = 'test_number', - TestBoolean = 'test_boolean', + ExifStripping = 'exif_stripping', }