WorkDir.vue 20.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
  <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"
      />
雨爱无痕 已提交
16
      <FormNode :show="showModal" @submit="createNode" @cancel="modalClose" :path="currentNode.path" :name="currentNode.title" ref="formNode" />
Z
zhaoke 已提交
17
    </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"
    />
雨爱无痕 已提交
35 36 37 38 39 40 41 42
    <FormWorkspace
      v-if="showWorkspaceModal"
      :show="showWorkspaceModal"
      @submit="createWorkSpace"
      @cancel="modalWorkspaceClose"
      ref="formWorkspace"
      :workspaceId="currentNode.workspaceId"
     />
aaronchen2k2k's avatar
aaronchen2k2k 已提交
43
  </div>
H
Hao Sun 已提交
44
</template>
aaronchen2k2k's avatar
aaronchen2k2k 已提交
45 46

<script setup lang="ts">
47 48
import { useI18n } from "vue-i18n";
import { useStore } from "vuex";
aaronchen2k2k's avatar
aaronchen2k2k 已提交
49
import { StateType as GlobalData } from "@/store/global";
50 51 52
import { ZentaoData } from "@/store/zentao";
import { ScriptData } from "@/views/script/store";
import { WorkspaceData } from "@/store/workspace";
53
import {getContextMenuStyle, resizeWidth} from "@/utils/dom";
aaronchen2k2k's avatar
aaronchen2k2k 已提交
54
import Tree from "@/components/Tree.vue";
R
root 已提交
55
import notification from "@/utils/notification";
雨爱无痕 已提交
56
import { computed, defineExpose, onMounted, onUnmounted, ref, watch, onBeforeUnmount } from "vue";
Z
zhaoke 已提交
57
import Button from '@/components/Button.vue';
58
import TreeContextMenu from './TreeContextMenu.vue';
59
import FormSyncFromZentao  from "./FormSyncFromZentao.vue";
雨爱无痕 已提交
60
import FormWorkspace from "@/views/workspace/FormWorkspace.vue";
Z
zhaoke 已提交
61 62

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

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

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

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

Z
zhaoke 已提交
81 82
const isWin = isWindows()

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

Z
zhaoke 已提交
86 87 88 89 90 91 92 93 94 95
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 已提交
96
const showModal = ref(false)
97
const toolbarAction = ref('')
aaronchen2k2k's avatar
aaronchen2k2k 已提交
98
const currentNode = ref({} as any) // parent node for create node
Z
zhaoke 已提交
99
const collapsedMap = ref({} as any)
Z
zhaoke 已提交
100
const checkedKeys = ref<string[]>([])
Z
zhaoke 已提交
101
const showSyncFromZentaoModal = ref(false);
102
const syncFromZentaoWorkspaceId = ref(0);
Z
zhaoke 已提交
103

aaronchen2k2k's avatar
aaronchen2k2k 已提交
104
onMounted(() => {
aaronchen2k2k's avatar
aaronchen2k2k 已提交
105 106 107 108 109
  console.log('onMounted')
  initData();
  setTimeout(() => {
    resizeWidth('main', 'left', 'splitter-h', 'right', 380, 800)
  }, 600)
雨爱无痕 已提交
110
  bus.on(settings.eventWebSocketMsg, onWebsocketMsgEvent);
aaronchen2k2k's avatar
aaronchen2k2k 已提交
111 112
})

雨爱无痕 已提交
113 114 115 116 117 118 119 120 121 122 123 124 125 126
onBeforeUnmount( () => {
  console.log('onBeforeUnmount')
  bus.off(settings.eventWebSocketMsg, onWebsocketMsgEvent);
})

const onWebsocketMsgEvent = (data: any) => {
  console.log('WebsocketMsgEvent in WatchFile', data.msg)

  let item = JSON.parse(data.msg)
  if(item.category == 'watch'){
    loadScripts()
  }
}

