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

change load scripts logic

上级 a01173e6
......@@ -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))
}
......
......@@ -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 = "套件列表"
......
......@@ -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)
......
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: [
......
......@@ -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<any[]>(() => store.state.zentao.sites);
......@@ -82,7 +84,7 @@ export default defineComponent({
const currSite = computed<any>(() => store.state.zentao.currSite);
const currProduct = computed<any>(() => 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 {
......
......@@ -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.',
......
......@@ -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': '请输入名称',
......
......@@ -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)
......
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);
}
......@@ -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;
......
<template>
<a-modal
:destroy-on-close="true"
:mask-closable="false"
:title="t('create_workspace')"
:visible="visible"
:onCancel="onCancel"
>
<template #footer>
<a-button key="submit" type="primary" @click="onFinish">{{t('save')}}</a-button>
<a-button key="back" @click="() => onCancel()">{{t('cancel')}}</a-button>
</template>
<div>
<a-form :labelCol="{ span: 4 }" :wrapper-col="{span:20}">
<a-form-item :label="t('path')" v-bind="validateInfos.path" :placeholder="t('workspace_path')">
<a-input-search
v-if="isElectron"
v-model:value="modelRef.path"
@search="selectDir"
spellcheck="false"
>
<template #enterButton>
<a-button>选择</a-button>
</template>
</a-input-search>
<a-input
v-if="!isElectron"
v-model:value="modelRef.path"
spellcheck="false" />
</a-form-item>
<a-form-item :label="t('name')">
<a-input v-model:value="modelRef.name" :placeholder="t('use_dir_name')"/>
</a-form-item>
<a-form-item :label="t('type')" v-bind="validateInfos.type">
<a-select v-model:value="modelRef.type">
<a-select-option key="func" value="func">{{t('test_type_ztf')}}</a-select-option>
<a-select-option key="unit" value="unit">{{t('test_type_other')}}</a-select-option>
</a-select>
</a-form-item>
</a-form>
</div>
</a-modal>
</template>
<script lang="ts">
import {defineComponent, onMounted, PropType, reactive, ref, Ref} from "vue";
import {Interpreter} from "@/views/config/data";
import {useI18n} from "vue-i18n";
import {Form} from "ant-design-vue";
import { validateInfos } from 'ant-design-vue/lib/form/useForm';
interface WorkspaceCreateFormSetupData {
t: (key: string | number) => string;
isElectron: Ref<boolean>;
selectDir: () => void;
modelRef: Ref<Interpreter>
validateInfos: validateInfos
onFinish: () => Promise<void>;
}
export default defineComponent({
name: 'WorkspaceCreateForm',
props: {
visible: {
type: Boolean,
required: true
},
onCancel: {
type: Function,
required: true
},
onSubmit: {
type: Function as PropType<(values: any) => void>,
required: true
}
},
components: {},
setup(props): WorkspaceCreateFormSetupData {
const { t } = useI18n();
const modelRef = ref<any>({path: '', type: 'func'})
const rulesRef = reactive({
path: [ { required: true, message: t('pls_workspace_path') } ],
type: [ { required: true, message: t('pls_workspace_type') } ],
});
const { validate, validateInfos } = Form.useForm(modelRef, rulesRef);
const isElectron = ref(!!window.require)
const selectDir = () => {
console.log('selectDir')
if (isElectron.value) {
const {dialog} = window.require('@electron/remote');
dialog.showOpenDialog({
properties: ['openDirectory']
}).then(result => {
if (result.filePaths && result.filePaths.length > 0) {
modelRef.value.path = result.filePaths[0]
}
}).catch(err => {
console.log(err)
})
}
}
const onFinish = async () => {
console.log('onFinish')
validate().then(() => {
props.onSubmit(modelRef);
}).catch(err => { console.log('') })
}
onMounted(()=> {
console.log('onMounted')
})
return {
t,
isElectron,
selectDir,
modelRef,
validateInfos,
onFinish
}
}
})
</script>
\ No newline at end of file
import request from '@/utils/request';
const apiPath = 'file';
export async function listUserHome(parentDir): Promise<any> {
const params = {parentDir: parentDir}
return request({
url: `/${apiPath}/listDir`,
method: 'get',
params
});
}
......@@ -3,7 +3,33 @@
<div id="main">
<div id="left">
<div class="toolbar">
<div class="left"></div>
<div class="left">
<a-select
ref="select"
v-model:value="filerType"
@change="selectFilerType"
style="width: 90px"
:bordered="false"
>
<a-select-option value="workspace">按目录</a-select-option>
<a-select-option value="module">按模块</a-select-option>
<a-select-option value="suite">按套件</a-select-option>
<a-select-option value="task">按任务</a-select-option>
</a-select>
<a-select
ref="select"
v-model:value="filerValue"
@change="selectFilerValue"
style="width: 120px"
:bordered="false"
:dropdownMatchSelectWidth="false"
>
<a-select-option v-for="item in filerItems" :key="item.id" :value="item.id">
{{item.name}}
</a-select-option>
</a-select>
</div>
<div class="right">
<a-button @click="expandAll" type="link">
<span v-if="!isExpand">{{ t('expand_all') }}</span>
......@@ -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<string>;
lang: Ref<string>;
......@@ -107,10 +140,31 @@ export default defineComponent({
let isExpand = ref(false);
const zentaoStore = useStore<{ zentao: ZentaoData }>();
let scriptLoaded = computed<any>(() => zentaoStore.state.zentao.scriptLoaded);
const currSite = computed<any>(() => zentaoStore.state.zentao.currSite);
const currProduct = computed<any>(() => zentaoStore.state.zentao.currProduct);
const treeData = computed<any>(() => 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<string[]>([]);
const getOpenKeys = (treeNode, isAll) => {
......@@ -195,6 +249,13 @@ export default defineComponent({
currSite,
currProduct,
treeData,
filerItems,
filerType,
filerValue,
selectFilerType,
selectFilerValue,
replaceFields,
expandNode,
selectNode,
......
......@@ -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',
};
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册