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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

114 lines
3.1 KiB
JavaScript
Raw Normal View History

import { ensureJSON, plainJSON, prettyJSON } from "discourse/lib/formatter";
import Component from "@ember/component";
import I18n from "I18n";
2016-06-16 01:49:57 +08:00
import { ajax } from "discourse/lib/ajax";
import bootbox from "bootbox";
import discourseComputed from "discourse-common/utils/decorators";
2016-06-16 01:49:57 +08:00
import { popupAjaxError } from "discourse/lib/ajax-error";
export default Component.extend({
2016-06-16 01:49:57 +08:00
tagName: "li",
expandDetails: null,
expandDetailsRequestKey: "request",
expandDetailsResponseKey: "response",
2016-06-16 01:49:57 +08:00
@discourseComputed("model.status")
2016-06-16 01:49:57 +08:00
statusColorClasses(status) {
if (!status) {
return "";
}
2016-06-16 01:49:57 +08:00
if (status >= 200 && status <= 299) {
return "text-successful";
} else {
return "text-danger";
}
},
@discourseComputed("model.created_at")
2016-06-16 01:49:57 +08:00
createdAt(createdAt) {
return moment(createdAt).format("YYYY-MM-DD HH:mm:ss");
},
@discourseComputed("model.duration")
2016-06-16 01:49:57 +08:00
completion(duration) {
const seconds = Math.floor(duration / 10.0) / 100.0;
2016-09-15 12:57:04 +08:00
return I18n.t("admin.web_hooks.events.completed_in", { count: seconds });
2016-06-16 01:49:57 +08:00
},
@discourseComputed("expandDetails")
expandRequestIcon(expandDetails) {
return expandDetails === this.expandDetailsRequestKey
? "ellipsis-h"
: "ellipsis-v";
},
@discourseComputed("expandDetails")
expandResponseIcon(expandDetails) {
return expandDetails === this.expandDetailsResponseKey
? "ellipsis-h"
: "ellipsis-v";
},
2016-06-16 01:49:57 +08:00
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/api/web_hooks/${this.get(
"model.web_hook_id"
)}/events/${this.get("model.id")}/redeliver`,
{ type: "POST" }
2018-06-15 23:03:24 +08:00
)
.then((json) => {
2016-06-16 01:49:57 +08:00
this.set("model", json.web_hook_event);
})
.catch(popupAjaxError);
2018-06-15 23:03:24 +08:00
}
2016-06-16 01:49:57 +08:00
}
);
},
toggleRequest() {
const expandDetailsKey = this.expandDetailsRequestKey;
2016-06-16 01:49:57 +08:00
if (this.expandDetails !== expandDetailsKey) {
let headers = Object.assign(
2016-06-16 01:49:57 +08:00
{
"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 = this.expandDetailsResponseKey;
2016-06-16 01:49:57 +08:00
if (this.expandDetails !== expandDetailsKey) {
2016-06-16 01:49:57 +08:00
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);
}
},
},
});