2020-05-14 04:23:41 +08:00
|
|
|
import I18n from "I18n";
|
2019-11-08 05:38:28 +08:00
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
2019-10-24 00:30:52 +08:00
|
|
|
import Component from "@ember/component";
|
2016-06-16 01:49:57 +08:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
|
|
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
|
|
|
import { ensureJSON, plainJSON, prettyJSON } from "discourse/lib/formatter";
|
2020-08-27 00:57:13 +08:00
|
|
|
import bootbox from "bootbox";
|
2016-06-16 01:49:57 +08:00
|
|
|
|
2019-10-24 00:30:52 +08:00
|
|
|
export default Component.extend({
|
2016-06-16 01:49:57 +08:00
|
|
|
tagName: "li",
|
|
|
|
expandDetails: null,
|
2019-04-16 14:24:30 +08:00
|
|
|
expandDetailsRequestKey: "request",
|
|
|
|
expandDetailsResponseKey: "response",
|
2016-06-16 01:49:57 +08:00
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed("model.status")
|
2016-06-16 01:49:57 +08:00
|
|
|
statusColorClasses(status) {
|
|
|
|
if (!status) return "";
|
|
|
|
|
|
|
|
if (status >= 200 && status <= 299) {
|
|
|
|
return "text-successful";
|
|
|
|
} else {
|
|
|
|
return "text-danger";
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed("model.created_at")
|
2016-06-16 01:49:57 +08:00
|
|
|
createdAt(createdAt) {
|
|
|
|
return moment(createdAt).format("YYYY-MM-DD HH:mm:ss");
|
|
|
|
},
|
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@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
|
|
|
},
|
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed("expandDetails")
|
2019-04-16 14:24:30 +08:00
|
|
|
expandRequestIcon(expandDetails) {
|
2019-05-27 16:15:39 +08:00
|
|
|
return expandDetails === this.expandDetailsRequestKey
|
2019-04-16 14:24:30 +08:00
|
|
|
? "ellipsis-h"
|
|
|
|
: "ellipsis-v";
|
|
|
|
},
|
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed("expandDetails")
|
2019-04-16 14:24:30 +08:00
|
|
|
expandResponseIcon(expandDetails) {
|
2019-05-27 16:15:39 +08:00
|
|
|
return expandDetails === this.expandDetailsResponseKey
|
2019-04-16 14:24:30 +08:00
|
|
|
? "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) {
|
2016-09-19 16:43:06 +08:00
|
|
|
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
|
|
|
)
|
2016-09-19 16:43:06 +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() {
|
2019-05-27 16:15:39 +08:00
|
|
|
const expandDetailsKey = this.expandDetailsRequestKey;
|
2016-06-16 01:49:57 +08:00
|
|
|
|
2019-05-27 16:15:39 +08:00
|
|
|
if (this.expandDetails !== expandDetailsKey) {
|
2016-06-16 01:49:57 +08:00
|
|
|
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() {
|
2019-05-27 16:15:39 +08:00
|
|
|
const expandDetailsKey = this.expandDetailsResponseKey;
|
2016-06-16 01:49:57 +08:00
|
|
|
|
2019-05-27 16:15:39 +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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|