aaronchen2k2k's avatar
aaronchen2k2k 已提交
127
const onToolbarClicked = (e) => {
Z
zhaoke 已提交
128
  const node = e.node == undefined ? treeDataMap.value[''] : treeDataMap.value[e.node.id]
aaronchen2k2k's avatar
aaronchen2k2k 已提交
129
  store.dispatch('Script/changeWorkspace',
130
    { id: node.workspaceId, type: node.workspaceType })
aaronchen2k2k's avatar
aaronchen2k2k 已提交
131

aaronchen2k2k's avatar
aaronchen2k2k 已提交
132
  currentNode.value = node;
Z
zhaoke 已提交
133 134 135 136 137 138 139
  switch (e.event.key) {
    case 'runTest':
      runTest(currentNode);
      break;
    case 'createFile':
    case 'createWorkspace':
    case 'createDir':
雨爱无痕 已提交
140
        currentNode.value = {}
Z
zhaoke 已提交
141 142 143
      showModal.value = true;
      toolbarAction.value = e.event.key;
      break;
雨爱无痕 已提交
144 145 146
    case 'editWorkspace':
      showWorkspaceModal.value = true;
      break;
Z
zhaoke 已提交
147 148 149 150 151 152 153 154 155 156
    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) => {
157 158 159 160 161
              if (response) {
                notification.success({ message: t('delete_success') });
                loadScripts()
              }
            })
Z
zhaoke 已提交
162
          }
163
        }
Z
zhaoke 已提交
164 165 166 167 168 169 170 171 172 173 174 175 176
      );
    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 已提交
177
  }
Z
zhaoke 已提交
178 179 180
}

const runTest = (node) => {
aaronchen2k2k's avatar
aaronchen2k2k 已提交
181 182 183 184 185 186 187 188 189 190 191 192
  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 已提交
193
}
Z
zhaoke 已提交
194

Z
zhaoke 已提交
195
const modalClose = () => {
aaronchen2k2k's avatar
aaronchen2k2k 已提交
196
  showModal.value = false;
Z
zhaoke 已提交
197 198 199 200
}

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

aaronchen2k2k's avatar
aaronchen2k2k 已提交
201
let treeData = computed<any>(() => store.state.Script.list);
H
Hao Sun 已提交
202 203 204 205

const checkable = ref(false);

function toggleCheckable(toggle?: boolean) {
aaronchen2k2k's avatar
aaronchen2k2k 已提交
206 207 208 209
  if (toggle === undefined) {
    toggle = !checkable.value;
  }
  checkable.value = toggle;
H
Hao Sun 已提交
210 211
}

Z
zhaoke 已提交
212 213

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

aaronchen2k2k's avatar
aaronchen2k2k 已提交
216 217 218
  getCaseIdsFromReport(workspace, seq, scope).then((json) => {
    checkedKeys.value = json.data
  })
Z
zhaoke 已提交
219 220 221 222
}
selectCasesFromReport()

watch(currProduct, () => {
aaronchen2k2k's avatar
aaronchen2k2k 已提交
223 224
  console.log('watch currProduct', currProduct.value.id)
  initData()
225
}, { deep: true })
Z
zhaoke 已提交
226

aaronchen2k2k's avatar
aaronchen2k2k 已提交
227
watch(treeData, () => {
aaronchen2k2k's avatar
aaronchen2k2k 已提交
228 229
  console.log('watch treeData', treeData.value)
  onTreeDataChanged()
230
}, { deep: true })
Z
zhaoke 已提交
231 232 233 234

let filerItems = ref([] as any)

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

238
  const params = { displayBy: displayBy.value, filerType: filerType.value, filerValue: filerValue.value } as any
aaronchen2k2k's avatar
aaronchen2k2k 已提交
239
  store.dispatch('Script/listScript', params)
Z
zhaoke 已提交
240 241 242
}

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

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

aaronchen2k2k's avatar
aaronchen2k2k 已提交
248 249
    if (cachedKeys) expandedKeys.value = cachedKeys
  })
Z
zhaoke 已提交
250 251 252 253
}

// display
const loadDisplayBy = async () => {
aaronchen2k2k's avatar
aaronchen2k2k 已提交
254
  displayBy.value = await getScriptDisplayBy(currSite.value.id, currProduct.value.id)
Z
zhaoke 已提交
255 256 257 258
}

// filters
const loadFilterItems = async () => {
aaronchen2k2k's avatar
aaronchen2k2k 已提交
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
  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 已提交
281 282
    }

aaronchen2k2k's avatar
aaronchen2k2k 已提交
283 284
    if (!found) filerValue.value = ''
  }
Z
zhaoke 已提交
285 286 287
}

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

