sql.vue 10.9 KB
Newer Older
L
ligang 已提交
1 2 3
<template>
  <div class="sql-model">
    <m-list-box>
G
i18n  
gongzijian 已提交
4
      <div slot="text">{{$t('Datasource')}}</div>
L
ligang 已提交
5 6 7 8 9 10 11 12 13
      <div slot="content">
        <m-datasource
                ref="refDs"
                @on-dsData="_onDsData"
                :data="{ type:type,datasource:datasource }">
        </m-datasource>
      </div>
    </m-list-box>
    <m-list-box>
G
i18n  
gongzijian 已提交
14
      <div slot="text">{{$t('SQL Type')}}</div>
L
ligang 已提交
15 16 17 18 19 20 21 22 23
      <div slot="content">
        <div style="display: inline-block;">
          <m-sql-type
                  @on-sqlType="_onSqlType"
                  :sql-type="sqlType">
          </m-sql-type>
        </div>
        <div v-if="!sqlType" style="display: inline-block;padding-left: 10px;margin-top: 2px;">
          <x-checkbox-group v-model="showType">
G
i18n  
gongzijian 已提交
24 25
            <x-checkbox :label="'TABLE'" :disabled="isDetails">{{$t('Table')}}</x-checkbox>
            <x-checkbox :label="'ATTACHMENT'" :disabled="isDetails">{{$t('Attachment')}}</x-checkbox>
L
ligang 已提交
26 27 28 29
          </x-checkbox-group>
        </div>
      </div>
    </m-list-box>
30
    <template v-if="!sqlType && showType.length">
31 32 33 34 35 36 37 38 39 40 41
      <m-list-box>
        <div slot="text">{{$t('Title')}}</div>
        <div slot="content">
          <x-input
            type="input"
            v-model="title"
            :placeholder="$t('Please enter the title of email')"
            autocomplete="off">
          </x-input>
        </div>
      </m-list-box>
42
      <m-list-box>
43
        <div slot="text">{{$t('Recipient')}}</div>
44
        <div slot="content">
45
          <m-email v-model="receivers" :disabled="isDetails" :repeat-data="receiversCc"></m-email>
46 47 48
        </div>
      </m-list-box>
      <m-list-box>
49
        <div slot="text">{{$t('Cc')}}</div>
50
        <div slot="content">
51
          <m-email v-model="receiversCc" :disabled="isDetails" :repeat-data="receivers"></m-email>
52 53 54
        </div>
      </m-list-box>
    </template>
L
ligang 已提交
55
    <m-list-box v-show="type === 'HIVE'">
G
i18n  
gongzijian 已提交
56
      <div slot="text">{{$t('SQL Parameter')}}</div>
L
ligang 已提交
57 58 59 60 61
      <div slot="content">
        <x-input
                :disabled="isDetails"
                type="input"
                v-model="connParams"
G
i18n  
gongzijian 已提交
62
                :placeholder="$t('Please enter format') + ' key1=value1;key2=value2...'"
L
ligang 已提交
63 64 65 66 67
                autocomplete="off">
        </x-input>
      </div>
    </m-list-box>
    <m-list-box>
G
i18n  
gongzijian 已提交
68
      <div slot="text">{{$t('SQL Statement')}}</div>
L
ligang 已提交
69 70 71 72 73 74 75 76 77 78 79
      <div slot="content">
        <div class="from-mirror">
          <textarea
                  id="code-sql-mirror"
                  name="code-sql-mirror"
                  style="opacity: 0;">
          </textarea>
        </div>
      </div>
    </m-list-box>
    <m-list-box v-if="type === 'HIVE'">
G
i18n  
gongzijian 已提交
80
      <div slot="text">{{$t('UDF Function')}}</div>
L
ligang 已提交
81 82 83 84 85 86 87 88 89 90
      <div slot="content">
        <m-udfs
                ref="refUdfs"
                @on-udfsData="_onUdfsData"
                :udfs="udfs"
                :type="type">
        </m-udfs>
      </div>
    </m-list-box>
    <m-list-box>
G
i18n  
gongzijian 已提交
91
      <div slot="text">{{$t('Custom Parameters')}}</div>
