snappymail/dev/App/Admin.js

122 lines
2.8 KiB
JavaScript
Raw Normal View History

2021-01-26 18:46:30 +08:00
import 'External/Admin/ko';
import ko from 'ko';
2015-11-19 01:32:29 +08:00
import { StorageResultType } from 'Common/Enums';
2015-11-19 01:32:29 +08:00
import { AppAdminStore } from 'Stores/Admin/App';
import { CapaAdminStore } from 'Stores/Admin/Capa';
import { DomainAdminStore } from 'Stores/Admin/Domain';
import { PluginAdminStore } from 'Stores/Admin/Plugin';
import { PackageAdminStore } from 'Stores/Admin/Package';
import Remote from 'Remote/Admin/Fetch';
2015-11-19 01:32:29 +08:00
2019-07-05 03:19:24 +08:00
import { SettingsAdminScreen } from 'Screen/Admin/Settings';
import { LoginAdminScreen } from 'Screen/Admin/Login';
2016-07-07 07:11:13 +08:00
2020-09-17 05:19:34 +08:00
import { startScreens } from 'Knoin/Knoin';
2019-07-05 03:19:24 +08:00
import { AbstractApp } from 'App/Abstract';
2015-11-19 01:32:29 +08:00
2019-07-05 03:19:24 +08:00
class AdminApp extends AbstractApp {
2016-07-16 05:29:42 +08:00
constructor() {
2015-11-19 01:32:29 +08:00
super(Remote);
}
remote() {
return Remote;
}
reloadDomainList() {
DomainAdminStore.loading(true);
2015-11-19 01:32:29 +08:00
Remote.domainList((result, data) => {
DomainAdminStore.loading(false);
2019-07-05 03:19:24 +08:00
if (StorageResultType.Success === result && data && data.Result) {
DomainAdminStore(
Object.entries(data.Result).map(([name, [enabled, alias]]) => ({
2019-07-05 03:19:24 +08:00
name: name,
disabled: ko.observable(!enabled),
alias: alias,
deleteAccess: ko.observable(false)
}))
);
2015-11-19 01:32:29 +08:00
}
});
}
reloadPluginList() {
PluginAdminStore.loading(true);
2015-11-19 01:32:29 +08:00
Remote.pluginList((result, data) => {
PluginAdminStore.loading(false);
2019-07-05 03:19:24 +08:00
if (StorageResultType.Success === result && data && data.Result) {
PluginAdminStore(
data.Result.map(item => ({
2019-07-05 03:19:24 +08:00
name: item.Name,
disabled: ko.observable(!item.Enabled),
configured: ko.observable(!!item.Configured)
}))
);
2015-11-19 01:32:29 +08:00
}
});
}
reloadPackagesList() {
PackageAdminStore.loading(true);
2015-11-19 01:32:29 +08:00
Remote.packagesList((result, data) => {
PackageAdminStore.loading(false);
2019-07-05 03:19:24 +08:00
if (StorageResultType.Success === result && data && data.Result) {
PackageAdminStore.real(!!data.Result.Real);
2015-11-19 01:32:29 +08:00
2016-06-30 08:02:45 +08:00
let list = [];
const loading = {};
2015-11-19 01:32:29 +08:00
PackageAdminStore.forEach(item => {
2019-07-05 03:19:24 +08:00
if (item && item.loading()) {
2016-04-21 01:12:51 +08:00
loading[item.file] = item;
2015-11-19 01:32:29 +08:00
}
});
if (Array.isArray(data.Result.List)) {
list = data.Result.List.map(item => {
if (item) {
item.loading = ko.observable(loading[item.file] !== undefined);
return 'core' === item.type && !item.canBeInstalled ? null : item;
}
return null;
}).filter(v => v);
2015-11-19 01:32:29 +08:00
}
PackageAdminStore(list);
2019-07-05 03:19:24 +08:00
} else {
PackageAdminStore.real(false);
2015-11-19 01:32:29 +08:00
}
});
}
bootend() {
2021-01-26 18:46:30 +08:00
progressJs.end();
2015-11-19 01:32:29 +08:00
}
bootstart() {
super.bootstart();
AppAdminStore.populate();
CapaAdminStore.populate();
2015-11-19 01:32:29 +08:00
2020-09-17 05:19:34 +08:00
this.hideLoading();
2015-11-19 01:32:29 +08:00
if (!rl.settings.app('allowAdminPanel')) {
rl.route.root();
setTimeout(() => location.href = '/', 1);
2019-07-05 03:19:24 +08:00
} else {
if (rl.settings.get('Auth')) {
2019-07-05 03:19:24 +08:00
startScreens([SettingsAdminScreen]);
} else {
startScreens([LoginAdminScreen]);
2015-11-19 01:32:29 +08:00
}
}
this.bootend();
}
}
2016-06-17 07:23:49 +08:00
export default new AdminApp();