mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-03 12:20:28 +08:00
增加消息管理
This commit is contained in:
2
go.mod
2
go.mod
@@ -8,7 +8,7 @@ require (
|
|||||||
github.com/TeaOSLab/EdgeCommon v0.0.0-00010101000000-000000000000
|
github.com/TeaOSLab/EdgeCommon v0.0.0-00010101000000-000000000000
|
||||||
github.com/go-sql-driver/mysql v1.5.0
|
github.com/go-sql-driver/mysql v1.5.0
|
||||||
github.com/go-yaml/yaml v2.1.0+incompatible
|
github.com/go-yaml/yaml v2.1.0+incompatible
|
||||||
github.com/iwind/TeaGo v0.0.0-20201010005321-430e836dee8a
|
github.com/iwind/TeaGo v0.0.0-20201020081413-7cf62d6f420f
|
||||||
golang.org/x/sys v0.0.0-20200724161237-0e2f3a69832c // indirect
|
golang.org/x/sys v0.0.0-20200724161237-0e2f3a69832c // indirect
|
||||||
google.golang.org/grpc v1.32.0
|
google.golang.org/grpc v1.32.0
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776
|
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776
|
||||||
|
|||||||
2
go.sum
2
go.sum
@@ -50,6 +50,8 @@ github.com/iwind/TeaGo v0.0.0-20200923021120-f5d76441fe9e h1:/xn7wUvlwaoA5IkdBUc
|
|||||||
github.com/iwind/TeaGo v0.0.0-20200923021120-f5d76441fe9e/go.mod h1:KU4mS7QNiZ7QWEuDBk1zw0/Q2LrAPZv3tycEFBsuUwc=
|
github.com/iwind/TeaGo v0.0.0-20200923021120-f5d76441fe9e/go.mod h1:KU4mS7QNiZ7QWEuDBk1zw0/Q2LrAPZv3tycEFBsuUwc=
|
||||||
github.com/iwind/TeaGo v0.0.0-20201010005321-430e836dee8a h1:sO6uDbQOEe6/tIB3o31vn6eD/JmkKGErKgcOA/Cpb+Q=
|
github.com/iwind/TeaGo v0.0.0-20201010005321-430e836dee8a h1:sO6uDbQOEe6/tIB3o31vn6eD/JmkKGErKgcOA/Cpb+Q=
|
||||||
github.com/iwind/TeaGo v0.0.0-20201010005321-430e836dee8a/go.mod h1:KU4mS7QNiZ7QWEuDBk1zw0/Q2LrAPZv3tycEFBsuUwc=
|
github.com/iwind/TeaGo v0.0.0-20201010005321-430e836dee8a/go.mod h1:KU4mS7QNiZ7QWEuDBk1zw0/Q2LrAPZv3tycEFBsuUwc=
|
||||||
|
github.com/iwind/TeaGo v0.0.0-20201020081413-7cf62d6f420f h1:6Ws2H+eorfVUoMO2jta6A9nIdh8oi5/5LXo/LkAxR+E=
|
||||||
|
github.com/iwind/TeaGo v0.0.0-20201020081413-7cf62d6f420f/go.mod h1:KU4mS7QNiZ7QWEuDBk1zw0/Q2LrAPZv3tycEFBsuUwc=
|
||||||
github.com/json-iterator/go v1.1.10 h1:Kz6Cvnvv2wGdaG/V8yMvfkmNiXq9Ya2KUv4rouJJr68=
|
github.com/json-iterator/go v1.1.10 h1:Kz6Cvnvv2wGdaG/V8yMvfkmNiXq9Ya2KUv4rouJJr68=
|
||||||
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||||
|
|||||||
@@ -175,6 +175,10 @@ func (this *RPCClient) SysSettingRPC() pb.SysSettingServiceClient {
|
|||||||
return pb.NewSysSettingServiceClient(this.pickConn())
|
return pb.NewSysSettingServiceClient(this.pickConn())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *RPCClient) MessageRPC() pb.MessageServiceClient {
|
||||||
|
return pb.NewMessageServiceClient(this.pickConn())
|
||||||
|
}
|
||||||
|
|
||||||
// 构造Admin上下文
|
// 构造Admin上下文
|
||||||
func (this *RPCClient) Context(adminId int64) context.Context {
|
func (this *RPCClient) Context(adminId int64) context.Context {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|||||||
22
internal/web/actions/default/messages/badge.go
Normal file
22
internal/web/actions/default/messages/badge.go
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package messages
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
)
|
||||||
|
|
||||||
|
type BadgeAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *BadgeAction) RunPost(params struct{}) {
|
||||||
|
countResp, err := this.RPC().MessageRPC().CountUnreadMessages(this.AdminContext(), &pb.CountUnreadMessagesRequest{})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Data["count"] = countResp.Count
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
11
internal/web/actions/default/messages/helper.go
Normal file
11
internal/web/actions/default/messages/helper.go
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
package messages
|
||||||
|
|
||||||
|
import "github.com/iwind/TeaGo/actions"
|
||||||
|
|
||||||
|
type Helper struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *Helper) BeforeAction(actionPtr actions.ActionWrapper) {
|
||||||
|
action := actionPtr.Object()
|
||||||
|
action.Data["teaMenu"] = "message"
|
||||||
|
}
|
||||||
65
internal/web/actions/default/messages/index.go
Normal file
65
internal/web/actions/default/messages/index.go
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
package messages
|
||||||
|
|
||||||
|
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{}) {
|
||||||
|
countResp, err := this.RPC().MessageRPC().CountUnreadMessages(this.AdminContext(), &pb.CountUnreadMessagesRequest{})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
count := countResp.Count
|
||||||
|
|
||||||
|
page := this.NewPage(count)
|
||||||
|
this.Data["page"] = page.AsHTML()
|
||||||
|
|
||||||
|
listResp, err := this.RPC().MessageRPC().ListUnreadMessages(this.AdminContext(), &pb.ListUnreadMessagesRequest{
|
||||||
|
Offset: page.Offset,
|
||||||
|
Size: page.Size,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
messages := []maps.Map{}
|
||||||
|
for _, message := range listResp.Messages {
|
||||||
|
clusterMap := maps.Map{}
|
||||||
|
if message.Cluster != nil {
|
||||||
|
clusterMap = maps.Map{
|
||||||
|
"id": message.Cluster.Id,
|
||||||
|
"name": message.Cluster.Name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nodeMap := maps.Map{}
|
||||||
|
|
||||||
|
messages = append(messages, maps.Map{
|
||||||
|
"id": message.Id,
|
||||||
|
"isRead": message.IsRead,
|
||||||
|
"body": message.Body,
|
||||||
|
"level": message.Level,
|
||||||
|
"datetime": timeutil.FormatTime("Y-m-d H:i:s", message.CreatedAt),
|
||||||
|
"params": string(message.ParamsJSON),
|
||||||
|
"type": message.Type,
|
||||||
|
"cluster": clusterMap,
|
||||||
|
"node": nodeMap,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
this.Data["messages"] = messages
|
||||||
|
|
||||||
|
this.Show()
|
||||||
|
}
|
||||||
20
internal/web/actions/default/messages/init.go
Normal file
20
internal/web/actions/default/messages/init.go
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
package messages
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
|
||||||
|
"github.com/iwind/TeaGo"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
TeaGo.BeforeStart(func(server *TeaGo.Server) {
|
||||||
|
server.
|
||||||
|
Helper(new(helpers.UserMustAuth)).
|
||||||
|
Helper(new(Helper)).
|
||||||
|
Prefix("/messages").
|
||||||
|
GetPost("", new(IndexAction)).
|
||||||
|
Post("/badge", new(BadgeAction)).
|
||||||
|
Post("/readAll", new(ReadAllAction)).
|
||||||
|
Post("/readPage", new(ReadPageAction)).
|
||||||
|
EndAll()
|
||||||
|
})
|
||||||
|
}
|
||||||
20
internal/web/actions/default/messages/readAll.go
Normal file
20
internal/web/actions/default/messages/readAll.go
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
package messages
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ReadAllAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ReadAllAction) RunPost(params struct{}) {
|
||||||
|
_, err := this.RPC().MessageRPC().UpdateAllMessagesRead(this.AdminContext(), &pb.UpdateAllMessagesReadRequest{})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
25
internal/web/actions/default/messages/readPage.go
Normal file
25
internal/web/actions/default/messages/readPage.go
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package messages
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ReadPageAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ReadPageAction) RunPost(params struct {
|
||||||
|
MessageIds []int64
|
||||||
|
}) {
|
||||||
|
_, err := this.RPC().MessageRPC().UpdateMessagesRead(this.AdminContext(), &pb.UpdateMessagesReadRequest{
|
||||||
|
MessageIds: params.MessageIds,
|
||||||
|
IsRead: true,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
@@ -13,6 +13,7 @@ import (
|
|||||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/index"
|
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/index"
|
||||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/log"
|
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/log"
|
||||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/logout"
|
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/logout"
|
||||||
|
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/messages"
|
||||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/nodes"
|
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/nodes"
|
||||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers"
|
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers"
|
||||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/components"
|
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/components"
|
||||||
|
|||||||
38
web/public/js/components/messages/message-row.js
Normal file
38
web/public/js/components/messages/message-row.js
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
Vue.component("message-row", {
|
||||||
|
props: ["v-message"],
|
||||||
|
data: function () {
|
||||||
|
let paramsJSON = this.vMessage.params
|
||||||
|
let params = null
|
||||||
|
if (paramsJSON != null && paramsJSON.length > 0) {
|
||||||
|
params = JSON.parse(paramsJSON)
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
message: this.vMessage,
|
||||||
|
params: params
|
||||||
|
}
|
||||||
|
},
|
||||||
|
template: `<div>
|
||||||
|
<table class="ui table selectable">
|
||||||
|
<tr :class="{error: message.level == 'error'}">
|
||||||
|
<td>
|
||||||
|
<strong>{{message.datetime}}</strong>
|
||||||
|
<span v-if="message.cluster != null && message.cluster.id != null">
|
||||||
|
<span> | </span>
|
||||||
|
<a :href="'/clusters/cluster?clusterId=' + message.cluster.id">集群:{{message.cluster.name}}</a>
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr :class="{error: message.level == 'error'}">
|
||||||
|
<td>
|
||||||
|
{{message.body}}
|
||||||
|
|
||||||
|
<div v-if="message.type == 'HealthCheckFail'" style="margin-top: 0.8em">
|
||||||
|
<a :href="'/clusters/cluster/node?clusterId=' + message.cluster.id + '&nodeId=' + param.node.id" v-for="param in params" class="ui label tiny">{{param.node.name}}</a>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<div class="margin"></div>
|
||||||
|
</div>`
|
||||||
|
})
|
||||||
@@ -28,7 +28,7 @@
|
|||||||
|
|
||||||
<div class="right menu">
|
<div class="right menu">
|
||||||
<a href="" class="item" v-if="globalChangedClusters.length > 0" @click.prevent="syncClustersConfigs()"><i class="icon refresh"></i>{{globalChangedClusters.length}}个集群服务已变更,点此同步</a>
|
<a href="" class="item" v-if="globalChangedClusters.length > 0" @click.prevent="syncClustersConfigs()"><i class="icon refresh"></i>{{globalChangedClusters.length}}个集群服务已变更,点此同步</a>
|
||||||
<a href="/monitor/messages" class="item" v-if="teaBadge > 0"><span :class="{'blink':teaBadge > 0}"><i class="icon bell"></i>告警({{teaBadge}}) </span></a>
|
<a href="/messages" class="item" :class="{active:teaMenu == 'message'}"><span :class="{'blink':globalMessageBadge > 0}"><i class="icon bell"></i>消息({{globalMessageBadge}}) </span></a>
|
||||||
<a href="/settings/profile" class="item" :class="{active: teaMenu == 'settings'}">
|
<a href="/settings/profile" class="item" :class="{active: teaMenu == 'settings'}">
|
||||||
<i class="icon user" v-if="teaUserAvatar.length == 0"></i>
|
<i class="icon user" v-if="teaUserAvatar.length == 0"></i>
|
||||||
<img class="avatar" alt="" :src="teaUserAvatar" v-if="teaUserAvatar.length > 0"/>
|
<img class="avatar" alt="" :src="teaUserAvatar" v-if="teaUserAvatar.length > 0"/>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
Tea.context(function () {
|
Tea.context(function () {
|
||||||
this.moreOptionsVisible = false
|
this.moreOptionsVisible = false
|
||||||
this.globalChangedClusters = []
|
this.globalChangedClusters = []
|
||||||
|
this.globalMessageBadge = 0
|
||||||
this.teaDemoEnabled = false
|
this.teaDemoEnabled = false
|
||||||
|
|
||||||
if (typeof this.leftMenuItemIsDisabled == "undefined") {
|
if (typeof this.leftMenuItemIsDisabled == "undefined") {
|
||||||
@@ -14,6 +15,9 @@ Tea.context(function () {
|
|||||||
|
|
||||||
// 检查变更
|
// 检查变更
|
||||||
this.checkClusterChanges()
|
this.checkClusterChanges()
|
||||||
|
|
||||||
|
// 检查消息
|
||||||
|
this.checkMessages()
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -58,7 +62,27 @@ Tea.context(function () {
|
|||||||
this.checkClusterChanges()
|
this.checkClusterChanges()
|
||||||
}, delay)
|
}, delay)
|
||||||
})
|
})
|
||||||
};
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查消息
|
||||||
|
*/
|
||||||
|
this.checkMessages = function () {
|
||||||
|
this.$post("/messages/badge")
|
||||||
|
.params({})
|
||||||
|
.success(function (resp) {
|
||||||
|
this.globalMessageBadge = resp.data.count
|
||||||
|
})
|
||||||
|
.done(function () {
|
||||||
|
let delay = 6000
|
||||||
|
if (this.globalMessageBadge > 0) {
|
||||||
|
delay = 30000
|
||||||
|
}
|
||||||
|
this.$delay(function () {
|
||||||
|
this.checkMessages()
|
||||||
|
}, delay)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 同步集群配置
|
* 同步集群配置
|
||||||
|
|||||||
13
web/views/@default/messages/index.html
Normal file
13
web/views/@default/messages/index.html
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
{$layout}
|
||||||
|
|
||||||
|
<first-menu v-if="messages.length > 0">
|
||||||
|
<a href="" class="item" @click.prevent="updatePageRead()">[设置当前页为已读]</a>
|
||||||
|
<a href="" class="item" @click.prevent="updateAllRead()">[设置全部为已读]</a>
|
||||||
|
</first-menu>
|
||||||
|
<div class="margin"></div>
|
||||||
|
|
||||||
|
<p class="comment" v-if="messages.length == 0">暂时还没有消息。</p>
|
||||||
|
|
||||||
|
<message-row v-for="message in messages" :v-message="message" :key="message.id"></message-row>
|
||||||
|
|
||||||
|
<div class="page" v-html="page"></div>
|
||||||
26
web/views/@default/messages/index.js
Normal file
26
web/views/@default/messages/index.js
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
Tea.context(function () {
|
||||||
|
this.updateAllRead = function () {
|
||||||
|
let that = this
|
||||||
|
teaweb.confirm("确定要设置所有的未读消息为已读吗?", function () {
|
||||||
|
that.$post("/messages/readAll")
|
||||||
|
.success(function () {
|
||||||
|
window.location = "/messages"
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
this.updatePageRead = function () {
|
||||||
|
let that = this
|
||||||
|
teaweb.confirm("确定要设置当前页的未读消息为已读吗?", function () {
|
||||||
|
let messageIds = []
|
||||||
|
that.messages.forEach(function (v) {
|
||||||
|
messageIds.push(v.id)
|
||||||
|
})
|
||||||
|
that.$post("/messages/readPage")
|
||||||
|
.params({
|
||||||
|
messageIds: messageIds
|
||||||
|
})
|
||||||
|
.refresh()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user