1.4.5.2
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
//go:build plus
|
||||
|
||||
package scripts
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
type IndexAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *IndexAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct{}) {
|
||||
// 检查是否更新
|
||||
updatesResp, err := this.RPC().ScriptRPC().CheckScriptUpdates(this.AdminContext(), &pb.CheckScriptUpdatesRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Data["hasUpdates"] = updatesResp.HasUpdates
|
||||
var lastVersion = updatesResp.Version
|
||||
|
||||
// 数量
|
||||
countResp, err := this.RPC().ScriptRPC().CountAllEnabledScripts(this.AdminContext(), &pb.CountAllEnabledScriptsRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var count = countResp.Count
|
||||
var page = this.NewPage(count)
|
||||
this.Data["page"] = page.AsHTML()
|
||||
|
||||
// 单页脚本
|
||||
scriptsResp, err := this.RPC().ScriptRPC().ListEnabledScripts(this.AdminContext(), &pb.ListEnabledScriptsRequest{
|
||||
Offset: page.Offset,
|
||||
Size: page.Size,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var scriptMaps = []maps.Map{}
|
||||
for _, script := range scriptsResp.Scripts {
|
||||
scriptMaps = append(scriptMaps, maps.Map{
|
||||
"id": script.Id,
|
||||
"name": script.Name,
|
||||
"filename": script.Filename,
|
||||
"isOn": script.IsOn,
|
||||
"updatedTime": timeutil.FormatTime("Y-m-d H:i:s", script.UpdatedAt),
|
||||
"isChanged": script.UpdatedAt > lastVersion,
|
||||
})
|
||||
}
|
||||
this.Data["scripts"] = scriptMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
Reference in New Issue
Block a user