Move adjustment forms to sidebar

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

5
.gitignore vendored

@ -6,4 +6,7 @@
/*.db-wal
/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());
}
let trigger_events =
HxResponseTrigger::normal(std::iter::once(HxEvent::from("new-adjustment")));
let trigger_events = vec![
HxEvent::from("new-adjustment"),
HxEvent::from("form-submit-success"),
];
let timestamp = chrono::Utc::now();
@ -93,7 +95,7 @@ pub async fn negative_adjustment_form_post(
.await?;
Ok((
trigger_events,
HxResponseTrigger::normal(trigger_events),
NegativeAdjustmentFormTemplate {
item_id: id,
amount_error: "",

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

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

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

@ -1,69 +1,92 @@
{% extends "main.html" %} {% block title %} Items {% endblock %} {% block
content %}
{% extends "main.html" %}
<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">
{{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>
{% block content %}
<section
hx-get="/item/{{item_id}}/stats"
hx-trigger="load"
hx-swap="outerHTML"
></section>
<div class="relative h-auto"
x-data="{ show_sidebar: false, sidebar_content: 'negative-adjustment-form' }"
x-on:form-submit-success="show_sidebar = false;"
>
<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 %}
<section
class="mx-auto mb-5"
x-data="{ negative_form_open: false, positive_form_open: false }"
>
<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="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"
<div class="relative h-auto mx-auto max-w-[68.75rem] w-[95vw] px-4 py-4">
<h2 class="mb-4 flex items-center text-4xl font-extrabold">
{{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"
>
Plus
</button>
</div>
Inactive
</span>
{% endif %}
</h2>
<div x-show="negative_form_open" @click.outside="negative_form_open = false">
<div
hx-get="/item/{{item_id}}/adjustment/negative"
hx-trigger="load"
hx-swap="outerHTML"
></div>
</div>
<section
hx-get="/item/{{item_id}}/stats"
hx-trigger="load"
hx-swap="outerHTML"
></section>
<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
hx-get="/item/{{item_id}}/adjustment/positive"
hx-get="/item/{{item_id}}/adjustments"
hx-trigger="load"
hx-swap="outerHTML"
></div>
</div>
</section>
{% endif %}
<section class="mx-auto">
<div
hx-get="/item/{{item_id}}/adjustments"
hx-trigger="load"
hx-swap="outerHTML"
></div>
</section>
</section>
</div>
</div>
{% endblock %}

@ -18,7 +18,7 @@
<body
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
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>
<a
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
</a>
<a
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
</a>
<a
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
</a>
<a
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
</a>
<a
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
</a>

Loading…
Cancel
Save

Powered by TurnKey Linux.