2021-01-26 18:46:30 +08:00
|
|
|
import 'External/Admin/ko';
|
|
|
|
import ko from 'ko';
|
2015-11-19 01:32:29 +08:00
|
|
|
|
2020-08-19 02:45:43 +08:00
|
|
|
import { StorageResultType } from 'Common/Enums';
|
2015-11-19 01:32:29 +08:00
|
|
|
|
2021-02-17 21:40:21 +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';
|
2020-09-15 01:40:56 +08:00
|
|
|
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() {
|
2021-02-17 21:40:21 +08:00
|
|
|
DomainAdminStore.loading(true);
|
2015-11-19 01:32:29 +08:00
|
|
|
Remote.domainList((result, data) => {
|
2021-02-17 21:40:21 +08:00
|
|
|
DomainAdminStore.loading(false);
|
2019-07-05 03:19:24 +08:00
|
|
|
if (StorageResultType.Success === result && data && data.Result) {
|
2021-02-17 21:40:21 +08:00
|
|
|
DomainAdminStore(
|
2020-07-30 18:02:43 +08:00
|
|
|
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() {
|
2021-02-17 21:40:21 +08:00
|
|
|
PluginAdminStore.loading(true);
|
2015-11-19 01:32:29 +08:00
|
|
|
Remote.pluginList((result, data) => {
|
2021-02-17 21:40:21 +08:00
|
|
|
PluginAdminStore.loading(false);
|
2019-07-05 03:19:24 +08:00
|
|
|
if (StorageResultType.Success === result && data && data.Result) {
|
2021-02-17 21:40:21 +08:00
|
|
|
PluginAdminStore(
|
2020-07-23 02:09:31 +08:00
|
|
|
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() {
|
2021-02-17 21:40:21 +08:00
|
|
|
PackageAdminStore.loading(true);
|
2015-11-19 01:32:29 +08:00
|
|
|
Remote.packagesList((result, data) => {
|
2021-02-17 21:40:21 +08:00
|
|
|
PackageAdminStore.loading(false);
|
2019-07-05 03:19:24 +08:00
|
|
|
if (StorageResultType.Success === result && data && data.Result) {
|
2021-02-17 21:40:21 +08:00
|
|
|
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
|
|
|
|
2021-02-17 21:40:21 +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
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-07-30 03:49:41 +08:00
|
|
|
if (Array.isArray(data.Result.List)) {
|
2020-07-23 22:06:16 +08:00
|
|
|
list = data.Result.List.map(item => {
|
|
|
|
if (item) {
|
2020-07-30 03:49:41 +08:00
|
|
|
item.loading = ko.observable(loading[item.file] !== undefined);
|
2020-07-23 22:06:16 +08:00
|
|
|
return 'core' === item.type && !item.canBeInstalled ? null : item;
|
|
|
|
}
|
|
|
|
return null;
|
2020-10-03 05:54:15 +08:00
|
|
|
}).filter(v => v);
|
2015-11-19 01:32:29 +08:00
|
|
|
}
|
|
|
|
|
2021-02-17 21:40:21 +08:00
|
|
|
PackageAdminStore(list);
|
2019-07-05 03:19:24 +08:00
|
|
|
} else {
|
2021-02-17 21:40:21 +08:00
|
|
|
PackageAdminStore.real(false);
|
2015-11-19 01:32:29 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-09-06 17:13:43 +08:00
|
|
|
bootend() {
|
2021-01-26 18:46:30 +08:00
|
|
|
progressJs.end();
|
2015-11-19 01:32:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bootstart() {
|
|
|
|
super.bootstart();
|
|
|
|
|
2021-02-17 21:40:21 +08:00
|
|
|
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
|
|
|
|
2020-09-04 18:05:17 +08:00
|
|
|
if (!rl.settings.app('allowAdminPanel')) {
|
2020-09-17 02:35:29 +08:00
|
|
|
rl.route.root();
|
|
|
|
setTimeout(() => location.href = '/', 1);
|
2019-07-05 03:19:24 +08:00
|
|
|
} else {
|
2020-09-04 18:05:17 +08:00
|
|
|
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();
|