Keep iface filter populated
This commit is contained in:
parent
9218624862
commit
5a8856350d
3 changed files with 38 additions and 14 deletions
File diff suppressed because one or more lines are too long
|
|
@ -1,4 +1,4 @@
|
|||
export const apiPath = 'http://0.0.0.0:8840';
|
||||
export const apiPath = '';
|
||||
|
||||
export const apiGetAllHosts = async () => {
|
||||
const url = apiPath+'/api/all';
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { apiGetAllHosts } from "./api";
|
||||
import { allHosts, setAllHosts, setBkpHosts, setIfaces } from "./exports";
|
||||
import { apiGetAllHosts, apiGetConfig } from "./api";
|
||||
import { appConfig, type Conf, type Host, ifaces as savedIfaces, setAllHosts, setAppConfig, setBkpHosts, setIfaces } from "./exports";
|
||||
import { filterAtStart, filterFunc } from "./filter";
|
||||
import { sortAtStart } from "./sort";
|
||||
|
||||
|
|
@ -13,27 +13,51 @@ export function runAtStart() {
|
|||
}
|
||||
|
||||
export async function getHosts() {
|
||||
const hosts = await apiGetAllHosts();
|
||||
const [hosts, config] = await Promise.all([
|
||||
apiGetAllHosts(),
|
||||
apiGetConfig().catch(() => null),
|
||||
]);
|
||||
|
||||
if (config !== null) {
|
||||
setAppConfig(config);
|
||||
}
|
||||
|
||||
if (hosts !== null) {
|
||||
setAllHosts(hosts);
|
||||
setBkpHosts(hosts);
|
||||
|
||||
listIfaces();
|
||||
listIfaces(hosts, config);
|
||||
sortAtStart();
|
||||
filterAtStart();
|
||||
}
|
||||
}
|
||||
|
||||
function listIfaces() {
|
||||
|
||||
let ifaces:string[] = [];
|
||||
|
||||
for (let host of allHosts) {
|
||||
if (!ifaces.includes(host.Iface)) {
|
||||
ifaces.push(host.Iface);
|
||||
function listIfaces(hosts: Host[], config: Conf | null) {
|
||||
const ifaceOptions: string[] = [];
|
||||
const addIface = (iface: string) => {
|
||||
const trimmed = iface.trim();
|
||||
if (trimmed !== "" && !ifaceOptions.includes(trimmed)) {
|
||||
ifaceOptions.push(trimmed);
|
||||
}
|
||||
};
|
||||
|
||||
for (let host of hosts) {
|
||||
addIface(host.Iface);
|
||||
}
|
||||
|
||||
setIfaces(ifaces);
|
||||
const configuredIfaces = config?.Ifaces || appConfig().Ifaces;
|
||||
for (let iface of configuredIfaces.split(/\s+/)) {
|
||||
addIface(iface);
|
||||
}
|
||||
|
||||
if (ifaceOptions.length > 0) {
|
||||
setIfaces(ifaceOptions);
|
||||
return;
|
||||
}
|
||||
|
||||
if (savedIfaces().length > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
setIfaces([]);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue