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

@ -3,7 +3,6 @@ import 'External/Admin/ko';
import { Settings, SettingsGet } from 'Common/Globals';
import { AppAdminStore } from 'Stores/Admin/App';
import { CapaAdminStore } from 'Stores/Admin/Capa';
import Remote from 'Remote/Admin/Fetch';
import { SettingsAdminScreen } from 'Screen/Admin/Settings';
@ -29,7 +28,6 @@ class AdminApp extends AbstractApp {
super.bootstart();
AppAdminStore.populate();
CapaAdminStore.populate();
this.hideLoading();

View file

@ -28,19 +28,6 @@ class RemoteAdminFetch extends AbstractFetchRemote {
this.defaultRequest(fCallback, 'AdminSettingsUpdate', oData);
}
/**
* @param {string} key
* @param {?Function} valueFn
* @param {?Function} fn
*/
saveAdminConfigHelper(key, valueFn, fn) {
return (value) => {
const data = {};
data[key] = valueFn ? valueFn(value) : value;
this.saveAdminConfig(fn || null, data);
};
}
/**
* @param {?Function} fCallback
* @param {boolean=} bIncludeAliases = true

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('');

View file

@ -1,30 +0,0 @@
import ko from 'ko';
import { Capa } from 'Common/Enums';
import { Settings } from 'Common/Globals';
export const CapaAdminStore = {
populate: function() {
const capa = Settings.capa;
this.additionalAccounts(capa(Capa.AdditionalAccounts));
this.identities(capa(Capa.Identities));
this.attachmentThumbnails(capa(Capa.AttachmentThumbnails));
this.themes(capa(Capa.Themes));
this.userBackground(capa(Capa.UserBackground));
this.openPGP(capa(Capa.OpenPGP));
this.twoFactorAuth(capa(Capa.TwoFactor));
this.twoFactorAuthForce(capa(Capa.TwoFactorForce));
this.templates(capa(Capa.Templates));
}
};
ko.addObservablesTo(CapaAdminStore, {
additionalAccounts: false,
identities: false,
attachmentThumbnails: false,
themes: true,
userBackground: false,
openPGP: false,
twoFactorAuth: false,
twoFactorAuthForce: false,
templates: false
});