formModel.vue 15.9 KB
Newer Older
L
ligang 已提交
1 2 3
<template>
  <div class="form-model-model" v-clickoutside="_handleClose">
    <div class="title-box">
G
i18n  
gongzijian 已提交
4
      <span class="name">{{$t('Current node settings')}}</span>
L
ligang 已提交
5 6 7
      <span class="go-subtask">
        <!-- Component can't pop up box to do component processing -->
        <m-log :item="backfillItem">
G
i18n  
gongzijian 已提交
8 9
          <template slot="history"><a href="javascript:" @click="_seeHistory" ><i class="iconfont">&#xe6ee;</i><em>{{$t('View history')}}</em></a></template>
          <template slot="log"><a href="javascript:"><i class="iconfont">&#xe691;</i><em>{{$t('View log')}}</em></a></template>
L
ligang 已提交
10
        </m-log>
G
i18n  
gongzijian 已提交
11
        <a href="javascript:" @click="_goSubProcess" v-if="_isGoSubProcess"><i class="iconfont">&#xe600;</i><em>{{$t('Enter this child node')}}</em></a>
L
ligang 已提交
12 13 14 15 16 17 18
      </span>
    </div>
    <div class="content-box" v-if="isContentBox">
      <div class="from-model">

        <!-- Node name -->
        <div class="clearfix list">
G
i18n  
gongzijian 已提交
19
          <div class="text-box"><span>{{$t('Node name')}}</span></div>
L
ligang 已提交
20 21 22 23 24 25
          <div class="cont-box">
            <label class="label-box">
              <x-input
                      type="text"
                      v-model="name"
                      :disabled="isDetails"
G
i18n  
gongzijian 已提交
26
                      :placeholder="$t('Please enter name(required)')"
L
ligang 已提交
27 28 29 30 31 32 33 34 35 36
                      maxlength="100"
                      @on-blur="_verifName()"
                      autocomplete="off">
              </x-input>
            </label>
          </div>
        </div>

        <!-- Running sign -->
        <div class="clearfix list">
G
i18n  
gongzijian 已提交
37
          <div class="text-box"><span>{{$t('Run flag')}}</span></div>
L
ligang 已提交
38 39 40
          <div class="cont-box">
            <label class="label-box">
              <x-radio-group v-model="runFlag" >
G
i18n  
gongzijian 已提交
41 42
                <x-radio :label="'NORMAL'" :disabled="isDetails">{{$t('Normal')}}</x-radio>
                <x-radio :label="'FORBIDDEN'" :disabled="isDetails">{{$t('Prohibition execution')}}</x-radio>
L
ligang 已提交
43 44 45 46 47 48 49 50
              </x-radio-group>
            </label>
          </div>
        </div>

        <!-- desc -->
        <div class="clearfix list">
          <div class="text-box">
G
i18n  
gongzijian 已提交
51
            <span>{{$t('Description')}}</span>
L
ligang 已提交
52 53 54 55 56 57 58 59 60 61
          </div>
          <div class="cont-box">

            <label class="label-box">
              <x-input
                      resize
                      :autosize="{minRows:2}"
                      type="textarea"
                      :disabled="isDetails"
                      v-model="desc"
G
i18n  
gongzijian 已提交
62
                      :placeholder="$t('Please enter description')"
L
ligang 已提交
63 64 65 66 67 68 69 70 71
                      autocomplete="off">
              </x-input>
            </label>
          </div>
        </div>

        <!-- Task priority -->
        <div class="clearfix list">
          <div class="text-box">
G
i18n  
gongzijian 已提交
72
            <span>{{$t('Task priority')}}</span>
L
ligang 已提交
73 74 75 76 77 78 79 80 81 82 83
          </div>
          <div class="cont-box">
            <label class="label-box">
              <m-priority v-model="taskInstancePriority" style="width: 180px;"></m-priority>
            </label>
          </div>
        </div>

        <!-- Number of failed retries -->
        <div class="clearfix list" v-if="taskType !== 'SUB_PROCESS'">
          <div class="text-box">
G
i18n  
gongzijian 已提交
84
            <span>{{$t('Number of failed retries')}}</span>
L
ligang 已提交
85 86 87 88
          </div>
          <div class="cont-box">
            <m-select-input v-model="maxRetryTimes" :list="[0,1,2,3,4]">
            </m-select-input>
