Compare commits
2 Commits
78731c1728
...
1a0797ef19
| Author | SHA1 | Date | |
|---|---|---|---|
|
1a0797ef19
|
|||
|
0a44df319d
|
110
frontend/assets/css/style.css
Normal file
110
frontend/assets/css/style.css
Normal file
@@ -0,0 +1,110 @@
|
||||
:root {
|
||||
--bg: #111827;
|
||||
--card: #1f2937;
|
||||
--border: #374151;
|
||||
--text: #f9fafb;
|
||||
--accent: #3b82f6;
|
||||
}
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
font-family: system-ui;
|
||||
}
|
||||
|
||||
nav {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
|
||||
padding: 1rem;
|
||||
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
|
||||
nav a {
|
||||
color: white;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
main {
|
||||
max-width: 1400px;
|
||||
|
||||
margin: auto;
|
||||
|
||||
padding: 2rem;
|
||||
}
|
||||
|
||||
.cards {
|
||||
display: grid;
|
||||
|
||||
grid-template-columns:
|
||||
repeat(auto-fit,minmax(250px,1fr));
|
||||
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.card {
|
||||
background: var(--card);
|
||||
|
||||
border: 1px solid var(--border);
|
||||
|
||||
border-radius: 12px;
|
||||
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
th,
|
||||
td {
|
||||
padding: 1rem;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
tr {
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
|
||||
input,
|
||||
select,
|
||||
button {
|
||||
|
||||
background: #1f2937;
|
||||
|
||||
color: white;
|
||||
|
||||
border: 1px solid var(--border);
|
||||
|
||||
border-radius: 8px;
|
||||
|
||||
padding: .8rem;
|
||||
}
|
||||
|
||||
button {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
background: var(--accent);
|
||||
}
|
||||
|
||||
@media(max-width:768px){
|
||||
|
||||
nav{
|
||||
flex-wrap:wrap;
|
||||
}
|
||||
|
||||
table{
|
||||
display:block;
|
||||
overflow:auto;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,10 +5,14 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var dashbaord = template.Must(template.ParseFiles(
|
||||
"frontend/htmx/contents/dash/base.html",
|
||||
"frontend/htmx/contents/dash/dashboard.html"))
|
||||
var home = template.Must(template.ParseFiles("frontend/htmx/home.html"))
|
||||
|
||||
func Home(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
var tmpl = template.Must(template.ParseFiles("frontend/htmx/home.html"))
|
||||
err := tmpl.Execute(w, struct {
|
||||
err := home.Execute(w, struct {
|
||||
Name string
|
||||
}{
|
||||
Name: "Miau",
|
||||
@@ -17,3 +21,15 @@ func Home(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func Dashboard(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
err := dashbaord.Execute(w, struct {
|
||||
Title string
|
||||
}{
|
||||
Title: "Miau",
|
||||
})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
27
frontend/htmx/contents/dash/base.html
Normal file
27
frontend/htmx/contents/dash/base.html
Normal file
@@ -0,0 +1,27 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{{ .Title }}</title>
|
||||
|
||||
<script src="https://unpkg.com/htmx.org@2.0.4"></script>
|
||||
|
||||
<link rel="stylesheet" href="/static/css/app.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<nav>
|
||||
<a href="/dashboard">Dashboard</a>
|
||||
<a href="/items">Inventar</a>
|
||||
<a href="/projects">Projekte</a>
|
||||
<a href="/locations">Orte</a>
|
||||
</nav>
|
||||
|
||||
<main>
|
||||
{{ template "content" . }}
|
||||
</main>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
24
frontend/htmx/contents/dash/dashboard.html
Normal file
24
frontend/htmx/contents/dash/dashboard.html
Normal file
@@ -0,0 +1,24 @@
|
||||
{{ define "content" }}
|
||||
|
||||
<h1>Dashboard</h1>
|
||||
|
||||
<div class="cards">
|
||||
|
||||
<div class="card">
|
||||
<h2>{{ .Stats.Items }}</h2>
|
||||
<p>Items</p>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<h2>{{ .Stats.Projects }}</h2>
|
||||
<p>Projekte</p>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<h2>{{ .Stats.Locations }}</h2>
|
||||
<p>Orte</p>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
{{ end }}
|
||||
21
frontend/htmx/contents/dash/inventory.html
Normal file
21
frontend/htmx/contents/dash/inventory.html
Normal file
@@ -0,0 +1,21 @@
|
||||
{{ define "content" }}
|
||||
|
||||
<h1>Inventar</h1>
|
||||
|
||||
<input
|
||||
type="search"
|
||||
name="q"
|
||||
placeholder="Suchen..."
|
||||
hx-get="/api/items/search"
|
||||
hx-trigger="keyup changed delay:300ms"
|
||||
hx-target="#items"
|
||||
>
|
||||
|
||||
<div
|
||||
id="items"
|
||||
hx-get="/api/items"
|
||||
hx-trigger="load"
|
||||
>
|
||||
</div>
|
||||
|
||||
{{ end }}
|
||||
32
frontend/htmx/contents/dash/itemlist.html
Normal file
32
frontend/htmx/contents/dash/itemlist.html
Normal file
@@ -0,0 +1,32 @@
|
||||
<table>
|
||||
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Kategorie</th>
|
||||
<th>Gesamt</th>
|
||||
<th>Frei</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
|
||||
{{ range . }}
|
||||
|
||||
<tr>
|
||||
|
||||
<td>{{ .Name }}</td>
|
||||
|
||||
<td>{{ .Category }}</td>
|
||||
|
||||
<td>{{ .TotalQuantity }}</td>
|
||||
|
||||
<td>{{ .FreeQuantity }}</td>
|
||||
|
||||
</tr>
|
||||
|
||||
{{ end }}
|
||||
|
||||
</tbody>
|
||||
|
||||
</table>
|
||||
11
frontend/htmx/contents/dash/locations.html
Normal file
11
frontend/htmx/contents/dash/locations.html
Normal file
@@ -0,0 +1,11 @@
|
||||
{{ define "content" }}
|
||||
|
||||
<h1>Lagerorte</h1>
|
||||
|
||||
<div
|
||||
hx-get="/api/locations"
|
||||
hx-trigger="load"
|
||||
>
|
||||
</div>
|
||||
|
||||
{{ end }}
|
||||
21
frontend/htmx/contents/dash/projects.html
Normal file
21
frontend/htmx/contents/dash/projects.html
Normal file
@@ -0,0 +1,21 @@
|
||||
{{ define "content" }}
|
||||
|
||||
<h1>Projekte</h1>
|
||||
|
||||
<button
|
||||
hx-get="/projects/new"
|
||||
hx-target="#modal"
|
||||
>
|
||||
Neues Projekt
|
||||
</button>
|
||||
|
||||
<div
|
||||
hx-get="/api/projects"
|
||||
hx-trigger="load"
|
||||
hx-target="this"
|
||||
>
|
||||
</div>
|
||||
|
||||
<div id="modal"></div>
|
||||
|
||||
{{ end }}
|
||||
41
handlers/items.go
Normal file
41
handlers/items.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"MiauInv/models"
|
||||
"MiauInv/storage"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func GetItems(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
items, err := storage.GetItems()
|
||||
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), 500)
|
||||
return
|
||||
}
|
||||
|
||||
json.NewEncoder(w).Encode(items)
|
||||
}
|
||||
|
||||
func CreateItem(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var item models.Item
|
||||
|
||||
err := json.NewDecoder(r.Body).Decode(&item)
|
||||
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), 400)
|
||||
return
|
||||
}
|
||||
|
||||
err = storage.AddItem(item)
|
||||
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), 500)
|
||||
return
|
||||
}
|
||||
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
}
|
||||
20
handlers/locations.go
Normal file
20
handlers/locations.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"MiauInv/storage"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func CreateLocation(w http.ResponseWriter, r *http.Request) {
|
||||
name := r.FormValue("name")
|
||||
|
||||
_, err := storage.DB.Exec(
|
||||
"INSERT INTO locations(name) VALUES(?)",
|
||||
name,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), 500)
|
||||
return
|
||||
}
|
||||
}
|
||||
34
handlers/project_items.go
Normal file
34
handlers/project_items.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"MiauInv/storage"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ProjectItemRequest struct {
|
||||
ItemID int `json:"item_id"`
|
||||
ProjectID int `json:"project_id"`
|
||||
Quantity int `json:"quantity"`
|
||||
}
|
||||
|
||||
func AllocateToProject(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var req ProjectItemRequest
|
||||
|
||||
json.NewDecoder(r.Body).Decode(&req)
|
||||
|
||||
_, err := storage.DB.Exec(`
|
||||
INSERT INTO project_items(item_id,project_id,quantity)
|
||||
VALUES(?,?,?)
|
||||
`,
|
||||
req.ItemID,
|
||||
req.ProjectID,
|
||||
req.Quantity,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), 500)
|
||||
return
|
||||
}
|
||||
}
|
||||
21
handlers/projects.go
Normal file
21
handlers/projects.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"MiauInv/storage"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func CreateProject(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
name := r.FormValue("name")
|
||||
|
||||
_, err := storage.DB.Exec(
|
||||
"INSERT INTO projects(name) VALUES(?)",
|
||||
name,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), 500)
|
||||
return
|
||||
}
|
||||
}
|
||||
34
handlers/stock.go
Normal file
34
handlers/stock.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"MiauInv/storage"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type StockRequest struct {
|
||||
ItemID int `json:"item_id"`
|
||||
LocationID int `json:"location_id"`
|
||||
Quantity int `json:"quantity"`
|
||||
}
|
||||
|
||||
func AddStock(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var req StockRequest
|
||||
|
||||
json.NewDecoder(r.Body).Decode(&req)
|
||||
|
||||
_, err := storage.DB.Exec(`
|
||||
INSERT INTO stock(item_id,location_id,quantity)
|
||||
VALUES(?,?,?)
|
||||
`,
|
||||
req.ItemID,
|
||||
req.LocationID,
|
||||
req.Quantity,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), 500)
|
||||
return
|
||||
}
|
||||
}
|
||||
34
models/inventory.go
Normal file
34
models/inventory.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package models
|
||||
|
||||
type Item struct {
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Category string `json:"category"`
|
||||
Description string `json:"description"`
|
||||
TotalQuantity int `json:"total_quantity"`
|
||||
}
|
||||
|
||||
type Location struct {
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type Project struct {
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
type Stock struct {
|
||||
ID int `json:"id"`
|
||||
ItemID int `json:"item_id"`
|
||||
LocationID int `json:"location_id"`
|
||||
Quantity int `json:"quantity"`
|
||||
}
|
||||
|
||||
type ProjectItem struct {
|
||||
ID int `json:"id"`
|
||||
ItemID int `json:"item_id"`
|
||||
ProjectID int `json:"project_id"`
|
||||
Quantity int `json:"quantity"`
|
||||
}
|
||||
@@ -58,6 +58,7 @@ func (this *Server) Run() {
|
||||
// FRONTEND
|
||||
//
|
||||
mux.HandleFunc("/", frontend.Home)
|
||||
mux.HandleFunc("/dashboard", frontend.Dashboard)
|
||||
|
||||
//
|
||||
// API
|
||||
@@ -69,6 +70,13 @@ func (this *Server) Run() {
|
||||
mux.HandleFunc("/api/refresh", handlers.RefreshToken)
|
||||
mux.HandleFunc("/api/logout", handlers.Logout)
|
||||
|
||||
mux.HandleFunc("/api/items", handlers.GetItems)
|
||||
mux.HandleFunc("/api/items/create", handlers.CreateItem)
|
||||
mux.HandleFunc("/api/locations/create", handlers.CreateLocation)
|
||||
mux.HandleFunc("/api/projects/create", handlers.CreateProject)
|
||||
mux.HandleFunc("/api/stock/add", handlers.AddStock)
|
||||
mux.HandleFunc("/api/project-items/add", handlers.AllocateToProject)
|
||||
|
||||
// Login required
|
||||
|
||||
// Admin-only
|
||||
|
||||
52
storage/inventory.go
Normal file
52
storage/inventory.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package storage
|
||||
|
||||
import "MiauInv/models"
|
||||
|
||||
func AddItem(item models.Item) error {
|
||||
_, err := DB.Exec(
|
||||
"INSERT INTO items(name, category, description, total_quantity) VALUES(?,?,?,?)",
|
||||
item.Name,
|
||||
item.Category,
|
||||
item.Description,
|
||||
item.TotalQuantity,
|
||||
)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func GetItems() ([]models.Item, error) {
|
||||
|
||||
rows, err := DB.Query(`
|
||||
SELECT id,name,category,description,total_quantity
|
||||
FROM items
|
||||
`)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
defer rows.Close()
|
||||
|
||||
var items []models.Item
|
||||
|
||||
for rows.Next() {
|
||||
|
||||
var item models.Item
|
||||
|
||||
err = rows.Scan(
|
||||
&item.ID,
|
||||
&item.Name,
|
||||
&item.Category,
|
||||
&item.Description,
|
||||
&item.TotalQuantity,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
items = append(items, item)
|
||||
}
|
||||
|
||||
return items, nil
|
||||
}
|
||||
@@ -41,30 +41,42 @@ func InitDB(filepath string) error {
|
||||
FOREIGN KEY(user_id) REFERENCES users(id)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS items (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT NOT NULL,
|
||||
category TEXT,
|
||||
total_quantity INTEGER NOT NULL DEFAULT 0
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS locations (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS projects (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS item_allocations (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
item_id INTEGER NOT NULL,
|
||||
location_id INTEGER,
|
||||
project_id INTEGER,
|
||||
quantity INTEGER NOT NULL
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS items (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT NOT NULL,
|
||||
category TEXT,
|
||||
description TEXT,
|
||||
total_quantity INTEGER NOT NULL DEFAULT 0
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS locations (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT NOT NULL UNIQUE
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS projects (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT NOT NULL UNIQUE,
|
||||
description TEXT
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS stock (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
item_id INTEGER NOT NULL,
|
||||
location_id INTEGER NOT NULL,
|
||||
quantity INTEGER NOT NULL,
|
||||
FOREIGN KEY(item_id) REFERENCES items(id),
|
||||
FOREIGN KEY(location_id) REFERENCES locations(id)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS project_items (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
item_id INTEGER NOT NULL,
|
||||
project_id INTEGER NOT NULL,
|
||||
quantity INTEGER NOT NULL,
|
||||
FOREIGN KEY(item_id) REFERENCES items(id),
|
||||
FOREIGN KEY(project_id) REFERENCES projects(id)
|
||||
);
|
||||
`
|
||||
|
||||
_, err = DB.Exec(schema)
|
||||
|
||||
Reference in New Issue
Block a user