snappymail/dev/Settings/Admin/About.js

98 lines
2.5 KiB
JavaScript
Raw Normal View History

2016-07-16 05:29:42 +08:00
import ko from 'ko';
2021-03-10 18:44:48 +08:00
import { Settings } from 'Common/Globals';
2022-04-12 23:08:26 +08:00
import { addObservablesTo } from 'External/ko';
import Remote from 'Remote/Admin/Fetch';
2016-06-30 08:02:45 +08:00
2022-10-10 19:52:56 +08:00
import { i18n, translateTrigger } from 'Common/Translator';
2022-04-12 23:08:26 +08:00
export class AdminSettingsAbout /*extends AbstractViewSettings*/ {
2016-07-16 05:29:42 +08:00
constructor() {
this.version = Settings.app('version');
this.phpextensions = ko.observableArray();
2022-04-12 23:08:26 +08:00
addObservablesTo(this, {
coreReal: true,
coreUpdatable: true,
coreWarning: false,
coreVersion: '',
coreVersionCompare: -2,
load1: 0,
load5: 0,
load15: 0,
2022-04-12 23:08:26 +08:00
errorDesc: ''
});
this.coreChecking = ko.observable(false).extend({ throttle: 100 });
this.coreUpdating = ko.observable(false).extend({ throttle: 100 });
this.coreVersionHtmlDesc = ko.computed(() => {
2022-10-10 19:52:56 +08:00
translateTrigger();
2022-04-12 23:08:26 +08:00
return i18n('TAB_ABOUT/HTML_NEW_VERSION', { 'VERSION': this.coreVersion() });
});
this.statusType = ko.computed(() => {
let type = '';
const versionToCompare = this.coreVersionCompare(),
isChecking = this.coreChecking(),
isUpdating = this.coreUpdating(),
isReal = this.coreReal();
if (isChecking) {
type = 'checking';
} else if (isUpdating) {
type = 'updating';
} else if (!isReal) {
type = 'error';
this.errorDesc('Cannot access the repository at the moment.');
} else if (0 === versionToCompare) {
type = 'up-to-date';
} else if (-1 === versionToCompare) {
type = 'available';
}
return type;
});
2016-06-30 08:02:45 +08:00
}
onBuild() {
2022-04-12 23:08:26 +08:00
// beforeShow() {
this.coreChecking(true);
Remote.request('AdminInfo', (iError, data) => {
2022-04-12 23:08:26 +08:00
this.coreChecking(false);
data = data?.Result;
if (!iError && data) {
this.load1(data.system.load?.[0]);
this.load5(data.system.load?.[1]);
this.load15(data.system.load?.[2]);
this.phpextensions(data.php);
2022-04-12 23:08:26 +08:00
this.coreReal(true);
this.coreUpdatable(!!data.core.updatable);
this.coreWarning(!!data.core.warning);
this.coreVersion(data.core.version || '');
this.coreVersionCompare(data.core.versionCompare);
2022-04-12 23:08:26 +08:00
} else {
this.coreReal(false);
this.coreWarning(false);
this.coreVersion('');
this.coreVersionCompare(-2);
}
});
}
2022-04-12 23:08:26 +08:00
updateCoreData() {
if (!this.coreUpdating()) {
this.coreUpdating(true);
Remote.request('AdminUpgradeCore', (iError, data) => {
this.coreUpdating(false);
this.coreVersion('');
this.coreVersionCompare(-2);
if (!iError && data?.Result) {
2022-04-12 23:08:26 +08:00
this.coreReal(true);
window.location.reload();
} else {
this.coreReal(false);
}
}, {}, 90000);
}
}
2016-07-16 05:29:42 +08:00
}