snappymail/dev/Stores/Admin/Package.js
2021-03-18 14:48:21 +01:00

42 lines
1,005 B
JavaScript

import ko from 'ko';
import { isArray } from 'Common/Utils';
import Remote from 'Remote/Admin/Fetch';
export const PackageAdminStore = ko.observableArray();
PackageAdminStore.real = ko.observable(true);
PackageAdminStore.loading = ko.observable(false);
PackageAdminStore.fetch = () => {
PackageAdminStore.loading(true);
Remote.packagesList((iError, data) => {
PackageAdminStore.loading(false);
if (!iError) {
PackageAdminStore.real(!!data.Result.Real);
let list = [];
const loading = {};
PackageAdminStore.forEach(item => {
if (item && item.loading()) {
loading[item.file] = item;
}
});
if (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(v => v);
}
PackageAdminStore(list);
} else {
PackageAdminStore.real(false);
}
});
};