Преглед изворни кода

feat(site-category): support for custom sorting #902

Jacky пре 1 месец
родитељ
комит
f3d4cdbeb4

+ 8 - 1
api/sites/category.go

@@ -4,6 +4,7 @@ import (
 	"github.com/0xJacky/Nginx-UI/model"
 	"github.com/gin-gonic/gin"
 	"github.com/uozi-tech/cosy"
+	"gorm.io/gorm"
 )
 
 func GetCategory(c *gin.Context) {
@@ -11,7 +12,9 @@ func GetCategory(c *gin.Context) {
 }
 
 func GetCategoryList(c *gin.Context) {
-	cosy.Core[model.SiteCategory](c).PagingList()
+	cosy.Core[model.SiteCategory](c).GormScope(func(tx *gorm.DB) *gorm.DB {
+		return tx.Order("order_id ASC")
+	}).PagingList()
 }
 
 func AddCategory(c *gin.Context) {
@@ -39,3 +42,7 @@ func DeleteCategory(c *gin.Context) {
 func RecoverCategory(c *gin.Context) {
 	cosy.Core[model.SiteCategory](c).Recover()
 }
+
+func UpdateCategoriesOrder(c *gin.Context) {
+	cosy.Core[model.SiteCategory](c).UpdateOrder()
+}

+ 1 - 0
api/sites/router.go

@@ -31,4 +31,5 @@ func InitCategoryRouter(r *gin.RouterGroup) {
 	r.POST("site_categories/:id", ModifyCategory)
 	r.DELETE("site_categories/:id", DeleteCategory)
 	r.POST("site_categories/:id/recover", RecoverCategory)
+	r.POST("site_categories/order", UpdateCategoriesOrder)
 }

+ 1 - 0
app/src/views/site/site_category/SiteCategory.vue

@@ -11,6 +11,7 @@ import columns from '@/views/site/site_category/columns'
     :api="site_category"
     :columns="columns"
     :scroll-x="600"
+    sortable
   >
     <template #edit="{ data }">
       <div class="mb-2">

+ 1 - 2
app/src/views/site/site_category/columns.ts

@@ -9,20 +9,19 @@ const columns: Column[] = [{
   edit: {
     type: input,
   },
+  handle: true,
   pithy: true,
   width: 120,
 }, {
   title: () => $gettext('Created at'),
   dataIndex: 'created_at',
   customRender: datetime,
-  sorter: true,
   pithy: true,
   width: 150,
 }, {
   title: () => $gettext('Updated at'),
   dataIndex: 'updated_at',
   customRender: datetime,
-  sorter: true,
   pithy: true,
   width: 150,
 }, {

+ 1 - 0
model/site_category.go

@@ -4,4 +4,5 @@ type SiteCategory struct {
 	Model
 	Name        string   `json:"name"`
 	SyncNodeIds []uint64 `json:"sync_node_ids" gorm:"serializer:json"`
+	OrderID     int      `json:"-" gorm:"default:0"`
 }