Initial commit (code only without large binaries)
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
// Copyright 2023 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
//go:build plus
|
||||
|
||||
package userscripts
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
type IndexAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *IndexAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct {
|
||||
Type string
|
||||
}) {
|
||||
this.Data["currentURL"] = url.QueryEscape(this.Request.URL.String())
|
||||
|
||||
// menu
|
||||
var listType = params.Type
|
||||
if len(listType) == 0 {
|
||||
listType = "auditing"
|
||||
}
|
||||
this.FirstMenu(listType)
|
||||
this.Data["type"] = listType
|
||||
|
||||
var isAuditing = listType == "auditing"
|
||||
|
||||
// total
|
||||
countResp, err := this.RPC().UserScriptRPC().CountUserScripts(this.AdminContext(), &pb.CountUserScriptsRequest{
|
||||
UserId: 0,
|
||||
IsAuditing: isAuditing,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var total = countResp.Count
|
||||
var page = this.NewPage(total)
|
||||
this.Data["page"] = page.AsHTML()
|
||||
|
||||
// list
|
||||
scriptsResp, err := this.RPC().UserScriptRPC().ListUserScripts(this.AdminContext(), &pb.ListUserScriptsRequest{
|
||||
UserId: 0,
|
||||
IsAuditing: isAuditing,
|
||||
Offset: page.Offset,
|
||||
Size: page.Size,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var scriptMaps = []maps.Map{}
|
||||
for _, script := range scriptsResp.UserScripts {
|
||||
// user
|
||||
var userMap = maps.Map{
|
||||
"id": 0,
|
||||
}
|
||||
if script.User != nil {
|
||||
userMap = maps.Map{
|
||||
"id": script.User.Id,
|
||||
"username": script.User.Username,
|
||||
"fullname": script.User.Fullname,
|
||||
}
|
||||
}
|
||||
|
||||
scriptMaps = append(scriptMaps, maps.Map{
|
||||
"id": script.Id,
|
||||
"createdTime": timeutil.FormatTime("Y-m-d H:i:s", script.CreatedAt),
|
||||
"isPassed": script.IsPassed,
|
||||
"isRejected": script.IsRejected,
|
||||
"user": userMap,
|
||||
})
|
||||
}
|
||||
this.Data["scripts"] = scriptMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
Reference in New Issue
Block a user