Simplify save settings

This commit is contained in:
the-djmaze
2022-03-01 10:18:12 +01:00
parent fc60dc94fc
commit f4d98130a5
12 changed files with 66 additions and 162 deletions

View File

@@ -150,6 +150,15 @@ export class AbstractViewSettings
}).debounce(999),
});
}
addSettings(names)
{
names.forEach(name => {
let prop = name[0].toLowerCase() + name.slice(1);
this[prop] || (this[prop] = ko.observable(SettingsGet(name)));
this[prop].subscribe(value => rl.app.Remote.saveSetting(name, value));
});
}
}
export class AbstractViewLogin extends AbstractViewCenter {

View File

@@ -2,21 +2,13 @@ import { AbstractFetchRemote } from 'Remote/AbstractFetch';
class RemoteAdminFetch extends AbstractFetchRemote {
/**
* @param {?Function} fCallback
* @param {?} oData
*/
saveConfig(oData, fCallback) {
this.request('AdminSettingsUpdate', fCallback, oData);
}
/**
* @param {string} key
* @param {?scalar} value
* @param {?Function} fCallback
*/
saveSetting(key, value, fCallback) {
this.saveConfig({[key]: value}, fCallback);
this.request('AdminSettingsUpdate', fCallback, {[key]: value});
}
}

View File

@@ -2,7 +2,7 @@ import ko from 'ko';
import { SettingsGet } from 'Common/Globals';
import { defaultOptionsAfterRender } from 'Common/Utils';
import { addObservablesTo, addSubscribablesTo } from 'External/ko';
import { addObservablesTo } from 'External/ko';
import Remote from 'Remote/Admin/Fetch';
import { decorateKoCommands } from 'Knoin/Knoin';
@@ -22,10 +22,9 @@ export class ContactsAdminSettings extends AbstractViewSettings {
this.testContactsErrorMessage('');
});
addObservablesTo(this, {
enableContacts: !!SettingsGet('ContactsEnable'),
contactsSync: !!SettingsGet('ContactsSync'),
this.addSettings(['ContactsEnable','ContactsSync']);
addObservablesTo(this, {
testing: false,
testContactsSuccess: false,
testContactsError: false,
@@ -65,18 +64,6 @@ export class ContactsAdminSettings extends AbstractViewSettings {
})
.extend({ notify: 'always' });
addSubscribablesTo(this, {
enableContacts: value =>
Remote.saveConfig({
ContactsEnable: value ? 1 : 0
}),
contactsSync: value =>
Remote.saveConfig({
ContactsSync: value ? 1 : 0
})
})
decorateKoCommands(this, {
testContactsCommand: self => self.contactsPdoDsn() && self.contactsPdoUser()
});

View File

@@ -37,9 +37,9 @@ export class GeneralAdminSettings extends AbstractViewSettings {
this.theme = ThemeStore.theme;
this.themes = ThemeStore.themes;
this.addSettings(['AllowLanguagesOnSettings','NewMoveToFolder']);
addObservablesTo(this, {
allowLanguagesOnSettings: SettingsGet('AllowLanguagesOnSettings'),
newMoveToFolder: SettingsGet('NewMoveToFolder'),
attachmentLimitTrigger: SaveSettingsStep.Idle,
themeTrigger: SaveSettingsStep.Idle,
capaThemes: SettingsCapa(Capa.Themes),
@@ -97,9 +97,7 @@ export class GeneralAdminSettings extends AbstractViewSettings {
this.languageAdminTrigger(SaveSettingsStep.Animate);
translatorReload(true, value)
.then(fReloadLanguageHelper(SaveSettingsStep.TrueResult), fReloadLanguageHelper(SaveSettingsStep.FalseResult))
.then(() => Remote.saveConfig({
LanguageAdmin: value.trim()
}));
.then(() => Remote.saveSetting('LanguageAdmin', value));
},
capaAdditionalAccounts: fSaveHelper('CapaAdditionalAccounts'),
@@ -110,11 +108,7 @@ export class GeneralAdminSettings extends AbstractViewSettings {
capaThemes: fSaveHelper('CapaThemes'),
capaUserBackground: fSaveHelper('CapaUserBackground'),
allowLanguagesOnSettings: fSaveHelper('AllowLanguagesOnSettings'),
newMoveToFolder: fSaveHelper('NewMoveToFolder')
capaUserBackground: fSaveHelper('CapaUserBackground')
});
}

View File

@@ -1,41 +1,9 @@
import { Settings, SettingsGet } from 'Common/Globals';
import { addObservablesTo, addSubscribablesTo } from 'External/ko';
import { AbstractViewSettings } from 'Knoin/AbstractViews';
import Remote from 'Remote/Admin/Fetch';
export class LoginAdminSettings extends AbstractViewSettings {
constructor() {
super();
this.addSetting('LoginDefaultDomain');
addObservablesTo(this, {
determineUserLanguage: !!SettingsGet('DetermineUserLanguage'),
determineUserDomain: !!SettingsGet('DetermineUserDomain'),
allowLanguagesOnLogin: !!SettingsGet('AllowLanguagesOnLogin'),
hideSubmitButton: !!Settings.app('hideSubmitButton'),
});
addSubscribablesTo(this, {
determineUserLanguage: value =>
Remote.saveConfig({
DetermineUserLanguage: value ? 1 : 0
}),
determineUserDomain: value =>
Remote.saveConfig({
DetermineUserDomain: value ? 1 : 0
}),
allowLanguagesOnLogin: value =>
Remote.saveConfig({
AllowLanguagesOnLogin: value ? 1 : 0
}),
hideSubmitButton: value =>
Remote.saveConfig({
hideSubmitButton: value ? 1 : 0
})
});
this.addSettings(['DetermineUserLanguage','DetermineUserDomain','AllowLanguagesOnLogin','hideSubmitButton']);
}
}

View File

@@ -8,14 +8,17 @@ import Remote from 'Remote/Admin/Fetch';
import { showScreenPopup } from 'Knoin/Knoin';
import { PluginPopupView } from 'View/Popup/Plugin';
import { SettingsGet } from 'Common/Globals';
import { addObservablesTo, addComputablesTo } from 'External/ko';
import { AbstractViewSettings } from 'Knoin/AbstractViews';
export class PackagesAdminSettings /*extends AbstractViewSettings*/ {
export class PackagesAdminSettings extends AbstractViewSettings {
constructor() {
super();
this.addSettings(['EnabledPlugins']);
addObservablesTo(this, {
packagesError: '',
enabledPlugins: !!SettingsGet('EnabledPlugins')
packagesError: ''
});
this.packages = PackageAdminStore;
@@ -27,12 +30,6 @@ export class PackagesAdminSettings /*extends AbstractViewSettings*/ {
visibility: () => (PackageAdminStore.loading() ? 'visible' : 'hidden')
});
this.enabledPlugins.subscribe(value =>
Remote.saveConfig({
EnabledPlugins: value ? 1 : 0
})
);
}
onShow() {

View File

@@ -5,17 +5,17 @@ import { addObservablesTo, addSubscribablesTo } from 'External/ko';
import Remote from 'Remote/Admin/Fetch';
import { decorateKoCommands } from 'Knoin/Knoin';
import { AbstractViewSettings } from 'Knoin/AbstractViews';
export class SecurityAdminSettings /*extends AbstractViewSettings*/ {
export class SecurityAdminSettings extends AbstractViewSettings {
constructor() {
super();
this.addSettings(['UseLocalProxyForExternalImages','VerifySslCertificate','AllowSelfSigned']);
this.weakPassword = rl.app.weakPassword;
addObservablesTo(this, {
useLocalProxyForExternalImages: !!SettingsGet('UseLocalProxyForExternalImages'),
verifySslCertificate: !!SettingsGet('VerifySslCertificate'),
allowSelfSigned: !!SettingsGet('AllowSelfSigned'),
adminLogin: SettingsGet('AdminLogin'),
adminLoginError: false,
adminPassword: '',
@@ -30,6 +30,12 @@ export class SecurityAdminSettings /*extends AbstractViewSettings*/ {
capaOpenPGP: SettingsCapa(Capa.OpenPGP)
});
const reset = () => {
this.adminPasswordUpdateError(false);
this.adminPasswordUpdateSuccess(false);
this.adminPasswordNewError(false);
};
addSubscribablesTo(this, {
adminPassword: () => {
this.adminPasswordUpdateError(false);
@@ -38,39 +44,11 @@ export class SecurityAdminSettings /*extends AbstractViewSettings*/ {
adminLogin: () => this.adminLoginError(false),
adminPasswordNew: () => {
this.adminPasswordUpdateError(false);
this.adminPasswordUpdateSuccess(false);
this.adminPasswordNewError(false);
},
adminPasswordNew: reset,
adminPasswordNew2: () => {
this.adminPasswordUpdateError(false);
this.adminPasswordUpdateSuccess(false);
this.adminPasswordNewError(false);
},
adminPasswordNew2: reset,
capaOpenPGP: value =>
Remote.saveConfig({
CapaOpenPGP: value ? 1 : 0
}),
useLocalProxyForExternalImages: value =>
Remote.saveConfig({
UseLocalProxyForExternalImages: value ? 1 : 0
}),
verifySslCertificate: value => {
value || this.allowSelfSigned(true);
Remote.saveConfig({
VerifySslCertificate: value ? 1 : 0
});
},
allowSelfSigned: value =>
Remote.saveConfig({
AllowSelfSigned: value ? 1 : 0
})
capaOpenPGP: value => Remote.saveSetting('CapaOpenPGP', value)
});
decorateKoCommands(this, {

View File

@@ -26,9 +26,7 @@ export class ContactsUserSettings /*extends AbstractViewSettings*/ {
.extend({ debounce: 500 });
this.contactsAutosave.subscribe(value =>
Remote.saveSettings(null, {
ContactsAutosave: value ? 1 : 0
})
Remote.saveSettings(null, { ContactsAutosave: value })
);
this.saveTrigger.subscribe(() =>

View File

@@ -35,11 +35,11 @@ export class GeneralUserSettings extends AbstractViewSettings {
this.editorDefaultType = SettingsUserStore.editorDefaultType;
this.layout = SettingsUserStore.layout;
this.enableSoundNotification = NotificationUserStore.enableSoundNotification;
this.soundNotification = NotificationUserStore.enableSoundNotification;
this.notificationSound = ko.observable(SettingsGet('NotificationSound'));
this.notificationSounds = ko.observableArray(SettingsGet('NewMailSounds'));
this.enableDesktopNotification = NotificationUserStore.enableDesktopNotification;
this.desktopNotification = NotificationUserStore.enableDesktopNotification;
this.isDesktopNotificationAllowed = NotificationUserStore.isDesktopNotificationAllowed;
this.viewHTML = SettingsUserStore.viewHTML;
@@ -93,11 +93,13 @@ export class GeneralUserSettings extends AbstractViewSettings {
this.addSetting('MessagesPerPage');
this.addSetting('Layout', () => MessagelistUserStore([]));
this.addSettings(['ViewHTML', 'ShowImages', 'UseCheckboxesInList', 'ReplySameFolder',
'DesktopNotifications', 'SoundNotification']);
const fReloadLanguageHelper = (saveSettingsStep) => () => {
this.languageTrigger(saveSettingsStep);
setTimeout(() => this.languageTrigger(SaveSettingsStep.Idle), 1000);
},
fSaveHelper = key => value => Remote.saveSetting(key, value);
};
addSubscribablesTo(this, {
language: value => {
@@ -107,9 +109,6 @@ export class GeneralUserSettings extends AbstractViewSettings {
.then(() => Remote.saveSetting('Language', value));
},
viewHTML: fSaveHelper('ViewHTML'),
showImages: fSaveHelper('ShowImages'),
removeColors: value => {
let dom = MessageUserStore.bodiesDom();
if (dom) {
@@ -118,18 +117,11 @@ export class GeneralUserSettings extends AbstractViewSettings {
Remote.saveSetting('RemoveColors', value);
},
useCheckboxesInList: fSaveHelper('UseCheckboxesInList'),
enableDesktopNotification: fSaveHelper('DesktopNotifications'),
enableSoundNotification: fSaveHelper('SoundNotification'),
notificationSound: value => {
Remote.saveSetting('NotificationSound', value);
Settings.set('NotificationSound', value);
},
replySameFolder: fSaveHelper('ReplySameFolder'),
useThreads: value => {
MessagelistUserStore([]);
Remote.saveSetting('UseThreads', value);

View File

@@ -72,29 +72,18 @@ trait Admin
return Utils::EncodeKeyValuesQ(array('token', $sRand));
}
private function setCapaFromParams(\RainLoop\Config\Application $oConfig, string $sParamName, string $sCapa) : void
public function DoAdminClearCache() : array
{
switch ($sCapa)
{
case Capa::ADDITIONAL_ACCOUNTS:
$this->setConfigFromParams($oConfig, $sParamName, 'webmail', 'allow_additional_accounts', 'bool');
break;
case Capa::IDENTITIES:
$this->setConfigFromParams($oConfig, $sParamName, 'webmail', 'allow_additional_identities', 'bool');
break;
case Capa::ATTACHMENT_THUMBNAILS:
$this->setConfigFromParams($oConfig, $sParamName, 'interface', 'show_attachment_thumbnail', 'bool');
break;
case Capa::THEMES:
$this->setConfigFromParams($oConfig, $sParamName, 'webmail', 'allow_themes', 'bool');
break;
case Capa::USER_BACKGROUND:
$this->setConfigFromParams($oConfig, $sParamName, 'webmail', 'allow_user_background', 'bool');
break;
case Capa::OPEN_PGP:
$this->setConfigFromParams($oConfig, $sParamName, 'security', 'openpgp', 'bool');
break;
$this->Cacher()->GC(1);
if (\is_dir(APP_PRIVATE_DATA . 'cache')) {
foreach (new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator(APP_PRIVATE_DATA.'cache', \FilesystemIterator::SKIP_DOTS),
\RecursiveIteratorIterator::CHILD_FIRST) as $sName) {
$sName->isDir() ? \rmdir($sName) : \unlink($sName);
}
\clearstatcache();
}
return $this->TrueResponse(__FUNCTION__);
}
public function DoAdminSettingsGet() : array
@@ -173,12 +162,12 @@ trait Admin
return \RainLoop\Providers\AddressBook\PdoAddressBook::validPdoType($sType);
});
$this->setCapaFromParams($oConfig, 'CapaAdditionalAccounts', Capa::ADDITIONAL_ACCOUNTS);
$this->setCapaFromParams($oConfig, 'CapaIdentities', Capa::IDENTITIES);
$this->setCapaFromParams($oConfig, 'CapaOpenPGP', Capa::OPEN_PGP);
$this->setCapaFromParams($oConfig, 'CapaThemes', Capa::THEMES);
$this->setCapaFromParams($oConfig, 'CapaUserBackground', Capa::USER_BACKGROUND);
$this->setCapaFromParams($oConfig, 'CapaAttachmentThumbnails', Capa::ATTACHMENT_THUMBNAILS);
$this->setConfigFromParams($oConfig, 'CapaAdditionalAccounts', 'webmail', 'allow_additional_accounts', 'bool');
$this->setConfigFromParams($oConfig, 'CapaIdentities', 'webmail', 'allow_additional_identities', 'bool');
$this->setConfigFromParams($oConfig, 'CapaAttachmentThumbnails', 'interface', 'show_attachment_thumbnail', 'bool');
$this->setConfigFromParams($oConfig, 'CapaThemes', 'webmail', 'allow_themes', 'bool');
$this->setConfigFromParams($oConfig, 'CapaUserBackground', 'webmail', 'allow_user_background', 'bool');
$this->setConfigFromParams($oConfig, 'CapaOpenPGP', 'security', 'openpgp', 'bool');
$this->setConfigFromParams($oConfig, 'DetermineUserLanguage', 'login', 'determine_user_language', 'bool');
$this->setConfigFromParams($oConfig, 'DetermineUserDomain', 'login', 'determine_user_domain', 'bool');

View File

@@ -10,7 +10,7 @@
<div>
<div data-bind="component: {
name: 'Checkbox',
params: { value: enableContacts, label: 'TAB_CONTACTS/LABEL_ENABLE_CONTACTS' }
params: { value: contactsEnable, label: 'TAB_CONTACTS/LABEL_ENABLE_CONTACTS' }
}"></div>
<div data-bind="component: {
name: 'Checkbox',

View File

@@ -116,7 +116,7 @@
name: 'Checkbox',
params: {
label: 'SETTINGS_GENERAL/LABEL_CHROME_NOTIFICATION_DESC',
value: enableDesktopNotification,
value: desktopNotification,
enable: isDesktopNotificationAllowed,
inline: true
}
@@ -130,7 +130,7 @@
name: 'Checkbox',
params: {
label: 'SETTINGS_GENERAL/LABEL_SOUND_NOTIFICATION',
value: enableSoundNotification,
value: soundNotification,
inline: true
}
}"></div>