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

@ -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);