dag.vue 28.6 KB
Newer Older
K
khadgarmage 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
L
ligang 已提交
17 18 19
<template>
  <div class="clearfix dag-model" >
    <div class="toolbar">
G
i18n  
gongzijian 已提交
20
      <div class="title"><span>{{$t('Toolbar')}}</span></div>
L
ligang 已提交
21 22 23 24
      <div class="toolbar-btn">
        <div class="bar-box roundedRect jtk-draggable jtk-droppable jtk-endpoint-anchor jtk-connected"
             :class="v === dagBarId ? 'active' : ''"
             :id="v"
B
break60 已提交
25
             :key="v"
L
ligang 已提交
26 27
             v-for="(item,v) in tasksTypeList"
             @mousedown="_getDagId(v)">
28
          <div data-toggle="tooltip" :title="item.desc">
L
ligang 已提交
29 30 31 32 33 34 35 36
            <div class="icos" :class="'icos-' + v" ></div>
          </div>
        </div>
      </div>
    </div>
    <div class="dag-contect">
      <div class="dag-toolbar">
        <div class="assist-btn">
37
          <el-button
H
huyuanming 已提交
38 39
            style="vertical-align: middle;"
            data-toggle="tooltip"
40
            :title="$t('View variables')"
H
huyuanming 已提交
41 42
            data-container="body"
            type="primary"
43
            size="mini"
H
huyuanming 已提交
44
            :disabled="$route.name !== 'projects-instance-details'"
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
            @click="_toggleView"
            icon="el-icon-c-scale-to-original">
          </el-button>
          <span>
            <el-button
              style="vertical-align: middle;"
              data-toggle="tooltip"
              :title="$t('Startup parameter')"
              data-container="body"
              type="primary"
              size="mini"
              :disabled="$route.name !== 'projects-instance-details'"
              @click="_toggleParam"
              icon="el-icon-arrow-right">
            </el-button>
          </span>
61
          <span class="name">{{name}}</span>
G
gongzijian 已提交
62
          &nbsp;
63
          <span v-if="name"  class="copy-name" @click="_copyName" :data-clipboard-text="name"><em class="el-icon-copy-document" data-container="body"  data-toggle="tooltip" :title="$t('Copy name')" ></em></span>
L
ligang 已提交
64 65
        </div>
        <div class="save-btn">
Z
zhukai 已提交
66
          <div class="operation" style="vertical-align: middle;">
L
ligang 已提交
67 68 69 70
            <a href="javascript:"
               v-for="(item,$index) in toolOperList"
               :class="_operationClass(item)"
               :id="item.code"
B
break60 已提交
71
               :key="$index"
L
ligang 已提交
72
               @click="_ckOperation(item,$event)">
73
              <el-button type="text" class="operBtn" data-container="body" :icon="item.icon" v-tooltip.light="item.desc"></el-button>
L
ligang 已提交
74 75
            </a>
          </div>
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
          <el-button
            type="primary"
            v-tooltip.light="$t('Format DAG')"
            icon="el-icon-caret-right"
            size="mini"
            data-container="body"
            v-if="(type === 'instance' || 'definition') && urlParam.id !=undefined"
            style="vertical-align: middle;"
            @click="dagAutomaticLayout">
          </el-button>
          <span>
            <el-button
              v-tooltip.light="$t('Refresh DAG status')"
              data-container="body"
              style="vertical-align: middle;"
              icon="el-icon-refresh"
              type="primary"
              :loading="isRefresh"
              v-if="type === 'instance'"
              @click="!isRefresh && _refresh()"
              size="mini" >
            </el-button>
          </span>
          <el-button
L
ligang 已提交
100 101 102
                  v-if="isRtTasks"
                  style="vertical-align: middle;"
                  type="primary"
103 104
                  size="mini"
                  icon="el-icon-back"
L
ligang 已提交
105
                  @click="_rtNodesDag" >