G
i18n  
gongzijian 已提交
89 90
            <span>({{$t('Times')}})</span>
            <span class="text-b">{{$t('Failed retry interval')}}</span>
L
ligang 已提交
91 92
            <m-select-input v-model="retryInterval" :list="[1,10,30,60,120]">
            </m-select-input>
G
i18n  
gongzijian 已提交
93
            <span>({{$t('Minute')}})</span>
L
ligang 已提交
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
          </div>
        </div>

        <!-- Task timeout alarm -->
        <m-timeout-alarm
                ref="timeout"
                :backfill-item="backfillItem"
                @on-timeout="_onTimeout">
        </m-timeout-alarm>

        <!-- shell node -->
        <m-shell
                v-if="taskType === 'SHELL'"
                @on-params="_onParams"
                ref="SHELL"
                :backfill-item="backfillItem">
        </m-shell>
        <!-- sub_process node -->
        <m-sub-process
                v-if="taskType === 'SUB_PROCESS'"
                @on-params="_onParams"
                @on-set-process-name="_onSetProcessName"
                ref="SUB_PROCESS"
                :backfill-item="backfillItem">
        </m-sub-process>
        <!-- procedure node -->
        <m-procedure
                v-if="taskType === 'PROCEDURE'"
                @on-params="_onParams"
                ref="PROCEDURE"
                :backfill-item="backfillItem">
        </m-procedure>
        <!-- sql node -->
        <m-sql
                v-if="taskType === 'SQL'"
                @on-params="_onParams"
                ref="SQL"
                :backfill-item="backfillItem">
        </m-sql>
        <!-- spark node -->
        <m-spark
                v-if="taskType === 'SPARK'"
                @on-params="_onParams"
                ref="SPARK"
                :backfill-item="backfillItem">
        </m-spark>
        <!-- mr node -->
        <m-mr
                v-if="taskType === 'MR'"
                @on-params="_onParams"
                ref="MR"
                :backfill-item="backfillItem">
        </m-mr>
        <!-- python node -->
        <m-python
                v-if="taskType === 'PYTHON'"
                @on-params="_onParams"
                ref="PYTHON"
                :backfill-item="backfillItem">
        </m-python>
        <!-- dependent node -->
        <m-dependent
                v-if="taskType === 'DEPENDENT'"
                @on-dependent="_onDependent"
                ref="DEPENDENT"
                :backfill-item="backfillItem">
        </m-dependent>

      </div>
    </div>
    <div class="bottom-box">
      <div class="submit" style="background: #fff;">
G
i18n  
gongzijian 已提交
166 167
        <x-button type="text" @click="close()"> {{$t('Cancel')}} </x-button>
        <x-button type="primary" shape="circle" :loading="spinnerLoading" @click="ok()" :disabled="isDetails" v-ps="['GENERAL_USER']">{{spinnerLoading ? 'Loading...' : $t('Confirm add')}} </x-button>
L
ligang 已提交
168 169 170 171 172 173 174 175 176 177 178 179 180
      </div>
    </div>
  </div>
</template>
<script>
  import _ from 'lodash'
  import mLog from './log'
  import mMr from './tasks/mr'
  import mSql from './tasks/sql'
  import i18n from '@/module/i18n'
  import mShell from './tasks/shell'
  import mSpark from './tasks/spark'
  import mPython from './tasks/python'
181
  import { isNameExDag, rtBantpl } from './../plugIn/util'
