mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-10-30 11:06:56 +00:00
Support priority ordering in table and card views with automatic priority calculation, same-tier and between-tier drop targets, live previews, conflict detection, and undo. Keep drag mode off by default and place its toggle before Batch Operations. Consolidate sorting controls and preserve the shared visibility and view controls.
41 lines
1.0 KiB
Go
41 lines
1.0 KiB
Go
package controller
|
|
|
|
import (
|
|
"errors"
|
|
"net/http"
|
|
|
|
"github.com/QuantumNous/new-api/common"
|
|
"github.com/QuantumNous/new-api/model"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func GetChannelPriorityOrder(c *gin.Context) {
|
|
order, err := model.GetChannelPriorityOrder()
|
|
if err != nil {
|
|
common.ApiError(c, err)
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{"success": true, "data": order})
|
|
}
|
|
|
|
func ReorderChannelPriority(c *gin.Context) {
|
|
var move model.ChannelPriorityMove
|
|
if err := common.DecodeJson(c.Request.Body, &move); err != nil {
|
|
common.ApiErrorT(c, "Invalid channel priority move")
|
|
return
|
|
}
|
|
order, err := model.ReorderChannelPriority(move)
|
|
if err != nil {
|
|
if errors.Is(err, model.ErrChannelPriorityConflict) || errors.Is(err, model.ErrChannelPriorityInvalid) || errors.Is(err, model.ErrChannelPriorityRange) {
|
|
common.ApiErrorT(c, err.Error())
|
|
} else {
|
|
common.ApiError(c, err)
|
|
}
|
|
return
|
|
}
|
|
if !move.Preview && len(order.Changes) > 0 {
|
|
model.InitChannelCache()
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{"success": true, "data": order})
|
|
}
|