Tmp #1

Merged
innocuous-symmetry merged 10 commits from tmp into main 2024-03-24 19:53:56 +00:00
34 changed files with 1017 additions and 1368 deletions

9
.gitignore vendored
View File

@@ -1,7 +1,10 @@
app
mikayla-moving
tmp
output.css
*.swp
*.test
*.out
tmp
output.css
example.db
*.db

View File

@@ -31,7 +31,16 @@ test:
## build: build a binary
.PHONY: build
build: test
go build -o ./app -v
sudo rm -f mikayla-moving
go build -o ./mikayla-moving -v
sudo cp mikayla-moving /usr/bin/mikayla-moving
# restart: rebuild and restart the systemd service running the project
.PHONY: restart
restart:
sudo systemctl stop mikayla-moving
make build
sudo systemctl restart mikayla-moving
## docker-build: build project into a docker container image
.PHONY: docker-build

View File

@@ -1,3 +0,0 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

View File

@@ -1,984 +0,0 @@
/*
! tailwindcss v3.3.3 | MIT License | https://tailwindcss.com
*/
/*
1. Prevent padding and border from affecting element width. (https://github.com/mozdevs/cssremedy/issues/4)
2. Allow adding a border to an element by just adding a border-width. (https://github.com/tailwindcss/tailwindcss/pull/116)
*/
*,
::before,
::after {
box-sizing: border-box;
/* 1 */
border-width: 0;
/* 2 */
border-style: solid;
/* 2 */
border-color: #e5e7eb;
/* 2 */
}
::before,
::after {
--tw-content: '';
}
/*
1. Use a consistent sensible line-height in all browsers.
2. Prevent adjustments of font size after orientation changes in iOS.
3. Use a more readable tab size.
4. Use the user's configured `sans` font-family by default.
5. Use the user's configured `sans` font-feature-settings by default.
6. Use the user's configured `sans` font-variation-settings by default.
*/
html {
line-height: 1.5;
/* 1 */
-webkit-text-size-adjust: 100%;
/* 2 */
-moz-tab-size: 4;
/* 3 */
-o-tab-size: 4;
tab-size: 4;
/* 3 */
font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
/* 4 */
font-feature-settings: normal;
/* 5 */
font-variation-settings: normal;
/* 6 */
}
/*
1. Remove the margin in all browsers.
2. Inherit line-height from `html` so users can set them as a class directly on the `html` element.
*/
body {
margin: 0;
/* 1 */
line-height: inherit;
/* 2 */
}
/*
1. Add the correct height in Firefox.
2. Correct the inheritance of border color in Firefox. (https://bugzilla.mozilla.org/show_bug.cgi?id=190655)
3. Ensure horizontal rules are visible by default.
*/
hr {
height: 0;
/* 1 */
color: inherit;
/* 2 */
border-top-width: 1px;
/* 3 */
}
/*
Add the correct text decoration in Chrome, Edge, and Safari.
*/
abbr:where([title]) {
-webkit-text-decoration: underline dotted;
text-decoration: underline dotted;
}
/*
Remove the default font size and weight for headings.
*/
h1,
h2,
h3,
h4,
h5,
h6 {
font-size: inherit;
font-weight: inherit;
}
/*
Reset links to optimize for opt-in styling instead of opt-out.
*/
a {
color: inherit;
text-decoration: inherit;
}
/*
Add the correct font weight in Edge and Safari.
*/
b,
strong {
font-weight: bolder;
}
/*
1. Use the user's configured `mono` font family by default.
2. Correct the odd `em` font sizing in all browsers.
*/
code,
kbd,
samp,
pre {
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
/* 1 */
font-size: 1em;
/* 2 */
}
/*
Add the correct font size in all browsers.
*/
small {
font-size: 80%;
}
/*
Prevent `sub` and `sup` elements from affecting the line height in all browsers.
*/
sub,
sup {
font-size: 75%;
line-height: 0;
position: relative;
vertical-align: baseline;
}
sub {
bottom: -0.25em;
}
sup {
top: -0.5em;
}
/*
1. Remove text indentation from table contents in Chrome and Safari. (https://bugs.chromium.org/p/chromium/issues/detail?id=999088, https://bugs.webkit.org/show_bug.cgi?id=201297)
2. Correct table border color inheritance in all Chrome and Safari. (https://bugs.chromium.org/p/chromium/issues/detail?id=935729, https://bugs.webkit.org/show_bug.cgi?id=195016)
3. Remove gaps between table borders by default.
*/
table {
text-indent: 0;
/* 1 */
border-color: inherit;
/* 2 */
border-collapse: collapse;
/* 3 */
}
/*
1. Change the font styles in all browsers.
2. Remove the margin in Firefox and Safari.
3. Remove default padding in all browsers.
*/
button,
input,
optgroup,
select,
textarea {
font-family: inherit;
/* 1 */
font-feature-settings: inherit;
/* 1 */
font-variation-settings: inherit;
/* 1 */
font-size: 100%;
/* 1 */
font-weight: inherit;
/* 1 */
line-height: inherit;
/* 1 */
color: inherit;
/* 1 */
margin: 0;
/* 2 */
padding: 0;
/* 3 */
}
/*
Remove the inheritance of text transform in Edge and Firefox.
*/
button,
select {
text-transform: none;
}
/*
1. Correct the inability to style clickable types in iOS and Safari.
2. Remove default button styles.
*/
button,
[type='button'],
[type='reset'],
[type='submit'] {
-webkit-appearance: button;
/* 1 */
background-color: transparent;
/* 2 */
background-image: none;
/* 2 */
}
/*
Use the modern Firefox focus style for all focusable elements.
*/
:-moz-focusring {
outline: auto;
}
/*
Remove the additional `:invalid` styles in Firefox. (https://github.com/mozilla/gecko-dev/blob/2f9eacd9d3d995c937b4251a5557d95d494c9be1/layout/style/res/forms.css#L728-L737)
*/
:-moz-ui-invalid {
box-shadow: none;
}
/*
Add the correct vertical alignment in Chrome and Firefox.
*/
progress {
vertical-align: baseline;
}
/*
Correct the cursor style of increment and decrement buttons in Safari.
*/
::-webkit-inner-spin-button,
::-webkit-outer-spin-button {
height: auto;
}
/*
1. Correct the odd appearance in Chrome and Safari.
2. Correct the outline style in Safari.
*/
[type='search'] {
-webkit-appearance: textfield;
/* 1 */
outline-offset: -2px;
/* 2 */
}
/*
Remove the inner padding in Chrome and Safari on macOS.
*/
::-webkit-search-decoration {
-webkit-appearance: none;
}
/*
1. Correct the inability to style clickable types in iOS and Safari.
2. Change font properties to `inherit` in Safari.
*/
::-webkit-file-upload-button {
-webkit-appearance: button;
/* 1 */
font: inherit;
/* 2 */
}
/*
Add the correct display in Chrome and Safari.
*/
summary {
display: list-item;
}
/*
Removes the default spacing and border for appropriate elements.
*/
blockquote,
dl,
dd,
h1,
h2,
h3,
h4,
h5,
h6,
hr,
figure,
p,
pre {
margin: 0;
}
fieldset {
margin: 0;
padding: 0;
}
legend {
padding: 0;
}
ol,
ul,
menu {
list-style: none;
margin: 0;
padding: 0;
}
/*
Reset default styling for dialogs.
*/
dialog {
padding: 0;
}
/*
Prevent resizing textareas horizontally by default.
*/
textarea {
resize: vertical;
}
/*
1. Reset the default placeholder opacity in Firefox. (https://github.com/tailwindlabs/tailwindcss/issues/3300)
2. Set the default placeholder color to the user's configured gray 400 color.
*/
input::-moz-placeholder, textarea::-moz-placeholder {
opacity: 1;
/* 1 */
color: #9ca3af;
/* 2 */
}
input::placeholder,
textarea::placeholder {
opacity: 1;
/* 1 */
color: #9ca3af;
/* 2 */
}
/*
Set the default cursor for buttons.
*/
button,
[role="button"] {
cursor: pointer;
}
/*
Make sure disabled buttons don't get the pointer cursor.
*/
:disabled {
cursor: default;
}
/*
1. Make replaced elements `display: block` by default. (https://github.com/mozdevs/cssremedy/issues/14)
2. Add `vertical-align: middle` to align replaced elements more sensibly by default. (https://github.com/jensimmons/cssremedy/issues/14#issuecomment-634934210)
This can trigger a poorly considered lint error in some tools but is included by design.
*/
img,
svg,
video,
canvas,
audio,
iframe,
embed,
object {
display: block;
/* 1 */
vertical-align: middle;
/* 2 */
}
/*
Constrain images and videos to the parent width and preserve their intrinsic aspect ratio. (https://github.com/mozdevs/cssremedy/issues/14)
*/
img,
video {
max-width: 100%;
height: auto;
}
/* Make elements with the HTML hidden attribute stay hidden by default */
[hidden] {
display: none;
}
[type='text'],[type='email'],[type='url'],[type='password'],[type='number'],[type='date'],[type='datetime-local'],[type='month'],[type='search'],[type='tel'],[type='time'],[type='week'],[multiple],textarea,select {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
background-color: #fff;
border-color: #6b7280;
border-width: 1px;
border-radius: 0px;
padding-top: 0.5rem;
padding-right: 0.75rem;
padding-bottom: 0.5rem;
padding-left: 0.75rem;
font-size: 1rem;
line-height: 1.5rem;
--tw-shadow: 0 0 #0000;
}
[type='text']:focus, [type='email']:focus, [type='url']:focus, [type='password']:focus, [type='number']:focus, [type='date']:focus, [type='datetime-local']:focus, [type='month']:focus, [type='search']:focus, [type='tel']:focus, [type='time']:focus, [type='week']:focus, [multiple]:focus, textarea:focus, select:focus {
outline: 2px solid transparent;
outline-offset: 2px;
--tw-ring-inset: var(--tw-empty,/*!*/ /*!*/);
--tw-ring-offset-width: 0px;
--tw-ring-offset-color: #fff;
--tw-ring-color: #2563eb;
--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);
--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color);
box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow);
border-color: #2563eb;
}
input::-moz-placeholder, textarea::-moz-placeholder {
color: #6b7280;
opacity: 1;
}
input::placeholder,textarea::placeholder {
color: #6b7280;
opacity: 1;
}
::-webkit-datetime-edit-fields-wrapper {
padding: 0;
}
::-webkit-date-and-time-value {
min-height: 1.5em;
}
::-webkit-datetime-edit,::-webkit-datetime-edit-year-field,::-webkit-datetime-edit-month-field,::-webkit-datetime-edit-day-field,::-webkit-datetime-edit-hour-field,::-webkit-datetime-edit-minute-field,::-webkit-datetime-edit-second-field,::-webkit-datetime-edit-millisecond-field,::-webkit-datetime-edit-meridiem-field {
padding-top: 0;
padding-bottom: 0;
}
select {
background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
background-position: right 0.5rem center;
background-repeat: no-repeat;
background-size: 1.5em 1.5em;
padding-right: 2.5rem;
-webkit-print-color-adjust: exact;
print-color-adjust: exact;
}
[multiple] {
background-image: initial;
background-position: initial;
background-repeat: unset;
background-size: initial;
padding-right: 0.75rem;
-webkit-print-color-adjust: unset;
print-color-adjust: unset;
}
[type='checkbox'],[type='radio'] {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
padding: 0;
-webkit-print-color-adjust: exact;
print-color-adjust: exact;
display: inline-block;
vertical-align: middle;
background-origin: border-box;
-webkit-user-select: none;
-moz-user-select: none;
user-select: none;
flex-shrink: 0;
height: 1rem;
width: 1rem;
color: #2563eb;
background-color: #fff;
border-color: #6b7280;
border-width: 1px;
--tw-shadow: 0 0 #0000;
}
[type='checkbox'] {
border-radius: 0px;
}
[type='radio'] {
border-radius: 100%;
}
[type='checkbox']:focus,[type='radio']:focus {
outline: 2px solid transparent;
outline-offset: 2px;
--tw-ring-inset: var(--tw-empty,/*!*/ /*!*/);
--tw-ring-offset-width: 2px;
--tw-ring-offset-color: #fff;
--tw-ring-color: #2563eb;
--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);
--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color);
box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow);
}
[type='checkbox']:checked,[type='radio']:checked {
border-color: transparent;
background-color: currentColor;
background-size: 100% 100%;
background-position: center;
background-repeat: no-repeat;
}
[type='checkbox']:checked {
background-image: url("data:image/svg+xml,%3csvg viewBox='0 0 16 16' fill='white' xmlns='http://www.w3.org/2000/svg'%3e%3cpath d='M12.207 4.793a1 1 0 010 1.414l-5 5a1 1 0 01-1.414 0l-2-2a1 1 0 011.414-1.414L6.5 9.086l4.293-4.293a1 1 0 011.414 0z'/%3e%3c/svg%3e");
}
[type='radio']:checked {
background-image: url("data:image/svg+xml,%3csvg viewBox='0 0 16 16' fill='white' xmlns='http://www.w3.org/2000/svg'%3e%3ccircle cx='8' cy='8' r='3'/%3e%3c/svg%3e");
}
[type='checkbox']:checked:hover,[type='checkbox']:checked:focus,[type='radio']:checked:hover,[type='radio']:checked:focus {
border-color: transparent;
background-color: currentColor;
}
[type='checkbox']:indeterminate {
background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 16 16'%3e%3cpath stroke='white' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M4 8h8'/%3e%3c/svg%3e");
border-color: transparent;
background-color: currentColor;
background-size: 100% 100%;
background-position: center;
background-repeat: no-repeat;
}
[type='checkbox']:indeterminate:hover,[type='checkbox']:indeterminate:focus {
border-color: transparent;
background-color: currentColor;
}
[type='file'] {
background: unset;
border-color: inherit;
border-width: 0;
border-radius: 0;
padding: 0;
font-size: unset;
line-height: inherit;
}
[type='file']:focus {
outline: 1px solid ButtonText;
outline: 1px auto -webkit-focus-ring-color;
}
*, ::before, ::after {
--tw-border-spacing-x: 0;
--tw-border-spacing-y: 0;
--tw-translate-x: 0;
--tw-translate-y: 0;
--tw-rotate: 0;
--tw-skew-x: 0;
--tw-skew-y: 0;
--tw-scale-x: 1;
--tw-scale-y: 1;
--tw-pan-x: ;
--tw-pan-y: ;
--tw-pinch-zoom: ;
--tw-scroll-snap-strictness: proximity;
--tw-gradient-from-position: ;
--tw-gradient-via-position: ;
--tw-gradient-to-position: ;
--tw-ordinal: ;
--tw-slashed-zero: ;
--tw-numeric-figure: ;
--tw-numeric-spacing: ;
--tw-numeric-fraction: ;
--tw-ring-inset: ;
--tw-ring-offset-width: 0px;
--tw-ring-offset-color: #fff;
--tw-ring-color: rgb(59 130 246 / 0.5);
--tw-ring-offset-shadow: 0 0 #0000;
--tw-ring-shadow: 0 0 #0000;
--tw-shadow: 0 0 #0000;
--tw-shadow-colored: 0 0 #0000;
--tw-blur: ;
--tw-brightness: ;
--tw-contrast: ;
--tw-grayscale: ;
--tw-hue-rotate: ;
--tw-invert: ;
--tw-saturate: ;
--tw-sepia: ;
--tw-drop-shadow: ;
--tw-backdrop-blur: ;
--tw-backdrop-brightness: ;
--tw-backdrop-contrast: ;
--tw-backdrop-grayscale: ;
--tw-backdrop-hue-rotate: ;
--tw-backdrop-invert: ;
--tw-backdrop-opacity: ;
--tw-backdrop-saturate: ;
--tw-backdrop-sepia: ;
}
::backdrop {
--tw-border-spacing-x: 0;
--tw-border-spacing-y: 0;
--tw-translate-x: 0;
--tw-translate-y: 0;
--tw-rotate: 0;
--tw-skew-x: 0;
--tw-skew-y: 0;
--tw-scale-x: 1;
--tw-scale-y: 1;
--tw-pan-x: ;
--tw-pan-y: ;
--tw-pinch-zoom: ;
--tw-scroll-snap-strictness: proximity;
--tw-gradient-from-position: ;
--tw-gradient-via-position: ;
--tw-gradient-to-position: ;
--tw-ordinal: ;
--tw-slashed-zero: ;
--tw-numeric-figure: ;
--tw-numeric-spacing: ;
--tw-numeric-fraction: ;
--tw-ring-inset: ;
--tw-ring-offset-width: 0px;
--tw-ring-offset-color: #fff;
--tw-ring-color: rgb(59 130 246 / 0.5);
--tw-ring-offset-shadow: 0 0 #0000;
--tw-ring-shadow: 0 0 #0000;
--tw-shadow: 0 0 #0000;
--tw-shadow-colored: 0 0 #0000;
--tw-blur: ;
--tw-brightness: ;
--tw-contrast: ;
--tw-grayscale: ;
--tw-hue-rotate: ;
--tw-invert: ;
--tw-saturate: ;
--tw-sepia: ;
--tw-drop-shadow: ;
--tw-backdrop-blur: ;
--tw-backdrop-brightness: ;
--tw-backdrop-contrast: ;
--tw-backdrop-grayscale: ;
--tw-backdrop-hue-rotate: ;
--tw-backdrop-invert: ;
--tw-backdrop-opacity: ;
--tw-backdrop-saturate: ;
--tw-backdrop-sepia: ;
}
.m-2 {
margin: 0.5rem;
}
.inline-block {
display: inline-block;
}
.flex {
display: flex;
}
.inline-flex {
display: inline-flex;
}
.table {
display: table;
}
.h-8 {
height: 2rem;
}
.w-full {
width: 100%;
}
.min-w-full {
min-width: 100%;
}
.appearance-none {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
}
.flex-col {
flex-direction: column;
}
.items-center {
align-items: center;
}
.justify-end {
justify-content: flex-end;
}
.overflow-hidden {
overflow: hidden;
}
.overflow-x-auto {
overflow-x: auto;
}
.whitespace-nowrap {
white-space: nowrap;
}
.rounded {
border-radius: 0.25rem;
}
.rounded-lg {
border-radius: 0.5rem;
}
.border {
border-width: 1px;
}
.border-b {
border-bottom-width: 1px;
}
.bg-blue-700 {
--tw-bg-opacity: 1;
background-color: rgb(29 78 216 / var(--tw-bg-opacity));
}
.bg-red-700 {
--tw-bg-opacity: 1;
background-color: rgb(185 28 28 / var(--tw-bg-opacity));
}
.px-1 {
padding-left: 0.25rem;
padding-right: 0.25rem;
}
.px-3 {
padding-left: 0.75rem;
padding-right: 0.75rem;
}
.px-4 {
padding-left: 1rem;
padding-right: 1rem;
}
.px-6 {
padding-left: 1.5rem;
padding-right: 1.5rem;
}
.py-1 {
padding-top: 0.25rem;
padding-bottom: 0.25rem;
}
.py-2 {
padding-top: 0.5rem;
padding-bottom: 0.5rem;
}
.py-4 {
padding-top: 1rem;
padding-bottom: 1rem;
}
.text-left {
text-align: left;
}
.text-3xl {
font-size: 1.875rem;
line-height: 2.25rem;
}
.text-sm {
font-size: 0.875rem;
line-height: 1.25rem;
}
.text-xl {
font-size: 1.25rem;
line-height: 1.75rem;
}
.font-light {
font-weight: 300;
}
.font-medium {
font-weight: 500;
}
.leading-tight {
line-height: 1.25;
}
.text-blue-100 {
--tw-text-opacity: 1;
color: rgb(219 234 254 / var(--tw-text-opacity));
}
.text-blue-700 {
--tw-text-opacity: 1;
color: rgb(29 78 216 / var(--tw-text-opacity));
}
.text-gray-700 {
--tw-text-opacity: 1;
color: rgb(55 65 81 / var(--tw-text-opacity));
}
.text-red-100 {
--tw-text-opacity: 1;
color: rgb(254 226 226 / var(--tw-text-opacity));
}
.shadow {
--tw-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
--tw-shadow-colored: 0 1px 3px 0 var(--tw-shadow-color), 0 1px 2px -1px var(--tw-shadow-color);
box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);
}
.transition-colors {
transition-property: color, background-color, border-color, text-decoration-color, fill, stroke;
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
transition-duration: 150ms;
}
.duration-150 {
transition-duration: 150ms;
}
@media (min-width: 768px) {
.md\:container {
width: 100%;
}
@media (min-width: 640px) {
.md\:container {
max-width: 640px;
}
}
@media (min-width: 768px) {
.md\:container {
max-width: 768px;
}
}
@media (min-width: 1024px) {
.md\:container {
max-width: 1024px;
}
}
@media (min-width: 1280px) {
.md\:container {
max-width: 1280px;
}
}
@media (min-width: 1536px) {
.md\:container {
max-width: 1536px;
}
}
}
.hover\:bg-blue-800:hover {
--tw-bg-opacity: 1;
background-color: rgb(30 64 175 / var(--tw-bg-opacity));
}
.hover\:bg-red-800:hover {
--tw-bg-opacity: 1;
background-color: rgb(153 27 27 / var(--tw-bg-opacity));
}
.hover\:underline:hover {
text-decoration-line: underline;
}
.focus\:outline-none:focus {
outline: 2px solid transparent;
outline-offset: 2px;
}
@media (prefers-color-scheme: dark) {
.dark\:border-neutral-500 {
--tw-border-opacity: 1;
border-color: rgb(115 115 115 / var(--tw-border-opacity));
}
}
@media (min-width: 640px) {
.sm\:-mx-6 {
margin-left: -1.5rem;
margin-right: -1.5rem;
}
.sm\:px-6 {
padding-left: 1.5rem;
padding-right: 1.5rem;
}
}
@media (min-width: 768px) {
.md\:mx-auto {
margin-left: auto;
margin-right: auto;
}
}
@media (min-width: 1024px) {
.lg\:-mx-8 {
margin-left: -2rem;
margin-right: -2rem;
}
.lg\:px-8 {
padding-left: 2rem;
padding-right: 2rem;
}
}

