WorkDir.vue 19.7 KB
Newer Older
H
Hao Sun 已提交
1
<template>
Z
zhaoke 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
  <div class="left-pannel-contain">
    <div :class="checkable && checkedKeys.length ? 'workdir-with-btn' : 'workdir'">
      <Tree
        :data="treeData"
        :checkable="checkable"
        ref="treeRef"
        @active="selectNode"
        @rightClick="onRightClick"
        @check="checkNode"
        @clickToolbar="onToolbarClicked"
        @collapse="expandNode"
        :defaultCollapsedMap="collapsedMap"
        :defaultCollapsed="true"
      />
      <FormNode :show="showModal" @submit="createNode" @cancel="modalClose" ref="formNode" />
    </div>
18
    <Button
Z
zhaoke 已提交
19
      v-if="checkable && checkedKeys.length"
20 21
      class="rounded border primary-pale run-selected" icon="run-all"
      :label="t('exec_selected')"
Z
zhaoke 已提交
22 23
      @click="execSelected"
     />
24 25

    <div v-if="contextNode.id && rightVisible" :style="menuStyle">
Z
zhaoke 已提交
26
      <TreeContextMenu :treeNode="contextNode" :clipboardData="clipboardData" :onMenuClick="menuClick" :siteId="currSite.id"/>
27
    </div>
Z
zhaoke 已提交
28
    <FormSyncFromZentao v-if="showSyncFromZentaoModal"
29 30 31 32 33 34
      :show="showSyncFromZentaoModal"
      @submit="syncFromZentaoSubmit"
      @cancel="showSyncFromZentaoModal = !showSyncFromZentaoModal"
      :workspaceId="syncFromZentaoWorkspaceId"
      ref="syncFromZentaoRef"
    />
aaronchen2k2k's avatar
aaronchen2k2k 已提交
35
  </div>
H
Hao Sun 已提交
36
</template>
aaronchen2k2k's avatar
aaronchen2k2k 已提交
37 38

<script setup lang="ts">
39 40
import { useI18n } from "vue-i18n";
import { useStore } from "vuex";
aaronchen2k2k's avatar
aaronchen2k2k 已提交
41
import { StateType as GlobalData } from "@/store/global";
42 43 44
import { ZentaoData } from "@/store/zentao";
import { ScriptData } from "@/views/script/store";
import { WorkspaceData } from "@/store/workspace";
45
import {getContextMenuStyle, resizeWidth} from "@/utils/dom";
aaronchen2k2k's avatar
aaronchen2k2k 已提交
46
import Tree from "@/components/Tree.vue";
R
root 已提交
47
import notification from "@/utils/notification";
Z
zhaoke 已提交
48
import { computed, defineExpose, onMounted, onUnmounted, ref, watch } from "vue";
Z
zhaoke 已提交
49
import Button from '@/components/Button.vue';
50
import TreeContextMenu from './TreeContextMenu.vue';
51
import FormSyncFromZentao  from "./FormSyncFromZentao.vue";
Z
zhaoke 已提交
52 53 54

import bus from "@/utils/eventBus";
import {
aaronchen2k2k's avatar
aaronchen2k2k 已提交
55 56 57 58
  getExpandedKeys,
  getScriptDisplayBy,
  getScriptFilters,
  setExpandedKeys,
Z
zhaoke 已提交
59 60
} from "@/utils/cache";
import {
aaronchen2k2k's avatar
aaronchen2k2k 已提交
61 62
  getCaseIdsFromReport,
  getNodeMap,
63
  listFilterItems,
Z
zhaoke 已提交
64
} from "@/views/script/service";
65 66
import { useRouter } from "vue-router";
import { isWindows } from "@/utils/comm";
Z
zhaoke 已提交
67 68
import debounce from "lodash.debounce";
import throttle from "lodash.debounce";
Z
zhaoke 已提交
69
import Modal from "@/utils/modal"
Z
zhaoke 已提交
70
import FormNode from "./FormNode.vue";
Z
zhaoke 已提交
71
import { key } from "localforage";
Z
zhaoke 已提交
72
import settings from "@/config/settings";
Z
zhaoke 已提交
73
import {getFileNodesUnderParent, genWorkspaceToScriptsMap} from "@/views/script/service";
Z
zhaoke 已提交
74

