服务分组增加特殊页面设置

This commit is contained in:
刘祥超
2021-10-10 10:52:58 +08:00
parent 32b8c91113
commit af440e5c5b
7 changed files with 136 additions and 5 deletions

View File

@@ -107,6 +107,12 @@ func InitGroup(parent *actionutils.ParentAction, groupId int64, menuItem string)
"isActive": menuItem == "compression", "isActive": menuItem == "compression",
"isOn": configInfoResp.HasCompressionConfig, "isOn": configInfoResp.HasCompressionConfig,
}, },
{
"name": "特殊页面",
"url": urlPrefix + "/pages?groupId=" + types.String(groupId),
"isActive": menuItem == "pages",
"isOn": configInfoResp.HasPagesConfig,
},
{ {
"name": "HTTP Header", "name": "HTTP Header",
"url": urlPrefix + "/headers?groupId=" + types.String(groupId), "url": urlPrefix + "/headers?groupId=" + types.String(groupId),

View File

@@ -0,0 +1,73 @@
package pages
import (
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/groups/group/servergrouputils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions"
)
type IndexAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
this.Nav("", "setting", "index")
this.SecondMenu("pages")
}
func (this *IndexAction) RunGet(params struct {
GroupId int64
}) {
_, err := servergrouputils.InitGroup(this.Parent(), params.GroupId, "pages")
if err != nil {
this.ErrorPage(err)
return
}
webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithServerGroupId(this.AdminContext(), params.GroupId)
if err != nil {
this.ErrorPage(err)
return
}
this.Data["webId"] = webConfig.Id
this.Data["pages"] = webConfig.Pages
this.Data["shutdownConfig"] = webConfig.Shutdown
this.Show()
}
func (this *IndexAction) RunPost(params struct {
WebId int64
PagesJSON string
ShutdownJSON string
Must *actions.Must
}) {
// 日志
defer this.CreateLog(oplogs.LevelInfo, "修改Web %d 的设置", params.WebId)
// TODO 检查配置
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWebPages(this.AdminContext(), &pb.UpdateHTTPWebPagesRequest{
WebId: params.WebId,
PagesJSON: []byte(params.PagesJSON),
})
if err != nil {
this.ErrorPage(err)
return
}
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebShutdown(this.AdminContext(), &pb.UpdateHTTPWebShutdownRequest{
WebId: params.WebId,
ShutdownJSON: []byte(params.ShutdownJSON),
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -0,0 +1,19 @@
package pages
import (
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
"github.com/iwind/TeaGo"
)
func init() {
TeaGo.BeforeStart(func(server *TeaGo.Server) {
server.
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeServer)).
Data("teaMenu", "servers").
Data("teaSubMenu", "group").
Prefix("/servers/groups/group/settings/pages").
GetPost("", new(IndexAction)).
EndAll()
})
}

View File

@@ -6,6 +6,7 @@ import (
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions" "github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/types"
) )
type IndexAction struct { type IndexAction struct {
@@ -20,6 +21,17 @@ func (this *IndexAction) Init() {
func (this *IndexAction) RunGet(params struct { func (this *IndexAction) RunGet(params struct {
ServerId int64 ServerId int64
}) { }) {
// 分组设置
groupResp, err := this.RPC().ServerGroupRPC().FindEnabledServerGroupConfigInfo(this.AdminContext(), &pb.FindEnabledServerGroupConfigInfoRequest{
ServerId: params.ServerId,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Data["hasGroupConfig"] = groupResp.HasPagesConfig
this.Data["groupSettingURL"] = "/servers/groups/group/settings/pages?groupId=" + types.String(groupResp.ServerGroupId)
webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithServerId(this.AdminContext(), params.ServerId) webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithServerId(this.AdminContext(), params.ServerId)
if err != nil { if err != nil {
this.ErrorPage(err) this.ErrorPage(err)

View File

@@ -0,0 +1,11 @@
{$layout}
{$template "/servers/groups/group/menu"}
{$template "/left_menu_without_menu"}
<div class="right-box without-menu">
<form method="post" class="ui form" data-tea-action="$" data-tea-success="success">
<input type="hidden" name="webId" :value="webId"/>
<http-pages-and-shutdown-box :v-pages="pages" :v-shutdown-config="shutdownConfig"></http-pages-and-shutdown-box>
<submit-btn></submit-btn>
</form>
</div>

View File

@@ -0,0 +1,3 @@
Tea.context(function () {
this.success = NotifyReloadSuccess("保存成功")
})

View File

@@ -3,9 +3,16 @@
{$template "/left_menu"} {$template "/left_menu"}
<div class="right-box"> <div class="right-box">
<form method="post" class="ui form" data-tea-action="$" data-tea-success="success"> <div v-if="hasGroupConfig">
<input type="hidden" name="webId" :value="webId"/> <div class="margin"></div>
<http-pages-and-shutdown-box :v-pages="pages" :v-shutdown-config="shutdownConfig"></http-pages-and-shutdown-box> <warning-message>由于已经在当前<a :href="groupSettingURL">服务分组</a>中进行了对应的配置,在这里的配置将不会生效。</warning-message>
<submit-btn></submit-btn> </div>
</form>
<div :class="{'opacity-mask': hasGroupConfig}">
<form method="post" class="ui form" data-tea-action="$" data-tea-success="success">
<input type="hidden" name="webId" :value="webId"/>
<http-pages-and-shutdown-box :v-pages="pages" :v-shutdown-config="shutdownConfig"></http-pages-and-shutdown-box>
<submit-btn></submit-btn>
</form>
</div>
</div> </div>