Updated subscribables

This commit is contained in:
djmaze 2021-03-16 11:38:40 +01:00
parent 4b6f6b1bfc
commit 004eba6be2
7 changed files with 200 additions and 219 deletions

View file

@ -2,7 +2,12 @@ import ko from 'ko';
import { SaveSettingsStep } from 'Common/Enums'; import { SaveSettingsStep } from 'Common/Enums';
import { SettingsGet } from 'Common/Globals'; import { SettingsGet } from 'Common/Globals';
import { settingsSaveHelperSimpleFunction, defaultOptionsAfterRender, addObservablesTo } from 'Common/Utils'; import {
settingsSaveHelperSimpleFunction,
defaultOptionsAfterRender,
addObservablesTo,
addSubscribablesTo
} from 'Common/Utils';
import Remote from 'Remote/Admin/Fetch'; import Remote from 'Remote/Admin/Fetch';
import { decorateKoCommands } from 'Knoin/Knoin'; import { decorateKoCommands } from 'Knoin/Knoin';
@ -50,7 +55,7 @@ export class ContactsAdminSettings {
this.mainContactsType = ko this.mainContactsType = ko
.computed({ .computed({
read: this.contactsType, read: this.contactsType,
write: (value) => { write: value => {
if (value !== this.contactsType()) { if (value !== this.contactsType()) {
if (supportedTypes.includes(value)) { if (supportedTypes.includes(value)) {
this.contactsType(value); this.contactsType(value);
@ -64,11 +69,41 @@ export class ContactsAdminSettings {
}) })
.extend({ notify: 'always' }); .extend({ notify: 'always' });
this.contactsType.subscribe(() => { addSubscribablesTo(this, {
this.testContactsSuccess(false); enableContacts: value =>
this.testContactsError(false); Remote.saveAdminConfig(null, {
this.testContactsErrorMessage(''); 'ContactsEnable': value ? 1 : 0
}); }),
contactsSync: value =>
Remote.saveAdminConfig(null, {
'ContactsSync': value ? 1 : 0
}),
contactsType: value => {
this.testContactsSuccess(false);
this.testContactsError(false);
this.testContactsErrorMessage('');
Remote.saveAdminConfig(settingsSaveHelperSimpleFunction(this.contactsTypeTrigger, this), {
'ContactsPdoType': value.trim()
})
},
pdoDsn: value =>
Remote.saveAdminConfig(settingsSaveHelperSimpleFunction(this.pdoDsnTrigger, this), {
'ContactsPdoDsn': value.trim()
}),
pdoUser: value =>
Remote.saveAdminConfig(settingsSaveHelperSimpleFunction(this.pdoUserTrigger, this), {
'ContactsPdoUser': value.trim()
}),
pdoPassword: value =>
Remote.saveAdminConfig(settingsSaveHelperSimpleFunction(this.pdoPasswordTrigger, this), {
'ContactsPdoPassword': value.trim()
})
})
this.contactsType(SettingsGet('ContactsPdoType')); this.contactsType(SettingsGet('ContactsPdoType'));
@ -117,51 +152,4 @@ export class ContactsAdminSettings {
this.testContactsError(false); this.testContactsError(false);
this.testContactsErrorMessage(''); this.testContactsErrorMessage('');
} }
onBuild() {
setTimeout(() => {
const f1 = settingsSaveHelperSimpleFunction(this.pdoDsnTrigger, this),
f3 = settingsSaveHelperSimpleFunction(this.pdoUserTrigger, this),
f4 = settingsSaveHelperSimpleFunction(this.pdoPasswordTrigger, this),
f5 = settingsSaveHelperSimpleFunction(this.contactsTypeTrigger, this);
this.enableContacts.subscribe((value) => {
Remote.saveAdminConfig(null, {
'ContactsEnable': value ? '1' : '0'
});
});
this.contactsSync.subscribe((value) => {
Remote.saveAdminConfig(null, {
'ContactsSync': value ? '1' : '0'
});
});
this.contactsType.subscribe((value) => {
Remote.saveAdminConfig(f5, {
'ContactsPdoType': value.trim()
});
});
this.pdoDsn.subscribe((value) => {
Remote.saveAdminConfig(f1, {
'ContactsPdoDsn': value.trim()
});
});
this.pdoUser.subscribe((value) => {
Remote.saveAdminConfig(f3, {
'ContactsPdoUser': value.trim()
});
});
this.pdoPassword.subscribe((value) => {
Remote.saveAdminConfig(f4, {
'ContactsPdoPassword': value.trim()
});
});
this.contactsType(SettingsGet('ContactsPdoType'));
}, 50);
}
} }

View file

@ -1,7 +1,7 @@
import ko from 'ko'; import ko from 'ko';
import { Settings, SettingsGet } from 'Common/Globals'; import { Settings, SettingsGet } from 'Common/Globals';
import { settingsSaveHelperSimpleFunction, addObservablesTo } from 'Common/Utils'; import { settingsSaveHelperSimpleFunction, addObservablesTo, addSubscribablesTo } from 'Common/Utils';
import Remote from 'Remote/Admin/Fetch'; import Remote from 'Remote/Admin/Fetch';
@ -15,41 +15,32 @@ export class LoginAdminSettings {
}); });
this.defaultDomain = ko.observable(SettingsGet('LoginDefaultDomain')).idleTrigger(); this.defaultDomain = ko.observable(SettingsGet('LoginDefaultDomain')).idleTrigger();
}
onBuild() { addSubscribablesTo(this, {
setTimeout(() => { determineUserLanguage: value =>
const f1 = settingsSaveHelperSimpleFunction(this.defaultDomain.trigger, this);
this.determineUserLanguage.subscribe(value =>
Remote.saveAdminConfig(null, { Remote.saveAdminConfig(null, {
'DetermineUserLanguage': value ? '1' : '0' 'DetermineUserLanguage': value ? 1 : 0
}) }),
);
this.determineUserDomain.subscribe(value => determineUserDomain: value =>
Remote.saveAdminConfig(null, { Remote.saveAdminConfig(null, {
'DetermineUserDomain': value ? '1' : '0' 'DetermineUserDomain': value ? 1 : 0
}) }),
);
this.allowLanguagesOnLogin.subscribe(value => allowLanguagesOnLogin: value =>
Remote.saveAdminConfig(null, { Remote.saveAdminConfig(null, {
'AllowLanguagesOnLogin': value ? '1' : '0' 'AllowLanguagesOnLogin': value ? 1 : 0
}) }),
);
this.hideSubmitButton.subscribe(value => hideSubmitButton: value =>
Remote.saveAdminConfig(null, { Remote.saveAdminConfig(null, {
'hideSubmitButton': value ? '1' : '0' 'hideSubmitButton': value ? 1 : 0
}) }),
);
this.defaultDomain.subscribe(value => defaultDomain: value =>
Remote.saveAdminConfig(f1, { Remote.saveAdminConfig(settingsSaveHelperSimpleFunction(this.defaultDomain.trigger, this), {
'LoginDefaultDomain': value.trim() 'LoginDefaultDomain': value.trim()
}) })
); });
}, 50);
} }
} }

