list.vue 18.4 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
<template>
18
  <div class="list-model" style="position: relative;">
L
ligang 已提交
19 20 21
    <div class="table-box">
      <table class="fixed">
        <tr>
22
          <th scope="col" style="min-width: 50px">
23 24
            <x-checkbox @on-change="_topCheckBoxClick" v-model="checkAll"></x-checkbox>
          </th>
25
          <th scope="col" style="min-width: 30px">
G
i18n  
gongzijian 已提交
26
            <span>{{$t('#')}}</span>
L
ligang 已提交
27
          </th>
28
          <th scope="col" style="min-width: 200px;max-width: 300px;">
G
i18n  
gongzijian 已提交
29
            <span>{{$t('Process Name')}}</span>
L
ligang 已提交
30
          </th>
31 32
          <th scope="col" style="min-width: 30px">
            <span>{{$t('State')}}</span>
33
          </th>
34
          <th scope="col" style="min-width: 70px">
G
i18n  
gongzijian 已提交
35
            <span>{{$t('Run Type')}}</span>
L
ligang 已提交
36
          </th>
37
          <th scope="col" style="min-width: 130px">
38 39
            <span>{{$t('Scheduling Time')}}</span>
          </th>
40
          <th scope="col" style="min-width: 130px">
G
i18n  
gongzijian 已提交
41
            <span>{{$t('Start Time')}}</span>
L
ligang 已提交
42
          </th>
43
          <th scope="col" style="min-width: 130px">
G
i18n  
gongzijian 已提交
44
            <span>{{$t('End Time')}}</span>
L
ligang 已提交
45
          </th>
46
          <th scope="col" style="min-width: 60px">
G
i18n  
gongzijian 已提交
47
            <span>{{$t('Duration')}}s</span>
L
ligang 已提交
48
          </th>
49
          <th scope="col" style="min-width: 60px">
G
i18n  
gongzijian 已提交
50
            <span>{{$t('Run Times')}}</span>
L
ligang 已提交
51
          </th>
52
          <th scope="col" style="min-width: 55px">
G
i18n  
gongzijian 已提交
53
            <span>{{$t('fault-tolerant sign')}}</span>
L
ligang 已提交
54
          </th>
55 56 57 58 59 60
          <th scope="col" style="min-width: 135px">
            <span>{{$t('host')}}</span>
          </th>
          <th scope="col" style="min-width: 60px">
            <div style="width: 60px">
              <span>{{$t('Executor')}}</span>
61
            </div>
L
ligang 已提交
62
          </th>
63
          <th scope="col" style="min-width: 210px">
G
i18n  
gongzijian 已提交
64
            <span>{{$t('Operation')}}</span>
L
ligang 已提交
65 66 67
          </th>
        </tr>
        <tr v-for="(item, $index) in list" :key="item.id">
68
          <td width="50"><x-checkbox v-model="item.isCheck" @on-change="_arrDelChange"></x-checkbox></td>
H
huyuanming 已提交
69
          <td width="50">
L
ligang 已提交
70 71
            <span>{{parseInt(pageNo === 1 ? ($index + 1) : (($index + 1) + (pageSize * (pageNo - 1))))}}</span>
          </td>
B
break60 已提交
72
          <td style="min-width: 200px;max-width: 300px;padding-right: 10px;">
73
            <span class="ellipsis" style="padding-left: 4px;"><router-link :to="{ path: '/projects/instance/list/' + item.id , query:{id: item.processDefinitionId}}" tag="a" class="links" :title="item.name">{{item.name}}</router-link></span>
L
ligang 已提交
74
          </td>
75
          <td>
76
            <span v-html="_rtState(item.state)" style="cursor: pointer;"></span>
77
          </td>
L
ligang 已提交
78
          <td><span>{{_rtRunningType(item.commandType)}}</span></td>
79
          <td>
80 81 82 83 84 85
            <span v-if="item.scheduleTime">{{item.scheduleTime | formatDate}}</span>
            <span v-else>-</span>
          </td>
          <td>
            <span v-if="item.startTime">{{item.startTime | formatDate}}</span>
            <span v-else>-</span>
86
          </td>
L
ligang 已提交
87 88
          <td>
            <span v-if="item.endTime">{{item.endTime | formatDate}}</span>
89
            <span v-else>-</span>
L
ligang 已提交
90
          </td>
