Move adjustment forms to sidebar

main
Wes Holland 12 months ago
parent 705f8d9902
commit 5977cbae77

5
.gitignore vendored

@ -6,4 +6,7 @@
/*.db-wal /*.db-wal
/node_modules /node_modules
/*.lockb /*.lockb
/.idea/inventory-app.iml
/.idea/vcs.xml

@ -1,13 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="EMPTY_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="alpinejs" level="application" />
</component>
</module>

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

@ -70,8 +70,10 @@ pub async fn negative_adjustment_form_post(
.into_response()); .into_response());
} }
let trigger_events = let trigger_events = vec![
HxResponseTrigger::normal(std::iter::once(HxEvent::from("new-adjustment"))); HxEvent::from("new-adjustment"),
HxEvent::from("form-submit-success"),
];
let timestamp = chrono::Utc::now(); let timestamp = chrono::Utc::now();
@ -93,7 +95,7 @@ pub async fn negative_adjustment_form_post(
.await?; .await?;
Ok(( Ok((
trigger_events, HxResponseTrigger::normal(trigger_events),
NegativeAdjustmentFormTemplate { NegativeAdjustmentFormTemplate {
item_id: id, item_id: id,
amount_error: "", amount_error: "",

@ -4,14 +4,16 @@ use crate::db::inventory_item::does_inventory_item_allow_fractional_units;
use crate::error::AppError; use crate::error::AppError;
use crate::session::SessionUser; use crate::session::SessionUser;
use crate::util::currency::dollars_string_to_int_cents; use crate::util::currency::dollars_string_to_int_cents;
use crate::util::extract::htmx_form_data::{HtmxFormData, HtmxFormDataError};
use askama::Template; use askama::Template;
use askama_axum::{IntoResponse, Response}; use askama_axum::{IntoResponse, Response};
use axum::extract::{Path, State}; use axum::extract::{Path, State};
use axum::{debug_handler, Form}; use axum::{async_trait, debug_handler, Form};
use axum_htmx::{HxEvent, HxResponseTrigger}; use axum_htmx::{HxEvent, HxResponseTrigger};
use serde::Deserialize; use serde::Deserialize;
use sqlx::SqlitePool; use sqlx::SqlitePool;
use tracing::info; use tracing::info;
use crate::app::routes::AppState;
#[derive(Template)] #[derive(Template)]
#[template(path = "item/adjustment/positive-adjustment-form.html")] #[template(path = "item/adjustment/positive-adjustment-form.html")]
@ -63,8 +65,10 @@ pub async fn positive_adjustment_form_post(
let price = price?; let price = price?;
let unit_price = (price as f64 / form_data.amount) as i64; let unit_price = (price as f64 / form_data.amount) as i64;
let trigger_events = let trigger_events = vec![
HxResponseTrigger::normal(std::iter::once(HxEvent::from("new-adjustment"))); HxEvent::from("form-submit-success"),
HxEvent::from("new-adjustment"),
];
let timestamp = chrono::Utc::now(); let timestamp = chrono::Utc::now();
@ -88,7 +92,7 @@ pub async fn positive_adjustment_form_post(
.await?; .await?;
Ok(( Ok((
trigger_events, HxResponseTrigger::normal(trigger_events),
PositiveAdjustmentFormTemplate { PositiveAdjustmentFormTemplate {
item_id: id, item_id: id,
amount_error: "", amount_error: "",

@ -16,15 +16,10 @@
placeholder="Amount" placeholder="Amount"
aria-label="amount" aria-label="amount"
required required
{% {% if !amount_error.is_empty() -%}
if
!amount_error.is_empty()
-%}
aria-invalid="true" aria-invalid="true"
aria-describedby="invalid-amount" aria-describedby="invalid-amount"
{% {% endif -%}
endif
-%}
/> />
{% if !amount_error.is_empty() -%} {% if !amount_error.is_empty() -%}
<small id="invalid-amount" class="mt-2 text-sm text-cerise"> <small id="invalid-amount" class="mt-2 text-sm text-cerise">

@ -20,7 +20,9 @@
{% endif -%} {% endif -%}
/> />
{% if !amount_error.is_empty() -%} {% if !amount_error.is_empty() -%}
<small id="invalid-amount" class="mt-2 text-sm text-cerise"> <small id="invalid-amount"
class="mt-2 text-sm text-cerise"
>
{{ amount_error }} {{ amount_error }}
</small> </small>
{% endif -%} {% endif -%}
@ -35,20 +37,17 @@
placeholder="Price" placeholder="Price"
aria-label="price" aria-label="price"
required required
{% {% if !price_error.is_empty() -%}
if
!price_error.is_empty()
-%}
aria-invalid="true" aria-invalid="true"
aria-describedby="invalid-price" aria-describedby="invalid-price"
{% {% endif -%}
endif
-%}
/> />
{% if !price_error.is_empty() -%} {% if !price_error.is_empty() -%}
<small id="invalid-price" class="mt-2 text-sm text-cerise" <small id="invalid-price"
>{{ price_error }}</small class="mt-2 text-sm text-cerise"
> >
{{ price_error }}
</small>
{% endif -%} {% endif -%}
</div> </div>
<div class="mb-5"> <div class="mb-5">

@ -1,69 +1,92 @@
{% extends "main.html" %} {% block title %} Items {% endblock %} {% block {% extends "main.html" %}
content %}
<div class="relative h-auto mx-auto max-w-[68.75rem] w-[95vw] px-4 py-4"> {% block title %} Items {% endblock %}
<h2 class="mb-4 flex items-center text-4xl font-extrabold"> {% block content %}
{{item.name}} {% if !item.active %}
<span
class="me-2 ms-2 rounded border border-cerise bg-orchid-pink px-2.5 py-0.5 text-2xl font-semibold text-cerise"
>
Inactive
</span>
{% endif %}
</h2>
<section <div class="relative h-auto"
hx-get="/item/{{item_id}}/stats" x-data="{ show_sidebar: false, sidebar_content: 'negative-adjustment-form' }"
hx-trigger="load" x-on:form-submit-success="show_sidebar = false;"
hx-swap="outerHTML" >
></section> <div class="absolute w-screen h-lvh" x-show="show_sidebar">
<div class="relative w-full h-full bg-neutral-300 backdrop-blur-md opacity-90 py-4 z-10">
</div>
<div class="py-2 px-4 absolute rounded-tl-xl inset-y-0 right-0 bg-slate-100 opacity-100 w-11/12 max-w-[40rem] z-20">
<div class="flex">
<div class="flex-1 inline-flex items-center">
<h2 class="text-lg font-semibold uppercase" x-show="sidebar_content === 'negative-adjustment-form'">Negative Adjustment</h2>
<h2 class="text-lg font-semibold uppercase" x-show="sidebar_content === 'positive-adjustment-form'">Positive Adjustment</h2>
</div>
<button
class="inline-flex items-center whitespace-nowrap p-2 text-sm font-medium tracking-wide text-neutral-900 transition focus:outline-none focus:ring-4 focus:ring-dark-cyan dark:border-neutral-900 dark:text-slate-100"
@click="show_sidebar = ! show_sidebar"
>
<span class="sr-only">Close Sidebar</span>
X
</button>
</div>
<div x-show="sidebar_content === 'positive-adjustment-form'">
<div
hx-get="/item/{{item_id}}/adjustment/positive"
hx-trigger="load"
hx-swap="outerHTML"
></div>
</div>
<div x-show="sidebar_content === 'negative-adjustment-form'">
<div
hx-get="/item/{{item_id}}/adjustment/negative"
hx-trigger="load"
hx-swap="outerHTML"
></div>
</div>
</div>
</div>
{% if item.active %} <div class="relative h-auto mx-auto max-w-[68.75rem] w-[95vw] px-4 py-4">
<section
class="mx-auto mb-5" <h2 class="mb-4 flex items-center text-4xl font-extrabold">
x-data="{ negative_form_open: false, positive_form_open: false }" {{item.name}} {% if !item.active %}
> <span
<div class="flex justify-evenly"> class="me-2 ms-2 rounded border border-cerise bg-orchid-pink px-2.5 py-0.5 text-2xl font-semibold text-cerise"
<button
class="mb-2 me-2 rounded-lg bg-paynes-gray px-5 py-2.5 text-sm font-medium text-slate-100 hover:bg-dark-cyan focus:outline-none focus:ring-4 focus:ring-dark-cyan"
@click="negative_form_open = ! negative_form_open"
>
Minus
</button>
<button
class="mb-2 me-2 rounded-lg bg-paynes-gray px-5 py-2.5 text-sm font-medium text-slate-100 hover:bg-dark-cyan focus:outline-none focus:ring-4 focus:ring-dark-cyan"
@click="positive_form_open = ! positive_form_open"
> >
Plus Inactive
</button> </span>
</div> {% endif %}
</h2>
<div x-show="negative_form_open" @click.outside="negative_form_open = false"> <section
<div hx-get="/item/{{item_id}}/stats"
hx-get="/item/{{item_id}}/adjustment/negative" hx-trigger="load"
hx-trigger="load" hx-swap="outerHTML"
hx-swap="outerHTML" ></section>
></div>
</div>
<div x-show="positive_form_open" @click.outside="positive_form_open = false"> {% if item.active %}
<section class="mx-auto mb-5">
<div class="flex justify-evenly">
<button
class="mb-2 me-2 rounded-lg bg-paynes-gray px-5 py-2.5 text-sm font-medium text-slate-100 hover:bg-dark-cyan focus:outline-none focus:ring-4 focus:ring-dark-cyan"
@click="sidebar_content = 'negative-adjustment-form'; show_sidebar = true"
>
Minus
</button>
<button
class="mb-2 me-2 rounded-lg bg-paynes-gray px-5 py-2.5 text-sm font-medium text-slate-100 hover:bg-dark-cyan focus:outline-none focus:ring-4 focus:ring-dark-cyan"
@click="sidebar_content = 'positive-adjustment-form'; show_sidebar = true"
>
Plus
</button>
</div>
</section>
{% endif %}
<section class="mx-auto">
<div <div
hx-get="/item/{{item_id}}/adjustment/positive" hx-get="/item/{{item_id}}/adjustments"
hx-trigger="load" hx-trigger="load"
hx-swap="outerHTML" hx-swap="outerHTML"
></div> ></div>
</div> </section>
</section> </div>
{% endif %}
<section class="mx-auto">
<div
hx-get="/item/{{item_id}}/adjustments"
hx-trigger="load"
hx-swap="outerHTML"
></div>
</section>
</div> </div>
{% endblock %} {% endblock %}

@ -18,7 +18,7 @@
<body <body
class="min-h-screen bg-slate-100 text-neutral-900 dark:bg-neutral-900 dark:text-slate-100" class="min-h-screen bg-slate-100 text-neutral-900 dark:bg-neutral-900 dark:text-slate-100"
> >
<header class="top-0 w-full bg-slate-100 border-b border-neutral-600 border-opacity-90 font-sans"> <header class="top-0 w-full bg-slate-100 border-b border-neutral-600 border-opacity-90 font-sans dark:bg-neutral-900 dark:text-slate-100">
<nav <nav
class="mx-auto flex max-w-7xl justify-between gap-2 px-2 py-4 sm:px-6 lg:px-8" class="mx-auto flex max-w-7xl justify-between gap-2 px-2 py-4 sm:px-6 lg:px-8"
> >
@ -33,31 +33,31 @@
<div> <div>
<a <a
href="/overview" href="/overview"
class="rounded-md px-3 py-2 text-sm font-medium text-gray-300 hover:bg-gray-700 hover:text-white" class="rounded-md px-3 py-2 text-sm font-medium text-neutral-900 dark:text-slate-100 hover:bg-gray-700 hover:text-white"
> >
Overview Overview
</a> </a>
<a <a
href="/catalog" href="/catalog"
class="rounded-md px-3 py-2 text-sm font-medium text-gray-300 hover:bg-gray-700 hover:text-white" class="rounded-md px-3 py-2 text-sm font-medium text-neutral-900 dark:text-slate-100 hover:bg-gray-700 hover:text-white"
> >
Catalog Catalog
</a> </a>
<a <a
href="/upload" href="/upload"
class="rounded-md px-3 py-2 text-sm font-medium text-gray-300 hover:bg-gray-700 hover:text-white" class="rounded-md px-3 py-2 text-sm font-medium text-neutral-900 dark:text-slate-100 hover:bg-gray-700 hover:text-white"
> >
Upload Upload
</a> </a>
<a <a
href="/reports" href="/reports"
class="rounded-md px-3 py-2 text-sm font-medium text-gray-300 hover:bg-gray-700 hover:text-white" class="rounded-md px-3 py-2 text-sm font-medium text-neutral-900 dark:text-slate-100 hover:bg-gray-700 hover:text-white"
> >
Reports Reports
</a> </a>
<a <a
href="/history" href="/history"
class="rounded-md px-3 py-2 text-sm font-medium text-gray-300 hover:bg-gray-700 hover:text-white" class="rounded-md px-3 py-2 text-sm font-medium text-neutral-900 dark:text-slate-100 hover:bg-gray-700 hover:text-white"
> >
History History
</a> </a>

Loading…
Cancel
Save

Powered by TurnKey Linux.