View file

@ -21,6 +21,12 @@ export class PluginsAdminSettings {
this.onPluginLoadRequest = this.onPluginLoadRequest.bind(this); this.onPluginLoadRequest = this.onPluginLoadRequest.bind(this);
this.onPluginDisableRequest = this.onPluginDisableRequest.bind(this); this.onPluginDisableRequest = this.onPluginDisableRequest.bind(this);
this.enabledPlugins.subscribe(value =>
Remote.saveAdminConfig(null, {
'EnabledPlugins': value ? 1 : 0
})
);
} }
disablePlugin(plugin) { disablePlugin(plugin) {
@ -40,12 +46,6 @@ export class PluginsAdminSettings {
el = event.target.closestWithin('.e-item .disabled-plugin', oDom); el = event.target.closestWithin('.e-item .disabled-plugin', oDom);
el && ko.dataFor(el) && this.disablePlugin(ko.dataFor(el)); el && ko.dataFor(el) && this.disablePlugin(ko.dataFor(el));
}); });
this.enabledPlugins.subscribe((value) => {
Remote.saveAdminConfig(null, {
'EnabledPlugins': value ? '1' : '0'
});
});
} }
onShow() { onShow() {

View file

@ -24,23 +24,21 @@ export class ContactsUserSettings {
].join('|') ].join('|')
) )
.extend({ debounce: 500 }); .extend({ debounce: 500 });
}
onBuild() { this.contactsAutosave.subscribe(value =>
this.contactsAutosave.subscribe((value) => {
Remote.saveSettings(null, { Remote.saveSettings(null, {
'ContactsAutosave': value ? '1' : '0' 'ContactsAutosave': value ? 1 : 0
}); })
}); );
this.saveTrigger.subscribe(() => { this.saveTrigger.subscribe(() =>
Remote.saveContactsSyncData( Remote.saveContactsSyncData(
null, null,
ContactUserStore.enableSync(), ContactUserStore.enableSync(),
ContactUserStore.syncUrl(), ContactUserStore.syncUrl(),
ContactUserStore.syncUser(), ContactUserStore.syncUser(),
ContactUserStore.syncPass() ContactUserStore.syncPass()
); )
}); );
} }
} }