View File

@@ -22,26 +22,35 @@ const (
// entities
type Item struct {
ID int
Name string
Notes *string
Description *string
Stage PackingStage
Category Category
ID int `json:"id"`
Name string `json:"name"`
Notes *string `json:"notes"`
Description *string `json:"description"`
Stage PackingStage `json:"stage"`
Category Category `json:"category"`
}
type Box struct {
ID int
Name string
Notes *string
Description *string
Stage PackingStage
Category Category
ID int `json:"id"`
Name string `json:"name"`
Notes *string `json:"notes"`
Description *string `json:"description"`
Stage PackingStage `json:"stage"`
Category Category `json:"category"`
}
// joins
// joining tables and derivative data types
type BoxItem struct {
ID int
BoxID int
ItemID int
}
type BoxItemWithItemInfo struct {
ID int
Name string
Stage PackingStage
Category Category
Description *string
Notes *string
}

344
db/sql.go
View File

@@ -38,61 +38,6 @@ func GetAllItems() (result []Item, err error) {
return
}
func GetItemByID(id int) (item Item, err error) {
db, err := CreateClient()
if err != nil {
return Item{}, err
}
defer db.Close()
row := db.QueryRow("SELECT * FROM items WHERE id = ?", id)
err = row.Scan(&item.ID, &item.Name, &item.Notes, &item.Description, &item.Stage, &item.Category)
return
}
func PostItem(item Item) (int64, error) {
db, err := CreateClient()
if err != nil {
return -1, err
}
defer db.Close()
query := `INSERT INTO items (name, notes, description, stage, category)
VALUES (?, ?, ?, ?, ?)`
result, err := db.Exec(query, item.Name, item.Notes, item.Description, item.Stage, item.Category)
if err != nil {
return -1, err
}
return result.LastInsertId()
}
func PostBox(box Box) (int64, error) {
db, err := CreateClient()
if err != nil {
return -1, err
}
defer db.Close()
query := `INSERT INTO boxes (name, notes, description, stage, category) VALUES (?, ?, ?, ?, ?)`
result, err := db.Exec(query, box.Name, box.Notes, box.Description, box.Stage, box.Category)
if err != nil {
return -1, err
}
return result.LastInsertId()
}
func GetAllBoxes() (result []Box, err error) {
db, err := CreateClient()
if err != nil {
@@ -123,12 +68,285 @@ func GetAllBoxes() (result []Box, err error) {
return
}
// func PostBoxItem(itemid int, boxid int) (int64, error) {
// db, err := CreateClient()
// if err != nil {
// return -1, err
// }
func GetAllBoxItems() ([]BoxItem, error) {
db, err := CreateClient()
if err != nil {
return nil, err
}
// defer db.Close()
// // query :=
// }
defer db.Close()
rows, err := db.Query("SELECT * FROM box_items")
if err != nil {
return nil, err
}
defer rows.Close()
var result []BoxItem
for rows.Next() {
boxItem := BoxItem{}
err = rows.Scan(&boxItem.ID, &boxItem.BoxID, &boxItem.ItemID)
if err != nil {
return nil, err
}
result = append(result, boxItem)
}
return result, nil
}
func GetItemByID(id int) (item Item, err error) {
db, err := CreateClient()
if err != nil {
return Item{}, err
}
defer db.Close()
row := db.QueryRow("SELECT * FROM items WHERE id = ?", id)
err = row.Scan(&item.ID, &item.Name, &item.Notes, &item.Description, &item.Stage, &item.Category)
return
}
func GetBoxByID(id int) (box Box, err error) {
db, err := CreateClient()
if err != nil {
return Box{}, err
}
defer db.Close()
row := db.QueryRow("SELECT * FROM boxes WHERE id = ?", id)
err = row.Scan(&box.ID, &box.Name, &box.Notes, &box.Description, &box.Stage, &box.Category)
return
}
func GetBoxItemByID(id int) (BoxItem, error) {
db, err := CreateClient()
if err != nil {
return BoxItem{}, err
}
defer db.Close()
row := db.QueryRow("SELECT * FROM box_items WHERE id = ?", id)
boxItem := BoxItem{}
err = row.Scan(&boxItem.ID, &boxItem.BoxID, &boxItem.ItemID)
return boxItem, err
}
func GetBoxItemsByBoxID(boxID int) ([]BoxItemWithItemInfo, error) {
db, err := CreateClient()
if err != nil {
return nil, err
}
defer db.Close()
// get all rows from box_items where boxid = boxID
// also get the item info for each item
rows, err := db.Query(
"SELECT id, items.name, items.stage, items.category, items.description, items.notes FROM boxitems JOIN items ON itemid=items.id WHERE boxid = ?",
boxID)
if err != nil {
return nil, err
}
defer rows.Close()
result := []BoxItemWithItemInfo{}
for rows.Next() {
boxItem := BoxItemWithItemInfo{}
if err = rows.Scan(&boxItem.ID, &boxItem.Name, &boxItem.Stage, &boxItem.Category, &boxItem.Description, &boxItem.Notes); err != nil {
return nil, err
}
result = append(result, boxItem)
}
return result, nil
}
func PostItem(item Item) (int64, error) {
db, err := CreateClient()
if err != nil {
return -1, err
}
defer db.Close()
query := `INSERT INTO items (name, notes, description, stage, category)
VALUES (?, ?, ?, ?, ?)`
result, err := db.Exec(query, item.Name, item.Notes, item.Description, item.Stage, item.Category)
if err != nil {
return -1, err
}
return result.LastInsertId()
}
func PostBox(box Box) (int64, error) {
db, err := CreateClient()
if err != nil {
return -1, err
}
defer db.Close()
query := `INSERT INTO boxes (name, notes, description, stage, category) VALUES (?, ?, ?, ?, ?)`
result, err := db.Exec(query, box.Name, box.Notes, box.Description, box.Stage, box.Category)
if err != nil {
return -1, err
}
return result.LastInsertId()
}
func PostBoxItem(boxItem BoxItem) (int64, error) {
db, err := CreateClient()
if err != nil {
return -1, err
}
defer db.Close()
query := `INSERT INTO box_items (boxid, item_id) VALUES (?, ?)`
result, err := db.Exec(query, boxItem.BoxID, boxItem.ItemID)
if err != nil {
return -1, err
}
return result.LastInsertId()
}
func PutItem(item Item) (int64, error) {
db, err := CreateClient()
if err != nil {
return -1, err
}
defer db.Close()
query := `UPDATE items SET name = ?, notes = ?, description = ?, stage = ?, category = ? WHERE id = ?`
result, err := db.Exec(query, item.Name, item.Notes, item.Description, item.Stage, item.Category, item.ID)
if err != nil {
return -1, err
}
return result.RowsAffected()
}
func PutBox(box Box) (int64, error) {
db, err := CreateClient()
if err != nil {
return -1, err
}
defer db.Close()
query := `UPDATE boxes SET name = ?, notes = ?, description = ?, stage = ?, category = ? WHERE id = ?`
result, err := db.Exec(query, box.Name, box.Notes, box.Description, box.Stage, box.Category, box.ID)
if err != nil {
return -1, err
}
return result.RowsAffected()
}
func PutBoxItem(boxItem BoxItem) (int64, error) {
db, err := CreateClient()
if err != nil {
return -1, err
}
defer db.Close()
query := `UPDATE box_items SET boxid = ?, item_id = ? WHERE id = ?`
result, err := db.Exec(query, boxItem.BoxID, boxItem.ItemID, boxItem.ID)
if err != nil {
return -1, err
}
return result.RowsAffected()
}
func DeleteItem(id int) (int64, error) {
db, err := CreateClient()
if err != nil {
return -1, err
}
defer db.Close()
query := `DELETE FROM items WHERE id = ?`
result, err := db.Exec(query, id)
if err != nil {
return -1, err
}
return result.RowsAffected()
}
func DeleteBox(id int) (int64, error) {
db, err := CreateClient()
if err != nil {
return -1, err
}
defer db.Close()
query := `DELETE FROM boxes WHERE id = ?`
result, err := db.Exec(query, id)
if err != nil {
return -1, err
}
return result.RowsAffected()
}
func DeleteBoxItem(id int) (int64, error) {
db, err := CreateClient()
if err != nil {
return -1, err
}
defer db.Close()
query := `DELETE FROM box_items WHERE id = ?`
result, err := db.Exec(query, id)
if err != nil {
return -1, err
}
return result.RowsAffected()
}

37
main.go
View File

@@ -23,9 +23,6 @@ var (
//go:embed all:templates/*
templateFS embed.FS
//go:embed css/output.css
css embed.FS
//parsed templates
html *template.Template
)
@@ -45,14 +42,38 @@ func main() {
//add routes
router := http.NewServeMux()
// router.Handle("/css/output.css", http.FileServer(http.FS(css)))
// router.Handle("/company/add", web.Action(companyAdd))
// router.Handle("/company/add/", web.Action(companyAdd))
itemActions := routes.Items(html)
boxActions := routes.Boxes(html)
boxItemActions := routes.BoxItems(html)
router.Handle("/items/edit", web.Action(itemActions.Edit))
router.Handle("/items/delete", web.Action(itemActions.Delete))
router.Handle("/items/save", web.Action(itemActions.Save))
router.Handle("/items/edit/", web.Action(itemActions.Edit))
router.Handle("/items/delete/", web.Action(itemActions.Delete))
router.Handle("/items/delete/:id", web.Action(itemActions.Delete))
router.Handle("/items/save/", web.Action(itemActions.Save))
router.Handle("/items/save/:id", web.Action(itemActions.Save))
router.Handle("/items/add", web.Action(itemActions.Post))
router.Handle("/items/add/", web.Action(itemActions.Post))
router.Handle("/box-items", web.Action(boxItemActions.Get))
router.Handle("/box-items/", web.Action(boxItemActions.Get))
router.Handle("/box-items/:id", web.Action(boxItemActions.Get))
router.Handle("/items", web.Action(itemActions.Get))
router.Handle("/boxes", web.Action(boxActions.GetAll))
router.Handle("/items/", web.Action(itemActions.Get))
router.Handle("/items/:id", web.Action(itemActions.Get))
router.Handle("/boxes/", web.Action(boxActions.GetAll))
router.Handle("/boxes/:id", web.Action(boxActions.GetAll))
router.Handle("/", web.Action(routes.HomePage))
router.Handle("/items", web.Action(routes.Items(html).GetAll))
router.Handle("/boxes", web.Action(routes.Boxes(html).GetAll))
router.Handle("/index.html", web.Action(routes.HomePage))
//logging/tracing
nextRequestID := func() string {

View File

@@ -1,45 +0,0 @@
package routes
import (
"net/http"
"github.com/jritsema/gotoolbox/web"
)
type Entity int
const (
Item Entity = iota
Box
BoxItem
)
type RouterActions struct {
GetAll func(r *http.Request) *web.Response
GetByID func(r *http.Request) *web.Response
Post func(r *http.Request) *web.Response
Put func(r *http.Request) *web.Response
Delete func(r *http.Request) *web.Response
}
type Router struct {
Entity Entity
Path string
GetAll func(r *http.Request) *web.Response
GetByID func(r *http.Request) *web.Response
Post func(r *http.Request) *web.Response
Put func(r *http.Request) *web.Response
Delete func(r *http.Request) *web.Response
}
func NewRouter(entity Entity, path string, actions RouterActions) *Router {
return &Router{
Entity: entity,
Path: path,
GetAll: actions.GetAll,
GetByID: actions.GetByID,
Post: actions.Post,
Put: actions.Put,
Delete: actions.Delete,
}
}

100
routes/boxItems.go Normal file
View File

@@ -0,0 +1,100 @@
package routes
import (
"html/template"
"net/http"
"strconv"
"github.com/innocuous-symmetry/moving-mgmt/db"
"github.com/jritsema/gotoolbox/web"
)
type BoxItemActions struct {
Get func(r *http.Request) *web.Response
GetAll func(r *http.Request) *web.Response
GetByID func(r *http.Request) *web.Response
GetByBoxID func(r *http.Request) *web.Response
}
func BoxItems(_html *template.Template) *BoxItemActions {
html = _html
return &BoxItemActions{
Get: BoxItemsHandler,
GetAll: nil,
GetByID: nil,
}
}
func BoxItemsHandler(r *http.Request) *web.Response {
switch r.Method {
case http.MethodGet:
if r.URL.Query().Has("boxid") {
return GetBoxItemsByBoxID(r)
}
_, count := web.PathLast(r)
if count == 1 {
return GetAllBoxItems(r)
} else {
return GetBoxItemByID(r)
}
default:
return nil
}
}
func GetAllBoxItems(_ *http.Request) *web.Response {
items, err := db.GetAllBoxItems()
if err != nil {
return web.Error(
http.StatusBadRequest,
err,
nil,
)
}
return web.HTML(
http.StatusOK,
html,
"box-items/box-item-list.html",
items,
nil,
)
}
func GetBoxItemsByBoxID(r *http.Request) *web.Response {
boxID := r.URL.Query().Get("boxid")
if id, err := strconv.ParseInt(boxID, 10, 64); err != nil {
return web.Error(
http.StatusBadRequest,
err,
nil,
)
} else {
items, err := db.GetBoxItemsByBoxID(int(id))
if err != nil {
return web.Error(
http.StatusNotFound,
err,
nil,
)
}
return web.HTML(
http.StatusOK,
html,
"box-items/box-item-list.html",
items,
nil,
)
}
}
func GetBoxItemByID(_ *http.Request) *web.Response {
return nil
}

View File

@@ -8,20 +8,24 @@ import (
"github.com/jritsema/gotoolbox/web"
)
func Boxes(_html *template.Template) *Router {
type BoxActions struct {
GetAll func(r *http.Request) *web.Response
GetByID func(r *http.Request) *web.Response
Post func(r *http.Request) *web.Response
Put func(r *http.Request) *web.Response
Delete func(r *http.Request) *web.Response
}
func Boxes(_html *template.Template) *BoxActions {
html = _html
return NewRouter(
Box,
"/boxes",
RouterActions{
GetAll: GetAllBoxes,
GetByID: nil,
Post: nil,
Put: nil,
Delete: nil,
},
)
return &BoxActions{
GetAll: GetAllBoxes,
GetByID: nil,
Post: nil,
Put: nil,
Delete: nil,
}
}
func GetAllBoxes(_ *http.Request) *web.Response {
@@ -33,7 +37,7 @@ func GetAllBoxes(_ *http.Request) *web.Response {
return web.HTML(
http.StatusOK,
html,
"entity-list.html",
"boxes/box-list.html",
result,
nil,
)

View File

@@ -9,20 +9,38 @@ import (
"github.com/jritsema/gotoolbox/web"
)
func Items(_html *template.Template) *Router {
type ItemActions struct {
Get func(r *http.Request) *web.Response
GetAll func(r *http.Request) *web.Response
Edit func(r *http.Request) *web.Response
Delete func(r *http.Request) *web.Response
Save func(r *http.Request) *web.Response
Post func(r *http.Request) *web.Response
Add func(r *http.Request) *web.Response
}
func Items(_html *template.Template) *ItemActions {
html = _html
return NewRouter(
Item,
"/items",
RouterActions{
GetAll: GetAllItems,
GetByID: nil,
Post: nil,
Put: nil,
Delete: nil,
},
)
return &ItemActions{
Get: Get,
GetAll: GetAllItems,
Edit: EditItem,
Delete: Delete,
Save: Put,
Post: Post,
Add: Add,
}
}
func Get(r *http.Request) *web.Response {
_, count := web.PathLast(r)
if count == 1 {
return GetAllItems(r)
} else {
return GetItemByID(r)
}
}
func GetAllItems(_ *http.Request) *web.Response {
@@ -34,20 +52,21 @@ func GetAllItems(_ *http.Request) *web.Response {
return web.HTML(
http.StatusOK,
html,
"entity-list.html",
"items/entity-list.html",
result,
nil,
)
}
func GetItemByID(r *http.Request) *web.Response {
var id int
id, err := strconv.Atoi(r.URL.Query().Get("id"))
func EditItem(r *http.Request) *web.Response {
idFromPath, _ := web.PathLast(r)
id, err := strconv.ParseInt(idFromPath, 10, 64)
if err != nil {
return web.Error(http.StatusBadRequest, err, nil)
}
result, err := db.GetItemByID(id)
result, err := db.GetItemByID(int(id))
if err != nil {
return web.Error(http.StatusInternalServerError, err, nil)
@@ -56,8 +75,168 @@ func GetItemByID(r *http.Request) *web.Response {
return web.HTML(
http.StatusOK,
html,
"item-by-id.html",
"items/entity-edit.html",
result,
nil,
)
}
func GetItemByID(r *http.Request) *web.Response {
idFromPath, _ := web.PathLast(r)
id, err := strconv.ParseInt(idFromPath, 10, 64)
if err != nil {
return web.Error(http.StatusBadRequest, err, nil)
}
result, err := db.GetItemByID(int(id))
if err != nil {
return web.Error(http.StatusInternalServerError, err, nil)
}
return web.HTML(
http.StatusOK,
html,
"items/entity-row.html",
result,
nil,
)
}
func Put(r *http.Request) *web.Response {
id, _ := web.PathLast(r)
if err := r.ParseForm(); err != nil {
return web.Error(http.StatusBadRequest, err, nil)
}
if r.Form.Get("category") == "" {
panic(r.Form.Get(""))
}
if r.Form.Get("stage") == "" {
panic(r.Form.Get(""))
}
name := r.Form.Get("name")
stage := r.Form.Get("stage")
category := r.Form.Get("category")
description := r.Form.Get("description")
notes := r.Form.Get("notes")
// id := r.Form.Get("id")
item := db.Item{
ID: func() int {
idInt, err := strconv.ParseInt(id, 10, 64)
if err != nil {
return -1
}
return int(idInt)
}(),
Name: name,
Description: &description,
Notes: &notes,
Stage: func() db.PackingStage {
stageInt, _ := strconv.Atoi(stage)
return db.PackingStage(stageInt)
}(),
Category: func() db.Category {
categoryInt, _ := strconv.Atoi(category)
return db.Category(categoryInt)
}(),
}
if _, err := db.PutItem(item); err != nil {
return web.Error(http.StatusInternalServerError, err, nil)
}
return web.HTML(
http.StatusOK,
html,
"items/entity-row.html",
item,
nil,
)
}
func Post(r *http.Request) *web.Response {
err := r.ParseForm()
if err != nil {
return web.Error(http.StatusBadRequest, err, nil)
}
name := r.Form.Get("name")
stage := r.Form.Get("stage")
category := r.Form.Get("category")
description := r.Form.Get("description")
notes := r.Form.Get("notes")
item := db.Item{
Name: name,
Description: &description,
Notes: &notes,
Stage: func() db.PackingStage {
stageInt, _ := strconv.Atoi(stage)
return db.PackingStage(stageInt)
}(),
Category: func() db.Category {
categoryInt, _ := strconv.Atoi(category)
return db.Category(categoryInt)
}(),
}
_, err = db.PostItem(item)
if err != nil {
return web.Error(http.StatusInternalServerError, err, nil)
}
return web.HTML(
http.StatusOK,
html,
"items/entity-add-success.html",
item,
nil,
)
}
func Add(r *http.Request) *web.Response {
return web.HTML(
http.StatusOK,
html,
"items/items/entity-add.html",
nil,
nil,
)
}
func Delete(r *http.Request) *web.Response {
idFromPath, _ := web.PathLast(r)
id, err := strconv.ParseInt(idFromPath, 10, 64)
if err != nil {
return web.Error(http.StatusBadRequest, err, nil)
}
_, err = db.DeleteItem(int(id))
if err != nil {
return web.Error(http.StatusInternalServerError, err, nil)
}
return web.HTML(
http.StatusOK,
html,
"items/entity-row.html",
nil,
nil,
)
}

0
scripts/index.js Normal file
View File

View File

@@ -0,0 +1,23 @@
<tr class="box-item-list">
<td>
<table>
<thead>
<tr>
<th scope="col" class="px-6 py-4"></th>
<th scope="col" class="px-6 py-4">#</th>
<th scope="col" class="px-6 py-4">Name</th>
<th scope="col" class="px-6 py-4">Stage</th>
<th scope="col" class="px-6 py-4">Category</th>
<th scope="col" class="px-6 py-4">Description</th>
<th scope="col" class="px-6 py-4">Notes</th>
<th scope="col" class="px-6 py-4"></th>
</tr>
</thead>
<tbody id="table-body">
{{range .}}
{{ template "box-items/box-item-row.html" . }}
{{end}}
</tbody>
</table>
</td>
</tr>

View File

@@ -0,0 +1,10 @@
<tr class="box-item-row border-b dark:border-neutral-500 hover:bg-slate-300 hover:bg-opacity-20">
<td class="whitespace-nowrap px-6 py-4">{{ .ID }}</td>
<td class="whitespace-nowrap px-6 py-4">{{ .Name }}</td>
{{ template "components/parsed-packing-stage.html" .Stage }}
{{ template "components/parsed-category.html" .Category }}
<td class="whitespace-nowrap px-6 py-4">{{ .Description }}</td>
<td class="whitespace-nowrap px-6 py-4">{{ .Notes }}</td>
</tr>

View File

@@ -1,35 +1,25 @@
<div id="box-list">
<div id="boxes/box-list">
<div id="processing" class="htmx-indicator">Processing...</div>
<div class="flex flex-col">
<div class="overflow-x-auto sm:-mx-6 lg:-mx-8">
<div class="inline-block min-w-full py-2 sm:px-6 lg:px-8">
<div class="overflow-hidden">
<!-- <div class="flex justify-end">
<button
hx-get="/company/add"
hx-target="#table-body"
hx-swap="outerHTML"
hx-indicator="#processing"
class="inline-flex items-center h-8 px-4 m-2 text-sm text-blue-100 transition-colors duration-150 bg-blue-700 rounded-lg focus:shadow-outline hover:bg-blue-800"
href=""
>
Add
</button>
</div> -->
<table class="min-w-full text-left text-sm font-light">
<thead class="border-b font-medium dark:border-neutral-500">
<tr>
<th scope="col" class="px-6 py-4"></th>
<th scope="col" class="px-6 py-4">#</th>
<th scope="col" class="px-6 py-4">Name</th>
<th scope="col" class="px-6 py-4">Stage</th>
<th scope="col" class="px-6 py-4">Category</th>
<th scope="col" class="px-6 py-4">Description</th>
<th scope="col" class="px-6 py-4">Notes</th>
<th scope="col" class="px-6 py-4"></th>
</tr>
</thead>
<tbody id="table-body">
{{range .}}
{{ template "entity-row.html". }}
{{ template "boxes/box-row.html" . }}
{{end}}
</tbody>
</table>

View File

@@ -0,0 +1,40 @@
<tr id="boxrow-{{.ID}}" class="border-b dark:border-neutral-500 hover:bg-slate-300 hover:bg-opacity-20">
<td class="whitespace-nowrap px-6 py-4">
<button
hx-get="/box-items?boxid={{ .ID }}"
hx-target="#boxrow-{{ .ID }}"
hx-swap="afterend"
class="inline-flex items-center h-8 px-4 m-2 text-sm text-stone-100 transition-colors duration-150 bg-stone-700 rounded-lg focus:shadow-outline hover:bg-stone-800"
>
&gt;
</button>
</td>
<td class="whitespace-nowrap px-6 py-4">{{.ID}}</td>
<td class="whitespace-nowrap px-6 py-4">{{.Name}}</td>
{{ template "components/parsed-packing-stage.html" .ID }}
{{ template "components/parsed-category.html" .ID }}
{{ if .Description }}
<td class="whitespace-nowrap px-6 py-4">{{.Description}}</td>
{{ else }}
<td class="whitespace-nowrap px-6 py-4">...</td>
{{ end }}
{{ if .Notes }}
<td class="whitespace-nowrap px-6 py-4">{{.Notes}}</td>
{{ else }}
<td class="whitespace-nowrap px-6 py-4">...</td>
{{ end }}
<td class="whitespace-nowrap px-6 py-4">
<button
hx-get="/items/edit/{{ .ID }}"
hx-target="#boxrow-{{ .ID }}"
hx-swap="outerHTML"
class="inline-flex items-center h-8 px-4 m-2 text-sm text-yellow-100 transition-colors duration-150 bg-yellow-700 rounded-lg focus:shadow-outline hover:bg-yellow-800"
>
Edit
</button>
</tr>

View File

@@ -1,38 +0,0 @@
<div id="companies">
<div id="processing" class="htmx-indicator">Processing...</div>
<div class="flex flex-col">
<div class="overflow-x-auto sm:-mx-6 lg:-mx-8">
<div class="inline-block min-w-full py-2 sm:px-6 lg:px-8">
<div class="overflow-hidden">
<div class="flex justify-end">
<button
hx-get="/company/add"
hx-target="#table-body"
hx-swap="outerHTML"
hx-indicator="#processing"
class="inline-flex items-center h-8 px-4 m-2 text-sm text-blue-100 transition-colors duration-150 bg-blue-700 rounded-lg focus:shadow-outline hover:bg-blue-800"
href=""
>
Add
</button>
</div>
<table class="min-w-full text-left text-sm font-light">
<thead class="border-b font-medium dark:border-neutral-500">
<tr>
<th scope="col" class="px-6 py-4">#</th>
<th scope="col" class="px-6 py-4">Company</th>
<th scope="col" class="px-6 py-4">Contact</th>
<th scope="col" class="px-6 py-4">Country</th>
</tr>
</thead>
<tbody id="table-body">
{{range .}}
{{ template "row.html". }}
{{end}}
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>

View File

@@ -1,6 +0,0 @@
<tbody id="table-body">
{{ template "row-add.html" . }}
{{range .}}
{{ template "row.html". }}
{{end}}
</tbody>

View File

@@ -0,0 +1,8 @@
<select class="data-input-NEW_ITEM_ROW" id="category-selector-NEW_ITEM_ROW" data-include-edit="NEW_ITEM_ROW" name="category">
<option value="0">Bedroom</option>
<option value="1">Bathroom</option>
<option value="2">Kitchen</option>
<option value="3">Office</option>
<option value="4">Living Room</option>
<option value="5">Other</option>
</select>

View File

@@ -0,0 +1,7 @@
<select class="data-input-NEW_ITEM_ROW" id="packing-stage-selector-NEW_ITEM_ROW" data-include-edit="NEW_ITEM_ROW" name="stage">
<option value="0">Essentials</option>
<option value="1">Stage One</option>
<option value="2">Stage Two</option>
<option value="3">Stage Three</option>
<option value="4">Determine Later</option>
</select>

View File

@@ -0,0 +1,8 @@
<select class="data-input-{{.ID}}" id="category-selector-{{.ID}}" data-include-edit="{{.ID}}" value="{{.Category}}" name="category">
<option value="0">Bedroom</option>
<option value="1">Bathroom</option>
<option value="2">Kitchen</option>
<option value="3">Office</option>
<option value="4">Living Room</option>
<option value="5">Other</option>
</select>

View File

@@ -0,0 +1,7 @@
<select class="data-input-{{.ID}}" id="packing-stage-selector-{{.ID}}" data-include-edit="{{.ID}}" value="{{.Stage}}" name="stage">
<option value="0">Essentials</option>
<option value="1">Stage One</option>
<option value="2">Stage Two</option>
<option value="3">Stage Three</option>
<option value="4">Determine Later</option>
</select>

View File

@@ -0,0 +1,27 @@
<td class="whitespace-nowrap px-6 py-4">
{{ if eq . 0 }}
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-purple-100 text-purple-800">
Bedroom
</span>
{{ else if eq . 1 }}
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-cyan-100 text-cyan-800">
Bathroom
</span>
{{ else if eq . 2 }}
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-orange-100 text-orange-800">
Kitchen
</span>
{{ else if eq . 3 }}
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-rose-100 text-rose-800">
Office
</span>
{{ else if eq . 4 }}
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-indigo-100 text-indigo-800">
Living Room
</span>
{{ else }}
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-gray-100 text-gray-800">
Other
</span>
{{ end }}
</td>

View File

@@ -0,0 +1,23 @@
<td class="whitespace-nowrap px-6 py-4">
{{ if eq . 0 }}
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-red-100 text-red-800">
Essentials
</span>
{{ else if eq . 1 }}
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-cyan-100 text-cyan-800">
Stage One
</span>
{{ else if eq . 2 }}
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-purple-100 text-purple-800">
Stage Two
</span>
{{ else if eq . 3 }}
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-stone-100 text-stone-800">
Stage Three
</span>
{{ else }}
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-amber-100 text-amber-800">
Determine Later
</span>
{{ end }}
</td>

View File

@@ -1,8 +0,0 @@
<tr id="datarow-{{.ID}}" class="border-b dark:border-neutral-500">
<td class="whitespace-nowrap px-6 py-4">{{.ID}}</td>
<td class="whitespace-nowrap px-6 py-4">{{.Name}}</td>
<td class="whitespace-nowrap px-6 py-4">{{.Stage}}</td>
<td class="whitespace-nowrap px-6 py-4">{{.Category}}</td>
<td class="whitespace-nowrap px-6 py-4">{{.Description}}</td>
<td class="whitespace-nowrap px-6 py-4">{{.Notes}}</td>
</tr>

View File

@@ -4,13 +4,13 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Mikayla's Move Manager</title>
<script src="https://unpkg.com/htmx.org@1.9.2"></script>
<link href="/css/output.css" rel="stylesheet" />
<title>Go + HTMX + Tailwind</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body>
<main>
<div class="md:container md:mx-auto">
<div class="md:container md:mx-auto w-full max-w-screen">
<h1 class="text-3xl">Mikayla's Move Manager</h1>
<nav>
@@ -18,6 +18,7 @@
hx-get="/items"
hx-target="#home-page-container"
hx-swap="innerHTML"
onclick="handleLabelUpdate"
class="inline-flex items-center h-8 px-4 m-2 text-sm text-blue-100 transition-colors duration-150 bg-blue-700 rounded-lg focus:shadow-outline hover:bg-blue-800"
>
Items
@@ -26,6 +27,7 @@
hx-get="/boxes"
hx-target="#home-page-container"
hx-swap="innerHTML"
onclick="handleLabelUpdate"
class="inline-flex items-center h-8 px-4 m-2 text-sm text-blue-100 transition-colors duration-150 bg-blue-700 rounded-lg focus:shadow-outline hover:bg-blue-800"
>
Boxes
@@ -34,11 +36,18 @@
</nav>
<br/>
<span class="text-xl">Items</span>
<span id="page-label" class="text-xl">Items</span>
<div id="home-page-container">
{{ template "entity-list.html" . }}
{{ template "items/entity-list.html" . }}
</div>
</div>
</main>
<script>
function handleLabelUpdate() {
const prev = document.getElementById('page-label').innerText;
document.getElementById('page-label').innerText = prev === 'Items' ? 'Boxes' : 'Items';
}
</script>
</body>
</html>

View File

@@ -0,0 +1,2 @@
{{ template "items/entity-row.html" . }}
{{ template "items/entity-add.html" }}

View File

@@ -0,0 +1,52 @@
<tr id="datarow-NEW_ITEM_ROW" class="datarow border-b dark:border-neutral-500">
<td class="whitespace-nowrap px-6 py-4">
<!-- <input hidden disabled type="text" name="id" value="NEW_ITEM_ROW" data-include-edit="NEW_ITEM_ROW" />
<span>NEW_ITEM_ROW</span> -->
</td>
<td class="whitespace-nowrap px-6 py-4">
<input
placeholder="Item name"
type="text"
class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline"
data-include-edit="NEW_ITEM_ROW"
name="name"
/>
</td>
<td class="whitespace-nowrap px-6 py-4">
{{ template "components/add-packing-stage.html" }}
</td>
<td class="whitespace-nowrap px-6 py-4">
{{ template "components/add-category.html" }}
</td>
<td class="whitespace-nowrap px-6 py-4">
<input
type="text"
placeholder="Short description"
class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline"
data-include-edit="NEW_ITEM_ROW"
name="description"
/>
</td>
<td class="whitespace-nowrap px-6 py-4">
<input
type="text"
placeholder="Notes"
class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline"
data-include-edit="NEW_ITEM_ROW"
name="notes"
/>
<td class="whitespace-nowrap px-1 py-1">
<a
id="add-new-item-button-NEW_ITEM_ROW"
hx-post="/items/add"
hx-target="#datarow-NEW_ITEM_ROW"
hx-swap="outerHTML"
hx-indicator="#processing"
hx-include="[data-include-edit='NEW_ITEM_ROW']"
class="inline-flex items-center h-8 px-4 m-2 text-sm text-blue-100 transition-colors duration-150 bg-blue-700 rounded-lg focus:shadow-outline hover:bg-blue-800"
href=""
>Add</a
>
</td>
</tr>

View File

@@ -0,0 +1,80 @@
<tr id="datarow-{{.ID}}" class="datarow w-full border-b dark:border-neutral-500">
<td id="datarow-{{.ID}}-id" class="hidden md:flex whitespace-nowrap px-6 py-4 w-1/12">
<input class="data-input-{{.ID}}" hidden disabled type="text" name="id" value="{{.ID}}" data-include-edit="{{.ID}}" />
<span>{{.ID}}</span>
</td>
<td id="datarow-{{.ID}}-name" class="whitespace-nowrap px-6 py-4 w-1/4 md:w-1/6">
<input
type="text"
class="data-input-{{.ID}} shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline"
data-include-edit="{{.ID}}"
name="name"
value="{{.Name}}"
/>
</td>
<td id="datarow-{{.ID}}-stage" class="whitespace-nowrap px-6 py-4 w-1/4 md:w-1/6">
{{ template "components/edit-packing-stage.html" . }}
</td>
<td id="datarow-{{.ID}}-category" class="whitespace-nowrap px-6 py-4 w-1/4 md:w-1/6">
{{ template "components/edit-category.html" . }}
</td>
<td id="datarow-{{.ID}}-description" class="hidden md:flex px-6 py-4 w-1/6">
<input
type="text"
class="data-input-{{.ID}} shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline"
data-include-edit="{{.ID}}"
name="description"
value="{{.Description}}"
/>
</td>
<td id="datarow-{{.ID}}-notes" class="hidden md:flex px-6 py-4 w-1/6">
<input
type="text"
class="data-input-{{.ID}} shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline"
data-include-edit="{{.ID}}"
name="notes"
value="{{.Notes}}"
/>
<td id="datarow-{{.ID}}-actions" class="whitespace-nowrap flex items-end px-1 py-1 w-1/4 md:w-1/12">
<a
id="datarow-{{.ID}}-save"
hx-put="/items/save/{{.ID}}"
hx-target="#datarow-{{.ID}}"
hx-swap="outerHTML"
hx-indicator="#processing"
hx-include=".data-input-{{.ID}}"
class="inline-flex items-center h-8 px-4 m-2 text-sm text-blue-100 transition-colors duration-150 bg-blue-700 rounded-lg focus:shadow-outline hover:bg-blue-800"
href=""
>Save</a
>
<a
hx-get="/items/{{.ID}}"
hx-target="#datarow-{{.ID}}"
hx-swap="outerHTML"
hx-indicator="#processing"
class="inline-flex items-center h-8 px-4 m-2 text-sm text-red-100 transition-colors duration-150 bg-red-700 rounded-lg focus:shadow-outline hover:bg-red-800"
href=""
>Cancel</a
>
</td>
<script>
window.addEventListener("keydown", (e) => {
/** @typedef KeyboardEvent */
const target = e.target;
if (e.target.key == "Enter") {
const a = document.getElementById("datarow-{{.ID}}-save");
void a.click();
}
})
document.getElementById("category-selector-{{.ID}}").onchange = (e) => {
console.log(e.target.value);
}
document.getElementById("packing-stage-selector-{{.ID}}").onchange = (e) => {
console.log(e.target.value);
}
</script>
</tr>

View File

@@ -4,18 +4,6 @@
<div class="overflow-x-auto sm:-mx-6 lg:-mx-8">
<div class="inline-block min-w-full py-2 sm:px-6 lg:px-8">
<div class="overflow-hidden">
<!-- <div class="flex justify-end">
<button
hx-get="/company/add"
hx-target="#table-body"
hx-swap="outerHTML"
hx-indicator="#processing"
class="inline-flex items-center h-8 px-4 m-2 text-sm text-blue-100 transition-colors duration-150 bg-blue-700 rounded-lg focus:shadow-outline hover:bg-blue-800"
href=""
>
Add
</button>
</div> -->
<table class="min-w-full text-left text-sm font-light">
<thead class="border-b font-medium dark:border-neutral-500">
<tr>
@@ -25,12 +13,15 @@
<th scope="col" class="px-6 py-4">Category</th>
<th scope="col" class="px-6 py-4">Description</th>
<th scope="col" class="px-6 py-4">Notes</th>
<th scope="col" class="px-6 py-4"></th>
</tr>
</thead>
<tbody id="table-body">
{{range .}}
{{ template "entity-row.html". }}
{{ template "items/entity-row.html" . }}
{{end}}
{{ template "items/entity-add.html" . }}
</tbody>
</table>
</div>

View File

@@ -0,0 +1,46 @@
<tr id="datarow-{{.ID}}" class="border-b dark:border-neutral-500 hover:bg-slate-300 hover:bg-opacity-20">
<td class="whitespace-nowrap items-center justify-center w-1/12">{{.ID}}</td>
<td class="whitespace-nowrap px-6 py-4 w-1/6">{{.Name}}</td>
<td class="whitespace-nowrap px-6 py-4 w-1/6">
{{ template "components/parsed-packing-stage.html" .Stage }}
</td>
<td class="whitespace-nowrap px-6 py-4 w-1/6">
{{ template "components/parsed-category.html" .Category }}
</td>
{{ if .Description }}
<td class="w-1/6 px-6 py-4 ">{{.Description}}</td>
{{ else }}
<td class="w-1/6 px-6 py-4 ">...</td>
{{ end }}
{{ if .Notes }}
<td class="w-1/6 px-6 py-4 ">{{.Notes}}</td>
{{ else }}
<td class="w-1/6 px-6 py-4 ">...</td>
{{ end }}
<td class="whitespace-nowrap px-6 py-4 w-1/12">
<button
hx-get="/items/edit/{{ .ID }}"
hx-target="#datarow-{{ .ID }}"
hx-swap="outerHTML"
class="inline-flex items-center h-8 px-4 m-2 text-sm text-yellow-100 transition-colors duration-150 bg-yellow-700 rounded-lg focus:shadow-outline hover:bg-yellow-800"
>
Edit
</button>
<button
hx-delete="/items/delete/{{ .ID }}"
hx-confirm="Are you sure?"
hx-target="#datarow-{{ .ID }}"
hx-swap="delete"
class="inline-flex items-center h-8 px-4 m-2 text-sm text-red-100 transition-colors duration-150 bg-red-700 rounded-lg focus:shadow-outline hover:bg-red-800"
>
Delete
</button>
</td>
</tr>

View File

@@ -1,51 +0,0 @@
<tr id="datarow-add" class="border-b dark:border-neutral-500">
<td class="whitespace-nowrap px-6 py-4"></td>
<td class="whitespace-nowrap px-6 py-4">
<input
type="text"
class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline"
data-include-add=""
name="company"
value=""
/>
</td>
<td class="whitespace-nowrap px-6 py-4">
<input
type="text"
class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline"
data-include-add=""
name="contact"
value=""
/>
</td>
<td class="whitespace-nowrap px-6 py-4">
<input
type="text"
class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline"
data-include-add=""
name="country"
value=""
/>
</td>
<td class="whitespace-nowrap px-1 py-1">
<a
hx-post="/company/"
hx-target="#companies"
hx-indicator="#processing"
hx-include="input[data-include-add]"
class="inline-flex items-center h-8 px-4 m-2 text-sm text-blue-100 transition-colors duration-150 bg-blue-700 rounded-lg focus:shadow-outline hover:bg-blue-800"
href=""
>Save</a
>
</td>
<td class="whitespace-nowrap px-1 py-1">
<a
hx-get="/company/"
hx-target="#companies"
hx-indicator="#processing"
class="inline-flex items-center h-8 px-4 m-2 text-sm text-red-100 transition-colors duration-150 bg-red-700 rounded-lg focus:shadow-outline hover:bg-red-800"
href=""
>Cancel</a
>
</td>
</tr>

View File

@@ -1,53 +0,0 @@
<tr id="datarow-{{.ID}}" class="border-b dark:border-neutral-500">
<td class="whitespace-nowrap px-6 py-4">{{.ID}}</td>
<td class="whitespace-nowrap px-6 py-4">
<input
type="text"
class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline"
data-include-edit="{{.ID}}"
name="company"
value="{{.Company}}"
/>
</td>
<td class="whitespace-nowrap px-6 py-4">
<input
type="text"
class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline"
data-include-edit="{{.ID}}"
name="contact"
value="{{.Contact}}"
/>
</td>
<td class="whitespace-nowrap px-6 py-4">
<input
type="text"
class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline"
data-include-edit="{{.ID}}"
name="country"
value="{{.Country}}"
/>
</td>
<td class="whitespace-nowrap px-1 py-1">
<a
hx-put="/company/{{.ID}}"
hx-target="#datarow-{{.ID}}"
hx-swap="outerHTML"
hx-indicator="#processing"
hx-include="input[data-include-edit='{{.ID}}']"
class="inline-flex items-center h-8 px-4 m-2 text-sm text-blue-100 transition-colors duration-150 bg-blue-700 rounded-lg focus:shadow-outline hover:bg-blue-800"
href=""
>Save</a
>
</td>
<td class="whitespace-nowrap px-1 py-1">
<a
hx-get="/company/{{.ID}}"
hx-target="#datarow-{{.ID}}"
hx-swap="outerHTML"
hx-indicator="#processing"
class="inline-flex items-center h-8 px-4 m-2 text-sm text-red-100 transition-colors duration-150 bg-red-700 rounded-lg focus:shadow-outline hover:bg-red-800"
href=""
>Cancel</a
>
</td>
</tr>

View File

@@ -1,29 +0,0 @@
<tr id="datarow-{{.ID}}" class="border-b dark:border-neutral-500">
<td class="whitespace-nowrap px-6 py-4">{{.ID}}</td>
<td class="whitespace-nowrap px-6 py-4">{{.Company}}</td>
<td class="whitespace-nowrap px-6 py-4">{{.Contact}}</td>
<td class="whitespace-nowrap px-6 py-4">{{.Country}}</td>
<td class="whitespace-nowrap px-1 py-1">
<a
hx-get="/company/edit/{{.ID}}"
hx-target="#datarow-{{.ID}}"
hx-swap="outerHTML"
hx-indicator="#processing"
class="hover:underline text-blue-700"
href=""
>
Edit
</a>
</td>
<td class="whitespace-nowrap px-1 py-1">
<a
hx-delete="/company/{{.ID}}"
hx-target="#companies"
hx-confirm="Are you sure you want to delete {{.Company}}?"
hx-indicator="#processing"
class="hover:underline text-blue-700"
href=""
>Delete</a
>
</td>
</tr>