Compare commits
7 Commits
7010aee5b2
...
v0.1.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f91303b92c | ||
|
|
aff3367623 | ||
|
|
1736aeb122 | ||
|
|
37d0c33633 | ||
|
|
3bfe779425 | ||
|
|
395099d0ee | ||
|
|
b922a610e6 |
@@ -3,7 +3,7 @@ name: Release
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
tags:
|
tags:
|
||||||
- 'v*.*.*'
|
- "v*.*.*"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build_release:
|
build_release:
|
||||||
@@ -22,6 +22,11 @@ jobs:
|
|||||||
- name: Build release
|
- name: Build release
|
||||||
run: |
|
run: |
|
||||||
cargo build --release
|
cargo build --release
|
||||||
|
|
||||||
|
- name: Package frontend
|
||||||
|
run: |
|
||||||
|
zip -r static.zip static
|
||||||
|
|
||||||
- name: Generate a changelog
|
- name: Generate a changelog
|
||||||
uses: orhun/git-cliff-action@v4
|
uses: orhun/git-cliff-action@v4
|
||||||
id: git-cliff
|
id: git-cliff
|
||||||
@@ -31,8 +36,10 @@ jobs:
|
|||||||
github_token: ""
|
github_token: ""
|
||||||
env:
|
env:
|
||||||
OUTPUT: CHANGELOG.md
|
OUTPUT: CHANGELOG.md
|
||||||
|
|
||||||
- uses: akkuman/gitea-release-action@v1
|
- uses: akkuman/gitea-release-action@v1
|
||||||
with:
|
with:
|
||||||
files: |-
|
files: |-
|
||||||
target/release/weight_tracker
|
target/release/weight_tracker
|
||||||
body: Release build for weight_tracker
|
static.zip
|
||||||
|
body: ${{ steps.git-cliff.outputs.content }}
|
||||||
|
|||||||
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -3259,7 +3259,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "weight_tracker"
|
name = "weight_tracker"
|
||||||
version = "0.1.0"
|
version = "0.1.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"askama",
|
"askama",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "weight_tracker"
|
name = "weight_tracker"
|
||||||
version = "0.1.0"
|
version = "0.1.2"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@@ -2,8 +2,14 @@
|
|||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
VERSION="$(git cliff --bumped-version)"
|
VERSION_CLEAN="$(git cliff --bumped-version)"
|
||||||
VERSION_CLEAN="${VERSION#v}"
|
if [[ ! $VERSION_CLEAN =~ ^[0-9] ]]; then
|
||||||
|
echo "Error: VERSION_CLEAN does not start with a number"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
VERSION="v${VERSION_CLEAN}"
|
||||||
|
|
||||||
|
|
||||||
sed -i "s/^version = \".*\"/version = \"${VERSION_CLEAN}\"/" Cargo.toml
|
sed -i "s/^version = \".*\"/version = \"${VERSION_CLEAN}\"/" Cargo.toml
|
||||||
cargo check
|
cargo check
|
||||||
|
|
||||||
@@ -14,7 +20,7 @@ if [ "${CONFIRM}" != "Y" ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
git commit -am "chore: bump version to ${VERSION}"
|
git commit --allow-empty -am "chore: bump version to ${VERSION}"
|
||||||
git tag -am "Version ${VERSION}" "${VERSION}"
|
git tag -am "Version ${VERSION}" "${VERSION}"
|
||||||
|
|
||||||
echo Press Y to push commit and tag
|
echo Press Y to push commit and tag
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ pub struct IndexTemplate {
|
|||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct WeightForm {
|
pub struct WeightForm {
|
||||||
date: String,
|
date: String,
|
||||||
|
time: String,
|
||||||
weight: f64,
|
weight: f64,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,8 +150,9 @@ pub async fn input_post(
|
|||||||
Form(form): Form<WeightForm>,
|
Form(form): Form<WeightForm>,
|
||||||
) -> Result<Html<String>, Redirect> {
|
) -> Result<Html<String>, Redirect> {
|
||||||
// Check if user is authenticated
|
// Check if user is authenticated
|
||||||
// if let Some(user_id) = session.get::<String>("user_id") {
|
if let Some(user_id) = session.get::<String>("user_id") {
|
||||||
super::models::insert_weight(&state.pool, "lukas", &form.date, form.weight)
|
let datetime = format!("{}T{}", form.date, form.time);
|
||||||
|
super::models::insert_weight(&state.pool, &user_id, &datetime, form.weight)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let weights = super::models::get_all_weights(&state.pool)
|
let weights = super::models::get_all_weights(&state.pool)
|
||||||
@@ -160,12 +162,12 @@ pub async fn input_post(
|
|||||||
for weight in weights {
|
for weight in weights {
|
||||||
html.push_str(&format!(
|
html.push_str(&format!(
|
||||||
"<p>{}: {} kg by {}</p>\n",
|
"<p>{}: {} kg by {}</p>\n",
|
||||||
weight.date, weight.weight, "lukas"
|
weight.date, weight.weight, &user_id
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
Ok(Html(html))
|
Ok(Html(html))
|
||||||
// } else {
|
} else {
|
||||||
// // Redirect to login if not authenticated
|
// Redirect to login if not authenticated
|
||||||
// Err(Redirect::to("/auth/login"))
|
Err(Redirect::to("/auth/login"))
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,6 @@ use weight_tracker::{AppState, config::Config, create_app};
|
|||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
// Load configuration from config.toml or environment variables
|
|
||||||
// config-rs automatically merges file + environment + defaults
|
|
||||||
let config = Config::load("config.toml").unwrap_or_else(|e| {
|
let config = Config::load("config.toml").unwrap_or_else(|e| {
|
||||||
eprintln!("Failed to load configuration: {}", e);
|
eprintln!("Failed to load configuration: {}", e);
|
||||||
eprintln!("Using default values. Set environment variables prefixed with WEIGHT_TRACKER_ to override.");
|
eprintln!("Using default values. Set environment variables prefixed with WEIGHT_TRACKER_ to override.");
|
||||||
|
|||||||
@@ -1,10 +1,46 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<title>Weight Tracker</title>
|
<title>Weight Tracker</title>
|
||||||
<script src="https://unpkg.com/htmx.org@1.9.10"></script>
|
<script src="https://unpkg.com/htmx.org@1.9.10"></script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function fillCurrentDateTime() {
|
||||||
|
// Fill date and time with current values
|
||||||
|
const now = new Date();
|
||||||
|
|
||||||
|
// Format date as YYYY-MM-DD
|
||||||
|
const year = now.getFullYear();
|
||||||
|
const month = String(now.getMonth() + 1).padStart(2, '0');
|
||||||
|
const day = String(now.getDate()).padStart(2, '0');
|
||||||
|
document.getElementById('date').value = `${year}-${month}-${day}`;
|
||||||
|
|
||||||
|
// Format time as HH:MM
|
||||||
|
const hours = String(now.getHours()).padStart(2, '0');
|
||||||
|
const minutes = String(now.getMinutes()).padStart(2, '0');
|
||||||
|
document.getElementById('time').value = `${hours}:${minutes}`;
|
||||||
|
|
||||||
|
// Fill weight with the latest weight from the list
|
||||||
|
const weightElements = document.querySelectorAll('#weights p');
|
||||||
|
if (weightElements.length > 0) {
|
||||||
|
const latestWeightText = weightElements[0].textContent;
|
||||||
|
// Extract weight value from format "YYYY-MM-DD: XX.X kg by username"
|
||||||
|
const match = latestWeightText.match(/(\d+\.?\d*)\s*kg/);
|
||||||
|
if (match) {
|
||||||
|
document.getElementById('weight').value = match[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function showInputDialog() {
|
||||||
|
fillCurrentDateTime();
|
||||||
|
document.getElementById('inputDialog').showModal();
|
||||||
|
}
|
||||||
|
</script>
|
||||||
<link rel="stylesheet" href="/static/css/style.css">
|
<link rel="stylesheet" href="/static/css/style.css">
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<h1>Weight Tracker</h1>
|
<h1>Weight Tracker</h1>
|
||||||
<div id="weights">
|
<div id="weights">
|
||||||
@@ -12,16 +48,20 @@
|
|||||||
<p>{{ weight.date }}: {{ weight.weight }} kg by {{ weight.user_id }}</p>
|
<p>{{ weight.date }}: {{ weight.weight }} kg by {{ weight.user_id }}</p>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
<button onclick="document.getElementById('inputDialog').showModal()">Add Weight</button>
|
<button onclick="showInputDialog()">Add Weight</button>
|
||||||
<dialog id="inputDialog">
|
<dialog id="inputDialog">
|
||||||
<h1>Add Weight</h1>
|
<h1>Add Weight</h1>
|
||||||
<form hx-post="/input" hx-target="#weights" hx-swap="innerHTML" hx-on:htmx:after-request="document.getElementById('inputDialog').close()">
|
<form hx-post="/input" hx-target="#weights" hx-swap="innerHTML"
|
||||||
|
hx-on:htmx:after-request="document.getElementById('inputDialog').close()">
|
||||||
<label for="date">Date:</label>
|
<label for="date">Date:</label>
|
||||||
<input type="date" id="date" name="date" required><br>
|
<input type="date" id="date" name="date" required><br>
|
||||||
|
<label for="time">Time:</label>
|
||||||
|
<input type="time" id="time" name="time" required><br>
|
||||||
<label for="weight">Weight (kg):</label>
|
<label for="weight">Weight (kg):</label>
|
||||||
<input type="number" step="0.1" id="weight" name="weight" required><br>
|
<input type="number" step="0.1" id="weight" name="weight" required><br>
|
||||||
<button type="submit">Submit</button>
|
<button type="submit">Submit</button>
|
||||||
</form>
|
</form>
|
||||||
</dialog>
|
</dialog>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>Add Weight</title>
|
|
||||||
<script src="https://unpkg.com/htmx.org@1.9.10"></script>
|
|
||||||
<link rel="stylesheet" href="/static/css/style.css">
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<h1>Add Weight</h1>
|
|
||||||
<form hx-post="/input" hx-target="#result" hx-swap="innerHTML">
|
|
||||||
<label for="date">Date:</label>
|
|
||||||
<input type="date" id="date" name="date" required><br>
|
|
||||||
<label for="weight">Weight (kg):</label>
|
|
||||||
<input type="number" step="0.1" id="weight" name="weight" required><br>
|
|
||||||
<button type="submit">Submit</button>
|
|
||||||
</form>
|
|
||||||
<div id="result"></div>
|
|
||||||
<a href="/">Back to Tracker</a>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
Reference in New Issue
Block a user