75
const { t } = useI18n();
aaronchen2k2k's avatar
aaronchen2k2k 已提交
76

aaronchen2k2k's avatar
aaronchen2k2k 已提交
77 78
const store = useStore<{ global: GlobalData, Zentao: ZentaoData, Script: ScriptData, Workspace: WorkspaceData }>();
const global = computed<any>(() => store.state.global.tabIdToWorkspaceIdMap);
aaronchen2k2k's avatar
aaronchen2k2k 已提交
79 80
const currSite = computed<any>(() => store.state.Zentao.currSite);
const currProduct = computed<any>(() => store.state.Zentao.currProduct);
aaronchen2k2k's avatar
aaronchen2k2k 已提交
81

aaronchen2k2k's avatar
aaronchen2k2k 已提交
82
const currWorkspace = computed<any>(() => store.state.Script.currWorkspace);
aaronchen2k2k's avatar
aaronchen2k2k 已提交
83

Z
zhaoke 已提交
84 85
const isWin = isWindows()

aaronchen2k2k's avatar
aaronchen2k2k 已提交
86 87
store.dispatch('Zentao/fetchLangs')
const langs = computed<any[]>(() => store.state.Zentao.langs);
Z
zhaoke 已提交
88

Z
zhaoke 已提交
89 90 91 92 93 94 95 96 97 98
const router = useRouter();
let workspace = router.currentRoute.value.params.workspace as string
workspace = workspace === '-' ? '' : workspace
let seq = router.currentRoute.value.params.seq as string
seq = seq === '-' ? '' : seq
let scope = router.currentRoute.value.params.scope as string
scope = scope === '-' ? '' : scope

const filerType = ref('')
const filerValue = ref('')
Z
zhaoke 已提交
99
const showModal = ref(false)
100
const toolbarAction = ref('')
aaronchen2k2k's avatar
aaronchen2k2k 已提交
101
const currentNode = ref({} as any) // parent node for create node
Z
zhaoke 已提交
102
const collapsedMap = ref({} as any)
Z
zhaoke 已提交
103
const checkedKeys = ref<string[]>([])
Z
zhaoke 已提交
104
const showSyncFromZentaoModal = ref(false);
105
const syncFromZentaoWorkspaceId = ref(0);
Z
zhaoke 已提交
106

aaronchen2k2k's avatar
aaronchen2k2k 已提交
107
onMounted(() => {
aaronchen2k2k's avatar
aaronchen2k2k 已提交
108 109 110 111 112
  console.log('onMounted')
  initData();
  setTimeout(() => {
    resizeWidth('main', 'left', 'splitter-h', 'right', 380, 800)
  }, 600)
aaronchen2k2k's avatar
aaronchen2k2k 已提交
113 114
})

aaronchen2k2k's avatar
aaronchen2k2k 已提交
115
const onToolbarClicked = (e) => {
Z
zhaoke 已提交
116
  const node = e.node == undefined ? treeDataMap.value[''] : treeDataMap.value[e.node.id]
aaronchen2k2k's avatar
aaronchen2k2k 已提交
117
  store.dispatch('Script/changeWorkspace',
118
    { id: node.workspaceId, type: node.workspaceType })
aaronchen2k2k's avatar
aaronchen2k2k 已提交
119

aaronchen2k2k's avatar
aaronchen2k2k 已提交
120
  currentNode.value = node;
Z
zhaoke 已提交
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
  switch (e.event.key) {
    case 'runTest':
      runTest(currentNode);
      break;
    case 'createFile':
    case 'createWorkspace':
    case 'createDir':
      showModal.value = true;
      toolbarAction.value = e.event.key;
      break;
    case 'deleteWorkspace':
      Modal.confirm({
          title: t('delete'),
          content: t('confirm_to_delete_workspace', { p: node.title }),
          showOkBtn: true
        },
        {
          "onOk": () => {
            store.dispatch('Workspace/removeWorkspace', node.path)
              .then((response) => {
141 142 143 144 145
              if (response) {
                notification.success({ message: t('delete_success') });
                loadScripts()
              }
            })
Z
zhaoke 已提交
146
          }
147
        }
Z
zhaoke 已提交
148 149 150 151 152 153 154 155 156 157 158 159 160
      );
    break;
    case 'runScript':
      console.log('run script', currentNode.value);
      bus.emit(settings.eventExec,
        {execType: currentNode.value.workspaceType === 'ztf' ? 'ztf' : 'unit', scripts: currentNode.value.isLeaf ? [currentNode.value] : currentNode.value.children});
      break;
    case 'checkinCase':
      console.log('checkin case', currentNode.value);
      break;
    case 'checkoutCase':
      console.log('checkout case', currentNode.value);
      break;
aaronchen2k2k's avatar
aaronchen2k2k 已提交
161
  }
Z
zhaoke 已提交
162 163 164
}

