mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
761 lines
25 KiB
761 lines
25 KiB
4 years ago
|
<template>
|
||
|
<div>
|
||
|
<v-toolbar flat height="42" class="toolbar-border-bottom">
|
||
|
<v-toolbar-title>
|
||
3 years ago
|
<v-breadcrumbs
|
||
3 years ago
|
:items="[
|
||
|
{
|
||
|
text: nodes.env,
|
||
|
disabled: true,
|
||
|
href: '#',
|
||
|
},
|
||
|
{
|
||
|
text: nodes.dbAlias,
|
||
|
disabled: true,
|
||
|
href: '#',
|
||
|
},
|
||
|
{
|
||
|
text: nodes.title + ' (Webhooks)',
|
||
|
disabled: true,
|
||
|
href: '#',
|
||
|
},
|
||
|
]"
|
||
3 years ago
|
divider=">"
|
||
|
small
|
||
|
>
|
||
|
<template #divider>
|
||
3 years ago
|
<v-icon small color="grey lighten-2"> forward </v-icon>
|
||
4 years ago
|
</template>
|
||
|
</v-breadcrumbs>
|
||
|
</v-toolbar-title>
|
||
3 years ago
|
<v-spacer />
|
||
|
|
||
3 years ago
|
<!--tooltip="Close webhooks modal"-->
|
||
3 years ago
|
<x-btn outlined small @click.prevent="$emit('close')">
|
||
3 years ago
|
<v-icon small left> mdi-close-circle-outline </v-icon>
|
||
3 years ago
|
<!-- Close -->
|
||
3 years ago
|
{{ $t('general.close') }}
|
||
3 years ago
|
</x-btn>
|
||
3 years ago
|
|
||
|
<!--tooltip="Reload hooks"-->
|
||
3 years ago
|
<x-btn v-ge="['hooks', 'reload']" outlined color="primary" small @click.prevent="loadHooksList">
|
||
|
<v-icon small left> mdi-reload </v-icon>
|
||
3 years ago
|
<!-- Reload -->
|
||
3 years ago
|
{{ $t('general.reload') }}
|
||
4 years ago
|
</x-btn>
|
||
|
|
||
3 years ago
|
<!--:tooltip="$t('tooltip.saveChanges')"-->
|
||
3 years ago
|
<x-btn v-ge="['hooks', 'add new']" outlined color="primary" small @click.prevent="addNewHook">
|
||
|
<v-icon small left> mdi-plus </v-icon>
|
||
3 years ago
|
<!--Add New-->
|
||
3 years ago
|
{{ $t('activity.addWebhook') }}
|
||
4 years ago
|
</x-btn>
|
||
|
|
||
|
<!-- <x-btn outlined tooltip="Save Changes"
|
||
|
color="primary"
|
||
|
small
|
||
|
:disabled="loading || !valid || !hook.event"
|
||
|
|
||
|
v-ge="['hooks','save']"
|
||
|
@click.prevent="saveHooks">
|
||
|
<v-icon small left>save</v-icon>
|
||
3 years ago
|
{{ $t('general.save') }}
|
||
4 years ago
|
</x-btn>-->
|
||
|
</v-toolbar>
|
||
|
|
||
3 years ago
|
<v-form ref="form" v-model="valid" class="mx-auto" lazy-validation>
|
||
3 years ago
|
<v-container fluid>
|
||
|
<v-row>
|
||
|
<v-col cols="7">
|
||
|
<v-radio-group v-model="selectedHook" @change="onEventChange">
|
||
|
<template #default>
|
||
|
<v-simple-table dense>
|
||
|
<template #default>
|
||
|
<thead>
|
||
|
<tr>
|
||
|
<th />
|
||
3 years ago
|
<th>
|
||
|
<!--Title-->
|
||
3 years ago
|
{{ $t('general.title') }}
|
||
3 years ago
|
</th>
|
||
|
<th>
|
||
|
<!--Event-->
|
||
3 years ago
|
{{ $t('general.event') }}
|
||
3 years ago
|
</th>
|
||
|
<th>
|
||
|
<!--Condition-->
|
||
3 years ago
|
{{ $t('general.condition') }}
|
||
3 years ago
|
</th>
|
||
|
<th>
|
||
|
<!--Notify Via-->
|
||
3 years ago
|
{{ $t('labels.notifyVia') }}
|
||
3 years ago
|
</th>
|
||
|
<th>
|
||
|
<!--Action-->
|
||
3 years ago
|
{{ $t('labels.action') }}
|
||
3 years ago
|
</th>
|
||
3 years ago
|
</tr>
|
||
|
</thead>
|
||
3 years ago
|
|
||
3 years ago
|
<tbody>
|
||
|
<template v-if="hooks && hooks.length">
|
||
3 years ago
|
<tr v-for="(item, i) in hooks" :key="i">
|
||
3 years ago
|
<td>
|
||
|
<v-radio :value="i" />
|
||
|
</td>
|
||
|
<td>{{ item.title }}</td>
|
||
|
<td>{{ item.event }} {{ item.operation }}</td>
|
||
|
<td>
|
||
3 years ago
|
<v-icon v-if="item.condition" color="success" small> mdi-check-bold </v-icon>
|
||
3 years ago
|
</td>
|
||
|
<td>
|
||
3 years ago
|
{{ item.notification && item.notification.type }}
|
||
|
</td>
|
||
|
<td>
|
||
3 years ago
|
<x-icon small color="error" @click.stop="deleteHook(item, i)"> mdi-delete </x-icon>
|
||
3 years ago
|
<!-- <x-icon small :color="loading || !valid || !hook.event ? 'grey' : 'primary'"
|
||
3 years ago
|
@click.stop="(!loading && valid && hook.event) && saveHooks()">save
|
||
|
</x-icon>-->
|
||
3 years ago
|
</td>
|
||
|
</tr>
|
||
3 years ago
|
</template>
|
||
|
<tr v-else>
|
||
|
<td colspan="6" class="text-center py-5">
|
||
3 years ago
|
<!--:tooltip="$t('tooltip.saveChanges')"-->
|
||
3 years ago
|
<x-btn v-ge="['hooks', 'add new']" outlined color="primary" small @click.prevent="addNewHook">
|
||
|
<v-icon small left> mdi-plus </v-icon>
|
||
3 years ago
|
<!--Add New Webhook-->
|
||
3 years ago
|
{{ $t('activity.addWebhook') }}
|
||
3 years ago
|
</x-btn>
|
||
|
</td>
|
||
|
</tr>
|
||
|
</tbody>
|
||
|
</template>
|
||
|
</v-simple-table>
|
||
|
</template>
|
||
|
</v-radio-group>
|
||
|
</v-col>
|
||
|
<v-col cols="5">
|
||
|
<v-card v-if="hook" class="">
|
||
|
<v-card-title>
|
||
|
Webhook
|
||
|
<v-spacer />
|
||
|
<x-btn
|
||
3 years ago
|
v-ge="['hooks', 'save']"
|
||
3 years ago
|
outlined
|
||
|
tooltip="Save"
|
||
|
color="primary"
|
||
|
small
|
||
|
:disabled="loading || !valid || !hook.event"
|
||
|
@click.prevent="saveHooks"
|
||
|
>
|
||
3 years ago
|
<v-icon small left> save </v-icon>
|
||
3 years ago
|
<!-- Save -->
|
||
3 years ago
|
{{ $t('general.save') }}
|
||
3 years ago
|
</x-btn>
|
||
|
</v-card-title>
|
||
|
<v-card-text>
|
||
|
<v-text-field
|
||
|
v-model="hook.title"
|
||
|
class="caption"
|
||
|
outlined
|
||
|
dense
|
||
3 years ago
|
:label="$t('general.title')"
|
||
3 years ago
|
required
|
||
3 years ago
|
:rules="[v => !!v || `${$t('general.required')}`]"
|
||
3 years ago
|
/>
|
||
|
|
||
3 years ago
|
<webhook-event :event.sync="hook.event" :operation.sync="hook.operation" />
|
||
3 years ago
|
|
||
|
<v-card class="mb-8">
|
||
|
<v-card-text>
|
||
|
<v-checkbox
|
||
3 years ago
|
v-model="hook.condition"
|
||
3 years ago
|
dense
|
||
|
hide-details
|
||
|
class="mt-1"
|
||
|
label="On Condition"
|
||
|
@change="checkConditionAvail"
|
||
|
/>
|
||
|
|
||
|
<column-filter
|
||
3 years ago
|
v-if="hook.condition"
|
||
|
:key="key"
|
||
|
ref="filter"
|
||
|
v-model="filters"
|
||
3 years ago
|
:meta="meta"
|
||
3 years ago
|
:field-list="fieldList"
|
||
|
dense
|
||
|
style="max-width: 100%"
|
||
3 years ago
|
:hook-id="hook.id"
|
||
|
web-hook
|
||
3 years ago
|
/>
|
||
|
</v-card-text>
|
||
|
</v-card>
|
||
|
|
||
|
<v-select
|
||
|
v-model="hook.notification.type"
|
||
|
outlined
|
||
|
dense
|
||
3 years ago
|
:label="$t('general.notification')"
|
||
3 years ago
|
required
|
||
|
:items="notificationList"
|
||
3 years ago
|
:rules="[v => !!v || `${$t('general.required')}`]"
|
||
3 years ago
|
class="caption"
|
||
|
:prepend-inner-icon="notificationIcon[hook.notification.type]"
|
||
|
@change="onNotTypeChange"
|
||
|
>
|
||
3 years ago
|
<template #item="{ item }">
|
||
3 years ago
|
<v-list-item-icon>
|
||
|
<v-icon small>
|
||
|
{{ notificationIcon[item] }}
|
||
|
</v-icon>
|
||
|
</v-list-item-icon>
|
||
|
<v-list-item-title>
|
||
|
{{ item }}
|
||
|
</v-list-item-title>
|
||
|
</template>
|
||
|
</v-select>
|
||
|
|
||
|
<template v-if="hook.notification.type === 'URL'">
|
||
|
<http-webhook v-model="notification" />
|
||
3 years ago
|
</template>
|
||
4 years ago
|
|
||
3 years ago
|
<template v-if="hook.notification.type === 'Slack'">
|
||
|
<v-combobox
|
||
|
v-if="slackChannels"
|
||
|
v-model="notification.channels"
|
||
3 years ago
|
:rules="[v => !!v || `${$t('general.required')}`]"
|
||
3 years ago
|
:items="slackChannels"
|
||
|
item-text="channel"
|
||
|
label="Select Slack channels"
|
||
|
multiple
|
||
|
outlined
|
||
|
dense
|
||
4 years ago
|
class="caption"
|
||
3 years ago
|
/>
|
||
|
</template>
|
||
|
<template v-if="hook.notification.type === 'Microsoft Teams'">
|
||
|
<v-combobox
|
||
|
v-if="teamsChannels"
|
||
|
v-model="notification.channels"
|
||
3 years ago
|
:rules="[v => !!v || `${$t('general.required')}`]"
|
||
3 years ago
|
:items="teamsChannels"
|
||
|
item-text="channel"
|
||
|
label="Select Teams channels"
|
||
|
multiple
|
||
4 years ago
|
outlined
|
||
|
dense
|
||
3 years ago
|
class="caption"
|
||
3 years ago
|
/>
|
||
3 years ago
|
</template>
|
||
|
<template v-if="hook.notification.type === 'Discord'">
|
||
|
<v-combobox
|
||
|
v-if="discordChannels"
|
||
|
v-model="notification.channels"
|
||
3 years ago
|
:rules="[v => !!v || `${$t('general.required')}`]"
|
||
3 years ago
|
:items="discordChannels"
|
||
|
item-text="channel"
|
||
|
label="Select Discord channels"
|
||
|
multiple
|
||
|
outlined
|
||
|
dense
|
||
|
class="caption"
|
||
3 years ago
|
/>
|
||
3 years ago
|
</template>
|
||
|
<template v-if="hook.notification.type === 'Mattermost'">
|
||
|
<v-combobox
|
||
|
v-if="mattermostChannels"
|
||
|
v-model="notification.channels"
|
||
3 years ago
|
:rules="[v => !!v || `${$t('general.required')}`]"
|
||
3 years ago
|
:items="mattermostChannels"
|
||
|
item-text="channel"
|
||
|
label="Select Mattermost channels"
|
||
|
multiple
|
||
4 years ago
|
outlined
|
||
|
dense
|
||
|
class="caption"
|
||
3 years ago
|
/>
|
||
|
</template>
|
||
4 years ago
|
|
||
3 years ago
|
<template v-if="inputs[hook.notification.type] && notification">
|
||
|
<template v-for="input in inputs[hook.notification.type]">
|
||
|
<v-textarea
|
||
|
v-if="input.type === 'LongText'"
|
||
|
:key="input.key"
|
||
|
v-model="notification[input.key]"
|
||
4 years ago
|
class="caption"
|
||
|
dense
|
||
|
outlined
|
||
3 years ago
|
:label="input.label"
|
||
3 years ago
|
:rules="[v => !input.required || !!v || `${$t('general.required')}`]"
|
||
3 years ago
|
/>
|
||
3 years ago
|
<v-text-field
|
||
|
v-else
|
||
|
:key="input.key"
|
||
|
v-model="notification[input.key]"
|
||
4 years ago
|
class="caption"
|
||
3 years ago
|
dense
|
||
|
outlined
|
||
|
:label="input.label"
|
||
3 years ago
|
:rules="[v => !input.required || !!v || `${$t('general.required')}`]"
|
||
3 years ago
|
/>
|
||
4 years ago
|
</template>
|
||
3 years ago
|
</template>
|
||
|
</v-card-text>
|
||
4 years ago
|
|
||
3 years ago
|
<v-card-text>
|
||
|
<span class="caption grey--text">
|
||
3 years ago
|
<em>Available context variables are <strong>data and user</strong></em>
|
||
3 years ago
|
<v-tooltip top>
|
||
3 years ago
|
<template #activator="{ on }">
|
||
3 years ago
|
<v-icon small color="grey" class="ml-2" v-on="on">mdi-information</v-icon>
|
||
4 years ago
|
</template>
|
||
3 years ago
|
<span class="caption">
|
||
3 years ago
|
<strong>data</strong> : Row data <br />
|
||
|
<strong>user</strong> : User information<br />
|
||
3 years ago
|
</span>
|
||
|
</v-tooltip>
|
||
3 years ago
|
<br />
|
||
|
<a href="https://docs.nocodb.com/developer-resources/webhooks/Webhooks.vue">
|
||
3 years ago
|
<!--Document Reference-->
|
||
3 years ago
|
{{ $t('labels.docReference') }}
|
||
3 years ago
|
</a>
|
||
3 years ago
|
</span>
|
||
3 years ago
|
|
||
|
<webhooks-test
|
||
|
:model-id="meta.id"
|
||
|
:hook="{
|
||
|
...hook,
|
||
|
filters,
|
||
|
notification: {
|
||
|
...hook.notification,
|
||
3 years ago
|
payload: notification,
|
||
|
},
|
||
3 years ago
|
}"
|
||
|
/>
|
||
3 years ago
|
</v-card-text>
|
||
|
</v-card>
|
||
|
</v-col>
|
||
|
</v-row>
|
||
|
</v-container>
|
||
4 years ago
|
</v-form>
|
||
|
</div>
|
||
|
</template>
|
||
|
|
||
|
<script>
|
||
3 years ago
|
import HttpWebhook from './webhook/HttpWebhook';
|
||
|
import ColumnFilter from '~/components/project/spreadsheet/components/ColumnFilter';
|
||
3 years ago
|
// import FormInput from '~/components/project/appStore/FormInput'
|
||
3 years ago
|
import WebhookEvent from '~/components/project/tableTabs/webhook/WebhookEvent';
|
||
|
import WebhooksTest from '~/components/project/tableTabs/webhook/WebhooksTest';
|
||
4 years ago
|
|
||
|
export default {
|
||
3 years ago
|
name: 'Webhooks',
|
||
3 years ago
|
components: {
|
||
3 years ago
|
WebhooksTest,
|
||
3 years ago
|
HttpWebhook,
|
||
|
WebhookEvent,
|
||
|
// FormInput,
|
||
3 years ago
|
ColumnFilter,
|
||
3 years ago
|
},
|
||
3 years ago
|
props: ['nodes'],
|
||
4 years ago
|
data: () => ({
|
||
3 years ago
|
key: 0,
|
||
|
apps: {},
|
||
4 years ago
|
slackChannels: null,
|
||
|
teamsChannels: null,
|
||
|
discordChannels: null,
|
||
|
mattermostChannels: null,
|
||
|
selectedHook: null,
|
||
|
enableCondition: false,
|
||
|
hooks: null,
|
||
|
valid: false,
|
||
3 years ago
|
meta: null,
|
||
4 years ago
|
loading: false,
|
||
|
notificationList: [
|
||
3 years ago
|
'URL',
|
||
|
'Email',
|
||
|
'Slack',
|
||
|
'Microsoft Teams',
|
||
|
'Discord',
|
||
|
'Mattermost',
|
||
|
'Twilio',
|
||
3 years ago
|
'Whatsapp Twilio',
|
||
4 years ago
|
],
|
||
|
filters: [],
|
||
|
hook: null,
|
||
|
notification: {},
|
||
|
notificationIcon: {
|
||
3 years ago
|
URL: 'mdi-link',
|
||
|
Email: 'mdi-email',
|
||
|
Slack: 'mdi-slack',
|
||
|
'Microsoft Teams': 'mdi-microsoft-teams',
|
||
|
Discord: 'mdi-discord',
|
||
|
Mattermost: 'mdi-chat',
|
||
|
'Whatsapp Twilio': 'mdi-whatsapp',
|
||
3 years ago
|
Twilio: 'mdi-cellphone-message',
|
||
4 years ago
|
},
|
||
3 years ago
|
urlRules: [v => !v || !v.trim() || /^https?:\/\/.{1,}/.test(v) || 'Not a valid URL'],
|
||
4 years ago
|
fieldList: [],
|
||
|
inputs: {
|
||
|
Email: [
|
||
|
{
|
||
3 years ago
|
key: 'to',
|
||
|
label: 'To Address',
|
||
|
placeholder: 'To Address',
|
||
|
type: 'SingleLineText',
|
||
3 years ago
|
required: true,
|
||
4 years ago
|
},
|
||
|
{
|
||
3 years ago
|
key: 'subject',
|
||
|
label: 'Subject',
|
||
|
placeholder: 'Subject',
|
||
|
type: 'SingleLineText',
|
||
3 years ago
|
required: true,
|
||
3 years ago
|
},
|
||
|
{
|
||
3 years ago
|
key: 'body',
|
||
|
label: 'Body',
|
||
|
placeholder: 'Body',
|
||
|
type: 'LongText',
|
||
3 years ago
|
required: true,
|
||
|
},
|
||
3 years ago
|
],
|
||
3 years ago
|
Slack: [
|
||
|
{
|
||
3 years ago
|
key: 'body',
|
||
|
label: 'Body',
|
||
|
placeholder: 'Body',
|
||
|
type: 'LongText',
|
||
3 years ago
|
required: true,
|
||
|
},
|
||
3 years ago
|
],
|
||
3 years ago
|
'Microsoft Teams': [
|
||
3 years ago
|
{
|
||
3 years ago
|
key: 'body',
|
||
|
label: 'Body',
|
||
|
placeholder: 'Body',
|
||
|
type: 'LongText',
|
||
3 years ago
|
required: true,
|
||
|
},
|
||
3 years ago
|
],
|
||
3 years ago
|
Discord: [
|
||
|
{
|
||
3 years ago
|
key: 'body',
|
||
|
label: 'Body',
|
||
|
placeholder: 'Body',
|
||
|
type: 'LongText',
|
||
3 years ago
|
required: true,
|
||
|
},
|
||
3 years ago
|
],
|
||
3 years ago
|
Mattermost: [
|
||
|
{
|
||
3 years ago
|
key: 'body',
|
||
|
label: 'Body',
|
||
|
placeholder: 'Body',
|
||
|
type: 'LongText',
|
||
3 years ago
|
required: true,
|
||
|
},
|
||
3 years ago
|
],
|
||
3 years ago
|
Twilio: [
|
||
|
{
|
||
3 years ago
|
key: 'body',
|
||
|
label: 'Body',
|
||
|
placeholder: 'Body',
|
||
|
type: 'LongText',
|
||
3 years ago
|
required: true,
|
||
3 years ago
|
},
|
||
|
{
|
||
3 years ago
|
key: 'to',
|
||
|
label: 'Comma separated Mobile #',
|
||
|
placeholder: 'Comma separated Mobile #',
|
||
|
type: 'LongText',
|
||
3 years ago
|
required: true,
|
||
|
},
|
||
3 years ago
|
],
|
||
3 years ago
|
'Whatsapp Twilio': [
|
||
3 years ago
|
{
|
||
3 years ago
|
key: 'body',
|
||
|
label: 'Body',
|
||
|
placeholder: 'Body',
|
||
|
type: 'LongText',
|
||
3 years ago
|
required: true,
|
||
3 years ago
|
},
|
||
|
{
|
||
3 years ago
|
key: 'to',
|
||
|
label: 'Comma separated Mobile #',
|
||
|
placeholder: 'Comma separated Mobile #',
|
||
|
type: 'LongText',
|
||
3 years ago
|
required: true,
|
||
|
},
|
||
|
],
|
||
|
},
|
||
4 years ago
|
}),
|
||
3 years ago
|
async created() {
|
||
3 years ago
|
await this.loadMeta();
|
||
|
await this.loadHooksList();
|
||
3 years ago
|
// todo: load only necessary plugins
|
||
3 years ago
|
await this.loadPluginList();
|
||
|
this.selectedHook = 0;
|
||
|
this.onEventChange();
|
||
3 years ago
|
},
|
||
4 years ago
|
methods: {
|
||
3 years ago
|
async loadPluginList() {
|
||
|
try {
|
||
|
// const plugins = await this.$store.dispatch('sqlMgr/ActSqlOp', [null, 'xcPluginList'])
|
||
3 years ago
|
const plugins = (await this.$api.plugin.list()).list;
|
||
3 years ago
|
// plugins.push(...plugins.splice(0, 3))
|
||
|
this.apps = plugins.reduce((o, p) => {
|
||
3 years ago
|
p.tags = p.tags ? p.tags.split(',') : [];
|
||
|
p.parsedInput = p.input && JSON.parse(p.input);
|
||
|
o[p.title] = p;
|
||
|
return o;
|
||
|
}, {});
|
||
3 years ago
|
} catch (e) {}
|
||
3 years ago
|
},
|
||
|
checkConditionAvail() {
|
||
|
// if (!process.env.EE) {
|
||
|
// this.enableCondition = false
|
||
|
// this.$toast.info('For webhook condition : Upgrade to Enterprise Edition').goAway(3000)
|
||
|
// }
|
||
|
// this.hook.condition = []
|
||
4 years ago
|
},
|
||
3 years ago
|
async onNotTypeChange() {
|
||
3 years ago
|
this.notification = {};
|
||
3 years ago
|
if (this.hook.notification.type === 'Slack') {
|
||
3 years ago
|
// const plugin = await this.$store.dispatch('sqlMgr/ActSqlOp', [null, 'xcPluginRead', {
|
||
|
// title: 'Slack'
|
||
|
// }])
|
||
|
// this.slackChannels = JSON.parse(plugin.input) || []
|
||
|
|
||
3 years ago
|
this.slackChannels = (this.apps && this.apps.Slack && this.apps.Slack.parsedInput) || [];
|
||
4 years ago
|
}
|
||
3 years ago
|
if (this.hook.notification.type === 'Microsoft Teams') {
|
||
3 years ago
|
// const plugin = await this.$store.dispatch('sqlMgr/ActSqlOp', [null, 'xcPluginRead', {
|
||
|
// title: 'Microsoft Teams'
|
||
|
// }])
|
||
|
// this.teamsChannels = JSON.parse(plugin.input) || []
|
||
3 years ago
|
this.teamsChannels =
|
||
3 years ago
|
(this.apps && this.apps['Microsoft Teams'] && this.apps['Microsoft Teams'].parsedInput) || [];
|
||
4 years ago
|
}
|
||
3 years ago
|
if (this.hook.notification.type === 'Discord') {
|
||
3 years ago
|
// const plugin = await this.$store.dispatch('sqlMgr/ActSqlOp', [null, 'xcPluginRead', {
|
||
|
// title: 'Discord'
|
||
|
// }])
|
||
3 years ago
|
this.discordChannels = (this.apps && this.apps.Discord && this.apps.Discord.parsedInput) || [];
|
||
4 years ago
|
}
|
||
3 years ago
|
if (this.hook.notification.type === 'Mattermost') {
|
||
3 years ago
|
// const plugin = await this.$store.dispatch('sqlMgr/ActSqlOp', [null, 'xcPluginRead', {
|
||
|
// title: 'Mattermost'
|
||
|
// }])
|
||
|
// this.mattermostChannels = JSON.parse(plugin.input) || []
|
||
3 years ago
|
this.mattermostChannels = (this.apps && this.apps.Mattermost && this.apps.Mattermost.parsedInput) || [];
|
||
4 years ago
|
}
|
||
|
},
|
||
3 years ago
|
async onEventChange() {
|
||
3 years ago
|
this.key++;
|
||
3 years ago
|
if (!this.hooks || !this.hooks.length) {
|
||
3 years ago
|
return;
|
||
3 years ago
|
}
|
||
3 years ago
|
const { notification: { payload, type } = {}, ...hook } = this.hooks[this.selectedHook] || {};
|
||
4 years ago
|
|
||
|
this.hook = {
|
||
|
...hook,
|
||
|
notification: {
|
||
3 years ago
|
type,
|
||
|
},
|
||
|
};
|
||
3 years ago
|
// this.enableCondition = !!(this.hook && this.hook.condition && Object.keys(this.hook.condition).length)
|
||
3 years ago
|
await this.onNotTypeChange();
|
||
|
this.notification = payload;
|
||
3 years ago
|
if (this.hook.notification.type === 'Slack') {
|
||
3 years ago
|
this.notification.webhook_url =
|
||
|
this.notification.webhook_url &&
|
||
3 years ago
|
this.notification.webhook_url.map(v => this.slackChannels.find(s => v.webhook_url === s.webhook_url));
|
||
4 years ago
|
}
|
||
3 years ago
|
if (this.hook.notification.type === 'Microsoft Teams') {
|
||
3 years ago
|
this.notification.webhook_url =
|
||
|
this.notification.webhook_url &&
|
||
3 years ago
|
this.notification.webhook_url.map(v => this.teamsChannels.find(s => v.webhook_url === s.webhook_url));
|
||
4 years ago
|
}
|
||
3 years ago
|
if (this.hook.notification.type === 'Discord') {
|
||
3 years ago
|
this.notification.webhook_url =
|
||
|
this.notification.webhook_url &&
|
||
3 years ago
|
this.notification.webhook_url.map(v => this.discordChannels.find(s => v.webhook_url === s.webhook_url));
|
||
4 years ago
|
}
|
||
3 years ago
|
if (this.hook.notification.type === 'Mattermost') {
|
||
3 years ago
|
this.notification.webhook_url =
|
||
|
this.notification.webhook_url &&
|
||
3 years ago
|
this.notification.webhook_url.map(v => this.mattermostChannels.find(s => v.webhook_url === s.webhook_url));
|
||
4 years ago
|
}
|
||
3 years ago
|
if (this.hook.notification.type === 'URL') {
|
||
3 years ago
|
// eslint-disable-next-line no-self-assign
|
||
3 years ago
|
this.notification.api = this.notification.api;
|
||
4 years ago
|
}
|
||
|
},
|
||
3 years ago
|
async saveHooks() {
|
||
4 years ago
|
if (!this.$refs.form.validate() || !this.valid || !this.hook.event) {
|
||
3 years ago
|
return;
|
||
4 years ago
|
}
|
||
3 years ago
|
this.loading = true;
|
||
4 years ago
|
try {
|
||
3 years ago
|
// const res = await this.$store.dispatch('sqlMgr/ActSqlOp', [
|
||
|
// {
|
||
|
// env: this.nodes.env,
|
||
|
// dbAlias: this.nodes.dbAlias
|
||
|
// }, 'tableXcHooksSet', {
|
||
|
// tn: this.nodes.table_name,
|
||
|
// data: {
|
||
|
// ...this.hook,
|
||
|
// notification: {
|
||
|
// ...this.hook.notification,
|
||
|
// payload: this.notification
|
||
|
// }
|
||
|
// }
|
||
|
// }
|
||
|
// ])
|
||
3 years ago
|
let res;
|
||
3 years ago
|
if (this.hook.id) {
|
||
|
res = await this.$api.dbTableWebhook.update(this.hook.id, {
|
||
|
...this.hook,
|
||
|
notification: {
|
||
|
...this.hook.notification,
|
||
3 years ago
|
payload: this.notification,
|
||
|
},
|
||
|
});
|
||
3 years ago
|
} else {
|
||
|
res = await this.$api.dbTableWebhook.create(this.meta.id, {
|
||
|
...this.hook,
|
||
|
notification: {
|
||
|
...this.hook.notification,
|
||
3 years ago
|
payload: this.notification,
|
||
|
},
|
||
|
});
|
||
3 years ago
|
}
|
||
4 years ago
|
|
||
|
if (!this.hook.id && res) {
|
||
3 years ago
|
this.hook.id = res.id;
|
||
3 years ago
|
}
|
||
|
if (this.$refs.filter) {
|
||
|
await this.$refs.filter.applyChanges(false, {
|
||
3 years ago
|
hookId: this.hook.id,
|
||
|
});
|
||
4 years ago
|
}
|
||
|
|
||
3 years ago
|
this.$toast.success('Webhook details updated successfully').goAway(3000);
|
||
4 years ago
|
} catch (e) {
|
||
3 years ago
|
this.$toast.error(e.message).goAway(3000);
|
||
4 years ago
|
}
|
||
3 years ago
|
this.loading = false;
|
||
|
await this.loadHooksList();
|
||
3 years ago
|
|
||
3 years ago
|
this.$e('a:webhook:add', {
|
||
3 years ago
|
operation: this.hook.operation,
|
||
|
condition: this.hook.condition,
|
||
3 years ago
|
notification: this.hook.notification.type,
|
||
|
});
|
||
4 years ago
|
},
|
||
3 years ago
|
async loadMeta() {
|
||
3 years ago
|
this.loadingMeta = true;
|
||
3 years ago
|
// const tableMeta = await this.$store.dispatch('sqlMgr/ActSqlOp', [{
|
||
|
// env: this.nodes.env,
|
||
|
// dbAlias: this.nodes.dbAlias
|
||
|
// }, 'tableXcModelGet', {
|
||
|
// tn: this.nodes.table_name
|
||
|
// }] )
|
||
3 years ago
|
this.meta = await this.$store.dispatch('meta/ActLoadMeta', {
|
||
3 years ago
|
table_name: this.nodes.table_name,
|
||
|
}); // JSON.parse(tableMeta.meta)
|
||
|
this.fieldList = this.meta.columns.map(c => c.column_name);
|
||
|
this.loadingMeta = false;
|
||
4 years ago
|
},
|
||
3 years ago
|
async loadHooksList() {
|
||
3 years ago
|
this.key++;
|
||
|
this.loading = true;
|
||
3 years ago
|
// const hooks = await this.$store.dispatch('sqlMgr/ActSqlOp', [{
|
||
|
// env: this.nodes.env,
|
||
|
// dbAlias: this.nodes.dbAlias
|
||
|
// }, 'tableXcHooksList', {
|
||
|
// tn: this.nodes.table_name
|
||
|
// }])
|
||
|
|
||
3 years ago
|
const hooks = await this.$api.dbTableWebhook.list(this.meta.id);
|
||
3 years ago
|
|
||
3 years ago
|
this.hooks = hooks.list.map(h => {
|
||
|
h.notification = h.notification && JSON.parse(h.notification);
|
||
3 years ago
|
// h.condition = h.condition && JSON.parse(h.condition)
|
||
3 years ago
|
|
||
3 years ago
|
return h;
|
||
|
});
|
||
|
this.loading = false;
|
||
4 years ago
|
},
|
||
3 years ago
|
addNewHook() {
|
||
3 years ago
|
this.key++;
|
||
|
this.selectedHook = this.hooks.length;
|
||
4 years ago
|
this.hooks.push({
|
||
|
notification: {
|
||
|
// type:'Email'
|
||
3 years ago
|
},
|
||
|
});
|
||
|
this.onEventChange();
|
||
|
this.$refs.form.resetValidation();
|
||
3 years ago
|
|
||
3 years ago
|
this.$e('c:webhook:add', { count: this.hooks.length });
|
||
4 years ago
|
},
|
||
3 years ago
|
async deleteHook(item, i) {
|
||
4 years ago
|
try {
|
||
|
if (item.id) {
|
||
3 years ago
|
await this.$api.dbTableWebhook.delete(item.id);
|
||
|
this.hooks.splice(i, 1);
|
||
4 years ago
|
} else {
|
||
3 years ago
|
this.hooks.splice(i, 1);
|
||
4 years ago
|
}
|
||
3 years ago
|
this.$toast.success('Hook deleted successfully').goAway(3000);
|
||
4 years ago
|
if (!this.hooks.length) {
|
||
3 years ago
|
this.hook = null;
|
||
4 years ago
|
}
|
||
|
} catch (e) {
|
||
3 years ago
|
this.$toast.error(e.message).goAway(3000);
|
||
4 years ago
|
}
|
||
3 years ago
|
|
||
3 years ago
|
this.$e('a:webhook:delete');
|
||
|
},
|
||
|
},
|
||
|
};
|
||
4 years ago
|
</script>
|
||
|
|
||
|
<style scoped>
|
||
|
/*tr.selected{*/
|
||
|
/* background: #8ceaf6;*/
|
||
|
/*}*/
|
||
|
|
||
|
/deep/ label {
|
||
3 years ago
|
font-size: 0.75rem !important;
|
||
4 years ago
|
}
|
||
|
</style>
|
||
|
<!--
|
||
|
/**
|
||
|
* @copyright Copyright (c) 2021, Xgene Cloud Ltd
|
||
|
*
|
||
|
* @author Naveen MR <oof1lab@gmail.com>
|
||
|
* @author Pranav C Balan <pranavxc@gmail.com>
|
||
|
*
|
||
|
* @license GNU AGPL version 3 or any later version
|
||
|
*
|
||
|
* This program is free software: you can redistribute it and/or modify
|
||
|
* it under the terms of the GNU Affero General Public License as
|
||
|
* published by the Free Software Foundation, either version 3 of the
|
||
|
* License, or (at your option) any later version.
|
||
|
*
|
||
|
* This program is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU Affero General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU Affero General Public License
|
||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
|
*
|
||
|
*/
|
||
|
-->
|