Merge pull request #358 from GodD6366/feat/support-sort-layout

Feature: support sort layout
pull/484/head
shamoon 2 years ago committed by GitHub
commit 0ad026503a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -4,7 +4,7 @@ import path from "path";
import yaml from "js-yaml";
import checkAndCopyConfig from "utils/config/config";
import checkAndCopyConfig, { getSettings } from "utils/config/config";
import { servicesFromConfig, servicesFromDocker, cleanServiceGroups } from "utils/config/service-helpers";
import { cleanWidgetGroups, widgetsFromConfig } from "utils/config/widget-helpers";
@ -46,6 +46,7 @@ export async function widgetsResponse() {
export async function servicesResponse() {
let discoveredServices;
let configuredServices;
let initialSettings;
try {
discoveredServices = cleanServiceGroups(await servicesFromDocker());
@ -63,11 +64,20 @@ export async function servicesResponse() {
configuredServices = [];
}
try {
initialSettings = await getSettings();
} catch (e) {
console.error("Failed to load settings.yaml, please check for errors");
if (e) console.error(e);
initialSettings = {};
}
const mergedGroupsNames = [
...new Set([discoveredServices.map((group) => group.name), configuredServices.map((group) => group.name)].flat()),
];
const mergedGroups = [];
const definedLayouts = initialSettings.layout ? Object.keys(initialSettings.layout) : null;
mergedGroupsNames.forEach((groupName) => {
const discoveredGroup = discoveredServices.find((group) => group.name === groupName) || { services: [] };
@ -78,7 +88,13 @@ export async function servicesResponse() {
services: [...discoveredGroup.services, ...configuredGroup.services].filter((service) => service),
};
if (definedLayouts) {
const layoutIndex = definedLayouts.findIndex(layout => layout === mergedGroup.name);
if (layoutIndex > -1) mergedGroups.splice(layoutIndex, 0, mergedGroup);
else mergedGroups.push(mergedGroup);
} else {
mergedGroups.push(mergedGroup);
}
});
return mergedGroups;

Loading…
Cancel
Save