Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/better record defaults #37

Merged
merged 2 commits into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 14 additions & 21 deletions public/record.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,9 @@

<body class="center-vertically center-horizontally">
<main class="main">

<form action="" id="form">
<h1>New Activity</h1>

<div class="container">
<label for="amount">Amount</label>
<div class="input-group">
<i class="fa-solid fa-hashtag"></i>
<input type="number" placeholder="amount" id="amount" class="input">
</div>
</div>

<div class="container">
<label for="activity_type">Activity Type</label>
<div class="input-group">
Expand All @@ -38,31 +29,33 @@ <h1>New Activity</h1>
</div>
</div>

<div class="container">
<label for="amount">Distance in km / Repetitions</label>
<div class="input-group">
<i class="fa-solid fa-hashtag"></i>
<input type="number" placeholder="5" id="amount" class="input">
</div>
</div>

<div class="container">
<label for="start_time">Start Date and Time</label>
<div class="flex-column container">
<div class="input-group">
<i class="fa-solid fa-calendar-days"></i>
<input type="datetime-local" id="start_time" class="input">
<button type="button" onclick="set_time_now('start_time');" class="button button-info">
Now
</button>
</div>
<div id="start_time-timezone-container"></div>
<button type="button" onclick="set_time_now('start_time');" class="button button-info">
Now
</button>
</div>
</div>

<div class="container">
<label for="end_time">End Date and Time</label>
<div class="flex-column container">
<label for="duration">Duration in min</label>
<div class="input-group">
<i class="fa-solid fa-calendar-days"></i>
<input type="datetime-local" id="end_time" class="input">
<i class="fa-solid fa-stopwatch"></i>
<input type="number" placeholder="25" id="duration" class="input" value="0">
</div>
<div id="end_time-timezone-container"></div>
<button type="button" onclick="set_time_now('end_time');" class="button button-info">
Now
</button>
</div>
</div>

Expand Down
13 changes: 9 additions & 4 deletions public/record.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,28 @@ function set_time_now(html_id) {
window.set_time_now = set_time_now;

spawn_timzone("start_time-timezone", document.getElementById("start_time-timezone-container"));
spawn_timzone("end_time-timezone", document.getElementById("end_time-timezone-container"));
set_time_now("start_time");


document.querySelector("#form").addEventListener("submit", async (e) => {
e.preventDefault();

const amount = Number(document.querySelector("#amount").value);
const activity_type = document.querySelector("#activity_type").value;

let start_time = new Date(document.getElementById("start_time").value).toISOString();
let start_time = new Date(document.getElementById("start_time").value);
let start_time_str = start_time.toISOString();
// todo add timezone to end of string
console.log(start_time);

let end_time = new Date(document.getElementById("end_time").value).toISOString();
let duration = Number(document.getElementById("duration").value);
let end_time = new Date(start_time.getTime() + duration*60000);
let end_time_str = end_time.toISOString();

// todo add timezone to end of string
console.log(end_time);

let activity = new NewActivity(amount, activity_type, start_time, end_time);
let activity = new NewActivity(amount, activity_type, start_time_str, end_time_str);
let res = await create(activity);
if (res.ok) {
window.location = "/home.html";
Expand Down