const runTest = (node) => {
aaronchen2k2k's avatar
aaronchen2k2k 已提交
165 166 167 168 169 170 171 172 173 174 175 176
  console.log('runTest', node.value)

  store.dispatch('tabs/open', {
    id: 'workspace-' + node.value.workspaceId,
    title: node.value.title,
    type: 'execUnit',
    changed: false,
    data: {
      workspaceId: node.value.workspaceId,
      workspaceType: node.value.workspaceType,
    }
  });
Z
zhaoke 已提交
177
}
Z
zhaoke 已提交
178

Z
zhaoke 已提交
179
const modalClose = () => {
aaronchen2k2k's avatar
aaronchen2k2k 已提交
180
  showModal.value = false;
Z
zhaoke 已提交
181 182 183 184
}

const treeRef = ref<{ isAllCollapsed: () => boolean, toggleAllCollapsed: () => void }>();

aaronchen2k2k's avatar
aaronchen2k2k 已提交
185
let treeData = computed<any>(() => store.state.Script.list);
H
Hao Sun 已提交
186 187 188 189

const checkable = ref(false);

function toggleCheckable(toggle?: boolean) {
aaronchen2k2k's avatar
aaronchen2k2k 已提交
190 191 192 193
  if (toggle === undefined) {
    toggle = !checkable.value;
  }
  checkable.value = toggle;
H
Hao Sun 已提交
194 195
}

Z
zhaoke 已提交
196 197

const selectCasesFromReport = async (): Promise<void> => {
aaronchen2k2k's avatar
aaronchen2k2k 已提交
198
  if (!seq) return
Z
zhaoke 已提交
199

aaronchen2k2k's avatar
aaronchen2k2k 已提交
200 201 202 203
  getCaseIdsFromReport(workspace, seq, scope).then((json) => {
    checkedKeys.value = json.data
    router.push(`/script/index`) // remove the params of re-test
  })
Z
zhaoke 已提交
204 205 206 207
}
selectCasesFromReport()

watch(currProduct, () => {
aaronchen2k2k's avatar
aaronchen2k2k 已提交
208 209
  console.log('watch currProduct', currProduct.value.id)
  initData()
210
}, { deep: true })
Z
zhaoke 已提交
211 212

watch(treeData, (currConfig) => {
aaronchen2k2k's avatar
aaronchen2k2k 已提交
213 214
  console.log('watch treeData', treeData.value)
  onTreeDataChanged()
215
}, { deep: true })
Z
zhaoke 已提交
216 217 218 219

let filerItems = ref([] as any)

const loadScripts = async () => {
aaronchen2k2k's avatar
aaronchen2k2k 已提交
220 221
  console.log(`loadScripts should be executed only once`)
  console.log(`filerType: ${filerType.value}, filerValue: ${filerValue.value}`)
Z
zhaoke 已提交
222

223
  const params = { displayBy: displayBy.value, filerType: filerType.value, filerValue: filerValue.value } as any
aaronchen2k2k's avatar
aaronchen2k2k 已提交
224
  store.dispatch('Script/listScript', params)
Z
zhaoke 已提交
225 226 227
}