aaronchen2k2k's avatar
aaronchen2k2k 已提交
291 292 293
  await loadDisplayBy()
  await loadFilterItems()
  await loadScripts()
Z
zhaoke 已提交
294 295 296 297 298 299 300
}, 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 已提交
301 302
  if (!treeNode) return
  expandedKeys.value.push(treeNode.path)
Z
zhaoke 已提交
303

aaronchen2k2k's avatar
aaronchen2k2k 已提交
304
  if (treeNode.children && openAll) {
aaronchen2k2k's avatar
aaronchen2k2k 已提交
305
    treeNode.children.forEach((item) => {
aaronchen2k2k's avatar
aaronchen2k2k 已提交
306 307 308
      getOpenKeys(item, openAll)
    })
  }
Z
zhaoke 已提交
309

aaronchen2k2k's avatar
aaronchen2k2k 已提交
310
  console.log('keys', expandedKeys.value)
Z
zhaoke 已提交
311 312
}

Z
zhaoke 已提交
313 314 315 316 317 318 319
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 已提交
320 321 322 323 324 325 326
let isExpand = ref(false);
let showCheckbox = ref(false)
let displayBy = ref('workspace')

let tree = ref(null)

onMounted(() => {
aaronchen2k2k's avatar
aaronchen2k2k 已提交
327
  console.log('onMounted', tree)
Z
zhaoke 已提交
328 329
})
onUnmounted(() => {
330
  console.log('onUnmounted', tree)
Z
zhaoke 已提交
331 332 333
})

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

Z
zhaoke 已提交
336
  const node = treeDataMap.value[activeNode.activeID]
aaronchen2k2k's avatar
aaronchen2k2k 已提交
337
  console.log('node id', node.caseId)
aaronchen2k2k's avatar
aaronchen2k2k 已提交
338
  if (node.workspaceType !== 'ztf') checkNothing()
Z
zhaoke 已提交
339

aaronchen2k2k's avatar
aaronchen2k2k 已提交
340
  store.dispatch('Script/getScript', node)
Z
zhaoke 已提交
341
  store.dispatch('Result/getStatistic', node)
aaronchen2k2k's avatar
aaronchen2k2k 已提交
342
  if (node.type === 'file') {
aaronchen2k2k's avatar
aaronchen2k2k 已提交
343 344
    const tabId = node.workspaceType === 'ztf' && node.path.indexOf('.exp') !== node.path.length - 4
        ? 'script-' + node.path : 'code-' + node.path
aaronchen2k2k's avatar
aaronchen2k2k 已提交
345 346
    global.value[tabId] = node.workspaceId

aaronchen2k2k's avatar
aaronchen2k2k 已提交
347
    store.dispatch('tabs/open', {
aaronchen2k2k's avatar
aaronchen2k2k 已提交
348
      id: tabId,
aaronchen2k2k's avatar
aaronchen2k2k 已提交
349 350 351 352 353 354 355
      title: node.title,
      changed: false,
      type: 'script',
      data: node.path
    });
  }

aaronchen2k2k's avatar
aaronchen2k2k 已提交
356
  store.dispatch('Script/changeWorkspace',
357
    { id: node.workspaceId, type: node.workspaceType })
Z
zhaoke 已提交
358 359
}

Z
zhaoke 已提交
360 361 362 363
const checkNode = (keys) => {
  console.log('checkNode', keys.checked)
  store.dispatch('Script/setCheckedNodes', keys.checked)
  let checkedKeysTmp:string[] = [];
aaronchen2k2k's avatar
aaronchen2k2k 已提交
364 365 366
  for(let checkedKey in keys.checked){
    if(keys.checked[checkedKey] === true){
        checkedKeysTmp.push(checkedKey)
Z
zhaoke 已提交
367 368 369
    }
  }
  checkedKeys.value = checkedKeysTmp;
Z
zhaoke 已提交
370 371 372
}

const checkNothing = () => {
aaronchen2k2k's avatar
aaronchen2k2k 已提交
373
  checkedKeys.value = []
Z
zhaoke 已提交
374 375
}

Z
zhaoke 已提交
376 377
const execSelected = () => {
    let arr = [] as string[]
aaronchen2k2k's avatar
aaronchen2k2k 已提交
378 379 380
    checkedKeys.value.forEach(checkedKey => {
      if (treeDataMap.value[checkedKey]?.type === 'file') {
        arr.push(treeDataMap.value[checkedKey])
Z
zhaoke 已提交
381 382 383
      }
    })
    bus.emit(settings.eventExec, { execType: 'ztf', scripts: arr });
384
}
Z
zhaoke 已提交
385

