diff --git a/internal/server/modules/v1/controller/base.go b/internal/server/modules/v1/controller/base.go index edbfb7d441368486c4a837455260263d93208be0..4348099b19be9d68114d6f2dad60085caf4d4e47 100644 --- a/internal/server/modules/v1/controller/base.go +++ b/internal/server/modules/v1/controller/base.go @@ -3,7 +3,6 @@ package controller import ( commConsts "github.com/aaronchen2k/deeptest/internal/comm/consts" "github.com/aaronchen2k/deeptest/internal/pkg/domain" - i118Utils "github.com/aaronchen2k/deeptest/internal/pkg/lib/i118" ) type BaseCtrl struct { @@ -26,11 +25,11 @@ func (c *BaseCtrl) ErrResp(err commConsts.ResponseCode, msg string) (ret domain. } func (c *BaseCtrl) ErrMsg(err commConsts.ResponseCode, msg string) (ret string) { - ret = i118Utils.Sprintf(err.Message) - - if ret != "" { - ret += ": " - } + //ret = i118Utils.Sprintf(err.Message) + // + //if ret != "" { + // ret += ": " + //} ret += msg diff --git a/internal/server/modules/v1/controller/interpreter.go b/internal/server/modules/v1/controller/interpreter.go new file mode 100644 index 0000000000000000000000000000000000000000..209744cad5ccb8dde7f803fc06919f32ea84c950 --- /dev/null +++ b/internal/server/modules/v1/controller/interpreter.go @@ -0,0 +1,88 @@ +package controller + +import ( + commConsts "github.com/aaronchen2k/deeptest/internal/comm/consts" + "github.com/aaronchen2k/deeptest/internal/server/modules/v1/model" + "github.com/aaronchen2k/deeptest/internal/server/modules/v1/service" + "github.com/kataras/iris/v12" +) + +type InterpreterCtrl struct { + InterpreterService *service.InterpreterService `inject:""` + BaseCtrl +} + +func NewInterpreterCtrl() *InterpreterCtrl { + return &InterpreterCtrl{} +} + +func (c *InterpreterCtrl) List(ctx iris.Context) { + data, err := c.InterpreterService.List() + if err != nil { + ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error())) + return + } + + ctx.JSON(c.SuccessResp(data)) +} + +func (c *InterpreterCtrl) Get(ctx iris.Context) { + id, err := ctx.Params().GetInt("id") + if err != nil { + ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error())) + return + } + + po, err := c.InterpreterService.Get(uint(id)) + if err != nil { + ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error())) + return + } + ctx.JSON(c.SuccessResp(po)) +} + +func (c *InterpreterCtrl) Create(ctx iris.Context) { + req := model.Interpreter{} + if err := ctx.ReadJSON(&req); err != nil { + ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error())) + } + + id, err := c.InterpreterService.Create(req) + if err != nil { + ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error())) + return + } + + ctx.JSON(c.SuccessResp(iris.Map{"id": id})) +} + +func (c *InterpreterCtrl) Update(ctx iris.Context) { + req := model.Interpreter{} + if err := ctx.ReadJSON(&req); err != nil { + ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error())) + } + + err := c.InterpreterService.Update(req) + if err != nil { + ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error())) + return + } + + ctx.JSON(c.SuccessResp(iris.Map{"id": req.ID})) +} + +func (c *InterpreterCtrl) Delete(ctx iris.Context) { + id, err := ctx.Params().GetInt("id") + if err != nil { + ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error())) + return + } + + err = c.InterpreterService.Delete(uint(id)) + if err != nil { + ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error())) + return + } + + ctx.JSON(c.SuccessResp(nil)) +} diff --git a/internal/server/modules/v1/index.go b/internal/server/modules/v1/index.go index bc716774f3e6a8ab993cfb3e7d08b0584af307ca..56595540717627a622932704a71535abcb981fb8 100644 --- a/internal/server/modules/v1/index.go +++ b/internal/server/modules/v1/index.go @@ -13,12 +13,12 @@ import ( type IndexModule struct { FileModule *index.FileModule `inject:""` - SiteModule *index.SiteModule `inject:""` + ZentaoModule *index.ZentaoModule `inject:""` + SiteModule *index.SiteModule `inject:""` - ZentaoModule *index.ZentaoModule `inject:""` - ConfigModule *index.ConfigModule `inject:""` - SyncModule *index.SyncModule `inject:""` - WorkspaceModule *index.WorkspaceModule `inject:""` + InterpreterModule *index.InterpreterModule `inject:""` + SyncModule *index.SyncModule `inject:""` + WorkspaceModule *index.WorkspaceModule `inject:""` TestFilterModule *index.TestFilterModule `inject:""` TestScriptModule *index.TestScriptModule `inject:""` @@ -45,9 +45,9 @@ func (m *IndexModule) Party() module.WebModule { modules := []module.WebModule{ m.FileModule.Party(), - m.SiteModule.Party(), m.ZentaoModule.Party(), - m.ConfigModule.Party(), + m.SiteModule.Party(), + m.InterpreterModule.Party(), m.SyncModule.Party(), m.WorkspaceModule.Party(), diff --git a/internal/server/modules/v1/index/interpreter.go b/internal/server/modules/v1/index/interpreter.go new file mode 100644 index 0000000000000000000000000000000000000000..64861cfddd1fe93ae352ddd2fe666374512526c7 --- /dev/null +++ b/internal/server/modules/v1/index/interpreter.go @@ -0,0 +1,30 @@ +package index + +import ( + "github.com/aaronchen2k/deeptest/internal/server/core/module" + "github.com/aaronchen2k/deeptest/internal/server/middleware" + "github.com/aaronchen2k/deeptest/internal/server/modules/v1/controller" + "github.com/kataras/iris/v12" +) + +type InterpreterModule struct { + InterpreterCtrl *controller.InterpreterCtrl `inject:""` +} + +func NewInterpreterModule() *InterpreterModule { + return &InterpreterModule{} +} + +// Party 执行 +func (m *InterpreterModule) Party() module.WebModule { + handler := func(index iris.Party) { + index.Use(middleware.InitCheck()) + + index.Get("/", m.InterpreterCtrl.List).Name = "列表" + index.Get("/{id:int}", m.InterpreterCtrl.Get).Name = "详情" + index.Post("/", m.InterpreterCtrl.Create).Name = "新建" + index.Put("/{id:int}", m.InterpreterCtrl.Update).Name = "更新" + index.Delete("/{id:int}", m.InterpreterCtrl.Delete).Name = "删除" + } + return module.NewModule("/interpreters", handler) +} diff --git a/internal/server/modules/v1/model/interpreter.go b/internal/server/modules/v1/model/interpreter.go new file mode 100644 index 0000000000000000000000000000000000000000..234431069fc1957c4848c53e3b3cc24bdbb991a2 --- /dev/null +++ b/internal/server/modules/v1/model/interpreter.go @@ -0,0 +1,12 @@ +package model + +type Interpreter struct { + BaseModel + + Lang string `json:"lang"` + Path string `json:"path"` +} + +func (Interpreter) TableName() string { + return "biz_interpreter" +} diff --git a/internal/server/modules/v1/model/models.go b/internal/server/modules/v1/model/models.go index 49fe6e56009a6feda941855815c134f0a6d7a323..22b0f0910c6c022c991f5b9ebf36dfb1a7eec29b 100644 --- a/internal/server/modules/v1/model/models.go +++ b/internal/server/modules/v1/model/models.go @@ -2,7 +2,8 @@ package model var ( Models = []interface{}{ - &Workspace{}, + &Interpreter{}, &Site{}, + &Workspace{}, } ) diff --git a/internal/server/modules/v1/repo/interpreter.go b/internal/server/modules/v1/repo/interpreter.go new file mode 100644 index 0000000000000000000000000000000000000000..1f8dce4b9bcdef4351c0c1874988db3f0744d951 --- /dev/null +++ b/internal/server/modules/v1/repo/interpreter.go @@ -0,0 +1,95 @@ +package repo + +import ( + "errors" + "fmt" + logUtils "github.com/aaronchen2k/deeptest/internal/pkg/lib/log" + "github.com/aaronchen2k/deeptest/internal/server/modules/v1/model" + "github.com/fatih/color" + "go.uber.org/zap" + "gorm.io/gorm" +) + +type InterpreterRepo struct { + DB *gorm.DB `inject:""` +} + +func NewInterpreterRepo() *InterpreterRepo { + return &InterpreterRepo{} +} + +func (r *InterpreterRepo) List() (pos []model.Interpreter, err error) { + db := r.DB.Model(&model.Interpreter{}).Where("NOT deleted") + err = db.Find(&pos).Error + + return +} + +func (r *InterpreterRepo) Get(id uint) (po model.Interpreter, err error) { + err = r.DB.Model(&model.Interpreter{}). + Where("id = ?", id). + Where("NOT deleted"). + First(&po).Error + if err != nil { + logUtils.Errorf(color.RedString("find interpreter by id failed, error: %s.", err.Error())) + return + } + + return +} + +func (r *InterpreterRepo) Create(interpreter model.Interpreter) (id uint, err error) { + po, err := r.FindDuplicate(interpreter.Lang, 0) + if po.ID != 0 { + return 0, errors.New(fmt.Sprintf("%s运行环境已存在", interpreter.Lang)) + } + + err = r.DB.Model(&model.Interpreter{}).Create(&interpreter).Error + if err != nil { + logUtils.Errorf(color.RedString("create interpreter failed, error: %s.", err.Error())) + return 0, err + } + + id = interpreter.ID + + return +} + +func (r *InterpreterRepo) Update(interpreter model.Interpreter) error { + po, err := r.FindDuplicate(interpreter.Lang, interpreter.ID) + if po.ID != 0 { + return errors.New(fmt.Sprintf("%s运行环境已存在", interpreter.Lang)) + } + + err = r.DB.Model(&model.Interpreter{}).Where("id = ?", interpreter.ID).Updates(&interpreter).Error + if err != nil { + logUtils.Errorf(color.RedString("update interpreter failed, error: %s.", err.Error())) + return err + } + + return nil +} + +func (r *InterpreterRepo) Delete(id uint) (err error) { + err = r.DB.Model(&model.Interpreter{}).Where("id = ?", id). + Updates(map[string]interface{}{"deleted": true}).Error + if err != nil { + logUtils.Errorf("delete interpreter by id error", zap.String("error:", err.Error())) + return + } + + return +} + +func (r *InterpreterRepo) FindDuplicate(lang string, id uint) (po model.Interpreter, err error) { + db := r.DB.Model(&model.Interpreter{}). + Where("NOT deleted"). + Where("lang = ?", lang) + + if id != 0 { + db.Where("id != ?", id) + } + err = db.First(&po).Error + + return +} diff --git a/internal/server/modules/v1/service/interpreter.go b/internal/server/modules/v1/service/interpreter.go new file mode 100644 index 0000000000000000000000000000000000000000..6773a4dca1f6ef78ae743efe510269093af5efce --- /dev/null +++ b/internal/server/modules/v1/service/interpreter.go @@ -0,0 +1,50 @@ +package service + +import ( + "errors" + "fmt" + fileUtils "github.com/aaronchen2k/deeptest/internal/pkg/lib/file" + "github.com/aaronchen2k/deeptest/internal/server/modules/v1/model" + "github.com/aaronchen2k/deeptest/internal/server/modules/v1/repo" +) + +type InterpreterService struct { + InterpreterRepo *repo.InterpreterRepo `inject:""` +} + +func NewInterpreterService() *InterpreterService { + return &InterpreterService{} +} + +func (s *InterpreterService) List() (ret []model.Interpreter, err error) { + ret, err = s.InterpreterRepo.List() + return +} + +func (s *InterpreterService) Get(id uint) (site model.Interpreter, err error) { + return s.InterpreterRepo.Get(id) +} + +func (s *InterpreterService) Create(site model.Interpreter) (id uint, err error) { + if !fileUtils.FileExist(site.Path) { + err = errors.New(fmt.Sprintf("可执行文件%s不存在", site.Path)) + return + } + + id, err = s.InterpreterRepo.Create(site) + return +} + +func (s *InterpreterService) Update(site model.Interpreter) (err error) { + if !fileUtils.FileExist(site.Path) { + err = errors.New(fmt.Sprintf("可执行文件%s不存在", site.Path)) + return + } + + err = s.InterpreterRepo.Update(site) + return +} + +func (s *InterpreterService) Delete(id uint) error { + return s.InterpreterRepo.Delete(id) +} diff --git a/ui/src/layouts/IndexLayout/components/TopSettings.vue b/ui/src/layouts/IndexLayout/components/TopSettings.vue index 229028150169cdd5cd07441d4f79ed29ff8774f5..b66e42d3cf6f7b62cfe6e93c4dd95172ddbe7eaa 100644 --- a/ui/src/layouts/IndexLayout/components/TopSettings.vue +++ b/ui/src/layouts/IndexLayout/components/TopSettings.vue @@ -60,6 +60,7 @@ export default defineComponent({ } const setEnv = (): void => { console.log('setEnv') + router.push(`/interpreter/list`) } const setLang = (): void => { console.log('setLang') diff --git a/ui/src/layouts/IndexLayout/routes.ts b/ui/src/layouts/IndexLayout/routes.ts index a5623e5aa6266a20aa408f70b7b4a59072bd9546..924829d7c02b09378c24b87a5f4937919a89b2d2 100644 --- a/ui/src/layouts/IndexLayout/routes.ts +++ b/ui/src/layouts/IndexLayout/routes.ts @@ -115,7 +115,7 @@ const IndexLayoutRoutes: Array = [ { icon: 'empty', - title: 'empty', + title: 'site', path: '/site', redirect: '/site/list', component: BlankLayout, @@ -142,6 +142,22 @@ const IndexLayoutRoutes: Array = [ ], }, + { + icon: 'empty', + title: 'interpreter', + path: '/interpreter', + redirect: '/interpreter/list', + component: BlankLayout, + hidden: true, + children: [ + { + title: 'interpreter', + path: 'list', + component: () => import('@/views/interpreter/index.vue'), + hidden: true, + }, + ], + }, ]; export default IndexLayoutRoutes; \ No newline at end of file diff --git a/ui/src/locales/zh-CN.ts b/ui/src/locales/zh-CN.ts index 0eb753e0589d5f0c2c09fc5aa4ecca8acc171ac5..0593b4544ba2c700699af61ae1efd06bafcff951 100644 --- a/ui/src/locales/zh-CN.ts +++ b/ui/src/locales/zh-CN.ts @@ -36,10 +36,11 @@ export default { 'zentao_url': '禅道地址', 'username': '用户名', 'password': '密码', - 'create_interpreter': '新建解析器', - 'edit_interpreter': '编辑解析器', - 'interpreter': '解析器', - 'interpreter_path': '解析器路径', + + 'interpreter': '运行环境', + 'create_interpreter': '新建运行环境', + 'edit_interpreter': '编辑运行环境', + 'interpreter_path': '可执行文件路径', 'script_lang': '脚本语言', 'script': '脚本', @@ -160,5 +161,5 @@ export default { 'pls_username': '请输入用户名', 'pls_password': '请输入密码', 'pls_input_lang': '请输入语言', - 'pls_input_interpreter_path': '请输入解析器可执行文件路径', + 'pls_input_interpreter_path': '请输入可执行文件路径', }; \ No newline at end of file diff --git a/ui/src/utils/testing.ts b/ui/src/utils/testing.ts index ed25f455db024213569a58ec90c9342c5b4a8a3e..d74ead76dce8b7335c41447b57dec14d4863ef32 100644 --- a/ui/src/utils/testing.ts +++ b/ui/src/utils/testing.ts @@ -1,31 +1,17 @@ import moment from "moment"; import {AutoTestTools, ScriptLanguages, TestTools, BuildTools} from "@/utils/const"; -import {Ref} from "vue"; -import {Config, Interpreter} from "@/views/config/data"; -export function getInterpretersFromConfig(currConfig: any): any { - const interpreters: any[] = [] +export function getInterpreters(): any { const languages: string[] = [] const languageMap = {} ScriptLanguages.forEach(item => { const lang = item.toLowerCase() + languages.push(lang) languageMap[lang] = item - - if (currConfig && currConfig[lang] && currConfig[lang].trim() != '') { - interpreters.push({ lang: lang, val: currConfig[lang] }) - } else { - languages.push(lang) - } }) - return {interpreters: interpreters, languages: languages, languageMap: languageMap} -} -export function setInterpreter(config: Ref, interpreters: Ref): Ref { - interpreters.value.forEach((item, i) => { - config[item.lang] = item.val - }) - return config + return {languages: languages, languageMap: languageMap} } export function getUnitTestFrameworks(): any { diff --git a/ui/src/views/config/data.d.ts b/ui/src/views/config/data.d.ts deleted file mode 100644 index 3d0cfe5f612104a0a6aa5fef550434e6390e1880..0000000000000000000000000000000000000000 --- a/ui/src/views/config/data.d.ts +++ /dev/null @@ -1,23 +0,0 @@ -export interface Config { - language: string - url: string; - username: string; - password: string; - - javascript: string - lua: string - perl: string - php: string - python: string - ruby: string - tcl: string - autoit: string - - version: string - isWin: boolean -} - -export interface Interpreter { - lang: string; - val: string; -} diff --git a/ui/src/views/config/index.vue b/ui/src/views/config/index.vue deleted file mode 100644 index aa7dc7a328930b7cb5c480d9d5c7777d807d69f8..0000000000000000000000000000000000000000 --- a/ui/src/views/config/index.vue +++ /dev/null @@ -1,301 +0,0 @@ - - - - diff --git a/ui/src/views/config/interpreter/create.vue b/ui/src/views/config/interpreter/create.vue deleted file mode 100644 index a3b5a9aebda71b31a301c88d867dfd86fc766429..0000000000000000000000000000000000000000 --- a/ui/src/views/config/interpreter/create.vue +++ /dev/null @@ -1,101 +0,0 @@ - - - \ No newline at end of file diff --git a/ui/src/views/config/interpreter/update.vue b/ui/src/views/config/interpreter/update.vue deleted file mode 100644 index 81f59fbbd95995a1f4c4171f1482bb16dc7d3a6d..0000000000000000000000000000000000000000 --- a/ui/src/views/config/interpreter/update.vue +++ /dev/null @@ -1,101 +0,0 @@ - - \ No newline at end of file diff --git a/ui/src/views/config/locales/en-US.ts b/ui/src/views/config/locales/en-US.ts deleted file mode 100644 index ff211b7611166fceddc7866b1aeff3ca3c9f016c..0000000000000000000000000000000000000000 --- a/ui/src/views/config/locales/en-US.ts +++ /dev/null @@ -1,17 +0,0 @@ -export default { - 'edit_config': 'Eidt Config', - 'zentao_url': 'ZenTao URL', - 'username': 'User Name', - 'password': 'Password', - 'pls_zentao_url': 'Please input ZenTao URL', - 'pls_username': 'Please input user name.', - 'pls_password': 'Please input password.', - - 'create_interpreter': 'Create Interpreter', - 'edit_interpreter': 'Edit Interpreter', - - 'interpreter_path': 'Interpreter Path', - 'script_lang': 'Script Language', - 'pls_input_lang': 'Please input language.', - 'pls_input_interpreter_path': 'Please input interpreter path.', -}; diff --git a/ui/src/views/config/locales/zh-CN.ts b/ui/src/views/config/locales/zh-CN.ts deleted file mode 100644 index ddfbbefaff3c2c3204e5df47e82b23f79f31f214..0000000000000000000000000000000000000000 --- a/ui/src/views/config/locales/zh-CN.ts +++ /dev/null @@ -1,20 +0,0 @@ -import {Interpreter} from "@/views/config/data"; - -export default { - 'edit_config': '修改配置', - 'zentao_url': '禅道地址', - 'username': '用户名', - 'password': '密码', - 'pls_zentao_url': '请输入禅道地址', - 'pls_username': '请输入用户名', - 'pls_password': '请输入密码', - - 'create_interpreter': '新建解析器', - 'edit_interpreter': '编辑解析器', - - 'interpreter': '解析器', - 'interpreter_path': '解析器路径', - 'script_lang': '脚本语言', - 'pls_input_lang': '请输入语言', - 'pls_input_interpreter_path': '请输入解析器可执行文件路径', -}; diff --git a/ui/src/views/config/service.ts b/ui/src/views/config/service.ts deleted file mode 100644 index a47eabf7452fc189a9d372f2b36e95d8c6e5a1a8..0000000000000000000000000000000000000000 --- a/ui/src/views/config/service.ts +++ /dev/null @@ -1,5 +0,0 @@ -import {Ref} from "vue"; -import {Config, Interpreter} from './data.d'; -import {ScriptLanguages} from "@/utils/const"; - - diff --git a/ui/src/views/interpreter/component/edit.vue b/ui/src/views/interpreter/component/edit.vue new file mode 100644 index 0000000000000000000000000000000000000000..63f2b3732ab61e63d15781c0899da04f07ca5c34 --- /dev/null +++ b/ui/src/views/interpreter/component/edit.vue @@ -0,0 +1,127 @@ + + + \ No newline at end of file diff --git a/ui/src/views/interpreter/index.vue b/ui/src/views/interpreter/index.vue new file mode 100644 index 0000000000000000000000000000000000000000..a222fbc91d72a2a0a2f712ebc5f01a0b90ee4f9f --- /dev/null +++ b/ui/src/views/interpreter/index.vue @@ -0,0 +1,237 @@ + + + + diff --git a/ui/src/views/interpreter/service.ts b/ui/src/views/interpreter/service.ts new file mode 100644 index 0000000000000000000000000000000000000000..da93f14ef09866781a2920e1cba7aaf7ff04a685 --- /dev/null +++ b/ui/src/views/interpreter/service.ts @@ -0,0 +1,33 @@ +import {QueryParams} from "@/types/data"; +import request from "@/utils/request"; + +const apiPath = 'interpreters'; + +export async function listInterpreter(params?: QueryParams): Promise { + return request({ + url: `/${apiPath}`, + method: 'get', + params, + }); +} + +export async function getInterpreter(seq: number): Promise { + return request({ + url: `/${apiPath}/${seq}` + }); +} + +export async function saveInterpreter(params: any): Promise { + return request({ + url: `/${apiPath}` + (params.id ? `/${params.id}` : ''), + method: params.id? 'PUT': 'POST', + data: params, + }); +} + +export async function removeInterpreter(id: number): Promise { + return request({ + url: `/${apiPath}/${id}`, + method: 'delete', + }); +} \ No newline at end of file