const onTreeDataChanged = async () => {
aaronchen2k2k's avatar
aaronchen2k2k 已提交
228
  getNodeMapCall()
Z
zhaoke 已提交
229

aaronchen2k2k's avatar
aaronchen2k2k 已提交
230 231
  getExpandedKeys(currSite.value.id, currProduct.value.id).then(async cachedKeys => {
    console.log('cachedKeys', currSite.value.id, currProduct.value.id)
Z
zhaoke 已提交
232

aaronchen2k2k's avatar
aaronchen2k2k 已提交
233
    if (cachedKeys) expandedKeys.value = cachedKeys
Z
zhaoke 已提交
234

aaronchen2k2k's avatar
aaronchen2k2k 已提交
235
    if (!cachedKeys || cachedKeys.length === 0) {
aaronchen2k2k's avatar
aaronchen2k2k 已提交
236
      // 修改
237 238
      // getOpenKeys(treeData.value[0], false) // expend first level folder
      // await setExpandedKeys(currSite.value.id, currProduct.value.id, expandedKeys.value)
aaronchen2k2k's avatar
aaronchen2k2k 已提交
239 240
    }
  })
Z
zhaoke 已提交
241 242 243 244
}

// display
const loadDisplayBy = async () => {
aaronchen2k2k's avatar
aaronchen2k2k 已提交
245
  displayBy.value = await getScriptDisplayBy(currSite.value.id, currProduct.value.id)
Z
zhaoke 已提交
246 247 248 249
}

// filters
const loadFilterItems = async () => {
aaronchen2k2k's avatar
aaronchen2k2k 已提交
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
  const data = await getScriptFilters(displayBy.value, currSite.value.id, currProduct.value.id)

  if (!filerType.value) {
    filerType.value = data.by
  }
  filerValue.value = data.val

  if (!currProduct.value.id && filerType.value !== 'workspace') {
    filerType.value = 'workspace'
    filerValue.value = ''
  }

  if (filerType.value) {
    const result = await listFilterItems(filerType.value)
    filerItems.value = result.data

    let found = false
    if (filerItems.value) {
      filerItems.value.forEach((item) => {
        // console.log(`${filerValue.value}, ${item.value}`)
        if (filerValue.value === item.value) found = true
      })
Z
zhaoke 已提交
272 273
    }

aaronchen2k2k's avatar
aaronchen2k2k 已提交
274 275
    if (!found) filerValue.value = ''
  }
Z
zhaoke 已提交
276 277 278
}

const initData = debounce(async () => {
aaronchen2k2k's avatar
aaronchen2k2k 已提交
279 280
  console.log('init')
  if (!currSite.value.id) return
Z
zhaoke 已提交
281

aaronchen2k2k's avatar
aaronchen2k2k 已提交
282 283 284
  await loadDisplayBy()
  await loadFilterItems()
  await loadScripts()
Z
zhaoke 已提交
285 286 287 288 289 290 291
}, 50)

// only do it when switch from another pages, otherwise will called by watching currProduct method.
if (filerValue.value.length === 0) initData()

const expandedKeys = ref<string[]>([]);
const getOpenKeys = (treeNode: any, openAll: boolean) => { // expand top one level if openAll is false
aaronchen2k2k's avatar
aaronchen2k2k 已提交
292 293
  if (!treeNode) return
  expandedKeys.value.push(treeNode.path)
Z
zhaoke 已提交
294

aaronchen2k2k's avatar
aaronchen2k2k 已提交
295 296 297 298 299
  if (treeNode.children && openAll) {
    treeNode.children.forEach((item, index) => {
      getOpenKeys(item, openAll)
    })
  }
Z
zhaoke 已提交
300

aaronchen2k2k's avatar
aaronchen2k2k 已提交
301
  console.log('keys', expandedKeys.value)
Z
zhaoke 已提交
302 303
}

Z
zhaoke 已提交
304 305 306 307 308 309 310
watch(expandedKeys, () => {
    console.log('watch expandedKeys')
    for (let treeDataKey in treeDataMap.value) {
        collapsedMap.value[treeDataKey] = expandedKeys.value.indexOf(treeDataKey) !== -1 ? false : true
    }
}, { deep: true })

