diff --git a/package-lock.json b/package-lock.json index 9ac6da4..cc42802 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,6 +7,7 @@ "": { "name": "eachwatt", "version": "1.0.0", + "hasInstallScript": true, "license": "GPL-3.0-or-later", "dependencies": { "@influxdata/influxdb-client": "^1.33.2", diff --git a/package.json b/package.json index b63ea7c..e6c0466 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,9 @@ "author": "Sam Stenvall ", "license": "GPL-3.0-or-later", "scripts": { + "postinstall": "cd webif/ && npm install", "build": "rm -rf dist/* && npx tsc", + "build-all": "npm run build && cd webif/ && npm run build", "prettier": "prettier --write src/ tests/", "prettier-check": "prettier --check src/ tests/", "lint": "eslint 'src/**/*.ts'", diff --git a/systemd/eachwatt.service b/systemd/eachwatt.service index 3e622cd..d2e1917 100644 --- a/systemd/eachwatt.service +++ b/systemd/eachwatt.service @@ -5,7 +5,8 @@ After=network.target [Service] WorkingDirectory=/opt/eachwatt -ExecStartPre=/usr/bin/npm run build +ExecStartPre=/usr/bin/npm install +ExecStartPre=/usr/bin/npm run build-all ExecStart=/usr/bin/node /opt/eachwatt/dist/eachwatt.js -c /etc/eachwatt/config.yml Restart=always RestartSec=5 diff --git a/webif/src/lib/stores.ts b/webif/src/lib/stores.ts new file mode 100644 index 0000000..8b879b1 --- /dev/null +++ b/webif/src/lib/stores.ts @@ -0,0 +1,8 @@ +import { writable } from 'svelte/store' + +export const configurationStore = writable({}) +export const characteristicsStore = writable([]) +export const mainSensorDataStore = writable([]) +export const circuitSensorDataStore = writable([]) +export const lastUpdateTimestampStore = writable(undefined) +export const webSocketUrlStore = writable(undefined) diff --git a/webif/src/routes/+layout.svelte b/webif/src/routes/+layout.svelte index a5204ae..09aef61 100644 --- a/webif/src/routes/+layout.svelte +++ b/webif/src/routes/+layout.svelte @@ -1,11 +1,80 @@ EachWatt
+
+ +
+
@@ -13,7 +82,7 @@ :root { --background: #fff; --color: #222; - --table-background: #e0e0e0; + --component-background: #e0e0e0; --highlight-color: #ff3d00; } @@ -21,16 +90,20 @@ :root { --background: #272727; --color: #aaa; - --table-background: #3b3b3b; + --component-background: #3b3b3b; --highlight-color: #ff3d00; } + nav { + background-color: var(--component-background); + } + /* pure-table overrides */ :global(.pure-table) { border: 2px solid #424242; } :global(.pure-table thead) { - background-color: var(--table-background); + background-color: var(--component-background); color: var(--color); } @@ -77,4 +150,15 @@ :global(.l-box) { padding: 1em; } + + /* pure-menu tweaks */ + :global(.pure-menu-link) { + border-bottom: 2px solid var(--component-background); + } + + :global(.pure-menu-link:hover) { + border-bottom: 2px solid var(--highlight-color); + background: inherit !important; + } + /* end pure-menu tweaks */ diff --git a/webif/src/routes/+page.svelte b/webif/src/routes/+page.svelte index 21ee6ca..3fec436 100644 --- a/webif/src/routes/+page.svelte +++ b/webif/src/routes/+page.svelte @@ -1,63 +1,14 @@ -{#if lastUpdateTimestamp === undefined} +{#if $lastUpdateTimestampStore === undefined}
-

Connecting to {webSocketUrl}

+

Connecting to {$webSocketUrlStore}

{:else}
- +
- +
- +
- +
{/if} diff --git a/webif/src/routes/Characteristics.svelte b/webif/src/routes/Characteristics.svelte index 7fbf4bd..aad2fec 100644 --- a/webif/src/routes/Characteristics.svelte +++ b/webif/src/routes/Characteristics.svelte @@ -1,5 +1,5 @@

Characteristics

@@ -13,7 +13,7 @@ - {#each sensorData as data} + {#each $characteristicsStore as data} {data.characteristics.name} {data.characteristics.phase} diff --git a/webif/src/routes/Circuits.svelte b/webif/src/routes/Circuits.svelte index 2d58865..7307bd5 100644 --- a/webif/src/routes/Circuits.svelte +++ b/webif/src/routes/Circuits.svelte @@ -1,7 +1,6 @@

All circuits

@@ -19,7 +18,7 @@ - {#each sensorData as data} + {#each $circuitSensorDataStore as data} {data.circuit.name} {data.circuit.group ?? ''} diff --git a/webif/src/routes/Configuration.svelte b/webif/src/routes/Configuration.svelte deleted file mode 100644 index 7de627f..0000000 --- a/webif/src/routes/Configuration.svelte +++ /dev/null @@ -1,15 +0,0 @@ - - -

Configuration

-
{configuration}
- - diff --git a/webif/src/routes/LastUpdate.svelte b/webif/src/routes/LastUpdate.svelte index 65cbdcd..6077538 100644 --- a/webif/src/routes/LastUpdate.svelte +++ b/webif/src/routes/LastUpdate.svelte @@ -1,5 +1,5 @@

- Last update: {lastUpdateTimestamp?.toISOString()}, connected to {webSocketUrl} + Last update: {$lastUpdateTimestampStore?.toISOString()}, connected to {$webSocketUrlStore}

diff --git a/webif/src/routes/MainsPower.svelte b/webif/src/routes/MainsPower.svelte index 7fae0c6..c716336 100644 --- a/webif/src/routes/MainsPower.svelte +++ b/webif/src/routes/MainsPower.svelte @@ -1,9 +1,9 @@
- {#each sensorData as data} + {#each $mainSensorDataStore as data}

{data.circuit.name}

{data.power}W @@ -22,7 +22,7 @@ .mains-power-cards { padding: 0.8em; box-sizing: border-box; - background-color: var(--table-background); + background-color: var(--component-background); margin-bottom: 1em; } diff --git a/webif/src/routes/configuration/+page.svelte b/webif/src/routes/configuration/+page.svelte new file mode 100644 index 0000000..8fa3fcf --- /dev/null +++ b/webif/src/routes/configuration/+page.svelte @@ -0,0 +1,18 @@ + + +
+

Configuration

+
{$configurationStore}
+
+ + +