View file

@ -4,7 +4,7 @@ import { MESSAGES_PER_PAGE_VALUES } from 'Common/Consts';
import { SaveSettingsStep } from 'Common/Enums'; import { SaveSettingsStep } from 'Common/Enums';
import { EditorDefaultType, Layout } from 'Common/EnumsUser'; import { EditorDefaultType, Layout } from 'Common/EnumsUser';
import { SettingsGet } from 'Common/Globals'; import { SettingsGet } from 'Common/Globals';
import { settingsSaveHelperSimpleFunction, addObservablesTo } from 'Common/Utils'; import { settingsSaveHelperSimpleFunction, addObservablesTo, addSubscribablesTo } from 'Common/Utils';
import { i18n, trigger as translatorTrigger, reload as translatorReload, convertLangName } from 'Common/Translator'; import { i18n, trigger as translatorTrigger, reload as translatorReload, convertLangName } from 'Common/Translator';
import { showScreenPopup } from 'Knoin/Knoin'; import { showScreenPopup } from 'Knoin/Knoin';
@ -83,6 +83,68 @@ export class GeneralUserSettings {
{ 'id': Layout.BottomPreview, 'name': i18n('SETTINGS_GENERAL/LABEL_LAYOUT_HORIZONTAL_SPLIT') } { 'id': Layout.BottomPreview, 'name': i18n('SETTINGS_GENERAL/LABEL_LAYOUT_HORIZONTAL_SPLIT') }
]; ];
}); });
const fReloadLanguageHelper = (saveSettingsStep) => () => {
this.languageTrigger(saveSettingsStep);
setTimeout(() => this.languageTrigger(SaveSettingsStep.Idle), 1000);
};
addSubscribablesTo(this, {
language: value => {
this.languageTrigger(SaveSettingsStep.Animate);
translatorReload(false, value)
.then(fReloadLanguageHelper(SaveSettingsStep.TrueResult), fReloadLanguageHelper(SaveSettingsStep.FalseResult))
.then(() => {
Remote.saveSettings(null, {
'Language': value
});
});
},
editorDefaultType:
Remote.saveSettingsHelper('EditorDefaultType', null,
settingsSaveHelperSimpleFunction(this.editorDefaultTypeTrigger, this)),
messagesPerPage: Remote.saveSettingsHelper('MPP', null, settingsSaveHelperSimpleFunction(this.mppTrigger, this)),
showImages: Remote.saveSettingsHelper('ShowImages', v=>v?'1':'0'),
removeColors: Remote.saveSettingsHelper('RemoveColors', v=>v?'1':'0'),
useCheckboxesInList: Remote.saveSettingsHelper('UseCheckboxesInList', v=>v?'1':'0'),
enableDesktopNotification: (value =>
Remote.saveSettings(null, {
'DesktopNotifications': value ? 1 : 0
})
).debounce(3000),
enableSoundNotification: (value =>
Remote.saveSettings(null, {
'SoundNotification': value ? 1 : 0
})
).debounce(3000),
replySameFolder: (value =>
Remote.saveSettings(null, {
'ReplySameFolder': value ? 1 : 0
})
).debounce(3000),
useThreads: value => {
MessageUserStore.list([]);
Remote.saveSettings(null, {
'UseThreads': value ? 1 : 0
});
},
layout: value => {
MessageUserStore.list([]);
Remote.saveSettings(settingsSaveHelperSimpleFunction(this.layoutTrigger, this), {
'Layout': value
});
}
});
} }
editMainIdentity() { editMainIdentity() {
@ -100,68 +162,6 @@ export class GeneralUserSettings {
NotificationUserStore.displayDesktopNotification('SnappyMail', 'Test notification', { }); NotificationUserStore.displayDesktopNotification('SnappyMail', 'Test notification', { });
} }
onBuild() {
setTimeout(() => {
const f0 = settingsSaveHelperSimpleFunction(this.editorDefaultTypeTrigger, this),
f1 = settingsSaveHelperSimpleFunction(this.mppTrigger, this),
f2 = settingsSaveHelperSimpleFunction(this.layoutTrigger, this),
fReloadLanguageHelper = (saveSettingsStep) => () => {
this.languageTrigger(saveSettingsStep);
setTimeout(() => this.languageTrigger(SaveSettingsStep.Idle), 1000);
};
this.language.subscribe((value) => {
this.languageTrigger(SaveSettingsStep.Animate);
translatorReload(false, value)
.then(fReloadLanguageHelper(SaveSettingsStep.TrueResult), fReloadLanguageHelper(SaveSettingsStep.FalseResult))
.then(() => {
Remote.saveSettings(null, {
'Language': value
});
});
});
this.editorDefaultType.subscribe(Remote.saveSettingsHelper('EditorDefaultType', null, f0));
this.messagesPerPage.subscribe(Remote.saveSettingsHelper('MPP', null, f1));
this.showImages.subscribe(Remote.saveSettingsHelper('ShowImages', v=>v?'1':'0'));
this.removeColors.subscribe(Remote.saveSettingsHelper('RemoveColors', v=>v?'1':'0'));
this.useCheckboxesInList.subscribe(Remote.saveSettingsHelper('UseCheckboxesInList', v=>v?'1':'0'));
this.enableDesktopNotification.subscribe((value =>
Remote.saveSettings(null, {
'DesktopNotifications': value ? 1 : 0
})
).debounce(3000));
this.enableSoundNotification.subscribe((value =>
Remote.saveSettings(null, {
'SoundNotification': value ? 1 : 0
})
).debounce(3000));
this.replySameFolder.subscribe((value =>
Remote.saveSettings(null, {
'ReplySameFolder': value ? 1 : 0
})
).debounce(3000));
this.useThreads.subscribe((value) => {
MessageUserStore.list([]);
Remote.saveSettings(null, {
'UseThreads': value ? 1 : 0
});
});
this.layout.subscribe((value) => {
MessageUserStore.list([]);
Remote.saveSettings(f2, {
'Layout': value
});
});
}, 50);
}
selectLanguage() { selectLanguage() {
showScreenPopup(LanguagesPopupView, [this.language, this.languages(), LanguageStore.userLanguage()]); showScreenPopup(LanguagesPopupView, [this.language, this.languages(), LanguageStore.userLanguage()]);
} }

View file

@ -2,7 +2,7 @@ import ko from 'ko';
import { FolderType } from 'Common/EnumsUser'; import { FolderType } from 'Common/EnumsUser';
import { UNUSED_OPTION_VALUE } from 'Common/Consts'; import { UNUSED_OPTION_VALUE } from 'Common/Consts';
import { addObservablesTo } from 'Common/Utils'; import { addObservablesTo, addSubscribablesTo } from 'Common/Utils';
import { folderListOptionsBuilder } from 'Common/UtilsUser'; import { folderListOptionsBuilder } from 'Common/UtilsUser';
import { getFolderInboxName, getFolderFromCacheList } from 'Common/Cache'; import { getFolderInboxName, getFolderFromCacheList } from 'Common/Cache';
import { SettingsGet } from 'Common/Globals'; import { SettingsGet } from 'Common/Globals';
@ -125,18 +125,19 @@ export const FolderUserStore = new class {
) )
); );
const fRemoveSystemFolderType = (observable) => () => { const
const folder = getFolderFromCacheList(observable()); fRemoveSystemFolderType = (observable) => () => {
if (folder) { const folder = getFolderFromCacheList(observable());
folder.type(FolderType.User); if (folder) {
} folder.type(FolderType.User);
}; }
const fSetSystemFolderType = (type) => (value) => { },
const folder = getFolderFromCacheList(value); fSetSystemFolderType = type => value => {
if (folder) { const folder = getFolderFromCacheList(value);
folder.type(type); if (folder) {
} folder.type(type);
}; }
};
this.sentFolder.subscribe(fRemoveSystemFolderType(this.sentFolder), this, 'beforeChange'); this.sentFolder.subscribe(fRemoveSystemFolderType(this.sentFolder), this, 'beforeChange');
this.draftFolder.subscribe(fRemoveSystemFolderType(this.draftFolder), this, 'beforeChange'); this.draftFolder.subscribe(fRemoveSystemFolderType(this.draftFolder), this, 'beforeChange');
@ -144,11 +145,13 @@ export const FolderUserStore = new class {
this.trashFolder.subscribe(fRemoveSystemFolderType(this.trashFolder), this, 'beforeChange'); this.trashFolder.subscribe(fRemoveSystemFolderType(this.trashFolder), this, 'beforeChange');
this.archiveFolder.subscribe(fRemoveSystemFolderType(this.archiveFolder), this, 'beforeChange'); this.archiveFolder.subscribe(fRemoveSystemFolderType(this.archiveFolder), this, 'beforeChange');
this.sentFolder.subscribe(fSetSystemFolderType(FolderType.SentItems), this); addSubscribablesTo(this, {
this.draftFolder.subscribe(fSetSystemFolderType(FolderType.Draft), this); sentFolder: fSetSystemFolderType(FolderType.SentItems),
this.spamFolder.subscribe(fSetSystemFolderType(FolderType.Spam), this); draftFolder: fSetSystemFolderType(FolderType.Draft),
this.trashFolder.subscribe(fSetSystemFolderType(FolderType.Trash), this); spamFolder: fSetSystemFolderType(FolderType.Spam),
this.archiveFolder.subscribe(fSetSystemFolderType(FolderType.Archive), this); trashFolder: fSetSystemFolderType(FolderType.Trash),
archiveFolder: fSetSystemFolderType(FolderType.Archive)
});
} }
/** /**

View file

@ -3,7 +3,7 @@ import ko from 'ko';
import { Notification } from 'Common/Enums'; import { Notification } from 'Common/Enums';
import { Focused, MessageSetAction } from 'Common/EnumsUser'; import { Focused, MessageSetAction } from 'Common/EnumsUser';
import { doc, elementById } from 'Common/Globals'; import { doc, elementById } from 'Common/Globals';
import { pInt, pString, addObservablesTo } from 'Common/Utils'; import { pInt, pString, addObservablesTo, addSubscribablesTo } from 'Common/Utils';
import { plainToHtml } from 'Common/UtilsUser'; import { plainToHtml } from 'Common/UtilsUser';
import { import {
@ -170,52 +170,53 @@ export const MessageUserStore = new class {
// Subscribers // Subscribers
let timer = 0, fn = this.listLoadingAnimation; let timer = 0, fn = this.listLoadingAnimation;
this.listCompleteLoading.subscribe(value => {
if (value) { addSubscribablesTo(this, {
fn(value); listCompleteLoading: value => {
} else if (fn()) { if (value) {
clearTimeout(timer); fn(value);
timer = setTimeout(() => { } else if (fn()) {
clearTimeout(timer);
timer = setTimeout(() => {
fn(value);
timer = 0;
}, 700);
} else {
fn(value); fn(value);
timer = 0;
}, 700);
} else {
fn(value);
}
});
this.listLoading.subscribe(value =>
this.listCompleteLoading(value || this.listIsNotCompleted())
);
this.listIsNotCompleted.subscribe(value =>
this.listCompleteLoading(value || this.listLoading())
);
this.list.subscribe(
(list => {
list.forEach(item =>
item && item.newForAnimation() && item.newForAnimation(false)
)
}).debounce(500)
);
this.message.subscribe(message => {
if (message) {
if (!SettingsUserStore.usePreviewPane()) {
AppUserStore.focusedState(Focused.MessageView);
} }
} else { },
AppUserStore.focusedState(Focused.MessageList);
this.messageFullScreenMode(false); listLoading: value =>
this.hideMessageBodies(); this.listCompleteLoading(value || this.listIsNotCompleted()),
}
});
this.listEndFolder.subscribe(folder => { listIsNotCompleted: value =>
const message = this.message(); this.listCompleteLoading(value || this.listLoading()),
if (message && folder && folder !== message.folder) {
this.message(null); list:
(list => {
list.forEach(item =>
item && item.newForAnimation() && item.newForAnimation(false)
)
}).debounce(500),
message: message => {
if (message) {
if (!SettingsUserStore.usePreviewPane()) {
AppUserStore.focusedState(Focused.MessageView);
}
} else {
AppUserStore.focusedState(Focused.MessageList);
this.messageFullScreenMode(false);
this.hideMessageBodies();
}
},
listEndFolder: folder => {
const message = this.message();
if (message && folder && folder !== message.folder) {
this.message(null);
}
} }
}); });