diff --git a/controllers/shopItemController.go b/controllers/shopItemController.go index a26d511..ce3ff9f 100644 --- a/controllers/shopItemController.go +++ b/controllers/shopItemController.go @@ -79,6 +79,7 @@ func (rc *shopItemController) NewShopItemFromForm(ctx *gin.Context) (models.Shop tagIds := ctx.PostFormArray("tags[]") image, err := ctx.FormFile("image") dstImage := defaultImagePath + printMode := ctx.PostForm("print-mode") if err == nil { dstImage = filepath.Join("static/uploads", image.Filename) @@ -150,6 +151,7 @@ func (rc *shopItemController) NewShopItemFromForm(ctx *gin.Context) (models.Shop Image: dstImage, Pdf: dstPdf, Variants: variants, + PrintMode: printMode, } for _, tagId := range tagIds { @@ -381,6 +383,7 @@ func (rc *shopItemController) AddItemsHandler(c *gin.Context) { Image: dstImage, Pdf: dstPdf, Variants: variants, + PrintMode: "CreateBooklet", } _, err = repositories.ShopItems.Create(shopItem) @@ -448,6 +451,7 @@ func (rc *shopItemController) EditItemHandler(c *gin.Context) { newShopItem.IsPublic = shopItem.IsPublic newShopItem.Tags = shopItem.Tags newShopItem.Variants = shopItem.Variants + newShopItem.PrintMode = shopItem.PrintMode tags, err := repositories.Tags.GetAll() if err != nil { diff --git a/models/printer.go b/models/printer.go index be8e6bb..ed30f6a 100644 --- a/models/printer.go +++ b/models/printer.go @@ -2,14 +2,19 @@ package models import ( "fmt" + "os/exec" + "strings" ) type PrintOption string const ( - CoverPage PrintOption = "-o FrontCoverPage=Printed -o FrontCoverTray=BypassTray -o InputSlot=Tray1" - Colored PrintOption = "-o SelectColor=Color" - Grayscale PrintOption = "-o SelectColor=Grayscale" + CoverPage PrintOption = "-o FrontCoverPage=Printed -o FrontCoverTray=Tray2 -o InputSlot=Tray1" + Colored PrintOption = "-o SelectColor=Color" + Grayscale PrintOption = "-o SelectColor=Grayscale" + CreateBooklet PrintOption = "-o Combination=Booklet -o PageSize=A5" + LongEdge PrintOption = "" + ShortEdge PrintOption = "-o Binding=TopBinding" ) type PrintJob struct { @@ -18,6 +23,18 @@ type PrintJob struct { Options []PrintOption } +func GetPrintMode(mode string) PrintOption { + if mode == "LongEdge" { + return LongEdge + } + + if mode == "ShortEdge" { + return ShortEdge + } + + return CreateBooklet +} + func NewPrintJob(shopItem ShopItem, variant ItemVariant, coverPage bool, amount uint) (PrintJob, error) { if shopItem.Pdf == "" { return PrintJob{}, fmt.Errorf("ShopItem has no PDF assigned") @@ -39,12 +56,14 @@ func NewPrintJob(shopItem ShopItem, variant ItemVariant, coverPage bool, amount result.Options = append(result.Options, CoverPage) } + result.Options = append(result.Options, GetPrintMode(shopItem.PrintMode)) + return result, nil } func (p *PrintJob) Execute() error { - baseCommand := "lp -p KONICA_MINOLTA_KONICA_MINOLTA_bizhub_C258/Booklet " - baseCommand += fmt.Sprintf("-n %v ", p.Amount) + baseCommand := "lp -d KONICA_MINOLTA_KONICA_MINOLTA_bizhub_C258/BookletPrint -o Fold=HalfFold" + baseCommand += fmt.Sprintf(" -n %v ", p.Amount) for _, option := range p.Options { baseCommand += fmt.Sprintf(" %v ", option) @@ -52,6 +71,18 @@ func (p *PrintJob) Execute() error { baseCommand += fmt.Sprintf(" -- %s", p.Pdf) - fmt.Println(baseCommand) + parts := strings.Fields(baseCommand) + + // The first part is the command, the rest are the arguments + fmt.Println(parts) + cmd := exec.Command(parts[0], parts[1:]...) + + output, err := cmd.CombinedOutput() + if err != nil { + fmt.Printf("Error: %s\n", err) + return err + } + + fmt.Printf("Output:\n%s\n", output) return nil } diff --git a/models/shopItem.go b/models/shopItem.go index 92047d6..55e49de 100644 --- a/models/shopItem.go +++ b/models/shopItem.go @@ -52,4 +52,5 @@ type ShopItem struct { Tags []Tag `gorm:"many2many:item_tags;"` Image string Pdf string + PrintMode string `json:"printMode" gorm:"default:CreateBooklet"` } diff --git a/static/output.css b/static/output.css index 34b6e1c..87db094 100644 --- a/static/output.css +++ b/static/output.css @@ -1301,11 +1301,6 @@ video { color: rgb(255 255 255 / var(--tw-text-opacity, 1)); } -.text-red-900 { - --tw-text-opacity: 1; - color: rgb(127 29 29 / var(--tw-text-opacity, 1)); -} - .underline { text-decoration-line: underline; } diff --git a/views/additem.html b/views/additem.html index e5e0c3a..0b803e6 100644 --- a/views/additem.html +++ b/views/additem.html @@ -123,6 +123,19 @@ + + + + + +
Choose 'Create Booklet' if its just a normal PDF (not converted to booklet already)
+{{ .data.error }}
diff --git a/views/edititem.html b/views/edititem.html index 0e5a7fb..5bf068d 100644 --- a/views/edititem.html +++ b/views/edititem.html @@ -123,6 +123,16 @@ + + + +{{ .data.error }}