add fittopage checkbox + custom print options
All checks were successful
Go / build (push) Successful in 16m26s

This commit is contained in:
2025-12-12 19:51:05 +01:00
parent 7fa932e378
commit faf07704d2
4 changed files with 70 additions and 34 deletions

View File

@@ -78,6 +78,8 @@ func (rc *shopItemController) NewShopItemFromForm(ctx *gin.Context) (models.Shop
image, err := ctx.FormFile("image") image, err := ctx.FormFile("image")
dstImage := defaultImagePath dstImage := defaultImagePath
printMode := ctx.PostForm("print-mode") printMode := ctx.PostForm("print-mode")
fitToPage := ctx.PostForm("fit-to-page")
customPrintOptions := ctx.PostForm("custom-print-options")
if err == nil { if err == nil {
dstImage = filepath.Join("static/uploads", image.Filename) dstImage = filepath.Join("static/uploads", image.Filename)
@@ -150,18 +152,26 @@ func (rc *shopItemController) NewShopItemFromForm(ctx *gin.Context) (models.Shop
}) })
} }
doFit := false
fmt.Println("FitToPage: ", fitToPage)
if fitToPage == "true" {
doFit = true
}
shopItem := models.ShopItem{ shopItem := models.ShopItem{
Name: name, Name: name,
Abstract: abstract, Abstract: abstract,
Description: description, Description: description,
Category: category, Category: category,
IsPublic: true, IsPublic: true,
BasePrice: rc.GetBasePrice(variants), BasePrice: rc.GetBasePrice(variants),
Image: dstImage, Image: dstImage,
Pdf: dstPdf, Pdf: dstPdf,
Variants: variants, Variants: variants,
PrintMode: printMode, PrintMode: printMode,
WasPrinted: false, WasPrinted: false,
FitToPage: doFit,
CustomPrintOptions: customPrintOptions,
} }
fmt.Println("Creating Shopitem: ", shopItem) fmt.Println("Creating Shopitem: ", shopItem)
@@ -391,17 +401,19 @@ func (rc *shopItemController) AddItemsHandler(c *gin.Context) {
} }
shopItem := models.ShopItem{ shopItem := models.ShopItem{
Name: file.Filename, Name: file.Filename,
Abstract: file.Filename, Abstract: file.Filename,
Description: file.Filename, Description: file.Filename,
Category: category, Category: category,
IsPublic: true, IsPublic: true,
BasePrice: rc.GetBasePrice(variants), BasePrice: rc.GetBasePrice(variants),
Image: dstImage, Image: dstImage,
Pdf: dstPdf, Pdf: dstPdf,
Variants: variants, Variants: variants,
PrintMode: "CreateBooklet", PrintMode: "CreateBooklet",
WasPrinted: false, WasPrinted: false,
FitToPage: false,
CustomPrintOptions: "",
} }
_, err = repositories.ShopItems.Create(shopItem) _, err = repositories.ShopItems.Create(shopItem)
@@ -540,6 +552,8 @@ func (rc *shopItemController) EditItemHandler(c *gin.Context) {
newShopItem.BasePrice = shopItem.BasePrice newShopItem.BasePrice = shopItem.BasePrice
newShopItem.IsPublic = shopItem.IsPublic newShopItem.IsPublic = shopItem.IsPublic
newShopItem.WasPrinted = false newShopItem.WasPrinted = false
newShopItem.FitToPage = shopItem.FitToPage
newShopItem.CustomPrintOptions = shopItem.CustomPrintOptions
if len(shopItem.Tags) != 0 { if len(shopItem.Tags) != 0 {
newShopItem.Tags = shopItem.Tags newShopItem.Tags = shopItem.Tags

View File

@@ -19,6 +19,7 @@ const (
ShortEdge PrintOption = "-o Binding=TopBinding" ShortEdge PrintOption = "-o Binding=TopBinding"
CreateBooklet PrintOption = "-o Combination=Booklet -o PageSize=A5" CreateBooklet PrintOption = "-o Combination=Booklet -o PageSize=A5"
TriFold PrintOption = "-o Fold=TriFold -o Binding=TopBinding" TriFold PrintOption = "-o Fold=TriFold -o Binding=TopBinding"
FitToPage PrintOption = "-o fit-to-page"
) )
type OldPrintJob struct { type OldPrintJob struct {
@@ -101,7 +102,12 @@ func (p *PrintJob) GeneratePrintOptions() []PrintOption {
result = append(result, CoverPage) result = append(result, CoverPage)
} }
if p.ShopItem.FitToPage {
result = append(result, FitToPage)
}
result = append(result, GetPrintMode(p.ShopItem.PrintMode)) result = append(result, GetPrintMode(p.ShopItem.PrintMode))
result = append(result, PrintOption(p.ShopItem.CustomPrintOptions))
return result return result
} }

View File

@@ -42,16 +42,18 @@ type ItemVariant struct {
type ShopItem struct { type ShopItem struct {
gorm.Model gorm.Model
Name string `json:"name" binding:"required" gorm:"unique;not null"` Name string `json:"name" binding:"required" gorm:"unique;not null"`
Abstract string `json:"abstract" binding:"required"` Abstract string `json:"abstract" binding:"required"`
Description string `json:"description" binding:"required"` Description string `json:"description" binding:"required"`
Category Category `json:"category"` Category Category `json:"category"`
Variants []ItemVariant `json:"variant"` Variants []ItemVariant `json:"variant"`
BasePrice float64 `json:"basePrice"` BasePrice float64 `json:"basePrice"`
IsPublic bool `json:"isPublic" gorm:"default:true"` IsPublic bool `json:"isPublic" gorm:"default:true"`
Tags []Tag `gorm:"many2many:item_tags;"` Tags []Tag `gorm:"many2many:item_tags;"`
Image string Image string
Pdf string Pdf string
PrintMode string `json:"printMode" gorm:"default:CreateBooklet"` PrintMode string `json:"printMode" gorm:"default:CreateBooklet"`
WasPrinted bool `gorm:"default:false"` CustomPrintOptions string `gorm:"default:''"`
FitToPage bool `gorm:"default:false"`
WasPrinted bool `gorm:"default:false"`
} }

View File

@@ -77,6 +77,20 @@
<option value="TriFold">Tri-Fold (Flyer)</option> <option value="TriFold">Tri-Fold (Flyer)</option>
</select> </select>
<label class="flex text-sm/6 items-center">
<input type="checkbox" {{ if .data.shopItem.FitToPage }} checked {{ else }} {{ end }} class="form-checkbox h-4 w-4 text-gray-900"
value="true" name="fit-to-page">
<span class="ml-2 text-sm/6 text-gray-900">Fit to Page</span>
</label>
<div>
<label for="custom-print-options" class="block text-sm/6 font-medium text-gray-900">Custom Print Options:</label>
<textarea id="custom-print-options" name="custom-print-options" type="textarea" class="block w-full px-4 py-2
mt-2 text-gray-900 bg-white border border-gray-300 rounded-md focus:border-blue-500 focus:outline-none
focus:ring">{{ .data.shopItem.CustomPrintOptions}}</textarea>
</div>
<div class="mb-4"> <div class="mb-4">
<label class="block text-sm/6 text-gray-900">Select Categories</label> <label class="block text-sm/6 text-gray-900">Select Categories</label>