From afa2b331c28b77b03d7d2de28697c1b7987f1924 Mon Sep 17 00:00:00 2001 From: aaron <462826@qq.com> Date: Fri, 18 Mar 2022 11:20:51 +0800 Subject: [PATCH] change load scripts logic --- .../server/modules/v1/controller/zentao.go | 13 +- internal/server/modules/v1/index/zentao.go | 3 +- internal/server/modules/v1/service/site.go | 11 ++ ui/src/config/settings.ts | 3 + .../IndexLayout/components/TopSiteProduct.vue | 6 +- ui/src/locales/en-US.ts | 4 + ui/src/locales/zh-CN.ts | 6 +- ui/src/store/zentao.ts | 16 +- ui/src/utils/cache.ts | 46 ++++++ ui/src/utils/request.ts | 17 ++- ui/src/views/component/workspace/create.vue | 138 ------------------ ui/src/views/component/workspace/service.ts | 13 -- ui/src/views/script/index.vue | 63 +++++++- ui/src/views/script/locales/en-US.ts | 3 +- 14 files changed, 165 insertions(+), 177 deletions(-) create mode 100644 ui/src/utils/cache.ts delete mode 100644 ui/src/views/component/workspace/create.vue delete mode 100644 ui/src/views/component/workspace/service.ts diff --git a/internal/server/modules/v1/controller/zentao.go b/internal/server/modules/v1/controller/zentao.go index 1244ddd6..2856860a 100644 --- a/internal/server/modules/v1/controller/zentao.go +++ b/internal/server/modules/v1/controller/zentao.go @@ -35,17 +35,22 @@ func (c *ZentaoCtrl) GetProfile(ctx iris.Context) { ctx.JSON(c.SuccessResp(data)) } -func (c *ZentaoCtrl) ListSiteAndProduct(ctx iris.Context) { +func (c *ZentaoCtrl) ListSiteAndProductWithScripts(ctx iris.Context) { currSiteId, _ := ctx.URLParamInt("currSiteId") currProductId, _ := ctx.URLParamInt("currProductId") + needLoadScript, _ := ctx.URLParamBool("needLoadScript") sites, currSite, _ := c.SiteService.LoadSites(currSiteId) products, currProduct, _ := zentaoHelper.LoadSiteProduct(currSite, currProductId) - testScripts, _ := c.TestScriptService.LoadTestScriptsBySiteProduct(currSite, currProduct) - - data := iris.Map{"sites": sites, "products": products, "testScripts": testScripts, + data := iris.Map{"sites": sites, "products": products, "currSite": currSite, "currProduct": currProduct} + + if needLoadScript { + testScripts, _ := c.TestScriptService.LoadTestScriptsBySiteProduct(currSite, currProduct) + data["testScripts"] = testScripts + } + ctx.JSON(c.SuccessResp(data)) } diff --git a/internal/server/modules/v1/index/zentao.go b/internal/server/modules/v1/index/zentao.go index 79aa5ca3..41511cdd 100644 --- a/internal/server/modules/v1/index/zentao.go +++ b/internal/server/modules/v1/index/zentao.go @@ -23,7 +23,8 @@ func (m *ZentaoModule) Party() module.WebModule { index.Get("/listLang", m.ZentaoCtrl.ListLang).Name = "脚本语言列表" index.Get("/getProfile", m.ZentaoCtrl.GetProfile).Name = "脚本语言列表" - index.Get("/listSiteAndProduct", m.ZentaoCtrl.ListSiteAndProduct).Name = "获取禅道站点及其下产品" + index.Get("/listSiteAndProduct", m.ZentaoCtrl.ListSiteAndProductWithScripts).Name = "获取禅道站点及其下产品" + index.Get("/listProduct", m.ZentaoCtrl.ListProduct).Name = "产品列表" index.Get("/listModule", m.ZentaoCtrl.ListModule).Name = "模块列表" index.Get("/listSuite", m.ZentaoCtrl.ListSuite).Name = "套件列表" diff --git a/internal/server/modules/v1/service/site.go b/internal/server/modules/v1/service/site.go index 82f0e8e6..6750a78d 100644 --- a/internal/server/modules/v1/service/site.go +++ b/internal/server/modules/v1/service/site.go @@ -23,6 +23,17 @@ func (s *SiteService) Paginate(req serverDomain.ReqPaginate) (ret domain.PageDat func (s *SiteService) Get(id uint) (site model.Site, err error) { return s.SiteRepo.Get(id) } +func (s *SiteService) GetDomainObject(id uint) (site serverDomain.ZentaoSite, err error) { + po, _ := s.SiteRepo.Get(id) + + site = serverDomain.ZentaoSite{ + Url: po.Url, + Username: po.Username, + Password: po.Password, + } + + return +} func (s *SiteService) Create(site model.Site) (id uint, err error) { id, err = s.SiteRepo.Create(site) diff --git a/ui/src/config/settings.ts b/ui/src/config/settings.ts index 2d3a6696..1bcdea06 100644 --- a/ui/src/config/settings.ts +++ b/ui/src/config/settings.ts @@ -1,4 +1,5 @@ import { RoutesDataItem } from "@/utils/routes"; +import {getScriptFilters} from "@/utils/cache"; /** * 站点配置 @@ -28,6 +29,7 @@ export interface SettingsType { currProductId: string; currProductIdBySite: string; currWorkspace: string; + scriptFilters: string; /** * Ajax请求头发送Token 的 Key值 @@ -55,6 +57,7 @@ const settings: SettingsType = { currProductId: 'currProductId', currProductIdBySite: 'currProductIdBySite', currWorkspace: 'currWorkspace', + scriptFilters: 'scriptFilters', ajaxHeadersTokenKey: 'Authorization', ajaxResponseNoVerifyUrl: [ diff --git a/ui/src/layouts/IndexLayout/components/TopSiteProduct.vue b/ui/src/layouts/IndexLayout/components/TopSiteProduct.vue index 853f01b1..4075668b 100644 --- a/ui/src/layouts/IndexLayout/components/TopSiteProduct.vue +++ b/ui/src/layouts/IndexLayout/components/TopSiteProduct.vue @@ -74,6 +74,8 @@ export default defineComponent({ const { t } = useI18n(); const router = useRouter(); + const needLoadScript = router.currentRoute.value.path === '/script/index' + const store = useStore<{ zentao: ZentaoData }>(); const sites = computed(() => store.state.zentao.sites); @@ -82,7 +84,7 @@ export default defineComponent({ const currSite = computed(() => store.state.zentao.currSite); const currProduct = computed(() => store.state.zentao.currProduct); - store.dispatch('zentao/fetchSitesAndProducts', {}) + store.dispatch('zentao/fetchSitesAndProducts', {needLoadScript: needLoadScript}) onMounted(() => { console.log('onMounted') @@ -94,7 +96,7 @@ export default defineComponent({ } const selectProduct = (product): void => { console.log('selectProduct', product) - store.dispatch('zentao/fetchSitesAndProducts', {currProductId: product.id}) + store.dispatch('zentao/fetchSitesAndProducts', {currProductId: product.id, needLoadScript: needLoadScript}) } return { diff --git a/ui/src/locales/en-US.ts b/ui/src/locales/en-US.ts index 49a583e6..198b5633 100644 --- a/ui/src/locales/en-US.ts +++ b/ui/src/locales/en-US.ts @@ -121,6 +121,8 @@ export default { 'save_success': 'Save successfully.', 'save_fail': 'Save failed.', + 'expand_all': 'Expand', + 'collapse_all': 'Collapse', 'wrong_url': 'Please input right ZenTao URL.', 'extract_success': 'Extract comments to test steps and checkpoints successfully.', 'extract_fail': 'Extract comments to test steps and checkpoints failed.', @@ -132,6 +134,8 @@ export default { 'delete_success': 'Delete successfully.', 'ws_conn_success': 'Connect to WebSocket successfully.', 'ws_conn_fail': 'Connect to WebSocket failed.', + 'no_script_for_unittest': 'No scriptS for Unit Test.', + 'extract_step': 'Extract Steps', 'pls_title': 'Please input title.', 'pls_name': 'Please input name.', diff --git a/ui/src/locales/zh-CN.ts b/ui/src/locales/zh-CN.ts index e9d782b8..117d9944 100644 --- a/ui/src/locales/zh-CN.ts +++ b/ui/src/locales/zh-CN.ts @@ -121,8 +121,8 @@ export default { 'save_success': '保存成功', 'save_fail': '保存失败', - 'expand_all': '展开全部', - 'collapse_all': '收缩全部', + 'expand_all': '展开', + 'collapse_all': '收缩', 'wrong_url': '请输入正确的的URL地址,以http或https开头。', 'extract_success': '提取注释为测试步骤和验证点成功。', 'extract_fail': '提取注释为测试步骤和验证点失败。', @@ -134,6 +134,8 @@ export default { 'delete_success': '删除成功', 'ws_conn_success': 'WebSocket连接成功。', 'ws_conn_fail': 'WebSocket连接失败。', + 'no_script_for_unittest': '此为单元测试工作目录,无ZTF脚本。', + 'extract_step': '提取步骤', 'pls_title': '请输入标题', 'pls_name': '请输入名称', diff --git a/ui/src/store/zentao.ts b/ui/src/store/zentao.ts index b011e27e..a40e2c4d 100644 --- a/ui/src/store/zentao.ts +++ b/ui/src/store/zentao.ts @@ -4,6 +4,7 @@ import { ResponseData } from '@/utils/request'; import {queryLang, querySiteAndProduct, getProfile, queryProduct, queryModule, querySuite, queryTask} from "../services/zentao"; import {getCache, setCache} from "@/utils/localCache"; import settings from "@/config/settings"; +import {setCurrProductIdBySite, setCurrSiteId} from "@/utils/cache"; export interface ZentaoData { langs: any[] @@ -15,6 +16,7 @@ export interface ZentaoData { testScripts: any[] currSite: any currProduct: any + scriptLoaded: boolean modules: any[] suites: any[] @@ -56,6 +58,7 @@ const initState: ZentaoData = { testScripts: [], currSite: {}, currProduct: {}, + scriptLoaded: false, modules: [], suites: [], @@ -80,18 +83,17 @@ const StoreModel: ModuleType = { async saveSitesAndProducts(state, payload) { state.sites = payload.sites; state.products = payload.products; - state.testScripts = [payload.testScripts]; + if (payload.testScripts) { + state.testScripts = [payload.testScripts]; + state.scriptLoaded = true + } state.currSite = payload.currSite; state.currProduct = payload.currProduct; // cache current site and product - setCache(settings.currSiteId, payload.currSite.id); - - let mp = await getCache(settings.currProductIdBySite); - if (!mp) mp = {} - mp[payload.currSite.id + ''] = payload.currProduct.id - setCache(settings.currProductIdBySite, mp); + await setCurrSiteId(payload.currSite.id); + await setCurrProductIdBySite(settings.currProductIdBySite, payload.currProduct.id); }, saveProducts(state, payload) { console.log('payload', payload) diff --git a/ui/src/utils/cache.ts b/ui/src/utils/cache.ts new file mode 100644 index 00000000..edf910f4 --- /dev/null +++ b/ui/src/utils/cache.ts @@ -0,0 +1,46 @@ + +import {getCache, setCache} from './localCache'; +import settings from '@/config/settings'; + +export const getCurrSiteId = async () => { + const currSiteId = await getCache(settings.currSiteId); + return currSiteId +} +export const setCurrSiteId = async (val) => { + await setCache(settings.currSiteId, val); +} + +export const getCurrProductIdBySite = async (currSiteId) => { + const mp = await getCache(settings.currProductIdBySite); + const currProductId = mp ? mp[currSiteId] : 0 + return currProductId +} +export const setCurrProductIdBySite = async (currSiteId, currProductId) => { + let mp = await getCache(settings.currProductIdBySite); + if (!mp) mp = {} + mp[currSiteId + ''] = currProductId + await setCache(settings.currProductIdBySite, mp); +} + +// script filters +export const getScriptFilters = async () => { + const mp = await getCache(settings.scriptFilters); + + if (!mp) { + return {by: 'workspace', val: ''} + } + + const by = mp.by + const val = mp[by] + + return {by: by, val: val} +} +export const setScriptFilters = async (by, val) => { + let mp = await getCache(settings.scriptFilters); + + if (!mp) mp = {} + mp.by = by + mp[by] = val + + await setCache(settings.scriptFilters, mp); +} diff --git a/ui/src/utils/request.ts b/ui/src/utils/request.ts index e857fc6b..93c50c01 100644 --- a/ui/src/utils/request.ts +++ b/ui/src/utils/request.ts @@ -7,6 +7,7 @@ import { notification } from "ant-design-vue"; import settings from '@/config/settings'; import { getCache, setCache } from '@/utils/localCache'; import i18n from "@/config/i18n"; +import {getCurrProductIdBySite, getCurrSiteId} from "@/utils/cache"; export interface ResponseData { code: number; @@ -96,18 +97,20 @@ request.interceptors.request.use( config.params = { ...config.params, ts: Date.now() }; if (!config.params[settings.currSiteId]) { - const currSiteId = await getCache(settings.currSiteId); + const currSiteId = await getCurrSiteId(); config.params = { ...config.params, [settings.currSiteId]: currSiteId, lang: i18n.global.locale.value }; } if (!config.params[settings.currProductId]) { - const mp = await getCache(settings.currProductIdBySite); - const currProductId = mp ? mp[config.params[settings.currSiteId]] : 0 + const currProductId = await getCurrProductIdBySite(config.params[settings.currSiteId]) config.params = { ...config.params, [settings.currProductId]: currProductId, lang: i18n.global.locale.value }; } - if (!config.params[settings.currWorkspace]) { - const workspacePath = await getCache(settings.currWorkspace); - config.params = { ...config.params, [settings.currWorkspace]: workspacePath, lang: i18n.global.locale.value }; - } + + console.log(`currSiteId=${config.params[settings.currSiteId]}, currProductId=${config.params[settings.currProductId]}`) + + // if (!config.params[settings.currWorkspace]) { + // const workspacePath = await getCache(settings.currWorkspace); + // config.params = { ...config.params, [settings.currWorkspace]: workspacePath, lang: i18n.global.locale.value }; + // } console.log('=== request ===', config.url, config) return config; diff --git a/ui/src/views/component/workspace/create.vue b/ui/src/views/component/workspace/create.vue deleted file mode 100644 index 9aad32c4..00000000 --- a/ui/src/views/component/workspace/create.vue +++ /dev/null @@ -1,138 +0,0 @@ - - - \ No newline at end of file diff --git a/ui/src/views/component/workspace/service.ts b/ui/src/views/component/workspace/service.ts deleted file mode 100644 index aa00dddd..00000000 --- a/ui/src/views/component/workspace/service.ts +++ /dev/null @@ -1,13 +0,0 @@ -import request from '@/utils/request'; - -const apiPath = 'file'; - -export async function listUserHome(parentDir): Promise { - const params = {parentDir: parentDir} - - return request({ - url: `/${apiPath}/listDir`, - method: 'get', - params - }); -} diff --git a/ui/src/views/script/index.vue b/ui/src/views/script/index.vue index 4579d6e1..8fa82a10 100644 --- a/ui/src/views/script/index.vue +++ b/ui/src/views/script/index.vue @@ -3,7 +3,33 @@
-
+
+ + 按目录 + 按模块 + 按套件 + 按任务 + + + + + {{item.name}} + + +
{{ t('expand_all') }} @@ -66,6 +92,7 @@ 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"; interface ListScriptPageSetupData { t: (key: string | number) => string; @@ -75,6 +102,12 @@ interface ListScriptPageSetupData { replaceFields: any, tree: Ref; + filerItems: Ref<[]> + filerType: Ref + filerValue: Ref + selectFilerType: (v) => void; + selectFilerValue: (v) => void; + script: ComputedRef scriptCode: Ref; lang: Ref; @@ -107,10 +140,31 @@ export default defineComponent({ let isExpand = ref(false); const zentaoStore = useStore<{ zentao: ZentaoData }>(); + let scriptLoaded = computed(() => zentaoStore.state.zentao.scriptLoaded); const currSite = computed(() => zentaoStore.state.zentao.currSite); const currProduct = computed(() => zentaoStore.state.zentao.currProduct); const treeData = computed(() => zentaoStore.state.zentao.testScripts); + console.log(`treeData loaded ${scriptLoaded.value}`, treeData.value.length) + if (!scriptLoaded.value) { // switch to current page + zentaoStore.dispatch('zentao/fetchSitesAndProducts', {needLoadScript: true}) + } + + let filerItems = ref([] as any) + const filerType = ref('') + const filerValue = ref('') + getScriptFilters().then( (filter) => { + filerType.value = filter.by + filerValue.value = filter.val + // filerItems = + }) + const selectFilerType = (val) => { + console.log('selectFilerType') + } + const selectFilerValue = (val) => { + console.log('selectFilerValue') + } + const expandedKeys = ref([]); const getOpenKeys = (treeNode, isAll) => { @@ -195,6 +249,13 @@ export default defineComponent({ currSite, currProduct, treeData, + filerItems, + + filerType, + filerValue, + selectFilerType, + selectFilerValue, + replaceFields, expandNode, selectNode, diff --git a/ui/src/views/script/locales/en-US.ts b/ui/src/views/script/locales/en-US.ts index 804f355c..be60da75 100644 --- a/ui/src/views/script/locales/en-US.ts +++ b/ui/src/views/script/locales/en-US.ts @@ -2,8 +2,7 @@ export default { 'index-layout.menu.script': 'Script', 'index-layout.menu.script.list': 'Script Management', - 'no_script_for_unittest': 'No scriptS for Unit Test.', + 'expand_all': 'Expand All', 'collapse_all': 'Collapse All', - 'extract_step': 'Extract Steps', }; -- GitLab