H
huyuanming 已提交
91 92
          <td width="70"><span>{{item.duration || '-'}}</span></td>
          <td width="70"><span>{{item.runTimes}}</span></td>
93
          <td><span>{{item.recovery}}</span></td>
L
ligang 已提交
94 95
          <td>
            <span v-if="item.host">{{item.host}}</span>
96
            <span v-else>-</span>
L
ligang 已提交
97 98
          </td>
          <td>
99 100
            <span style="word-break: break-all" v-if="item.executorName">{{item.executorName}}</span>
            <span v-else>-</span>
L
ligang 已提交
101
          </td>
B
break60 已提交
102
          <td style="z-index: inherit;">
L
ligang 已提交
103 104 105 106 107
            <div v-show="item.disabled">
              <x-button type="info"
                        shape="circle"
                        size="xsmall"
                        data-toggle="tooltip"
G
i18n  
gongzijian 已提交
108
                        :title="$t('Edit')"
L
ligang 已提交
109
                        @click="_reEdit(item)"
110
                        icon="ans-icon-edit"
G
i18n  
gongzijian 已提交
111
                        :disabled="item.state !== 'SUCCESS' && item.state !== 'PAUSE' && item.state !== 'FAILURE' && item.state !== 'STOP'"></x-button>
L
ligang 已提交
112 113 114 115
              <x-button type="info"
                        shape="circle"
                        size="xsmall"
                        data-toggle="tooltip"
G
i18n  
gongzijian 已提交
116
                        :title="$t('Rerun')"
L
ligang 已提交
117
                        @click="_reRun(item,$index)"
118
                        icon="ans-icon-refresh"
G
i18n  
gongzijian 已提交
119
                        :disabled="item.state !== 'SUCCESS' && item.state !== 'PAUSE' && item.state !== 'FAILURE' && item.state !== 'STOP'"></x-button>
L
ligang 已提交
120 121 122 123
              <x-button type="success"
                        shape="circle"
                        size="xsmall"
                        data-toggle="tooltip"
G
i18n  
gongzijian 已提交
124
                        :title="$t('Recovery Failed')"
L
ligang 已提交
125
                        @click="_restore(item,$index)"
126
                        icon="ans-icon-fail-empty"
G
i18n  
gongzijian 已提交
127
                        :disabled="item.state !== 'FAILURE'"></x-button>
L
ligang 已提交
128 129 130 131
              <x-button type="error"
                        shape="circle"
                        size="xsmall"
                        data-toggle="tooltip"
leon-baoliang's avatar
leon-baoliang 已提交
132
                        :title="item.state === 'STOP' ? $t('Recovery Suspend') : $t('Stop')"
leon-baoliang's avatar
leon-baoliang 已提交
133
                        @click="_stop(item,$index)"
134
                        :icon="item.state === 'STOP' ? 'ans-icon-pause-solid' : 'ans-icon-stop'"
leon-baoliang's avatar
leon-baoliang 已提交
135
                        :disabled="item.state !== 'RUNNING_EXEUTION' && item.state != 'STOP'"></x-button>
L
ligang 已提交
136 137 138 139
              <x-button type="warning"
                        shape="circle"
                        size="xsmall"
                        data-toggle="tooltip"
G
i18n  
gongzijian 已提交
140
                        :title="item.state === 'PAUSE' ? $t('Recovery Suspend') : $t('Pause')"
L
ligang 已提交
141
                        @click="_suspend(item,$index)"
142
                        :icon="item.state === 'PAUSE' ? 'ans-icon-pause-solid' : 'ans-icon-pause'"
G
i18n  
gongzijian 已提交
143
                        :disabled="item.state !== 'RUNNING_EXEUTION' && item.state !== 'PAUSE'"></x-button>
L
ligang 已提交
144 145
              <x-poptip
                      :ref="'poptip-delete-' + $index"
B
break60 已提交
146
                      placement="top-end"
L
ligang 已提交
147
                      width="90">
G
i18n  
gongzijian 已提交
148
                <p>{{$t('Delete?')}}</p>
L
ligang 已提交
149
                <div style="text-align: right; margin: 0;padding-top: 4px;">
G
i18n  
gongzijian 已提交
150 151
                  <x-button type="text" size="xsmall" shape="circle" @click="_closeDelete($index)">{{$t('Cancel')}}</x-button>
                  <x-button type="primary" size="xsmall" shape="circle" @click="_delete(item,$index)">{{$t('Confirm')}}</x-button>