L
ligang 已提交
92 93 94 95 96 97 98 99
      <div slot="content">
        <m-local-params
                ref="refLocalParams"
                @on-udpData="_onUdpData"
                :udp-list="localParams">
        </m-local-params>
      </div>
    </m-list-box>
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
    <m-list-box>
      <div slot="text">{{$t('Pre Statement')}}</div>
      <div slot="content">
        <m-statement-list
          ref="refPreStatements"
          @on-statement-list="_onPreStatements"
          :statement-list="preStatements">
        </m-statement-list>
      </div>
    </m-list-box>
    <m-list-box>
      <div slot="text">{{$t('Post Statement')}}</div>
      <div slot="content">
        <m-statement-list
          ref="refPostStatements"
          @on-statement-list="_onPostStatements"
          :statement-list="postStatements">
        </m-statement-list>
      </div>
    </m-list-box>
L
ligang 已提交
120 121 122 123 124 125 126 127 128 129
  </div>
</template>
<script>
  import _ from 'lodash'
  import i18n from '@/module/i18n'
  import mUdfs from './_source/udfs'
  import mListBox from './_source/listBox'
  import mSqlType from './_source/sqlType'
  import mDatasource from './_source/datasource'
  import mLocalParams from './_source/localParams'
130
  import mStatementList from './_source/statementList'
L
ligang 已提交
131
  import disabledState from '@/module/mixin/disabledState'
132
  import mEmail from '@/conf/home/pages/projects/pages/definition/pages/list/_source/email'
