Compare commits

...

18 Commits

Author SHA1 Message Date
1c66c841ab Updated drink state to 'completed' 2023-08-27 15:38:46 +02:00
6f80aee823 Handle state being undefined without crashing 2023-08-27 15:38:31 +02:00
699a67161b Merge branch 'main' of github.com:KevinMidboe/brewPi 2023-08-27 13:57:50 +02:00
20f4a173d4 Added Pilsner category to Utepils 2023-08-27 13:57:22 +02:00
c146ffccfd Some margin under logo 2023-08-27 13:56:32 +02:00
c0a46b8cca Height & width 100% to grow to parent 2023-08-27 13:56:13 +02:00
d5e46af091 Fill with white 2023-08-27 13:55:46 +02:00
2da44956be .link animated style on hover & --orange 2023-08-27 13:55:20 +02:00
b34b18ad37 Navigation arrow top left for going to /brews list page 2023-08-27 13:54:16 +02:00
0071bd3791 Every brew takes more spaces & displays details on card 2023-08-27 13:52:46 +02:00
38e42bb37c Resize grid template on ~ tablet sizes
Also set max image width for brew progress to have more predictable
height.
2023-08-27 13:50:53 +02:00
3a8587b2ad Better use of entire viewport size 2023-08-27 13:45:20 +02:00
c1953517e7 Call /api/state after relay is switched 2023-08-27 13:44:03 +02:00
f5f759ca0a DTO interfaces for API responses. 2023-08-27 13:43:04 +02:00
b9a5fde53f Make top right hamburger a button for accessibility 2023-08-27 13:39:45 +02:00
0218c048e9 Expanded brewprogress w/ brew details & image. Better CTA 2023-08-27 13:38:24 +02:00
89b17ea714 Header color and form fit better w/ rest of page colors 2023-08-27 13:30:53 +02:00
c16bce0a1a Gradient background color under graph lines & display NO DATA if none 2023-08-27 13:28:48 +02:00
21 changed files with 522 additions and 157 deletions

View File

@@ -75,7 +75,7 @@
"beer": { "beer": {
"name": "Utepils", "name": "Utepils",
"brewery": "Finest", "brewery": "Finest",
"category": "", "category": "Pilsner",
"description": "" "description": ""
}, },
"date": "1637694000", "date": "1637694000",

View File