L
ligang 已提交
152 153 154
                </div>
                <template slot="reference">
                  <x-button
155
                          icon="ans-icon-trash"
L
ligang 已提交
156 157 158 159
                          type="error"
                          shape="circle"
                          size="xsmall"
                          data-toggle="tooltip"
160
                          :disabled="item.state !== 'SUCCESS' && item.state !== 'FAILURE' && item.state !== 'STOP' && item.state !== 'PAUSE'"
161
                          :title="$t('delete')">
L
ligang 已提交
162 163 164 165 166 167 168 169
                  </x-button>
                </template>
              </x-poptip>

              <x-button type="info"
                        shape="circle"
                        size="xsmall"
                        data-toggle="tooltip"
G
i18n  
gongzijian 已提交
170
                        :title="$t('Gantt')"
L
ligang 已提交
171
                        @click="_gantt(item)"
172
                        icon="ans-icon-gantt">
L
ligang 已提交
173 174 175 176
              </x-button>

            </div>
            <div v-show="!item.disabled">
G
i18n  
gongzijian 已提交
177
              <!--Edit-->
L
ligang 已提交
178 179 180 181
              <x-button
                      type="info"
                      shape="circle"
                      size="xsmall"
182
                      icon="ans-icon-edit"
L
ligang 已提交
183 184 185
                      disabled="true">
              </x-button>

G
i18n  
gongzijian 已提交
186
              <!--Rerun-->
L
ligang 已提交
187 188 189 190 191 192
              <x-button
                      v-show="buttonType === 'run'"
                      type="info"
                      shape="circle"
                      size="xsmall"
                      disabled="true">
leon-baoliang's avatar
leon-baoliang 已提交
193
                {{item.count}}
L
ligang 已提交
194 195 196 197 198 199
              </x-button>
              <x-button
                      v-show="buttonType !== 'run'"
                      type="info"
                      shape="circle"
                      size="xsmall"
200
                      icon="ans-icon-refresh"
L
ligang 已提交
201 202 203
                      disabled="true">
              </x-button>

G
i18n  
gongzijian 已提交
204
              <!--Recovery Failed-->
L
ligang 已提交
205 206 207 208 209 210
              <x-button
                      v-show="buttonType === 'store'"
                      type="success"
                      shape="circle"
                      size="xsmall"
                      disabled="true">
leon-baoliang's avatar
leon-baoliang 已提交
211
                {{item.count}}
L
ligang 已提交
212 213 214 215 216 217
              </x-button>
              <x-button
                      v-show="buttonType !== 'store'"
                      type="success"
                      shape="circle"
                      size="xsmall"
218
                      icon="ans-icon-fail-empty"
L
ligang 已提交
219 220 221
                      disabled="true">
              </x-button>

G
i18n  
gongzijian 已提交
222
              <!--Stop-->
leon-baoliang's avatar
leon-baoliang 已提交
223 224 225 226
              <!--<x-button-->
                      <!--type="error"-->
                      <!--shape="circle"-->
                      <!--size="xsmall"-->
227
                      <!--icon="ans-icon-pause"-->
leon-baoliang's avatar
leon-baoliang 已提交
228 229
                      <!--disabled="true">-->
              <!--</x-button>-->
L
ligang 已提交
230

G
i18n  
gongzijian 已提交
231
              <!--倒计时 => Recovery Suspend/Pause-->
L
ligang 已提交
232
              <x-button
leon-baoliang's avatar
leon-baoliang 已提交
233
                      v-show="(item.state === 'PAUSE' || item.state == 'STOP') && buttonType === 'suspend'"
L
ligang 已提交
234 235 236 237
                      type="warning"
                      shape="circle"
                      size="xsmall"
                      disabled="true">
leon-baoliang's avatar
leon-baoliang 已提交
238
                {{item.count}}
L
ligang 已提交
239
              </x-button>
G
i18n  
gongzijian 已提交
240
              <!--Recovery Suspend-->
L
ligang 已提交
241
              <x-button
leon-baoliang's avatar
leon-baoliang 已提交
242
                      v-show="(item.state === 'PAUSE' || item.state == 'STOP') && buttonType !== 'suspend'"
L
ligang 已提交
243 244 245
                      type="warning"
                      shape="circle"
                      size="xsmall"
246
                      icon="ans-icon-pause-solid"
L
ligang 已提交
247 248
                      disabled="true">
              </x-button>
G
i18n  
gongzijian 已提交
249
              <!--Pause-->
