diff --git a/internal/web/actions/default/ns/clusters/create.go b/internal/web/actions/default/ns/clusters/create.go index 9db92d49..ce7e55c3 100644 --- a/internal/web/actions/default/ns/clusters/create.go +++ b/internal/web/actions/default/ns/clusters/create.go @@ -3,7 +3,9 @@ package clusters import ( + "encoding/json" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/iwind/TeaGo/actions" ) @@ -17,24 +19,44 @@ func (this *CreateAction) Init() { } func (this *CreateAction) RunGet(params struct{}) { + // 默认的访问日志设置 + this.Data["accessLogRef"] = &dnsconfigs.AccessLogRef{ + IsOn: true, + } + this.Show() } func (this *CreateAction) RunPost(params struct { - Name string + Name string + AccessLogJSON []byte Must *actions.Must CSRF *actionutils.CSRF }) { var clusterId int64 - defer this.CreateLogInfo("创建域名服务集群 %d", clusterId) + defer func() { + this.CreateLogInfo("创建域名服务集群 %d", clusterId) + }() params.Must. Field("name", params.Name). Require("请输入集群名称") + // 校验访问日志设置 + ref := &dnsconfigs.AccessLogRef{} + err := json.Unmarshal(params.AccessLogJSON, ref) + if err != nil { + this.Fail("数据格式错误:" + err.Error()) + } + err = ref.Init() + if err != nil { + this.Fail("数据格式错误:" + err.Error()) + } + resp, err := this.RPC().NSClusterRPC().CreateNSCluster(this.AdminContext(), &pb.CreateNSClusterRequest{ - Name: params.Name, + Name: params.Name, + AccessLogJSON: params.AccessLogJSON, }) if err != nil { this.ErrorPage(err) diff --git a/internal/web/actions/default/ns/domains/create.go b/internal/web/actions/default/ns/domains/create.go index b0643861..b24b4811 100644 --- a/internal/web/actions/default/ns/domains/create.go +++ b/internal/web/actions/default/ns/domains/create.go @@ -19,6 +19,14 @@ func (this *CreateAction) Init() { } func (this *CreateAction) RunGet(params struct{}) { + // 集群数量 + countClustersResp, err := this.RPC().NSClusterRPC().CountAllEnabledNSClusters(this.AdminContext(), &pb.CountAllEnabledNSClustersRequest{}) + if err != nil { + this.ErrorPage(err) + return + } + this.Data["countClusters"] = countClustersResp.Count + this.Show() } diff --git a/web/views/@default/ns/clusters/create.html b/web/views/@default/ns/clusters/create.html index b4f4ad54..ebf5b017 100644 --- a/web/views/@default/ns/clusters/create.html +++ b/web/views/@default/ns/clusters/create.html @@ -12,5 +12,9 @@ + +