mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-03 12:20:28 +08:00
[API节点]显示API节点运行日志 [用户]增加可用功能控制
This commit is contained in:
@@ -23,6 +23,7 @@ func init() {
|
||||
Get("", new(IndexAction)).
|
||||
GetPost("/update", new(UpdateAction)).
|
||||
Get("/install", new(InstallAction)).
|
||||
Get("/logs", new(LogsAction)).
|
||||
|
||||
EndAll()
|
||||
})
|
||||
|
||||
71
internal/web/actions/default/api/node/logs.go
Normal file
71
internal/web/actions/default/api/node/logs.go
Normal file
@@ -0,0 +1,71 @@
|
||||
package node
|
||||
|
||||
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 LogsAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *LogsAction) Init() {
|
||||
this.Nav("", "node", "log")
|
||||
this.SecondMenu("nodes")
|
||||
}
|
||||
|
||||
func (this *LogsAction) RunGet(params struct {
|
||||
NodeId int64
|
||||
}) {
|
||||
apiNodeResp, err := this.RPC().APINodeRPC().FindEnabledAPINode(this.AdminContext(), &pb.FindEnabledAPINodeRequest{NodeId: params.NodeId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
apiNode := apiNodeResp.Node
|
||||
if apiNode == nil {
|
||||
this.NotFound("apiNode", params.NodeId)
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["node"] = maps.Map{
|
||||
"id": apiNode.Id,
|
||||
"name": apiNode.Name,
|
||||
}
|
||||
|
||||
countResp, err := this.RPC().NodeLogRPC().CountNodeLogs(this.AdminContext(), &pb.CountNodeLogsRequest{
|
||||
Role: "api",
|
||||
NodeId: params.NodeId,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
count := countResp.Count
|
||||
page := this.NewPage(count, 20)
|
||||
|
||||
logsResp, err := this.RPC().NodeLogRPC().ListNodeLogs(this.AdminContext(), &pb.ListNodeLogsRequest{
|
||||
NodeId: params.NodeId,
|
||||
Role: "api",
|
||||
Offset: page.Offset,
|
||||
Size: page.Size,
|
||||
})
|
||||
|
||||
logs := []maps.Map{}
|
||||
for _, log := range logsResp.NodeLogs {
|
||||
logs = append(logs, maps.Map{
|
||||
"tag": log.Tag,
|
||||
"description": log.Description,
|
||||
"createdTime": timeutil.FormatTime("Y-m-d H:i:s", log.CreatedAt),
|
||||
"level": log.Level,
|
||||
"isToday": timeutil.FormatTime("Y-m-d", log.CreatedAt) == timeutil.Format("Y-m-d"),
|
||||
})
|
||||
}
|
||||
this.Data["logs"] = logs
|
||||
|
||||
this.Data["page"] = page.AsHTML()
|
||||
|
||||
this.Show()
|
||||
}
|
||||
78
internal/web/actions/default/users/features.go
Normal file
78
internal/web/actions/default/users/features.go
Normal file
@@ -0,0 +1,78 @@
|
||||
package users
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/users/userutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/lists"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type FeaturesAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *FeaturesAction) Init() {
|
||||
this.Nav("", "", "feature")
|
||||
}
|
||||
|
||||
func (this *FeaturesAction) RunGet(params struct {
|
||||
UserId int64
|
||||
}) {
|
||||
err := userutils.InitUser(this.Parent(), params.UserId)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
featuresResp, err := this.RPC().UserRPC().FindAllUserFeatureDefinitions(this.AdminContext(), &pb.FindAllUserFeatureDefinitionsRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
allFeatures := featuresResp.Features
|
||||
|
||||
userFeaturesResp, err := this.RPC().UserRPC().FindUserFeatures(this.AdminContext(), &pb.FindUserFeaturesRequest{UserId: params.UserId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
userFeatureCodes := []string{}
|
||||
for _, userFeature := range userFeaturesResp.Features {
|
||||
userFeatureCodes = append(userFeatureCodes, userFeature.Code)
|
||||
}
|
||||
|
||||
featureMaps := []maps.Map{}
|
||||
for _, feature := range allFeatures {
|
||||
featureMaps = append(featureMaps, maps.Map{
|
||||
"name": feature.Name,
|
||||
"code": feature.Code,
|
||||
"description": feature.Description,
|
||||
"isChecked": lists.ContainsString(userFeatureCodes, feature.Code),
|
||||
})
|
||||
}
|
||||
this.Data["features"] = featureMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *FeaturesAction) RunPost(params struct {
|
||||
UserId int64
|
||||
Codes []string
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
defer this.CreateLogInfo("设置用户 %d 的功能列表", params.UserId)
|
||||
|
||||
_, err := this.RPC().UserRPC().UpdateUserFeatures(this.AdminContext(), &pb.UpdateUserFeaturesRequest{
|
||||
UserId: params.UserId,
|
||||
FeatureCodes: params.Codes,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Success()
|
||||
}
|
||||
@@ -17,6 +17,7 @@ func init() {
|
||||
Get("/user", new(UserAction)).
|
||||
GetPost("/update", new(UpdateAction)).
|
||||
Post("/delete", new(DeleteAction)).
|
||||
GetPost("/features", new(FeaturesAction)).
|
||||
EndAll()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
<menu-item href="/api">节点列表</menu-item>
|
||||
<span class="item">|</span>
|
||||
<menu-item :href="'/api/node?nodeId=' + node.id" code="index">"{{node.name}}"详情</menu-item>
|
||||
<menu-item :href="'/api/node/logs?nodeId=' + node.id" code="log">运行日志</menu-item>
|
||||
<menu-item :href="'/api/node/install?nodeId=' + node.id" code="install">安装节点</menu-item>
|
||||
<menu-item :href="'/api/node/update?nodeId=' + node.id" code="update">修改节点</menu-item>
|
||||
</first-menu>
|
||||
|
||||
5
web/views/@default/api/node/logs.css
Normal file
5
web/views/@default/api/node/logs.css
Normal file
@@ -0,0 +1,5 @@
|
||||
pre.log-box {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
/*# sourceMappingURL=logs.css.map */
|
||||
1
web/views/@default/api/node/logs.css.map
Normal file
1
web/views/@default/api/node/logs.css.map
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["logs.less"],"names":[],"mappings":"AAAA,GAAG;EACF,SAAA;EACA,UAAA","file":"logs.css"}
|
||||
20
web/views/@default/api/node/logs.html
Normal file
20
web/views/@default/api/node/logs.html
Normal file
@@ -0,0 +1,20 @@
|
||||
{$layout}
|
||||
|
||||
{$template "menu"}
|
||||
|
||||
<p class="comment" v-if="logs.length == 0">暂时还没有日志。</p>
|
||||
|
||||
<table class="ui table selectable" v-if="logs.length > 0">
|
||||
<thead>
|
||||
<tr>
|
||||
|
||||
</tr>
|
||||
</thead>
|
||||
<tr v-for="log in logs">
|
||||
<td>
|
||||
<pre class="log-box"><span :class="{red:log.level == 'error', yellow:log.level == 'warning'}"><span v-if="!log.isToday">[{{log.createdTime}}]</span><strong v-if="log.isToday">[{{log.createdTime}}]</strong>[{{log.tag}}]{{log.description}}</span></pre>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<div class="page" v-html="page"></div>
|
||||
4
web/views/@default/api/node/logs.less
Normal file
4
web/views/@default/api/node/logs.less
Normal file
@@ -0,0 +1,4 @@
|
||||
pre.log-box {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
@@ -3,4 +3,5 @@
|
||||
<span class="item">|</span>
|
||||
<menu-item :href="'/users/user?userId=' + user.id" code="index">{{user.fullname}} <span class="small">({{user.username}})</span></menu-item>
|
||||
<menu-item :href="'/users/update?userId=' + user.id" code="update">修改</menu-item>
|
||||
<menu-item :href="'/users/features?userId=' + user.id" code="feature">功能</menu-item>
|
||||
</first-menu>
|
||||
4
web/views/@default/users/features.css
Normal file
4
web/views/@default/users/features.css
Normal file
@@ -0,0 +1,4 @@
|
||||
.feature-boxes .feature-box {
|
||||
margin-bottom: 0.7em;
|
||||
}
|
||||
/*# sourceMappingURL=features.css.map */
|
||||
1
web/views/@default/users/features.css.map
Normal file
1
web/views/@default/users/features.css.map
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["features.less"],"names":[],"mappings":"AAAA,cACC;EACC,oBAAA","file":"features.css"}
|
||||
24
web/views/@default/users/features.html
Normal file
24
web/views/@default/users/features.html
Normal file
@@ -0,0 +1,24 @@
|
||||
{$layout}
|
||||
{$template "user_menu"}
|
||||
|
||||
<div class="margin"></div>
|
||||
|
||||
<form class="ui form" data-tea-success="success" data-tea-action="$">
|
||||
<csrf-token></csrf-token>
|
||||
<input type="hidden" name="userId" :value="user.id"/>
|
||||
|
||||
<table class="ui table definition selectable">
|
||||
<tr>
|
||||
<td class="title">功能列表</td>
|
||||
<td>
|
||||
<div class="feature-boxes">
|
||||
<div class="feature-box" v-for="feature in features">
|
||||
<checkbox name="codes" :v-value="feature.code" v-model="feature.isChecked">{{feature.name}}</checkbox>
|
||||
<p class="comment">{{feature.description}}</p>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<submit-btn></submit-btn>
|
||||
</form>
|
||||
3
web/views/@default/users/features.js
Normal file
3
web/views/@default/users/features.js
Normal file
@@ -0,0 +1,3 @@
|
||||
Tea.context(function () {
|
||||
this.success = NotifyReloadSuccess("保存成功")
|
||||
})
|
||||
5
web/views/@default/users/features.less
Normal file
5
web/views/@default/users/features.less
Normal file
@@ -0,0 +1,5 @@
|
||||
.feature-boxes {
|
||||
.feature-box {
|
||||
margin-bottom: 0.7em;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user