Skip to content

Commit

Permalink
chore: simplefied config origin
Browse files Browse the repository at this point in the history
  • Loading branch information
MSchmoecker committed Apr 4, 2024
1 parent 6cd7471 commit 117c6bc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 29 deletions.
18 changes: 5 additions & 13 deletions frontend/src/routes/config-overview/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,22 @@
$: modules = getModules(tag, device);
$: modulesAnywhere = getModulesInstalledAnywhere();
const getOrigin = (tag: Tag | undefined, device: Device | undefined) => {
if (tag) {
return tag.displayName;
}
if (device) {
return device.displayName;
}
const getOrigin = (target: Tag | Device) => {
return target.displayName;
};
const getModuleSettings = (tag: Tag | undefined, device: Device | undefined) => {
if (tag) {
return tag.modules.map((m) => ({ origin: getOrigin(tag, undefined), ...m }));
return tag.modules.map((m) => ({ origin: getOrigin(tag), ...m }));
}
if (device) {
let usedTags = device.tags.flatMap(
(t) => data.state.tags.find((tag) => tag.displayName === t) ?? []
);
return [
...device.modules.map((m) => ({ origin: getOrigin(undefined, device), ...m })),
...usedTags.flatMap((t) =>
t.modules.map((m) => ({ origin: getOrigin(t, undefined), ...m }))
)
...device.modules.map((m) => ({ origin: getOrigin(device), ...m })),
...usedTags.flatMap((t) => t.modules.map((m) => ({ origin: getOrigin(t), ...m })))
];
}
};
Expand Down
22 changes: 6 additions & 16 deletions frontend/src/routes/config/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,27 @@
const deviceParam = queryParam('device');
const moduleParam = queryParam('module');
let modules: Module[];
$: tag = data.state.tags.find((t) => t.identifier === $tagParam);
$: device = data.state.devices.find((d) => d.identifier === $deviceParam);
$: modules = getModules(tag, device);
$: selectedModule = data.availableModules.find((m) => m.type === $moduleParam);
const getOrigin = (tag: Tag | undefined, device: Device | undefined) => {
if (tag) {
return tag.displayName;
}
if (device) {
return device.displayName;
}
const getOrigin = (target: Tag | Device | undefined) => {
return target?.displayName;
};
const getModuleSettings = (tag: Tag | undefined, device: Device | undefined) => {
if (tag) {
return tag.modules.map((m) => ({ origin: getOrigin(tag, undefined), ...m }));
return tag.modules.map((m) => ({ origin: getOrigin(tag), ...m }));
}
if (device) {
let usedTags = device.tags.flatMap(
(t) => data.state.tags.find((tag) => tag.displayName === t) ?? []
);
return [
...device.modules.map((m) => ({ origin: getOrigin(undefined, device), ...m })),
...usedTags.flatMap((t) =>
t.modules.map((m) => ({ origin: getOrigin(t, undefined), ...m }))
)
...device.modules.map((m) => ({ origin: getOrigin(device), ...m })),
...usedTags.flatMap((t) => t.modules.map((m) => ({ origin: getOrigin(t), ...m })))
];
}
};
Expand Down Expand Up @@ -251,7 +241,7 @@
<p>{effectingSetting.origin}: {effectingSetting.settings[settingKey].value}</p>
{/each}
</Tooltip>
{#if effectingSettings.reverse()[0].origin == getOrigin(tag, device)}
{#if effectingSettings.reverse()[0].origin == getOrigin(tag ?? device)}
<button
class="btn p-0"
on:click={() => {
Expand Down

0 comments on commit 117c6bc

Please sign in to comment.