2016-08-17 06:01:20 +08:00
|
|
|
import ko from 'ko';
|
2021-03-16 23:49:14 +08:00
|
|
|
import { isArray } from 'Common/Utils';
|
2021-03-15 05:36:23 +08:00
|
|
|
import Remote from 'Remote/Admin/Fetch';
|
2015-01-27 05:06:00 +08:00
|
|
|
|
2021-02-17 21:40:21 +08:00
|
|
|
export const PackageAdminStore = ko.observableArray();
|
2015-01-27 05:06:00 +08:00
|
|
|
|
2021-02-17 21:40:21 +08:00
|
|
|
PackageAdminStore.real = ko.observable(true);
|
2015-01-27 05:06:00 +08:00
|
|
|
|
2021-03-15 05:36:23 +08:00
|
|
|
PackageAdminStore.loading = ko.observable(false);
|
|
|
|
|
2021-08-30 20:01:42 +08:00
|
|
|
PackageAdminStore.error = ko.observable('');
|
2021-07-16 19:57:04 +08:00
|
|
|
|
2021-03-15 05:36:23 +08:00
|
|
|
PackageAdminStore.fetch = () => {
|
|
|
|
PackageAdminStore.loading(true);
|
2021-12-03 07:11:19 +08:00
|
|
|
Remote.request('AdminPackagesList', (iError, data) => {
|
2021-03-15 05:36:23 +08:00
|
|
|
PackageAdminStore.loading(false);
|
2021-07-16 19:57:04 +08:00
|
|
|
if (iError) {
|
|
|
|
PackageAdminStore.real(false);
|
|
|
|
} else {
|
2021-03-15 05:36:23 +08:00
|
|
|
PackageAdminStore.real(!!data.Result.Real);
|
2021-08-30 20:01:42 +08:00
|
|
|
PackageAdminStore.error(data.Result.Error);
|
2021-03-15 05:36:23 +08:00
|
|
|
|
|
|
|
const loading = {};
|
|
|
|
PackageAdminStore.forEach(item => {
|
2022-09-02 17:52:07 +08:00
|
|
|
if (item?.loading()) {
|
2021-03-15 05:36:23 +08:00
|
|
|
loading[item.file] = item;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-07-16 19:57:04 +08:00
|
|
|
let list = [];
|
2021-03-16 23:49:14 +08:00
|
|
|
if (isArray(data.Result.List)) {
|
2021-07-16 19:57:04 +08:00
|
|
|
list = data.Result.List.filter(v => v).map(item => {
|
|
|
|
item.loading = ko.observable(loading[item.file] !== undefined);
|
|
|
|
item.enabled = ko.observable(item.enabled);
|
|
|
|
return item;
|
|
|
|
});
|
2021-03-15 05:36:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
PackageAdminStore(list);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|