Z
zhaoke 已提交
386 387
const nameFormVisible = ref(false)

Z
zhaoke 已提交
388
const treeDataMap = computed<any>(() => store.state.Script.treeDataMap);
aaronchen2k2k's avatar
aaronchen2k2k 已提交
389
const getNodeMapCall = debounce(async () => {
aaronchen2k2k's avatar
aaronchen2k2k 已提交
390
  treeData.value.forEach(item => {
Z
zhaoke 已提交
391
    getNodeMap(item, treeDataMap.value)
aaronchen2k2k's avatar
aaronchen2k2k 已提交
392
  })
Z
zhaoke 已提交
393 394 395 396
}, 300)

let rightClickedNode = {} as any

Z
zhaoke 已提交
397
const formNode = ref({} as any)
Z
zhaoke 已提交
398
const createNode = (formData) => {
雨爱无痕 已提交
399 400 401 402 403 404
  if(formData.path != ""){
    store.dispatch('Script/renameScript', formData)
    formNode.value.clearFormData()
    showModal.value = false;
    return;
  }
405 406
  const mode = 'child';
  let type = 'dir';
407
  if(toolbarAction.value === 'createFile') type = 'node'
aaronchen2k2k's avatar
aaronchen2k2k 已提交
408
  store.dispatch('Script/createScript', {
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424
    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 已提交
425
    }
426
  })
Z
zhaoke 已提交
427 428
}

Z
zhaoke 已提交
429 430
const expandNode = (expandedKeysMap) => {
    console.log('expandNode', expandedKeysMap.collapsed)
Z
zhaoke 已提交
431 432
    let expandedKeysTmp:string[] = [];
    for(let key in expandedKeysMap.collapsed){
Z
zhaoke 已提交
433 434 435 436 437 438 439
        if(expandedKeysMap.collapsed[key]){
            expandedKeys.value.forEach((item, index) => {
                if(item === key){
                    expandedKeys.value.splice(index, 1)
                }
            })
        }else{
Z
zhaoke 已提交
440
            expandedKeysTmp.push(key)
Z
zhaoke 已提交
441 442
        }
    }
Z
zhaoke 已提交
443 444
    expandedKeys.value = expandedKeysTmp;
    console.log('expandkeys', expandedKeys.value)
Z
zhaoke 已提交
445 446 447
    setExpandedKeys(currSite.value.id, currProduct.value.id, expandedKeys.value)
}

448 449
let menuStyle = ref({} as any)
let contextNode = ref({} as any)
aaronchen2k2k's avatar
aaronchen2k2k 已提交
450 451
const clipboardAction = ref('')
const clipboardData = ref({} as any)
452

aaronchen2k2k's avatar
aaronchen2k2k 已提交
453
const rightVisible = ref(false)
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474

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) => {
475
  const contextNodeData = treeDataMap.value[targetId]
476
  console.log('menuClick', menuKey, targetId, contextNodeData)
Z
zhaoke 已提交
477

Z
zhaoke 已提交
478
  if(menuKey === 'exec'){
479
    execScript(contextNodeData)
480
  } else if (menuKey === 'copy' || menuKey === 'cut') {
aaronchen2k2k's avatar
aaronchen2k2k 已提交
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508
    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)
      },
    });
雨爱无痕 已提交
509 510 511
} else if (menuKey === 'rename') {
    showModal.value = true;
    currentNode.value = contextNodeData;
aaronchen2k2k's avatar
aaronchen2k2k 已提交
512 513 514
  } else if(menuKey == 'sync-from-zentao'){
    syncFromZentao(contextNodeData)
  } else if(menuKey === 'sync-to-zentao'){
Z
zhaoke 已提交
515
    checkinCases(contextNodeData)
aaronchen2k2k's avatar
aaronchen2k2k 已提交
516 517 518
  } else {
    clipboardAction.value = ''
    clipboardData.value = {}
519 520 521 522 523 524 525 526 527 528 529

    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 已提交
530
  }