L
ligang 已提交
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
  import codemirror from '@/conf/home/pages/resource/pages/file/pages/_source/codemirror'

  let editor

  export default {
    name: 'sql',
    data () {
      return {
        // Data source type
        type: '',
        // data source
        datasource: '',
        // Return to the selected data source
        rtDatasource: '',
        // Sql statement
        sql: '',
        // Custom parameter
        localParams: [],
        // UDF function
        udfs: '',
        // Sql type
        sqlType: 0,
155 156
        // Email title
        title: '',
L
ligang 已提交
157 158 159
        // Form/attachment
        showType: ['TABLE'],
        // Sql parameter
160 161 162 163
        connParams: '',
        // Pre statements
        preStatements: [],
        // Post statements
B
baoliang 已提交
164
        postStatements: [],
165 166 167 168
        // recipients
        receivers: [],
        // copy to
        receiversCc: []
L
ligang 已提交
169 170 171 172
      }
    },
    mixins: [disabledState],
    props: {
173 174
      backfillItem: Object,
      createNodeId: Number
L
ligang 已提交
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
    },
    methods: {
      /**
       * return sqlType
       */
      _onSqlType (a) {
        this.sqlType = a
      },
      /**
       * return udfs
       */
      _onUdfsData (a) {
        this.udfs = a
      },
      /**
       * return Custom parameter
       */
      _onUdpData (a) {
        this.localParams = a
      },
      /**
       * return data source
       */
      _onDsData (o) {
        this.type = o.type
        this.rtDatasource = o.datasource
      },
202 203 204 205 206 207 208 209 210 211 212 213
      /**
       * return pre statements
       */
      _onPreStatements (a) {
        this.preStatements = a
      },
      /**
       * return post statements
       */
      _onPostStatements (a) {
        this.postStatements = a
      },
L
ligang 已提交
214 215 216 217 218
      /**
       * verification
       */
      _verification () {
        if (!editor.getValue()) {
G
i18n  
gongzijian 已提交
219
          this.$message.warning(`${i18n.$t('Please enter a SQL Statement(required)')}`)
L
ligang 已提交
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
          return false
        }

        // datasource Subcomponent verification
        if (!this.$refs.refDs._verifDatasource()) {
          return false
        }

        // udfs Subcomponent verification Verification only if the data type is HIVE
        if (this.type === 'HIVE') {
          if (!this.$refs.refUdfs._verifUdfs()) {
            return false
          }
        }

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

240 241 242 243 244 245 246 247 248 249
        // preStatements Subcomponent verification
        if (!this.$refs.refPreStatements._verifProp()) {
          return false
        }

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

L
ligang 已提交
250 251 252 253 254 255 256
        // storage
        this.$emit('on-params', {
          type: this.type,
          datasource: this.rtDatasource,
          sql: editor.getValue(),
          udfs: this.udfs,
          sqlType: this.sqlType,
257
          title: this.title,
258 259
          receivers: this.receivers.join(','),
          receiversCc: this.receiversCc.join(','),
L
ligang 已提交
260 261 262 263 264 265 266 267 268 269 270 271 272
          showType: (() => {
            /**
             * Special processing return order TABLE,ATTACHMENT
             * Handling checkout sequence
             */
            let showType = this.showType
            if (showType.length === 2 && showType[0] === 'ATTACHMENT') {
              return [showType[1], showType[0]].join(',')
            } else {
              return showType.join(',')
            }
          })(),
          localParams: this.localParams,
273 274 275
          connParams: this.connParams,
          preStatements: this.preStatements,
          postStatements: this.postStatements
L
ligang 已提交
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
        })
        return true
      },
      /**
       * Processing code highlighting
       */
      _handlerEditor () {
        // editor
        editor = codemirror('code-sql-mirror', {
          mode: 'sql',
          readOnly: this.isDetails
        })

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

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

        editor.setValue(this.sql)

        return editor
303 304
      },
      _getReceiver () {
305 306 307 308 309 310 311 312
        let param = {}
        let current = this.router.history.current
        if (current.name === 'projects-definition-details') {
          param.processDefinitionId = current.params.id
        } else {
          param.processInstanceId = current.params.id
        }
        this.store.dispatch('dag/getReceiver', param).then(res => {
313 314 315
          this.receivers = res.receivers && res.receivers.split(',') || []
          this.receiversCc = res.receiversCc && res.receiversCc.split(',') || []
        })
L
ligang 已提交
316 317 318 319 320 321 322 323
      }
    },
    watch: {
      // Listening to sqlType
      sqlType (val) {
        if (val) {
          this.showType = []
        }
324
        if (val !== 0) {
325
          this.title = ''
326 327 328
          this.receivers = []
          this.receiversCc = []
        }
L
ligang 已提交
329 330 331 332 333 334
      },
      // Listening data source
      type (val) {
        if (val !== 'HIVE') {
          this.connParams = ''
        }
335 336 337 338
      },
      //
      showType (val) {
        if (!val.length) {
339
          this.title = ''
340 341 342
          this.receivers = []
          this.receiversCc = []
        }
L
ligang 已提交
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358
      }
    },
    created () {
      let o = this.backfillItem

      // Non-null objects represent backfill
      if (!_.isEmpty(o)) {
        // backfill
        this.type = o.params.type || ''
        this.datasource = o.params.datasource || ''
        this.sql = o.params.sql || ''
        this.udfs = o.params.udfs || ''
        this.sqlType = o.params.sqlType
        this.connParams = o.params.connParams || ''
        this.localParams = o.params.localParams || []
        this.showType = o.params.showType.split(',') || []
359 360
        this.preStatements = o.params.preStatements || []
        this.postStatements = o.params.postStatements || []
361
        this.title = o.params.title || ''
362 363
        this.receivers = o.params.receivers && o.params.receivers.split(',') || []
        this.receiversCc = o.params.receiversCc && o.params.receiversCc.split(',') || []
L
ligang 已提交
364
      }
365 366
      if (!_.some(this.store.state.dag.tasks, { id: this.createNodeId }) &&
        this.router.history.current.name !== 'definition-create') {
367
        this._getReceiver()
L
ligang 已提交
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384
      }
    },
    mounted () {
      setTimeout(() => {
        this._handlerEditor()
      }, 200)
    },
    destroyed () {
      /**
       * Destroy the editor instance
       */
      if (editor) {
        editor.toTextArea() // Uninstall
        editor.off($('.code-sql-mirror'), 'keypress', this.keypress)
      }
    },
    computed: {},
B
baoliang 已提交
385
    components: { mListBox, mDatasource, mLocalParams, mUdfs, mSqlType, mStatementList, mEmail }
L
ligang 已提交
386 387
  }
</script>