Z
zhaoke 已提交
311 312 313 314 315 316 317
let isExpand = ref(false);
let showCheckbox = ref(false)
let displayBy = ref('workspace')

let tree = ref(null)

onMounted(() => {
aaronchen2k2k's avatar
aaronchen2k2k 已提交
318
  console.log('onMounted', tree)
Z
zhaoke 已提交
319 320
})
onUnmounted(() => {
321
  console.log('onUnmounted', tree)
Z
zhaoke 已提交
322 323 324
})

const selectNode = (activeNode) => {
aaronchen2k2k's avatar
aaronchen2k2k 已提交
325
  console.log('selectNode', activeNode.activeID, global.value)
Z
zhaoke 已提交
326

Z
zhaoke 已提交
327
  const node = treeDataMap.value[activeNode.activeID]
aaronchen2k2k's avatar
aaronchen2k2k 已提交
328
  console.log('node id', node.caseId)
aaronchen2k2k's avatar
aaronchen2k2k 已提交
329
  if (node.workspaceType !== 'ztf') checkNothing()
Z
zhaoke 已提交
330

aaronchen2k2k's avatar
aaronchen2k2k 已提交
331
  store.dispatch('Script/getScript', node)
aaronchen2k2k's avatar
aaronchen2k2k 已提交
332
  if (node.type === 'file') {
aaronchen2k2k's avatar
aaronchen2k2k 已提交
333 334
    const tabId = node.workspaceType === 'ztf' && node.path.indexOf('.exp') !== node.path.length - 4
        ? 'script-' + node.path : 'code-' + node.path
aaronchen2k2k's avatar
aaronchen2k2k 已提交
335 336
    global.value[tabId] = node.workspaceId

aaronchen2k2k's avatar
aaronchen2k2k 已提交
337
    store.dispatch('tabs/open', {
aaronchen2k2k's avatar
aaronchen2k2k 已提交
338
      id: tabId,
aaronchen2k2k's avatar
aaronchen2k2k 已提交
339 340 341 342 343 344 345
      title: node.title,
      changed: false,
      type: 'script',
      data: node.path
    });
  }

aaronchen2k2k's avatar
aaronchen2k2k 已提交
346
  store.dispatch('Script/changeWorkspace',
347
    { id: node.workspaceId, type: node.workspaceType })
Z
zhaoke 已提交
348 349
}

Z
zhaoke 已提交
350 351 352 353 354 355 356 357 358 359
const checkNode = (keys) => {
  console.log('checkNode', keys.checked)
  store.dispatch('Script/setCheckedNodes', keys.checked)
  let checkedKeysTmp:string[] = [];
  for(let key in keys.checked){
    if(keys.checked[key] === true){
        checkedKeysTmp.push(key)
    }
  }
  checkedKeys.value = checkedKeysTmp;
360 361
  //   scriptStore.dispatch('Script/changeWorkspace',
  //       {id: e.node.dataRef.workspaceId, type: e.node.dataRef.workspaceType})
Z
zhaoke 已提交
362 363 364
}

const checkNothing = () => {
aaronchen2k2k's avatar
aaronchen2k2k 已提交
365
  checkedKeys.value = []
Z
zhaoke 已提交
366 367
}

Z
zhaoke 已提交
368 369 370 371 372 373 374 375
const execSelected = () => {
    let arr = [] as string[]
    checkedKeys.value.forEach(item => {
      if (treeDataMap.value[item]?.type === 'file') {
        arr.push(treeDataMap.value[item])
      }
    })
    bus.emit(settings.eventExec, { execType: 'ztf', scripts: arr });
376
}
Z
zhaoke 已提交
377

Z
zhaoke 已提交
378 379 380
const editedData = ref<any>({})
const nameFormVisible = ref(false)

