Add button to add 5 minutes to session start time
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -1450,7 +1450,7 @@ checksum = "7345c971d1ef21ffdbd103a75990a15eb03604fc8b8852ca8cb418ee1a099028"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "stl"
|
name = "stl"
|
||||||
version = "0.1.0"
|
version = "0.1.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bincode",
|
"bincode",
|
||||||
"chrono",
|
"chrono",
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "stl"
|
name = "stl"
|
||||||
description = "studielogg, pronounced 'stell', aka scuffed toggl"
|
description = "studielogg, pronounced 'stell', aka scuffed toggl"
|
||||||
version = "0.1.0"
|
version = "0.1.1"
|
||||||
authors = ["Joakim Hulthe <joakim@hulthe.net>"]
|
authors = ["Joakim Hulthe <joakim@hulthe.net>"]
|
||||||
license = "MPL-2.0"
|
license = "MPL-2.0"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|||||||
@ -47,6 +47,7 @@ fn main() -> io::Result<()> {
|
|||||||
routes::api::create_category,
|
routes::api::create_category,
|
||||||
routes::api::start_session,
|
routes::api::start_session,
|
||||||
routes::api::end_session,
|
routes::api::end_session,
|
||||||
|
routes::api::bump_session,
|
||||||
routes::api::delete_session,
|
routes::api::delete_session,
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|||||||
@ -52,6 +52,36 @@ pub fn end_session(
|
|||||||
toggle_category_session(category_uuid, false, db)
|
toggle_category_session(category_uuid, false, db)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[post("/category/<category_uuid>/bump_session/minutes/<minutes>")]
|
||||||
|
pub fn bump_session(
|
||||||
|
category_uuid: String,
|
||||||
|
minutes: i64,
|
||||||
|
db: State<'_, sled::Db>,
|
||||||
|
) -> Result<Redirect, StatusJson> {
|
||||||
|
let duration = Duration::minutes(minutes);
|
||||||
|
let category_uuid = Uuid::parse_str(&category_uuid)?;
|
||||||
|
let category_uuid_s = sled::IVec::from(serialize(&category_uuid)?);
|
||||||
|
|
||||||
|
let categories_tree = db.open_tree(categories::NAME)?;
|
||||||
|
|
||||||
|
Ok((&categories_tree).transaction(|tx_categories| {
|
||||||
|
match tx_categories.get(&category_uuid_s)? {
|
||||||
|
None => return Ok(Err(Status::NotFound.into())),
|
||||||
|
Some(data) => {
|
||||||
|
let mut category: categories::V = deserialize(&data).unwrap();
|
||||||
|
match category.started.as_mut() {
|
||||||
|
Some(started) => {
|
||||||
|
*started -= duration;
|
||||||
|
tx_categories.insert(&category_uuid_s, serialize(&category).unwrap())?;
|
||||||
|
Ok(Ok(Redirect::to(uri!(pages::index))))
|
||||||
|
}
|
||||||
|
None => return Ok(Err(StatusJson::new(Status::BadRequest, "No active session"))),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})??)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn toggle_category_session(
|
pub fn toggle_category_session(
|
||||||
category_uuid: String,
|
category_uuid: String,
|
||||||
set_active: bool,
|
set_active: bool,
|
||||||
|
|||||||
@ -14,7 +14,7 @@
|
|||||||
function toggle_category(id) {
|
function toggle_category(id) {
|
||||||
// Find out whether the button is in active (play) or inactive (paused) state
|
// Find out whether the button is in active (play) or inactive (paused) state
|
||||||
let toggled_class = "category_button_toggled";
|
let toggled_class = "category_button_toggled";
|
||||||
let cl = document.getElementById("button-" + id).classList;
|
let cl = document.getElementById("toggle-button-" + id).classList;
|
||||||
let active = cl.contains(toggled_class);
|
let active = cl.contains(toggled_class);
|
||||||
|
|
||||||
// Get the corresponding route to activate/inactivate the category
|
// Get the corresponding route to activate/inactivate the category
|
||||||
@ -49,9 +49,14 @@
|
|||||||
style="background-color: {{this.1.color}}"
|
style="background-color: {{this.1.color}}"
|
||||||
></div>
|
></div>
|
||||||
<span class="category_name">{{this.1.name}}</span>
|
<span class="category_name">{{this.1.name}}</span>
|
||||||
|
{{#if this.1.started}}
|
||||||
|
<form action="/category/{{this.0}}/bump_session/minutes/5", method="post">
|
||||||
|
<button style="height: 100%; color: green;" type="submit">+5</button>
|
||||||
|
</form>
|
||||||
|
{{/if}}
|
||||||
<div class="category_button_container">
|
<div class="category_button_container">
|
||||||
<button
|
<button
|
||||||
id="button-{{this.0}}"
|
id="toggle-button-{{this.0}}"
|
||||||
onClick="toggle_category('{{this.0}}')"
|
onClick="toggle_category('{{this.0}}')"
|
||||||
{{#if this.1.started}}
|
{{#if this.1.started}}
|
||||||
class="category_button category_button_toggled"
|
class="category_button category_button_toggled"
|
||||||
|
|||||||
Reference in New Issue
Block a user