531 532 533

  clearMenu()
}
Z
zhaoke 已提交
534 535 536 537 538 539 540
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 已提交
541 542 543 544 545 546
        notification.success({message:
              t('sync_success', {
                success: resp.data.success,
                ignore: resp.data.total - resp.data.success
              }
          )});
Z
zhaoke 已提交
547 548 549 550 551 552
    } else {
        notification.error({message: t('sync_fail'), description: resp.data.msg});
    }
    }))
  }
}
553 554 555 556 557 558 559 560
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 已提交
561
        checkout(node.workspaceId, node.caseId, node.path)
Z
zhaoke 已提交
562 563
      }else if(node.type == 'module'){
        checkoutFromModule(node.workspaceId, node)
564 565 566 567 568 569 570 571 572 573 574
      }
    }
}
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 已提交
575
            checkout(workspaceId, item.caseId, item.path, false)
576 577
        }
    });
Z
zhaoke 已提交
578
    notification.success({
Z
zhaoke 已提交
579 580 581
        message: t('sync_from_zentao_success', {
                success: node.children.length,
              }),
Z
zhaoke 已提交
582 583 584 585 586 587 588 589 590 591 592
      });
}
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 已提交
593 594 595
        message: t('sync_from_zentao_success', {
            success: resp.data.length,
        }),
Z
zhaoke 已提交
596 597 598 599 600 601 602
      });
    } else {
        notification.error({
          message: resp.data.msg,
        });
    }
    }))
603
}
Z
zhaoke 已提交
604 605 606
const checkout = (workspaceId, caseId, path, successNotice = true) => {
    console.log('checkout', workspaceId, caseId, path)
    const data = {caseId: caseId, workspaceId: workspaceId, casePath: path}
607 608 609
    store.dispatch('Script/syncFromZentao', data).then((resp => {
    if (resp.code === 0) {
      successNotice && notification.success({
Z
zhaoke 已提交
610 611 612
        message: t('sync_from_zentao_success', {
          success: 1,
        }),
613 614 615 616 617 618 619 620
      });
    } else {
        notification.error({
          message: resp.data.msg,
        });
    }
    }))
}
621 622 623 624 625
const syncFromZentaoRef = ref({} as any)
const syncFromZentaoSubmit = (model) => {
  store.dispatch("Script/syncFromZentao", model).then((resp) => {
    if (resp.code === 0) {
      notification.success({
Z
zhaoke 已提交
626
        message: t("sync_from_zentao_success", {success: resp.data == undefined? 0 : resp.data.length, ignore:0}),
627 628 629 630 631 632 633 634 635 636 637 638 639 640 641
      });
      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,
aaronchen2k2k's avatar
aaronchen2k2k 已提交
642
        {execType: 'ztf', scripts: node.type === 'file' ? [node] : node.children});
643 644
  }
}
645 646 647 648 649
const clearMenu = () => {
  console.log('clearMenu')
  contextNode.value = ref(null)
}

雨爱无痕 已提交
650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665
const showWorkspaceModal = ref(false)
const formWorkspace = ref({} as any)
const createWorkSpace = (formData) => {
    store.dispatch('Workspace/save', formData).then((response) => {
        if (response) {
            formWorkspace.value.clearFormData()
            notification.success({message: t('save_success')});
            showWorkspaceModal.value = false;
            loadScripts()
        }
    })
};
const modalWorkspaceClose = () => {
  showWorkspaceModal.value = false;
}

H
Hao Sun 已提交
666
defineExpose({
aaronchen2k2k's avatar
aaronchen2k2k 已提交
667 668 669 670 671 672 673 674 675 676
  get isCheckable() {
    return checkable.value;
  },
  get isAllCollapsed() {
    return treeRef.value?.isAllCollapsed();
  },
  toggleAllCollapsed() {
    return treeRef.value?.toggleAllCollapsed();
  },
  toggleCheckable,
677 678
  onToolbarClicked,
  loadScripts
H
Hao Sun 已提交
679
});
680 681 682 683 684 685 686 687 688

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

aaronchen2k2k's avatar
aaronchen2k2k 已提交
689 690 691
</script>

<style lang="less" scoped>
Z
zhaoke 已提交
692 693
.left-pannel-contain{
  text-align: center;
aaronchen2k2k's avatar
aaronchen2k2k 已提交
694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709
  .workdir {
      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 已提交
710 711
}
</style>