snappymail/dev/App/Admin.js

125 lines
2.9 KiB
JavaScript
Raw Normal View History

import ko from 'External/Admin/ko';
2015-11-19 01:32:29 +08:00
import { StorageResultType } from 'Common/Enums';
2015-11-19 01:32:29 +08:00
import AppStore from 'Stores/Admin/App';
import CapaStore from 'Stores/Admin/Capa';
2015-11-19 01:32:29 +08:00
import DomainStore from 'Stores/Admin/Domain';
import PluginStore from 'Stores/Admin/Plugin';
import PackageStore 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() {
DomainStore.domains.loading(true);
Remote.domainList((result, data) => {
DomainStore.domains.loading(false);
2019-07-05 03:19:24 +08:00
if (StorageResultType.Success === result && data && data.Result) {
DomainStore.domains(
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() {
PluginStore.plugins.loading(true);
Remote.pluginList((result, data) => {
PluginStore.plugins.loading(false);
2019-07-05 03:19:24 +08:00
if (StorageResultType.Success === result && data && data.Result) {
PluginStore.plugins(
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() {
PackageStore.packages.loading(true);
PackageStore.packagesReal(true);
Remote.packagesList((result, data) => {
PackageStore.packages.loading(false);
2019-07-05 03:19:24 +08:00
if (StorageResultType.Success === result && data && data.Result) {
2015-11-19 01:32:29 +08:00
PackageStore.packagesReal(!!data.Result.Real);
PackageStore.packagesMainUpdatable(!!data.Result.MainUpdatable);
2016-06-30 08:02:45 +08:00
let list = [];
const loading = {};
2015-11-19 01:32:29 +08:00
PackageStore.packages().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(value => !!value);
2015-11-19 01:32:29 +08:00
}
PackageStore.packages(list);
2019-07-05 03:19:24 +08:00
} else {
2015-11-19 01:32:29 +08:00
PackageStore.packagesReal(false);
}
});
}
bootend() {
2020-08-07 22:28:30 +08:00
if (window.progressJs) {
progressJs.end();
2015-11-19 01:32:29 +08:00
}
}
bootstart() {
super.bootstart();
AppStore.populate();
CapaStore.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();