2019-11-08 05:38:28 +08:00
|
|
|
import { ensureJSON, plainJSON, prettyJSON } from "discourse/lib/formatter";
|
2019-10-24 00:30:52 +08:00
|
|
|
import Component from "@ember/component";
|
2020-05-14 04:23:41 +08:00
|
|
|
import I18n from "I18n";
|
2016-06-16 01:49:57 +08:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
2019-11-08 05:38:28 +08:00
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
2016-06-16 01:49:57 +08:00
|
|
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
2022-09-14 23:06:56 +08:00
|
|
|
import { inject as service } from "@ember/service";
|
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",
|
2022-09-14 23:06:56 +08:00
|
|
|
dialog: service(),
|
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) {
|
2020-09-22 22:28:28 +08:00
|
|
|
if (!status) {
|
|
|
|
return "";
|
|
|
|
}
|
2016-06-16 01:49:57 +08:00
|
|
|
|
|
|
|
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() {
|
2022-09-14 23:06:56 +08:00
|
|
|
return this.dialog.yesNoConfirm({
|
|
|
|
message: I18n.t("admin.web_hooks.events.redeliver_confirm"),
|
|
|
|
didConfirm: () => {
|
|
|
|
return 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-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) {
|
2020-09-01 03:44:14 +08:00
|
|
|
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() {
|
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);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|