L
ligang 已提交
250 251 252 253 254
              <x-button
                      v-show="item.state !== 'PAUSE'"
                      type="warning"
                      shape="circle"
                      size="xsmall"
255
                      icon="ans-icon-stop"
leon-baoliang's avatar
leon-baoliang 已提交
256 257 258 259 260 261 262 263
                      disabled="true">
              </x-button>
            <!--Stop-->
              <x-button
                      v-show="item.state !== 'STOP'"
                      type="warning"
                      shape="circle"
                      size="xsmall"
264
                      icon="ans-icon-pause"
L
ligang 已提交
265 266 267
                      disabled="true">
              </x-button>

G
i18n  
gongzijian 已提交
268
              <!--delete-->
L
ligang 已提交
269 270 271 272
              <x-button
                      type="error"
                      shape="circle"
                      size="xsmall"
273
                      icon="ans-icon-trash"
L
ligang 已提交
274 275 276
                      :disabled="true">
              </x-button>

G
i18n  
gongzijian 已提交
277
              <!--Gantt-->
L
ligang 已提交
278 279 280 281
              <x-button
                      type="info"
                      shape="circle"
                      size="xsmall"
282
                      icon="ans-icon-gantt"
L
ligang 已提交
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
                      disabled="true">
              </x-button>
            </div>
          </td>
        </tr>
      </table>
    </div>
  </div>
