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

cache tree expend keys

上级 a003603c
......@@ -115,7 +115,6 @@ func ListProduct(workspacePath string) (products []serverDomain.ZentaoProduct, e
config := configUtils.LoadByWorkspacePath(workspacePath)
return loadProduct(config)
}
func loadProduct(config commDomain.WorkspaceConf) (products []serverDomain.ZentaoProduct, err error) {
if config.Url == "" {
err = errors.New(i118Utils.Sprintf("pls_config_workspace"))
......@@ -155,8 +154,11 @@ func loadProduct(config commDomain.WorkspaceConf) (products []serverDomain.Zenta
return
}
func ListModuleForCase(productId int, workspacePath string) (modules []serverDomain.ZentaoModule, err error) {
func ListModule(productId int, workspacePath string) (modules []serverDomain.ZentaoModule, err error) {
config := configUtils.LoadByWorkspacePath(workspacePath)
return LoadModule(productId, config)
}
func LoadModule(productId int, config commDomain.WorkspaceConf) (modules []serverDomain.ZentaoModule, err error) {
err = Login(config)
if err != nil {
return
......@@ -183,34 +185,17 @@ func ListModuleForCase(productId int, workspacePath string) (modules []serverDom
for _, item := range arr {
mp := item.(map[string]interface{})
mp["level"] = 0
GenModuleData(mp, &modules)
genModuleData(mp, &modules)
}
return
}
func GenModuleData(mp map[string]interface{}, modules *[]serverDomain.ZentaoModule) {
mpLevel := mp["level"].(int)
idStr := mp["id"].(string)
id, _ := strconv.Atoi(idStr)
name := strings.Repeat(" ", mpLevel*3) + mp["name"].(string)
*modules = append(*modules, serverDomain.ZentaoModule{Id: id, Name: name})
if mp["children"] == nil {
return
}
children := mp["children"].([]interface{})
for _, child := range children {
childMap := child.(map[string]interface{})
childMap["level"] = mp["level"].(int) + 1
GenModuleData(childMap, modules)
}
}
func ListSuiteByProduct(productId int, workspacePath string) (suites []serverDomain.ZentaoSuite, err error) {
func ListSuite(productId int, workspacePath string) (products []serverDomain.ZentaoSuite, err error) {
config := configUtils.LoadByWorkspacePath(workspacePath)
return LoadSuite(productId, config)
}
func LoadSuite(productId int, config commDomain.WorkspaceConf) (suites []serverDomain.ZentaoSuite, err error) {
err = Login(config)
if err != nil {
return
......@@ -246,8 +231,11 @@ func ListSuiteByProduct(productId int, workspacePath string) (suites []serverDom
return
}
func ListTaskByProduct(productId int, workspacePath string) (tasks []serverDomain.ZentaoTask, err error) {
func ListTask(productId int, workspacePath string) (products []serverDomain.ZentaoTask, err error) {
config := configUtils.LoadByWorkspacePath(workspacePath)
return LoadTask(productId, config)
}
func LoadTask(productId int, config commDomain.WorkspaceConf) (tasks []serverDomain.ZentaoTask, err error) {
if config.Url == "" {
err = errors.New(i118Utils.Sprintf("pls_config_workspace"))
return
......@@ -288,3 +276,23 @@ func ListTaskByProduct(productId int, workspacePath string) (tasks []serverDomai
return
}
func genModuleData(mp map[string]interface{}, modules *[]serverDomain.ZentaoModule) {
mpLevel := mp["level"].(int)
idStr := mp["id"].(string)
id, _ := strconv.Atoi(idStr)
name := strings.Repeat(" ", mpLevel*3) + mp["name"].(string)
*modules = append(*modules, serverDomain.ZentaoModule{Id: id, Name: name})
if mp["children"] == nil {
return
}
children := mp["children"].([]interface{})
for _, child := range children {
childMap := child.(map[string]interface{})
childMap["level"] = mp["level"].(int) + 1
genModuleData(childMap, modules)
}
}
......@@ -78,7 +78,7 @@ func (c *ZentaoCtrl) ListModule(ctx iris.Context) {
return
}
data, err := zentaoHelper.ListModuleForCase(productId, workspacePath)
data, err := zentaoHelper.ListModule(productId, workspacePath)
if err != nil {
ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error()))
return
......@@ -95,7 +95,7 @@ func (c *ZentaoCtrl) ListSuite(ctx iris.Context) {
return
}
data, err := zentaoHelper.ListSuiteByProduct(productId, workspacePath)
data, err := zentaoHelper.ListSuite(productId, workspacePath)
if err != nil {
ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error()))
return
......@@ -112,7 +112,7 @@ func (c *ZentaoCtrl) ListTask(ctx iris.Context) {
return
}
data, err := zentaoHelper.ListTaskByProduct(productId, workspacePath)
data, err := zentaoHelper.ListTask(productId, workspacePath)
if err != nil {
ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error()))
return
......
......@@ -2,6 +2,8 @@ package service
import (
commConsts "github.com/aaronchen2k/deeptest/internal/comm/consts"
commDomain "github.com/aaronchen2k/deeptest/internal/comm/domain"
zentaoHelper "github.com/aaronchen2k/deeptest/internal/comm/helper/zentao"
serverDomain "github.com/aaronchen2k/deeptest/internal/server/modules/v1/domain"
"github.com/aaronchen2k/deeptest/internal/server/modules/v1/repo"
)
......@@ -23,19 +25,19 @@ func (s *TestFilterService) ListFilterItems(filerType commConsts.ScriptFilterTyp
return
}
//site, _ := s.SiteService.GetDomainObject(uint(siteId))
//config := commDomain.WorkspaceConf{
// Url: site.Url,
// Username: site.Username,
// Password: site.Password,
//}
site, _ := s.SiteService.GetDomainObject(uint(siteId))
config := commDomain.WorkspaceConf{
Url: site.Url,
Username: site.Username,
Password: site.Password,
}
if filerType == commConsts.FilterModule {
ret, err = s.ListModuleFilter(config, productId)
} else if filerType == commConsts.FilterSuite {
ret, err = s.ListSuiteFilter(config, productId)
} else if filerType == commConsts.FilterTask {
ret, err = s.ListTaskFilter(config, productId)
}
return
......@@ -51,3 +53,34 @@ func (s *TestFilterService) ListWorkspaceFilter(siteId int, productId int) (ret
return
}
func (s *TestFilterService) ListModuleFilter(config commDomain.WorkspaceConf, productId int) (ret []serverDomain.FilterItem, err error) {
modules, _ := zentaoHelper.LoadModule(productId, config)
for _, item := range modules {
filterItem := serverDomain.FilterItem{Label: item.Name, Value: item.Id}
ret = append(ret, filterItem)
}
return
}
func (s *TestFilterService) ListSuiteFilter(config commDomain.WorkspaceConf, productId int) (ret []serverDomain.FilterItem, err error) {
suites, _ := zentaoHelper.LoadSuite(productId, config)
for _, item := range suites {
filterItem := serverDomain.FilterItem{Label: item.Name, Value: item.Id}
ret = append(ret, filterItem)
}
return
}
func (s *TestFilterService) ListTaskFilter(config commDomain.WorkspaceConf, productId int) (ret []serverDomain.FilterItem, err error) {
tasks, _ := zentaoHelper.LoadTask(productId, config)
for _, item := range tasks {
filterItem := serverDomain.FilterItem{Label: item.Name, Value: item.Id}
ret = append(ret, filterItem)
}
return
}
......@@ -30,6 +30,7 @@ export interface SettingsType {
currProductIdBySite: string;
currWorkspace: string;
scriptFilters: string;
expandedKeys: string;
/**
* Ajax请求头发送Token 的 Key值
......@@ -58,6 +59,7 @@ const settings: SettingsType = {
currProductIdBySite: 'currProductIdBySite',
currWorkspace: 'currWorkspace',
scriptFilters: 'scriptFilters',
expandedKeys: 'expandedKeys',
ajaxHeadersTokenKey: 'Authorization',
ajaxResponseNoVerifyUrl: [
......
......@@ -43,6 +43,17 @@ export const setScriptFilters = async (by, val) => {
if (val) mp[by] = val
console.log('---', mp)
await setCache(settings.scriptFilters, mp);
}
export const cacheExpandedKeys = async (keys) => {
console.log('cacheExpandedKeys', keys)
const arr = [...keys]
await setCache(settings.expandedKeys, arr);
}
export const retrieveExpandedKeys = async () => {
console.log('retrieveExpandedKeys')
const keys = await getCache(settings.expandedKeys);
return [...keys]
}
......@@ -21,7 +21,7 @@
ref="select"
v-model:value="filerValue"
@change="selectFilerValue"
style="width: 120px"
style="width: 200px"
:bordered="false"
:dropdownMatchSelectWidth="false"
>
......@@ -92,8 +92,9 @@ 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, setScriptFilters} from "@/utils/cache";
import {cacheExpandedKeys, getScriptFilters, retrieveExpandedKeys, setScriptFilters} from "@/utils/cache";
import {listFilterItems} from "@/views/script/service";
import _ from "lodash";
interface ListScriptPageSetupData {
t: (key: string | number) => string;
......@@ -146,6 +147,19 @@ export default defineComponent({
const currProduct = computed<any>(() => zentaoStore.state.zentao.currProduct);
const treeData = computed<any>(() => zentaoStore.state.zentao.testScripts);
watch(treeData, (currConfig) => {
console.log('watch treeData', treeData.value)
retrieveExpandedKeys().then(async keys => {
console.log('keys', keys, expandedKeys.value)
if (keys) expandedKeys.value = keys
if (!expandedKeys.value || expandedKeys.value.length === 0) {
getOpenKeys(treeData.value[0], false) // expend first level folder
await cacheExpandedKeys(expandedKeys.value)
}
})
}, {deep: true})
console.log(`treeData loaded ${scriptLoaded.value}`, treeData.value.length)
if (!scriptLoaded.value) { // switch to current page
zentaoStore.dispatch('zentao/fetchSitesAndProducts', {needLoadScript: true})
......@@ -160,7 +174,6 @@ export default defineComponent({
filerType.value = filter.by
filerValue.value = filter.val
listFilterItems(filerType.value).then((data) => {
console.log('ksjdhfdsf', data)
filerItems.value = data.data
})
}
......@@ -190,10 +203,6 @@ export default defineComponent({
expandedKeys.value = []
getOpenKeys(treeData.value[0], false)
watch(treeData, (currConfig) => {
expandedKeys.value = []
getOpenKeys(treeData.value[0], false)
})
let tree = ref(null)
......@@ -208,10 +217,6 @@ export default defineComponent({
resizeWidth('main', 'left', 'resize', 'content', 280, 800)
})
const expandNode = (keys: string[], e: any) => {
console.log('expandNode', keys[0], e)
}
onUnmounted(() => {
console.log('onUnmounted', tree)
})
......@@ -230,15 +235,20 @@ export default defineComponent({
})
}
const expandNode = (keys: string[], e: any) => {
console.log('expandNode', expandedKeys.value)
cacheExpandedKeys(expandedKeys.value)
}
const expandAll = (e) => {
console.log('expandAll')
isExpand.value = !isExpand.value
expandedKeys.value = []
if (isExpand.value) {
getOpenKeys(treeData.value[0], true)
}
if (isExpand.value) getOpenKeys(treeData.value[0], true)
console.log('expandAll', expandedKeys.value)
cacheExpandedKeys(expandedKeys.value)
}
const extract = () => {
console.log('extract', selectedNode.props)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册