mirror of
https://github.com/discourse/discourse.git
synced 2025-05-23 20:21:25 +08:00
FEATURE: prompts new webhook events
This commit is contained in:

committed by
Guo Xiang Tan

parent
115461b395
commit
00d5facf36
@ -1,14 +1,65 @@
|
||||
import { ajax } from 'discourse/lib/ajax';
|
||||
import { popupAjaxError } from 'discourse/lib/ajax-error';
|
||||
import computed from 'ember-addons/ember-computed-decorators';
|
||||
|
||||
export default Ember.Controller.extend({
|
||||
pingDisabled: false,
|
||||
incomingEventIds: [],
|
||||
incomingCount: Ember.computed.alias("incomingEventIds.length"),
|
||||
|
||||
@computed('incomingCount')
|
||||
hasIncoming(incomingCount) {
|
||||
return incomingCount > 0;
|
||||
},
|
||||
|
||||
subscribe() {
|
||||
this.messageBus.subscribe(`/web_hook_events/${this.get('model.extras.web_hook_id')}`, data => {
|
||||
if (data.event_type === 'ping') {
|
||||
this.set('pingDisabled', false);
|
||||
}
|
||||
this._addIncoming(data.web_hook_event_id);
|
||||
});
|
||||
},
|
||||
|
||||
unsubscribe() {
|
||||
this.messageBus.unsubscribe('/web_hook_events/*');
|
||||
},
|
||||
|
||||
_addIncoming(eventId) {
|
||||
const incomingEventIds = this.get("incomingEventIds");
|
||||
|
||||
if (incomingEventIds.indexOf(eventId) === -1) {
|
||||
incomingEventIds.pushObject(eventId);
|
||||
}
|
||||
},
|
||||
|
||||
actions: {
|
||||
loadMore() {
|
||||
this.get('model').loadMore();
|
||||
},
|
||||
|
||||
ping() {
|
||||
ajax(`/admin/web_hooks/${this.get('model.extras.web_hook_id')}/ping`, {type: 'POST'}).catch(popupAjaxError);
|
||||
this.set('pingDisabled', true);
|
||||
|
||||
ajax(`/admin/web_hooks/${this.get('model.extras.web_hook_id')}/ping`, {
|
||||
type: 'POST'
|
||||
}).catch(error => {
|
||||
this.set('pingDisabled', false);
|
||||
popupAjaxError(error);
|
||||
});
|
||||
},
|
||||
|
||||
showInserted() {
|
||||
const webHookId = this.get('model.extras.web_hook_id');
|
||||
|
||||
ajax(`/admin/web_hooks/${webHookId}/events/bulk`, {
|
||||
type: 'GET',
|
||||
data: { ids: this.get('incomingEventIds') }
|
||||
}).then(data => {
|
||||
const objects = data.map(event => this.store.createRecord('web-hook-event', event));
|
||||
this.get("model").unshiftObjects(objects);
|
||||
this.set("incomingEventIds", []);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user