Also reduce admin remote fetch

This commit is contained in:
djmaze 2021-12-03 00:11:19 +01:00
parent c1228d09f0
commit 35bce8cf62
11 changed files with 148 additions and 260 deletions

View file

@ -1,25 +1,6 @@
import { AbstractFetchRemote } from 'Remote/AbstractFetch'; import { AbstractFetchRemote } from 'Remote/AbstractFetch';
class RemoteAdminFetch extends AbstractFetchRemote { class RemoteAdminFetch extends AbstractFetchRemote {
/**
* @param {?Function} fCallback
* @param {string} sLogin
* @param {string} sPassword
*/
adminLogin(fCallback, sLogin, sPassword, sCode) {
this.request('AdminLogin', fCallback, {
Login: sLogin,
Password: sPassword,
TOTP: sCode
});
}
/**
* @param {?Function} fCallback
*/
adminLogout(fCallback) {
this.request('AdminLogout', fCallback);
}
/** /**
* @param {?Function} fCallback * @param {?Function} fCallback
@ -29,170 +10,6 @@ class RemoteAdminFetch extends AbstractFetchRemote {
this.request('AdminSettingsUpdate', fCallback, oData); this.request('AdminSettingsUpdate', fCallback, oData);
} }
/**
* @param {?Function} fCallback
* @param {boolean=} bIncludeAliases = true
*/
domainList(fCallback, bIncludeAliases = true) {
this.request('AdminDomainList', fCallback, {
IncludeAliases: bIncludeAliases ? 1 : 0
});
}
/**
* @param {?Function} fCallback
*/
packagesList(fCallback) {
this.request('AdminPackagesList', fCallback);
}
/**
* @param {?Function} fCallback
* @param {Object} oPackage
*/
packageInstall(fCallback, oPackage) {
this.request('AdminPackageInstall', fCallback,
{
Id: oPackage.id,
Type: oPackage.type,
File: oPackage.file
},
60000
);
}
/**
* @param {?Function} fCallback
* @param {Object} oPackage
*/
packageDelete(fCallback, oPackage) {
this.request('AdminPackageDelete', fCallback, {
Id: oPackage.id
});
}
/**
* @param {?Function} fCallback
* @param {string} sName
*/
domain(fCallback, sName) {
this.request('AdminDomainLoad', fCallback, {
Name: sName
});
}
/**
* @param {?Function} fCallback
* @param {string} sId
*/
plugin(fCallback, sId) {
this.request('AdminPluginLoad', fCallback, {
Id: sId
});
}
/**
* @param {?Function} fCallback
* @param {string} sName
*/
domainDelete(fCallback, sName) {
this.request('AdminDomainDelete', fCallback, {
Name: sName
});
}
/**
* @param {?Function} fCallback
* @param {string} sName
* @param {boolean} bDisabled
*/
domainDisable(fCallback, sName, bDisabled) {
this.request('AdminDomainDisable', fCallback, {
Name: sName,
Disabled: bDisabled ? 1 : 0
});
}
/**
* @param {?Function} fCallback
* @param {Object} oConfig
*/
pluginSettingsUpdate(fCallback, oConfig) {
this.request('AdminPluginSettingsUpdate', fCallback, oConfig);
}
/**
* @param {?Function} fCallback
* @param {string} sId
* @param {boolean} bDisabled
*/
pluginDisable(fCallback, sId, bDisabled) {
this.request('AdminPluginDisable', fCallback, {
Id: sId,
Disabled: bDisabled ? 1 : 0
});
}
createDomainAlias(fCallback, sName, sAlias) {
this.request('AdminDomainAliasSave', fCallback, {
Name: sName,
Alias: sAlias
});
}
createOrUpdateDomain(fCallback, oDomain) {
this.request('AdminDomainSave', fCallback, {
Create: oDomain.edit() ? 0 : 1,
Name: oDomain.name(),
IncHost: oDomain.imapServer(),
IncPort: oDomain.imapPort(),
IncSecure: oDomain.imapSecure(),
IncShortLogin: oDomain.imapShortLogin() ? 1 : 0,
UseSieve: oDomain.useSieve() ? 1 : 0,
SieveHost: oDomain.sieveServer(),
SievePort: oDomain.sievePort(),
SieveSecure: oDomain.sieveSecure(),
OutHost: oDomain.smtpServer(),
OutPort: oDomain.smtpPort(),
OutSecure: oDomain.smtpSecure(),
OutShortLogin: oDomain.smtpShortLogin() ? 1 : 0,
OutAuth: oDomain.smtpAuth() ? 1 : 0,
OutSetSender: oDomain.smtpSetSender() ? 1 : 0,
OutUsePhpMail: oDomain.smtpPhpMail() ? 1 : 0,
WhiteList: oDomain.whiteList()
});
}
testConnectionForDomain(fCallback, oDomain) {
this.request('AdminDomainTest', fCallback, {
Name: oDomain.name(),
IncHost: oDomain.imapServer(),
IncPort: oDomain.imapPort(),
IncSecure: oDomain.imapSecure(),
UseSieve: oDomain.useSieve() ? 1 : 0,
SieveHost: oDomain.sieveServer(),
SievePort: oDomain.sievePort(),
SieveSecure: oDomain.sieveSecure(),
OutHost: oDomain.smtpServer(),
OutPort: oDomain.smtpPort(),
OutSecure: oDomain.smtpSecure(),
OutAuth: oDomain.smtpAuth() ? 1 : 0,
OutUsePhpMail: oDomain.smtpPhpMail() ? 1 : 0
});
}
/**
* @param {?Function} fCallback
* @param {?} oData
*/
testContacts(fCallback, oData) {
this.request('AdminContactsTest', fCallback, oData);
}
} }
export default new RemoteAdminFetch(); export default new RemoteAdminFetch();