L
ligang 已提交
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 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 261 262 263 264 265 266 267 268 269 270 271
  import JSP from './../plugIn/jsPlumbHandle'
  import mProcedure from './tasks/procedure'
  import mDependent from './tasks/dependent'
  import mSubProcess from './tasks/sub_process'
  import mSelectInput from './_source/selectInput'
  import mTimeoutAlarm from './_source/timeoutAlarm'
  import clickoutside from '@/module/util/clickoutside'
  import disabledState from '@/module/mixin/disabledState'
  import mPriority from '@/module/components/priority/priority'

  export default {
    name: 'form-model',
    data () {
      return {
        // loading
        spinnerLoading: false,
        // node name
        name: ``,
        // desc
        desc: '',
        // Node echo data
        backfillItem: {},
        // Resource(list)
        resourcesList: [],
        // dependence
        dependence: {},
        // Current node params data
        params: {},
        // Running sign
        runFlag: 'NORMAL',
        // The second echo problem caused by the node data is specifically which node hook caused the unfinished special treatment
        isContentBox: false,
        // Number of failed retries
        maxRetryTimes: '0',
        // Failure retry interval
        retryInterval: '1',
        // Task timeout alarm
        timeout: {},
        // Task priority
        taskInstancePriority: 'MEDIUM'
      }
    },
    /**
     * Click on events that are not generated internally by the component
     */
    directives: { clickoutside },
    mixins: [disabledState],
    props: {
      id: Number,
      taskType: String,
      self: Object
    },
    methods: {
      /**
       * depend
       */
      _onDependent (o) {
        this.dependence = Object.assign(this.dependence, {}, o)
      },
      /**
       * Task timeout alarm
       */
      _onTimeout (o) {
        this.timeout = Object.assign(this.timeout, {}, o)
      },
      /**
       * Click external to close the current component
       */
      _handleClose () {
        this.close()
      },
      /**
       * Jump to task instance
       */
      _seeHistory () {
        this.self.$router.push({
          name: 'task-instance-list',
          query: {
            processInstanceId: this.self.$route.params.id,
            taskName: this.backfillItem.name
          }
        })
        this.$modal.destroy()
      },
      /**
       * Enter the child node to judge the process instance or the process definition
       * @param  type = instance
       */
      _goSubProcess () {
        if (_.isEmpty(this.backfillItem)) {
G
i18n  
gongzijian 已提交
272
          this.$message.warning(`${i18n.$t('The newly created sub-Process has not yet been executed and cannot enter the sub-Process')}`)
L
ligang 已提交
273 274 275 276 277
          return
        }
        if (this.router.history.current.name === 'projects-instance-details') {
          let stateId = $(`#${this.id}`).attr('data-state-id') || null
          if (!stateId) {
G
i18n  
gongzijian 已提交
278
            this.$message.warning(`${i18n.$t('The task has not been executed and cannot enter the sub-Process')}`)
L
ligang 已提交
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
            return
          }
          this.store.dispatch('dag/getSubProcessId', { taskId: stateId }).then(res => {
            this.$emit('onSubProcess', {
              subProcessId: res.data.subProcessInstanceId,
              fromThis: this
            })
          }).catch(e => {
            this.$message.error(e.msg || '')
          })
        } else {
          this.$emit('onSubProcess', {
            subProcessId: this.backfillItem.params.processDefinitionId,
            fromThis: this
          })
        }
      },
      /**
       * return params
       */
      _onParams (o) {
        this.params = Object.assign(this.params, {}, o)
      },
      /**
       * verification name
       */
      _verifName () {
        if (!_.trim(this.name)) {
G
i18n  
gongzijian 已提交
307
          this.$message.warning(`${i18n.$t('Please enter name (required)')}`)
L
ligang 已提交
308 309 310 311 312 313 314
          return false
        }
        if (this.name === this.backfillItem.name) {
          return true
        }
        // Name repeat depends on dom backfill dependent store
        if (isNameExDag(this.name, _.isEmpty(this.backfillItem) ? 'dom' : 'backfill')) {
G
i18n  
gongzijian 已提交
315
          this.$message.warning(`${i18n.$t('Name already exists')}`)
L
ligang 已提交
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355
          return false
        }
        return true
      },
      /**
       * Global verification procedure
       */
      _verification () {
        // Verify name
        if (!this._verifName()) {
          return
        }
        // Verify task alarm parameters
        if (!this.$refs['timeout']._verification()) {
          return
        }
        // Verify node parameters
        if (!this.$refs[this.taskType]._verification()) {
          return
        }

        $(`#${this.id}`).find('span').text(this.name)

        // Store the corresponding node data structure
        this.$emit('addTaskInfo', {
          item: {
            type: this.taskType,
            id: this.id,
            name: this.name,
            params: this.params,
            desc: this.desc,
            runFlag: this.runFlag,
            dependence: this.dependence,
            maxRetryTimes: this.maxRetryTimes,
            retryInterval: this.retryInterval,
            timeout: this.timeout,
            taskInstancePriority: this.taskInstancePriority
          },
          fromThis: this
        })
G
bug1  
gongzijian 已提交
356 357 358

        // set run flag
        this._setRunFlag()
L
ligang 已提交
359 360 361 362 363 364 365
      },
      /**
       * Sub-workflow selected node echo name
       */
      _onSetProcessName (name) {
        this.name = name
      },
G
bug1  
gongzijian 已提交
366 367 368
      /**
       *  set run flag
       */
369
      _setRunFlag () {
G
bug1  
gongzijian 已提交
370 371 372 373 374 375
        let dom = $(`#${this.id}`).find('.ban-p')
        dom.html('')
        if (this.runFlag === 'FORBIDDEN') {
          dom.append(rtBantpl())
        }
      },
L
ligang 已提交
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
      /**
       * Submit verification
       */
      ok () {
        this._verification()
      },
      /**
       * Close and destroy component and component internal events
       */
      close () {
        let flag = false
        // Delete node without storage
        if (!this.backfillItem.name) {
          flag = true
        }
        this.isContentBox = false
        // flag Whether to delete a node this.$destroy()
        this.$emit('close', {
          flag: flag,
          fromThis: this
        })
      }
    },
G
gongzijian 已提交
399
    watch: {
G
bug1  
gongzijian 已提交
400

G
gongzijian 已提交
401
    },
L
ligang 已提交
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 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 473 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 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530
    created () {
      // Unbind copy and paste events
      JSP.removePaste()
      // Backfill data
      let taskList = this.store.state.dag.tasks
      let o = {}
      if (taskList.length) {
        taskList.forEach(v => {
          if (v.id === this.id) {
            o = v
            this.backfillItem = v
          }
        })
        // Non-null objects represent backfill
        if (!_.isEmpty(o)) {
          this.name = o.name
          this.taskInstancePriority = o.taskInstancePriority
          this.runFlag = o.runFlag || 'NORMAL'
          this.desc = o.desc
          this.maxRetryTimes = o.maxRetryTimes
          this.retryInterval = o.retryInterval
        }
      }
      this.isContentBox = true
    },
    mounted () {},
    updated () {
    },
    beforeDestroy () {
    },
    destroyed () {
    },
    computed: {
      /**
       * Child workflow entry show/hide
       */
      _isGoSubProcess () {
        return this.taskType === 'SUB_PROCESS' && this.name
      }
    },
    components: {
      mMr,
      mShell,
      mSubProcess,
      mProcedure,
      mSql,
      mLog,
      mSpark,
      mPython,
      mDependent,
      mSelectInput,
      mTimeoutAlarm,
      mPriority
    }
  }