@@ -28,13 +28,12 @@
const brew: IBrew = { const brew: IBrew = {
name: beer?.name, name: beer?.name,
by: beer?.brewery,
date: latestBrew.date, date: latestBrew.date,
dates: { dates: {
brew: dates?.brew || 'June 24', brew: dates?.brew || 'June 24',
ferment: 'July 8', ferment: 'July 12',
bottle: 'July 8', bottle: 'July 12',
consume: 'July 22' consume: 'July 26'
} }
}; };
@@ -57,22 +56,22 @@
icon: 'M19.803 5h1.572c.226 0 .443.244.603.404l1.772 1.85c.16.16.25.453.25.68v2.832c0 .015 0 .234-1 .234-.415-.854-1.116-1.287-2.124-1.287-.426 0-1.05.173-1.403.356-.14.072-.473.086-.473-.07V5.803c0-.442.36-.803.803-.803zM9.263 3h7.83c.5 0 .907.406.907.906v6.188c0 .5-.406.906-.906.906h-2.138c-.115 0-.214.206-.26.1-.397-.9-1.297-1.387-2.338-1.387-1.04 0-1.94.418-2.338 1.32-.046.104-.145-.033-.26-.033H8.672c-.37 0-.672-.3-.672-.672V4.265C8 3.57 8.57 3 9.264 3zm11.676 7.978c.828 0 1.5.67 1.5 1.5 0 .828-.672 1.5-1.5 1.5-.83 0-1.5-.672-1.5-1.5 0-.83.67-1.5 1.5-1.5zm-8.582-.07c.828 0 1.5.67 1.5 1.5 0 .828-.672 1.5-1.5 1.5s-1.5-.672-1.5-1.5c0-.83.672-1.5 1.5-1.5z', icon: 'M19.803 5h1.572c.226 0 .443.244.603.404l1.772 1.85c.16.16.25.453.25.68v2.832c0 .015 0 .234-1 .234-.415-.854-1.116-1.287-2.124-1.287-.426 0-1.05.173-1.403.356-.14.072-.473.086-.473-.07V5.803c0-.442.36-.803.803-.803zM9.263 3h7.83c.5 0 .907.406.907.906v6.188c0 .5-.406.906-.906.906h-2.138c-.115 0-.214.206-.26.1-.397-.9-1.297-1.387-2.338-1.387-1.04 0-1.94.418-2.338 1.32-.046.104-.145-.033-.26-.033H8.672c-.37 0-.672-.3-.672-.672V4.265C8 3.57 8.57 3 9.264 3zm11.676 7.978c.828 0 1.5.67 1.5 1.5 0 .828-.672 1.5-1.5 1.5-.83 0-1.5-.672-1.5-1.5 0-.83.67-1.5 1.5-1.5zm-8.582-.07c.828 0 1.5.67 1.5 1.5 0 .828-.672 1.5-1.5 1.5s-1.5-.672-1.5-1.5c0-.83.672-1.5 1.5-1.5z',
name: 'Ferment', name: 'Ferment',
date: brew.dates.ferment, date: brew.dates.ferment,
state: 'in-progress', state: 'completed',
description: `The fermented stage is where the magic happens. The cooled wort is transferred to a fermentation vessel, typically a large container called a fermenter. Yeast is added to the wort, and the fermentation process begins. Yeast consumes the fermentable sugars in the wort and converts them into alcohol and carbon dioxide through a process called fermentation. This stage can last from a few days to several weeks, depending on the beer style and desired characteristics. The temperature and conditions during fermentation play a crucial role in shaping the beer's flavors and aromas.` description: `The fermented stage is where the magic happens. The cooled wort is transferred to a fermentation vessel, typically a large container called a fermenter. Yeast is added to the wort, and the fermentation process begins. Yeast consumes the fermentable sugars in the wort and converts them into alcohol and carbon dioxide through a process called fermentation. This stage can last from a few days to several weeks, depending on the beer style and desired characteristics. The temperature and conditions during fermentation play a crucial role in shaping the beer's flavors and aromas.`
}, },
{ {
icon: 'M23.45 10.99c-.162-.307-.54-.42-.84-.257l-4.582 2.45-6.557-11.93H8.62c-.347 0-.62.283-.62.628 0 .346.273.628.62.628h2.118l4.825 8.783c-.037-.006-.074-.006-.112-.006-1.37 0-2.482 1.123-2.482 2.508s1.11 2.508 2.483 2.508c1.038 0 1.92-.64 2.293-1.543l5.445-2.92c.304-.164.422-.54.26-.847zm-8 3.874c-.59 0-1.06-.476-1.06-1.072 0-.596.47-1.072 1.06-1.072.59 0 1.063.476 1.063 1.072 0 .596-.472 1.072-1.062 1.072zm8.994-6.698l-5.848 3.288-2.718-4.93 5.847-3.287 2.72 4.93zm-4.288-5.482l-4.882 2.744-1.48-2.683L18.675 0l1.48 2.684z', icon: 'M23.45 10.99c-.162-.307-.54-.42-.84-.257l-4.582 2.45-6.557-11.93H8.62c-.347 0-.62.283-.62.628 0 .346.273.628.62.628h2.118l4.825 8.783c-.037-.006-.074-.006-.112-.006-1.37 0-2.482 1.123-2.482 2.508s1.11 2.508 2.483 2.508c1.038 0 1.92-.64 2.293-1.543l5.445-2.92c.304-.164.422-.54.26-.847zm-8 3.874c-.59 0-1.06-.476-1.06-1.072 0-.596.47-1.072 1.06-1.072.59 0 1.063.476 1.063 1.072 0 .596-.472 1.072-1.062 1.072zm8.994-6.698l-5.848 3.288-2.718-4.93 5.847-3.287 2.72 4.93zm-4.288-5.482l-4.882 2.744-1.48-2.683L18.675 0l1.48 2.684z',
name: 'Bottle', name: 'Bottle',
date: brew.dates.bottle, date: brew.dates.bottle,
state: '', state: 'completed',
description: description:
'Once fermentation is complete, the beer is ready for packaging. The beer is carefully transferred from the fermentation vessel to a bottling bucket or keg. During this transfer, care is taken to avoid disturbing the sediment, known as trub, that has settled at the bottom of the fermenter. If desired, additional priming sugar can be added at this stage to provide carbonation in the bottles. The beer is then filled into clean and sanitized bottles or kegs, ensuring that the containers are properly sealed to prevent oxygen exposure and contamination.' 'Once fermentation is complete, the beer is ready for packaging. The beer is carefully transferred from the fermentation vessel to a bottling bucket or keg. During this transfer, care is taken to avoid disturbing the sediment, known as trub, that has settled at the bottom of the fermenter. If desired, additional priming sugar can be added at this stage to provide carbonation in the bottles. The beer is then filled into clean and sanitized bottles or kegs, ensuring that the containers are properly sealed to prevent oxygen exposure and contamination.'
}, },
{ {
icon: 'M15.623 5.014l-4.29 3.577c-.196.168-.327.362-.327.62v6.206c0 .322.335.584.656.584h2.004c.32 0 .584-.262.584-.584l-.033-3.115c0-.16.13-.29.29-.29h2.918c.16 0 .292.13.292.29l.033 3.116c0 .322.263.584.584.584h2.09c.322 0 .585-.262.585-.584V9.48c0-.257-.172-.626-.37-.792l-4.263-3.674c-.218-.184-.536-.184-.754 0zm7.17 2.374l-5.967-5.046C16.606 2.122 16.312 2 16 2c-.312 0-.606.123-.79.31L9.207 7.388c-.245.208-.276.576-.068.822.115.136.28.206.446.206.133 0 .266-.044.376-.137l5.69-4.847c.208-.155.49-.157.697-.002 1.286.962 5.693 4.85 5.693 4.85.246.206.614.177.822-.07.208-.246.177-.614-.068-.822z', icon: 'M15.623 5.014l-4.29 3.577c-.196.168-.327.362-.327.62v6.206c0 .322.335.584.656.584h2.004c.32 0 .584-.262.584-.584l-.033-3.115c0-.16.13-.29.29-.29h2.918c.16 0 .292.13.292.29l.033 3.116c0 .322.263.584.584.584h2.09c.322 0 .585-.262.585-.584V9.48c0-.257-.172-.626-.37-.792l-4.263-3.674c-.218-.184-.536-.184-.754 0zm7.17 2.374l-5.967-5.046C16.606 2.122 16.312 2 16 2c-.312 0-.606.123-.79.31L9.207 7.388c-.245.208-.276.576-.068.822.115.136.28.206.446.206.133 0 .266-.044.376-.137l5.69-4.847c.208-.155.49-.157.697-.002 1.286.962 5.693 4.85 5.693 4.85.246.206.614.177.822-.07.208-.246.177-.614-.068-.822z',
name: 'Carbonate', name: 'Ready to drink',
date: brew.dates.consume, date: brew.dates.consume,
state: '', state: 'completed',
description: description:
'After the beer is bottled or kegged, it enters the carbonation stage. If priming sugar was added during the bottling stage, the remaining yeast in the beer consumes the sugar and produces carbon dioxide, naturally carbonating the beer over time. The sealed bottles or kegs are stored at a controlled temperature for a period of time to allow carbonation to occur. This process typically takes a few weeks, during which the flavors and aromas continue to develop. If kegging, carbonation can also be achieved through forced carbonation, where carbon dioxide is directly injected into the keg under pressure.' 'After the beer is bottled or kegged, it enters the carbonation stage. If priming sugar was added during the bottling stage, the remaining yeast in the beer consumes the sugar and produces carbon dioxide, naturally carbonating the beer over time. The sealed bottles or kegs are stored at a controlled temperature for a period of time to allow carbonation to occur. This process typically takes a few weeks, during which the flavors and aromas continue to develop. If kegging, carbonation can also be achieved through forced carbonation, where carbon dioxide is directly injected into the keg under pressure.'
} }
@@ -82,11 +81,19 @@
<div class="card"> <div class="card">
<h1>Brew progress</h1> <h1>Brew progress</h1>
<a href="{`/brews/${brew.date}`}" class="brew"> <p>View progress of the latest brew, click for more info</p>
<h2>{brew.name} <span class="company">av {brew.by}</span></h2> <a href="{`/brews/${brew.date}`}" class="brew-details">
<ArrowRight /> <img src="/images/{latestBrew.image}" alt="Beer label of {beer.name}" />
<ul>
<li>Name: <span>{beer.name}</span></li>
<li>Brewery: <span>{beer.brewery}</span></li>
<li>Brewed by: <span>{latestBrew.by.join(', ')}</span></li>
</ul>
<i class="arrow"><ArrowRight /></i>
</a> </a>
<ol class="os-timeline"> <ol class="os-timeline">
{#each steps as step, index} {#each steps as step, index}
<li <li
@@ -121,6 +128,52 @@
</div> </div>
<style lang="scss"> <style lang="scss">
.brew-details {
position: relative;
display: flex;
border-radius: 1rem;
transition: all 0.3s ease;
&:hover {
}
img {
width: 30%;
max-width: 140px;
margin-right: 1rem;
border-radius: 1rem;
}
ul {
display: flex;
flex-direction: column;
justify-content: center;
}
li {
display: flex;
flex-direction: column;
font-weight: bold;
span {
margin-top: 0.1rem;
margin-bottom: 0.5rem;
font-weight: normal;
font-size: 1.2rem;
}
}
}
.arrow {
position: absolute;
top: calc(50% - 0.75rem);
right: 0;
height: 1.5rem;
width: 1.5rem;
transition: all 0.3s ease;
}
a.brew { a.brew {
display: flex; display: flex;
align-items: center; align-items: center;
@@ -140,8 +193,9 @@
} }
} }
:global(a.brew:hover svg, a.brew svg.animate) { :global(.brew-details:hover svg, .brew-details svg.animate) {
animation: bounce 2s infinite; animation: bounce 2s infinite;
stroke: var(--green);
} }
@keyframes bounce { @keyframes bounce {
@@ -152,10 +206,10 @@
100% { 100% {
transform: translateX(0); transform: translateX(0);
} }
40% { 10% {
transform: translateX(-5px); transform: translateX(-5px);
} }
60% { 30% {
transform: translateX(-3px); transform: translateX(-3px);
} }
} }