View file

@ -116,7 +116,8 @@ export class ContactsAdminSettings /*extends AbstractViewSettings*/ {
this.testContactsErrorMessage(''); this.testContactsErrorMessage('');
this.testing(true); this.testing(true);
Remote.testContacts((iError, data) => { Remote.request('AdminContactsTest',
(iError, data) => {
this.testContactsSuccess(false); this.testContactsSuccess(false);
this.testContactsError(false); this.testContactsError(false);
this.testContactsErrorMessage(''); this.testContactsErrorMessage('');
@ -138,7 +139,8 @@ export class ContactsAdminSettings /*extends AbstractViewSettings*/ {
ContactsPdoDsn: this.pdoDsn(), ContactsPdoDsn: this.pdoDsn(),
ContactsPdoUser: this.pdoUser(), ContactsPdoUser: this.pdoUser(),
ContactsPdoPassword: this.pdoPassword() ContactsPdoPassword: this.pdoPassword()
}); }
);
} }
onShow() { onShow() {

View file

@ -26,19 +26,29 @@ export class DomainsAdminSettings /*extends AbstractViewSettings*/ {
deleteDomain(domain) { deleteDomain(domain) {
DomainAdminStore.remove(domain); DomainAdminStore.remove(domain);
Remote.domainDelete(DomainAdminStore.fetch, domain.name); Remote.domainDelete(DomainAdminStore.fetch, domain.name);
Remote.request('AdminDomainDelete', DomainAdminStore.fetch, {
Name: domain.name
});
} }
disableDomain(domain) { disableDomain(domain) {
domain.disabled(!domain.disabled()); domain.disabled(!domain.disabled());
Remote.domainDisable(DomainAdminStore.fetch, domain.name, domain.disabled()); Remote.request('AdminDomainDisable', DomainAdminStore.fetch, {
Name: domain.name,
Disabled: domain.disabled() ? 1 : 0
});
} }
onBuild(oDom) { onBuild(oDom) {
oDom.addEventListener('click', event => { oDom.addEventListener('click', event => {
let el = event.target.closestWithin('.b-admin-domains-list-table .e-action', oDom); let el = event.target.closestWithin('.b-admin-domains-list-table .e-action', oDom);
el && ko.dataFor(el) && Remote.domain( el && ko.dataFor(el) && Remote.request('AdminDomainLoad',
(iError, oData) => iError || showScreenPopup(DomainPopupView, [oData.Result]), ko.dataFor(el).name (iError, oData) => iError || showScreenPopup(DomainPopupView, [oData.Result]),
{
Name: ko.dataFor(el).name
}
); );
}); });
DomainAdminStore.fetch(); DomainAdminStore.fetch();

View file

@ -44,7 +44,12 @@ export class PackagesAdminSettings /*extends AbstractViewSettings*/ {
// configurePlugin // configurePlugin
let el = event.target.closestWithin('.package-configure', oDom), let el = event.target.closestWithin('.package-configure', oDom),
data = el ? ko.dataFor(el) : 0; data = el ? ko.dataFor(el) : 0;
data && Remote.plugin((iError, data) => iError || showScreenPopup(PluginPopupView, [data.Result]), data.id) data && Remote.request('AdminPluginLoad',
(iError, data) => iError || showScreenPopup(PluginPopupView, [data.Result]),
{
Id: data.id
}
);
// disablePlugin // disablePlugin
el = event.target.closestWithin('.package-active', oDom); el = event.target.closestWithin('.package-active', oDom);
data = el ? ko.dataFor(el) : 0; data = el ? ko.dataFor(el) : 0;
@ -77,23 +82,37 @@ export class PackagesAdminSettings /*extends AbstractViewSettings*/ {
deletePackage(packageToDelete) { deletePackage(packageToDelete) {
if (packageToDelete) { if (packageToDelete) {
packageToDelete.loading(true); packageToDelete.loading(true);
Remote.packageDelete(this.requestHelper(packageToDelete, false), packageToDelete); Remote.request('AdminPackageDelete',
this.requestHelper(packageToDelete, false),
{
Id: packageToDelete.id
}
);
} }
} }
installPackage(packageToInstall) { installPackage(packageToInstall) {
if (packageToInstall) { if (packageToInstall) {
packageToInstall.loading(true); packageToInstall.loading(true);
Remote.packageInstall(this.requestHelper(packageToInstall, true), packageToInstall); Remote.request('AdminPackageInstall',
this.requestHelper(packageToInstall, true),
{
Id: packageToInstall.id,
Type: packageToInstall.type,
File: packageToInstall.file
},
60000
);
} }
} }
disablePlugin(plugin) { disablePlugin(plugin) {
let b = plugin.enabled(); let disable = plugin.enabled();
plugin.enabled(!b); plugin.enabled(!disable);
Remote.pluginDisable((iError, data) => { Remote.request('AdminPluginDisable',
(iError, data) => {
if (iError) { if (iError) {
plugin.enabled(b); plugin.enabled(disable);
this.packagesError( this.packagesError(
(Notification.UnsupportedPluginPackage === iError && data && data.ErrorMessage) (Notification.UnsupportedPluginPackage === iError && data && data.ErrorMessage)
? data.ErrorMessage ? data.ErrorMessage
@ -101,7 +120,11 @@ export class PackagesAdminSettings /*extends AbstractViewSettings*/ {
); );
} }
// PackageAdminStore.fetch(); // PackageAdminStore.fetch();
}, plugin.id, b); }, {
Id: plugin.id,
Disabled: disable ? 1 : 0
}
);
} }
} }

View file

@ -7,7 +7,8 @@ DomainAdminStore.loading = ko.observable(false);
DomainAdminStore.fetch = () => { DomainAdminStore.fetch = () => {
DomainAdminStore.loading(true); DomainAdminStore.loading(true);
Remote.domainList((iError, data) => { Remote.request('AdminDomainList',
(iError, data) => {
DomainAdminStore.loading(false); DomainAdminStore.loading(false);
if (!iError) { if (!iError) {
DomainAdminStore( DomainAdminStore(
@ -19,5 +20,8 @@ DomainAdminStore.fetch = () => {
})) }))
); );
} }
}, {
IncludeAliases: 1
}); });
Remote.domainList();
}; };

View file

@ -12,7 +12,7 @@ PackageAdminStore.error = ko.observable('');
PackageAdminStore.fetch = () => { PackageAdminStore.fetch = () => {
PackageAdminStore.loading(true); PackageAdminStore.loading(true);
Remote.packagesList((iError, data) => { Remote.request('AdminPackagesList', (iError, data) => {
PackageAdminStore.loading(false); PackageAdminStore.loading(false);
if (iError) { if (iError) {
PackageAdminStore.real(false); PackageAdminStore.real(false);

View file

@ -43,7 +43,7 @@ class LoginAdminView extends AbstractViewLogin {
if (valid) { if (valid) {
this.submitRequest(true); this.submitRequest(true);
Remote.adminLogin( Remote.request('AdminLogin',
(iError, oData) => { (iError, oData) => {
if (iError) { if (iError) {
this.submitRequest(false); this.submitRequest(false);
@ -51,11 +51,11 @@ class LoginAdminView extends AbstractViewLogin {
} else { } else {
rl.setData(oData.Result); rl.setData(oData.Result);
} }
}, }, {
name, Login: name,
pass, Password: pass,
this.totp() TOTP: this.totp()
); });
} }
return valid; return valid;

View file

@ -21,7 +21,7 @@ class PaneSettingsAdminView extends AbstractViewRight {
} }
logoutClick() { logoutClick() {
Remote.adminLogout(() => rl.logoutReload()); Remote.request('AdminLogout', () => rl.logoutReload());
} }
} }

View file

@ -8,6 +8,25 @@ import { AbstractViewPopup } from 'Knoin/AbstractViews';
import { DomainAdminStore } from 'Stores/Admin/Domain'; import { DomainAdminStore } from 'Stores/Admin/Domain';
const domainToParams = oDomain => ({
Name: oDomain.name(),
IncHost: oDomain.imapServer(),
IncPort: oDomain.imapPort(),
IncSecure: oDomain.imapSecure(),
UseSieve: oDomain.useSieve() ? 1 : 0,
SieveHost: oDomain.sieveServer(),
SievePort: oDomain.sievePort(),
SieveSecure: oDomain.sieveSecure(),
OutHost: oDomain.smtpServer(),
OutPort: oDomain.smtpPort(),
OutSecure: oDomain.smtpSecure(),
OutAuth: oDomain.smtpAuth() ? 1 : 0,
OutUsePhpMail: oDomain.smtpPhpMail() ? 1 : 0
});
class DomainPopupView extends AbstractViewPopup { class DomainPopupView extends AbstractViewPopup {
constructor() { constructor() {
super('Domain'); super('Domain');
@ -144,9 +163,18 @@ class DomainPopupView extends AbstractViewPopup {
createOrAddCommand() { createOrAddCommand() {
this.saving(true); this.saving(true);
Remote.createOrUpdateDomain( Remote.request('AdminDomainSave',
this.onDomainCreateOrSaveResponse.bind(this), this.onDomainCreateOrSaveResponse.bind(this),
this Object.assign(domainToParams(this), {
Create: this.edit() ? 0 : 1,
IncShortLogin: this.imapShortLogin() ? 1 : 0,
OutShortLogin: this.smtpShortLogin() ? 1 : 0,
OutSetSender: this.smtpSetSender() ? 1 : 0,
WhiteList: this.whiteList()
})
); );
} }
@ -157,7 +185,7 @@ class DomainPopupView extends AbstractViewPopup {
this.testingSmtpError(false); this.testingSmtpError(false);
this.testing(true); this.testing(true);
Remote.testConnectionForDomain( Remote.request('AdminDomainTest',
(iError, oData) => { (iError, oData) => {
this.testing(false); this.testing(false);
if (iError) { if (iError) {
@ -186,7 +214,7 @@ class DomainPopupView extends AbstractViewPopup {
} }
} }
}, },
this domainToParams(this)
); );
} }

View file

@ -35,7 +35,8 @@ class DomainAliasPopupView extends AbstractViewPopup {
createCommand() { createCommand() {
this.saving(true); this.saving(true);
Remote.createDomainAlias(iError => { Remote.request('AdminDomainAliasSave',
iError => {
this.saving(false); this.saving(false);
if (iError) { if (iError) {
this.savingError(getNotification(iError)); this.savingError(getNotification(iError));
@ -43,7 +44,10 @@ class DomainAliasPopupView extends AbstractViewPopup {
DomainAdminStore.fetch(); DomainAdminStore.fetch();
this.closeCommand(); this.closeCommand();
} }
}, this.name(), this.alias()); }, {
Name: this.name(),
Alias: this.alias()
});
} }
onShow() { onShow() {

View file

@ -39,7 +39,7 @@ class PluginPopupView extends AbstractViewPopup {
} }
saveCommand() { saveCommand() {
const list = { const oConfig = {
Id: this.id(), Id: this.id(),
Settings: {} Settings: {}
}; };
@ -49,15 +49,15 @@ class PluginPopupView extends AbstractViewPopup {
if (false === value || true === value) { if (false === value || true === value) {
value = value ? 1 : 0; value = value ? 1 : 0;
} }
list.Settings[oItem.Name] = value; oConfig.Settings[oItem.Name] = value;
}); });
this.saveError(''); this.saveError('');
Remote.pluginSettingsUpdate(iError => Remote.request('AdminPluginSettingsUpdate',
iError iError => iError
? this.saveError(getNotification(iError)) ? this.saveError(getNotification(iError))
: this.cancelCommand() : this.cancelCommand(),
, list); oConfig);
} }
onShow(oPlugin) { onShow(oPlugin) {