python.vue 6.7 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="shell-model">
    <m-list-box>
G
i18n  
gongzijian 已提交
20
      <div slot="text">{{$t('Script')}}</div>
L
ligang 已提交
21 22 23 24 25 26 27 28
      <div slot="content">
        <div class="from-mirror">
          <textarea id="code-python-mirror" name="code-python-mirror" style="opacity: 0;">
          </textarea>
        </div>
      </div>
    </m-list-box>
    <m-list-box>
G
i18n  
gongzijian 已提交
29
      <div slot="text">{{$t('Resources')}}</div>
L
ligang 已提交
30
      <div slot="content">
B
break60 已提交
31 32 33 34 35 36 37 38 39
        <treeselect v-model="resourceList" :multiple="true" :options="resourceOptions" :normalizer="normalizer" :value-consists-of="valueConsistsOf" :placeholder="$t('Please select resources')">
          <div slot="value-label" slot-scope="{ node }">{{ node.raw.fullName }}</div>
        </treeselect>
        <!-- <m-resources
            ref="refResources"
            @on-resourcesData="_onResourcesData"
            @on-cache-resourcesData="_onCacheResourcesData"
            :resource-list="resourceList">
        </m-resources> -->
L
ligang 已提交
40 41 42 43
      </div>
    </m-list-box>

    <m-list-box>
G
i18n  
gongzijian 已提交
44
      <div slot="text">{{$t('Custom Parameters')}}</div>
L
ligang 已提交
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
      <div slot="content">
        <m-local-params
                ref="refLocalParams"
                @on-local-params="_onLocalParams"
                :udp-list="localParams"
                :hide="false">
        </m-local-params>
      </div>
    </m-list-box>
  </div>
</template>
<script>
  import _ from 'lodash'
  import i18n from '@/module/i18n'
  import mListBox from './_source/listBox'
  import mResources from './_source/resources'
  import mLocalParams from './_source/localParams'
B
break60 已提交
62 63
  import Treeselect from '@riophae/vue-treeselect'
  import '@riophae/vue-treeselect/dist/vue-treeselect.css'
L
ligang 已提交
64 65 66 67 68 69 70 71 72
  import disabledState from '@/module/mixin/disabledState'
  import codemirror from '@/conf/home/pages/resource/pages/file/pages/_source/codemirror'

  let editor

  export default {
    name: 'python',
    data () {
      return {
B
break60 已提交
73
        valueConsistsOf: 'LEAF_PRIORITY',
L
ligang 已提交
74 75 76 77 78
        // script
        rawScript: '',
        // Custom parameter
        localParams: [],
        // resource(list)
Z
zhukai 已提交
79 80
        resourceList: [],
        // Cache ResourceList
B
break60 已提交
81 82
        cacheResourceList: [],
        resourceOptions: [],
L
ligang 已提交
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
      }
    },
    mixins: [disabledState],
    props: {
      backfillItem: Object
    },
    methods: {
      /**
       * return localParams
       */
      _onLocalParams (a) {
        this.localParams = a
      },
      /**
       * return resourceList
       */
      _onResourcesData (a) {
        this.resourceList = a
      },
Z
zhukai 已提交
102 103 104 105 106 107
      /**
       * cache resourceList
       */
      _onCacheResourcesData (a) {
        this.cacheResourceList = a
      },
L
ligang 已提交
108 109 110 111 112 113
      /**
       * verification
       */
      _verification () {
        // rawScript 验证
        if (!editor.getValue()) {
G
i18n  
gongzijian 已提交
114
          this.$message.warning(`${i18n.$t('Please enter script(required)')}`)
L
ligang 已提交
115 116 117 118 119 120 121 122 123 124
          return false
        }

        // localParams Subcomponent verification
        if (!this.$refs.refLocalParams._verifProp()) {
          return false
        }

        // storage
        this.$emit('on-params', {
B
break60 已提交
125 126 127
          resourceList: _.map(this.resourceList, v => {
            return {id: v}
          }),
L
ligang 已提交
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
          localParams: this.localParams,
          rawScript: editor.getValue()
        })
        return true
      },
      /**
       * Processing code highlighting
       */
      _handlerEditor () {
        // editor
        editor = codemirror('code-python-mirror', {
          mode: 'python',
          readOnly: this.isDetails
        })

        this.keypress = () => {
          if (!editor.getOption('readOnly')) {
            editor.showHint({
              completeSingle: false
            })
          }
        }

        // Monitor keyboard
        editor.on('keypress', this.keypress)

        editor.setValue(this.rawScript)

        return editor
B
break60 已提交
157 158 159 160 161 162 163 164 165 166 167 168
      },
      diGuiTree(item) {  // Recursive convenience tree structure
        item.forEach(item => {
          item.children === '' || item.children === undefined || item.children === null || item.children.length === 0?        
            this.operationTree(item) : this.diGuiTree(item.children);
        })
      },
      operationTree(item) {
        if(item.dirctory) {
          item.isDisabled =true
        }
        delete item.children
L
ligang 已提交
169 170
      }
    },
Z
zhukai 已提交
171 172 173
    watch: {
      //Watch the cacheParams
      cacheParams (val) {
B
break60 已提交
174
        this.$emit('on-cache-params', val);
Z
zhukai 已提交
175 176 177 178 179
      }
    },
    computed: {
      cacheParams () {
        return {
B
break60 已提交
180 181 182
          resourceList: _.map(this.resourceList, v => {
            return {id: v}
          }),
183
          localParams: this.localParams
Z
zhukai 已提交
184 185 186
        }
      }
    },
L
ligang 已提交
187
    created () {
B
break60 已提交
188 189 190
      let item = this.store.state.dag.resourcesListS
      this.diGuiTree(item)
      this.options = item
L
ligang 已提交
191 192 193 194
      let o = this.backfillItem

      // Non-null objects represent backfill
      if (!_.isEmpty(o)) {
Z
zhukai 已提交
195
        this.rawScript = o.params.rawScript || ''
L
ligang 已提交
196 197 198 199

        // backfill resourceList
        let resourceList = o.params.resourceList || []
        if (resourceList.length) {
200 201 202 203 204 205 206 207 208 209 210 211 212
          _.map(resourceList, v => {
            if(v.res) {
              this.store.dispatch('dag/getResourceId',{
                type: 'FILE',
                fullName: '/'+v.res
              }).then(res => {
                this.resourceList.push(res.id)
              }).catch(e => {
                this.$message.error(e.msg || '')
              })
            } else {
              this.resourceList.push(v.id)
            }
B
break60 已提交
213
          })
Z
zhukai 已提交
214
          this.cacheResourceList = resourceList
L
ligang 已提交
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
        }

        // backfill localParams
        let localParams = o.params.localParams || []
        if (localParams.length) {
          this.localParams = localParams
        }
      }
    },
    mounted () {
      setTimeout(() => {
        this._handlerEditor()
      }, 200)
    },
    destroyed () {
B
break60 已提交
230 231
      editor.toTextArea() // Uninstall
      editor.off($('.code-python-mirror'), 'keypress', this.keypress)
L
ligang 已提交
232 233 234
    },
    components: { mLocalParams, mListBox, mResources }
  }
Z
zhukai 已提交
235
</script>