Expand webhook options, allow for budgets.

This commit is contained in:
James Cole
2025-08-17 07:40:19 +02:00
parent 52abe3bbc2
commit 7771b0311c
20 changed files with 3279 additions and 3046 deletions

View File

@@ -24,7 +24,10 @@
{{ $t('form.webhook_delivery') }}
</label>
<div class="col-sm-8">
<select
<div v-if="loading" class="form-control-static">
<em class="fa fa-spinner fa-spin"></em> {{ $t('firefly.loading') }}
</div>
<select v-if="!loading"
ref="bill"
v-model="delivery"
:title="$t('form.webhook_delivery')"
@@ -49,6 +52,7 @@ export default {
name: "WebhookDelivery",
data() {
return {
loading: true,
delivery : 0,
deliveries: [
@@ -71,8 +75,24 @@ export default {
mounted() {
this.delivery = this.value;
this.deliveries = [
{id: 300, name: this.$t('firefly.webhook_delivery_JSON')},
//{id: 300, name: this.$t('firefly.webhook_delivery_JSON')},
];
axios.get('./api/v1/configuration/webhook.deliveries').then((response) => {
for (let key in response.data.data.value) {
if (!response.data.data.value.hasOwnProperty(key)) {
continue;
}
this.deliveries.push(
{
id: response.data.data.value[key],
name: this.$t('firefly.webhook_delivery_' + key),
}
);
}
this.loading = false;
}).catch((error) => {
this.loading = false;
});
},
watch: {
value() {

View File

@@ -19,73 +19,89 @@
-->
<template>
<div class="form-group" v-bind:class="{ 'has-error': hasError()}">
<label class="col-sm-4 control-label">
{{ $t('form.webhook_response') }}
</label>
<div class="col-sm-8">
<select
ref="bill"
v-model="response"
:title="$t('form.webhook_response')"
class="form-control"
name="webhook_response"
>
<option v-for="response in this.responses"
:label="response.name"
:value="response.id">{{ response.name }}
</option>
</select>
<p class="help-block" v-text="$t('firefly.webhook_response_form_help')"></p>
<ul v-for="error in this.error" class="list-unstyled">
<li class="text-danger">{{ error }}</li>
</ul>
<div class="form-group" v-bind:class="{ 'has-error': hasError()}">
<label class="col-sm-4 control-label">
{{ $t('form.webhook_response') }}
</label>
<div class="col-sm-8">
<div v-if="loading" class="form-control-static">
<em class="fa fa-spinner fa-spin"></em> {{ $t('firefly.loading') }}
</div>
<select v-if="!loading"
ref="response"
v-model="response"
:title="$t('form.webhook_response')"
class="form-control"
name="webhook_response"
>
<option v-for="response in this.responses"
:label="response.name"
:value="response.id">{{ response.name }}
</option>
</select>
<p class="help-block" v-text="$t('firefly.webhook_response_form_help')"></p>
<ul v-for="error in this.error" class="list-unstyled">
<li class="text-danger">{{ error }}</li>
</ul>
</div>
</div>
</div>
</template>
<script>
export default {
name: "WebhookResponse",
data() {
return {
response: 0,
responses: [],
};
},
props: {
error: {
type: Array,
required: true,
default() {
return []
}
name: "WebhookResponse",
data() {
return {
loading: true,
response: 0,
responses: [],
};
},
value: {
type: Number,
required: true,
}
},
watch: {
value() {
this.response = this.value;
props: {
error: {
type: Array,
required: true,
default() {
return []
}
},
value: {
type: Number,
required: true,
}
},
watch: {
value() {
this.response = this.value;
},
response(newValue) {
this.$emit('input', newValue);
}
},
mounted() {
this.response = this.value;
this.responses = [];
axios.get('./api/v1/configuration/webhook.responses').then((response) => {
for (let key in response.data.data.value) {
if (!response.data.data.value.hasOwnProperty(key)) {
continue;
}
this.responses.push(
{
id: response.data.data.value[key],
name: this.$t('firefly.webhook_response_' + key),
}
);
}
this.loading = false;
}).catch((error) => {
this.loading = false;
});
},
methods: {
hasError() {
return this.error?.length > 0;
}
},
response(newValue) {
this.$emit('input', newValue);
}
},
mounted() {
this.response = this.value;
this.responses = [
{id: 200, name: this.$t('firefly.webhook_response_TRANSACTIONS')},
{id: 210, name: this.$t('firefly.webhook_response_ACCOUNTS')},
{id: 220, name: this.$t('firefly.webhook_response_none_NONE')},
];
},
methods: {
hasError() {
return this.error?.length > 0;
}
},
}
</script>

View File

@@ -19,73 +19,90 @@
-->
<template>
<div class="form-group" v-bind:class="{ 'has-error': hasError()}">
<label class="col-sm-4 control-label">
{{ $t('form.webhook_trigger') }}
</label>
<div class="col-sm-8">
<select
ref="bill"
v-model="trigger"
:title="$t('form.webhook_trigger')"
class="form-control"
name="webhook_trigger"
>
<option v-for="trigger in this.triggers"
:label="trigger.name"
:value="trigger.id">{{ trigger.name }}
</option>
</select>
<p class="help-block" v-text="$t('firefly.webhook_trigger_form_help')"></p>
<ul v-for="error in this.error" class="list-unstyled">
<li class="text-danger">{{ error }}</li>
</ul>
<div class="form-group" v-bind:class="{ 'has-error': hasError()}">
<label class="col-sm-4 control-label">
{{ $t('form.webhook_trigger') }}
</label>
<div class="col-sm-8">
<div v-if="loading" class="form-control-static">
<em class="fa fa-spinner fa-spin"></em> {{ $t('firefly.loading') }}
</div>
<select v-if="!loading"
ref="trigger"
v-model="trigger"
:title="$t('form.webhook_trigger')"
class="form-control"
name="webhook_trigger"
>
<option v-for="trigger in this.triggers"
:label="trigger.name"
:value="trigger.id">{{ trigger.name }}
</option>
</select>
<p class="help-block" v-text="$t('firefly.webhook_trigger_form_help')"></p>
<ul v-for="error in this.error" class="list-unstyled">
<li class="text-danger">{{ error }}</li>
</ul>
</div>
</div>
</div>
</template>
<script>
export default {
name: "WebhookTrigger",
data() {
return {
trigger: 0,
triggers: [],
};
},
props: {
error: {
type: Array,
required: true,
default() {
return []
}
name: "WebhookTrigger",
data() {
return {
trigger: 0,
loading: true,
triggers: [],
};
},
value: {
type: Number,
required: true,
}
},
mounted() {
this.trigger = this.value;
this.triggers = [
{id: 100, name: this.$t('firefly.webhook_trigger_STORE_TRANSACTION')},
{id: 110, name: this.$t('firefly.webhook_trigger_UPDATE_TRANSACTION')},
{id: 120, name: this.$t('firefly.webhook_trigger_DESTROY_TRANSACTION')},
];
},
watch: {
value() {
this.trigger = this.value;
props: {
error: {
type: Array,
required: true,
default() {
return []
}
},
value: {
type: Number,
required: true,
}
},
mounted() {
this.trigger = this.value;
this.triggers = [];
axios.get('./api/v1/configuration/webhook.triggers').then((response) => {
for (let key in response.data.data.value) {
if (!response.data.data.value.hasOwnProperty(key)) {
continue;
}
this.triggers.push(
{
id: response.data.data.value[key],
name: this.$t('firefly.webhook_trigger_' + key),
}
);
console.log('webhook trigger: id=' + response.data.data.value[key] + ', name=' + key);
}
this.loading = false;
}).catch((error) => {
this.loading = false;
});
},
watch: {
value() {
this.trigger = this.value;
},
trigger(newValue) {
this.$emit('input', newValue);
}
},
methods: {
hasError() {
return this.error?.length > 0;
}
},
trigger(newValue) {
this.$emit('input', newValue);
}
},
methods: {
hasError() {
return this.error?.length > 0;
}
},
}
</script>

View File

@@ -19,138 +19,172 @@
-->
<template>
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12">
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">
{{ $t('firefly.webhooks') }}
</h3>
</div>
<div class="box-body no-padding">
<div style="padding:8px;">
<a href="webhooks/create" class="btn btn-success"><span class="fa fa-plus fa-fw"></span>{{ $t('firefly.create_new_webhook') }}</a>
</div>
<table class="table table-responsive table-hover" v-if="webhooks.length > 0" aria-label="A table.">
<thead>
<tr>
<th>Title</th>
<th>Responds when</th>
<th>Responds with (delivery)</th>
<th style="width:20%;">Secret (show / hide)</th>
<th>URL</th>
<th class="hidden-sm hidden-xs">&nbsp;</th>
</tr>
</thead>
<tbody>
<tr v-for="webhook in webhooks" :key="webhook.id">
<td>
<a :href="'webhooks/show/' + webhook.id">{{ webhook.title }}</a>
</td>
<td>
<span v-if="webhook.active">{{ triggers[webhook.trigger] }}</span>
<span v-if="!webhook.active" class="text-muted"><s>{{ triggers[webhook.trigger] }}</s> ({{ $t('firefly.inactive') }})</span>
</td>
<td>{{ responses[webhook.response] }} ({{ deliveries[webhook.delivery] }})</td>
<td>
<em style="cursor:pointer"
v-if="webhook.show_secret" class="fa fa-eye" @click="toggleSecret(webhook)"></em>
<em style="cursor:pointer"
v-if="!webhook.show_secret" class="fa fa-eye-slash" @click="toggleSecret(webhook)"></em>
<code v-if="webhook.show_secret">{{ webhook.secret }}</code>
<code v-if="!webhook.show_secret">********</code>
</td>
<td>
<code :title="webhook.full_url">{{ webhook.url }}</code>
</td>
<td class="hidden-sm hidden-xs">
<div class="btn-group btn-group-xs pull-right">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
{{ $t('firefly.actions') }} <span class="caret"></span></button>
<ul class="dropdown-menu dropdown-menu-right" role="menu">
<li><a :href="'webhooks/show/' + webhook.id"><span class="fa fa-fw fa-search"></span> {{ $t('firefly.inspect') }}</a></li>
<li><a :href="'webhooks/edit/' + webhook.id"><span class="fa fa-fw fa-pencil"></span> {{$t( 'firefly.edit') }}</a></li>
<li><a :href="'webhooks/delete/' + webhook.id"><span class="fa fa-fw fa-trash"></span> {{ $t('firefly.delete') }}</a></li>
</ul>
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12">
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">
{{ $t('firefly.webhooks') }}
</h3>
</div>
</td>
</tr>
</tbody>
</table>
<div class="box-body no-padding">
<div style="padding:8px;">
<a href="webhooks/create" class="btn btn-success"><span
class="fa fa-plus fa-fw"></span>{{ $t('firefly.create_new_webhook') }}</a>
</div>
<div v-if="webhooks.length > 0" style="padding:8px;">
<a href="webhooks/create" class="btn btn-success"><span class="fa fa-plus fa-fw"></span>{{ $t('firefly.create_new_webhook') }}</a>
</div>
<table class="table table-responsive table-hover" v-if="webhooks.length > 0" aria-label="A table.">
<thead>
<tr>
<th>Title</th>
<th>Responds when</th>
<th>Responds with (delivery)</th>
<th style="width:20%;">Secret (show / hide)</th>
<th>URL</th>
<th class="hidden-sm hidden-xs">&nbsp;</th>
</tr>
</thead>
<tbody>
<tr v-for="webhook in webhooks" :key="webhook.id">
<td>
<a :href="'webhooks/show/' + webhook.id">{{ webhook.title }}</a>
</td>
<td>
<span v-if="webhook.active">{{ triggers[webhook.trigger] }}</span>
<span v-if="!webhook.active" class="text-muted"><s>{{ triggers[webhook.trigger] }}</s> ({{
$t('firefly.inactive')
}})</span>
</td>
<td>{{ responses[webhook.response] }} ({{ deliveries[webhook.delivery] }})</td>
<td>
<em style="cursor:pointer"
v-if="webhook.show_secret" class="fa fa-eye" @click="toggleSecret(webhook)"></em>
<em style="cursor:pointer"
v-if="!webhook.show_secret" class="fa fa-eye-slash"
@click="toggleSecret(webhook)"></em>
<code v-if="webhook.show_secret">{{ webhook.secret }}</code>
<code v-if="!webhook.show_secret">********</code>
</td>
<td>
<code :title="webhook.full_url">{{ webhook.url }}</code>
</td>
<td class="hidden-sm hidden-xs">
<div class="btn-group btn-group-xs pull-right">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false">
{{ $t('firefly.actions') }} <span class="caret"></span></button>
<ul class="dropdown-menu dropdown-menu-right" role="menu">
<li><a :href="'webhooks/show/' + webhook.id"><span
class="fa fa-fw fa-search"></span> {{ $t('firefly.inspect') }}</a></li>
<li><a :href="'webhooks/edit/' + webhook.id"><span
class="fa fa-fw fa-pencil"></span> {{ $t('firefly.edit') }}</a></li>
<li><a :href="'webhooks/delete/' + webhook.id"><span
class="fa fa-fw fa-trash"></span> {{ $t('firefly.delete') }}</a></li>
</ul>
</div>
</td>
</tr>
</tbody>
</table>
<div v-if="webhooks.length > 0" style="padding:8px;">
<a href="webhooks/create" class="btn btn-success"><span
class="fa fa-plus fa-fw"></span>{{ $t('firefly.create_new_webhook') }}</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
name: "Index",
data() {
return {
webhooks: [],
triggers: {
STORE_TRANSACTION: this.$t('firefly.webhook_trigger_STORE_TRANSACTION'),
UPDATE_TRANSACTION: this.$t('firefly.webhook_trigger_UPDATE_TRANSACTION'),
DESTROY_TRANSACTION: this.$t('firefly.webhook_trigger_DESTROY_TRANSACTION'),
},
responses: {
TRANSACTIONS: this.$t('firefly.webhook_response_TRANSACTIONS'),
ACCOUNTS: this.$t('firefly.webhook_response_ACCOUNTS'),
NONE: this.$t('firefly.webhook_response_none_NONE'),
},
deliveries: {
JSON: this.$t('firefly.webhook_delivery_JSON'),
},
};
},
mounted() {
this.getWebhooks();
},
methods: {
getWebhooks: function () {
this.webhooks = [];
this.downloadWebhooks(1);
name: "Index",
data() {
return {
webhooks: [],
triggers: {
},
responses: {
},
deliveries: {
},
};
},
toggleSecret: function (webhook) {
webhook.show_secret = !webhook.show_secret;
mounted() {
this.getOptions();
},
downloadWebhooks: function (page) {
axios.get("./api/v1/webhooks?page=" + page).then((response) => {
for (let i in response.data.data) {
if (response.data.data.hasOwnProperty(i)) {
let current = response.data.data[i];
let webhook = {
id: current.id,
title: current.attributes.title,
url: current.attributes.url,
active: current.attributes.active,
full_url: current.attributes.url,
secret: current.attributes.secret,
trigger: current.attributes.trigger,
response: current.attributes.response,
delivery: current.attributes.delivery,
show_secret: false,
};
if(current.attributes.url.length > 20) {
webhook.url = current.attributes.url.slice(0, 20) + '...';
}
this.webhooks.push(webhook);
}
}
methods: {
getOptions: function () {
// get triggers
axios.get('./api/v1/configuration/webhook.triggers').then((response) => {
for (let key in response.data.data.value) {
if (!response.data.data.value.hasOwnProperty(key)) {
continue;
}
this.triggers[key] = this.$t('firefly.webhook_trigger_' + key);
}
if (response.data.meta.pagination.current_page < response.data.meta.pagination.total_pages) {
this.downloadWebhooks(response.data.meta.pagination.current_page + 1);
}
});
},
}
// get responses
axios.get('./api/v1/configuration/webhook.responses').then((response) => {
for (let key in response.data.data.value) {
if (!response.data.data.value.hasOwnProperty(key)) {
continue;
}
this.responses[key] = this.$t('firefly.webhook_response_' + key);
}
// get deliveries
axios.get('./api/v1/configuration/webhook.deliveries').then((response) => {
for (let key in response.data.data.value) {
if (!response.data.data.value.hasOwnProperty(key)) {
continue;
}
this.deliveries[key] = this.$t('firefly.webhook_delivery_' + key);
}
// get webhooks
this.getWebhooks();
})
})
});
},
getWebhooks: function () {
this.webhooks = [];
this.downloadWebhooks(1);
},
toggleSecret: function (webhook) {
webhook.show_secret = !webhook.show_secret;
},
downloadWebhooks: function (page) {
axios.get("./api/v1/webhooks?page=" + page).then((response) => {
for (let i in response.data.data) {
if (response.data.data.hasOwnProperty(i)) {
let current = response.data.data[i];
let webhook = {
id: current.id,
title: current.attributes.title,
url: current.attributes.url,
active: current.attributes.active,
full_url: current.attributes.url,
secret: current.attributes.secret,
trigger: current.attributes.trigger,
response: current.attributes.response,
delivery: current.attributes.delivery,
show_secret: false,
};
if (current.attributes.url.length > 20) {
webhook.url = current.attributes.url.slice(0, 20) + '...';
}
this.webhooks.push(webhook);
}
}
if (response.data.meta.pagination.current_page < response.data.meta.pagination.total_pages) {
this.downloadWebhooks(response.data.meta.pagination.current_page + 1);
}
});
},
}
}
</script>