mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: Webhooks.
This commit is contained in:
committed by
Guo Xiang Tan
parent
1f70fc9e11
commit
9ce61b4586
@@ -0,0 +1,42 @@
|
||||
import computed from 'ember-addons/ember-computed-decorators';
|
||||
|
||||
export default Ember.Component.extend({
|
||||
classNames: ['hook-event'],
|
||||
typeName: Ember.computed.alias('type.name'),
|
||||
|
||||
@computed('typeName')
|
||||
name(typeName) {
|
||||
return I18n.t(`admin.web_hooks.${typeName}_event.name`);
|
||||
},
|
||||
|
||||
@computed('typeName')
|
||||
details(typeName) {
|
||||
return I18n.t(`admin.web_hooks.${typeName}_event.details`);
|
||||
},
|
||||
|
||||
@computed('model.[]', 'typeName')
|
||||
eventTypeExists(eventTypes, typeName) {
|
||||
return eventTypes.any(event => event.name === typeName);
|
||||
},
|
||||
|
||||
@computed('eventTypeExists')
|
||||
enabled: {
|
||||
get(eventTypeExists) {
|
||||
return eventTypeExists;
|
||||
},
|
||||
set(value, eventTypeExists) {
|
||||
const type = this.get('type');
|
||||
const model = this.get('model');
|
||||
// add an association when not exists
|
||||
if (value !== eventTypeExists) {
|
||||
if (value) {
|
||||
model.addObject(type);
|
||||
} else {
|
||||
model.removeObjects(model.filter(eventType => eventType.name === type.name));
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,78 @@
|
||||
import computed from 'ember-addons/ember-computed-decorators';
|
||||
import { ajax } from 'discourse/lib/ajax';
|
||||
import { popupAjaxError } from 'discourse/lib/ajax-error';
|
||||
import { ensureJSON, plainJSON, prettyJSON } from 'discourse/lib/formatter';
|
||||
|
||||
export default Ember.Component.extend({
|
||||
tagName: 'li',
|
||||
expandDetails: null,
|
||||
|
||||
@computed('model.status')
|
||||
statusColorClasses(status) {
|
||||
if (!status) return '';
|
||||
|
||||
if (status >= 200 && status <= 299) {
|
||||
return 'text-successful';
|
||||
} else {
|
||||
return 'text-danger';
|
||||
}
|
||||
},
|
||||
|
||||
@computed('model.created_at')
|
||||
createdAt(createdAt) {
|
||||
return moment(createdAt).format('YYYY-MM-DD HH:mm:ss');
|
||||
},
|
||||
|
||||
@computed('model.duration')
|
||||
completion(duration) {
|
||||
const seconds = Math.floor(duration / 10.0) / 100.0;
|
||||
return I18n.t('admin.web_hooks.events.completion', { seconds });
|
||||
},
|
||||
|
||||
actions: {
|
||||
redeliver() {
|
||||
return bootbox.confirm(I18n.t('admin.web_hooks.events.redeliver_confirm'), I18n.t('no_value'), I18n.t('yes_value'), result => {
|
||||
if (result) {
|
||||
ajax(`/admin/web_hooks/${this.get('model.web_hook_id')}/events/${this.get('model.id')}/redeliver`, { type: 'POST' }).then(json => {
|
||||
this.set('model', json.web_hook_event);
|
||||
}).catch(popupAjaxError);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
toggleRequest() {
|
||||
const expandDetailsKey = 'request';
|
||||
|
||||
if (this.get('expandDetails') !== expandDetailsKey) {
|
||||
let headers = _.extend({
|
||||
'Request URL': this.get('model.request_url'),
|
||||
'Request method': 'POST'
|
||||
}, ensureJSON(this.get('model.headers')));
|
||||
this.setProperties({
|
||||
headers: plainJSON(headers),
|
||||
body: prettyJSON(this.get('model.payload')),
|
||||
expandDetails: expandDetailsKey,
|
||||
bodyLabel: I18n.t('admin.web_hooks.events.payload')
|
||||
});
|
||||
} else {
|
||||
this.set('expandDetails', null);
|
||||
}
|
||||
},
|
||||
|
||||
toggleResponse() {
|
||||
const expandDetailsKey = 'response';
|
||||
|
||||
if (this.get('expandDetails') !== expandDetailsKey) {
|
||||
this.setProperties({
|
||||
headers: plainJSON(this.get('model.response_headers')),
|
||||
body: this.get('model.response_body'),
|
||||
expandDetails: expandDetailsKey,
|
||||
bodyLabel: I18n.t('admin.web_hooks.events.body')
|
||||
});
|
||||
} else {
|
||||
this.set('expandDetails', null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
@@ -0,0 +1,28 @@
|
||||
import computed from 'ember-addons/ember-computed-decorators';
|
||||
import StringBuffer from 'discourse/mixins/string-buffer';
|
||||
import { iconHTML } from 'discourse/helpers/fa-icon';
|
||||
|
||||
export default Ember.Component.extend(StringBuffer, {
|
||||
classes: ["text-muted", "text-danger", "text-successful"],
|
||||
icons: ["circle-o", "times-circle", "circle"],
|
||||
|
||||
@computed('deliveryStatuses', 'model.last_delivery_status')
|
||||
status(deliveryStatuses, lastDeliveryStatus) {
|
||||
return deliveryStatuses.find(s => s.id === lastDeliveryStatus);
|
||||
},
|
||||
|
||||
@computed('status.id', 'icons')
|
||||
icon(statusId, icons) {
|
||||
return icons[statusId - 1];
|
||||
},
|
||||
|
||||
@computed('status.id', 'classes')
|
||||
class(statusId, classes) {
|
||||
return classes[statusId - 1];
|
||||
},
|
||||
|
||||
renderString(buffer) {
|
||||
buffer.push(iconHTML(this.get('icon'), { class: this.get('class') }));
|
||||
buffer.push(I18n.t(`admin.web_hooks.delivery_status.${this.get('status.name')}`));
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user