Merge pull request 'trifold+sort+fixes' (#24) from trifold into master
All checks were successful
Go / build (push) Successful in 12m30s

Reviewed-on: #24
This commit was merged in pull request #24.
This commit is contained in:
2025-04-21 12:46:35 +02:00
8 changed files with 55 additions and 36 deletions

View File

@@ -260,14 +260,16 @@ func (rc *shopItemController) ShopItemView(c *gin.Context) {
shopItem, err := repositories.ShopItems.GetById(c.Param("id"))
if err != nil {
c.HTML(http.StatusBadRequest, "shopitem.html", gin.H{"data": gin.H{"error": err}})
c.HTML(http.StatusBadRequest, "error.html", gin.H{"data": gin.H{"error": "Item does not exist"}})
return
}
//TODO: get tags by item
tags, err := repositories.Tags.GetAll()
if err != nil {
c.HTML(http.StatusBadRequest, "shopitem.html", gin.H{"data": gin.H{"error": err}})
c.HTML(http.StatusBadRequest, "error.html", gin.H{"data": gin.H{"error": err}})
return
}
data := CreateSessionData(c, gin.H{
@@ -275,10 +277,6 @@ func (rc *shopItemController) ShopItemView(c *gin.Context) {
"tags": tags,
})
if err != nil {
c.HTML(http.StatusBadRequest, "shopitem.html", data)
}
c.HTML(http.StatusOK, "shopitem.html", data)
}

View File

@@ -333,8 +333,20 @@ func (rc *UserController) InviteHandler(c *gin.Context) {
}
func (rc *UserController) MainView(c *gin.Context) {
shopItems, _ := repositories.ShopItems.GetAll()
fmt.Println(len(shopItems))
itemOrder := c.Query("order")
var shopItems []models.ShopItem
if itemOrder == "newestFirst" {
shopItems, _ = repositories.ShopItems.GetAllNewestFirst()
} else if itemOrder == "oldestFirst" {
shopItems, _ = repositories.ShopItems.GetAllNewestLast()
} else if itemOrder == "az" {
shopItems, _ = repositories.ShopItems.GetAllLexicalFirst()
} else if itemOrder == "za" {
shopItems, _ = repositories.ShopItems.GetAllLexicalLast()
} else {
shopItems, _ = repositories.ShopItems.GetAllNewestFirst()
}
data := CreateSessionData(c, gin.H{
"title": "shopItem Page",

View File

@@ -15,6 +15,7 @@ const (
LongEdge PrintOption = ""
ShortEdge PrintOption = "-o Binding=TopBinding"
CreateBooklet PrintOption = "-o Combination=Booklet -o PageSize=A5"
TriFold PrintOption = "-o Fold=TriFold"
)
type PrintJob struct {
@@ -32,6 +33,10 @@ func GetPrintMode(mode string) PrintOption {
return ShortEdge
}
if mode == "TriFold" {
return TriFold
}
return CreateBooklet
}

View File

@@ -11,6 +11,11 @@ import (
type ShopItemRepository interface {
Create(models.ShopItem) (models.ShopItem, error)
GetAll() ([]models.ShopItem, error)
GetAllSorted(string) ([]models.ShopItem, error)
GetAllNewestFirst() ([]models.ShopItem, error)
GetAllNewestLast() ([]models.ShopItem, error)
GetAllLexicalFirst() ([]models.ShopItem, error)
GetAllLexicalLast() ([]models.ShopItem, error)
GetAllPublic() ([]models.ShopItem, error)
GetById(string) (models.ShopItem, error)
GetNextOfId(string) (models.ShopItem, error)
@@ -47,6 +52,29 @@ func (r *GORMShopItemRepository) GetAll() ([]models.ShopItem, error) {
return shopItems, result.Error
}
func (r *GORMShopItemRepository) GetAllSorted(sortString string) ([]models.ShopItem, error) {
var shopItems []models.ShopItem
result := r.DB.Preload("Tags").Preload("Variants").Order(sortString).Find(&shopItems)
return shopItems, result.Error
}
func (r *GORMShopItemRepository) GetAllNewestFirst() ([]models.ShopItem, error) {
return r.GetAllSorted("created_at desc")
}
func (r *GORMShopItemRepository) GetAllNewestLast() ([]models.ShopItem, error) {
return r.GetAllSorted("created_at asc")
}
func (r *GORMShopItemRepository) GetAllLexicalFirst() ([]models.ShopItem, error) {
return r.GetAllSorted("name asc")
}
func (r *GORMShopItemRepository) GetAllLexicalLast() ([]models.ShopItem, error) {
return r.GetAllSorted("name desc")
}
func (r *GORMShopItemRepository) GetAllPublic() ([]models.ShopItem, error) {
var shopItems []models.ShopItem
result := r.DB.Preload("Tags").Preload("Variants").Where("is_public = 1").Find(&shopItems)

View File

@@ -810,26 +810,10 @@ video {
grid-template-columns: repeat(12, minmax(0, 1fr));
}
.grid-cols-2 {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.grid-cols-3 {
grid-template-columns: repeat(3, minmax(0, 1fr));
}
.grid-cols-6 {
grid-template-columns: repeat(6, minmax(0, 1fr));
}
.grid-cols-4 {
grid-template-columns: repeat(4, minmax(0, 1fr));
}
.grid-rows-6 {
grid-template-rows: repeat(6, minmax(0, 1fr));
}
.flex-col {
flex-direction: column;
}
@@ -1245,16 +1229,6 @@ video {
background-color: rgb(24 24 27 / var(--tw-bg-opacity, 1));
}
.bg-green-500 {
--tw-bg-opacity: 1;
background-color: rgb(34 197 94 / var(--tw-bg-opacity, 1));
}
.bg-gray-700 {
--tw-bg-opacity: 1;
background-color: rgb(55 65 81 / var(--tw-bg-opacity, 1));
}
.fill-red-50 {
fill: #fef2f2;
}

View File

@@ -131,6 +131,7 @@
<option selected value="CreateBooklet">Create Booklet</option>
<option value="LongEdge">Long Edge</option>
<option value="ShortEdge">Short Edge</option>
<option value="TriFold">Tri-Fold (Flyer)</option>
</select>

View File

@@ -74,6 +74,7 @@
<option value="CreateBooklet">CreateBooklet</option>
<option value="LongEdge">Long Edge</option>
<option value="ShortEdge">Short Edge</option>
<option value="TriFold">Tri-Fold (Flyer)</option>
</select>

View File

@@ -1,8 +1,8 @@
<div class="bg-white">
<div class="mx-auto max-w-2xl px-4 py-16 sm:px-6 sm:py-24 lg:max-w-7xl">
<h2 class="text-2xl font-bold tracking-tight text-gray-900">Available Zines</h2>
<h2 class="text-2xl font-bold tracking-tight text-gray-900">Available Zines</h2>
<input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search for names..">
<input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search for names..">
<div class="mt-6 grid grid-cols-1 gap-x-6 gap-y-10 md:grid-cols-2 xl:grid-cols-4">
{{ range .data.shopItems }}