Z
zhaoke 已提交
381
const treeDataMap = computed<any>(() => store.state.Script.treeDataMap);
Z
zhaoke 已提交
382
const getNodeMapCall = throttle(async () => {
aaronchen2k2k's avatar
aaronchen2k2k 已提交
383
  treeData.value.forEach(item => {
Z
zhaoke 已提交
384
    getNodeMap(item, treeDataMap.value)
aaronchen2k2k's avatar
aaronchen2k2k 已提交
385
  })
Z
zhaoke 已提交
386 387 388 389 390
}, 300)

let rightClickedNode = {} as any
let createAct = ''

Z
zhaoke 已提交
391
const formNode = ref({} as any)
Z
zhaoke 已提交
392
const createNode = (formData) => {
393 394
  const mode = 'child';
  let type = 'dir';
395
  if(toolbarAction.value === 'createFile') type = 'node'
aaronchen2k2k's avatar
aaronchen2k2k 已提交
396
  store.dispatch('Script/createScript', {
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412
    name: formData.name, mode: mode, type: type, target: currentNode.value.path,
    workspaceId: currentNode.value.workspaceId, productId: currProduct.value.id,
  }).then((result) => {
    if (result) {
      formNode.value.clearFormData()
      showModal.value = false;
      notification.success({ message: t('create_success') });
      nameFormVisible.value = false

      if (mode == 'child') {
        expandedKeys.value.push(rightClickedNode.path)
      }
      if (type === 'dir') {
        expandedKeys.value.push(result)
      }
      setExpandedKeys(currSite.value.id, currProduct.value.id, expandedKeys.value)
aaronchen2k2k's avatar
aaronchen2k2k 已提交
413
    }
414
  })
Z
zhaoke 已提交
415 416
}

Z
zhaoke 已提交
417 418
const expandNode = (expandedKeysMap) => {
    console.log('expandNode', expandedKeysMap.collapsed)
Z
zhaoke 已提交
419 420
    let expandedKeysTmp:string[] = [];
    for(let key in expandedKeysMap.collapsed){
Z
zhaoke 已提交
421 422 423 424 425 426 427
        if(expandedKeysMap.collapsed[key]){
            expandedKeys.value.forEach((item, index) => {
                if(item === key){
                    expandedKeys.value.splice(index, 1)
                }
            })
        }else{
Z
zhaoke 已提交
428
            expandedKeysTmp.push(key)
Z
zhaoke 已提交
429 430
        }
    }
Z
zhaoke 已提交
431 432
    expandedKeys.value = expandedKeysTmp;
    console.log('expandkeys', expandedKeys.value)
Z
zhaoke 已提交
433 434 435
    setExpandedKeys(currSite.value.id, currProduct.value.id, expandedKeys.value)
}

436 437
let menuStyle = ref({} as any)
let contextNode = ref({} as any)
aaronchen2k2k's avatar
aaronchen2k2k 已提交
438 439
const clipboardAction = ref('')
const clipboardData = ref({} as any)
440

aaronchen2k2k's avatar
aaronchen2k2k 已提交
441
const rightVisible = ref(false)
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462

const onRightClick = (e) => {
  console.log('onRightClick', e)
  const {event, node} = e

  const contextNodeData = treeDataMap.value[node.id]
  contextNode.value = {
    id: contextNodeData.id,
    title: contextNodeData.title,
    type: contextNodeData.type,
    isLeaf: contextNodeData.isLeaf,
    workspaceId: contextNodeData.workspaceId,
    workspaceType: contextNodeData.workspaceType,
  }

  menuStyle.value = getContextMenuStyle(event.currentTarget.getBoundingClientRect().right, event.currentTarget.getBoundingClientRect().top, 260)

  rightVisible.value = true
}

