提交 a003603c 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

show filter list

上级 9494dd03
......@@ -163,3 +163,12 @@ const (
Dir TreeNodeType = "dir"
File TreeNodeType = "file"
)
type ScriptFilterType string
const (
FilterWorkspace ScriptFilterType = "workspace"
FilterModule ScriptFilterType = "module"
FilterSuite ScriptFilterType = "suite"
FilterTask ScriptFilterType = "task"
)
package controller
import (
commConsts "github.com/aaronchen2k/deeptest/internal/comm/consts"
"github.com/aaronchen2k/deeptest/internal/server/modules/v1/service"
"github.com/kataras/iris/v12"
)
type TestFilterCtrl struct {
TestFilterService *service.TestFilterService `inject:""`
BaseCtrl
}
func NewTestFilterCtrl() *TestFilterCtrl {
return &TestFilterCtrl{}
}
// ListItems 获取脚本过滤器的内容列表
func (c *TestFilterCtrl) ListItems(ctx iris.Context) {
currSiteId, _ := ctx.URLParamInt("currSiteId")
currProductId, _ := ctx.URLParamInt("currProductId")
filerType := ctx.URLParam("filerType")
ret, _ := c.TestFilterService.ListFilterItems(commConsts.ScriptFilterType(filerType), currSiteId, currProductId)
ctx.JSON(c.SuccessResp(ret))
}
......@@ -57,7 +57,9 @@ func (c *WorkspaceCtrl) Get(ctx iris.Context) {
}
func (c *WorkspaceCtrl) Create(ctx iris.Context) {
currSiteId, _ := ctx.URLParamInt("currSiteId")
currProductId, _ := ctx.URLParamInt("currProductId")
if currProductId <= 0 {
ctx.JSON(c.ErrResp(commConsts.ParamErr, fmt.Sprintf("参数%s不合法", "currProductId")))
return
......@@ -68,6 +70,7 @@ func (c *WorkspaceCtrl) Create(ctx iris.Context) {
ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error()))
}
req.SiteId = uint(currSiteId)
req.ProductId = uint(currProductId)
id, err := c.WorkspaceService.Create(req)
if err != nil {
......@@ -79,6 +82,7 @@ func (c *WorkspaceCtrl) Create(ctx iris.Context) {
}
func (c *WorkspaceCtrl) Update(ctx iris.Context) {
currSiteId, _ := ctx.URLParamInt("currSiteId")
currProductId, _ := ctx.URLParamInt("currProductId")
if currProductId <= 0 {
ctx.JSON(c.ErrResp(commConsts.ParamErr, fmt.Sprintf("参数%s不合法", "currProductId")))
......@@ -90,6 +94,7 @@ func (c *WorkspaceCtrl) Update(ctx iris.Context) {
ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error()))
}
req.SiteId = uint(currSiteId)
req.ProductId = uint(currProductId)
err := c.WorkspaceService.Update(req)
if err != nil {
......
......@@ -9,3 +9,8 @@ type TestScript struct {
WorkspaceId uint `json:"workspaceId"`
}
type FilterItem struct {
Label string `json:"label"`
Value int `json:"value"`
}
......@@ -20,6 +20,7 @@ type IndexModule struct {
SyncModule *index.SyncModule `inject:""`
WorkspaceModule *index.WorkspaceModule `inject:""`
TestFilterModule *index.TestFilterModule `inject:""`
TestScriptModule *index.TestScriptModule `inject:""`
TestExecModule *index.TestExecModule `inject:""`
TestResultModule *index.TestResultModule `inject:""`
......@@ -49,6 +50,8 @@ func (m *IndexModule) Party() module.WebModule {
m.ConfigModule.Party(),
m.SyncModule.Party(),
m.WorkspaceModule.Party(),
m.TestFilterModule.Party(),
m.TestScriptModule.Party(),
m.TestExecModule.Party(),
m.TestBugModule.Party(),
......
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 TestFilterModule struct {
TestFilterCtrl *controller.TestFilterCtrl `inject:""`
}
func NewTestFilterModule() *TestFilterModule {
return &TestFilterModule{}
}
// Party 脚本
func (m *TestFilterModule) Party() module.WebModule {
handler := func(index iris.Party) {
index.Use(middleware.InitCheck())
index.Get("/listItems", m.TestFilterCtrl.ListItems).Name = "获取脚本过滤器的内容列表"
}
return module.NewModule("/filters", handler)
}
......@@ -5,12 +5,14 @@ import commConsts "github.com/aaronchen2k/deeptest/internal/comm/consts"
type Workspace struct {
BaseModel
Path string `json:"path"`
Name string `json:"name"`
Desc string `json:"desc" gorm:"column:descr"`
Type commConsts.TestTool `json:"type" gorm:"default:ztf"`
Cmd string `json:"cmd"`
ProductId uint `json:"productId"`
Path string `json:"path"`
Name string `json:"name"`
Desc string `json:"desc" gorm:"column:descr"`
Type commConsts.TestTool `json:"type" gorm:"default:ztf"`
Cmd string `json:"cmd"`
SiteId uint `json:"siteId"`
ProductId uint `json:"productId"`
IsDefault bool `json:"isDefault"`
}
......
......@@ -195,9 +195,9 @@ func (r *WorkspaceRepo) SetCurrWorkspace(pth string) (err error) {
return err
}
func (r *WorkspaceRepo) ListWorkspacesByProduct(productId int) (pos []model.Workspace, err error) {
func (r *WorkspaceRepo) ListWorkspacesByProduct(siteId, productId int) (pos []model.Workspace, err error) {
err = r.DB.Model(&model.Workspace{}).
Where("product_id = ?", productId).
Where("site_id = ? AND product_id = ?", siteId, productId).
Where("NOT deleted AND NOT disabled").
Find(&pos).Error
......
package service
import (
commConsts "github.com/aaronchen2k/deeptest/internal/comm/consts"
serverDomain "github.com/aaronchen2k/deeptest/internal/server/modules/v1/domain"
"github.com/aaronchen2k/deeptest/internal/server/modules/v1/repo"
)
type TestFilterService struct {
WorkspaceRepo *repo.WorkspaceRepo `inject:""`
SiteService *SiteService `inject:""`
}
func NewTestFilterService() *TestFilterService {
return &TestFilterService{}
}
func (s *TestFilterService) ListFilterItems(filerType commConsts.ScriptFilterType,
siteId int, productId int) (ret []serverDomain.FilterItem, err error) {
if filerType == commConsts.FilterWorkspace {
ret, err = s.ListWorkspaceFilter(siteId, productId)
return
}
//site, _ := s.SiteService.GetDomainObject(uint(siteId))
//config := commDomain.WorkspaceConf{
// Url: site.Url,
// Username: site.Username,
// Password: site.Password,
//}
if filerType == commConsts.FilterModule {
} else if filerType == commConsts.FilterSuite {
} else if filerType == commConsts.FilterTask {
}
return
}
func (s *TestFilterService) ListWorkspaceFilter(siteId int, productId int) (ret []serverDomain.FilterItem, err error) {
workspaces, err := s.WorkspaceRepo.ListWorkspacesByProduct(siteId, productId)
for _, item := range workspaces {
filterItem := serverDomain.FilterItem{Label: item.Name, Value: int(item.ID)}
ret = append(ret, filterItem)
}
return
}
......@@ -10,6 +10,7 @@ import (
type TestScriptService struct {
WorkspaceRepo *repo.WorkspaceRepo `inject:""`
SiteService *SiteService `inject:""`
}
func NewTestScriptService() *TestScriptService {
......@@ -19,7 +20,7 @@ func NewTestScriptService() *TestScriptService {
func (s *TestScriptService) LoadTestScriptsBySiteProduct(site serverDomain.ZentaoSite, product serverDomain.ZentaoProduct) (
root serverDomain.TestAsset, err error) {
workspaces, _ := s.WorkspaceRepo.ListWorkspacesByProduct(product.Id)
workspaces, _ := s.WorkspaceRepo.ListWorkspacesByProduct(site.Id, product.Id)
root = serverDomain.TestAsset{Path: "", Title: "测试脚本", Type: commConsts.Root, Slots: iris.Map{"icon": "icon"}}
for _, workspace := range workspaces {
......
......@@ -16,7 +16,9 @@ export interface ZentaoData {
testScripts: any[]
currSite: any
currProduct: any
scriptLoaded: boolean
filerItems: any[]
modules: any[]
suites: any[]
......@@ -58,7 +60,9 @@ const initState: ZentaoData = {
testScripts: [],
currSite: {},
currProduct: {},
scriptLoaded: false,
filerItems: [],
modules: [],
suites: [],
......@@ -83,11 +87,12 @@ const StoreModel: ModuleType = {
async saveSitesAndProducts(state, payload) {
state.sites = payload.sites;
state.products = payload.products;
if (payload.testScripts) {
state.scriptLoaded = payload.needLoadScript
if (state.scriptLoaded) {
state.testScripts = [payload.testScripts];
state.scriptLoaded = true
} else {
state.scriptLoaded = false
state.testScripts = [];
}
state.currSite = payload.currSite;
......@@ -146,6 +151,9 @@ const StoreModel: ModuleType = {
async fetchSitesAndProducts({ commit }, payload) {
const response: ResponseData = await querySiteAndProduct(payload);
const { data } = response;
data.needLoadScript = payload.needLoadScript
commit('saveSitesAndProducts', data)
return true;
......
......@@ -37,10 +37,12 @@ export const getScriptFilters = async () => {
}
export const setScriptFilters = async (by, val) => {
let mp = await getCache(settings.scriptFilters);
if (!mp) mp = {}
mp.by = by
mp[by] = val
if (val) mp[by] = val
console.log('---', mp)
await setCache(settings.scriptFilters, mp);
}
......@@ -25,8 +25,8 @@
:bordered="false"
:dropdownMatchSelectWidth="false"
>
<a-select-option v-for="item in filerItems" :key="item.id" :value="item.id">
{{item.name}}
<a-select-option v-for="item in filerItems" :key="item.value" :value="item.value">
{{item.label}}
</a-select-option>
</a-select>
</div>
......@@ -92,7 +92,8 @@ import {Empty, message, notification} from "ant-design-vue";
import {MonacoOptions} from "@/utils/const";
import MonacoEditor from "@/components/Editor/MonacoEditor.vue";
import {ZentaoData} from "@/store/zentao";
import {getScriptFilters} from "@/utils/cache";
import {getScriptFilters, setScriptFilters} from "@/utils/cache";
import {listFilterItems} from "@/views/script/service";
interface ListScriptPageSetupData {
t: (key: string | number) => string;
......@@ -153,16 +154,26 @@ export default defineComponent({
let filerItems = ref([] as any)
const filerType = ref('')
const filerValue = ref('')
getScriptFilters().then( (filter) => {
const loadFilterItems = async () => {
const filter = await getScriptFilters()
filerType.value = filter.by
filerValue.value = filter.val
// filerItems =
})
const selectFilerType = (val) => {
console.log('selectFilerType')
listFilterItems(filerType.value).then((data) => {
console.log('ksjdhfdsf', data)
filerItems.value = data.data
})
}
loadFilterItems()
const selectFilerType = async (val) => {
console.log('selectFilerType', val)
await setScriptFilters(val, null)
await loadFilterItems()
}
const selectFilerValue = (val) => {
console.log('selectFilerValue')
const selectFilerValue = async (val) => {
console.log('selectFilerValue', val)
await setScriptFilters(filerType.value, val)
}
const expandedKeys = ref<string[]>([]);
......
......@@ -2,12 +2,21 @@ import request from '@/utils/request';
import { Script } from './data.d';
const apiPath = 'scripts';
const apiPathFilters = 'filters';
export async function listFilterItems(filerType: string): Promise<any> {
const params = {filerType: filerType}
return request({
url: `/${apiPathFilters}/listItems`,
params
});
}
export async function get(path: string): Promise<any> {
const params = {path: path}
return request({
url: `/scripts/get`,
url: `/${apiPath}/get`,
params
});
}
......@@ -16,7 +25,7 @@ export async function extract(path: string): Promise<any> {
const params = {path: path}
return request({
url: `/scripts/extract`,
url: `/${apiPath}/extract`,
params
});
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册