67 lines
1.6 KiB
Go
67 lines
1.6 KiB
Go
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
|
|
|
package clientsystems
|
|
|
|
import (
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
"github.com/iwind/TeaGo/actions"
|
|
)
|
|
|
|
type CreatePopupAction struct {
|
|
actionutils.ParentAction
|
|
}
|
|
|
|
func (this *CreatePopupAction) Init() {
|
|
this.Nav("", "", "")
|
|
}
|
|
|
|
func (this *CreatePopupAction) RunGet(params struct{}) {
|
|
this.Show()
|
|
}
|
|
|
|
func (this *CreatePopupAction) RunPost(params struct {
|
|
Name string
|
|
Codes []string
|
|
DataId string
|
|
|
|
Must *actions.Must
|
|
CSRF *actionutils.CSRF
|
|
}) {
|
|
defer this.CreateLogInfo(codes.ClientSystem_LogCreateSystem, params.Name)
|
|
|
|
params.Must.
|
|
Field("name", params.Name).
|
|
Require("请输入操作系统名称").
|
|
Field("dataId", params.DataId).
|
|
Require("请输入数据ID")
|
|
|
|
if len(params.Codes) == 0 {
|
|
params.Codes = []string{params.Name}
|
|
}
|
|
|
|
// 检查dataId
|
|
systemResp, err := this.RPC().FormalClientSystemRPC().FindFormalClientSystemWithDataId(this.AdminContext(), &pb.FindFormalClientSystemWithDataIdRequest{DataId: params.DataId})
|
|
if err != nil {
|
|
this.ErrorPage(err)
|
|
return
|
|
}
|
|
if systemResp.FormalClientSystem != nil {
|
|
this.Fail("该数据ID已经被 '" + systemResp.FormalClientSystem.Name + "'所使用,请换一个")
|
|
return
|
|
}
|
|
|
|
_, err = this.RPC().FormalClientSystemRPC().CreateFormalClientSystem(this.AdminContext(), &pb.CreateFormalClientSystemRequest{
|
|
Name: params.Name,
|
|
Codes: params.Codes,
|
|
DataId: params.DataId,
|
|
})
|
|
if err != nil {
|
|
this.ErrorPage(err)
|
|
return
|
|
}
|
|
|
|
this.Success()
|
|
}
|