dependItemList.vue 11.5 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
<template>
  <div class="dep-list-model">
19 20
    <div v-for="(el,$index) in dependItemList" :key='$index'>
      <el-select filterable :disabled="isDetails" style="width: 450px" v-model="el.projectId" @change="v => _onChangeProjectId(v, $index)" size="small">
B
fix  
break60 已提交
21
        <el-option v-for="item in projectList" :key="item.value" :value="item.value" :label="item.label"></el-option>
22
      </el-select>
23
      <el-select filterable :disabled="isDetails" style="width: 450px" v-model="el.definitionCode" @change="v => _onChangeDefinitionCode(v, $index)" size="small">
B
fix  
break60 已提交
24
        <el-option v-for="item in el.definitionList" :key="item.value" :value="item.value" :label="item.label"></el-option>
25
      </el-select>
B
fix  
break60 已提交
26 27
      <el-select filterable :disabled="isDetails" style="width: 450px" v-model="el.depTasks" size="small">
        <el-option v-for="item in el.depTasksList || []" :key="item" :value="item" :label="item"></el-option>
28
      </el-select>
29
      <el-select v-model="el.cycle" :disabled="isDetails" @change="v => _onChangeCycle(v, $index)" size="small">
B
fix  
break60 已提交
30
        <el-option v-for="item in cycleList" :key="item.value" :value="item.value" :label="item.label"></el-option>
31
      </el-select>
B
fix  
break60 已提交
32 33
      <el-select v-model="el.dateValue" :disabled="isDetails" size="small">
        <el-option v-for="item in el.dateValueList || []" :key="item.value" :value="item.value" :label="item.label"></el-option>
34
      </el-select>
L
ligang 已提交
35 36
      <template v-if="isInstance">
        <span class="instance-state">
37 38 39
          <em class="iconfont el-icon-success" :class="'icon-' + el.state" v-if="el.state === 'SUCCESS'" data-toggle="tooltip" data-container="body" :title="$t('Success')"></em>
          <em class="iconfont el-icon-timer" :class="'icon-' + el.state" v-if="el.state === 'WAITING'" data-toggle="tooltip" data-container="body" :title="$t('Waiting')"></em>
          <em class="iconfont el-icon-error" :class="'icon-' + el.state" v-if="el.state === 'FAILED'" data-toggle="tooltip" data-container="body" :title="$t('Failed')"></em>
L
ligang 已提交
40 41 42 43
        </span>
      </template>
      <span class="operation">
        <a href="javascript:" class="delete" @click="!isDetails && _remove($index)">
44
          <em class="el-icon-delete" :class="_isDetails" data-toggle="tooltip" data-container="body" :title="$t('Delete')" ></em>
L
ligang 已提交
45 46
        </a>
        <a href="javascript:" class="add" @click="!isDetails && _add()" v-if="$index === (dependItemList.length - 1)">
47
          <em class="iconfont el-icon-circle-plus-outline" :class="_isDetails" data-toggle="tooltip" data-container="body" :title="$t('Add')"></em>
L
ligang 已提交
48 49 50 51 52
        </a>
      </span>
    </div>
  </div>
</template>
B
fix  
break60 已提交
53

L
ligang 已提交
54
<script>
55 56 57
  import _ from 'lodash'
  import { cycleList, dateValueList } from './commcon'
  import disabledState from '@/module/mixin/disabledState'
