2015-11-19 01:32:29 +08:00
|
|
|
|
2016-07-02 06:49:59 +08:00
|
|
|
import window from 'window';
|
|
|
|
import _ from '_';
|
2015-11-19 01:32:29 +08:00
|
|
|
import ko from 'ko';
|
|
|
|
import progressJs from 'progressJs';
|
|
|
|
|
2016-08-22 05:30:34 +08:00
|
|
|
import {root} from 'Common/Links';
|
2016-06-17 07:23:49 +08:00
|
|
|
import {getNotification} from 'Common/Translator';
|
2016-06-07 05:57:52 +08:00
|
|
|
import {StorageResultType, Notification} from 'Common/Enums';
|
|
|
|
import {pInt, isNormal, isArray, inArray, isUnd} from 'Common/Utils';
|
2015-11-19 01:32:29 +08:00
|
|
|
|
2016-06-16 07:36:44 +08:00
|
|
|
import * as Settings from 'Storage/Settings';
|
2015-11-19 01:32:29 +08:00
|
|
|
|
|
|
|
import AppStore from 'Stores/Admin/App';
|
2016-09-13 04:50:21 +08:00
|
|
|
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 LicenseStore from 'Stores/Admin/License';
|
|
|
|
import PackageStore from 'Stores/Admin/Package';
|
|
|
|
import CoreStore from 'Stores/Admin/Core';
|
|
|
|
import Remote from 'Remote/Admin/Ajax';
|
|
|
|
|
2016-07-07 07:11:13 +08:00
|
|
|
import {SettingsAdminScreen} from 'Screen/Admin/Settings';
|
|
|
|
import {LoginAdminScreen} from 'Screen/Admin/Login';
|
|
|
|
|
2016-07-08 07:22:58 +08:00
|
|
|
import {hideLoading, routeOff, setHash, startScreens} from 'Knoin/Knoin';
|
2015-11-19 01:32:29 +08:00
|
|
|
import {AbstractApp} from 'App/Abstract';
|
|
|
|
|
|
|
|
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);
|
2016-06-07 05:57:52 +08:00
|
|
|
if (StorageResultType.Success === result && data && data.Result)
|
2015-11-19 01:32:29 +08:00
|
|
|
{
|
2016-07-02 06:49:59 +08:00
|
|
|
DomainStore.domains(_.map(data.Result, ([enabled, alias], name) => ({
|
|
|
|
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);
|
2016-06-07 05:57:52 +08:00
|
|
|
if (StorageResultType.Success === result && data && data.Result)
|
2015-11-19 01:32:29 +08:00
|
|
|
{
|
2016-07-02 06:49:59 +08:00
|
|
|
PluginStore.plugins(_.map(data.Result, (item) => ({
|
|
|
|
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);
|
2016-06-07 05:57:52 +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
|
|
|
|
|
|
|
_.each(PackageStore.packages(), (item) => {
|
2016-04-21 01:12:51 +08:00
|
|
|
if (item && item.loading())
|
2015-11-19 01:32:29 +08:00
|
|
|
{
|
2016-04-21 01:12:51 +08:00
|
|
|
loading[item.file] = item;
|
2015-11-19 01:32:29 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-06-07 05:57:52 +08:00
|
|
|
if (isArray(data.Result.List))
|
2015-11-19 01:32:29 +08:00
|
|
|
{
|
|
|
|
list = _.compact(_.map(data.Result.List, (item) => {
|
|
|
|
if (item)
|
|
|
|
{
|
2016-06-07 05:57:52 +08:00
|
|
|
item.loading = ko.observable(!isUnd(loading[item.file]));
|
2016-04-21 01:12:51 +08:00
|
|
|
return 'core' === item.type && !item.canBeInstalled ? null : item;
|
2015-11-19 01:32:29 +08:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
PackageStore.packages(list);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PackageStore.packagesReal(false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
updateCoreData() {
|
|
|
|
CoreStore.coreUpdating(true);
|
|
|
|
Remote.updateCoreData((result, data) => {
|
|
|
|
CoreStore.coreUpdating(false);
|
|
|
|
CoreStore.coreVersion('');
|
|
|
|
CoreStore.coreRemoteVersion('');
|
|
|
|
CoreStore.coreRemoteRelease('');
|
|
|
|
CoreStore.coreVersionCompare(-2);
|
2016-06-07 05:57:52 +08:00
|
|
|
if (StorageResultType.Success === result && data && data.Result)
|
2015-11-19 01:32:29 +08:00
|
|
|
{
|
|
|
|
CoreStore.coreReal(true);
|
|
|
|
window.location.reload();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CoreStore.coreReal(false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
reloadCoreData() {
|
|
|
|
CoreStore.coreChecking(true);
|
|
|
|
CoreStore.coreReal(true);
|
|
|
|
Remote.coreData((result, data) => {
|
|
|
|
CoreStore.coreChecking(false);
|
2016-06-07 05:57:52 +08:00
|
|
|
if (StorageResultType.Success === result && data && data.Result)
|
2015-11-19 01:32:29 +08:00
|
|
|
{
|
|
|
|
CoreStore.coreReal(!!data.Result.Real);
|
|
|
|
CoreStore.coreChannel(data.Result.Channel || 'stable');
|
|
|
|
CoreStore.coreType(data.Result.Type || 'stable');
|
|
|
|
CoreStore.coreUpdatable(!!data.Result.Updatable);
|
|
|
|
CoreStore.coreAccess(!!data.Result.Access);
|
|
|
|
CoreStore.coreWarning(!!data.Result.Warning);
|
|
|
|
CoreStore.coreVersion(data.Result.Version || '');
|
|
|
|
CoreStore.coreRemoteVersion(data.Result.RemoteVersion || '');
|
|
|
|
CoreStore.coreRemoteRelease(data.Result.RemoteRelease || '');
|
2016-06-07 05:57:52 +08:00
|
|
|
CoreStore.coreVersionCompare(pInt(data.Result.VersionCompare));
|
2015-11-19 01:32:29 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CoreStore.coreReal(false);
|
|
|
|
CoreStore.coreChannel('stable');
|
|
|
|
CoreStore.coreType('stable');
|
|
|
|
CoreStore.coreWarning(false);
|
|
|
|
CoreStore.coreVersion('');
|
|
|
|
CoreStore.coreRemoteVersion('');
|
|
|
|
CoreStore.coreRemoteRelease('');
|
|
|
|
CoreStore.coreVersionCompare(-2);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {boolean=} force = false
|
|
|
|
*/
|
|
|
|
reloadLicensing(force = false) {
|
|
|
|
LicenseStore.licensingProcess(true);
|
|
|
|
LicenseStore.licenseError('');
|
|
|
|
Remote.licensing((result, data) => {
|
|
|
|
LicenseStore.licensingProcess(false);
|
2016-06-07 05:57:52 +08:00
|
|
|
if (StorageResultType.Success === result && data && data.Result && isNormal(data.Result.Expired))
|
2015-11-19 01:32:29 +08:00
|
|
|
{
|
|
|
|
LicenseStore.licenseValid(true);
|
2016-06-07 05:57:52 +08:00
|
|
|
LicenseStore.licenseExpired(pInt(data.Result.Expired));
|
2015-11-19 01:32:29 +08:00
|
|
|
LicenseStore.licenseError('');
|
|
|
|
LicenseStore.licensing(true);
|
|
|
|
AppStore.prem(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-06-07 05:57:52 +08:00
|
|
|
if (data && data.ErrorCode && -1 < inArray(pInt(data.ErrorCode), [
|
|
|
|
Notification.LicensingServerIsUnavailable,
|
|
|
|
Notification.LicensingExpired
|
2015-11-19 01:32:29 +08:00
|
|
|
]))
|
|
|
|
{
|
2016-06-17 07:23:49 +08:00
|
|
|
LicenseStore.licenseError(getNotification(pInt(data.ErrorCode)));
|
2015-11-19 01:32:29 +08:00
|
|
|
LicenseStore.licensing(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-06-07 05:57:52 +08:00
|
|
|
if (StorageResultType.Abort === result)
|
2015-11-19 01:32:29 +08:00
|
|
|
{
|
2016-06-17 07:23:49 +08:00
|
|
|
LicenseStore.licenseError(getNotification(Notification.LicensingServerIsUnavailable));
|
2015-11-19 01:32:29 +08:00
|
|
|
LicenseStore.licensing(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LicenseStore.licensing(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, force);
|
|
|
|
}
|
|
|
|
|
2016-07-02 06:49:59 +08:00
|
|
|
bootend(bootendCallback = null) {
|
2015-11-19 01:32:29 +08:00
|
|
|
if (progressJs)
|
|
|
|
{
|
|
|
|
progressJs.end();
|
|
|
|
}
|
|
|
|
|
2016-07-02 06:49:59 +08:00
|
|
|
if (bootendCallback)
|
2015-11-19 01:32:29 +08:00
|
|
|
{
|
2016-07-02 06:49:59 +08:00
|
|
|
bootendCallback();
|
2015-11-19 01:32:29 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bootstart() {
|
|
|
|
|
|
|
|
super.bootstart();
|
|
|
|
|
2016-09-13 04:50:21 +08:00
|
|
|
AppStore.populate();
|
|
|
|
CapaStore.populate();
|
2015-11-19 01:32:29 +08:00
|
|
|
|
2016-07-08 07:22:58 +08:00
|
|
|
hideLoading();
|
2015-11-19 01:32:29 +08:00
|
|
|
|
2016-04-30 07:42:18 +08:00
|
|
|
if (!Settings.appSettingsGet('allowAdminPanel'))
|
2015-11-19 01:32:29 +08:00
|
|
|
{
|
2016-07-08 07:22:58 +08:00
|
|
|
routeOff();
|
2016-08-22 05:30:34 +08:00
|
|
|
setHash(root(), true);
|
2016-07-08 07:22:58 +08:00
|
|
|
routeOff();
|
2015-11-19 01:32:29 +08:00
|
|
|
|
|
|
|
_.defer(() => {
|
|
|
|
window.location.href = '/';
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-04-21 01:12:51 +08:00
|
|
|
if (Settings.settingsGet('Auth'))
|
2015-11-19 01:32:29 +08:00
|
|
|
{
|
2016-07-08 07:22:58 +08:00
|
|
|
startScreens([
|
2016-07-07 07:11:13 +08:00
|
|
|
SettingsAdminScreen
|
2015-11-19 01:32:29 +08:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-07-08 07:22:58 +08:00
|
|
|
startScreens([
|
2016-07-07 07:11:13 +08:00
|
|
|
LoginAdminScreen
|
2015-11-19 01:32:29 +08:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.bootend();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-17 07:23:49 +08:00
|
|
|
export default new AdminApp();
|