const menuClick = (menuKey: string, targetId: number) => {
463
  const contextNodeData = treeDataMap.value[targetId]
464
  console.log('menuClick', menuKey, targetId, contextNodeData)
Z
zhaoke 已提交
465

Z
zhaoke 已提交
466
  if(menuKey === 'exec'){
467
    execScript(contextNodeData)
468
  } else if (menuKey === 'copy' || menuKey === 'cut') {
aaronchen2k2k's avatar
aaronchen2k2k 已提交
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496
    clipboardAction.value = menuKey
    clipboardData.value = contextNodeData

  } else if (menuKey === 'paste') {
    console.log(clipboardData.value)
    const data = {
      srcKey: clipboardData.value.id,
      srcType: clipboardData.value.type,
      srcWorkspaceId: clipboardData.value.workspaceId,
      distKey: contextNodeData.id,
      distType: contextNodeData.type,
      distWorkspaceId: contextNodeData.workspaceId,
      action: clipboardAction.value,
    }
    store.dispatch('Script/pasteScript', data)

  } else if (menuKey === 'delete') {
    Modal.confirm({
      title: t("confirm_delete", {
        name: contextNodeData.title,
        typ: t("node"),
      }),
      okText: t("confirm"),
      cancelText: t("cancel"),
      onOk: async () => {
        store.dispatch('Script/deleteScript', contextNodeData.id)
      },
    });
aaronchen2k2k's avatar
aaronchen2k2k 已提交
497 498 499
  } else if(menuKey == 'sync-from-zentao'){
    syncFromZentao(contextNodeData)
  } else if(menuKey === 'sync-to-zentao'){
Z
zhaoke 已提交
500
    checkinCases(contextNodeData)
aaronchen2k2k's avatar
aaronchen2k2k 已提交
501 502 503
  } else {
    clipboardAction.value = ''
    clipboardData.value = {}
504 505 506 507 508 509 510 511 512 513 514

    if (menuKey === 'open-in-explore') {
      const { ipcRenderer } = window.require('electron')
      ipcRenderer.send(settings.electronMsg, {action: 'openInExplore', path: contextNodeData.path})

    } else if (menuKey === 'open-in-terminal') {
      const { ipcRenderer } = window.require('electron')

      ipcRenderer.send(settings.electronMsg, {action: 'openInTerminal', path: contextNodeData.path})

    }
aaronchen2k2k's avatar
aaronchen2k2k 已提交
515
  }
516 517 518

  clearMenu()
}
Z
zhaoke 已提交
519 520 521 522 523 524 525
const checkinCases = (node) => {
  if(node.workspaceType == 'ztf'){
    console.log('checkinCases')
    const fileNodes = getFileNodesUnderParent(node)
    const workspaceWithScripts = genWorkspaceToScriptsMap(fileNodes)
    store.dispatch('Script/syncToZentao', workspaceWithScripts).then((resp => {
    if (resp.code === 0) {
aaronchen2k2k's avatar
aaronchen2k2k 已提交
526 527 528 529 530 531
        notification.success({message:
              t('sync_success', {
                success: resp.data.success,
                ignore: resp.data.total - resp.data.success
              }
          )});
Z
zhaoke 已提交
532 533 534 535 536 537
    } else {
        notification.error({message: t('sync_fail'), description: resp.data.msg});
    }
    }))
  }
}
538 539 540 541 542 543 544 545
const syncFromZentao = (node) => {
    if(node.workspaceType == 'ztf'){
      if(node.type == 'workspace'){
        showSyncFromZentaoModal.value = true;
        syncFromZentaoWorkspaceId.value = node.workspaceId;
      }else if(node.type == 'dir'){
        checkoutCases(node.workspaceId, node)
      }else if(node.type == 'file'){
Z
zhaoke 已提交
546
        checkout(node.workspaceId, node.caseId, node.path)
Z
zhaoke 已提交
547 548
      }else if(node.type == 'module'){
        checkoutFromModule(node.workspaceId, node)
549 550 551 552 553 554 555 556 557 558 559
      }
    }
}
const checkoutCases = (workspaceId, node) => {
    if(node.children == undefined || node.children.length == 0){
        return;
    }
    node.children.forEach(item => {
        if(item.type == 'dir'){
            checkoutCases(workspaceId, item)
        }else if(item.type == 'file' && item.caseId){
Z
zhaoke 已提交
560
            checkout(workspaceId, item.caseId, item.path, false)
561 562
        }
    });
Z
zhaoke 已提交
563
    notification.success({
Z
zhaoke 已提交
564 565 566
        message: t('sync_from_zentao_success', {
                success: node.children.length,
              }),
Z
zhaoke 已提交
567 568 569 570 571 572 573 574 575 576 577
      });
}
const checkoutFromModule = (workspaceId, node) => {
    if(node.children == undefined || node.children.length == 0){
        return;
    }
    console.log('checkout from module', workspaceId, node.children[0].moduleId)
    const data = {moduleId: node.children[0].moduleId, workspaceId: workspaceId}
    store.dispatch('Script/syncFromZentao', data).then((resp => {
    if (resp.code === 0) {
      notification.success({
Z
zhaoke 已提交
578 579 580
        message: t('sync_from_zentao_success', {
            success: resp.data.length,
        }),
Z
zhaoke 已提交
581 582 583 584 585 586 587
      });
    } else {
        notification.error({
          message: resp.data.msg,
        });
    }
    }))
588
}
Z
zhaoke 已提交
589 590 591
const checkout = (workspaceId, caseId, path, successNotice = true) => {
    console.log('checkout', workspaceId, caseId, path)
    const data = {caseId: caseId, workspaceId: workspaceId, casePath: path}
592 593 594
    store.dispatch('Script/syncFromZentao', data).then((resp => {
    if (resp.code === 0) {
      successNotice && notification.success({
Z
zhaoke 已提交
595 596 597
        message: t('sync_from_zentao_success', {
          success: 1,
        }),
598 599 600 601 602 603 604 605
      });
    } else {
        notification.error({
          message: resp.data.msg,
        });
    }
    }))
}
606 607 608 609 610
const syncFromZentaoRef = ref({} as any)
const syncFromZentaoSubmit = (model) => {
  store.dispatch("Script/syncFromZentao", model).then((resp) => {
    if (resp.code === 0) {
      notification.success({
Z
zhaoke 已提交
611
        message: t("sync_from_zentao_success", {success: resp.data == undefined? 0 : resp.data.length, ignore:0}),
612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629
      });
      showSyncFromZentaoModal.value = false;
      syncFromZentaoRef.value.clearFormData()
    } else {
      notification.error({
        message: resp.data.msg,
      });
    }
  });
}
const execScript = (node) => {
  if(node.workspaceType !== 'ztf'){
    runTest(ref(node));
  }else{
    bus.emit(settings.eventExec,
        {execType: node.workspaceType === 'ztf' ? 'ztf' : 'unit', scripts: node.type === 'file' ? [node] : node.children});
  }
}
630 631 632 633 634
const clearMenu = () => {
  console.log('clearMenu')
  contextNode.value = ref(null)
}