</script>

<style lang="scss" rel="stylesheet/scss">
  .form-model-model {
    width: 720px;
    position: relative;
    .title-box {
      height: 61px;
      border-bottom: 1px solid #DCDEDC;
      position: relative;
      .name {
        position: absolute;
        left: 24px;
        top: 18px;
        font-size: 16px;
      }
      .go-subtask {
        position: absolute;
        right: 30px;
        top: 17px;
        a {
          font-size: 14px;
          color: #0097e0;
          margin-left: 10px;
          i.iconfont {
            font-size: 18px;
            vertical-align: middle;
          }
          em {
            color: #333;
            vertical-align: middle;
            font-style: normal;
            vertical-align: middle;
            padding-left: 2px;
          }
          &:hover {
            em {
              text-decoration: underline;
            }
          }
        }
      }
    }
    .bottom-box {
      position: absolute;
      bottom: 0;
      left: 0;
      width: 100%;
      text-align: right;
      height: 60px;
      line-height: 60px;
      border-top: 1px solid #DCDEDC;
      background: #fff;
      .submit {
        padding-right: 20px;
        position: relative;
        z-index: 9;
      }
    }
    .content-box {
      overflow-y: scroll;
      height: calc(100vh - 61px);
      padding-bottom: 60px;
    }
  }
  .from-model {
    padding-top: 26px;
    >div {
      clear: both;
    }
    .list {
      position: relative;
      margin-bottom: 10px;
      .text-box {
531
        width: 112px;
L
ligang 已提交
532 533
        float: left;
        text-align: right;
534
        margin-right: 8px;
L
ligang 已提交
535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569
        >span {
          font-size: 14px;
          color: #777;
          display: inline-block;
          padding-top: 6px;
        }
      }
      .cont-box {
        width: 580px;
        float: left;
        .label-box {
          width: 100%;
        }
        .text-b {
          font-size: 14px;
          color: #777;
          display: inline-block;
          padding:0 6px 0 20px;
        }
      }
      .add {
        line-height: 32px;
        a {
          color: #0097e0;
        }
      }
      &:hover {
      }
      .list-t {
        width: 50%;
        float: left;
      }
    }
  }
</style>