View File

@@ -9,7 +9,8 @@
PointElement, PointElement,
Tooltip, Tooltip,
Title, Title,
Legend Legend,
Filler
} from 'chart.js'; } from 'chart.js';
import { getRelativePosition } from 'chart.js/helpers'; import { getRelativePosition } from 'chart.js/helpers';
@@ -24,7 +25,8 @@
PointElement, PointElement,
Tooltip, Tooltip,
Title, Title,
Legend Legend,
Filler
); );
export let name: string; export let name: string;
@@ -41,6 +43,8 @@
// Converts Date to format suitable for the current range displayed // Converts Date to format suitable for the current range displayed
function dateLabelsFormatedBasedOnResolution(dataFrames: IChartFrame[]): string[] { function dateLabelsFormatedBasedOnResolution(dataFrames: IChartFrame[]): string[] {
if (dataFrames.length < 2) return ['NO DATA'];
const firstFrame = dataFrames[0]; const firstFrame = dataFrames[0];
const lastFrame = dataFrames[dataFrames.length - 1]; const lastFrame = dataFrames[dataFrames.length - 1];
const deltaSeconds = const deltaSeconds =
@@ -69,25 +73,49 @@
return dataFrames.map((frame) => scaledDate.format(frame.key)); return dataFrames.map((frame) => scaledDate.format(frame.key));
} }
function hexToRgb(hex: string) {
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result
? {
r: parseInt(result[1], 16),
g: parseInt(result[2], 16),
b: parseInt(result[3], 16)
}
: null;
}
function createLineBackgroundGradient(hex: string, context: CanvasRenderingContext2D) {
const gradient = context.createLinearGradient(0, 0, 0, 400);
const c = hexToRgb(hex);
if (c == null) return;
gradient.addColorStop(0.2, `rgb(${c.r}, ${c.g}, ${c.b}, 0.8)`);
gradient.addColorStop(1, `rgb(${c.r}, ${c.g}, ${c.b}, 0.2)`);
return gradient;
}
// set dataset label & colors matching the name sent as prop // set dataset label & colors matching the name sent as prop
function setDataColorAndName(data: ChartDataset) { function setDataColorAndName(data: ChartDataset, context: CanvasRenderingContext2D) {
if (name === 'Pressure') { if (name === 'Pressure') {
Object.assign(data, { Object.assign(data, {
label: 'Bar of pressure', label: 'Bar of pressure',
borderColor: '#ef5878', borderColor: '#ef5878',
backgroundColor: '#fbd7de' fill: true,
backgroundColor: createLineBackgroundGradient('#fbd7de', context)
}); });
} else if (name === 'Humidity') { } else if (name === 'Humidity') {
Object.assign(data, { Object.assign(data, {
label: '% humidity', label: '% humidity',
borderColor: '#57d2fb', borderColor: '#57d2fb',
backgroundColor: '#d4f2fe' fill: true,
backgroundColor: createLineBackgroundGradient('#d4f2fe', context)
}); });
} else if (name === 'Temperature') { } else if (name === 'Temperature') {
Object.assign(data, { Object.assign(data, {
label: '℃ inside', label: '℃ inside',
borderColor: '#10e783', borderColor: '#10e783',
backgroundColor: '#c8f9df' fill: true,
backgroundColor: createLineBackgroundGradient('#c8f9df', context)
}); });
} }
} }
@@ -97,13 +125,14 @@
if (!context) return; if (!context) return;
// create labels and singular dataset (data) // create labels and singular dataset (data)
const labels: string[] = dateLabelsFormatedBasedOnResolution(dataFrames); const labels = dateLabelsFormatedBasedOnResolution(dataFrames);
const data: ChartDataset = { const data: ChartDataset = {
data: dataFrames.map((frame) => frame.value), data: dataFrames.map((frame) => frame.value),
borderWidth: 3 borderWidth: 3
}; };
// based on name, add label and color options to dataset // based on name, add label and color options to dataset
setDataColorAndName(data); setDataColorAndName(data, context);
// create chart instance, most here is chart options // create chart instance, most here is chart options
chart = new Chart(context, { chart = new Chart(context, {
@@ -152,7 +181,7 @@
speed: 0.001 speed: 0.001
}, },
// pinch: { // pinch: {
// enabled: true // enabled: true
// }, // },
mode: 'xy' mode: 'xy'
} }
@@ -174,7 +203,6 @@
scales: { scales: {
y: { y: {
beginAtZero: false, beginAtZero: false,
offset: true,
ticks: { ticks: {
color: 'black' color: 'black'
}, },

View File

@@ -3,7 +3,7 @@
import Navigation from './Navigation.svelte'; import Navigation from './Navigation.svelte';
import GithubIcon from '../icons/Github.svelte'; import GithubIcon from '../icons/Github.svelte';
let open: boolean = false; let open = false;
function toggleMenu() { function toggleMenu() {
open = !open; open = !open;
@@ -17,37 +17,35 @@
</script> </script>
{#if open} {#if open}
<div class="slideout-menu" transition:fly="{{ x: 550, duration: 300 }}"> <div class="slideout-menu" transition:fly="{{ x: 550, duration: 300 }}">
<h1>Navigation</h1> <h1>Page navigation</h1>
<Navigation on:click="{close}" /> <Navigation on:click="{close}" />
<ul class="bottom-content"> <ul class="bottom-content">
<li> <li>
<a href="https://github.com/kevinmidboe/brewpi"> <a class="link" href="https://github.com/kevinmidboe/brewpi">
<GithubIcon /> <GithubIcon />
<span class="meta">View on Github</span> <span class="meta">View on Github</span>
</a> </a>
</li> </li>
</ul> </ul>
</div> </div>
{/if} {/if}
<header> <header>
<div on:click="{toggleMenu}" class:open="{open}" aria-label="Open menu" class="menu"> <button on:click="{toggleMenu}" class:open="{open}" aria-label="Open menu" class="menu">
{#if !open} {#if !open}
<span class="page-header-buttons__open"> <span class="page-header-buttons__open"> <span></span> <span></span> <span></span> </span>
<span></span> <span></span> <span></span>
</span>
{:else} {:else}
<span class="page-header-buttons__close"> <span class="page-header-buttons__close">
<span></span> <span></span>
<span></span> <span></span>
</span> </span>
{/if} {/if}
<span class="page-header-text">{headerText}</span> <span class="page-header-text">{headerText}</span>
</div> </button>
</header> </header>
<style lang="scss" module="scoped"> <style lang="scss" module="scoped">
@@ -55,19 +53,23 @@
position: fixed; position: fixed;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
height: 100vh; height: calc(100vh + 4px);
width: 100vw; width: 100vw;
max-width: 550px; max-width: 550px;
right: 0; right: 0;
top: 0; top: -2px;
z-index: 10; z-index: 10;
border-left: 2px solid white;
border-top: 2px solid white;
background-color: #fff3f6; background-color: var(--green);
color: black; color: black;
padding: calc(100px + 2rem) 2rem 1rem; padding: calc(100px + 2rem) 2rem 1rem;
border-top-left-radius: 4rem; border-top-left-radius: 4rem;
color: var(--background);
h1 { h1 {
font-size: 3rem;
padding-bottom: 4rem; padding-bottom: 4rem;
} }
@@ -119,12 +121,15 @@
transition: all 0.3s ease; transition: all 0.3s ease;
cursor: pointer; cursor: pointer;
pointer-events: auto; pointer-events: auto;
-webkit-style: none;
border: none;
font-size: 1rem;
-webkit-user-select: none; -webkit-user-select: none;
user-select: none; user-select: none;
&.open { &.open {
background-color: salmon; background-color: var(--background);
color: black; color: black;
} }

View File

@@ -192,5 +192,6 @@
.desktop-only { .desktop-only {
display: grid; display: grid;
max-height: 80px; max-height: 80px;
margin-bottom: 4rem;
} }
</style> </style>

View File

@@ -23,7 +23,10 @@ const routes: Array<IRoute> = [{
<a href={route.path}> <a href={route.path}>
<li> <li>
<span>{ route.name }</span> <span>{ route.name }</span>
<i class="arrow">
<ArrowRight /> <ArrowRight />
</i>
</li> </li>
</a> </a>
{/each} {/each}
@@ -33,7 +36,8 @@ const routes: Array<IRoute> = [{
.navigation-cards a { .navigation-cards a {
display: block; display: block;
border-radius: 2rem; border-radius: 2rem;
background: var(--green); color: var(--text-color);
background: var(--background);
transition: background-color var(--color-transition-duration) ease-in-out, transform 0.2s ease; transition: background-color var(--color-transition-duration) ease-in-out, transform 0.2s ease;
&:hover { &:hover {
@@ -50,8 +54,12 @@ const routes: Array<IRoute> = [{
align-items: center; align-items: center;
justify-content: space-between; justify-content: space-between;
padding: 1rem 1.75rem; padding: 1rem 1.75rem;
color: white;
font-size: 1.3rem; font-size: 1.3rem;
i {
width: 1.5rem;
height: 1.5rem;
}
} }
} }
</style> </style>

View File

@@ -1,37 +1,39 @@
<script lang="ts"> <script lang="ts">
// import { toggleRelay } from '$lib/server/relayToggle' // import { toggleRelay } from '$lib/server/relayToggle'
import { createEventDispatcher } from 'svelte';
import Switch from './Switch.svelte'; import Switch from './Switch.svelte';
import type { IRelaysDTO } from '../interfaces/IRelaysDTO';
export let relays = []; export let relays: IRelaysDTO[] = [];
const dispatch = createEventDispatcher();
function toggleRelay(location) { function toggleRelay(controls: string) {
const url = `/api/relay/${location}`; const url = `/api/relay/${controls}`;
const options = { const options = {
method: 'POST' method: 'POST'
}; };
fetch(url, options) fetch(url, options)
.then((resp) => resp.json()) .then((resp) => resp.json())
.then(console.log); .then((response) => {
} const changedRelay = relays.findIndex((relay) => relay.pin === response.pin);
relays[changedRelay] = response;
});
function handleChange(event) { dispatch('relaySwitched');
let isChecked = event.detail.checked;
// Perform any desired actions based on the new value
console.log('New value:', isChecked);
} }
</script> </script>
<div class="card"> <div class="card">
<h1>Manual relay controls</h1> <h1>Manual fridge controls</h1>
<div class="vertical-sensor-display"> <div class="vertical-sensor-display">
{#each relays as relay} {#each relays as relay}
<div> <div>
<h2>{relay.location} relay</h2> <h2>{relay.controls} relay</h2>
<div class="sensor-reading"> <div class="sensor-reading">
<Switch checked="{relay.state}" on:change="{() => toggleRelay(relay.location)}" /> <Switch checked="{relay.state}" on:change="{() => toggleRelay(relay.controls)}" />
</div> </div>
</div> </div>
{/each} {/each}

View File

@@ -1,22 +1,31 @@
<script lang="ts"> <script lang="ts">
import { onMount } from 'svelte' import { onMount } from 'svelte';
import CardButton from "./CardButton.svelte"; import CardButton from './CardButton.svelte';
import Activity from "../icons/Activity.svelte"; import Activity from '../icons/Activity.svelte';
import { ISensorDTO } from '../interfaces/ISensorDTO';
import { IRelaysDTO } from '../interfaces/IRelaysDTO';
import { IStateDTO } from '../interfaces/IStateDTO';
export let inside; export let inside: ISensorDTO;
export let outside; export let outside: ISensorDTO;
export let relays: IRelaysDTO[] = [];
export let state: IStateDTO;
let loadedTime: number = new Date().getTime(); let loadedTime: number = new Date().getTime();
let currentTime: number = new Date().getTime(); let currentTime: number = new Date().getTime();
let autoReload = false; let autoReload = false;
const currentGoal = 18.5;
function updateTime() { function updateTime() {
currentTime = new Date().getTime(); currentTime = new Date().getTime();
} }
function flipCard(): void { function flipCard(): void {
console.log("flip-a-delphia") console.log('flip-a-delphia');
}
function tempToStateClass(temp: number | undefined) {
if (temp === undefined || !!isNaN(temp)) return 'idle';
return Number(temp) > 14 ? 'heating' : 'cooling';
} }
onMount(() => setInterval(updateTime, 1000)); onMount(() => setInterval(updateTime, 1000));
@@ -24,41 +33,47 @@
</script> </script>
<div class="card"> <div class="card">
<h1>Fridge sensors</h1>
<CardButton> <CardButton>
<Activity on:click={flipCard} /> <Activity on:click="{flipCard}" />
</CardButton> </CardButton>
<h2>Current target temperature</h2> <h2>Current target temperature</h2>
<div class="sensor-reading"> <div class="sensor-reading">
<div class="blue"> <div class="{state?.state}">
<span class="value">{currentGoal}</span> <span class="value">{state?.goal || 0}</span>
<span class="unit">°C</span> <span class="unit">°C</span>
</div> </div>
</div>
<h2>Inside temperature</h2>
<div class="sensor-reading">
<div class="blue">
<span class="value">{inside?.temperature}</span>
<span class="unit">{inside?.temperature_unit}</span>
</div>
<div> <div>
<span class="value">{Math.floor(inside?.humidity)}</span> <span class="value"></span>
<span class="unit">{state?.state || 'unknown'}</span>
</div>
</div>
<h2>Inside frigde temperature</h2>
<div class="sensor-reading">
<div class="{tempToStateClass(inside?.temperature)}">
<span class="value">{inside?.temperature || 0}</span>
<span class="unit">{inside?.temperature_unit || '°C'}</span>
</div>
<div>
<span class="value">{Math.floor(inside?.humidity || 0)}</span>
<span class="unit">{inside?.humidity_unit || '%'}</span> <span class="unit">{inside?.humidity_unit || '%'}</span>
</div> </div>
</div> </div>
<h2>Outside temperature</h2> <h2>Outside temperature</h2>
<div class="sensor-reading"> <div class="sensor-reading">
<div class="red"> <div class="{tempToStateClass(outside?.temperature)}">
<span class="value">{outside?.temperature}</span> <span class="value">{outside?.temperature || 0}</span>
<span class="unit">{outside?.temperature_unit}</span> <span class="unit">{outside?.temperature_unit || '°C'}</span>
</div> </div>
<div> <div>
<span class="value">{Math.floor(outside?.humidity)}</span> <span class="value">{Math.floor(outside?.humidity || 0)}</span>
<span class="unit">{outside?.humidity_unit}</span> <span class="unit">{outside?.humidity_unit || '%'}</span>
</div> </div>
</div> </div>
@@ -70,14 +85,16 @@
<div class="button-timer"> <div class="button-timer">
<span>Updated {secondsSinceUpdate === 0 ? 'now' : secondsSinceUpdate + 's ago'}</span> <span>Updated {secondsSinceUpdate === 0 ? 'now' : secondsSinceUpdate + 's ago'}</span>
</div> </div>
</div> </div>
<style lang="scss" module="scoped"> <style lang="scss" module="scoped">
@import '../../styles/media-queries.scss'; @import '../../styles/media-queries.scss';
.card {
position: relative;
}
h2 { h2 {
font-size: 1.4rem; font-size: 1.4rem;
margin-bottom: 1.5rem; margin-bottom: 1.5rem;
@@ -92,6 +109,7 @@
.sensor-reading { .sensor-reading {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
flex-wrap: wrap;
margin-bottom: 1.75rem; margin-bottom: 1.75rem;
font-size: 2.2rem; font-size: 2.2rem;
@@ -117,13 +135,24 @@
margin-left: 0.3rem; margin-left: 0.3rem;
} }
.red { .info {
font-size: 1rem;
width: 100%;
margin-bottom: 0;
font-weight: 500;
}
.heating {
color: var(--red); color: var(--red);
} }
.blue { .cooling {
color: var(--blue); color: var(--blue);
} }
.idle {
color: var(--green);
}
} }
.button-timer { .button-timer {

View File

@@ -1 +1 @@
<svg on:click xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-arrow-right"><line x1="5" y1="12" x2="19" y2="12"></line><polyline points="12 5 19 12 12 19"></polyline></svg> <svg on:click xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-arrow-right"><line x1="5" y1="12" x2="19" y2="12"></line><polyline points="12 5 19 12 12 19"></polyline></svg>

Before

Width:  |  Height:  |  Size: 323 B

After

Width:  |  Height:  |  Size: 328 B

View File

@@ -1 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z"/></svg> <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z" fill="white"/></svg>

Before

Width:  |  Height:  |  Size: 814 B

After

Width:  |  Height:  |  Size: 828 B

View File

@@ -0,0 +1,17 @@
enum Controls {
heating = 'heating',
cooling = 'cooling',
fan = 'fan',
lights = 'lights'
}
interface IRelaysDTO {
controls: Controls;
pin: number;
state: boolean;
}
export {
IRelaysDTO,
Controls
}

View File

@@ -0,0 +1,19 @@
enum Location {
inside = 'inside',
outside = 'outside'
}
interface ISensorDTO {
location: Location;
temperature?: number
temperature_unit?: string
humidity?: number
humidity_unit?: string
pressure?: number
pressure_unit?: string
}
export {
ISensorDTO,
Location
}

View File

@@ -0,0 +1,15 @@
enum State {
idle = 'idle',
cooling = 'cooling',
heating = 'heating'
}
interface IStateDTO {
goal: number;
state: State
}
export {
IStateDTO,
State
}

View File

@@ -4,24 +4,31 @@
import '../styles/global.css'; import '../styles/global.css';
</script> </script>
<HeaderComponent /> <div class="app">
<!-- <Darkmode/> --> <HeaderComponent />
<!-- <Darkmode/> -->
<div class="page-content"> <main>
<slot /> <slot />
</main>
</div> </div>
<style lang="scss"> <style lang="scss">
@import '../styles/media-queries.scss'; @import '../styles/media-queries.scss';
.page-content { .app {
min-height: calc(100vh - var(--header-height));
}
main {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
min-height: calc(100vh - var(--header-height)); min-height: 95vh;
margin: var(--header-height) 2.5rem 0; margin: var(--header-height) 2.5rem 0;
@include mobile { @include mobile {
margin: var(--header-height) 1rem 0; margin: var(--header-height) 1rem 0;
min-height: 85vh;
} }
} }
</style> </style>

View File

@@ -1,34 +1,36 @@
import { BREWLOGGER_HOST } from '$env/static/private'; import { BREWLOGGER_HOST } from '$env/static/private';
import type { PageServerLoad } from './$types'; import type { PageServerLoad } from './$types';
import type { ISensorDTO } from '../lib/interfaces/ISensorDTO'
import { IRelaysDTO } from '../lib/interfaces/IRelaysDTO';
import { IStateDTO } from '../lib/interfaces/IStateDTO';
const sensorsUrl = `${BREWLOGGER_HOST}/api/sensors`; const sensorsUrl = `${BREWLOGGER_HOST}/api/sensors`;
const relaysUrl = `${BREWLOGGER_HOST}/api/relays`; const relaysUrl = `${BREWLOGGER_HOST}/api/relays`;
const stateUrl = `${BREWLOGGER_HOST}/api/regulator`;
async function getSensors() { async function getFromEndpoint(endpoint: string) {
return fetch(sensorsUrl) return fetch(endpoint)
.then((resp) => resp.json()) .then((resp) => resp.json())
.then((response) => { .catch((error) => {
return response?.sensors; console.error('Failed to fetch endpoint:', endpoint);
}); console.error(error);
} return null
async function getRelays() {
return fetch(relaysUrl)
.then((resp) => resp.json())
.then((response) => {
return response?.relays || [];
}); });
} }
export const load: PageServerLoad = async () => { export const load: PageServerLoad = async () => {
const [sensors, relays] = await Promise.all([getSensors(), getRelays()]); const [sensorsResp, relaysResp, stateResp] = await Promise.all([getFromEndpoint(sensorsUrl), getFromEndpoint(relaysUrl), getFromEndpoint(stateUrl)]);
const sensors: ISensorDTO[] = sensorsResp?.sensors || []
const relays: IRelaysDTO[] = relaysResp?.relays || []
const state: IStateDTO = stateResp
const inside = sensors.find((sensor) => sensor.location === 'inside'); const inside = sensors.find((sensor: ISensorDTO) => sensor.location === 'inside');
const outside = sensors.find((sensor) => sensor.location === 'outside'); const outside = sensors.find((sensor: ISensorDTO) => sensor.location === 'outside');
return { return {
inside: inside || null, inside: inside || null,
outside: outside || null, outside: outside || null,
relays relays,
state
}; };
}; };

View File

@@ -1,13 +1,21 @@
<script lang="ts"> <script lang="ts">
import Logo from '../lib/components/Logo.svelte'; import Logo from '../lib/components/Logo.svelte';
import VerticalSensorDisplay from '../lib/components/VerticalSensorDisplay.svelte'; import VerticalSensorDisplay from '../lib/components/VerticalSensorDisplay.svelte';
// import Livestream from '$lib/components/Livestream.svelte'
import BrewProgress from '../lib/components/BrewProgress.svelte'; import BrewProgress from '../lib/components/BrewProgress.svelte';
import type { PageData } from './$types';
import RelayControls from '../lib/components/RelayControls.svelte'; import RelayControls from '../lib/components/RelayControls.svelte';
import type { PageData } from './$types';
import type { IStateDTO } from '../lib/interfaces/IStateDTO';
export let data: PageData; export let data: PageData;
const { inside, outside, relays } = data; const { inside, outside } = data;
let { relays, state } = data;
const updateState = () =>
setTimeout(() => {
fetch('/api/state')
.then((resp) => resp.json())
.then((response: IStateDTO) => (state = response));
}, 100);
</script> </script>
<Logo /> <Logo />
@@ -15,11 +23,9 @@
<div class="vertical-grid"> <div class="vertical-grid">
<BrewProgress /> <BrewProgress />
<VerticalSensorDisplay inside="{inside}" outside="{outside}" /> <VerticalSensorDisplay {inside} {outside} {relays} {state} />
<RelayControls relays="{relays}" /> <RelayControls bind:relays="{relays}" on:relaySwitched="{updateState}" />
<!-- <Livestream /> -->
</div> </div>
<style lang="scss"> <style lang="scss">
@@ -36,5 +42,15 @@
grid-template-columns: 2fr 2fr 3fr; grid-template-columns: 2fr 2fr 3fr;
margin: 2rem; margin: 2rem;
} }
@media (min-width: 900px) and (max-width: 1550px) {
grid-template-columns: 2fr 2fr;
}
}
:global(.vertical-grid > div:nth-child(3)) {
@media (min-width: 900px) and (max-width: 1550px) {
margin-top: -185px;
}
} }
</style> </style>

View File

@@ -0,0 +1,9 @@
import { json, RequestEvent } from '@sveltejs/kit';
import { BREWLOGGER_HOST } from '$env/static/private';
import type { RequestHandler } from './$types';
export const GET = (async (event: RequestEvent) => {
return fetch(BREWLOGGER_HOST + '/api/regulator')
.then((resp) => resp.json())
.then((response) => json(response));
}) satisfies RequestHandler;

View File

@@ -1,12 +1,14 @@
<script lang="ts"> <script lang="ts">
import ArrowRight from '../../lib/icons/ArrowRight.svelte';
export let data; export let data;
const brews = data?.brews || []; const brews = data?.brews || [];
const path = (date: string) => '/brews/' + String(date); const path = (date: string) => '/brews/' + String(date);
const dateFormat = { year: 'numeric', month: 'short', day: 'numeric' }; const dateFormat = { year: 'numeric', month: 'short', day: 'numeric' };
const dateString = (date: number) => new Date(date * 1000).toLocaleDateString('no-NB', dateFormat); const dateString = (date: number) =>
new Date(date * 1000).toLocaleDateString('no-NB', dateFormat);
</script> </script>
<main class="card"> <main class="card">
@@ -14,26 +16,130 @@
<ul> <ul>
{#each brews as brew} {#each brews as brew}
<li><a href="{path(brew.date)}">{ brew.beer.name } av { brew.beer.brewery }</a> - {dateString(brew.date)}</li> <li class="brew">
<a href="{path(brew.date)}">
<img src="/images/{brew.image}" alt="Beer label of {brew.beer.name}" />
<div class="details">
<h2>
{brew.beer.name}
<span>{brew.beer.category}</span>
</h2>
<p>By: {brew.by.join(', ')}</p>
<p>Date: {dateString(brew.date)}</p>
<p>Recipe by: {brew.beer.brewery}</p>
</div>
<div class="nav-arrow"><ArrowRight /></div>
</a>
</li>
{/each} {/each}
</ul> </ul>
</main> </main>
<style lang="scss"> <style lang="scss">
main.card { @import '../../styles/media-queries.scss';
height: calc(100vh - var(--header-height) * 2);
ul { main.card {
margin-left: 1.2em; min-height: calc(100vh - var(--header-height) * 2);
margin-bottom: 2rem;
padding: 0;
h1 {
margin: 1.5rem 0;
font-size: 3rem;
} }
ul li { ul {
list-style-type: disc; margin: 0;
line-height: 1.5; border-radius: inherit;
}
}
a { .brew {
font-size: 1.2rem; list-style-type: none;
color: #19A786; line-height: 1.5;
padding: 1.5rem;
transition: all 0.2s ease-in-out;
background-color: white;
z-index: 1;
border-radius: inherit;
&:not(:last-of-type) {
border-bottom: 1px solid #f5f5f7;
}
&:hover {
// transform: scale(1.01);
scale: 1.01;
will-change: transform;
box-shadow: 0px 2px 15px -3px rgba(25, 167, 134, 0.2);
z-index: 2;
}
a {
font-size: 1.2rem;
color: #19a786;
display: grid;
grid-template-columns: 160px 1fr 30px;
h2 {
margin: 0 0 0.75rem;
color: var(--green);
span {
display: block;
font-style: italic;
font-size: 1.2rem;
}
}
img {
width: 100%;
max-width: 160px;
border-radius: 0.5rem;
}
div.details {
margin-left: 2rem;
color: var(--text-color);
p {
margin: 0;
}
}
div.nav-arrow {
display: flex;
align-items: center;
}
}
}
@include mobile {
.brew {
padding-left: 1rem !important;
}
.brew a {
grid-template-columns: 80px 1fr;
img {
margin-top: 0.5rem;
background-color: pink;
}
div.details {
margin-left: 1rem;
h2 {
font-size: 1.5rem;
}
}
div.nav-arrow {
display: none;
} }
} }
} }

View File

@@ -1,5 +1,6 @@
<script lang="ts"> <script lang="ts">
import Graph from '../../../lib/components/Graph.svelte'; import Graph from '../../../lib/components/Graph.svelte';
import ArrowRight from '../../../lib/icons/ArrowRight.svelte';
import IChartFrame from '../../../lib/interfaces/IChartFrame'; import IChartFrame from '../../../lib/interfaces/IChartFrame';
let height: number; let height: number;
@@ -19,12 +20,23 @@
const wizards = brew.by.join(', '); const wizards = brew.by.join(', ');
</script> </script>
<a href="/brews" class="nav-back">
<ArrowRight />
</a>
<section class="card"> <section class="card">
<div class="desktop-only image-container" style="height: {height}px; background-color: {brew.color_primary || '#93a4a0'}"> <div
class="desktop-only image-container"
style="height: {height}px; background-color: {brew.color_primary || '#93a4a0'}"
>
<img src="/images/{brew.image}" alt="Tuborg Sommerøl" aria-label="Tuborg Sommerøl" /> <img src="/images/{brew.image}" alt="Tuborg Sommerøl" aria-label="Tuborg Sommerøl" />
</div> </div>
<div class="beer-container" bind:clientHeight="{height}" style="background-color: {brew.color_secondary || '#DFE6E5'}"> <div
class="beer-container"
bind:clientHeight="{height}"
style="background-color: {brew.color_secondary || '#DFE6E5'}"
>
<h1>{brew.beer.name}</h1> <h1>{brew.beer.name}</h1>
<div class="links"> <div class="links">
@@ -57,7 +69,10 @@
</tbody> </tbody>
</table> </table>
<div class="mobile-only image-container" style="background-color: {brew.color_primary || '#93a4a0'}"> <div
class="mobile-only image-container"
style="background-color: {brew.color_primary || '#93a4a0'}"
>
<img src="/images/{brew.image}" alt="Tuborg Sommerøl" aria-label="Tuborg Sommerøl" /> <img src="/images/{brew.image}" alt="Tuborg Sommerøl" aria-label="Tuborg Sommerøl" />
</div> </div>
@@ -66,17 +81,15 @@
<div class="graph-container"> <div class="graph-container">
{#if temperatureData && temperatureData?.length} {#if temperatureData && temperatureData?.length}
<div class="graph"> <div class="graph">
<h3>Temperature during fermentation</h3> <h3>Temperature during fermentation</h3>
<Graph dataFrames="{temperatureData}" name="Temperature" hideTitle="{true}" /> <Graph dataFrames="{temperatureData}" name="Temperature" hideTitle="{true}" />
</div> </div>
{/if} {/if} {#if humidityData && temperatureData?.length}
<div class="graph">
{#if humidityData && temperatureData?.length} <h3>Humidity during carbonation</h3>
<div class="graph"> <Graph dataFrames="{humidityData}" name="Humidity" hideTitle="{true}" />
<h3>Humidity during carbonation</h3> </div>
<Graph dataFrames="{humidityData}" name="Humidity" hideTitle="{true}" />
</div>
{/if} {/if}
</div> </div>
@@ -101,6 +114,24 @@
<style lang="scss"> <style lang="scss">
@import '../../../styles/media-queries.scss'; @import '../../../styles/media-queries.scss';
.nav-back {
position: fixed;
top: 1.5rem;
left: 1rem;
width: 2rem;
height: 2rem;
transform: rotate(180deg);
cursor: pointer;
transition: all 0.3s ease;
&:hover,
&:focus {
scale: 1.3;
will-change: transform;
color: var(--green);
}
}
section { section {
@import url('https://fonts.googleapis.com/css2?family=Epilogue:wght@200;300;400;500;600;700;800&display=swap'); @import url('https://fonts.googleapis.com/css2?family=Epilogue:wght@200;300;400;500;600;700;800&display=swap');
font-family: 'Epilogue', sans-serif; font-family: 'Epilogue', sans-serif;

View File

@@ -6,6 +6,7 @@
--text-color: black; --text-color: black;
--red: #ff97a3; --red: #ff97a3;
--blue: #9ad9ff; --blue: #9ad9ff;
--orange: orange;
--green: #19a786; --green: #19a786;
--header-height: 80px; --header-height: 80px;
@@ -39,6 +40,21 @@ a {
text-decoration: inherit; /* no underline */ text-decoration: inherit; /* no underline */
} }
a.link {
--color-text: white;
text-decoration: none;
transition: all 0.3s ease;
-webkit-transition: -webkit-transform 0.15s linear;
transition: transform 0.15s linear;
-webkit-transform-origin: 50% 80%;
transform-origin: 50% 80%;
border-bottom: 2px solid var(--green);
}
a.link:hover {
border-color: white;
transform: skew(-15deg);
}
ul, ul,
li { li {
margin: 0; margin: 0;

View File

@@ -1,14 +1,14 @@
$tablet-width: 1200px; $tablet-width: 1200px;
$mobile-width: 768px; $mobile-width: 768px;
@mixin tablet { @mixin mobile {
@media (min-width: #{$mobile-width}) { @media (max-width: #{$mobile-width}) {
@content; @content;
} }
} }
@mixin mobile { @mixin tablet {
@media (max-width: #{$mobile-width}) { @media (min-width: #{$mobile-width}) {
@content; @content;
} }
} }
@@ -29,4 +29,4 @@ $mobile-width: 768px;
@include tablet { @include tablet {
display: none !important; display: none !important;
} }
} }