Enable AbstractViewSettings

This commit is contained in:
the-djmaze 2022-02-28 10:38:47 +01:00
parent 92cec80b73
commit 97bc3ef585
20 changed files with 149 additions and 212 deletions

View file

@ -1,40 +1,10 @@
import { SaveSettingsStep } from 'Common/Enums';
import { SettingsGet } from 'Common/Globals';
import { settingsSaveHelperSimpleFunction } from 'Common/Utils';
import { addObservablesTo, addSubscribablesTo } from 'External/ko';
import { AbstractViewSettings } from 'Knoin/AbstractViews';
import Remote from 'Remote/Admin/Fetch';
export class BrandingAdminSettings /*extends AbstractViewSettings*/ {
export class BrandingAdminSettings extends AbstractViewSettings {
constructor() {
addObservablesTo(this, {
title: SettingsGet('Title'),
loadingDesc: SettingsGet('LoadingDescription'),
faviconUrl: SettingsGet('FaviconUrl'),
titleTrigger: SaveSettingsStep.Idle,
loadingDescTrigger: SaveSettingsStep.Idle,
faviconUrlTrigger: SaveSettingsStep.Idle
});
addSubscribablesTo(this, {
title: (value =>
Remote.saveConfig({
Title: value.trim()
}, settingsSaveHelperSimpleFunction(this.titleTrigger, this))
).debounce(999),
loadingDesc: (value =>
Remote.saveConfig({
LoadingDescription: value.trim()
}, settingsSaveHelperSimpleFunction(this.loadingDescTrigger, this))
).debounce(999),
faviconUrl: (value =>
Remote.saveConfig({
FaviconUrl: value.trim()
}, settingsSaveHelperSimpleFunction(this.faviconUrlTrigger, this))
).debounce(999)
});
super();
this.addSetting('Title');
this.addSetting('LoadingDescription');
this.addSetting('FaviconUrl');
}
}

View file

@ -1,33 +1,30 @@
import ko from 'ko';
import { SaveSettingsStep } from 'Common/Enums';
import { SettingsGet } from 'Common/Globals';
import {
settingsSaveHelperSimpleFunction,
defaultOptionsAfterRender
} from 'Common/Utils';
import { defaultOptionsAfterRender } from 'Common/Utils';
import { addObservablesTo, addSubscribablesTo } from 'External/ko';
import Remote from 'Remote/Admin/Fetch';
import { decorateKoCommands } from 'Knoin/Knoin';
import { AbstractViewSettings } from 'Knoin/AbstractViews';
export class ContactsAdminSettings /*extends AbstractViewSettings*/ {
export class ContactsAdminSettings extends AbstractViewSettings {
constructor() {
super();
this.defaultOptionsAfterRender = defaultOptionsAfterRender;
this.addSetting('ContactsPdoDsn');
this.addSetting('ContactsPdoUser');
this.addSetting('ContactsPdoPassword');
this.addSetting('ContactsPdoType', () => {
this.testContactsSuccess(false);
this.testContactsError(false);
this.testContactsErrorMessage('');
});
addObservablesTo(this, {
enableContacts: !!SettingsGet('ContactsEnable'),
contactsSync: !!SettingsGet('ContactsSync'),
contactsType: SettingsGet('ContactsPdoType'),
pdoDsn: SettingsGet('ContactsPdoDsn'),
pdoUser: SettingsGet('ContactsPdoUser'),
pdoPassword: SettingsGet('ContactsPdoPassword'),
pdoDsnTrigger: SaveSettingsStep.Idle,
pdoUserTrigger: SaveSettingsStep.Idle,
pdoPasswordTrigger: SaveSettingsStep.Idle,
contactsTypeTrigger: SaveSettingsStep.Idle,
testing: false,
testContactsSuccess: false,
@ -53,16 +50,16 @@ export class ContactsAdminSettings /*extends AbstractViewSettings*/ {
this.mainContactsType = ko
.computed({
read: this.contactsType,
read: this.contactsPdoType,
write: value => {
if (value !== this.contactsType()) {
if (value !== this.contactsPdoType()) {
if (supportedTypes.includes(value)) {
this.contactsType(value);
this.contactsPdoType(value);
} else if (types.length) {
this.contactsType('');
this.contactsPdoType('');
}
} else {
this.contactsType.valueHasMutated();
this.contactsPdoType.valueHasMutated();
}
}
})
@ -77,35 +74,11 @@ export class ContactsAdminSettings /*extends AbstractViewSettings*/ {
contactsSync: value =>
Remote.saveConfig({
ContactsSync: value ? 1 : 0
}),
contactsType: value => {
this.testContactsSuccess(false);
this.testContactsError(false);
this.testContactsErrorMessage('');
Remote.saveConfig({
ContactsPdoType: value.trim()
}, settingsSaveHelperSimpleFunction(this.contactsTypeTrigger, this))
},
pdoDsn: value =>
Remote.saveConfig({
ContactsPdoDsn: value.trim()
}, settingsSaveHelperSimpleFunction(this.pdoDsnTrigger, this)),
pdoUser: value =>
Remote.saveConfig({
ContactsPdoUser: value.trim()
}, settingsSaveHelperSimpleFunction(this.pdoUserTrigger, this)),
pdoPassword: value =>
Remote.saveConfig({
ContactsPdoPassword: value.trim()
}, settingsSaveHelperSimpleFunction(this.pdoPasswordTrigger, this))
})
})
decorateKoCommands(this, {
testContactsCommand: self => self.pdoDsn() && self.pdoUser()
testContactsCommand: self => self.contactsPdoDsn() && self.contactsPdoUser()
});
}
@ -134,10 +107,10 @@ export class ContactsAdminSettings /*extends AbstractViewSettings*/ {
this.testing(false);
}, {
ContactsPdoType: this.contactsType(),
ContactsPdoDsn: this.pdoDsn(),
ContactsPdoUser: this.pdoUser(),
ContactsPdoPassword: this.pdoPassword()
ContactsPdoType: this.contactsPdoType(),
ContactsPdoDsn: this.contactsPdoDsn(),
ContactsPdoUser: this.contactsPdo(),
ContactsPdoPassword: this.contactsPdoPassword()
}
);
}

View file

@ -2,8 +2,6 @@ import ko from 'ko';
import {
isArray,
pInt,
settingsSaveHelperSimpleFunction,
changeTheme,
convertThemeName
} from 'Common/Utils';
@ -14,6 +12,7 @@ import { Capa, SaveSettingsStep } from 'Common/Enums';
import { Settings, SettingsGet, SettingsCapa } from 'Common/Globals';
import { translatorReload, convertLangName } from 'Common/Translator';
import { AbstractViewSettings } from 'Knoin/AbstractViews';
import { showScreenPopup } from 'Knoin/Knoin';
import Remote from 'Remote/Admin/Fetch';
@ -22,8 +21,10 @@ import { ThemeStore } from 'Stores/Theme';
import { LanguageStore } from 'Stores/Language';
import { LanguagesPopupView } from 'View/Popup/Languages';
export class GeneralAdminSettings /*extends AbstractViewSettings*/ {
export class GeneralAdminSettings extends AbstractViewSettings {
constructor() {
super();
this.language = LanguageStore.language;
this.languages = LanguageStore.languages;
@ -37,10 +38,9 @@ export class GeneralAdminSettings /*extends AbstractViewSettings*/ {
this.themes = ThemeStore.themes;
addObservablesTo(this, {
allowLanguagesOnSettings: !!SettingsGet('AllowLanguagesOnSettings'),
newMoveToFolder: !!SettingsGet('NewMoveToFolder'),
allowLanguagesOnSettings: SettingsGet('AllowLanguagesOnSettings'),
newMoveToFolder: SettingsGet('NewMoveToFolder'),
attachmentLimitTrigger: SaveSettingsStep.Idle,
languageTrigger: SaveSettingsStep.Idle,
themeTrigger: SaveSettingsStep.Idle,
capaThemes: SettingsCapa(Capa.Themes),
capaUserBackground: SettingsCapa(Capa.UserBackground),
@ -58,10 +58,14 @@ export class GeneralAdminSettings /*extends AbstractViewSettings*/ {
}
*/
this.mainAttachmentLimit = ko
.observable(pInt(SettingsGet('AttachmentLimit')) / (1024 * 1024))
this.attachmentLimit = ko
.observable(SettingsGet('AttachmentLimit') / (1024 * 1024))
.extend({ debounce: 500 });
this.addSetting('Language');
this.addSetting('AttachmentLimit');
this.addSetting('Theme', value => changeTheme(value, this.themeTrigger));
this.uploadData = SettingsGet('PhpUploadSizes');
this.uploadDataDesc =
this.uploadData && (this.uploadData.upload_max_filesize || this.uploadData.post_max_size)
@ -86,20 +90,9 @@ export class GeneralAdminSettings /*extends AbstractViewSettings*/ {
this.languageAdminTrigger(saveSettingsStep);
setTimeout(() => this.languageAdminTrigger(SaveSettingsStep.Idle), 1000);
},
fSaveBoolHelper = key =>
value => Remote.saveConfig({[key]: value ? 1 : 0});
fSaveHelper = key => value => Remote.saveSetting(key, value);
addSubscribablesTo(this, {
mainAttachmentLimit: value =>
Remote.saveConfig({
AttachmentLimit: pInt(value)
}, settingsSaveHelperSimpleFunction(this.attachmentLimitTrigger, this)),
language: value =>
Remote.saveConfig({
Language: value.trim()
}, settingsSaveHelperSimpleFunction(this.languageTrigger, this)),
languageAdmin: value => {
this.languageAdminTrigger(SaveSettingsStep.Animate);
translatorReload(true, value)
@ -109,26 +102,19 @@ export class GeneralAdminSettings /*extends AbstractViewSettings*/ {
}));
},
theme: value => {
changeTheme(value, this.themeTrigger);
Remote.saveConfig({
Theme: value.trim()
}, settingsSaveHelperSimpleFunction(this.themeTrigger, this));
},
capaAdditionalAccounts: fSaveHelper('CapaAdditionalAccounts'),
capaAdditionalAccounts: fSaveBoolHelper('CapaAdditionalAccounts'),
capaIdentities: fSaveHelper('CapaIdentities'),
capaIdentities: fSaveBoolHelper('CapaIdentities'),
capaAttachmentThumbnails: fSaveHelper('CapaAttachmentThumbnails'),
capaAttachmentThumbnails: fSaveBoolHelper('CapaAttachmentThumbnails'),
capaThemes: fSaveHelper('CapaThemes'),
capaThemes: fSaveBoolHelper('CapaThemes'),
capaUserBackground: fSaveHelper('CapaUserBackground'),
capaUserBackground: fSaveBoolHelper('CapaUserBackground'),
allowLanguagesOnSettings: fSaveHelper('AllowLanguagesOnSettings'),
allowLanguagesOnSettings: fSaveBoolHelper('AllowLanguagesOnSettings'),
newMoveToFolder: fSaveBoolHelper('NewMoveToFolder')
newMoveToFolder: fSaveHelper('NewMoveToFolder')
});
}

View file

@ -1,19 +1,19 @@
import { SaveSettingsStep } from 'Common/Enums';
import { Settings, SettingsGet } from 'Common/Globals';
import { settingsSaveHelperSimpleFunction } from 'Common/Utils';
import { addObservablesTo, addSubscribablesTo } from 'External/ko';
import { AbstractViewSettings } from 'Knoin/AbstractViews';
import Remote from 'Remote/Admin/Fetch';
export class LoginAdminSettings /*extends AbstractViewSettings*/ {
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'),
defaultDomain: SettingsGet('LoginDefaultDomain'),
defaultDomainTrigger: SaveSettingsStep.Idle
});
addSubscribablesTo(this, {
@ -35,13 +35,7 @@ export class LoginAdminSettings /*extends AbstractViewSettings*/ {
hideSubmitButton: value =>
Remote.saveConfig({
hideSubmitButton: value ? 1 : 0
}),
defaultDomain: (value =>
Remote.saveConfig({
LoginDefaultDomain: value.trim()
}, settingsSaveHelperSimpleFunction(this.defaultDomainTrigger, this))
).debounce(999)
})
});
}
}