Compare commits
2 Commits
f4faeb351d
...
17a1ef0123
| Author | SHA1 | Date | |
|---|---|---|---|
|
17a1ef0123
|
|||
|
6330a990f5
|
@@ -136,6 +136,7 @@ func (rc *configController) PaperHandler(ctx *gin.Context) {
|
||||
paper.Name = newPaper.Name
|
||||
paper.Brand = newPaper.Brand
|
||||
paper.Size = newPaper.Size
|
||||
paper.Weight = newPaper.Weight
|
||||
paper.Price = newPaper.Price
|
||||
paper, err = repositories.Papers.Update(paper)
|
||||
|
||||
|
||||
@@ -34,40 +34,49 @@ func ParseSize(s string) (c PaperSize, err error) {
|
||||
|
||||
type Paper struct {
|
||||
gorm.Model
|
||||
Name string `json:"name" binding:"required" gorm:"not null"`
|
||||
Brand string `json:"brand" binding:"required"`
|
||||
Size PaperSize `json:"size" binding:"required"`
|
||||
Price float64 `json:"price" binding:"required"`
|
||||
Name string `json:"name" binding:"required" gorm:"not null"`
|
||||
Brand string `json:"brand" binding:"required"`
|
||||
Size PaperSize `json:"size" binding:"required"`
|
||||
Weight int `json:"weight" binding:"required"`
|
||||
Price float64 `json:"price" binding:"required"`
|
||||
}
|
||||
|
||||
func NewPaper(ctx *gin.Context) (Paper, error) {
|
||||
name := ctx.PostForm("name")
|
||||
brand := ctx.PostForm("brand")
|
||||
sizeTmp := ctx.PostForm("size")
|
||||
weightTmp := ctx.PostForm("weight")
|
||||
priceTmp := ctx.PostForm("price")
|
||||
|
||||
price, err := strconv.ParseFloat(priceTmp, 64)
|
||||
|
||||
if err != nil {
|
||||
return Paper{}, fmt.Errorf("Couldnt parse Price")
|
||||
}
|
||||
|
||||
size, err := ParseSize(sizeTmp)
|
||||
|
||||
if err != nil {
|
||||
return Paper{}, fmt.Errorf("Couldnt parse Size")
|
||||
}
|
||||
|
||||
weight, err := strconv.Atoi(weightTmp)
|
||||
|
||||
if err != nil {
|
||||
return Paper{}, fmt.Errorf("Couldnt parse Weight")
|
||||
}
|
||||
|
||||
price, err := strconv.ParseFloat(priceTmp, 64)
|
||||
|
||||
if err != nil {
|
||||
return Paper{}, fmt.Errorf("Couldnt parse Price")
|
||||
}
|
||||
|
||||
if name == "" || brand == "" {
|
||||
return Paper{}, fmt.Errorf("Name or brand empty")
|
||||
}
|
||||
|
||||
// Convert the price string to float64
|
||||
tag := Paper{
|
||||
Name: name,
|
||||
Brand: brand,
|
||||
Size: size,
|
||||
Price: price,
|
||||
Name: name,
|
||||
Brand: brand,
|
||||
Size: size,
|
||||
Weight: weight,
|
||||
Price: price,
|
||||
}
|
||||
|
||||
return tag, nil
|
||||
|
||||
@@ -674,6 +674,10 @@ video {
|
||||
margin-top: 1.5rem;
|
||||
}
|
||||
|
||||
.mb-3 {
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
|
||||
.block {
|
||||
display: block;
|
||||
}
|
||||
@@ -810,14 +814,34 @@ video {
|
||||
grid-template-columns: repeat(12, minmax(0, 1fr));
|
||||
}
|
||||
|
||||
.grid-cols-2 {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
|
||||
.grid-cols-4 {
|
||||
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||
}
|
||||
|
||||
.grid-cols-6 {
|
||||
grid-template-columns: repeat(6, minmax(0, 1fr));
|
||||
}
|
||||
|
||||
.grid-cols-3 {
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
}
|
||||
|
||||
.flex-col {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.flex-wrap {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.content-stretch {
|
||||
align-content: stretch;
|
||||
}
|
||||
|
||||
.items-center {
|
||||
align-items: center;
|
||||
}
|
||||
@@ -830,6 +854,10 @@ video {
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.gap-2 {
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.gap-4 {
|
||||
gap: 1rem;
|
||||
}
|
||||
@@ -974,6 +1002,11 @@ video {
|
||||
background-color: rgb(219 234 254 / var(--tw-bg-opacity, 1));
|
||||
}
|
||||
|
||||
.bg-blue-500 {
|
||||
--tw-bg-opacity: 1;
|
||||
background-color: rgb(59 130 246 / var(--tw-bg-opacity, 1));
|
||||
}
|
||||
|
||||
.bg-blue-600 {
|
||||
--tw-bg-opacity: 1;
|
||||
background-color: rgb(37 99 235 / var(--tw-bg-opacity, 1));
|
||||
@@ -1049,6 +1082,11 @@ video {
|
||||
background-color: rgb(220 252 231 / var(--tw-bg-opacity, 1));
|
||||
}
|
||||
|
||||
.bg-green-500 {
|
||||
--tw-bg-opacity: 1;
|
||||
background-color: rgb(34 197 94 / var(--tw-bg-opacity, 1));
|
||||
}
|
||||
|
||||
.bg-green-600 {
|
||||
--tw-bg-opacity: 1;
|
||||
background-color: rgb(22 163 74 / var(--tw-bg-opacity, 1));
|
||||
@@ -1134,6 +1172,11 @@ video {
|
||||
background-color: rgb(254 226 226 / var(--tw-bg-opacity, 1));
|
||||
}
|
||||
|
||||
.bg-red-500 {
|
||||
--tw-bg-opacity: 1;
|
||||
background-color: rgb(239 68 68 / var(--tw-bg-opacity, 1));
|
||||
}
|
||||
|
||||
.bg-red-800 {
|
||||
--tw-bg-opacity: 1;
|
||||
background-color: rgb(153 27 27 / var(--tw-bg-opacity, 1));
|
||||
@@ -1229,6 +1272,16 @@ video {
|
||||
background-color: rgb(24 24 27 / var(--tw-bg-opacity, 1));
|
||||
}
|
||||
|
||||
.bg-gray-700 {
|
||||
--tw-bg-opacity: 1;
|
||||
background-color: rgb(55 65 81 / var(--tw-bg-opacity, 1));
|
||||
}
|
||||
|
||||
.bg-gray-500 {
|
||||
--tw-bg-opacity: 1;
|
||||
background-color: rgb(107 114 128 / var(--tw-bg-opacity, 1));
|
||||
}
|
||||
|
||||
.fill-red-50 {
|
||||
fill: #fef2f2;
|
||||
}
|
||||
@@ -1329,6 +1382,16 @@ video {
|
||||
padding-bottom: 2rem;
|
||||
}
|
||||
|
||||
.py-20 {
|
||||
padding-top: 5rem;
|
||||
padding-bottom: 5rem;
|
||||
}
|
||||
|
||||
.px-8 {
|
||||
padding-left: 2rem;
|
||||
padding-right: 2rem;
|
||||
}
|
||||
|
||||
.pb-3 {
|
||||
padding-bottom: 0.75rem;
|
||||
}
|
||||
@@ -1353,6 +1416,10 @@ video {
|
||||
padding-top: 1.25rem;
|
||||
}
|
||||
|
||||
.pb-4 {
|
||||
padding-bottom: 1rem;
|
||||
}
|
||||
|
||||
.text-left {
|
||||
text-align: left;
|
||||
}
|
||||
@@ -1717,6 +1784,10 @@ video {
|
||||
color: rgb(39 39 42 / var(--tw-text-opacity, 1));
|
||||
}
|
||||
|
||||
.underline {
|
||||
text-decoration-line: underline;
|
||||
}
|
||||
|
||||
.antialiased {
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
@@ -1734,6 +1805,18 @@ video {
|
||||
box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);
|
||||
}
|
||||
|
||||
.shadow-xl {
|
||||
--tw-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
|
||||
--tw-shadow-colored: 0 20px 25px -5px var(--tw-shadow-color), 0 8px 10px -6px var(--tw-shadow-color);
|
||||
box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);
|
||||
}
|
||||
|
||||
.shadow-md {
|
||||
--tw-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
|
||||
--tw-shadow-colored: 0 4px 6px -1px var(--tw-shadow-color), 0 2px 4px -2px var(--tw-shadow-color);
|
||||
box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);
|
||||
}
|
||||
|
||||
.outline {
|
||||
outline-style: solid;
|
||||
}
|
||||
@@ -1838,6 +1921,11 @@ video {
|
||||
background-color: rgb(67 56 202 / var(--tw-bg-opacity, 1));
|
||||
}
|
||||
|
||||
.hover\:bg-red-700:hover {
|
||||
--tw-bg-opacity: 1;
|
||||
background-color: rgb(185 28 28 / var(--tw-bg-opacity, 1));
|
||||
}
|
||||
|
||||
.hover\:bg-red-900:hover {
|
||||
--tw-bg-opacity: 1;
|
||||
background-color: rgb(127 29 29 / var(--tw-bg-opacity, 1));
|
||||
@@ -2004,6 +2092,10 @@ video {
|
||||
max-width: 24rem;
|
||||
}
|
||||
|
||||
.sm\:grid-cols-2 {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
|
||||
.sm\:items-center {
|
||||
align-items: center;
|
||||
}
|
||||
@@ -2047,6 +2139,10 @@ video {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
|
||||
.md\:grid-cols-3 {
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
}
|
||||
|
||||
.md\:flex-row {
|
||||
flex-direction: row;
|
||||
}
|
||||
@@ -2095,6 +2191,14 @@ video {
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
}
|
||||
|
||||
.lg\:grid-cols-4 {
|
||||
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||
}
|
||||
|
||||
.lg\:grid-cols-2 {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
|
||||
.lg\:p-8 {
|
||||
padding: 2rem;
|
||||
}
|
||||
@@ -2118,9 +2222,17 @@ video {
|
||||
.xl\:grid-cols-4 {
|
||||
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||
}
|
||||
|
||||
.xl\:grid-cols-3 {
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 1536px) {
|
||||
.\32xl\:grid-cols-4 {
|
||||
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||
}
|
||||
|
||||
.\32xl\:px-0 {
|
||||
padding-left: 0px;
|
||||
padding-right: 0px;
|
||||
|
||||
@@ -7,31 +7,76 @@
|
||||
<h2 class="mt-10 text-center text-2xl/9 font-bold tracking-tight text-gray-900">Edit Paper</h2>
|
||||
</div>
|
||||
|
||||
<div class="mt-10 sm:mx-auto sm:w-full sm:max-w-sm">
|
||||
<div class="mt-10 ">
|
||||
<div class="w-full grid grid-cols-1 lg:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4 gap-4">
|
||||
{{ range .data.paper }}
|
||||
<form action="/paper/{{ .ID }}" method="POST">
|
||||
<div class="max-w-md mx-auto mt-4">
|
||||
<div class="flex">
|
||||
|
||||
<input type="text" id="name" name="name" value="{{ .Name }}" class="flex-grow border border-gray-300 rounded-l-md p-2 focus:outline-none focus:ring focus:ring-blue-500">
|
||||
<input type="text" id="brand" name="brand" value="{{ .Brand }}" class="flex-grow border border-gray-300 rounded-l-md p-2 focus:outline-none focus:ring focus:ring-blue-500">
|
||||
<input type="text" id="size" name="size" value="{{ .Size }}" class="flex-grow border border-gray-300 rounded-l-md p-2 focus:outline-none focus:ring focus:ring-blue-500">
|
||||
<input type="number" step="0.01" min="0.00" id="price" name="price" value="{{ .Price }}" class="flex-grow border border-gray-300 rounded-l-md p-2 focus:outline-none focus:ring focus:ring-blue-500">
|
||||
<button type="submit" name="action" value="update" class="bg-blue-600 text-white ml-4 mr-4 rounded px-4 hover:bg-blue-700">Update</button>
|
||||
<button type="submit" name="action" value="delete" class="bg-red-800 text-white rounded px-4 hover:bg-red-900">Delete</button>
|
||||
<div class="max-w-md mx-auto p-4 m-4 bg-gray-100 flex flex-wrap border rounded shadow-md">
|
||||
<div class="font-bold text-center mb-4">
|
||||
{{ .Brand }} - {{ .Name }}: {{ .Size }} {{ .Weight }}g/m2
|
||||
</div>
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label for="variant-value1" class="block text-sm/6 font-medium text-gray-900">Name</label>
|
||||
<input type="text" id="name" name="name" value="{{ .Name }}" class="w-full border border-gray-300 rounded-md p-2 focus:outline-none focus:ring focus:ring-blue-500">
|
||||
</div>
|
||||
<div>
|
||||
<label for="variant-value1" class="block text-sm/6 font-medium text-gray-900">Brand</label>
|
||||
<input type="text" id="brand" name="brand" value="{{ .Brand }}" class="w-full border border-gray-300 rounded-md p-2 focus:outline-none focus:ring focus:ring-blue-500">
|
||||
</div>
|
||||
<div>
|
||||
<label for="variant-value1" class="block text-sm/6 font-medium text-gray-900">DIN Size</label>
|
||||
<input type="text" id="size" name="size" value="{{ .Size }}" class="w-full border border-gray-300 rounded-md p-2 focus:outline-none focus:ring focus:ring-blue-500">
|
||||
</div>
|
||||
<div>
|
||||
<label for="variant-value1" class="block text-sm/6 font-medium text-gray-900">Weight</label>
|
||||
<input type="text" id="weight" name="weight" value="{{ .Weight }}" class="w-full border border-gray-300 rounded-md p-2 focus:outline-none focus:ring focus:ring-blue-500">
|
||||
</div>
|
||||
<div>
|
||||
<label for="variant-value1" class="block text-sm/6 font-medium text-gray-900">Price per Sheet</label>
|
||||
<input type="number" step="0.0001" min="0.0000" id="price" name="price" value="{{ .Price }}" class="w-full flex-grow border border-gray-300 rounded-md p-2 focus:outline-none focus:ring focus:ring-blue-500">
|
||||
</div>
|
||||
</div>
|
||||
<div class="grid grid-cols-2 mt-4 flex flex-wrap gap-2 w-full">
|
||||
<button type="submit" name="action" value="update" class="bg-blue-500 hover:bg-blue-700 text-white text-sm/6 font-bold py-2 px-4 rounded">Update</button>
|
||||
<button type="submit" name="action" value="delete" class="bg-red-500 hover:bg-red-700 text-white text-sm/6 font-bold py-2 px-4 rounded">Delete</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
{{ end }}
|
||||
</div>
|
||||
<form action="/paper" method="POST">
|
||||
<div class="max-w-md mx-auto mt-4">
|
||||
<div class="flex">
|
||||
<input type="text" id="name" name="name" placeholder="name" class="flex-grow border border-gray-300 rounded-l-md p-2 focus:outline-none focus:ring focus:ring-blue-500">
|
||||
<input type="text" id="brand" name="brand" placeholder="brand" class="flex-grow border border-gray-300 rounded-l-md p-2 focus:outline-none focus:ring focus:ring-blue-500">
|
||||
<input type="text" id="size" name="size" placeholder="size" class="flex-grow border border-gray-300 rounded-l-md p-2 focus:outline-none focus:ring focus:ring-blue-500">
|
||||
<input type="number" step="0.01" min="0.00" id="price" name="price" placeholder="price per sheet" class="flex-grow border border-gray-300 rounded-l-md p-2 focus:outline-none focus:ring focus:ring-blue-500">
|
||||
<button type="submit" class="bg-green-600 text-white ml-4 mr-4 rounded px-4 hover:bg-green-700">Add</button>
|
||||
<div class="max-w-md mx-auto p-4 flex flex-wrap border rounded shadow-md">
|
||||
<div class="font-bold text-center mb-4">
|
||||
Add new Paper
|
||||
</div>
|
||||
</div>
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label for="variant-value1" class="block text-sm/6 font-medium text-gray-900">Name</label>
|
||||
<input type="text" id="name" name="name" placeholder="name" class="w-full border border-gray-300 rounded-md p-2 focus:outline-none focus:ring focus:ring-blue-500">
|
||||
</div>
|
||||
<div>
|
||||
<label for="variant-value1" class="block text-sm/6 font-medium text-gray-900">Brand</label>
|
||||
<input type="text" id="brand" name="brand" placeholder="brand" class="w-full border border-gray-300 rounded-md p-2 focus:outline-none focus:ring focus:ring-blue-500">
|
||||
</div>
|
||||
<div>
|
||||
<label for="variant-value1" class="block text-sm/6 font-medium text-gray-900">DIN Size</label>
|
||||
<input type="text" id="size" name="size" placeholder="size" class="w-full border border-gray-300 rounded-md p-2 focus:outline-none focus:ring focus:ring-blue-500">
|
||||
</div>
|
||||
<div>
|
||||
<label for="variant-value1" class="block text-sm/6 font-medium text-gray-900">Weight</label>
|
||||
<input type="text" id="weight" name="weight" placeholder="Weight" class="w-full border border-gray-300 rounded-md p-2 focus:outline-none focus:ring focus:ring-blue-500">
|
||||
</div>
|
||||
<div>
|
||||
<label for="variant-value1" class="block text-sm/6 font-medium text-gray-900">Price per Sheet</label>
|
||||
<input type="number" step="0.0001" min="0.0000" id="price" name="price" placeholder="price per sheet"
|
||||
class="w-full flex-grow border border-gray-300 rounded-md p-2 focus:outline-none focus:ring focus:ring-blue-500">
|
||||
</div>
|
||||
</div>
|
||||
<div class="grid grid-cols-4 mt-4 flex flex-wrap gap-2 w-full">
|
||||
<button type="submit" class="bg-green-500 hover:bg-green-700 text-white text-sm/6 font-bold py-2 px-4 rounded">Add</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
{{ template "footer.html" . }}
|
||||
|
||||
Reference in New Issue
Block a user