feat: support sorting tasks and exit dialogs on ESC key (#148)
This commit is contained in:
@@ -337,7 +337,10 @@ func (tc *TaskController) GetTasks(c *gin.Context) {
|
||||
agentID = &agentIDStr
|
||||
}
|
||||
|
||||
tasks, total := tc.taskService.GetTasksWithPagination(p.Page, p.PageSize, name, agentID, tags, taskType)
|
||||
sortBy := c.DefaultQuery("sort_by", "")
|
||||
order := c.DefaultQuery("order", "")
|
||||
|
||||
tasks, total := tc.taskService.GetTasksWithPagination(p.Page, p.PageSize, name, agentID, tags, taskType, sortBy, order)
|
||||
utils.PaginatedResponse(c, vo.ToTaskVOListFromModels(tasks), total, p)
|
||||
}
|
||||
|
||||
@@ -702,7 +705,7 @@ func (tc *TaskController) BatchDeleteByQuery(c *gin.Context) {
|
||||
agentID = &agentIDStr
|
||||
}
|
||||
|
||||
tasks, _ := tc.taskService.GetTasksWithPagination(1, 999999, name, agentID, tags, taskType)
|
||||
tasks, _ := tc.taskService.GetTasksWithPagination(1, 999999, name, agentID, tags, taskType, "", "")
|
||||
if len(tasks) == 0 {
|
||||
utils.Success(c, gin.H{"count": 0})
|
||||
return
|
||||
|
||||
@@ -111,7 +111,7 @@ func (ts *TaskService) GetTasks() []models.Task {
|
||||
}
|
||||
|
||||
// GetTasksWithPagination 分页获取任务列表
|
||||
func (ts *TaskService) GetTasksWithPagination(page, pageSize int, name string, agentID *string, tags string, taskType string) ([]models.Task, int64) {
|
||||
func (ts *TaskService) GetTasksWithPagination(page, pageSize int, name string, agentID *string, tags string, taskType string, sortBy string, order string) ([]models.Task, int64) {
|
||||
var tasks []models.Task
|
||||
var total int64
|
||||
|
||||
@@ -154,8 +154,20 @@ func (ts *TaskService) GetTasksWithPagination(page, pageSize int, name string, a
|
||||
query = query.Where("agent_id = ?", *agentID)
|
||||
}
|
||||
|
||||
sortColumn := "created_at"
|
||||
if sortBy != "" {
|
||||
switch sortBy {
|
||||
case "name", "next_run", "last_run", "created_at", "enabled":
|
||||
sortColumn = sortBy
|
||||
}
|
||||
}
|
||||
sortOrder := "DESC"
|
||||
if strings.ToUpper(order) == "ASC" {
|
||||
sortOrder = "ASC"
|
||||
}
|
||||
|
||||
query.Count(&total)
|
||||
query.Order("pin_type DESC, created_at DESC").Offset((page - 1) * pageSize).Limit(pageSize).Find(&tasks)
|
||||
query.Order("pin_type DESC, " + sortColumn + " " + sortOrder).Offset((page - 1) * pageSize).Limit(pageSize).Find(&tasks)
|
||||
ts.loadTagsAndEnvs(tasks)
|
||||
|
||||
return tasks, total
|
||||
|
||||
Reference in New Issue
Block a user