admin-webhooks.vue 4.2 KB
Newer Older
Nick's avatar
Nick committed
1 2 3 4 5
<template lang='pug'>
  v-container(fluid, grid-list-lg)
    v-layout(row, wrap)
      v-flex(xs12)
        .admin-header
6
          img.animated.fadeInUp(src='/_assets/svg/icon-winter.svg', alt='Mail', style='width: 80px;')
Nick's avatar
Nick committed
7 8
          .admin-header-title
            .headline.primary--text.animated.fadeInLeft {{ $t('admin:webhooks.title') }}
9
            .subtitle-1.grey--text.animated.fadeInLeft.wait-p4s {{ $t('admin:webhooks.subtitle') }}
Nick's avatar
Nick committed
10 11 12 13 14 15 16 17
          v-spacer
          v-btn.animated.fadeInDown(color='success', depressed, @click='save', large, disabled)
            v-icon(left) check
            span {{$t('common:actions.apply')}}

      v-flex(lg3, xs12)
        v-card.animated.fadeInUp
          v-toolbar(flat, color='primary', dark, dense)
18
            .subtitle-1 Webhooks
Nick's avatar
Nick committed
19 20 21 22 23 24
            v-spacer
            v-btn(outline, small)
              v-icon.mr-2 add
              span New
          v-list(two-line, dense).py-0
            template(v-for='(str, idx) in hooks')
25 26
              v-list-item(:key='str.key', @click='selectedHook = str.key')
                v-list-item-avatar
Nick's avatar
Nick committed
27 28
                  v-icon(color='primary', v-if='str.isEnabled', v-ripple, @click='str.isEnabled = false') check_box
                  v-icon(color='grey', v-else, v-ripple, @click='str.isEnabled = true') check_box_outline_blank
29 30 31 32
                v-list-item-content
                  v-list-item-title.body-2(:class='!str.isAvailable ? `grey--text` : (selectedHook === str.key ? `primary--text` : ``)') {{ str.title }}
                  v-list-item-sub-title.caption(:class='!str.isAvailable ? `grey--text text--lighten-1` : (selectedHook === str.key ? `blue--text ` : ``)') {{ str.description }}
                v-list-item-avatar(v-if='selectedHook === str.key')
Nick's avatar
Nick committed
33 34 35 36 37 38
                  v-icon.animated.fadeInLeft(color='primary') arrow_forward_ios
              v-divider(v-if='idx < hooks.length - 1')

      v-flex(xs12, lg9)
        v-card.wiki-form.animated.fadeInUp.wait-p2s
          v-toolbar(color='primary', dense, flat, dark)
39
            .subtitle-1 {{hook.title}}
Nick's avatar
Nick committed
40 41 42 43 44 45 46 47 48 49 50 51 52
          v-card-text
            v-form
              .authlogo
                img(:src='hook.logo', :alt='hook.title')
              .caption.pt-3 {{hook.description}}
              .caption.pb-3: a(:href='hook.website') {{hook.website}}
              .body-2(v-if='hook.isEnabled')
                span This hook is

</template>

<script>
import _ from 'lodash'
53
// import { get } from 'vuex-pathify'
Nick's avatar
Nick committed
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
import mailConfigQuery from 'gql/admin/mail/mail-query-config.gql'
import mailUpdateConfigMutation from 'gql/admin/mail/mail-mutation-save-config.gql'

export default {
  data() {
    return {
      hooks: [],
      selectedHook: ''
    }
  },
  computed: {
    hook() {
      return _.find(this.hooks, ['id', this.selectedHook]) || {}
    }
  },
  methods: {
    async save () {
      try {
        await this.$apollo.mutate({
          mutation: mailUpdateConfigMutation,
          variables: {
            senderName: this.config.senderName || '',
            senderEmail: this.config.senderEmail || '',
            host: this.config.host || '',
            port: _.toSafeInteger(this.config.port) || 0,
            secure: this.config.secure || false,
            user: this.config.user || '',
            pass: this.config.pass || '',
            useDKIM: this.config.useDKIM || false,
            dkimDomainName: this.config.dkimDomainName || '',
            dkimKeySelector: this.config.dkimKeySelector || '',
            dkimPrivateKey: this.config.dkimPrivateKey || ''
          },
          watchLoading (isLoading) {
            this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-mail-update')
          }
        })
        this.$store.commit('showNotification', {
          style: 'success',
          message: 'Configuration saved successfully.',
          icon: 'check'
        })
      } catch (err) {
        this.$store.commit('pushGraphError', err)
      }
    }
  },
  apollo: {
    hooks: {
      query: mailConfigQuery,
      fetchPolicy: 'network-only',
      update: (data) => _.cloneDeep(data.mail.config),
      watchLoading (isLoading) {
        this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-mail-refresh')
      }
    }
  }
}
</script>

<style lang='scss'>

</style>