H
Hao Sun 已提交
635
defineExpose({
aaronchen2k2k's avatar
aaronchen2k2k 已提交
636 637 638 639 640 641 642 643 644 645
  get isCheckable() {
    return checkable.value;
  },
  get isAllCollapsed() {
    return treeRef.value?.isAllCollapsed();
  },
  toggleAllCollapsed() {
    return treeRef.value?.toggleAllCollapsed();
  },
  toggleCheckable,
646 647
  onToolbarClicked,
  loadScripts
H
Hao Sun 已提交
648
});
649 650 651 652 653 654 655 656 657

onMounted(() => {
  console.log('onMounted')
  document.addEventListener("click", clearMenu)
})
onUnmounted(() => {
  document.removeEventListener("click", clearMenu)
})

aaronchen2k2k's avatar
aaronchen2k2k 已提交
658 659 660
</script>

<style lang="less" scoped>
Z
zhaoke 已提交
661 662
.left-pannel-contain{
  text-align: center;
aaronchen2k2k's avatar
aaronchen2k2k 已提交
663
.workdir {
Z
zhaoke 已提交
664 665 666 667 668 669 670 671 672 673 674 675 676 677 678
    height: calc(100vh - 80px);
    overflow: auto;
    text-align: left;
}
.workdir-with-btn {
    height: calc(100vh - 120px);
    overflow: auto;
    text-align: left;
}
.run-selected{
max-width: 100px;
margin: auto;
text-align: center;
margin-top: 10px;
}
aaronchen2k2k's avatar
aaronchen2k2k 已提交
679 680
}
</style>