Removed CapaAdminStore

This commit is contained in:
djmaze
2021-03-16 10:46:22 +01:00
parent 4a8d516123
commit eda0ee695d
5 changed files with 97 additions and 196 deletions

View File

@@ -7,7 +7,7 @@ import {
convertThemeName
} from 'Common/Utils';
import { SaveSettingsStep } from 'Common/Enums';
import { Capa, SaveSettingsStep } from 'Common/Enums';
import { Settings, SettingsGet } from 'Common/Globals';
import { reload as translatorReload, convertLangName } from 'Common/Translator';
@@ -18,7 +18,6 @@ import Remote from 'Remote/Admin/Fetch';
import { ThemeStore } from 'Stores/Theme';
import { LanguageStore } from 'Stores/Language';
import { AppAdminStore } from 'Stores/Admin/App';
import { CapaAdminStore } from 'Stores/Admin/Capa';
import LanguagesPopupView from 'View/Popup/Languages';
export class GeneralAdminSettings {
@@ -35,19 +34,18 @@ export class GeneralAdminSettings {
this.theme = ThemeStore.theme;
this.themes = ThemeStore.themes;
this.capaThemes = CapaAdminStore.themes;
this.capaUserBackground = CapaAdminStore.userBackground;
this.capaAdditionalAccounts = CapaAdminStore.additionalAccounts;
this.capaIdentities = CapaAdminStore.identities;
this.capaAttachmentThumbnails = CapaAdminStore.attachmentThumbnails;
this.capaTemplates = CapaAdminStore.templates;
ko.addObservablesTo(this, {
allowLanguagesOnSettings: !!SettingsGet('AllowLanguagesOnSettings'),
newMoveToFolder: !!SettingsGet('NewMoveToFolder'),
attachmentLimitTrigger: SaveSettingsStep.Idle,
languageTrigger: SaveSettingsStep.Idle,
themeTrigger: SaveSettingsStep.Idle
themeTrigger: SaveSettingsStep.Idle,
capaThemes: Settings.capa(Capa.Themes),
capaUserBackground: Settings.capa(Capa.UserBackground),
capaAdditionalAccounts: Settings.capa(Capa.AdditionalAccounts),
capaIdentities: Settings.capa(Capa.Identities),
capaAttachmentThumbnails: Settings.capa(Capa.AttachmentThumbnails),
capaTemplates: Settings.capa(Capa.Templates)
});
this.weakPassword = AppAdminStore.weakPassword;
@@ -77,96 +75,61 @@ export class GeneralAdminSettings {
this.languageAdminFullName = ko.computed(() => convertLangName(this.languageAdmin()));
this.languageAdminTrigger = ko.observable(SaveSettingsStep.Idle).extend({ debounce: 100 });
}
onBuild() {
setTimeout(() => {
const f1 = settingsSaveHelperSimpleFunction(this.attachmentLimitTrigger, this),
f2 = settingsSaveHelperSimpleFunction(this.languageTrigger, this),
f3 = settingsSaveHelperSimpleFunction(this.themeTrigger, this),
fReloadLanguageHelper = (saveSettingsStep) => () => {
this.languageAdminTrigger(saveSettingsStep);
setTimeout(() => this.languageAdminTrigger(SaveSettingsStep.Idle), 1000);
};
const fReloadLanguageHelper = (saveSettingsStep) => () => {
this.languageAdminTrigger(saveSettingsStep);
setTimeout(() => this.languageAdminTrigger(SaveSettingsStep.Idle), 1000);
},
fSaveBoolHelper = (key, fn) =>
value => {
const data = {};
data[key] = value ? 1 : 0;
Remote.saveAdminConfig(fn, data);
};
this.mainAttachmentLimit.subscribe(value => {
Remote.saveAdminConfig(f1, {
ko.addSubscribablesTo(this, {
mainAttachmentLimit: value =>
Remote.saveAdminConfig(settingsSaveHelperSimpleFunction(this.attachmentLimitTrigger, this), {
'AttachmentLimit': pInt(value)
});
});
}),
this.language.subscribe(value => {
Remote.saveAdminConfig(f2, {
language: value =>
Remote.saveAdminConfig(settingsSaveHelperSimpleFunction(this.languageTrigger, this), {
'Language': value.trim()
});
});
}),
this.languageAdmin.subscribe(value => {
languageAdmin: value => {
this.languageAdminTrigger(SaveSettingsStep.Animate);
translatorReload(true, value)
.then(fReloadLanguageHelper(SaveSettingsStep.TrueResult), fReloadLanguageHelper(SaveSettingsStep.FalseResult))
.then(() => {
Remote.saveAdminConfig(null, {
'LanguageAdmin': value.trim()
});
});
});
.then(() => Remote.saveAdminConfig(null, {
'LanguageAdmin': value.trim()
}));
},
this.theme.subscribe(value => {
theme: value => {
changeTheme(value, this.themeTrigger);
Remote.saveAdminConfig(f3, {
Remote.saveAdminConfig(settingsSaveHelperSimpleFunction(this.themeTrigger, this), {
'Theme': value.trim()
});
});
},
this.capaAdditionalAccounts.subscribe(value => {
Remote.saveAdminConfig(null, {
'CapaAdditionalAccounts': value ? '1' : '0'
});
});
capaAdditionalAccounts: fSaveBoolHelper('CapaAdditionalAccounts'),
this.capaIdentities.subscribe(value => {
Remote.saveAdminConfig(null, {
'CapaIdentities': value ? '1' : '0'
});
});
capaIdentities: fSaveBoolHelper('CapaIdentities'),
this.capaTemplates.subscribe(value => {
Remote.saveAdminConfig(null, {
'CapaTemplates': value ? '1' : '0'
});
});
capaTemplates: fSaveBoolHelper('CapaTemplates'),
this.capaAttachmentThumbnails.subscribe(value => {
Remote.saveAdminConfig(null, {
'CapaAttachmentThumbnails': value ? '1' : '0'
});
});
capaAttachmentThumbnails: fSaveBoolHelper('CapaAttachmentThumbnails'),
this.capaThemes.subscribe(value => {
Remote.saveAdminConfig(null, {
'CapaThemes': value ? '1' : '0'
});
});
capaThemes: fSaveBoolHelper('CapaThemes'),
this.capaUserBackground.subscribe(value => {
Remote.saveAdminConfig(null, {
'CapaUserBackground': value ? '1' : '0'
});
});
capaUserBackground: fSaveBoolHelper('CapaUserBackground'),
this.allowLanguagesOnSettings.subscribe(value => {
Remote.saveAdminConfig(null, {
'AllowLanguagesOnSettings': value ? '1' : '0'
});
});
allowLanguagesOnSettings: fSaveBoolHelper('AllowLanguagesOnSettings'),
this.newMoveToFolder.subscribe(value => {
Remote.saveAdminConfig(null, {
'NewMoveToFolder': value ? '1' : '0'
});
});
}, 50);
newMoveToFolder: fSaveBoolHelper('NewMoveToFolder')
});
}
selectLanguage() {

View File

@@ -1,9 +1,9 @@
import ko from 'ko';
import { SettingsGet } from 'Common/Globals';
import { Capa } from 'Common/Enums';
import { Settings, SettingsGet } from 'Common/Globals';
import { AppAdminStore } from 'Stores/Admin/App';
import { CapaAdminStore } from 'Stores/Admin/Capa';
import Remote from 'Remote/Admin/Fetch';
@@ -13,11 +13,6 @@ export class SecurityAdminSettings {
constructor() {
this.weakPassword = AppAdminStore.weakPassword;
this.capaOpenPGP = CapaAdminStore.openPGP;
this.capaTwoFactorAuth = CapaAdminStore.twoFactorAuth;
this.capaTwoFactorAuthForce = CapaAdminStore.twoFactorAuthForce;
ko.addObservablesTo(this, {
useLocalProxyForExternalImages: !!SettingsGet('UseLocalProxyForExternalImages'),
@@ -36,40 +31,66 @@ export class SecurityAdminSettings {
adminPasswordNewError: false,
adminPasswordUpdateError: false,
adminPasswordUpdateSuccess: false
adminPasswordUpdateSuccess: false,
capaOpenPGP: Settings.capa(Capa.OpenPGP),
capaTwoFactorAuth: Settings.capa(Capa.TwoFactor),
capaTwoFactorAuthForce: Settings.capa(Capa.TwoFactorForce)
});
this.capaTwoFactorAuth.subscribe(value => {
if (!value) {
this.capaTwoFactorAuthForce(false);
}
});
ko.addSubscribablesTo(this, {
adminPassword: () => {
this.adminPasswordUpdateError(false);
this.adminPasswordUpdateSuccess(false);
},
this.verifySslCertificate.subscribe(value => {
if (!value) {
this.allowSelfSigned(true);
}
});
adminLogin: () => this.adminLoginError(false),
this.adminPassword.subscribe(() => {
this.adminPasswordUpdateError(false);
this.adminPasswordUpdateSuccess(false);
});
adminPasswordNew: () => {
this.adminPasswordUpdateError(false);
this.adminPasswordUpdateSuccess(false);
this.adminPasswordNewError(false);
},
this.adminLogin.subscribe(() => {
this.adminLoginError(false);
});
adminPasswordNew2: () => {
this.adminPasswordUpdateError(false);
this.adminPasswordUpdateSuccess(false);
this.adminPasswordNewError(false);
},
this.adminPasswordNew.subscribe(() => {
this.adminPasswordUpdateError(false);
this.adminPasswordUpdateSuccess(false);
this.adminPasswordNewError(false);
});
capaOpenPGP: value =>
Remote.saveAdminConfig(null, {
'CapaOpenPGP': value ? 1 : 0
}),
this.adminPasswordNew2.subscribe(() => {
this.adminPasswordUpdateError(false);
this.adminPasswordUpdateSuccess(false);
this.adminPasswordNewError(false);
capaTwoFactorAuth: value => {
value || this.capaTwoFactorAuthForce(false);
Remote.saveAdminConfig(null, {
'CapaTwoFactorAuth': value ? 1 : 0
});
},
capaTwoFactorAuthForce: value =>
Remote.saveAdminConfig(null, {
'CapaTwoFactorAuthForce': value ? 1 : 0
}),
useLocalProxyForExternalImages: value =>
Remote.saveAdminConfig(null, {
'UseLocalProxyForExternalImages': value ? 1 : 0
}),
verifySslCertificate: value => {
value => value || this.allowSelfSigned(true);
Remote.saveAdminConfig(null, {
'VerifySslCertificate': value ? 1 : 0
});
},
allowSelfSigned: value =>
Remote.saveAdminConfig(null, {
'AllowSelfSigned': value ? 1 : 0
})
});
this.onNewAdminPasswordResponse = this.onNewAdminPasswordResponse.bind(this);
@@ -125,44 +146,6 @@ export class SecurityAdminSettings {
}
}
onBuild() {
this.capaOpenPGP.subscribe(value => {
Remote.saveAdminConfig(null, {
'CapaOpenPGP': value ? '1' : '0'
});
});
this.capaTwoFactorAuth.subscribe(value => {
Remote.saveAdminConfig(null, {
'CapaTwoFactorAuth': value ? '1' : '0'
});
});
this.capaTwoFactorAuthForce.subscribe(value => {
Remote.saveAdminConfig(null, {
'CapaTwoFactorAuthForce': value ? '1' : '0'
});
});
this.useLocalProxyForExternalImages.subscribe(value => {
Remote.saveAdminConfig(null, {
'UseLocalProxyForExternalImages': value ? '1' : '0'
});
});
this.verifySslCertificate.subscribe(value => {
Remote.saveAdminConfig(null, {
'VerifySslCertificate': value ? '1' : '0'
});
});
this.allowSelfSigned.subscribe(value => {
Remote.saveAdminConfig(null, {
'AllowSelfSigned': value ? '1' : '0'
});
});
}
onHide() {
this.adminPassword('');
this.adminPasswordNew('');