Initial commit (code only without large binaries)
This commit is contained in:
74
EdgeUser/internal/web/actions/default/tickets/createPopup.go
Normal file
74
EdgeUser/internal/web/actions/default/tickets/createPopup.go
Normal file
@@ -0,0 +1,74 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package tickets
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type CreatePopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) RunGet(params struct{}) {
|
||||
// 分类
|
||||
categoriesResp, err := this.RPC().UserTicketCategoryRPC().FindAllAvailableUserTicketCategories(this.UserContext(), &pb.FindAllAvailableUserTicketCategoriesRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var categories = categoriesResp.UserTicketCategories
|
||||
var categoryMaps = []maps.Map{}
|
||||
for _, category := range categories {
|
||||
categoryMaps = append(categoryMaps, maps.Map{
|
||||
"id": category.Id,
|
||||
"name": category.Name,
|
||||
})
|
||||
}
|
||||
this.Data["categories"] = categoryMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) RunPost(params struct {
|
||||
CategoryId int64
|
||||
Subject string
|
||||
Body string
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
var ticketId int64
|
||||
defer func() {
|
||||
this.CreateLogInfo(codes.UserTicket_LogCreateUserTicket, ticketId)
|
||||
}()
|
||||
|
||||
params.Must.
|
||||
Field("subject", params.Subject).
|
||||
Require("请输入工单标题").
|
||||
MaxCharacters(100, "标题最大长度不能超过100").
|
||||
Field("body", params.Body).
|
||||
Require("请输入工单内容")
|
||||
|
||||
createResp, err := this.RPC().UserTicketRPC().CreateUserTicket(this.UserContext(), &pb.CreateUserTicketRequest{
|
||||
UserTicketCategoryId: params.CategoryId,
|
||||
Subject: params.Subject,
|
||||
Body: params.Body,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
ticketId = createResp.UserTicketId
|
||||
|
||||
this.Success()
|
||||
}
|
||||
121
EdgeUser/internal/web/actions/default/tickets/index.go
Normal file
121
EdgeUser/internal/web/actions/default/tickets/index.go
Normal file
@@ -0,0 +1,121 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package tickets
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
type IndexAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *IndexAction) Init() {
|
||||
var status = this.Request.URL.Query().Get("status")
|
||||
if len(status) == 0 {
|
||||
status = "none"
|
||||
}
|
||||
this.Nav("", "", status)
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct {
|
||||
Status string
|
||||
CategoryId int64
|
||||
}) {
|
||||
if len(params.Status) == 0 {
|
||||
params.Status = "none"
|
||||
}
|
||||
|
||||
this.Data["status"] = params.Status
|
||||
this.Data["categoryId"] = params.CategoryId
|
||||
this.Data["currentURL"] = url.QueryEscape(this.Request.URL.String())
|
||||
|
||||
// 处于新状态的数字
|
||||
countNewTicketsResp, err := this.RPC().UserTicketRPC().CountUserTickets(this.UserContext(), &pb.CountUserTicketsRequest{
|
||||
Status: userconfigs.UserTicketStatusNone,
|
||||
UserTicketCategoryId: params.CategoryId,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var countNewTickets = countNewTicketsResp.Count
|
||||
this.Data["countNewTickets"] = countNewTickets
|
||||
|
||||
// 列表
|
||||
var page *actionutils.Page
|
||||
if params.Status == userconfigs.UserTicketStatusNone {
|
||||
page = this.NewPage(countNewTickets)
|
||||
} else {
|
||||
countTicketsRPC, err := this.RPC().UserTicketRPC().CountUserTickets(this.UserContext(), &pb.CountUserTicketsRequest{
|
||||
UserId: this.UserId(),
|
||||
UserTicketCategoryId: params.CategoryId,
|
||||
Status: params.Status,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var count = countTicketsRPC.Count
|
||||
page = this.NewPage(count)
|
||||
}
|
||||
|
||||
this.Data["page"] = page.AsHTML()
|
||||
|
||||
// 工单列表
|
||||
ticketsResp, err := this.RPC().UserTicketRPC().ListUserTickets(this.UserContext(), &pb.ListUserTicketsRequest{
|
||||
UserId: this.UserId(),
|
||||
UserTicketCategoryId: params.CategoryId,
|
||||
Status: params.Status,
|
||||
Offset: page.Offset,
|
||||
Size: page.Size,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var ticketMaps = []maps.Map{}
|
||||
for _, ticket := range ticketsResp.UserTickets {
|
||||
// category
|
||||
var categoryMap maps.Map
|
||||
if ticket.UserTicketCategory != nil {
|
||||
categoryMap = maps.Map{
|
||||
"id": ticket.UserTicketCategory.Id,
|
||||
"name": ticket.UserTicketCategory.Name,
|
||||
}
|
||||
}
|
||||
|
||||
// latest log
|
||||
var latestLogMap maps.Map
|
||||
if ticket.LatestUserTicketLog != nil {
|
||||
var logAdminMap maps.Map
|
||||
if ticket.LatestUserTicketLog.Admin != nil {
|
||||
logAdminMap = maps.Map{
|
||||
"id": ticket.LatestUserTicketLog.Admin.Id,
|
||||
}
|
||||
}
|
||||
latestLogMap = maps.Map{
|
||||
"admin": logAdminMap,
|
||||
}
|
||||
}
|
||||
|
||||
ticketMaps = append(ticketMaps, maps.Map{
|
||||
"id": ticket.Id,
|
||||
"subject": ticket.Subject,
|
||||
"category": categoryMap,
|
||||
"createdTime": timeutil.FormatTime("Y-m-d H:i:s", ticket.CreatedAt),
|
||||
"status": ticket.Status,
|
||||
"statusName": userconfigs.UserTicketStatusName(ticket.Status),
|
||||
"lastLogTime": timeutil.FormatTime("Y-m-d H:i:s", ticket.LastLogAt),
|
||||
"latestLog": latestLogMap,
|
||||
})
|
||||
}
|
||||
this.Data["tickets"] = ticketMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
33
EdgeUser/internal/web/actions/default/tickets/init.go
Normal file
33
EdgeUser/internal/web/actions/default/tickets/init.go
Normal file
@@ -0,0 +1,33 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package tickets
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/default/tickets/ticket"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/helpers"
|
||||
"github.com/iwind/TeaGo"
|
||||
)
|
||||
|
||||
func init() {
|
||||
TeaGo.BeforeStart(func(server *TeaGo.Server) {
|
||||
server.
|
||||
Helper(helpers.NewUserMustAuth("")).
|
||||
Data("teaMenu", "tickets").
|
||||
|
||||
// 工单列表
|
||||
Prefix("/tickets").
|
||||
Get("", new(IndexAction)).
|
||||
GetPost("/createPopup", new(CreatePopupAction)).
|
||||
|
||||
// 工单
|
||||
Prefix("/tickets/ticket").
|
||||
Get("", new(ticket.IndexAction)).
|
||||
GetPost("/updatePopup", new(ticket.UpdatePopupAction)).
|
||||
GetPost("/createLogPopup", new(ticket.CreateLogPopupAction)).
|
||||
Post("/deleteLog", new(ticket.DeleteLogAction)).
|
||||
Post("/delete", new(ticket.DeleteAction)).
|
||||
|
||||
//
|
||||
EndAll()
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package ticket
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
)
|
||||
|
||||
type CreateLogPopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *CreateLogPopupAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *CreateLogPopupAction) RunGet(params struct {
|
||||
TicketId int64
|
||||
}) {
|
||||
this.Data["ticketId"] = params.TicketId
|
||||
|
||||
this.Data["statusList"] = userconfigs.FindAllUserTicketStatusList()
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *CreateLogPopupAction) RunPost(params struct {
|
||||
TicketId int64
|
||||
Comment string
|
||||
Status string
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.UserTicketLog_LogReplyTicket, params.TicketId)
|
||||
|
||||
_, err := this.RPC().UserTicketLogRPC().CreateUserTicketLog(this.UserContext(), &pb.CreateUserTicketLogRequest{
|
||||
UserTicketId: params.TicketId,
|
||||
Status: params.Status,
|
||||
Comment: params.Comment,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package ticket
|
||||
|
||||
import "github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
|
||||
type DeleteAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *DeleteAction) RunPost(params struct{}) {
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package ticket
|
||||
|
||||
import "github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
|
||||
type DeleteLogAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *DeleteLogAction) RunPost(params struct{}) {
|
||||
this.Success()
|
||||
}
|
||||
114
EdgeUser/internal/web/actions/default/tickets/ticket/index.go
Normal file
114
EdgeUser/internal/web/actions/default/tickets/ticket/index.go
Normal file
@@ -0,0 +1,114 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package ticket
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||
"html"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type IndexAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *IndexAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct {
|
||||
TicketId int64
|
||||
FromURL string
|
||||
}) {
|
||||
this.Data["fromURL"] = params.FromURL
|
||||
|
||||
// 工单信息
|
||||
ticketResp, err := this.RPC().UserTicketRPC().FindUserTicket(this.UserContext(), &pb.FindUserTicketRequest{UserTicketId: params.TicketId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var ticket = ticketResp.UserTicket
|
||||
if ticket == nil {
|
||||
return
|
||||
}
|
||||
|
||||
// category
|
||||
var categoryMap maps.Map
|
||||
if ticket.UserTicketCategory != nil {
|
||||
categoryMap = maps.Map{
|
||||
"id": ticket.UserTicketCategory.Id,
|
||||
"name": ticket.UserTicketCategory.Name,
|
||||
}
|
||||
}
|
||||
|
||||
// user
|
||||
var userMap maps.Map
|
||||
if ticket.User != nil {
|
||||
userMap = maps.Map{
|
||||
"id": ticket.User.Id,
|
||||
"username": ticket.User.Username,
|
||||
"fullname": ticket.User.Fullname,
|
||||
}
|
||||
}
|
||||
|
||||
this.Data["ticket"] = maps.Map{
|
||||
"id": ticket.Id,
|
||||
"subject": ticket.Subject,
|
||||
"body": this.formatText(ticket.Body),
|
||||
"createdTime": timeutil.FormatTime("Y-m-d H:i:s", ticket.CreatedAt),
|
||||
"lastLogTime": timeutil.FormatTime("Y-m-d H:i:s", ticket.LastLogAt),
|
||||
"status": ticket.Status,
|
||||
"statusName": userconfigs.UserTicketStatusName(ticket.Status),
|
||||
"category": categoryMap,
|
||||
"user": userMap,
|
||||
}
|
||||
|
||||
// 工单处理日志
|
||||
countLogsResp, err := this.RPC().UserTicketLogRPC().CountUserTicketLogs(this.UserContext(), &pb.CountUserTicketLogsRequest{UserTicketId: params.TicketId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var countLogs = countLogsResp.Count
|
||||
var page = this.NewPage(countLogs)
|
||||
this.Data["page"] = page.AsHTML()
|
||||
|
||||
logsResp, err := this.RPC().UserTicketLogRPC().ListUserTicketLogs(this.UserContext(), &pb.ListUserTicketLogsRequest{
|
||||
UserTicketId: params.TicketId,
|
||||
Offset: page.Offset,
|
||||
Size: page.Size,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var logMaps = []maps.Map{}
|
||||
for _, log := range logsResp.UserTicketLogs {
|
||||
logMaps = append(logMaps, maps.Map{
|
||||
"id": log.Id,
|
||||
"comment": this.formatText(log.Comment),
|
||||
"createdTime": timeutil.FormatTime("Y-m-d H:i:s", log.CreatedAt),
|
||||
"status": log.Status,
|
||||
"statusName": userconfigs.UserTicketStatusName(log.Status),
|
||||
"userId": log.UserId,
|
||||
"adminId": log.AdminId,
|
||||
})
|
||||
}
|
||||
this.Data["logs"] = logMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *IndexAction) formatText(s string) string {
|
||||
s = html.EscapeString(s)
|
||||
s = strings.ReplaceAll(s, " ", " ")
|
||||
s = strings.ReplaceAll(s, "\t", " ")
|
||||
s = strings.ReplaceAll(s, "\n", "<br/>\n")
|
||||
return s
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package ticket
|
||||
|
||||
import "github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
|
||||
type UpdatePopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *UpdatePopupAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *UpdatePopupAction) RunGet(params struct{}) {
|
||||
this.Show()
|
||||
}
|
||||
Reference in New Issue
Block a user