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 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 { servicesFromConfig, servicesFromDocker, cleanServiceGroups } from "utils/config/service-helpers";
import { cleanWidgetGroups, widgetsFromConfig } from "utils/config/widget-helpers"; import { cleanWidgetGroups, widgetsFromConfig } from "utils/config/widget-helpers";
@ -46,6 +46,7 @@ export async function widgetsResponse() {
export async function servicesResponse() { export async function servicesResponse() {
let discoveredServices; let discoveredServices;
let configuredServices; let configuredServices;
let initialSettings;
try { try {
discoveredServices = cleanServiceGroups(await servicesFromDocker()); discoveredServices = cleanServiceGroups(await servicesFromDocker());
@ -63,11 +64,20 @@ export async function servicesResponse() {
configuredServices = []; 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 = [ const mergedGroupsNames = [
...new Set([discoveredServices.map((group) => group.name), configuredServices.map((group) => group.name)].flat()), ...new Set([discoveredServices.map((group) => group.name), configuredServices.map((group) => group.name)].flat()),
]; ];
const mergedGroups = []; const mergedGroups = [];
const definedLayouts = initialSettings.layout ? Object.keys(initialSettings.layout) : null;
mergedGroupsNames.forEach((groupName) => { mergedGroupsNames.forEach((groupName) => {
const discoveredGroup = discoveredServices.find((group) => group.name === groupName) || { services: [] }; 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), services: [...discoveredGroup.services, ...configuredGroup.services].filter((service) => service),
}; };
mergedGroups.push(mergedGroup); 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; return mergedGroups;

Loading…
Cancel
Save