L
ligang 已提交
58 59
  export default {
    name: 'dep-list',
60
    data () {
L
ligang 已提交
61 62
      return {
        list: [],
63
        projectList: [],
L
ligang 已提交
64
        cycleList: cycleList,
65
        isInstance: false
66
      }
L
ligang 已提交
67 68 69 70
    },
    mixins: [disabledState],
    props: {
      dependItemList: Array,
71
      index: Number,
72
      dependTaskList: Array
L
ligang 已提交
73 74 75 76 77 78 79 80 81
    },
    model: {
      prop: 'dependItemList',
      event: 'dependItemListEvent'
    },
    methods: {
      /**
       * add task
       */
82
      _add () {
L
ligang 已提交
83
        // btn loading
84
        this.isLoading = true
Z
zhukai 已提交
85

L
ligang 已提交
86
        // add task list
87
        let projectId = this.projectList[0].value
88
        this._getProcessByProjectCode().then(definitionList => {
Z
zhukai 已提交
89
          // dependItemList index
90
          let is = (value) => _.some(this.dependItemList, { definitionCode: value })
Z
zhukai 已提交
91 92 93 94 95 96 97
          let noArr = _.filter(definitionList, v => !is(v.value))
          let value = noArr[0] && noArr[0].value || null
          let val = value || definitionList[0].value
          this._getDependItemList(val).then(depTasksList => {
            this.$nextTick(() => {
              this.$emit('dependItemListEvent', _.concat(this.dependItemList, this._rtNewParams(val, definitionList, depTasksList, projectId)))
            })
98 99
          })
        })
L
ligang 已提交
100
        // remove tooltip
101
        this._removeTip()
L
ligang 已提交
102 103 104 105
      },
      /**
       * remove task
       */
106
      _remove (i) {
107 108
        // eslint-disable-next-line
        this.dependTaskList[this.index].dependItemList.splice(i, 1)
109
        this._removeTip()
110
        if (!this.dependItemList.length || this.dependItemList.length === 0) {
L
ligang 已提交
111 112
          this.$emit('on-delete-all', {
            index: this.index
113
          })
L
ligang 已提交
114 115
        }
      },
116
      _getProjectList () {
117
        return new Promise((resolve, reject) => {
118
          this.projectList = _.map(_.cloneDeep(this.store.state.dag.projectListS), v => {
119 120 121
            return {
              value: v.id,
              label: v.name
122 123 124 125
            }
          })
          resolve()
        })
126
      },
127
      _getProcessByProjectCode () {
128
        return new Promise((resolve, reject) => {
129
          this.store.dispatch('dag/getProcessByProjectCode').then(res => {
Z
zhukai 已提交
130
            let definitionList = _.map(_.cloneDeep(res), v => {
131
              return {
132 133
                value: v.processDefinition.code,
                label: v.processDefinition.name
134 135
              }
            })
Z
zhukai 已提交
136
            resolve(definitionList)
137 138
          })
        })
139
      },
L
ligang 已提交
140 141 142
      /**
       * get dependItemList
       */
143
      _getDependItemList (codes, is = true) {
L
ligang 已提交
144 145
        return new Promise((resolve, reject) => {
          if (is) {
146
            this.store.dispatch('dag/getProcessTasksList', { code: codes }).then(res => {
147 148
              resolve(['ALL'].concat(_.map(res, v => v.name)))
            })
L
ligang 已提交
149
          } else {
150
            this.store.dispatch('dag/getTaskListDefIdAll', { codes: codes }).then(res => {
151 152
              resolve(res)
            })
L
ligang 已提交
153
          }
154
        })
L
ligang 已提交
155 156 157 158
      },
      /**
       * change process get dependItemList
       */
159
      _onChangeProjectId (value, itemIndex) {
160
        this._getProcessByProjectCode().then(definitionList => {
161
          /* this.$set(this.dependItemList, itemIndex, this._dlOldParams(value, definitionList, item)) */
162 163
          let definitionCode = definitionList[0].value
          this._getDependItemList(definitionCode).then(depTasksList => {
164
            let item = this.dependItemList[itemIndex]
165
            // init set depTasks All
166
            item.depTasks = 'ALL'
167
            // set dependItemList item data
168
            this.$set(this.dependItemList, itemIndex, this._cpOldParams(value, definitionCode, definitionList, depTasksList, item))
169 170
          })
        })
171
      },
172
      _onChangeDefinitionCode (value, itemIndex) {
L
ligang 已提交
173 174
        // get depItem list data
        this._getDependItemList(value).then(depTasksList => {
175
          let item = this.dependItemList[itemIndex]
L
ligang 已提交
176
          // init set depTasks All
177
          item.depTasks = 'ALL'
L
ligang 已提交
178
          // set dependItemList item data
179
          this.$set(this.dependItemList, itemIndex, this._rtOldParams(value, item.definitionList, depTasksList, item))
180
        })
L
ligang 已提交
181
      },
182
      _onChangeCycle (value, itemIndex) {
183
        let list = _.cloneDeep(dateValueList[value])
184 185
        this.$set(this.dependItemList[itemIndex], 'dateValue', list[0].value)
        this.$set(this.dependItemList[itemIndex], 'dateValueList', list)
186
      },
Z
zhukai 已提交
187
      _rtNewParams (value, definitionList, depTasksList, projectId) {
188 189
        return {
          projectId: projectId,
190
          definitionCode: value,
Z
zhukai 已提交
191 192
          // dependItem need private definitionList
          definitionList: definitionList,
193 194 195 196
          depTasks: 'ALL',
          depTasksList: depTasksList,
          cycle: 'day',
          dateValue: 'today',
197
          dateValueList: _.cloneDeep(dateValueList.day),
198
          state: ''
199
        }
L
ligang 已提交
200
      },
Z
zhukai 已提交
201
      _rtOldParams (value, definitionList, depTasksList, item) {
L
ligang 已提交
202
        return {
203
          projectId: item.projectId,
204
          definitionCode: value,
Z
zhukai 已提交
205 206
          // dependItem need private definitionList
          definitionList: definitionList,
L
ligang 已提交
207 208 209 210 211 212
          depTasks: item.depTasks || 'ALL',
          depTasksList: depTasksList,
          cycle: item.cycle,
          dateValue: item.dateValue,
          dateValueList: _.cloneDeep(dateValueList[item.cycle]),
          state: item.state
213
        }
L
ligang 已提交
214
      },
215

216
      _cpOldParams (value, definitionCode, definitionList, depTasksList, item) {
217 218 219
        return {
          projectId: value,
          definitionList: definitionList,
220
          definitionCode: definitionCode,
221 222 223 224 225 226
          depTasks: item.depTasks || 'ALL',
          depTasksList: depTasksList,
          cycle: item.cycle,
          dateValue: item.dateValue,
          dateValueList: _.cloneDeep(dateValueList[item.cycle]),
          state: item.state
227
        }
228
      },
L
ligang 已提交
229 230 231
      /**
       * remove tip
       */
232 233
      _removeTip () {
        $('body').find('.tooltip.fade.top.in').remove()
L
ligang 已提交
234 235
      }
    },
236 237 238 239 240
    watch: {
    },
    beforeCreate () {
    },
    created () {
L
ligang 已提交
241
      // is type projects-instance-details
242
      this.isInstance = this.router.history.current.name === 'projects-instance-details'
L
ligang 已提交
243
      // get processlist
244
      this._getProjectList().then(() => {
L
ligang 已提交
245
        if (!this.dependItemList.length) {
246
          if (!this.projectList.length) return
Z
zhukai 已提交
247
          let projectId = this.projectList[0].value
248
          this._getProcessByProjectCode().then(definitionList => {
Z
zhukai 已提交
249
            let value = definitionList[0].value
250
            this._getDependItemList(value).then(depTasksList => {
Z
zhukai 已提交
251
              this.$emit('dependItemListEvent', _.concat(this.dependItemList, this._rtNewParams(value, definitionList, depTasksList, projectId)))
252 253
            })
          })
L
ligang 已提交
254
        } else {
255 256
          // get definitionCode codes
          let codes = _.map(this.dependItemList, v => v.definitionCode).join(',')
L
ligang 已提交
257
          // get item list
258
          this._getDependItemList(codes, false).then(res => {
259
            _.map(this.dependItemList, (v, i) => {
260
              this._getProcessByProjectCode().then(definitionList => {
261
                this.$set(this.dependItemList, i, this._rtOldParams(v.definitionCode, definitionList, ['ALL'].concat(_.map(res[v.definitionCode] || [], v => v.name)), v))
262 263 264
              })
            })
          })
L
ligang 已提交
265
        }
266 267 268
      })
    },
    mounted () {
L
ligang 已提交
269 270
    },
    components: {}
271
  }
L
ligang 已提交
272 273 274 275 276 277 278 279 280
</script>

<style lang="scss" rel="stylesheet/scss">
  .dep-list-model {
    position: relative;
    min-height: 32px;
    .list {
      margin-bottom: 6px;
      .operation {
B
fix  
break60 已提交
281
        width: 80px;
L
ligang 已提交
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 307 308 309 310 311
        padding-left: 4px;
        a {
          i {
            font-size: 18px;
            vertical-align: middle;
          }
        }
        .delete {
          color: #ff0000;
        }
        .add {
          color: #0097e0;
        }
      }
    }
    .instance-state {
      display: inline-block;
      width: 24px;
      .iconfont {
        font-size: 20px;
        vertical-align: middle;
        cursor: pointer;
        margin-left: 6px;
        &.icon-SUCCESS {
          color: #33cc00;
        }
        &.icon-WAITING {
          color: #888888;
        }
        &.icon-FAILED {
312
          color: #F31322;
L
ligang 已提交
313 314 315 316 317
        }
      }
    }
  }
</style>