discourse/app/assets/javascripts/admin/components/admin-web-hook-event.js.es6

93 lines
2.5 KiB
Plaintext
Raw Normal View History

2018-06-15 11:03:24 -04:00
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";
2016-06-15 13:49:57 -04:00
export default Ember.Component.extend({
2018-06-15 11:03:24 -04:00
tagName: "li",
2016-06-15 13:49:57 -04:00
expandDetails: null,
2018-06-15 11:03:24 -04:00
@computed("model.status")
2016-06-15 13:49:57 -04:00
statusColorClasses(status) {
2018-06-15 11:03:24 -04:00
if (!status) return "";
2016-06-15 13:49:57 -04:00
if (status >= 200 && status <= 299) {
2018-06-15 11:03:24 -04:00
return "text-successful";
2016-06-15 13:49:57 -04:00
} else {
2018-06-15 11:03:24 -04:00
return "text-danger";
2016-06-15 13:49:57 -04:00
}
},
2018-06-15 11:03:24 -04:00
@computed("model.created_at")
2016-06-15 13:49:57 -04:00
createdAt(createdAt) {
2018-06-15 11:03:24 -04:00
return moment(createdAt).format("YYYY-MM-DD HH:mm:ss");
2016-06-15 13:49:57 -04:00
},
2018-06-15 11:03:24 -04:00
@computed("model.duration")
2016-06-15 13:49:57 -04:00
completion(duration) {
const seconds = Math.floor(duration / 10.0) / 100.0;
2018-06-15 11:03:24 -04:00
return I18n.t("admin.web_hooks.events.completed_in", { count: seconds });
2016-06-15 13:49:57 -04:00
},
actions: {
redeliver() {
2018-06-15 11:03:24 -04:00
return bootbox.confirm(
I18n.t("admin.web_hooks.events.redeliver_confirm"),
I18n.t("no_value"),
I18n.t("yes_value"),
result => {
if (result) {
ajax(
`/admin/api/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);
}
2016-06-15 13:49:57 -04:00
}
2018-06-15 11:03:24 -04:00
);
2016-06-15 13:49:57 -04:00
},
toggleRequest() {
2018-06-15 11:03:24 -04:00
const expandDetailsKey = "request";
2016-06-15 13:49:57 -04:00
2018-06-15 11:03:24 -04:00
if (this.get("expandDetails") !== expandDetailsKey) {
let headers = _.extend(
{
"Request URL": this.get("model.request_url"),
"Request method": "POST"
},
ensureJSON(this.get("model.headers"))
);
2016-06-15 13:49:57 -04:00
this.setProperties({
headers: plainJSON(headers),
2018-06-15 11:03:24 -04:00
body: prettyJSON(this.get("model.payload")),
2016-06-15 13:49:57 -04:00
expandDetails: expandDetailsKey,
2018-06-15 11:03:24 -04:00
bodyLabel: I18n.t("admin.web_hooks.events.payload")
2016-06-15 13:49:57 -04:00
});
} else {
2018-06-15 11:03:24 -04:00
this.set("expandDetails", null);
2016-06-15 13:49:57 -04:00
}
},
toggleResponse() {
2018-06-15 11:03:24 -04:00
const expandDetailsKey = "response";
2016-06-15 13:49:57 -04:00
2018-06-15 11:03:24 -04:00
if (this.get("expandDetails") !== expandDetailsKey) {
2016-06-15 13:49:57 -04:00
this.setProperties({
2018-06-15 11:03:24 -04:00
headers: plainJSON(this.get("model.response_headers")),
body: this.get("model.response_body"),
2016-06-15 13:49:57 -04:00
expandDetails: expandDetailsKey,
2018-06-15 11:03:24 -04:00
bodyLabel: I18n.t("admin.web_hooks.events.body")
2016-06-15 13:49:57 -04:00
});
} else {
2018-06-15 11:03:24 -04:00
this.set("expandDetails", null);
2016-06-15 13:49:57 -04:00
}
}
}
});