G
i18n  
gongzijian 已提交
106
            {{$t('Return_1')}}
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
          </el-button>
          <span>
            <el-button
              type="primary"
              v-tooltip.light="$t('Close')"
              icon="el-icon-switch-button"
              size="mini"
              data-container="body"
              v-if="(type === 'instance' || 'definition') "
              style="vertical-align: middle;"
              @click="_closeDAG">
              {{$t('Close')}}
            </el-button>
          </span>
          <el-button
L
ligang 已提交
122 123
                  style="vertical-align: middle;"
                  type="primary"
124
                  size="mini"
L
ligang 已提交
125 126
                  :loading="spinnerLoading"
                  @click="_saveChart"
127
                  icon="el-icon-document-checked"
128
                  >
G
i18n  
gongzijian 已提交
129
            {{spinnerLoading ? 'Loading...' : $t('Save')}}
130 131 132 133 134 135 136 137 138 139 140 141
          </el-button>
          <span>
            <el-button
              style="vertical-align: middle;"
              type="primary"
              size="mini"
              :loading="spinnerLoading"
              @click="_version"
              icon="el-icon-info">
              {{spinnerLoading ? 'Loading...' : $t('Version Info')}}
            </el-button>
          </span>
L
ligang 已提交
142 143 144 145 146 147 148
        </div>
      </div>
      <div class="scrollbar dag-container">
        <div class="jtk-demo" id="jtk-demo">
          <div class="jtk-demo-canvas canvas-wide statemachine-demo jtk-surface jtk-surface-nopan jtk-draggable" id="canvas" ></div>
        </div>
      </div>
149 150 151 152 153 154 155 156 157 158
      <el-drawer
        :visible.sync="drawer"
        size="35%"
        :with-header="false">
        <m-versions :versionData = versionData @mVersionSwitchProcessDefinitionVersion="mVersionSwitchProcessDefinitionVersion" @mVersionGetProcessDefinitionVersionsPage="mVersionGetProcessDefinitionVersionsPage" @mVersionDeleteProcessDefinitionVersion="mVersionDeleteProcessDefinitionVersion"></m-versions>
      </el-drawer>
      <el-drawer
        :visible.sync="nodeDrawer"
        size="50%"
        :with-header="false">
159
        <m-form-model v-if="nodeDrawer" :nodeData=nodeData @seeHistory="seeHistory" @addTaskInfo="addTaskInfo" @cacheTaskInfo="cacheTaskInfo" @close="close" @onSubProcess="onSubProcess"></m-form-model>
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
      </el-drawer>
      <el-drawer
        :visible.sync="lineDrawer"
        size="50%"
        :wrapperClosable="false"
        :with-header="false">
        <m-form-line-model :lineData = lineData @addLineInfo="addLineInfo" @cancel="cancel"></m-form-line-model>
      </el-drawer>
      <el-drawer
        :visible.sync="udpDrawer"
        size="50%"
        :wrapperClosable="false"
        :with-header="false">
        <m-udp></m-udp>
      </el-drawer>
      <el-dialog
        :title="$t('Set the DAG diagram name')"
        :visible.sync="dialogVisible"
        width="45%">
        <m-udp @onUdp="onUdpDialog" @close="closeDialog"></m-udp>
      </el-dialog>

      <el-dialog
      :title="$t('Please set the parameters before starting')"
      :visible.sync="startDialog"
      width="65%">
      <m-start :startData= "startData" :startNodeList="startNodeList" :sourceType="sourceType" @onUpdateStart="onUpdateStart" @closeStart="closeStart"></m-start>
    </el-dialog>
L
ligang 已提交
188 189 190 191 192 193 194 195 196
    </div>
  </div>
</template>
<script>
  import _ from 'lodash'
  import Dag from './dag'
  import mUdp from './udp/udp'
  import i18n from '@/module/i18n'
  import { jsPlumb } from 'jsplumb'
G
gongzijian 已提交
197
  import Clipboard from 'clipboard'
L
ligang 已提交
198 199 200
  import { allNodesId } from './plugIn/util'
  import { toolOper, tasksType } from './config'
  import mFormModel from './formModel/formModel'
