Skip to content

Commit f3d4cdb

Browse files
committed
feat(site-category): support for custom sorting #902
1 parent efc9b1c commit f3d4cdb

File tree

5 files changed

+12
-3
lines changed

5 files changed

+12
-3
lines changed

api/sites/category.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@ import (
44
"github.com/0xJacky/Nginx-UI/model"
55
"github.com/gin-gonic/gin"
66
"github.com/uozi-tech/cosy"
7+
"gorm.io/gorm"
78
)
89

910
func GetCategory(c *gin.Context) {
1011
cosy.Core[model.SiteCategory](c).Get()
1112
}
1213

1314
func GetCategoryList(c *gin.Context) {
14-
cosy.Core[model.SiteCategory](c).PagingList()
15+
cosy.Core[model.SiteCategory](c).GormScope(func(tx *gorm.DB) *gorm.DB {
16+
return tx.Order("order_id ASC")
17+
}).PagingList()
1518
}
1619

1720
func AddCategory(c *gin.Context) {
@@ -39,3 +42,7 @@ func DeleteCategory(c *gin.Context) {
3942
func RecoverCategory(c *gin.Context) {
4043
cosy.Core[model.SiteCategory](c).Recover()
4144
}
45+
46+
func UpdateCategoriesOrder(c *gin.Context) {
47+
cosy.Core[model.SiteCategory](c).UpdateOrder()
48+
}

api/sites/router.go

+1
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@ func InitCategoryRouter(r *gin.RouterGroup) {
3131
r.POST("site_categories/:id", ModifyCategory)
3232
r.DELETE("site_categories/:id", DeleteCategory)
3333
r.POST("site_categories/:id/recover", RecoverCategory)
34+
r.POST("site_categories/order", UpdateCategoriesOrder)
3435
}

app/src/views/site/site_category/SiteCategory.vue

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import columns from '@/views/site/site_category/columns'
1111
:api="site_category"
1212
:columns="columns"
1313
:scroll-x="600"
14+
sortable
1415
>
1516
<template #edit="{ data }">
1617
<div class="mb-2">

app/src/views/site/site_category/columns.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,19 @@ const columns: Column[] = [{
99
edit: {
1010
type: input,
1111
},
12+
handle: true,
1213
pithy: true,
1314
width: 120,
1415
}, {
1516
title: () => $gettext('Created at'),
1617
dataIndex: 'created_at',
1718
customRender: datetime,
18-
sorter: true,
1919
pithy: true,
2020
width: 150,
2121
}, {
2222
title: () => $gettext('Updated at'),
2323
dataIndex: 'updated_at',
2424
customRender: datetime,
25-
sorter: true,
2625
pithy: true,
2726
width: 150,
2827
}, {

model/site_category.go

+1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ type SiteCategory struct {
44
Model
55
Name string `json:"name"`
66
SyncNodeIds []uint64 `json:"sync_node_ids" gorm:"serializer:json"`
7+
OrderID int `json:"-" gorm:"default:0"`
78
}

0 commit comments

Comments
 (0)