</template>
<script>
  import _ from 'lodash'
  import { mapActions } from 'vuex'
  import { tasksState, runningType } from '@/conf/home/pages/dag/_source/config'

  export default {
    name: 'list',
    data () {
      return {
B
break60 已提交
301
        // data
L
ligang 已提交
302
        list: [],
B
break60 已提交
303
        // btn type
304 305 306
        buttonType: '',
        strDelete: '',
        checkAll: false
L
ligang 已提交
307 308 309 310 311 312 313 314
      }
    },
    props: {
      processInstanceList: Array,
      pageNo: Number,
      pageSize: Number
    },
    methods: {
315
      ...mapActions('dag', ['editExecutorsState', 'deleteInstance', 'batchDeleteInstance']),
L
ligang 已提交
316 317 318 319 320 321 322 323 324 325 326
      /**
       * Return run type
       */
      _rtRunningType (code) {
        return _.filter(runningType, v => v.code === code)[0].desc
      },
      /**
       * Return status
       */
      _rtState (code) {
        let o = tasksState[code]
327
        return `<em class="ansfont ${o.icoUnicode} ${o.isSpin ? 'as as-spin' : ''}" style="color:${o.color}" data-toggle="tooltip" data-container="body" title="${o.desc}"></em>`
L
ligang 已提交
328 329 330 331 332
      },
      /**
       * Close the delete layer
       */
      _closeDelete (i) {
B
break60 已提交
333
        this.$refs[`poptip-delete-${i}`][0].doClose()
L
ligang 已提交
334 335 336 337 338
      },
      /**
       * delete
       */
      _delete (item, i) {
G
gongzijian 已提交
339 340 341 342 343 344
        // remove tow++
        if (i < 0) {
          this._batchDelete()
          return
        }
        // remove one
L
ligang 已提交
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390
        this.deleteInstance({
          processInstanceId: item.id
        }).then(res => {
          this.$refs[`poptip-delete-${i}`][0].doClose()
          this._onUpdate()
          this.$message.success(res.msg)
        }).catch(e => {
          this.$refs[`poptip-delete-${i}`][0].doClose()
          this.$message.error(e.msg || '')
        })
      },
      /**
       * edit
       */
      _reEdit (item) {
        this.$router.push({ path: `/projects/instance/list/${item.id}` })
      },
      /**
       * Rerun
       * @param REPEAT_RUNNING
       */
      _reRun (item, index) {
        this._countDownFn({
          id: item.id,
          executeType: 'REPEAT_RUNNING',
          index: index,
          buttonType: 'run'
        })
      },
      /**
       * Resume running
       * @param PAUSE => RECOVER_SUSPENDED_PROCESS
       * @param FAILURE => START_FAILURE_TASK_PROCESS
       */
      _restore (item, index) {
        this._countDownFn({
          id: item.id,
          executeType: 'START_FAILURE_TASK_PROCESS',
          index: index,
          buttonType: 'store'
        })
      },
      /**
       * stop
       * @param STOP
       */
leon-baoliang's avatar
leon-baoliang 已提交
391 392 393 394 395 396 397 398 399 400 401 402 403 404
      _stop (item, index) {
        if(item.state == 'STOP') {
          this._countDownFn({
            id: item.id,
            executeType: 'RECOVER_SUSPENDED_PROCESS',
            index: index,
            buttonType: 'suspend'
          })
        } else {
          this._upExecutorsState({
            processInstanceId: item.id,
            executeType: 'STOP'
          })
        }
L
ligang 已提交
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420
      },
      /**
       * pause
       * @param PAUSE
       */
      _suspend (item, index) {
        if (item.state === 'PAUSE') {
          this._countDownFn({
            id: item.id,
            executeType: 'RECOVER_SUSPENDED_PROCESS',
            index: index,
            buttonType: 'suspend'
          })
        } else {
          this._upExecutorsState({
            processInstanceId: item.id,
leon-baoliang's avatar
leon-baoliang 已提交
421
            executeType: 'PAUSE'
L
ligang 已提交
422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472
          })
        }
      },
      /**
       * operating
       */
      _upExecutorsState (o) {
        this.editExecutorsState(o).then(res => {
          this.$message.success(res.msg)
          $('body').find('.tooltip.fade.top.in').remove()
          this._onUpdate()
        }).catch(e => {
          this.$message.error(e.msg || '')
          this._onUpdate()
        })
      },
      /**
       * Countdown method refresh
       */
      _countDownFn (param) {
        this.buttonType = param.buttonType
        this.editExecutorsState({
          processInstanceId: param.id,
          executeType: param.executeType
        }).then(res => {
          this.list[param.index].disabled = false
          $('body').find('.tooltip.fade.top.in').remove()
          this.$forceUpdate()
          this.$message.success(res.msg)
          // Countdown
          this._countDown(() => {
            this._onUpdate()
          }, param.index)
        }).catch(e => {
          this.$message.error(e.msg || '')
          this._onUpdate()
        })
      },
      /**
       * update
       */
      _onUpdate () {
        this.$emit('on-update')
      },
      /**
       * list data handle
       */
      _listDataHandle (data) {
        if (data.length) {
          _.map(data, v => {
            v.disabled = true
leon-baoliang's avatar
leon-baoliang 已提交
473
            v.count = 9
L
ligang 已提交
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501
          })
        }
        return data
      },
      /**
       * Countdown
       */
      _countDown (fn, index) {
        const TIME_COUNT = 10
        let timer
        let $count
        if (!timer) {
          $count = TIME_COUNT
          timer = setInterval(() => {
            if ($count > 0 && $count <= TIME_COUNT) {
              $count--
              this.list[index].count = $count
              this.$forceUpdate()
            } else {
              fn()
              clearInterval(timer)
              timer = null
            }
          }, 1000)
        }
      },
      _gantt (item) {
        this.$router.push({ path: `/projects/instance/gantt/${item.id}` })
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521
      },
      _topCheckBoxClick (v) {
        this.list.forEach((item, i) => {
          this.$set(this.list[i], 'isCheck', v)
        })
        this._arrDelChange()
      },
      _arrDelChange (v) {
        let arr = []
        this.list.forEach((item)=>{
          if (item.isCheck) {
            arr.push(item.id)
          }
        })
        this.strDelete = _.join(arr, ',')
        if (v === false) {
          this.checkAll = false
        }
      },
      _batchDelete () {
G
gongzijian 已提交
522
        this.$refs['poptipDeleteAll'].doClose()
523 524 525 526 527 528 529 530 531 532
        this.batchDeleteInstance({
          processInstanceIds: this.strDelete
        }).then(res => {
          this._onUpdate()
          this.checkAll = false
          this.$message.success(res.msg)
        }).catch(e => {
          this.checkAll = false
          this.$message.error(e.msg || '')
        })
L
ligang 已提交
533 534 535
      }
    },
    watch: {
H
huyuanming 已提交
536 537 538 539 540 541 542 543 544 545
      processInstanceList: {
        handler (a) {
          this.checkAll = false
          this.list = []
          setTimeout(() => {
            this.list = _.cloneDeep(this._listDataHandle(a))
          })
        },
        immediate: true,
        deep: true
546 547 548
      },
      pageNo () {
        this.strDelete = ''
L
ligang 已提交
549 550 551 552 553 554 555 556
      }
    },
    created () {
    },
    mounted () {
    },
    components: { }
  }
557
</script>