201
  import mFormLineModel from './formModel/formLineModel'
L
ligang 已提交
202 203 204 205
  import { formatDate } from '@/module/filter/filter'
  import { findComponentDownward } from '@/module/util/'
  import disabledState from '@/module/mixin/disabledState'
  import { mapActions, mapState, mapMutations } from 'vuex'
206
  import mStart from '../../projects/pages/definition/pages/list/_source/start'
C
chengshiwen 已提交
207
  import mVersions from '../../projects/pages/definition/pages/list/_source/versions'
L
ligang 已提交
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225

  let eventModel

  export default {
    name: 'dag-chart',
    data () {
      return {
        tasksTypeList: tasksType,
        toolOperList: toolOper(this),
        dagBarId: null,
        toolOperCode: '',
        spinnerLoading: false,
        urlParam: {
          id: this.$route.params.id || null
        },
        isRtTasks: false,
        isRefresh: false,
        isLoading: false,
B
break60 已提交
226 227
        taskId: null,
        arg: false,
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
        versionData: {
          processDefinition: {
            id: null,
            version: '',
            state: ''
          },
          processDefinitionVersions: [],
          total: null,
          pageNo: null,
          pageSize: null
        },
        drawer: false,
        nodeData: {
          id: null,
          taskType: '',
          self: {},
          preNode: [],
          rearList: [],
          instanceId: null
        },
        nodeDrawer: false,
        lineData: {
          id: null,
          sourceId: '',
          targetId: ''
        },
        lineDrawer: false,
        udpDrawer: false,
        dialogVisible: false,
        startDialog: false,
        startData: {},
        startNodeList: '',
        sourceType: ''
L
ligang 已提交
261 262 263 264 265 266 267 268
      }
    },
    mixins: [disabledState],
    props: {
      type: String,
      releaseState: String
    },
    methods: {
269
      ...mapActions('dag', ['saveDAGchart', 'updateInstance', 'updateDefinition', 'getTaskState', 'switchProcessDefinitionVersion', 'getProcessDefinitionVersionsPage', 'deleteProcessDefinitionVersion']),
270
      ...mapMutations('dag', ['addTasks', 'cacheTasks', 'resetParams', 'setIsEditDag', 'setName', 'addConnects']),
271
      startRunning (item, startNodeList, sourceType) {
272
        this.startData = item
C
chengshiwen 已提交
273
        this.startNodeList = startNodeList
274 275 276
        this.sourceType = sourceType
        this.startDialog = true
      },
277
      onUpdateStart () {
278 279
        this.startDialog = false
      },
280
      closeStart () {
281 282
        this.startDialog = false
      },
B
break60 已提交
283
      // DAG automatic layout
284 285
      dagAutomaticLayout () {
        if (this.store.state.dag.isEditDag) {
286 287 288
          this.$message.warning(`${i18n.$t('Please save the DAG before formatting')}`)
          return false
        }
B
break60 已提交
289
        $('#canvas').html('')
Z
zhukai 已提交
290

291
        // Destroy round robin
B
break60 已提交
292
        Dag.init({
293 294 295 296
          dag: this,
          instance: jsPlumb.getInstance({
            Endpoint: [
              'Dot', { radius: 1, cssClass: 'dot-style' }
297
            ],
298 299 300 301 302 303 304 305 306 307 308 309 310
            Connector: 'Bezier',
            PaintStyle: { lineWidth: 2, stroke: '#456' }, // Connection style
            ConnectionOverlays: [
              [
                'Arrow',
                {
                  location: 1,
                  id: 'arrow',
                  length: 12,
                  foldback: 0.8
                }
              ],
              ['Label', {
311 312
                location: 0.5,
                id: 'label'
313 314 315 316 317
              }]
            ],
            Container: 'canvas',
            ConnectionsDetachable: true
          })
B
break60 已提交
318 319 320
        })
        if (this.tasks.length) {
          Dag.backfill(true)
321 322 323
          if (this.type === 'instance') {
            this._getTaskState(false).then(res => {})
          }
B
break60 已提交
324 325 326 327 328 329
        } else {
          Dag.create()
        }
      },

      init (args) {
L
ligang 已提交
330
        if (this.tasks.length) {
B
break60 已提交
331
          Dag.backfill(args)
L
ligang 已提交
332 333 334 335 336 337 338 339 340 341 342 343
          // Process instances can view status
          if (this.type === 'instance') {
            this._getTaskState(false).then(res => {})
            // Round robin acquisition status
            this.setIntervalP = setInterval(() => {
              this._getTaskState(true).then(res => {})
            }, 90000)
          }
        } else {
          Dag.create()
        }
      },
344 345 346
      /**
       * copy name
       */
347 348
      _copyName () {
        let clipboard = new Clipboard('.copy-name')
G
gongzijian 已提交
349 350 351 352 353 354 355 356 357 358 359 360
        clipboard.on('success', e => {
          this.$message.success(`${i18n.$t('Copy success')}`)
          // Free memory
          clipboard.destroy()
        })
        clipboard.on('error', e => {
          // Copy is not supported
          this.$message.warning(`${i18n.$t('The browser does not support automatic copying')}`)
          // Free memory
          clipboard.destroy()
        })
      },
L
ligang 已提交
361 362 363 364 365 366 367 368 369 370 371
      /**
       * Get state interface
       * @param isReset Whether to manually refresh
       */
      _getTaskState (isReset) {
        return new Promise((resolve, reject) => {
          this.getTaskState(this.urlParam.id).then(res => {
            let data = res.list
            let state = res.processInstanceState
            let taskList = res.taskList
            let idArr = allNodesId()
372
            const titleTpl = (item, desc) => {
L
ligang 已提交
373
              let $item = _.filter(taskList, v => v.name === item.name)[0]
374
              return `<div style="text-align: left">${i18n.$t('Name')}${$item.name}</br>${i18n.$t('State')}${desc}</br>${i18n.$t('type')}${$item.taskType}</br>${i18n.$t('host')}${$item.host || '-'}</br>${i18n.$t('Retry Count')}${$item.retryTimes}</br>${i18n.$t('Submit Time')}${formatDate($item.submitTime)}</br>${i18n.$t('Start Time')}${formatDate($item.startTime)}</br>${i18n.$t('End Time')}${$item.endTime ? formatDate($item.endTime) : '-'}</br></div>`
L
ligang 已提交
375
            }
376 377 378 379

            // remove tip state dom
            $('.w').find('.state-p').html('')

L
ligang 已提交
380 381 382 383 384
            data.forEach(v1 => {
              idArr.forEach(v2 => {
                if (v2.name === v1.name) {
                  let dom = $(`#${v2.id}`)
                  let state = dom.find('.state-p')
B
break60 已提交
385
                  let depState = ''
386
                  taskList.forEach(item => {
387
                    if (item.name === v1.name) {
B
break60 已提交
388 389 390
                      depState = item.state
                    }
                  })
L
ligang 已提交
391 392
                  dom.attr('data-state-id', v1.stateId)
                  dom.attr('data-dependent-result', v1.dependentResult || '')
B
break60 已提交
393
                  dom.attr('data-dependent-depState', depState)
394 395
                  state.append(`<strong class="${v1.icoUnicode} ${v1.isSpin ? 'as as-spin' : ''}" style="color:${v1.color}" data-toggle="tooltip" data-html="true" data-container="body"></strong>`)
                  state.find('strong').attr('title', titleTpl(v2, v1.desc))
L
ligang 已提交
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413
                }
              })
            })
            if (state === 'PAUSE' || state === 'STOP' || state === 'FAILURE' || this.state === 'SUCCESS') {
              // Manual refresh does not regain large json
              if (isReset) {
                findComponentDownward(this.$root, `${this.type}-details`)._reset()
              }
            }
            resolve()
          })
        })
      },
      /**
       * Get the action bar id
       * @param item
       */
      _getDagId (v) {
414 415 416
        // if (this.isDetails) {
        //   return
        // }
L
ligang 已提交
417 418 419 420 421 422 423 424 425
        this.dagBarId = v
      },
      /**
       * operating
       */
      _ckOperation (item) {
        let is = true
        let code = ''

426
        if (item.disable) {
L
ligang 已提交
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447
          return
        }

        if (this.toolOperCode === item.code) {
          this.toolOperCode = ''
          code = item.code
          is = false
        } else {
          this.toolOperCode = item.code
          code = this.toolOperCode
          is = true
        }

        // event type
        Dag.toolbarEvent({
          item: item,
          code: code,
          is: is
        })
      },
      _operationClass (item) {
448 449 450 451 452 453
        return this.toolOperCode === item.code ? 'active' : ''
        // if (item.disable) {
        //   return this.toolOperCode === item.code ? 'active' : ''
        // } else {
        //   return 'disable'
        // }
L
ligang 已提交
454 455 456 457 458
      },
      /**
       * Storage interface
       */
      _save (sourceType) {
B
break60 已提交
459 460 461 462
        return new Promise((resolve, reject) => {
          this.spinnerLoading = true
          // Storage store
          Dag.saveStore().then(res => {
463
            if (this._verifConditions(res.tasks)) {
464 465 466 467 468 469 470
              if (this.urlParam.id) {
                /**
                 * Edit
                 * @param saveInstanceEditDAGChart => Process instance editing
                 * @param saveEditDAGChart => Process definition editing
                 */
                this[this.type === 'instance' ? 'updateInstance' : 'updateDefinition'](this.urlParam.id).then(res => {
471 472 473 474 475 476
                  // this.$message.success(res.msg)
                  this.$message({
                    message: res.msg,
                    type: 'success',
                    offset: 80
                  })
477
                  this.spinnerLoading = false
478 479 480 481 482 483
                  // Jump process definition
                  if (this.type === 'instance') {
                    this.$router.push({ path: `/projects/instance/list/${this.urlParam.id}?_t=${new Date().getTime()}` })
                  } else {
                    this.$router.push({ path: `/projects/definition/list/${this.urlParam.id}?_t=${new Date().getTime()}` })
                  }
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507
                  resolve()
                }).catch(e => {
                  this.$message.error(e.msg || '')
                  this.spinnerLoading = false
                  reject(e)
                })
              } else {
                // New
                this.saveDAGchart().then(res => {
                  this.$message.success(res.msg)
                  this.spinnerLoading = false
                  // source @/conf/home/pages/dag/_source/editAffirmModel/index.js
                  if (sourceType !== 'affirm') {
                    // Jump process definition
                    this.$router.push({ name: 'projects-definition-list' })
                  }
                  resolve()
                }).catch(e => {
                  this.$message.error(e.msg || '')
                  this.setName('')
                  this.spinnerLoading = false
                  reject(e)
                })
              }
B
break60 已提交
508
            }
L
ligang 已提交
509
          })
B
break60 已提交
510
        })
511
      },
512
      _closeDAG () {
B
BoYiZhang 已提交
513
        let $name = this.$route.name
514
        if ($name && $name.indexOf('definition') !== -1) {
515 516 517
          this.$router.push({ name: 'projects-definition-list' })
        } else {
          this.$router.push({ name: 'projects-instance-list' })
B
BoYiZhang 已提交
518 519
        }
      },
B
break60 已提交
520 521
      _verifConditions (value) {
        let tasks = value
522
        let bool = true
523
        tasks.map(v => {
524
          if (v.type === 'CONDITIONS' && (v.conditionResult.successNode[0] === '' || v.conditionResult.successNode[0] === null || v.conditionResult.failedNode[0] === '' || v.conditionResult.failedNode[0] === null)) {
525 526 527
            bool = false
            return false
          }
L
ligang 已提交
528
        })
529
        if (!bool) {
530
          this.$message.warning(`${i18n.$t('Successful branch flow and failed branch flow are required')}`)
B
break60 已提交
531
          this.spinnerLoading = false
532 533 534
          return false
        }
        return true
L
ligang 已提交
535
      },
536 537 538 539 540 541
      onUdpDialog () {
        this._save()
        this.dialogVisible = false
      },
      closeDialog () {
        this.dialogVisible = false
L
ligang 已提交
542 543 544 545 546 547 548
      },
      /**
       * Save chart
       */
      _saveChart () {
        // Verify node
        if (!this.tasks.length) {
G
i18n  
gongzijian 已提交
549
          this.$message.warning(`${i18n.$t('Failed to create node to save')}`)
L
ligang 已提交
550 551
          return
        }
552
        this.dialogVisible = true
L
ligang 已提交
553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594
      },
      /**
       * Return to the previous child node
       */
      _rtNodesDag () {
        let getIds = this.$route.query.subProcessIds
        let idsArr = getIds.split(',')
        let ids = idsArr.slice(0, idsArr.length - 1)
        let id = idsArr[idsArr.length - 1]
        let query = {}

        if (id !== idsArr[0]) {
          query = { subProcessIds: ids.join(',') }
        }
        let $name = this.$route.name.split('-')
        this.$router.push({ path: `/${$name[0]}/${$name[1]}/list/${id}`, query: query })
      },
      /**
       * Subprocess processing
       * @param subProcessId Subprocess ID
       */
      _subProcessHandle (subProcessId) {
        let subProcessIds = []
        let getIds = this.$route.query.subProcessIds
        if (getIds) {
          let newId = getIds.split(',')
          newId.push(this.urlParam.id)
          subProcessIds = newId
        } else {
          subProcessIds.push(this.urlParam.id)
        }
        let $name = this.$route.name.split('-')
        this.$router.push({ path: `/${$name[0]}/${$name[1]}/list/${subProcessId}`, query: { subProcessIds: subProcessIds.join(',') } })
      },
      /**
       * Refresh data
       */
      _refresh () {
        this.isRefresh = true
        this._getTaskState(false).then(res => {
          setTimeout(() => {
            this.isRefresh = false
G
i18n  
gongzijian 已提交
595
            this.$message.success(`${i18n.$t('Refresh status succeeded')}`)
L
ligang 已提交
596 597 598 599 600 601 602
          }, 2200)
        })
      },
      /**
       * View variables
       */
      _toggleView () {
603
        findComponentDownward(this.$root, 'assist-dag-index')._toggleView()
L
ligang 已提交
604
      },
H
huyuanming 已提交
605 606 607 608 609

      /**
       * Starting parameters
       */
      _toggleParam () {
610
        findComponentDownward(this.$root, 'starting-params-dag-index')._toggleParam()
H
huyuanming 已提交
611
      },
612 613 614 615
      addLineInfo ({ item, fromThis }) {
        this.addConnects(item)
        this.lineDrawer = false
      },
616
      cancel ({ fromThis }) {
617 618 619
        this.lineDrawer = false
      },

L
ligang 已提交
620 621 622 623
      /**
       * Create a node popup layer
       * @param Object id
       */
624
      _createLineLabel ({ id, sourceId, targetId }) {
625 626 627 628 629 630
        this.lineData.id = id
        this.lineData.sourceId = sourceId
        this.lineData.targetId = targetId
        this.lineDrawer = true
      },

631 632 633 634 635 636 637 638 639 640
      seeHistory (taskName) {
        this.nodeData.self.$router.push({
          name: 'task-instance',
          query: {
            processInstanceId: this.nodeData.self.$route.params.id,
            taskName: taskName
          }
        })
      },

641 642 643 644 645
      addTaskInfo ({ item, fromThis }) {
        this.addTasks(item)
        this.nodeDrawer = false
      },

646
      cacheTaskInfo ({ item, fromThis }) {
647 648 649
        this.cacheTasks(item)
      },

650
      close ({ item, flag, fromThis }) {
651 652 653 654
        this.addTasks(item)
        // Edit status does not allow deletion of nodes
        if (flag) {
          jsPlumb.remove(this.nodeData.id)
655
        }
656
        this.nodeDrawer = false
657
      },
658 659 660 661
      onSubProcess ({ subProcessId, fromThis }) {
        this._subProcessHandle(subProcessId)
      },

L
ligang 已提交
662 663
      _createNodes ({ id, type }) {
        let self = this
664 665 666
        let preNode = []
        let rearNode = []
        let rearList = []
667 668
        $('div[data-targetarr*="' + id + '"]').each(function () {
          rearNode.push($(this).attr('id'))
669
        })
L
ligang 已提交
670

671
        if (rearNode.length > 0) {
672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692
          rearNode.forEach(v => {
            let rearobj = {}
            rearobj.value = $(`#${v}`).find('.name-p').text()
            rearobj.label = $(`#${v}`).find('.name-p').text()
            rearList.push(rearobj)
          })
        } else {
          rearList = []
        }
        let targetarr = $(`#${id}`).attr('data-targetarr')
        if (targetarr) {
          let nodearr = targetarr.split(',')
          nodearr.forEach(v => {
            let nodeobj = {}
            nodeobj.value = $(`#${v}`).find('.name-p').text()
            nodeobj.label = $(`#${v}`).find('.name-p').text()
            preNode.push(nodeobj)
          })
        } else {
          preNode = []
        }
L
ligang 已提交
693 694

        this.taskId = id
Z
zhukai 已提交
695
        type = type || self.dagBarId
L
ligang 已提交
696

697 698 699 700 701 702
        this.nodeData.id = id
        this.nodeData.taskType = type
        this.nodeData.self = self
        this.nodeData.preNode = preNode
        this.nodeData.rearList = rearList
        this.nodeData.instanceId = this.$route.params.id
703

704
        this.nodeDrawer = true
Z
zhukai 已提交
705 706
      },
      removeEventModelById ($id) {
707
        if (eventModel && this.taskId === $id) {
Z
zhukai 已提交
708 709
          eventModel.remove()
        }
710 711
      },

712 713 714 715 716 717 718
      /**
        * switch version in process definition version list
        *
        * @param version the version user want to change
        * @param processDefinitionId the process definition id
        * @param fromThis fromThis
      */
719
      mVersionSwitchProcessDefinitionVersion ({ version, processDefinitionId, fromThis }) {
720 721 722 723
        this.$store.state.dag.isSwitchVersion = true
        this.switchProcessDefinitionVersion({
          version: version,
          processDefinitionId: processDefinitionId
724
        }).then(res => {
725 726 727 728 729 730 731
          this.$message.success($t('Switch Version Successfully'))
          this.$router.push({ path: `/projects/definition/list/${processDefinitionId}?_t=${new Date().getTime()}` })
        }).catch(e => {
          this.$store.state.dag.isSwitchVersion = false
          this.$message.error(e.msg || '')
        })
      },
732

733 734 735 736 737 738 739 740
      /**
        * Paging event of process definition versions
        *
        * @param pageNo page number
        * @param pageSize page size
        * @param processDefinitionId the process definition id of page version
        * @param fromThis fromThis
      */
741
      mVersionGetProcessDefinitionVersionsPage ({ pageNo, pageSize, processDefinitionId, fromThis }) {
742 743 744 745
        this.getProcessDefinitionVersionsPage({
          pageNo: pageNo,
          pageSize: pageSize,
          processDefinitionId: processDefinitionId
746
        }).then(res => {
747 748 749 750
          this.versionData.processDefinitionVersions = res.data.lists
          this.versionData.total = res.data.totalCount
          this.versionData.pageSize = res.data.pageSize
          this.versionData.pageNo = res.data.currentPage
751
        }).catch(e => {
752 753 754 755
          this.$message.error(e.msg || '')
        })
      },

756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778
      /**
       * delete one version of process definition
       *
       * @param version the version need to delete
       * @param processDefinitionId the process definition id user want to delete
       * @param fromThis fromThis
       */
      mVersionDeleteProcessDefinitionVersion ({ version, processDefinitionId, fromThis }) {
        this.deleteProcessDefinitionVersion({
          version: version,
          processDefinitionId: processDefinitionId
        }).then(res => {
          this.$message.success(res.msg || '')
          this.mVersionGetProcessDefinitionVersionsPage({
            pageNo: 1,
            pageSize: 10,
            processDefinitionId: processDefinitionId,
            fromThis: fromThis
          })
        }).catch(e => {
          this.$message.error(e.msg || '')
        })
      },
779 780 781 782 783 784 785 786 787 788 789 790 791
      /**
       * query the process definition pagination version
       */
      _version (item) {
        this.getProcessDefinitionVersionsPage({
          pageNo: 1,
          pageSize: 10,
          processDefinitionId: this.urlParam.id
        }).then(res => {
          let processDefinitionVersions = res.data.lists
          let total = res.data.totalCount
          let pageSize = res.data.pageSize
          let pageNo = res.data.currentPage
792 793 794 795 796 797 798 799
          this.versionData.processDefinition.id = this.urlParam.id
          this.versionData.processDefinition.version = this.$store.state.dag.version
          this.versionData.processDefinition.state = this.releaseState
          this.versionData.processDefinitionVersions = processDefinitionVersions
          this.versionData.total = total
          this.versionData.pageNo = pageNo
          this.versionData.pageSize = pageSize
          this.drawer = true
800 801 802
        }).catch(e => {
          this.$message.error(e.msg || '')
        })
L
ligang 已提交
803 804 805
      }
    },
    watch: {
806
      tasks: {
L
ligang 已提交
807
        deep: true,
G
gongzijian 已提交
808
        handler (o) {
L
ligang 已提交
809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827
          // Edit state does not allow deletion of node a...
          this.setIsEditDag(true)
        }
      }
    },
    created () {
      // Edit state does not allow deletion of node a...
      this.setIsEditDag(false)

      if (this.$route.query.subProcessIds) {
        this.isRtTasks = true
      }

      Dag.init({
        dag: this,
        instance: jsPlumb.getInstance({
          Endpoint: [
            'Dot', { radius: 1, cssClass: 'dot-style' }
          ],
B
break60 已提交
828
          Connector: 'Bezier',
L
ligang 已提交
829 830 831 832 833 834 835 836 837 838
          PaintStyle: { lineWidth: 2, stroke: '#456' }, // Connection style
          ConnectionOverlays: [
            [
              'Arrow',
              {
                location: 1,
                id: 'arrow',
                length: 12,
                foldback: 0.8
              }
839 840
            ],
            ['Label', {
841 842
              location: 0.5,
              id: 'label'
843
            }]
L
ligang 已提交
844
          ],
845 846
          Container: 'canvas',
          ConnectionsDetachable: true
L
ligang 已提交
847 848 849 850
        })
      })
    },
    mounted () {
B
break60 已提交
851
      this.init(this.arg)
L
ligang 已提交
852 853 854 855 856 857 858 859
    },
    beforeDestroy () {
      this.resetParams()

      // Destroy round robin
      clearInterval(this.setIntervalP)
    },
    destroyed () {
Z
zhukai 已提交
860 861 862
      if (eventModel) {
        eventModel.remove()
      }
L
ligang 已提交
863 864 865 866
    },
    computed: {
      ...mapState('dag', ['tasks', 'locations', 'connects', 'isEditDag', 'name'])
    },
867
    components: { mVersions, mFormModel, mFormLineModel, mUdp, mStart }
L
ligang 已提交
868 869 870 871
  }
</script>

<style lang="scss" rel="stylesheet/scss">
G
gongzijian 已提交
872
  @import "./dag";
873 874 875
  .operBtn {
    padding: 8px 20px;
  }
L
ligang 已提交
876
</style>